Author: darran.lofthouse(a)jboss.com
Date: 2008-07-22 11:36:18 -0400 (Tue, 22 Jul 2008)
New Revision: 7885
Modified:
stack/native/branches/dlofthouse/JBWS-2234/modules/core/src/main/java/org/jboss/ws/core/jaxrpc/SOAPFaultHelperJAXRPC.java
stack/native/branches/dlofthouse/JBWS-2234/modules/core/src/main/java/org/jboss/ws/core/jaxws/SOAPFaultHelperJAXWS.java
stack/native/branches/dlofthouse/JBWS-2234/modules/testsuite/native-tests/src/test/java/org/jboss/test/ws/common/soap/SOAPFaultTestCase.java
stack/native/branches/dlofthouse/JBWS-2234/modules/testsuite/native-tests/src/test/java/org/jboss/test/ws/jaxrpc/jbws2234/JBWS2234TestCase.java
Log:
Use MessageContext to identify binding.
Modified:
stack/native/branches/dlofthouse/JBWS-2234/modules/core/src/main/java/org/jboss/ws/core/jaxrpc/SOAPFaultHelperJAXRPC.java
===================================================================
---
stack/native/branches/dlofthouse/JBWS-2234/modules/core/src/main/java/org/jboss/ws/core/jaxrpc/SOAPFaultHelperJAXRPC.java 2008-07-22
14:44:31 UTC (rev 7884)
+++
stack/native/branches/dlofthouse/JBWS-2234/modules/core/src/main/java/org/jboss/ws/core/jaxrpc/SOAPFaultHelperJAXRPC.java 2008-07-22
15:36:18 UTC (rev 7885)
@@ -36,12 +36,14 @@
import javax.xml.soap.MessageFactory;
import javax.xml.soap.Name;
import javax.xml.soap.SOAPBody;
+import javax.xml.soap.SOAPConstants;
import javax.xml.soap.SOAPElement;
import javax.xml.soap.SOAPException;
import javax.xml.soap.SOAPFault;
import javax.xml.transform.Result;
import javax.xml.transform.Source;
import javax.xml.transform.dom.DOMSource;
+import javax.xml.ws.soap.SOAPBinding;
import org.jboss.logging.Logger;
import org.jboss.ws.Constants;
@@ -61,6 +63,7 @@
import org.jboss.ws.core.soap.SOAPFactoryImpl;
import org.jboss.ws.core.soap.SOAPMessageImpl;
import org.jboss.ws.core.soap.XMLFragment;
+import org.jboss.ws.metadata.umdm.EndpointMetaData;
import org.jboss.ws.metadata.umdm.FaultMetaData;
import org.jboss.ws.metadata.umdm.OperationMetaData;
import org.jboss.xb.binding.NamespaceRegistry;
@@ -191,7 +194,15 @@
}
else
{
- QName faultCode = Constants.SOAP11_FAULT_CODE_SERVER;
+ QName faultCode;
+ if (isSOAP12() == false)
+ {
+ faultCode = Constants.SOAP11_FAULT_CODE_SERVER;
+ }
+ else
+ {
+ faultCode = SOAPConstants.SOAP_RECEIVER_FAULT;
+ }
String faultString = (reqEx.getMessage() != null ? reqEx.getMessage() :
reqEx.toString());
faultEx = new SOAPFaultException(faultCode, faultString, null, null);
faultEx.initCause(reqEx);
@@ -224,8 +235,7 @@
SerializationContext serContext = (msgContext != null ?
msgContext.getSerializationContext() : new SerializationContextJAXRPC());
NamespaceRegistry nsRegistry = serContext.getNamespaceRegistry();
- MessageFactory factory = new MessageFactoryImpl();
- SOAPMessageImpl soapMessage = (SOAPMessageImpl)factory.createMessage();
+ SOAPMessageImpl soapMessage = createSOAPMessage();
SOAPEnvelopeImpl soapEnvelope =
(SOAPEnvelopeImpl)soapMessage.getSOAPPart().getEnvelope();
SOAPBody soapBody = soapEnvelope.getBody();
@@ -298,6 +308,34 @@
return soapMessage;
}
+ private static SOAPMessageImpl createSOAPMessage() throws SOAPException
+ {
+ MessageFactoryImpl factory = (MessageFactoryImpl)MessageFactory.newInstance();
+
+ if (isSOAP12() == true)
+ {
+ factory.setEnvNamespace(Constants.NS_SOAP12_ENV);
+ }
+
+ return (SOAPMessageImpl)factory.createMessage();
+ }
+
+ private static boolean isSOAP12()
+ {
+ CommonMessageContext msgContext = MessageContextAssociation.peekMessageContext();
+ if (msgContext != null)
+ {
+ EndpointMetaData emd = msgContext.getEndpointMetaData();
+ String bindingId = emd.getBindingId();
+ if (SOAPBinding.SOAP12HTTP_BINDING.equals(bindingId) ||
SOAPBinding.SOAP12HTTP_MTOM_BINDING.equals(bindingId))
+ {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
private static String getValidFaultString(SOAPFaultException faultEx)
{
String faultString = faultEx.getFaultString();
Modified:
stack/native/branches/dlofthouse/JBWS-2234/modules/core/src/main/java/org/jboss/ws/core/jaxws/SOAPFaultHelperJAXWS.java
===================================================================
---
stack/native/branches/dlofthouse/JBWS-2234/modules/core/src/main/java/org/jboss/ws/core/jaxws/SOAPFaultHelperJAXWS.java 2008-07-22
14:44:31 UTC (rev 7884)
+++
stack/native/branches/dlofthouse/JBWS-2234/modules/core/src/main/java/org/jboss/ws/core/jaxws/SOAPFaultHelperJAXWS.java 2008-07-22
15:36:18 UTC (rev 7885)
@@ -30,6 +30,7 @@
import javax.xml.transform.Source;
import javax.xml.transform.dom.DOMSource;
import javax.xml.ws.WebServiceException;
+import javax.xml.ws.soap.SOAPBinding;
import javax.xml.ws.soap.SOAPFaultException;
import org.jboss.logging.Logger;
@@ -44,10 +45,12 @@
import org.jboss.ws.core.binding.SerializerSupport;
import org.jboss.ws.core.jaxrpc.SOAPFaultHelperJAXRPC;
import org.jboss.ws.core.soap.MessageContextAssociation;
+import org.jboss.ws.core.soap.MessageFactoryImpl;
import org.jboss.ws.core.soap.NameImpl;
import org.jboss.ws.core.soap.SOAPFactoryImpl;
import org.jboss.ws.core.soap.SOAPMessageImpl;
import org.jboss.ws.core.soap.XMLFragment;
+import org.jboss.ws.metadata.umdm.EndpointMetaData;
import org.jboss.ws.metadata.umdm.FaultMetaData;
import org.jboss.ws.metadata.umdm.OperationMetaData;
import org.w3c.dom.Element;
@@ -136,7 +139,8 @@
throw new WebServiceException(e);
}
}
- else log.debug("Cannot find fault meta data for: " + xmlName);
+ else
+ log.debug("Cannot find fault meta data for: " + xmlName);
}
}
@@ -185,8 +189,7 @@
private static SOAPMessageImpl toSOAPMessage(SOAPFaultException faultEx) throws
SOAPException
{
- MessageFactory factory = MessageFactory.newInstance();
- SOAPMessageImpl soapMessage = (SOAPMessageImpl)factory.createMessage();
+ SOAPMessageImpl soapMessage = createSOAPMessage();
SOAPBody soapBody = soapMessage.getSOAPBody();
populateSOAPFault(soapBody, faultEx);
@@ -241,8 +244,7 @@
private static SOAPMessageImpl toSOAPMessage(Exception ex) throws SOAPException
{
- MessageFactory factory = MessageFactory.newInstance();
- SOAPMessageImpl soapMessage = (SOAPMessageImpl)factory.createMessage();
+ SOAPMessageImpl soapMessage = createSOAPMessage();
SOAPBody soapBody = soapMessage.getSOAPBody();
@@ -266,11 +268,31 @@
SOAPElement detailEntry = toDetailEntry(faultBean, serContext, faultMetaData);
detail.addChildElement(detailEntry);
}
- else log.debug("Cannot obtain fault meta data for: " + exClass);
+ else
+ log.debug("Cannot obtain fault meta data for: " + exClass);
return soapMessage;
}
+ private static SOAPMessageImpl createSOAPMessage() throws SOAPException
+ {
+ MessageFactoryImpl factory = (MessageFactoryImpl)MessageFactory.newInstance();
+
+ CommonMessageContext msgContext = MessageContextAssociation.peekMessageContext();
+ if (msgContext != null)
+ {
+ EndpointMetaData emd = msgContext.getEndpointMetaData();
+ String bindingId = emd.getBindingId();
+ if (SOAPBinding.SOAP12HTTP_BINDING.equals(bindingId) ||
SOAPBinding.SOAP12HTTP_MTOM_BINDING.equals(bindingId))
+ {
+ factory.setEnvNamespace(Constants.NS_SOAP12_ENV);
+ }
+
+ }
+
+ return (SOAPMessageImpl)factory.createMessage();
+ }
+
private static Name getFallbackFaultCode()
{
/* faultcode
Modified:
stack/native/branches/dlofthouse/JBWS-2234/modules/testsuite/native-tests/src/test/java/org/jboss/test/ws/common/soap/SOAPFaultTestCase.java
===================================================================
---
stack/native/branches/dlofthouse/JBWS-2234/modules/testsuite/native-tests/src/test/java/org/jboss/test/ws/common/soap/SOAPFaultTestCase.java 2008-07-22
14:44:31 UTC (rev 7884)
+++
stack/native/branches/dlofthouse/JBWS-2234/modules/testsuite/native-tests/src/test/java/org/jboss/test/ws/common/soap/SOAPFaultTestCase.java 2008-07-22
15:36:18 UTC (rev 7885)
@@ -69,7 +69,7 @@
{
Detail detail = createDetailElement();
SOAPFaultException faultEx = new
SOAPFaultException(Constants.SOAP11_FAULT_CODE_CLIENT, "Some fault message",
"Some fault actor", detail);
- SOAPEnvelope soapEnv = SOAPFaultHelperJAXRPC.exceptionToFaultMessage(faultEx,
null).getSOAPPart().getEnvelope();
+ SOAPEnvelope soapEnv =
SOAPFaultHelperJAXRPC.exceptionToFaultMessage(faultEx).getSOAPPart().getEnvelope();
assertEquals(DOMUtils.parse(envStr), soapEnv);
}
Modified:
stack/native/branches/dlofthouse/JBWS-2234/modules/testsuite/native-tests/src/test/java/org/jboss/test/ws/jaxrpc/jbws2234/JBWS2234TestCase.java
===================================================================
---
stack/native/branches/dlofthouse/JBWS-2234/modules/testsuite/native-tests/src/test/java/org/jboss/test/ws/jaxrpc/jbws2234/JBWS2234TestCase.java 2008-07-22
14:44:31 UTC (rev 7884)
+++
stack/native/branches/dlofthouse/JBWS-2234/modules/testsuite/native-tests/src/test/java/org/jboss/test/ws/jaxrpc/jbws2234/JBWS2234TestCase.java 2008-07-22
15:36:18 UTC (rev 7885)
@@ -83,7 +83,7 @@
}
catch (Exception e)
{
- assertEquals(TestEndpointImpl.RUNTIME_EXCEPTION, e.getMessage());
+ assertEquals("Simulated failure", e.getCause().getMessage());
}
}
}
Show replies by date