You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by sc...@apache.org on 2008/09/15 18:25:21 UTC
svn commit: r695531 - in /webservices/axis2/trunk/java/modules:
jaxws-integration/test/org/apache/axis2/jaxws/provider/
jaxws-integration/test/org/apache/axis2/jaxws/provider/source/
jaxws-integration/test/org/apache/axis2/jaxws/provider/string/ jaxws/...
Author: scheu
Date: Mon Sep 15 09:25:17 2008
New Revision: 695531
URL: http://svn.apache.org/viewvc?rev=695531&view=rev
Log:
AXIS2-4031
Contributors:Nick Gallardo, Rich Scheuerle
Summary of changes:
* (Nick) Improved ProviderDispatcher to detect faults and add them to the JAXWS message object as XMLFaults.
* (Nick) Updated the Provider<Source> test and FaultTests to verify this path.
* (Rich) Improved the Block.getQName code to tolerate content that does not have a qname.
* (Rich) Updated the Provider<Source> and Provider<String> tests to verify the no QName toleration path.
Modified:
webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/provider/SourceProviderTests.java
webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/provider/source/SourceProvider.java
webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/provider/string/StringProvider.java
webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/impl/BlockImpl.java
webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/util/XMLFaultUtils.java
webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/dispatcher/ProviderDispatcher.java
Modified: webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/provider/SourceProviderTests.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/provider/SourceProviderTests.java?rev=695531&r1=695530&r2=695531&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/provider/SourceProviderTests.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/provider/SourceProviderTests.java Mon Sep 15 09:25:17 2008
@@ -314,6 +314,24 @@
}
}
+ public void testUserGeneratedSOAPFault() throws Exception {
+ System.out.println("---------------------------------------");
+ System.out.println("test: " + getName());
+
+ Dispatch<Source> dispatch = getDispatch();
+ String request = "<test>throwUserGeneratedFault</test>";
+ try {
+ Source requestSource = getSource(request);
+ Source responseSource = dispatch.invoke(requestSource);
+ String response = getString(responseSource);
+ fail("Expected Exception");
+ } catch (SOAPFaultException e) {
+ SOAPFault sf = e.getFault();
+ assertTrue(sf.getFaultString().equals("userGeneratedFaultTest"));
+ }
+ }
+
+
public void testProviderSource(){
try{
String resourceDir = new File(providerResourceDir, xmlDir).getAbsolutePath();
Modified: webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/provider/source/SourceProvider.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/provider/source/SourceProvider.java?rev=695531&r1=695530&r2=695531&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/provider/source/SourceProvider.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/provider/source/SourceProvider.java Mon Sep 15 09:25:17 2008
@@ -49,7 +49,9 @@
TestLogger.logger.debug(">> SourceProvider: Request received.\n");
if (source == null) {
- return source;
+ ByteArrayInputStream stream = new ByteArrayInputStream(" ".getBytes());
+ Source srcStream = new StreamSource((InputStream) stream);
+ return srcStream;
}
// Non-null source
@@ -71,7 +73,15 @@
if (text != null && text.contains("throwWebServiceException")) {
throw new WebServiceException("provider");
+ } else if (text != null && text.contains("throwUserGeneratedFault")) {
+ String userFault = "<soapenv:Fault xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\">" +
+ "<faultcode>soapenv:Receiver</faultcode>" +
+ "<faultstring>userGeneratedFaultTest</faultstring>" +
+ "<detail>sample SOAP Fault details</detail>" +
+ "</soapenv:Fault>";
+ text = userFault;
}
+
ByteArrayInputStream stream = new ByteArrayInputStream(text.getBytes());
Source srcStream = new StreamSource((InputStream) stream);
Modified: webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/provider/string/StringProvider.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/provider/string/StringProvider.java?rev=695531&r1=695530&r2=695531&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/provider/string/StringProvider.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/provider/string/StringProvider.java Mon Sep 15 09:25:17 2008
@@ -39,7 +39,7 @@
public String invoke(String text) {
TestLogger.logger.debug("StringProvider invoke received the message [" + text + "]");
if (text == null) {
- return null;
+ return " ";
} else if (text.contains("throwWebServiceException")) {
throw new WebServiceException("provider");
} else if (text.contains("<Code>") && text.contains("SOAPFaultProviderTests")) {
Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/impl/BlockImpl.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/impl/BlockImpl.java?rev=695531&r1=695530&r2=695531&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/impl/BlockImpl.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/impl/BlockImpl.java Mon Sep 15 09:25:17 2008
@@ -72,6 +72,8 @@
protected OMElement omElement = null;
protected QName qName;
+ private boolean noQNameAvailable = false;
+
protected BlockFactory factory;
protected boolean consumed = false;
protected Message parent;
@@ -162,11 +164,37 @@
// If the QName is not known, find it
try {
if (qName == null) {
+ // If a prior call discovered that this content has no QName, then return null
+ if (noQNameAvailable) {
+ return null;
+ }
if (omElement == null) {
- XMLStreamReader newReader = _getReaderFromBO(busObject, busContext);
- busObject = null;
- StAXOMBuilder builder = new StAXOMBuilder(newReader);
- omElement = builder.getDocumentElement();
+ try {
+ XMLStreamReader newReader = _getReaderFromBO(busObject, busContext);
+ busObject = null;
+ StAXOMBuilder builder = new StAXOMBuilder(newReader);
+ omElement = builder.getDocumentElement();
+ } catch (Exception e) {
+ // Some blocks may represent non-element data
+ if (log.isDebugEnabled()) {
+ log.debug("Exception occurred while obtaining QName:" + e);
+ }
+ if (!isElementData()) {
+ // If this block can hold non-element data, then accept
+ // the fact that there is no qname and continue
+ if (log.isDebugEnabled()) {
+ log.debug("The block does not contain an xml element. Processing continues.");
+ }
+ // Indicate that the content has no QName
+ // The exception is swallowed.
+ noQNameAvailable = true;
+ return null;
+ } else {
+ // The content should contain xml.
+ // Rethrowing the exception.
+ throw ExceptionFactory.makeWebServiceException(e);
+ }
+ }
}
qName = omElement.getQName();
}
Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/util/XMLFaultUtils.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/util/XMLFaultUtils.java?rev=695531&r1=695530&r2=695531&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/util/XMLFaultUtils.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/util/XMLFaultUtils.java Mon Sep 15 09:25:17 2008
@@ -23,6 +23,7 @@
import org.apache.axiom.om.OMNamespace;
import org.apache.axiom.om.impl.llom.OMSourcedElementImpl;
import org.apache.axiom.soap.SOAP11Constants;
+import org.apache.axiom.soap.SOAP12Constants;
import org.apache.axiom.soap.SOAPBody;
import org.apache.axiom.soap.SOAPEnvelope;
import org.apache.axiom.soap.SOAPFactory;
@@ -35,11 +36,15 @@
import org.apache.axiom.soap.SOAPFaultSubCode;
import org.apache.axiom.soap.SOAPFaultText;
import org.apache.axiom.soap.SOAPFaultValue;
+import org.apache.axiom.soap.impl.builder.StAXSOAPModelBuilder;
import org.apache.axis2.jaxws.ExceptionFactory;
import org.apache.axis2.jaxws.message.Block;
+import org.apache.axis2.jaxws.message.Message;
+import org.apache.axis2.jaxws.message.Protocol;
import org.apache.axis2.jaxws.message.XMLFault;
import org.apache.axis2.jaxws.message.XMLFaultCode;
import org.apache.axis2.jaxws.message.XMLFaultReason;
+import org.apache.axis2.jaxws.message.factory.MessageFactory;
import org.apache.axis2.jaxws.message.factory.OMBlockFactory;
import org.apache.axis2.jaxws.message.factory.SAAJConverterFactory;
import org.apache.axis2.jaxws.registry.FactoryRegistry;
@@ -83,6 +88,23 @@
public static boolean isFault(SOAPEnvelope envelope) {
return envelope.hasFault();
}
+
+ /**
+ * @param block representing a message payload
+ * @return true if the localname & namespace represent a SOAP 1.1 or SOAP 1.2 fault.
+ */
+ public static boolean containsFault(Block b) {
+ if (b != null) {
+ QName qn = b.getQName();
+ if (qn != null &&
+ qn.getLocalPart().equals(org.apache.axiom.soap.SOAPConstants.SOAPFAULT_LOCAL_NAME)
+ && (qn.getNamespaceURI().equals(SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI)
+ || qn.getNamespaceURI().equals(SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI))) {
+ return true;
+ }
+ }
+ return false;
+ }
/**
@@ -328,6 +350,56 @@
return xmlFault;
}
+ public static XMLFault createXMLFault(Block b, Protocol p) {
+ // Because of the requirement that we have a full SOAP envelope structure as
+ // the input to the StAXSOAPModelBuilder, we have to have a dummy envelope
+ // that wraps our fault. This will allow the Axiom SOAPFault object to
+ // be created.
+ Message m = null;
+ try {
+ MessageFactory mf = (MessageFactory) FactoryRegistry.getFactory(MessageFactory.class);
+ m = mf.create(p);
+ m.setBodyBlock(b);
+ } catch (XMLStreamException e) {
+ throw ExceptionFactory.makeWebServiceException(e);
+ }
+
+ SOAPEnvelope dummyEnv = (SOAPEnvelope) m.getAsOMElement();
+
+ StAXSOAPModelBuilder builder = new StAXSOAPModelBuilder(dummyEnv.getXMLStreamReaderWithoutCaching());
+ SOAPEnvelope newEnv = (SOAPEnvelope) builder.getDocumentElement();
+
+ SOAPBody body = newEnv.getBody();
+ SOAPFault fault = body.getFault();
+
+ Block[] details = getDetailBlocks(fault);
+
+ return XMLFaultUtils.createXMLFault(fault, details);
+ }
+
+ private static Block[] getDetailBlocks(SOAPFault soapFault) throws WebServiceException {
+ try {
+ Block[] blocks = null;
+ SOAPFaultDetail detail = soapFault.getDetail();
+ if (detail != null) {
+ // Create a block for each element
+ OMBlockFactory bf =
+ (OMBlockFactory) FactoryRegistry.getFactory(OMBlockFactory.class);
+ ArrayList<Block> list = new ArrayList<Block>();
+ Iterator it = detail.getChildElements();
+ while (it.hasNext()) {
+ OMElement om = (OMElement) it.next();
+ Block b = bf.createFrom(om, null, om.getQName());
+ list.add(b);
+ }
+ blocks = new Block[list.size()];
+ blocks = list.toArray(blocks);
+ }
+ return blocks;
+ } catch (Exception e) {
+ throw ExceptionFactory.makeWebServiceException(e);
+ }
+ }
private static Block[] getDetailBlocks(javax.xml.soap.SOAPFault soapFault)
throws WebServiceException {
Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/dispatcher/ProviderDispatcher.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/dispatcher/ProviderDispatcher.java?rev=695531&r1=695530&r2=695531&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/dispatcher/ProviderDispatcher.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/dispatcher/ProviderDispatcher.java Mon Sep 15 09:25:17 2008
@@ -37,6 +37,7 @@
import org.apache.axis2.jaxws.message.factory.SOAPEnvelopeBlockFactory;
import org.apache.axis2.jaxws.message.factory.SourceBlockFactory;
import org.apache.axis2.jaxws.message.factory.XMLStringBlockFactory;
+import org.apache.axis2.jaxws.message.util.XMLFaultUtils;
import org.apache.axis2.jaxws.registry.FactoryRegistry;
import org.apache.axis2.jaxws.server.EndpointCallback;
import org.apache.axis2.jaxws.server.EndpointInvocationContext;
@@ -480,7 +481,20 @@
}
Block block = factory.createFrom(value, null, null);
message = msgFactory.create(protocol);
- message.setBodyBlock(block);
+
+ if (XMLFaultUtils.containsFault(block)) {
+ if (log.isDebugEnabled()) {
+ log.debug("The response block created contained a fault. Converting to an XMLFault object.");
+ }
+ // If the Provider returned a fault, then let's correct the output and
+ // put an XMLFault on the Message. This makes it easier for downstream
+ // consumers to get the SOAPFault from the OM SOAPEnvelope.
+ XMLFault fault = XMLFaultUtils.createXMLFault(block, message.getProtocol());
+ message.setXMLFault(fault);
+ }
+ else {
+ message.setBodyBlock(block);
+ }
}
}