Author: alex.guizar(a)jboss.com
Date: 2006-11-17 02:56:40 -0500 (Fri, 17 Nov 2006)
New Revision: 1455
Added:
trunk/src/main/java/org/jboss/ws/jaxrpc/SOAPFaultHelperJAXRPC.java
trunk/src/main/java/org/jboss/ws/jaxws/core/SOAPFaultHelperJAXWS.java
Removed:
trunk/src/main/java/org/jboss/ws/jaxrpc/SOAPFaultExceptionHelper.java
Modified:
trunk/src/main/java/org/jboss/ws/common/CommonSOAPBinding.java
trunk/src/main/java/org/jboss/ws/deployment/JSR181MetaDataBuilder.java
trunk/src/main/java/org/jboss/ws/integration/jboss50/ServiceEndpointInvokerEJB3.java
trunk/src/main/java/org/jboss/ws/jaxrpc/SOAP11BindingJAXRPC.java
trunk/src/main/java/org/jboss/ws/jaxrpc/SOAP12BindingJAXRPC.java
trunk/src/main/java/org/jboss/ws/jaxws/client/ClientImpl.java
trunk/src/main/java/org/jboss/ws/jaxws/client/ClientProxy.java
trunk/src/main/java/org/jboss/ws/jaxws/core/SOAP11BindingJAXWS.java
trunk/src/main/java/org/jboss/ws/jaxws/core/SOAP12BindingJAXWS.java
trunk/src/main/java/org/jboss/ws/metadata/FaultMetaData.java
trunk/src/main/java/org/jboss/ws/server/AbstractServiceEndpointInvoker.java
trunk/src/main/java/org/jboss/ws/server/ServiceEndpoint.java
trunk/src/main/java/org/jboss/ws/server/ServiceEndpointInvokerJSE.java
trunk/src/test/build.xml
trunk/src/test/java/org/jboss/test/ws/common/soap/SOAPFaultTestCase.java
trunk/src/test/java/org/jboss/test/ws/jaxrpc/encoded/marshalltest/MarshallTestCase.java
trunk/src/test/java/org/jboss/test/ws/jaxrpc/jbws807/JBWS807TestCase.java
trunk/src/test/java/org/jboss/test/ws/jaxrpc/samples/exception/ExceptionTestCase.java
trunk/src/test/java/org/jboss/test/ws/jaxws/exception/ExceptionTestCase.java
trunk/src/test/java/org/jboss/test/ws/jaxws/jsr181/webmethod/JSR181WebMethodTestCase.java
trunk/src/test/java/org/jboss/test/ws/jaxws/samples/retail/profile/ObjectFactory.java
trunk/src/test/java/org/jboss/test/ws/jaxws/wsaddressing/replyto/AddressingReplyToTestCase.java
Log:
JBWS-1297
Modified: trunk/src/main/java/org/jboss/ws/common/CommonSOAPBinding.java
===================================================================
--- trunk/src/main/java/org/jboss/ws/common/CommonSOAPBinding.java 2006-11-17 02:06:33 UTC
(rev 1454)
+++ trunk/src/main/java/org/jboss/ws/common/CommonSOAPBinding.java 2006-11-17 07:56:40 UTC
(rev 1455)
@@ -31,7 +31,6 @@
import javax.activation.DataHandler;
import javax.xml.namespace.QName;
import javax.xml.rpc.ParameterMode;
-import javax.xml.rpc.soap.SOAPFaultException;
import javax.xml.soap.AttachmentPart;
import javax.xml.soap.MessageFactory;
import javax.xml.soap.Name;
@@ -49,12 +48,10 @@
import org.jboss.logging.Logger;
import org.jboss.ws.Constants;
import org.jboss.ws.WSException;
-import org.jboss.ws.xop.XOPContext;
import org.jboss.ws.binding.BindingException;
import org.jboss.ws.binding.EndpointInvocation;
import org.jboss.ws.binding.UnboundHeader;
import org.jboss.ws.jaxrpc.ParameterWrapping;
-import org.jboss.ws.jaxrpc.SOAPFaultExceptionHelper;
import org.jboss.ws.jaxrpc.Style;
import org.jboss.ws.metadata.OperationMetaData;
import org.jboss.ws.metadata.ParameterMetaData;
@@ -75,6 +72,7 @@
import org.jboss.ws.utils.DOMUtils;
import org.jboss.ws.utils.JavaUtils;
import org.jboss.ws.utils.MimeUtils;
+import org.jboss.ws.xop.XOPContext;
import org.jboss.xb.binding.NamespaceRegistry;
import org.w3c.dom.Element;
@@ -642,6 +640,8 @@
handleException(e);
}
}
+
+ public abstract SOAPMessage exceptionToFaultMessage(Exception ex);
private void verifySOAPVersion(OperationMetaData opMetaData, SOAPEnvelope
soapEnvelope)
{
Modified: trunk/src/main/java/org/jboss/ws/deployment/JSR181MetaDataBuilder.java
===================================================================
--- trunk/src/main/java/org/jboss/ws/deployment/JSR181MetaDataBuilder.java 2006-11-17
02:06:33 UTC (rev 1454)
+++ trunk/src/main/java/org/jboss/ws/deployment/JSR181MetaDataBuilder.java 2006-11-17
07:56:40 UTC (rev 1455)
@@ -298,13 +298,22 @@
{
for (OperationMetaData operation : epMetaData.getOperations())
{
+ // parameters
for (ParameterMetaData paramMetaData : operation.getParameters())
{
populateXmlType(paramMetaData);
}
+
+ // return value
ParameterMetaData returnParameter = operation.getReturnParameter();
if (returnParameter != null)
populateXmlType(returnParameter);
+
+ // faults
+ for (FaultMetaData faultMetaData : operation.getFaults())
+ {
+ populateXmlType(faultMetaData);
+ }
}
}
@@ -344,6 +353,17 @@
types.addTypeMapping(new TypeMappingMetaData(types, xmlType, javaName));
}
+
+ private void populateXmlType(FaultMetaData faultMetaData)
+ {
+ EndpointMetaData epMetaData =
faultMetaData.getOperationMetaData().getEndpointMetaData();
+ TypesMetaData types = epMetaData.getServiceMetaData().getTypesMetaData();
+
+ QName xmlType = faultMetaData.getXmlType();
+ String faultBeanName = faultMetaData.getFaultBeanName();
+
+ types.addTypeMapping(new TypeMappingMetaData(types, xmlType, faultBeanName));
+ }
protected void processSOAPBinding(EndpointMetaData epMetaData, Class wsClass)
{
Modified:
trunk/src/main/java/org/jboss/ws/integration/jboss50/ServiceEndpointInvokerEJB3.java
===================================================================
---
trunk/src/main/java/org/jboss/ws/integration/jboss50/ServiceEndpointInvokerEJB3.java 2006-11-17
02:06:33 UTC (rev 1454)
+++
trunk/src/main/java/org/jboss/ws/integration/jboss50/ServiceEndpointInvokerEJB3.java 2006-11-17
07:56:40 UTC (rev 1455)
@@ -91,7 +91,7 @@
}
/** Invoke an instance of the SEI implementation bean */
- public void invokeServiceEndpoint(ServiceEndpointInfo seInfo, Object seiImpl,
EndpointInvocation epInv) throws SOAPFaultException
+ public void invokeServiceEndpoint(ServiceEndpointInfo seInfo, Object seiImpl,
EndpointInvocation epInv) throws SOAPFaultException, Exception
{
log.debug("invokeServiceEndpoint: " + epInv.getJavaMethod().getName());
@@ -125,9 +125,9 @@
Object retObj = container.localInvoke(implMethod, args);
epInv.setReturnValue(retObj);
}
- catch (Throwable e)
+ catch (Throwable th)
{
- handleInvocationException(e);
+ handleInvocationException(th);
}
}
Modified: trunk/src/main/java/org/jboss/ws/jaxrpc/SOAP11BindingJAXRPC.java
===================================================================
--- trunk/src/main/java/org/jboss/ws/jaxrpc/SOAP11BindingJAXRPC.java 2006-11-17 02:06:33
UTC (rev 1454)
+++ trunk/src/main/java/org/jboss/ws/jaxrpc/SOAP11BindingJAXRPC.java 2006-11-17 07:56:40
UTC (rev 1455)
@@ -23,7 +23,6 @@
//$Id:SOAP11BindingJAXRPC.java 1054 2006-09-26 10:33:43Z thomas.diesler(a)jboss.com $
-import javax.xml.rpc.soap.SOAPFaultException;
import javax.xml.soap.SOAPMessage;
import org.jboss.ws.common.CommonSOAP11Binding;
@@ -49,6 +48,12 @@
@Override
protected void throwFaultException(SOAPFaultImpl fault) throws Exception
{
- throw SOAPFaultExceptionHelper.getSOAPFaultException(fault);
+ throw SOAPFaultHelperJAXRPC.getSOAPFaultException(fault);
}
+
+ @Override
+ public SOAPMessage exceptionToFaultMessage(Exception ex)
+ {
+ return SOAPFaultHelperJAXRPC.exceptionToFaultMessage(ex);
+ }
}
Modified: trunk/src/main/java/org/jboss/ws/jaxrpc/SOAP12BindingJAXRPC.java
===================================================================
--- trunk/src/main/java/org/jboss/ws/jaxrpc/SOAP12BindingJAXRPC.java 2006-11-17 02:06:33
UTC (rev 1454)
+++ trunk/src/main/java/org/jboss/ws/jaxrpc/SOAP12BindingJAXRPC.java 2006-11-17 07:56:40
UTC (rev 1455)
@@ -48,6 +48,12 @@
@Override
protected void throwFaultException(SOAPFaultImpl fault) throws Exception
{
- throw SOAPFaultExceptionHelper.getSOAPFaultException(fault);
+ throw SOAPFaultHelperJAXRPC.getSOAPFaultException(fault);
}
+
+ @Override
+ public SOAPMessage exceptionToFaultMessage(Exception ex)
+ {
+ return SOAPFaultHelperJAXRPC.exceptionToFaultMessage(ex);
+ }
}
Deleted: trunk/src/main/java/org/jboss/ws/jaxrpc/SOAPFaultExceptionHelper.java
===================================================================
--- trunk/src/main/java/org/jboss/ws/jaxrpc/SOAPFaultExceptionHelper.java 2006-11-17
02:06:33 UTC (rev 1454)
+++ trunk/src/main/java/org/jboss/ws/jaxrpc/SOAPFaultExceptionHelper.java 2006-11-17
07:56:40 UTC (rev 1455)
@@ -1,317 +0,0 @@
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2005, JBoss Inc., and individual contributors as indicated
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* This is free software; you can redistribute it and/or modify it
-* under the terms of the GNU Lesser General Public License as
-* published by the Free Software Foundation; either version 2.1 of
-* the License, or (at your option) any later version.
-*
-* This software is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public
-* License along with this software; if not, write to the Free
-* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-* 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
-*/
-package org.jboss.ws.jaxrpc;
-
-// $Id$
-
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
-import javax.xml.namespace.QName;
-import javax.xml.rpc.JAXRPCException;
-import javax.xml.rpc.encoding.TypeMapping;
-import javax.xml.rpc.soap.SOAPFaultException;
-import javax.xml.soap.Detail;
-import javax.xml.soap.DetailEntry;
-import javax.xml.soap.MessageFactory;
-import javax.xml.soap.Name;
-import javax.xml.soap.SOAPBody;
-import javax.xml.soap.SOAPElement;
-import javax.xml.soap.SOAPException;
-import javax.xml.soap.SOAPFault;
-import javax.xml.soap.SOAPMessage;
-
-import org.jboss.logging.Logger;
-import org.jboss.ws.utils.DOMUtils;
-import org.jboss.ws.utils.DOMWriter;
-import org.jboss.ws.Constants;
-import org.jboss.ws.WSException;
-import org.jboss.ws.binding.BindingException;
-import org.jboss.ws.binding.DeserializerSupport;
-import org.jboss.ws.binding.SerializationContext;
-import org.jboss.ws.binding.SerializerSupport;
-import org.jboss.ws.common.CommonMessageContext;
-import org.jboss.ws.jaxrpc.encoding.DeserializerFactoryBase;
-import org.jboss.ws.jaxrpc.encoding.SerializerFactoryBase;
-import org.jboss.ws.metadata.FaultMetaData;
-import org.jboss.ws.metadata.OperationMetaData;
-import org.jboss.ws.soap.MessageContextAssociation;
-import org.jboss.ws.soap.MessageFactoryImpl;
-import org.jboss.ws.soap.NameImpl;
-import org.jboss.ws.soap.SOAPEnvelopeImpl;
-import org.jboss.ws.soap.SOAPFactoryImpl;
-import org.jboss.xb.binding.NamespaceRegistry;
-import org.w3c.dom.Element;
-
-/**
- * A Helper that translates between SOAPFaultException and SOAPFault.
- *
- * @author Thomas.Diesler(a)jboss.org
- * @since 03-Feb-2005
- */
-public class SOAPFaultExceptionHelper
-{
- // provide logging
- private static Logger log = Logger.getLogger(SOAPFaultExceptionHelper.class);
-
- private static List<QName> allowedFaultCodes = new ArrayList<QName>();
- static
- {
- allowedFaultCodes.add(Constants.SOAP11_FAULT_CODE_CLIENT);
- allowedFaultCodes.add(Constants.SOAP11_FAULT_CODE_SERVER);
- allowedFaultCodes.add(Constants.SOAP11_FAULT_CODE_VERSION_MISMATCH);
- allowedFaultCodes.add(Constants.SOAP11_FAULT_CODE_MUST_UNDERSTAND);
- }
-
- /** Hide constructor */
- private SOAPFaultExceptionHelper()
- {
- }
-
- /** Factory method for FaultException for a given SOAPFault */
- public static SOAPFaultException getSOAPFaultException(SOAPFault soapFault)
- {
- QName faultCode = ((NameImpl)soapFault.getFaultCodeAsName()).toQName();
- String faultString = soapFault.getFaultString();
- String faultActor = soapFault.getFaultActor();
- Detail detail = soapFault.getDetail();
-
- SOAPFaultException faultEx = new SOAPFaultException(faultCode, faultString,
faultActor, detail);
-
- CommonMessageContext msgContext = MessageContextAssociation.peekMessageContext();
- if (detail != null && msgContext != null)
- {
- SerializationContext serContext = msgContext.getSerializationContext();
- TypeMapping typeMapping = serContext.getTypeMapping();
-
- Iterator it = detail.getDetailEntries();
- while (it.hasNext())
- {
- DetailEntry deElement = (DetailEntry)it.next();
- Name deName = deElement.getElementName();
- QName xmlName = new QName(deName.getURI(), deName.getLocalName());
-
- OperationMetaData opMetaData = msgContext.getOperationMetaData();
- FaultMetaData faultMetaData = opMetaData.getFault(xmlName);
- if (faultMetaData != null)
- {
- log.debug("Deserialize fault: " + faultMetaData);
- QName xmlType = faultMetaData.getXmlType();
- Class javaType = faultMetaData.getJavaType();
-
- // Get the deserializer from the type mapping
- DeserializerFactoryBase desFactory =
(DeserializerFactoryBase)typeMapping.getDeserializer(javaType, xmlType);
- if (desFactory == null)
- throw new JAXRPCException("Cannot obtain deserializer factory for:
" + xmlType);
-
- // Try jaxb deserialization
- try
- {
- //
http://jira.jboss.org/jira/browse/JBWS-955
- // Cannot deserialize fault detail
- String prefix = deName.getPrefix();
- if (prefix.length() > 0)
- {
- String nsURI = deName.getURI();
- String attrValue = deElement.getAttribute("xmlns:" +
prefix);
- if (nsURI.length() > 0 && attrValue.length() == 0)
- deElement.addNamespaceDeclaration(prefix, nsURI);
- }
-
- String xmlFragment = DOMWriter.printNode(deElement, false);
- DeserializerSupport des =
(DeserializerSupport)desFactory.getDeserializer();
- Object userEx = des.deserialize(xmlName, xmlType, xmlFragment,
serContext);
- if (userEx == null || (userEx instanceof Exception) == false)
- throw new WSException("Invalid deserialization result: " +
userEx);
-
- faultEx.initCause((Exception)userEx);
- }
- catch (RuntimeException rte)
- {
- throw rte;
- }
- catch (Exception ex)
- {
- log.error("Cannot deserialize fault detail", ex);
- }
- }
- else
- {
- log.debug("Cannot find fault meta data for: " + xmlName);
- }
- }
- }
-
- return faultEx;
- }
-
- /** Translate the request exception into a SOAPFault message.
- */
- public static SOAPMessage exceptionToFaultMessage(Exception reqEx)
- {
- // Get or create the SOAPFaultException
- SOAPFaultException faultEx;
- if (reqEx instanceof SOAPFaultException)
- {
- faultEx = (SOAPFaultException)reqEx;
- }
- else
- {
- QName faultCode = Constants.SOAP11_FAULT_CODE_CLIENT;
- String faultString = (reqEx.getMessage() != null ? reqEx.getMessage() :
reqEx.toString());
- faultEx = new SOAPFaultException(faultCode, faultString, null, null);
- faultEx.initCause(reqEx);
- }
-
- Throwable faultCause = faultEx.getCause();
- log.error("SOAP request exception", faultCause != null ? faultCause :
faultEx);
-
- try
- {
- SOAPMessage faultMessage = toSOAPMessage(faultEx);
- return faultMessage;
- }
- catch (RuntimeException rte)
- {
- throw rte;
- }
- catch (Exception ex)
- {
- log.error("Error creating SOAPFault message", ex);
- throw new JAXRPCException("Cannot create SOAPFault message for: " +
faultEx);
- }
- }
-
- private static SOAPMessage toSOAPMessage(SOAPFaultException faultEx) throws
SOAPException
- {
- assertFaultCode(faultEx.getFaultCode());
-
- CommonMessageContext msgContext = MessageContextAssociation.peekMessageContext();
- SerializationContext serContext = (msgContext != null ?
msgContext.getSerializationContext() : new SerializationContextJAXRPC());
- NamespaceRegistry nsRegistry = serContext.getNamespaceRegistry();
-
- MessageFactory factory = new MessageFactoryImpl();
- SOAPMessage soapMessage = factory.createMessage();
-
- SOAPEnvelopeImpl soapEnvelope =
(SOAPEnvelopeImpl)soapMessage.getSOAPPart().getEnvelope();
- SOAPBody soapBody = soapEnvelope.getBody();
-
- QName faultCode = faultEx.getFaultCode();
- if (faultCode.getNamespaceURI().length() > 0)
- faultCode = nsRegistry.registerQName(faultCode);
-
- String faultString = getValidFaultString(faultEx);
- SOAPFault soapFault = soapBody.addFault(new NameImpl(faultCode), faultString);
-
- String faultActor = faultEx.getFaultActor();
- if (faultActor != null)
- {
- SOAPElement soapElement = soapFault.addChildElement("faultactor");
- soapElement.addTextNode(faultActor);
- }
-
- Exception faultCause = (Exception)faultEx.getCause();
- Detail detail = faultEx.getDetail();
- if (detail != null)
- {
- soapFault.addChildElement(detail);
- }
- else if (faultCause != null && (faultCause instanceof RuntimeException) ==
false)
- {
- Class javaType = faultCause.getClass();
-
- TypeMapping typeMapping = serContext.getTypeMapping();
-
- OperationMetaData opMetaData = msgContext.getOperationMetaData();
- if (opMetaData != null && opMetaData.getFault(javaType) != null)
- {
- FaultMetaData faultMetaData = opMetaData.getFault(javaType);
- QName xmlName = faultMetaData.getXmlName();
- QName xmlType = faultMetaData.getXmlType();
-
- xmlName = nsRegistry.registerQName(xmlName);
-
- // Get the serializer from the type mapping
- SerializerFactoryBase serFactory =
(SerializerFactoryBase)typeMapping.getSerializer(javaType, xmlType);
- if (serFactory == null)
- throw new JAXRPCException("Cannot obtain serializer factory for:
" + xmlType);
-
- try
- {
- SerializerSupport ser = (SerializerSupport)serFactory.getSerializer();
- String xmlFragment = ser.serialize(xmlName, xmlType, faultCause,
serContext, null);
-
- SOAPFactoryImpl soapFactory = new SOAPFactoryImpl();
- Element domElement = DOMUtils.parse(xmlFragment);
- SOAPElement soapElement = soapFactory.createElement(domElement, true);
-
- detail = soapFault.addDetail();
- detail.addChildElement(soapElement);
- }
- catch (BindingException e)
- {
- throw new JAXRPCException(e);
- }
- catch (IOException e)
- {
- throw new JAXRPCException(e);
- }
- }
- else
- {
- log.debug("Cannot obtain fault meta data for: " + javaType);
- }
- }
-
- return soapMessage;
- }
-
- private static String getValidFaultString(SOAPFaultException faultEx)
- {
- String faultString = faultEx.getFaultString();
- if (faultString == null || faultString.length() == 0)
- faultString = "Unqualified " + faultEx.getFaultCode() + "
fault";
-
- return faultString;
- }
-
- private static void assertFaultCode(QName faultCode)
- {
- if (faultCode == null)
- throw new IllegalArgumentException("faultcode cannot be null");
-
- // For lazy folkes like the CTS that don't bother to give
- // a namesapce URI, assume they use a standard code
- String nsURI = faultCode.getNamespaceURI();
- if ("".equals(nsURI))
- {
- log.warn("Empty namespace URI with fault code '" + faultCode +
"', assuming: " + Constants.NS_SOAP11_ENV);
- faultCode = new QName(Constants.NS_SOAP11_ENV, faultCode.getLocalPart());
- }
-
- // WS-I allows non custom faultcodes if you use a non soap namespace
- if (Constants.NS_SOAP11_ENV.equals(nsURI) &&
allowedFaultCodes.contains(faultCode) == false)
- throw new IllegalArgumentException("Illegal faultcode '" +
faultCode + "', allowed values are: " + allowedFaultCodes);
- }
-}
\ No newline at end of file
Copied: trunk/src/main/java/org/jboss/ws/jaxrpc/SOAPFaultHelperJAXRPC.java (from rev 1453,
trunk/src/main/java/org/jboss/ws/jaxrpc/SOAPFaultExceptionHelper.java)
===================================================================
--- trunk/src/main/java/org/jboss/ws/jaxrpc/SOAPFaultExceptionHelper.java 2006-11-16
22:51:43 UTC (rev 1453)
+++ trunk/src/main/java/org/jboss/ws/jaxrpc/SOAPFaultHelperJAXRPC.java 2006-11-17 07:56:40
UTC (rev 1455)
@@ -0,0 +1,317 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+*/
+package org.jboss.ws.jaxrpc;
+
+// $Id$
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.xml.namespace.QName;
+import javax.xml.rpc.JAXRPCException;
+import javax.xml.rpc.encoding.TypeMapping;
+import javax.xml.rpc.soap.SOAPFaultException;
+import javax.xml.soap.Detail;
+import javax.xml.soap.DetailEntry;
+import javax.xml.soap.MessageFactory;
+import javax.xml.soap.Name;
+import javax.xml.soap.SOAPBody;
+import javax.xml.soap.SOAPElement;
+import javax.xml.soap.SOAPException;
+import javax.xml.soap.SOAPFault;
+import javax.xml.soap.SOAPMessage;
+
+import org.jboss.logging.Logger;
+import org.jboss.ws.utils.DOMUtils;
+import org.jboss.ws.utils.DOMWriter;
+import org.jboss.ws.Constants;
+import org.jboss.ws.WSException;
+import org.jboss.ws.binding.BindingException;
+import org.jboss.ws.binding.DeserializerSupport;
+import org.jboss.ws.binding.SerializationContext;
+import org.jboss.ws.binding.SerializerSupport;
+import org.jboss.ws.common.CommonMessageContext;
+import org.jboss.ws.jaxrpc.encoding.DeserializerFactoryBase;
+import org.jboss.ws.jaxrpc.encoding.SerializerFactoryBase;
+import org.jboss.ws.metadata.FaultMetaData;
+import org.jboss.ws.metadata.OperationMetaData;
+import org.jboss.ws.soap.MessageContextAssociation;
+import org.jboss.ws.soap.MessageFactoryImpl;
+import org.jboss.ws.soap.NameImpl;
+import org.jboss.ws.soap.SOAPEnvelopeImpl;
+import org.jboss.ws.soap.SOAPFactoryImpl;
+import org.jboss.xb.binding.NamespaceRegistry;
+import org.w3c.dom.Element;
+
+/**
+ * A Helper that translates between SOAPFaultException and SOAPFault.
+ *
+ * @author Thomas.Diesler(a)jboss.org
+ * @since 03-Feb-2005
+ */
+public class SOAPFaultHelperJAXRPC
+{
+ // provide logging
+ private static Logger log = Logger.getLogger(SOAPFaultHelperJAXRPC.class);
+
+ private static List<QName> allowedFaultCodes = new ArrayList<QName>();
+ static
+ {
+ allowedFaultCodes.add(Constants.SOAP11_FAULT_CODE_CLIENT);
+ allowedFaultCodes.add(Constants.SOAP11_FAULT_CODE_SERVER);
+ allowedFaultCodes.add(Constants.SOAP11_FAULT_CODE_VERSION_MISMATCH);
+ allowedFaultCodes.add(Constants.SOAP11_FAULT_CODE_MUST_UNDERSTAND);
+ }
+
+ /** Hide constructor */
+ private SOAPFaultHelperJAXRPC()
+ {
+ }
+
+ /** Factory method for FaultException for a given SOAPFault */
+ public static SOAPFaultException getSOAPFaultException(SOAPFault soapFault)
+ {
+ QName faultCode = ((NameImpl)soapFault.getFaultCodeAsName()).toQName();
+ String faultString = soapFault.getFaultString();
+ String faultActor = soapFault.getFaultActor();
+ Detail detail = soapFault.getDetail();
+
+ SOAPFaultException faultEx = new SOAPFaultException(faultCode, faultString,
faultActor, detail);
+
+ CommonMessageContext msgContext = MessageContextAssociation.peekMessageContext();
+ if (detail != null && msgContext != null)
+ {
+ SerializationContext serContext = msgContext.getSerializationContext();
+ TypeMapping typeMapping = serContext.getTypeMapping();
+
+ Iterator it = detail.getDetailEntries();
+ while (it.hasNext())
+ {
+ DetailEntry deElement = (DetailEntry)it.next();
+ Name deName = deElement.getElementName();
+ QName xmlName = new QName(deName.getURI(), deName.getLocalName());
+
+ OperationMetaData opMetaData = msgContext.getOperationMetaData();
+ FaultMetaData faultMetaData = opMetaData.getFault(xmlName);
+ if (faultMetaData != null)
+ {
+ log.debug("Deserialize fault: " + faultMetaData);
+ QName xmlType = faultMetaData.getXmlType();
+ Class javaType = faultMetaData.getJavaType();
+
+ // Get the deserializer from the type mapping
+ DeserializerFactoryBase desFactory =
(DeserializerFactoryBase)typeMapping.getDeserializer(javaType, xmlType);
+ if (desFactory == null)
+ throw new JAXRPCException("Cannot obtain deserializer factory for:
" + xmlType);
+
+ // Try jaxb deserialization
+ try
+ {
+ //
http://jira.jboss.org/jira/browse/JBWS-955
+ // Cannot deserialize fault detail
+ String prefix = deName.getPrefix();
+ if (prefix.length() > 0)
+ {
+ String nsURI = deName.getURI();
+ String attrValue = deElement.getAttribute("xmlns:" +
prefix);
+ if (nsURI.length() > 0 && attrValue.length() == 0)
+ deElement.addNamespaceDeclaration(prefix, nsURI);
+ }
+
+ String xmlFragment = DOMWriter.printNode(deElement, false);
+ DeserializerSupport des =
(DeserializerSupport)desFactory.getDeserializer();
+ Object userEx = des.deserialize(xmlName, xmlType, xmlFragment,
serContext);
+ if (userEx == null || (userEx instanceof Exception) == false)
+ throw new WSException("Invalid deserialization result: " +
userEx);
+
+ faultEx.initCause((Exception)userEx);
+ }
+ catch (RuntimeException rte)
+ {
+ throw rte;
+ }
+ catch (Exception ex)
+ {
+ log.error("Cannot deserialize fault detail", ex);
+ }
+ }
+ else
+ {
+ log.debug("Cannot find fault meta data for: " + xmlName);
+ }
+ }
+ }
+
+ return faultEx;
+ }
+
+ /** Translate the request exception into a SOAPFault message.
+ */
+ public static SOAPMessage exceptionToFaultMessage(Exception reqEx)
+ {
+ // Get or create the SOAPFaultException
+ SOAPFaultException faultEx;
+ if (reqEx instanceof SOAPFaultException)
+ {
+ faultEx = (SOAPFaultException)reqEx;
+ }
+ else
+ {
+ QName faultCode = Constants.SOAP11_FAULT_CODE_CLIENT;
+ String faultString = (reqEx.getMessage() != null ? reqEx.getMessage() :
reqEx.toString());
+ faultEx = new SOAPFaultException(faultCode, faultString, null, null);
+ faultEx.initCause(reqEx);
+ }
+
+ Throwable faultCause = faultEx.getCause();
+ log.error("SOAP request exception", faultCause != null ? faultCause :
faultEx);
+
+ try
+ {
+ SOAPMessage faultMessage = toSOAPMessage(faultEx);
+ return faultMessage;
+ }
+ catch (RuntimeException rte)
+ {
+ throw rte;
+ }
+ catch (Exception ex)
+ {
+ log.error("Error creating SOAPFault message", ex);
+ throw new JAXRPCException("Cannot create SOAPFault message for: " +
faultEx);
+ }
+ }
+
+ private static SOAPMessage toSOAPMessage(SOAPFaultException faultEx) throws
SOAPException
+ {
+ assertFaultCode(faultEx.getFaultCode());
+
+ CommonMessageContext msgContext = MessageContextAssociation.peekMessageContext();
+ SerializationContext serContext = (msgContext != null ?
msgContext.getSerializationContext() : new SerializationContextJAXRPC());
+ NamespaceRegistry nsRegistry = serContext.getNamespaceRegistry();
+
+ MessageFactory factory = new MessageFactoryImpl();
+ SOAPMessage soapMessage = factory.createMessage();
+
+ SOAPEnvelopeImpl soapEnvelope =
(SOAPEnvelopeImpl)soapMessage.getSOAPPart().getEnvelope();
+ SOAPBody soapBody = soapEnvelope.getBody();
+
+ QName faultCode = faultEx.getFaultCode();
+ if (faultCode.getNamespaceURI().length() > 0)
+ faultCode = nsRegistry.registerQName(faultCode);
+
+ String faultString = getValidFaultString(faultEx);
+ SOAPFault soapFault = soapBody.addFault(new NameImpl(faultCode), faultString);
+
+ String faultActor = faultEx.getFaultActor();
+ if (faultActor != null)
+ {
+ SOAPElement soapElement = soapFault.addChildElement("faultactor");
+ soapElement.addTextNode(faultActor);
+ }
+
+ Exception faultCause = (Exception)faultEx.getCause();
+ Detail detail = faultEx.getDetail();
+ if (detail != null)
+ {
+ soapFault.addChildElement(detail);
+ }
+ else if (faultCause != null && (faultCause instanceof RuntimeException) ==
false)
+ {
+ Class javaType = faultCause.getClass();
+
+ TypeMapping typeMapping = serContext.getTypeMapping();
+
+ OperationMetaData opMetaData = msgContext.getOperationMetaData();
+ if (opMetaData != null && opMetaData.getFault(javaType) != null)
+ {
+ FaultMetaData faultMetaData = opMetaData.getFault(javaType);
+ QName xmlName = faultMetaData.getXmlName();
+ QName xmlType = faultMetaData.getXmlType();
+
+ xmlName = nsRegistry.registerQName(xmlName);
+
+ // Get the serializer from the type mapping
+ SerializerFactoryBase serFactory =
(SerializerFactoryBase)typeMapping.getSerializer(javaType, xmlType);
+ if (serFactory == null)
+ throw new JAXRPCException("Cannot obtain serializer factory for:
" + xmlType);
+
+ try
+ {
+ SerializerSupport ser = (SerializerSupport)serFactory.getSerializer();
+ String xmlFragment = ser.serialize(xmlName, xmlType, faultCause,
serContext, null);
+
+ SOAPFactoryImpl soapFactory = new SOAPFactoryImpl();
+ Element domElement = DOMUtils.parse(xmlFragment);
+ SOAPElement soapElement = soapFactory.createElement(domElement, true);
+
+ detail = soapFault.addDetail();
+ detail.addChildElement(soapElement);
+ }
+ catch (BindingException e)
+ {
+ throw new JAXRPCException(e);
+ }
+ catch (IOException e)
+ {
+ throw new JAXRPCException(e);
+ }
+ }
+ else
+ {
+ log.debug("Cannot obtain fault meta data for: " + javaType);
+ }
+ }
+
+ return soapMessage;
+ }
+
+ private static String getValidFaultString(SOAPFaultException faultEx)
+ {
+ String faultString = faultEx.getFaultString();
+ if (faultString == null || faultString.length() == 0)
+ faultString = "Unqualified " + faultEx.getFaultCode() + "
fault";
+
+ return faultString;
+ }
+
+ private static void assertFaultCode(QName faultCode)
+ {
+ if (faultCode == null)
+ throw new IllegalArgumentException("faultcode cannot be null");
+
+ // For lazy folkes like the CTS that don't bother to give
+ // a namesapce URI, assume they use a standard code
+ String nsURI = faultCode.getNamespaceURI();
+ if ("".equals(nsURI))
+ {
+ log.warn("Empty namespace URI with fault code '" + faultCode +
"', assuming: " + Constants.NS_SOAP11_ENV);
+ faultCode = new QName(Constants.NS_SOAP11_ENV, faultCode.getLocalPart());
+ }
+
+ // WS-I allows non custom faultcodes if you use a non soap namespace
+ if (Constants.NS_SOAP11_ENV.equals(nsURI) &&
allowedFaultCodes.contains(faultCode) == false)
+ throw new IllegalArgumentException("Illegal faultcode '" +
faultCode + "', allowed values are: " + allowedFaultCodes);
+ }
+}
\ No newline at end of file
Modified: trunk/src/main/java/org/jboss/ws/jaxws/client/ClientImpl.java
===================================================================
--- trunk/src/main/java/org/jboss/ws/jaxws/client/ClientImpl.java 2006-11-17 02:06:33 UTC
(rev 1454)
+++ trunk/src/main/java/org/jboss/ws/jaxws/client/ClientImpl.java 2006-11-17 07:56:40 UTC
(rev 1455)
@@ -53,7 +53,6 @@
import org.jboss.ws.metadata.OperationMetaData;
import org.jboss.ws.metadata.HandlerMetaData.HandlerType;
import org.jboss.ws.soap.MessageContextAssociation;
-import org.jboss.ws.soap.SOAPFaultImpl;
/**
* Provides support for the dynamic invocation of a service endpoint.
@@ -177,7 +176,7 @@
}
/**
- * 4.13 Conformance (Remote Exceptions): If an error occurs during a remote operation
invocation, an implemention
+ * 4.2.4 Conformance (Remote Exceptions): If an error occurs during a remote
operation invocation, an implemention
* MUST throw a service specific exception if possible. If the error cannot be mapped
to a service
* specific exception, an implementation MUST throw a ProtocolException or one of its
subclasses, as
* appropriate for the binding in use. See section 6.4.1 for more details.
@@ -187,7 +186,14 @@
String bindingId = opMetaData.getEndpointMetaData().getBindingId();
if (SOAPBinding.SOAP11HTTP_BINDING.equals(bindingId) ||
SOAPBinding.SOAP12HTTP_BINDING.equals(bindingId))
{
- throw new SOAPFaultException(ex);
+ if (ex instanceof SOAPFaultException)
+ {
+ throw (SOAPFaultException)ex;
+ }
+ else
+ {
+ throw new SOAPFaultException(ex);
+ }
}
else if (HTTPBinding.HTTP_BINDING.equals(bindingId))
{
Modified: trunk/src/main/java/org/jboss/ws/jaxws/client/ClientProxy.java
===================================================================
--- trunk/src/main/java/org/jboss/ws/jaxws/client/ClientProxy.java 2006-11-17 02:06:33 UTC
(rev 1454)
+++ trunk/src/main/java/org/jboss/ws/jaxws/client/ClientProxy.java 2006-11-17 07:56:40 UTC
(rev 1455)
@@ -35,6 +35,7 @@
import javax.xml.ws.BindingProvider;
import javax.xml.ws.Response;
import javax.xml.ws.WebServiceException;
+import javax.xml.ws.soap.SOAPFaultException;
import org.jboss.logging.Logger;
import org.jboss.ws.WSException;
@@ -183,9 +184,24 @@
return response;
}
+ /**
+ * 4.2.4 Conformance (Remote Exceptions): If an error occurs during a remote
operation invocation, an implemention
+ * MUST throw a service specific exception if possible. If the error cannot be mapped
to a service
+ * specific exception, an implementation MUST throw a ProtocolException or one of its
subclasses, as
+ * appropriate for the binding in use. See section 6.4.1 for more details.
+ */
private void handleException(Exception ex) throws Throwable
{
Throwable th = ex;
+ if (ex instanceof SOAPFaultException)
+ {
+ // The cause of a SOAPFaultException, if any, is the service specific exception
+ Throwable cause = ex.getCause();
+ if (cause != null)
+ {
+ th = cause;
+ }
+ }
throw th;
}
Modified: trunk/src/main/java/org/jboss/ws/jaxws/core/SOAP11BindingJAXWS.java
===================================================================
--- trunk/src/main/java/org/jboss/ws/jaxws/core/SOAP11BindingJAXWS.java 2006-11-17
02:06:33 UTC (rev 1454)
+++ trunk/src/main/java/org/jboss/ws/jaxws/core/SOAP11BindingJAXWS.java 2006-11-17
07:56:40 UTC (rev 1455)
@@ -31,7 +31,6 @@
import javax.xml.soap.SOAPMessage;
import javax.xml.ws.handler.Handler;
import javax.xml.ws.soap.SOAPBinding;
-import javax.xml.ws.soap.SOAPFaultException;
import org.jboss.ws.Constants;
import org.jboss.ws.common.CommonSOAP11Binding;
@@ -92,6 +91,12 @@
@Override
protected void throwFaultException(SOAPFaultImpl fault) throws Exception
{
- throw new SOAPFaultException(fault);
+ throw SOAPFaultHelperJAXWS.getSOAPFaultException(fault);
}
+
+ @Override
+ public SOAPMessage exceptionToFaultMessage(Exception ex)
+ {
+ return SOAPFaultHelperJAXWS.exceptionToFaultMessage(ex);
+ }
}
Modified: trunk/src/main/java/org/jboss/ws/jaxws/core/SOAP12BindingJAXWS.java
===================================================================
--- trunk/src/main/java/org/jboss/ws/jaxws/core/SOAP12BindingJAXWS.java 2006-11-17
02:06:33 UTC (rev 1454)
+++ trunk/src/main/java/org/jboss/ws/jaxws/core/SOAP12BindingJAXWS.java 2006-11-17
07:56:40 UTC (rev 1455)
@@ -32,7 +32,6 @@
import javax.xml.ws.WebServiceException;
import javax.xml.ws.handler.Handler;
import javax.xml.ws.soap.SOAPBinding;
-import javax.xml.ws.soap.SOAPFaultException;
import org.jboss.ws.Constants;
import org.jboss.ws.common.CommonSOAP12Binding;
@@ -100,6 +99,12 @@
@Override
protected void throwFaultException(SOAPFaultImpl fault) throws Exception
{
- throw new SOAPFaultException(fault);
+ throw SOAPFaultHelperJAXWS.getSOAPFaultException(fault);
}
+
+ @Override
+ public SOAPMessage exceptionToFaultMessage(Exception ex)
+ {
+ return SOAPFaultHelperJAXWS.exceptionToFaultMessage(ex);
+ }
}
Added: trunk/src/main/java/org/jboss/ws/jaxws/core/SOAPFaultHelperJAXWS.java
===================================================================
--- trunk/src/main/java/org/jboss/ws/jaxws/core/SOAPFaultHelperJAXWS.java 2006-11-17
02:06:33 UTC (rev 1454)
+++ trunk/src/main/java/org/jboss/ws/jaxws/core/SOAPFaultHelperJAXWS.java 2006-11-17
07:56:40 UTC (rev 1455)
@@ -0,0 +1,503 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the JBPM BPEL PUBLIC LICENSE AGREEMENT as
+ * published by JBoss Inc.; either version 1.0 of the License, or
+ * (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ */
+package org.jboss.ws.jaxws.core;
+
+import java.io.IOException;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Iterator;
+
+import javax.xml.bind.annotation.XmlType;
+import javax.xml.namespace.QName;
+import javax.xml.rpc.encoding.TypeMapping;
+import javax.xml.soap.Detail;
+import javax.xml.soap.DetailEntry;
+import javax.xml.soap.MessageFactory;
+import javax.xml.soap.Name;
+import javax.xml.soap.SOAPBody;
+import javax.xml.soap.SOAPElement;
+import javax.xml.soap.SOAPException;
+import javax.xml.soap.SOAPFault;
+import javax.xml.soap.SOAPMessage;
+import javax.xml.ws.WebServiceException;
+import javax.xml.ws.soap.SOAPFaultException;
+
+import org.jboss.logging.Logger;
+import org.jboss.ws.Constants;
+import org.jboss.ws.binding.BindingException;
+import org.jboss.ws.binding.DeserializerSupport;
+import org.jboss.ws.binding.SerializationContext;
+import org.jboss.ws.binding.SerializerSupport;
+import org.jboss.ws.common.CommonMessageContext;
+import org.jboss.ws.jaxrpc.SOAPFaultHelperJAXRPC;
+import org.jboss.ws.jaxrpc.encoding.DeserializerFactoryBase;
+import org.jboss.ws.jaxrpc.encoding.SerializerFactoryBase;
+import org.jboss.ws.metadata.FaultMetaData;
+import org.jboss.ws.metadata.OperationMetaData;
+import org.jboss.ws.soap.MessageContextAssociation;
+import org.jboss.ws.soap.NameImpl;
+import org.jboss.ws.soap.SOAPFactoryImpl;
+import org.jboss.ws.utils.DOMUtils;
+import org.jboss.ws.utils.DOMWriter;
+import org.w3c.dom.Element;
+
+/**
+ * @author <a href="mailto:alex.guizar@jboss.com">Alejandro
Guizar</a>
+ * @version $Revision$
+ */
+public class SOAPFaultHelperJAXWS
+{
+ // provide logging
+ private static Logger log = Logger.getLogger(SOAPFaultHelperJAXWS.class);
+
+ private static final Collection<String> excludedGetters = Arrays.asList(new
String[] { "getCause", "getLocalizedMessage",
"getStackTrace", "getClass" });
+
+ /** Factory method for FaultException for a given SOAPFault */
+ public static SOAPFaultException getSOAPFaultException(SOAPFault soapFault)
+ {
+ SOAPFaultException faultEx = new SOAPFaultException(soapFault);
+ Detail detail = soapFault.getDetail();
+
+ CommonMessageContext msgContext = MessageContextAssociation.peekMessageContext();
+ if (detail != null && msgContext != null)
+ {
+ SerializationContext serContext = msgContext.getSerializationContext();
+ TypeMapping typeMapping = serContext.getTypeMapping();
+
+ Iterator it = detail.getDetailEntries();
+ while (it.hasNext())
+ {
+ DetailEntry deElement = (DetailEntry)it.next();
+ QName xmlName = new QName(deElement.getNamespaceURI(),
deElement.getLocalName());
+
+ OperationMetaData opMetaData = msgContext.getOperationMetaData();
+ FaultMetaData faultMetaData = opMetaData.getFault(xmlName);
+ if (faultMetaData != null)
+ {
+ log.debug("Deserialize fault: " + faultMetaData);
+ QName xmlType = faultMetaData.getXmlType();
+ Class<?> faultBeanClass = faultMetaData.getFaultBean();
+
+ // Get the deserializer from the type mapping
+ DeserializerFactoryBase desFactory =
(DeserializerFactoryBase)typeMapping.getDeserializer(faultBeanClass, xmlType);
+ if (desFactory == null)
+ throw new WebServiceException("Cannot obtain deserializer factory:
xmlType=" + xmlType + ", javaType=" + faultBeanClass);
+
+ //
http://jira.jboss.org/jira/browse/JBWS-955
+ // Cannot deserialize fault detail
+ String prefix = deElement.getPrefix();
+ if (prefix.length() > 0)
+ {
+ String nsURI = deElement.getNamespaceURI();
+ String attrValue = deElement.getAttribute("xmlns:" +
prefix);
+ if (nsURI.length() > 0 && attrValue.length() == 0)
+ {
+ try
+ {
+ deElement.addNamespaceDeclaration(prefix, nsURI);
+ }
+ catch (SOAPException e)
+ {
+ log.warn("Declaration of detail entry namespace
failed", e);
+ }
+ }
+ }
+
+ // Try jaxb deserialization
+ try
+ {
+ String xmlFragment = DOMWriter.printNode(deElement, false);
+ DeserializerSupport des =
(DeserializerSupport)desFactory.getDeserializer();
+ Object faultBean = des.deserialize(xmlName, xmlType, xmlFragment,
serContext);
+
+ /* JAX-WS 2.5: A wsdl:fault element refers to a wsdl:message that
contains
+ * a single part. The global element declaration referred to by that
part
+ * is mapped to a Java bean. A wrapper exception class contains the
+ * following methods:
+ * - WrapperException(String message, FaultBean faultInfo)
+ * - WrapperException(String message, FaultBean faultInfo, Throwable
cause)
+ * - FaultBean getFaultInfo() */
+ Class<?> serviceExGenericClass = faultMetaData.getJavaType();
+ Class<? extends Exception> serviceExClass =
serviceExGenericClass.asSubclass(Exception.class);
+
+ Exception serviceEx;
+ try
+ {
+ Constructor<? extends Exception> serviceExCtor =
serviceExClass.getConstructor(String.class, faultBeanClass);
+ serviceEx = serviceExCtor.newInstance(soapFault.getFaultString(),
faultBean);
+ }
+ catch (NoSuchMethodException e)
+ {
+ serviceEx = toServiceException(faultBean, serviceExClass);
+ }
+ catch (InstantiationException e)
+ {
+ throw new WebServiceException("Service specific exception class
is not instantiable", e);
+ }
+
+ faultEx.initCause(serviceEx);
+ }
+ catch (BindingException e)
+ {
+ throw new WebServiceException(e);
+ }
+ catch (IllegalAccessException e)
+ {
+ throw new WebServiceException(e);
+ }
+ catch (InvocationTargetException e)
+ {
+ throw new WebServiceException(e.getTargetException());
+ }
+ }
+ else
+ {
+ log.debug("Cannot find fault meta data for: " + xmlName);
+ }
+ }
+ }
+
+ return faultEx;
+ }
+
+ private static Exception toServiceException(Object faultBean, Class<? extends
Exception> serviceExClass) throws IllegalAccessException, InvocationTargetException
+ {
+ Class<?> faultBeanClass = faultBean.getClass();
+ XmlType xmlType = faultBeanClass.getAnnotation(XmlType.class);
+
+ if (xmlType == null)
+ throw new WebServiceException("@XmlType annotation missing from fault bean
class: " + faultBeanClass.getName());
+
+ String[] propertyNames = xmlType.propOrder();
+ Class<?>[] propertyTypes = new Class<?>[propertyNames.length];
+ Object[] propertyValues = new Object[propertyNames.length];
+
+ for (int i = 0; i < propertyNames.length; i++)
+ {
+ String propertyName = propertyNames[i];
+ propertyName = Character.toUpperCase(propertyName.charAt(0)) +
propertyName.substring(1);
+
+ Method propertyGetter;
+ try
+ {
+ propertyGetter = faultBeanClass.getMethod("get" + propertyName);
+ }
+ catch (NoSuchMethodException e)
+ {
+ try
+ {
+ propertyGetter = faultBeanClass.getMethod("is" + propertyName);
+ }
+ catch (NoSuchMethodException ee)
+ {
+ throw new WebServiceException("Fault bean has no getter for property:
" + propertyName, ee);
+ }
+ }
+ propertyValues[i] = propertyGetter.invoke(faultBean);
+ propertyTypes[i] = propertyGetter.getReturnType();
+ }
+
+ try
+ {
+ Constructor<? extends Exception> serviceExCtor =
serviceExClass.getConstructor(propertyTypes);
+ return serviceExCtor.newInstance(propertyValues);
+ }
+ catch (NoSuchMethodException e)
+ {
+ throw new WebServiceException("Service exception has no constructor for
parameter types: " + Arrays.toString(propertyTypes));
+ }
+ catch (InstantiationException e)
+ {
+ throw new WebServiceException("Service exception is not instantiable",
e);
+ }
+ }
+
+ /** Translate the request exception into a SOAPFault message. */
+ public static SOAPMessage exceptionToFaultMessage(Exception reqEx)
+ {
+ log.error("SOAP request exception", reqEx);
+
+ try
+ {
+ SOAPMessage faultMessage;
+ if (reqEx instanceof SOAPFaultException)
+ {
+ faultMessage = toSOAPMessage((SOAPFaultException)reqEx);
+ }
+ else if (reqEx instanceof javax.xml.rpc.soap.SOAPFaultException)
+ {
+ /* this exception should not occur in JAX-WS endpoints, but JBossWS
+ * throws it to signal internal error conditions */
+ faultMessage = SOAPFaultHelperJAXRPC.exceptionToFaultMessage(reqEx);
+ }
+ else
+ {
+ faultMessage = toSOAPMessage(reqEx);
+ }
+
+ return faultMessage;
+ }
+ catch (SOAPException ex)
+ {
+ log.error("Error creating SOAPFault message", ex);
+ throw new WebServiceException("Cannot create SOAPFault message for: "
+ reqEx);
+ }
+ }
+
+ private static SOAPMessage toSOAPMessage(SOAPFaultException faultEx) throws
SOAPException
+ {
+ MessageFactory factory = MessageFactory.newInstance();
+ SOAPMessage soapMessage = factory.createMessage();
+
+ SOAPBody soapBody = soapMessage.getSOAPBody();
+ populateSOAPFault(soapBody, faultEx);
+
+ /* detail
+ * X. Serialized service specific exception
+ * 2. SOAPFaultException.getFault().getDetail() */
+ Detail detail = faultEx.getFault().getDetail();
+ if (detail != null)
+ soapBody.getFault().addChildElement(detail);
+
+ return soapMessage;
+ }
+
+ private static void populateSOAPFault(SOAPBody soapBody, SOAPFaultException faultEx)
throws SOAPException
+ {
+ SOAPFault sourceFault = faultEx.getFault();
+
+ /* JAX-WS 10.2.2.3: the fields of the fault message are populated according to the
+ * following rules of precedence: */
+
+ /* faultcode
+ * 1. SOAPFaultException.getFault().getFaultCodeAsQName()
+ * X. env:Server (Subcode omitted for SOAP 1.2) */
+ Name faultCode = sourceFault.getFaultCodeAsName();
+ if (faultCode != null)
+ {
+ faultCode = new NameImpl(faultCode.getLocalName(), "codeNS",
faultCode.getURI());
+ }
+ else
+ {
+ faultCode = getFallbackFaultCode();
+ }
+
+ /* faultstring
+ * 1. SOAPFaultException.getFault().getFaultString()
+ * X. Exception.getMessage()
+ * X. Exception.toString() */
+ String faultString = sourceFault.getFaultString();
+ if (faultString == null)
+ faultString = getFallbackFaultString(faultEx);
+
+ SOAPFault targetFault = soapBody.addFault(faultCode, faultString);
+
+ /* faultactor
+ * 1. SOAPFaultException.getFault().getFaultActor()
+ * 2. Empty */
+ String faultActor = sourceFault.getFaultActor();
+ if (faultActor != null)
+ targetFault.setFaultActor(faultActor);
+ }
+
+ private static SOAPMessage toSOAPMessage(Exception ex) throws SOAPException
+ {
+ MessageFactory factory = MessageFactory.newInstance();
+ SOAPMessage soapMessage = factory.createMessage();
+
+ SOAPBody soapBody = soapMessage.getSOAPBody();
+ SOAPFault soapFault;
+
+ /* JAX-WS 6.4.1: When an implementation catches an exception thrown by a
+ * service endpoint implementation and the cause of that exception is an
+ * instance of the appropriate ProtocolException subclass for the protocol
+ * in use, an implementation MUST reflect the information contained in the
+ * ProtocolException subclass within the generated protocol level fault. */
+ Throwable cause = ex.getCause();
+ if (cause instanceof SOAPFaultException)
+ {
+ populateSOAPFault(soapBody, (SOAPFaultException)cause);
+ soapFault = soapBody.getFault();
+ }
+ else
+ {
+ soapFault = soapBody.addFault(getFallbackFaultCode(),
getFallbackFaultString(ex));
+ }
+
+ CommonMessageContext msgContext = MessageContextAssociation.peekMessageContext();
+ SerializationContext serContext = msgContext.getSerializationContext();
+
+ NameImpl faultCode = (NameImpl)soapFault.getFaultCodeAsName();
+ if (faultCode.getURI().length() > 0)
+ serContext.getNamespaceRegistry().registerQName(faultCode.toQName());
+
+ OperationMetaData opMetaData = msgContext.getOperationMetaData();
+ Class<? extends Exception> exClass = ex.getClass();
+ if (opMetaData != null && opMetaData.getFault(exClass) != null)
+ {
+ FaultMetaData faultMetaData = opMetaData.getFault(exClass);
+ Class faultBeanClass = faultMetaData.getFaultBean();
+ Object faultBean;
+ try
+ {
+ try
+ {
+ /* JAX-WS 3.7: For exceptions that match the pattern described in section
+ * 2.5 (i.e. exceptions that have a getFaultInfo method), the FaultBean
+ * is used as input to JAXB */
+ Method getFaultInfo = exClass.getMethod("getFaultInfo");
+ faultBean = getFaultInfo.invoke(ex);
+ }
+ catch (NoSuchMethodException e)
+ {
+ /* JAX-WS 3.7: For exceptions that do not match the pattern described in
+ * section 2.5, JAX-WS maps those exceptions to Java beans and then uses
+ * those Java beans as input to the JAXB mapping. */
+ faultBean = toFaultBean(ex, faultBeanClass);
+ }
+ }
+ catch (IllegalAccessException e)
+ {
+ throw new WebServiceException(e);
+ }
+ catch (InvocationTargetException e)
+ {
+ throw new WebServiceException(e.getTargetException());
+ }
+
+ Detail detail = soapFault.addDetail();
+ SOAPElement detailEntry = toDetailEntry(faultBean, serContext, faultMetaData);
+ detail.addChildElement(detailEntry);
+ }
+ else
+ {
+ log.debug("Cannot obtain fault meta data for: " + exClass);
+ }
+
+ return soapMessage;
+ }
+
+ private static Name getFallbackFaultCode()
+ {
+ /* faultcode
+ * X. SOAPFaultException.getFault().getFaultCodeAsQName()
+ * 2. env:Server (Subcode omitted for SOAP 1.2) */
+ return new NameImpl(Constants.SOAP11_FAULT_CODE_SERVER);
+ }
+
+ private static String getFallbackFaultString(Exception ex)
+ {
+ /* faultstring
+ * X. SOAPFaultException.getFault().getFaultString()
+ * 2. Exception.getMessage()
+ * 3. Exception.toString() */
+ String faultString = ex.getMessage();
+
+ if (faultString == null)
+ faultString = ex.toString();
+
+ return faultString;
+ }
+
+ private static Object toFaultBean(Exception userEx, Class faultBeanClass) throws
IllegalAccessException, InvocationTargetException
+ {
+ Object faultBean;
+ try
+ {
+ faultBean = faultBeanClass.newInstance();
+ }
+ catch (InstantiationException e)
+ {
+ throw new WebServiceException("Fault bean class is not instantiable",
e);
+ }
+
+ /* For each getter in the exception and its superclasses, a property of
+ * the same type and name is added to the bean. The getCause, getLocalizedMessage
+ * and getStackTrace getters from java.lang.Throwable and the getClass getter
+ * from java.lang.Object are excluded from the list of getters to be mapped. */
+ for (Method exMethod : userEx.getClass().getMethods())
+ {
+ if (exMethod.getParameterTypes().length > 0)
+ continue;
+
+ String exMethodName = exMethod.getName();
+
+ if (excludedGetters.contains(exMethodName))
+ continue;
+
+ String propertyName;
+ if (exMethodName.startsWith("get"))
+ {
+ propertyName = exMethodName.substring(3);
+ }
+ else if (exMethodName.startsWith("is"))
+ {
+ propertyName = exMethodName.substring(2);
+ }
+ else continue;
+
+ // get the property value from the exception
+ Object propertyValue = exMethod.invoke(userEx);
+ Class propertyClass = exMethod.getReturnType();
+
+ try
+ {
+ // set the value to the bean
+ Method beanSetter = faultBeanClass.getMethod("set" + propertyName,
propertyClass);
+ beanSetter.invoke(faultBean, propertyValue);
+ }
+ catch (NoSuchMethodException e)
+ {
+ throw new WebServiceException("Fault bean has no setter for property:
" + propertyName, e);
+ }
+ }
+
+ return faultBean;
+ }
+
+ private static SOAPElement toDetailEntry(Object faultObject, SerializationContext
serContext, FaultMetaData faultMetaData) throws SOAPException
+ {
+ QName xmlName = faultMetaData.getXmlName();
+ xmlName = serContext.getNamespaceRegistry().registerQName(xmlName);
+
+ // Get the serializer from the type mapping
+ QName xmlType = faultMetaData.getXmlType();
+ Class javaType = faultMetaData.getFaultBean() != null ?
faultMetaData.getFaultBean() : faultMetaData.getJavaType();
+ SerializerFactoryBase serFactory =
(SerializerFactoryBase)serContext.getTypeMapping().getSerializer(javaType, xmlType);
+ if (serFactory == null)
+ throw new WebServiceException("Cannot obtain serializer factory:
xmlType=" + xmlType + ", javaType=" + javaType);
+
+ try
+ {
+ SerializerSupport ser = serFactory.getSerializer();
+ String xmlFragment = ser.serialize(xmlName, xmlType, faultObject, serContext,
null);
+
+ SOAPFactoryImpl soapFactory = new SOAPFactoryImpl();
+ Element domElement = DOMUtils.parse(xmlFragment);
+ return soapFactory.createElement(domElement, true);
+ }
+ catch (BindingException e)
+ {
+ throw new WebServiceException(e);
+ }
+ catch (IOException e)
+ {
+ throw new WebServiceException(e);
+ }
+ }
+}
Property changes on:
trunk/src/main/java/org/jboss/ws/jaxws/core/SOAPFaultHelperJAXWS.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Modified: trunk/src/main/java/org/jboss/ws/metadata/FaultMetaData.java
===================================================================
--- trunk/src/main/java/org/jboss/ws/metadata/FaultMetaData.java 2006-11-17 02:06:33 UTC
(rev 1454)
+++ trunk/src/main/java/org/jboss/ws/metadata/FaultMetaData.java 2006-11-17 07:56:40 UTC
(rev 1455)
@@ -1,24 +1,24 @@
/*
-* JBoss, Home of Professional Open Source
-* Copyright 2005, JBoss Inc., and individual contributors as indicated
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* This is free software; you can redistribute it and/or modify it
-* under the terms of the GNU Lesser General Public License as
-* published by the Free Software Foundation; either version 2.1 of
-* the License, or (at your option) any later version.
-*
-* This software is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public
-* License along with this software; if not, write to the Free
-* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-* 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
-*/
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
package org.jboss.ws.metadata;
// $Id$
@@ -26,7 +26,6 @@
import javax.xml.namespace.QName;
import org.jboss.ws.WSException;
-import org.jboss.ws.jaxrpc.ParameterWrapping;
import org.jboss.ws.jaxws.DynamicWrapperGenerator;
import org.jboss.ws.utils.JavaUtils;
@@ -97,12 +96,12 @@
public Class getJavaType()
{
- ClassLoader loader = getClassLoader();
-
if (javaTypeName == null)
return null;
- if (javaType == null || ((!javaType.isPrimitive()) &&
javaType.getClassLoader() != loader))
+ ClassLoader loader = getClassLoader();
+
+ if (javaType == null || (!javaType.isPrimitive() &&
javaType.getClassLoader() != loader))
{
try
{
@@ -119,15 +118,20 @@
public Class getFaultBean()
{
- if (faultBean == null && faultBeanName != null)
+ if (faultBeanName == null)
+ return null;
+
+ ClassLoader loader = getClassLoader();
+
+ if (faultBean == null || (!faultBean.isPrimitive() &&
faultBean.getClassLoader() != loader))
{
try
{
- faultBean = JavaUtils.loadJavaType(faultBeanName, getClassLoader());
+ faultBean = JavaUtils.loadJavaType(faultBeanName, loader);
}
catch (ClassNotFoundException ex)
{
- throw new WSException("Cannot load java type: " + javaTypeName,
ex);
+ throw new WSException("Cannot load fault bean: " + faultBeanName,
ex);
}
}
@@ -167,7 +171,7 @@
buffer.append("\n xmlName=" + xmlName);
buffer.append("\n xmlType=" + xmlType);
buffer.append("\n javaType=" + javaTypeName);
- buffer.append("\n faultbean=" + faultBeanName);
+ buffer.append("\n faultBean=" + faultBeanName);
return buffer.toString();
}
}
\ No newline at end of file
Modified: trunk/src/main/java/org/jboss/ws/server/AbstractServiceEndpointInvoker.java
===================================================================
--- trunk/src/main/java/org/jboss/ws/server/AbstractServiceEndpointInvoker.java 2006-11-17
02:06:33 UTC (rev 1454)
+++ trunk/src/main/java/org/jboss/ws/server/AbstractServiceEndpointInvoker.java 2006-11-17
07:56:40 UTC (rev 1455)
@@ -25,6 +25,7 @@
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
+import java.lang.reflect.UndeclaredThrowableException;
import javax.management.MBeanException;
import javax.xml.namespace.QName;
@@ -45,7 +46,7 @@
import org.jboss.ws.common.CommonBinding;
import org.jboss.ws.common.CommonBindingProvider;
import org.jboss.ws.common.CommonMessageContext;
-import org.jboss.ws.jaxrpc.SOAPFaultExceptionHelper;
+import org.jboss.ws.common.CommonSOAPBinding;
import org.jboss.ws.jaxrpc.handler.HandlerDelegateJAXRPC;
import org.jboss.ws.jaxws.core.BindingProviderImpl;
import org.jboss.ws.jaxws.handler.HandlerDelegateJAXWS;
@@ -97,7 +98,7 @@
InstantiationException;
/** Invoke the instance of the SEI implementation bean */
- protected abstract void invokeServiceEndpoint(ServiceEndpointInfo seInfo, Object
seiImpl, EndpointInvocation epInv);
+ protected abstract void invokeServiceEndpoint(ServiceEndpointInfo seInfo, Object
seiImpl, EndpointInvocation epInv) throws Exception;
/** Destroy the instance of the SEI implementation bean if necessary */
protected abstract void destroyServiceEndpoint(ServiceEndpointInfo seInfo, Object
seiImpl);
@@ -139,7 +140,7 @@
// call the handler chain
boolean handlersPass = callRequestHandlerChain(seInfo, HandlerType.PRE);
-
+
// Unbind the request message
if (handlersPass)
{
@@ -154,7 +155,7 @@
// Unbind the request message
epInv = binding.unbindRequestMessage(opMetaData, reqMessage);
}
-
+
handlersPass = handlersPass && callRequestHandlerChain(seInfo,
HandlerType.ENDPOINT);
handlersPass = handlersPass && callRequestHandlerChain(seInfo,
HandlerType.POST);
@@ -164,7 +165,7 @@
log.debug("Handler modified body payload, unbind message again");
epInv = binding.unbindRequestMessage(opMetaData, reqMessage);
}
-
+
if (handlersPass)
{
// Invoke the service endpoint
@@ -202,7 +203,8 @@
{
try
{
- SOAPMessage faultMessage =
SOAPFaultExceptionHelper.exceptionToFaultMessage(ex);
+ CommonSOAPBinding soapBinding =
(CommonSOAPBinding)bindingProvider.getCommonBinding();
+ SOAPMessage faultMessage = soapBinding.exceptionToFaultMessage(ex);
msgContext.setSOAPMessage(faultMessage);
// call the handler chain
@@ -278,48 +280,37 @@
return implMethod;
}
- /** handle invokation exceptions */
- public void handleInvocationException(Throwable th) throws SOAPFaultException
+ /** handle invocation exceptions */
+ public void handleInvocationException(Throwable th) throws Exception
{
- if (th instanceof RuntimeException)
- throw (RuntimeException)th;
-
if (th instanceof InvocationTargetException)
{
- InvocationTargetException targetException = (InvocationTargetException)th;
- Throwable targetEx = targetException.getTargetException();
- if (targetEx instanceof SOAPFaultException)
- {
- throw (SOAPFaultException)targetEx;
- }
- else
- {
- String faultString = targetEx.toString();
- SOAPFaultException soapFaultEx = new
SOAPFaultException(Constants.SOAP11_FAULT_CODE_CLIENT, faultString, null, null);
- soapFaultEx.initCause(targetEx);
- throw soapFaultEx;
- }
+ // unwrap the throwable raised by the service endpoint implementation
+ Throwable targetEx = ((InvocationTargetException)th).getTargetException();
+ handleInvocationThrowable(targetEx);
}
if (th instanceof MBeanException)
{
- Exception targetEx = ((MBeanException)th).getTargetException();
- if (targetEx instanceof SOAPFaultException)
- {
- throw (SOAPFaultException)targetEx;
- }
- else
- {
- String faultString = targetEx.toString();
- SOAPFaultException soapFaultEx = new
SOAPFaultException(Constants.SOAP11_FAULT_CODE_CLIENT, faultString, null, null);
- soapFaultEx.initCause(targetEx);
- throw soapFaultEx;
- }
+ throw ((MBeanException)th).getTargetException();
}
- String faultString = th.toString();
- SOAPFaultException soapFaultEx = new
SOAPFaultException(Constants.SOAP11_FAULT_CODE_CLIENT, faultString, null, null);
- soapFaultEx.initCause(th);
- throw soapFaultEx;
+ handleInvocationThrowable(th);
}
+
+ private void handleInvocationThrowable(Throwable th) throws Exception
+ {
+ if (th instanceof Exception)
+ {
+ throw (Exception)th;
+ }
+ else if (th instanceof Error)
+ {
+ throw (Error)th;
+ }
+ else
+ {
+ throw new UndeclaredThrowableException(th);
+ }
+ }
}
Modified: trunk/src/main/java/org/jboss/ws/server/ServiceEndpoint.java
===================================================================
--- trunk/src/main/java/org/jboss/ws/server/ServiceEndpoint.java 2006-11-17 02:06:33 UTC
(rev 1454)
+++ trunk/src/main/java/org/jboss/ws/server/ServiceEndpoint.java 2006-11-17 07:56:40 UTC
(rev 1455)
@@ -37,11 +37,11 @@
import javax.xml.soap.SOAPMessage;
import org.jboss.logging.Logger;
-import org.jboss.ws.utils.DOMWriter;
import org.jboss.ws.Constants;
import org.jboss.ws.binding.BindingException;
+import org.jboss.ws.common.CommonBindingProvider;
import org.jboss.ws.common.CommonMessageContext;
-import org.jboss.ws.jaxrpc.SOAPFaultExceptionHelper;
+import org.jboss.ws.common.CommonSOAPBinding;
import org.jboss.ws.metadata.EndpointMetaData;
import org.jboss.ws.metadata.ServerEndpointMetaData;
import org.jboss.ws.metadata.UnifiedMetaData;
@@ -50,6 +50,7 @@
import org.jboss.ws.soap.SOAPElementImpl;
import org.jboss.ws.soap.SOAPElementWriter;
import org.jboss.ws.soap.SOAPMessageImpl;
+import org.jboss.ws.utils.DOMWriter;
import org.w3c.dom.Document;
/**
@@ -201,7 +202,10 @@
// we create the fault message here.
if (resMessage == null || ((SOAPMessageImpl)resMessage).isFaultMessage() ==
false)
{
- resMessage = SOAPFaultExceptionHelper.exceptionToFaultMessage(ex);
+ CommonBindingProvider bindingProvider = getCommonBindingProvider();
+ CommonSOAPBinding soapBinding =
(CommonSOAPBinding)bindingProvider.getCommonBinding();
+
+ resMessage = soapBinding.exceptionToFaultMessage(ex);
msgContext.setSOAPMessage(resMessage);
}
@@ -267,6 +271,11 @@
}
}
+ private CommonBindingProvider getCommonBindingProvider()
+ {
+ return new CommonBindingProvider(seInfo.getServerEndpointMetaData());
+ }
+
/**
* Returns a string representation of the object.
*/
Modified: trunk/src/main/java/org/jboss/ws/server/ServiceEndpointInvokerJSE.java
===================================================================
--- trunk/src/main/java/org/jboss/ws/server/ServiceEndpointInvokerJSE.java 2006-11-17
02:06:33 UTC (rev 1454)
+++ trunk/src/main/java/org/jboss/ws/server/ServiceEndpointInvokerJSE.java 2006-11-17
07:56:40 UTC (rev 1455)
@@ -81,7 +81,7 @@
}
/** Invoke an instance of the SEI implementation bean */
- public void invokeServiceEndpoint(ServiceEndpointInfo seInfo, Object seiImpl,
EndpointInvocation epInv) throws SOAPFaultException
+ public void invokeServiceEndpoint(ServiceEndpointInfo seInfo, Object seiImpl,
EndpointInvocation epInv) throws SOAPFaultException, Exception
{
log.debug("invokeServiceEndpoint: " + epInv.getJavaMethod().getName());
try
Modified: trunk/src/test/build.xml
===================================================================
--- trunk/src/test/build.xml 2006-11-17 02:06:33 UTC (rev 1454)
+++ trunk/src/test/build.xml 2006-11-17 07:56:40 UTC (rev 1455)
@@ -189,10 +189,10 @@
<pathelement location="${thirdparty.dir}/stax-api-1.0.jar"/>
</path>
- <!-- Check that jBPM BPEL has been deployed -->
+ <!-- Deploy jBPM BPEL (no action if deployed already) -->
<property name="jboss.server.deploy.jbpmbpel"
value="${jboss.server.deploy}/jbpm-bpel.sar" />
- <available property="jbpmbpel.available"
file="${jboss.server.deploy.jbpmbpel}" />
- <antcall target="deploy-jbpmbpel" />
+ <mkdir dir="${jboss.server.deploy.jbpmbpel}" />
+ <unjar dest="${jboss.server.deploy.jbpmbpel}"
src="${thirdparty.dir}/jbpm-bpel.sar" overwrite="no"/>
<!-- The jBPM BPEL classpath -->
<path id="jbpmbpel.classpath">
@@ -210,11 +210,6 @@
<path location="${test.etc.dir}" />
</path>
</target>
-
- <target name="deploy-jbpmbpel" unless="jbpmbpel.available">
- <mkdir dir="${jboss.server.deploy.jbpmbpel}" />
- <unjar dest="${jboss.server.deploy.jbpmbpel}"
src="${thirdparty.dir}/jbpm-bpel.sar" />
- </target>
<!-- ================================================================== -->
<!-- Compiling -->
Modified: trunk/src/test/java/org/jboss/test/ws/common/soap/SOAPFaultTestCase.java
===================================================================
--- trunk/src/test/java/org/jboss/test/ws/common/soap/SOAPFaultTestCase.java 2006-11-17
02:06:33 UTC (rev 1454)
+++ trunk/src/test/java/org/jboss/test/ws/common/soap/SOAPFaultTestCase.java 2006-11-17
07:56:40 UTC (rev 1455)
@@ -37,7 +37,7 @@
import org.jboss.test.ws.JBossWSTest;
import org.jboss.ws.Constants;
-import org.jboss.ws.jaxrpc.SOAPFaultExceptionHelper;
+import org.jboss.ws.jaxrpc.SOAPFaultHelperJAXRPC;
import org.jboss.ws.utils.DOMUtils;
/**
@@ -57,7 +57,7 @@
{
Detail detail = createDetailElement();
SOAPFaultException faultEx = new
SOAPFaultException(Constants.SOAP11_FAULT_CODE_CLIENT, "Some fault message",
"Some fault actor", detail);
- SOAPEnvelope soapEnv =
SOAPFaultExceptionHelper.exceptionToFaultMessage(faultEx).getSOAPPart().getEnvelope();
+ SOAPEnvelope soapEnv =
SOAPFaultHelperJAXRPC.exceptionToFaultMessage(faultEx).getSOAPPart().getEnvelope();
assertEquals(DOMUtils.parse(envStr), soapEnv);
}
@@ -72,7 +72,7 @@
assertEquals("Some fault actor", soapFault.getFaultActor());
assertEquals(createDetailElement(), soapFault.getDetail());
- SOAPFaultException faultEx =
SOAPFaultExceptionHelper.getSOAPFaultException((SOAPFault)soapFault);
+ SOAPFaultException faultEx =
SOAPFaultHelperJAXRPC.getSOAPFaultException((SOAPFault)soapFault);
assertEquals(Constants.SOAP11_FAULT_CODE_CLIENT, faultEx.getFaultCode());
assertEquals("Some fault message", faultEx.getFaultString());
Modified:
trunk/src/test/java/org/jboss/test/ws/jaxrpc/encoded/marshalltest/MarshallTestCase.java
===================================================================
---
trunk/src/test/java/org/jboss/test/ws/jaxrpc/encoded/marshalltest/MarshallTestCase.java 2006-11-17
02:06:33 UTC (rev 1454)
+++
trunk/src/test/java/org/jboss/test/ws/jaxrpc/encoded/marshalltest/MarshallTestCase.java 2006-11-17
07:56:40 UTC (rev 1455)
@@ -279,7 +279,7 @@
public void testJavaBeanTest() throws Exception
{
JavaBean inObj = new JavaBean();
-
+
inObj.setMyBigDecimal(new BigDecimal("100"));
inObj.setMyBigDecimalArray(new BigDecimal[] { new BigDecimal("100"), new
BigDecimal("200"), new BigDecimal("300") });
inObj.setMyBigInteger(new BigInteger("100"));
@@ -321,8 +321,9 @@
inObj.setMyStringArray(new String[] { "String1", "String2" });
System.out.println("FIXME: [JBWS-485] SOAP encoded arrays as bean
properties");
- if (true) return;
-
+ if (true)
+ return;
+
JavaBean retObj = port.javaBeanTest(inObj);
assertEquals(inObj, retObj);
}
@@ -352,9 +353,6 @@
public void testMyServiceExceptionTest() throws Exception
{
- System.out.println("FIXME: [JBWS-1297] Implement JAXB Fault
Marshalling");
- if (true) return;
-
try
{
port.myServiceExceptionTest();
@@ -431,7 +429,7 @@
public void testValueTypeTest() throws Exception
{
ValueType inObj = new ValueType();
-
+
inObj.setMyBigDecimal(new BigDecimal("100"));
inObj.setMyBigDecimalArray(new BigDecimal[] { new BigDecimal("100"), new
BigDecimal("200"), new BigDecimal("300") });
inObj.setMyBigInteger(new BigInteger("100"));
@@ -473,8 +471,9 @@
inObj.setMyStringArray(new String[] { "String1", "String2" });
System.out.println("FIXME: [JBWS-485] SOAP encoded arrays as bean
properties");
- if (true) return;
-
+ if (true)
+ return;
+
ValueType retObj = port.valueTypeTest(inObj);
assertEquals(inObj, retObj);
}
Modified: trunk/src/test/java/org/jboss/test/ws/jaxrpc/jbws807/JBWS807TestCase.java
===================================================================
--- trunk/src/test/java/org/jboss/test/ws/jaxrpc/jbws807/JBWS807TestCase.java 2006-11-17
02:06:33 UTC (rev 1454)
+++ trunk/src/test/java/org/jboss/test/ws/jaxrpc/jbws807/JBWS807TestCase.java 2006-11-17
07:56:40 UTC (rev 1455)
@@ -63,14 +63,10 @@
public void testPingMsg() throws Exception
{
- System.out.println("FIXME: [JBWS-1297] Implement JAXB Fault
Marshalling");
- if (true) return;
-
try
{
port.ping(new PingMsg("Hello World"));
fail("JBWS807 endpoint is supposed to fault");
-
}
catch (RemoteException e)
{
Modified:
trunk/src/test/java/org/jboss/test/ws/jaxrpc/samples/exception/ExceptionTestCase.java
===================================================================
---
trunk/src/test/java/org/jboss/test/ws/jaxrpc/samples/exception/ExceptionTestCase.java 2006-11-17
02:06:33 UTC (rev 1454)
+++
trunk/src/test/java/org/jboss/test/ws/jaxrpc/samples/exception/ExceptionTestCase.java 2006-11-17
07:56:40 UTC (rev 1455)
@@ -110,9 +110,6 @@
/** Test simple exception propagation */
public void testException() throws Exception
{
- System.out.println("FIXME: [JBWS-1297] Implement JAXB Fault
Marshalling");
- if (true) return;
-
ExceptionServiceInterface port = getPort();
try
{
@@ -132,9 +129,6 @@
/** Test exception with message */
public void testExceptionWithMessage() throws Exception
{
- System.out.println("FIXME: [JBWS-1297] Implement JAXB Fault
Marshalling");
- if (true) return;
-
ExceptionServiceInterface port = getPort();
String message = "Don't worry it's just a test";
@@ -156,9 +150,6 @@
/** Test a complex user exception */
public void testComplexUserException() throws Exception
{
- System.out.println("FIXME: [JBWS-1297] Implement JAXB Fault
Marshalling");
- if (true) return;
-
ExceptionServiceInterface port = getPort();
String message = "Don't worry it's just a test";
@@ -181,9 +172,6 @@
/** Test a complex user exception that contains an array */
public void testComplexUserArrayException() throws Exception
{
- System.out.println("FIXME: [JBWS-1297] Implement JAXB Fault
Marshalling");
- if (true) return;
-
ExceptionServiceInterface port = getPort();
String message = "Don't worry it's just a test";
@@ -207,9 +195,6 @@
/** Test a fault message for a non existant operation */
public void testNonExistantOperation() throws Exception
{
- System.out.println("FIXME: [JBWS-1297] Implement JAXB Fault
Marshalling");
- if (true) return;
-
String reqEnv = "<env:Envelope
xmlns:env='http://schemas.xmlsoap.org/soap/envelope/'>" + "
<env:Header/>" + " <env:Body>"
+ " <ns1:nonExistantOperation
xmlns:ns1='http://org.jboss.webservice/exception'/>" + "
</env:Body>" + "</env:Envelope>";
@@ -230,9 +215,6 @@
/** Test a fault message for a non existant operation */
public void testNonExistantOperationDII() throws Exception
{
- System.out.println("FIXME: [JBWS-1297] Implement JAXB Fault
Marshalling");
- if (true) return;
-
ServiceFactory factory = ServiceFactory.newInstance();
Service service = factory.createService(new QName(TARGET_NAMESPACE,
"ExceptionService"));
Modified: trunk/src/test/java/org/jboss/test/ws/jaxws/exception/ExceptionTestCase.java
===================================================================
---
trunk/src/test/java/org/jboss/test/ws/jaxws/exception/ExceptionTestCase.java 2006-11-17
02:06:33 UTC (rev 1454)
+++
trunk/src/test/java/org/jboss/test/ws/jaxws/exception/ExceptionTestCase.java 2006-11-17
07:56:40 UTC (rev 1455)
@@ -80,66 +80,48 @@
*/
public void testRuntimeException() throws Exception
{
- System.out.println("FIXME: [JBWS-1297] Implement JAXB Fault
Marshalling");
- if (true) return;
-
try
{
proxy.throwRuntimeException();
+ fail("Expected SOAPFaultException");
}
catch (SOAPFaultException e)
{
assertEquals("oh no, a runtime exception occured.", e.getMessage());
assertEquals("oh no, a runtime exception occured.",
e.getFault().getFaultString());
- return;
}
-
- assertTrue("Expected SOAPFaultException", false);
}
public void testSoapFaultException() throws Exception
{
- System.out.println("FIXME: [JBWS-1297] Implement JAXB Fault
Marshalling");
- if (true)
- return;
-
try
{
proxy.throwSoapFaultException();
+ fail("Expected SOAPFaultException");
}
catch (SOAPFaultException e)
{
- assertEquals("this is a fault string", e.getMessage());
- assertEquals("this is a fault string",
e.getFault().getFaultString());
+ assertEquals("this is a fault string!", e.getMessage());
+ assertEquals("this is a fault string!",
e.getFault().getFaultString());
assertEquals("mr.actor", e.getFault().getFaultActor());
assertEquals("FooCode",
e.getFault().getFaultCodeAsName().getLocalName());
assertEquals("http://foo",
e.getFault().getFaultCodeAsName().getURI());
assertEquals("test",
((Element)e.getFault().getDetail().getChildElements().next()).getLocalName());
-
- return;
}
-
- assertTrue("Expected SOAPFaultException", false);
}
public void testApplicationException() throws Exception
{
- System.out.println("FIXME: [JBWS-1297] Implement JAXB Fault
Marshalling");
- if (true)
- return;
-
try
{
proxy.throwApplicationException();
+ fail("Expected UserException");
}
catch (UserException e)
{
assertEquals("Some validation error", e.getMessage());
assertEquals("validation", e.getErrorCategory());
assertEquals(123, e.getErrorCode());
- return;
}
-
- assertTrue("Expected UserException", false);
}
}
\ No newline at end of file
Modified:
trunk/src/test/java/org/jboss/test/ws/jaxws/jsr181/webmethod/JSR181WebMethodTestCase.java
===================================================================
---
trunk/src/test/java/org/jboss/test/ws/jaxws/jsr181/webmethod/JSR181WebMethodTestCase.java 2006-11-17
02:06:33 UTC (rev 1454)
+++
trunk/src/test/java/org/jboss/test/ws/jaxws/jsr181/webmethod/JSR181WebMethodTestCase.java 2006-11-17
07:56:40 UTC (rev 1455)
@@ -41,7 +41,6 @@
import org.jboss.test.ws.JBossWSTest;
import org.jboss.test.ws.JBossWSTestSetup;
-import org.jboss.ws.utils.DOMUtils;
import org.jboss.ws.soap.NameImpl;
import org.jboss.ws.utils.DOMUtils;
import org.w3c.dom.Element;
Modified:
trunk/src/test/java/org/jboss/test/ws/jaxws/samples/retail/profile/ObjectFactory.java
===================================================================
---
trunk/src/test/java/org/jboss/test/ws/jaxws/samples/retail/profile/ObjectFactory.java 2006-11-17
02:06:33 UTC (rev 1454)
+++
trunk/src/test/java/org/jboss/test/ws/jaxws/samples/retail/profile/ObjectFactory.java 2006-11-17
07:56:40 UTC (rev 1455)
@@ -8,7 +8,9 @@
import javax.xml.bind.annotation.XmlRegistry;
import javax.xml.namespace.QName;
+import org.jboss.test.ws.jaxws.samples.retail.Customer;
+
/**
* This object contains factory methods for each
* Java content interface and Java element interface
Modified:
trunk/src/test/java/org/jboss/test/ws/jaxws/wsaddressing/replyto/AddressingReplyToTestCase.java
===================================================================
---
trunk/src/test/java/org/jboss/test/ws/jaxws/wsaddressing/replyto/AddressingReplyToTestCase.java 2006-11-17
02:06:33 UTC (rev 1454)
+++
trunk/src/test/java/org/jboss/test/ws/jaxws/wsaddressing/replyto/AddressingReplyToTestCase.java 2006-11-17
07:56:40 UTC (rev 1455)
@@ -35,7 +35,6 @@
import org.jboss.test.ws.JBossWSTest;
import org.jboss.test.ws.JBossWSTestSetup;
-import org.jboss.test.ws.jaxws.logicalhandler.SOAPEndpointJAXB;
/**
* Test endpoint using ws-addressing
@@ -142,6 +141,16 @@
public void testFaultTo() throws Exception
{
String lastFault = faultto.getLastFault();
- assertEquals("java.lang.IllegalArgumentException: Invalid Value",
lastFault);
+
+ /* JAX-WS 10.2.2.3: the fields of the fault message are populated according to
+ * the following rules of precedence:
+ *
+ * faultstring
+ * 1. SOAPFaultException.getFault().getFaultString()
+ * 2. Exception.getMessage()
+ * 3. Exception.toString()
+ *
+ * this test used to expect the value returned by toString() */
+ assertEquals("Invalid Value", lastFault);
}
}