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 ng...@apache.org on 2007/06/27 18:08:53 UTC
svn commit: r551215 - in /webservices/axis2/trunk/java/modules/jaxws:
src/org/apache/axis2/jaxws/handler/
src/org/apache/axis2/jaxws/message/databinding/impl/
src/org/apache/axis2/jaxws/message/impl/
src/org/apache/axis2/jaxws/message/util/ src/org/apa...
Author: ngallardo
Date: Wed Jun 27 09:08:51 2007
New Revision: 551215
URL: http://svn.apache.org/viewvc?view=rev&rev=551215
Log:
AXIS2-2548
For fault scenarios involving the LogicalMessage, we have to do some extra manipulation to get the message returned correctly.
Added:
webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/handler/context/CompositeMessageContextTests.java
Modified:
webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/handler/LogicalMessageImpl.java
webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/impl/SourceBlockImpl.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/message/util/impl/SAAJConverterImpl.java
webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/framework/JAXWSTest.java
webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/handler/context/LogicalMessageContextTests.java
webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/message/FaultTests.java
webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/sample/AddNumbersHandlerTests.java
Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/handler/LogicalMessageImpl.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/handler/LogicalMessageImpl.java?view=diff&rev=551215&r1=551214&r2=551215
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/handler/LogicalMessageImpl.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/handler/LogicalMessageImpl.java Wed Jun 27 09:08:51 2007
@@ -20,9 +20,11 @@
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
+import java.io.StringReader;
import javax.xml.bind.JAXBContext;
import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
import javax.xml.transform.OutputKeys;
import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
@@ -35,6 +37,11 @@
import javax.xml.ws.LogicalMessage;
import javax.xml.ws.WebServiceException;
+import org.apache.axiom.om.impl.builder.StAXOMBuilder;
+import org.apache.axiom.om.util.StAXUtils;
+import org.apache.axiom.soap.SOAPEnvelope;
+import org.apache.axiom.soap.SOAPFactory;
+import org.apache.axiom.soap.SOAPFault;
import org.apache.axis2.jaxws.ExceptionFactory;
import org.apache.axis2.jaxws.core.MEPContext;
import org.apache.axis2.jaxws.message.Block;
@@ -42,6 +49,7 @@
import org.apache.axis2.jaxws.message.databinding.JAXBBlockContext;
import org.apache.axis2.jaxws.message.factory.BlockFactory;
import org.apache.axis2.jaxws.message.factory.JAXBBlockFactory;
+import org.apache.axis2.jaxws.message.factory.MessageFactory;
import org.apache.axis2.jaxws.message.factory.SourceBlockFactory;
import org.apache.axis2.jaxws.registry.FactoryRegistry;
@@ -86,8 +94,7 @@
// able to create a copy of itself just yet.
Payloads payloads = createPayloads(content);
- Block cacheBlock = factory.createFrom(payloads.CACHE_PAYLOAD, context, block.getQName());
- mepCtx.getMessageObject().setBodyBlock(cacheBlock);
+ _setPayload(payloads.CACHE_PAYLOAD, context, factory);
payload = payloads.HANDLER_PAYLOAD;
} catch (XMLStreamException e) {
@@ -120,7 +127,28 @@
Block block = factory.createFrom(object, context, null);
if (mepCtx.getMessageObject() != null) {
- mepCtx.getMessageObject().setBodyBlock(block);
+ if (!mepCtx.getMessageObject().isFault()) {
+ mepCtx.getMessageObject().setBodyBlock(block);
+ }
+ else {
+ mepCtx.getMessageObject().setBodyBlock(block);
+
+ // If the payload is a fault, then we can't set it back on the message
+ // as a block. Blocks are OMSourcedElements, and faults cannot be OMSourcedElements.
+ try {
+ SOAPEnvelope env = (SOAPEnvelope) mepCtx.getMessageObject().getAsOMElement();
+ String content = env.toStringWithConsume();
+
+ MessageFactory mf = (MessageFactory) FactoryRegistry.getFactory(MessageFactory.class);
+ StringReader sr = new StringReader(content);
+ XMLStreamReader stream = StAXUtils.createXMLStreamReader(sr);
+ Message msg = mf.createFrom(stream, mepCtx.getMessageObject().getProtocol());
+
+ mepCtx.setMessage(msg);
+ } catch (Exception e) {
+ throw ExceptionFactory.makeWebServiceException(e);
+ }
+ }
}
}
Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/impl/SourceBlockImpl.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/impl/SourceBlockImpl.java?view=diff&rev=551215&r1=551214&r2=551215
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/impl/SourceBlockImpl.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/impl/SourceBlockImpl.java Wed Jun 27 09:08:51 2007
@@ -18,6 +18,7 @@
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.util.StAXUtils;
+import org.apache.axiom.soap.SOAP11Constants;
import org.apache.axis2.java.security.AccessController;
import org.apache.axis2.jaxws.ExceptionFactory;
import org.apache.axis2.jaxws.i18n.Messages;
@@ -251,5 +252,56 @@
}
return cl;
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.apache.axis2.jaxws.message.Block#getBusinessObject(boolean)
+ */
+ public Object getBusinessObject(boolean consume) throws XMLStreamException,
+ WebServiceException {
+ if (consumed) {
+ throw ExceptionFactory.makeWebServiceException(Messages.getMessage("BlockImplErr1",
+ this.getClass()
+ .getName()));
+ }
+
+ if (busObject != null) {
+ busObject = _getBOFromBO(busObject, busContext, consume);
+ } else {
+ // If the message is a fault, there are some special gymnastics that we have to do
+ // to get this working for all of the handler scenarios.
+ boolean hasFault = false;
+ if ((parent != null && parent.isFault()) ||
+ omElement.getQName().getLocalPart().equals(SOAP11Constants.SOAPFAULT_LOCAL_NAME)) {
+ hasFault = true;
+ }
+
+ // Transform reader into business object
+ if (!hasFault) {
+ XMLStreamReader reader;
+ if (omElement.getBuilder() != null && !omElement.getBuilder().isCompleted()) {
+ reader = omElement.getXMLStreamReaderWithoutCaching();
+ } else {
+ reader = omElement.getXMLStreamReader();
+ }
+ busObject = _getBOFromReader(reader, busContext);
+ }
+ else {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ omElement.serialize(baos);
+
+ ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
+ busObject = new StreamSource(bais);
+ }
+
+ omElement = null;
+ }
+
+ // Save the businessObject in a local variable
+ // so that we can reset the Block if consume was indicated
+ Object newBusObject = busObject;
+ setConsumed(consume);
+ return newBusObject;
}
}
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?view=diff&rev=551215&r1=551214&r2=551215
==============================================================================
--- 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 Wed Jun 27 09:08:51 2007
@@ -58,15 +58,15 @@
private static Log log = LogFactory.getLog(BlockImpl.class);
- private Object busObject;
- private Object busContext;
+ protected Object busObject;
+ protected Object busContext;
- private OMElement omElement = null;
+ protected OMElement omElement = null;
- private QName qName;
- private BlockFactory factory;
- private boolean consumed = false;
- private Message parent;
+ protected QName qName;
+ protected BlockFactory factory;
+ protected boolean consumed = false;
+ protected Message parent;
/**
* A Block has the following components
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?view=diff&rev=551215&r1=551214&r2=551215
==============================================================================
--- 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 Wed Jun 27 09:08:51 2007
@@ -80,7 +80,7 @@
public static boolean isFault(SOAPEnvelope envelope) {
SOAPBody body = envelope.getBody();
if (body != null) {
- return (body.getFault() != null);
+ return (body.hasFault() || body.getFault() != null);
}
return false;
}
Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/util/impl/SAAJConverterImpl.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/util/impl/SAAJConverterImpl.java?view=diff&rev=551215&r1=551214&r2=551215
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/util/impl/SAAJConverterImpl.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/util/impl/SAAJConverterImpl.java Wed Jun 27 09:08:51 2007
@@ -21,6 +21,9 @@
import org.apache.axiom.om.OMException;
import org.apache.axiom.om.util.StAXUtils;
import org.apache.axiom.om.impl.builder.StAXOMBuilder;
+import org.apache.axiom.om.impl.dom.ElementImpl;
+import org.apache.axiom.soap.SOAP11Constants;
+import org.apache.axiom.soap.SOAP12Constants;
import org.apache.axiom.soap.impl.builder.StAXSOAPModelBuilder;
import org.apache.axis2.jaxws.ExceptionFactory;
import org.apache.axis2.jaxws.i18n.Messages;
@@ -30,6 +33,7 @@
import org.apache.axis2.util.XMLUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.w3c.dom.Node;
import javax.xml.namespace.QName;
import javax.xml.soap.Detail;
@@ -114,6 +118,8 @@
*/
public org.apache.axiom.soap.SOAPEnvelope toOM(SOAPEnvelope saajEnvelope)
throws WebServiceException {
+ // Before we do the conversion, we have to fix the QNames for fault elements
+ _fixFaultElements(saajEnvelope);
// Get a XMLStreamReader backed by a SOAPElement tree
XMLStreamReader reader = new SOAPElementReader(saajEnvelope);
// Get a SOAP OM Builder. Passing null causes the version to be automatically triggered
@@ -487,6 +493,68 @@
// TODO NLS
throw ExceptionFactory
.makeWebServiceException(Messages.getMessage("SAAJConverterErr2", event));
+ }
+
+
+ /*
+ * A utility method to fix the localnames of elements with an Axis2 SAAJ
+ * tree. The SAAJ impl relies on the Axiom SOAP APIs, which represent
+ * all faults as SOAP 1.2. This has to be corrected before we can convert
+ * to OM or the faults will not be handled correctly.
+ */
+ private void _fixFaultElements(SOAPEnvelope env) {
+ try {
+ // If we have a SOAP 1.2 envelope, then there's nothing to do.
+ if (env.getNamespaceURI().equals(SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI)) {
+ return;
+ }
+
+ SOAPBody body = env.getBody();
+ if (body != null && body.hasFault()) {
+ SOAPFault fault = body.getFault();
+
+ Iterator itr = fault.getChildElements();
+ while (itr.hasNext()) {
+ SOAPElement se = (SOAPElement) itr.next();
+ if (se.getLocalName().equals(SOAP12Constants.SOAP_FAULT_CODE_LOCAL_NAME)) {
+ // Axis2 SAAJ stores the acutal faultcode text under a SOAPFaultValue object, so we have to
+ // get that and add it as a text node under the original element.
+ Node value = se.getFirstChild();
+ if (value != null && value instanceof org.apache.axis2.saaj.SOAPElementImpl) {
+ org.apache.axis2.saaj.SOAPElementImpl valueElement = (org.apache.axis2.saaj.SOAPElementImpl) value;
+ ElementImpl e = valueElement.getElement();
+ String content = e.getText();
+
+ SOAPElement child = fault.addChildElement(new QName(se.getNamespaceURI(), SOAP11Constants.SOAP_FAULT_CODE_LOCAL_NAME));
+ child.addTextNode(content);
+
+ se.detachNode();
+ }
+ }
+ else if (se.getLocalName().equals(SOAP12Constants.SOAP_FAULT_DETAIL_LOCAL_NAME)) {
+ se.setElementQName(new QName(se.getNamespaceURI(), SOAP11Constants.SOAP_FAULT_DETAIL_LOCAL_NAME));
+ }
+ else if (se.getLocalName().equals(SOAP12Constants.SOAP_FAULT_REASON_LOCAL_NAME)) {
+ se.setElementQName(new QName(se.getNamespaceURI(), SOAP11Constants.SOAP_FAULT_STRING_LOCAL_NAME));
+ // Axis2 SAAJ stores the acutal faultstring text under a SOAPFaultValue object, so we have to
+ // get that and add it as a text node under the original element.
+ Node value = se.getFirstChild();
+ if (value != null && value instanceof org.apache.axis2.saaj.SOAPElementImpl) {
+ org.apache.axis2.saaj.SOAPElementImpl valueElement = (org.apache.axis2.saaj.SOAPElementImpl) value;
+ ElementImpl e = valueElement.getElement();
+ String content = e.getText();
+
+ SOAPElement child = fault.addChildElement(new QName(se.getNamespaceURI(), SOAP11Constants.SOAP_FAULT_STRING_LOCAL_NAME));
+ child.addTextNode(content);
+
+ se.detachNode();
+ }
+ }
+ }
+ }
+ } catch (SOAPException e) {
+ throw ExceptionFactory.makeWebServiceException(e);
+ }
}
/**
Modified: webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/framework/JAXWSTest.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/framework/JAXWSTest.java?view=diff&rev=551215&r1=551214&r2=551215
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/framework/JAXWSTest.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/framework/JAXWSTest.java Wed Jun 27 09:08:51 2007
@@ -39,6 +39,7 @@
import org.apache.axis2.jaxws.endpoint.BasicEndpointTests;
import org.apache.axis2.jaxws.exception.ExceptionFactoryTests;
import org.apache.axis2.jaxws.handler.HandlerChainProcessorTests;
+import org.apache.axis2.jaxws.handler.context.CompositeMessageContextTests;
import org.apache.axis2.jaxws.handler.context.LogicalMessageContextTests;
import org.apache.axis2.jaxws.i18n.JaxwsMessageBundleTests;
import org.apache.axis2.jaxws.injection.ResourceInjectionTests;
@@ -137,6 +138,7 @@
// ------ Handler Tests ------
suite.addTestSuite(LogicalMessageContextTests.class);
+ suite.addTestSuite(CompositeMessageContextTests.class);
suite.addTestSuite(HandlerChainProcessorTests.class);
// ------ Message Tests ------
Added: webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/handler/context/CompositeMessageContextTests.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/handler/context/CompositeMessageContextTests.java?view=auto&rev=551215
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/handler/context/CompositeMessageContextTests.java (added)
+++ webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/handler/context/CompositeMessageContextTests.java Wed Jun 27 09:08:51 2007
@@ -0,0 +1,144 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.axis2.jaxws.handler.context;
+
+import java.io.ByteArrayOutputStream;
+
+import javax.xml.soap.SOAPMessage;
+import javax.xml.transform.Source;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.stream.StreamResult;
+import javax.xml.ws.LogicalMessage;
+import javax.xml.ws.handler.LogicalMessageContext;
+
+import junit.framework.TestCase;
+
+import org.apache.axis2.jaxws.context.factory.MessageContextFactory;
+import org.apache.axis2.jaxws.core.MessageContext;
+import org.apache.axis2.jaxws.core.MEPContext;
+import org.apache.axis2.jaxws.handler.SoapMessageContext;
+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.registry.FactoryRegistry;
+
+/**
+ * A test suite for scenarios where the internal MessageContext is converted
+ * between handler context formats (SOAPMessageContext and LogicalMessageContext).
+ *
+ * The flows that need to be tested here are:
+ *
+ * 1) INBOUND: The MessageContext will be converted from a LogicalMessageContext
+ * to a SOAPMessageContext. This drives converting the OM message
+ * to an SAAJ SOAPMessage among other things.
+ *
+ * specific tests:
+ * - Normal message
+ * - Fault message
+ *
+ * 2) OUTBOUND: The MessageContext will be converted from a SOAPMessageContext
+ * to a LogicalMessageContext. This will drive conversion from
+ * an SAAJ SOAPMessage back to an OM (there are some very tricky
+ * pieces of code contained within that scenario).
+ *
+ * specific test:
+ * - Normal message
+ * - Fault message
+ */
+public class CompositeMessageContextTests extends TestCase {
+
+ private final String FAULT_INPUT = "sample fault input";
+
+ /**
+ * A test that mimics the inbound flow through a handler chain.
+ */
+ public void testInboundFaultFlow() throws Exception {
+ MessageContext mc = createSampleFaultMessageContext();
+
+ LogicalMessageContext lmc = MessageContextFactory.createLogicalMessageContext(mc);
+ LogicalMessage lm = lmc.getMessage();
+ Source payload = lm.getPayload();
+ assertTrue("The returned payload (Source) was null", payload != null);
+
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ StreamResult result = new StreamResult(baos);
+ Transformer t = TransformerFactory.newInstance().newTransformer();
+ t.transform(payload, result);
+
+ String content = new String(baos.toByteArray());
+ assertTrue("The returned content (String) from the payload was null", content != null);
+ assertTrue("The <faultcode> element was not found", content.indexOf("faultcode") > -1);
+ assertTrue("The <faultstring> element was not found", content.indexOf("faultstring") > -1);
+ assertTrue("The fault did not contain the expected fault string", content.indexOf(FAULT_INPUT) > -1);
+
+ SoapMessageContext smc = MessageContextFactory.createSoapMessageContext(mc);
+ SOAPMessage sm = smc.getMessage();
+ assertTrue("The returned SOAPMessage was null", sm != null);
+ assertTrue("The SOAPMessage did not contain a SOAPBody", sm.getSOAPBody() != null);
+ assertTrue("The SOAPBody did not contain a SOAPFault", sm.getSOAPBody().getFault() != null);
+ }
+
+ /**
+ * A test that mimics the outbound flow through a handler chain.
+ */
+ public void testOutboundFaultFlow() throws Exception {
+ MessageContext mc = createSampleFaultMessageContext();
+
+ SoapMessageContext smc = MessageContextFactory.createSoapMessageContext(mc);
+ SOAPMessage sm = smc.getMessage();
+ assertTrue("The returned SOAPMessage was null", sm != null);
+ assertTrue("The SOAPMessage did not contain a SOAPBody", sm.getSOAPBody() != null);
+ assertTrue("The SOAPBody did not contain a SOAPFault", sm.getSOAPBody().getFault() != null);
+
+ LogicalMessageContext lmc = MessageContextFactory.createLogicalMessageContext(mc);
+ LogicalMessage lm = lmc.getMessage();
+ Source payload = lm.getPayload();
+ assertTrue("The returned payload (Source) was null", payload != null);
+
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ StreamResult result = new StreamResult(baos);
+ Transformer t = TransformerFactory.newInstance().newTransformer();
+ t.transform(payload, result);
+
+ String content = new String(baos.toByteArray());
+ assertTrue("The returned content (String) from the payload was null", content != null);
+ assertTrue("The <faultcode> element was not found", content.indexOf("faultcode") > -1);
+ assertTrue("The <faultstring> element was not found", content.indexOf("faultstring") > -1);
+ assertTrue("The fault did not contain the expected fault string", content.indexOf(FAULT_INPUT) > -1);
+ }
+
+ private MessageContext createSampleFaultMessageContext() throws Exception {
+ MessageFactory factory = (MessageFactory) FactoryRegistry.getFactory(MessageFactory.class);
+ Message msg = factory.create(Protocol.soap11);
+
+ XMLFaultReason reason = new XMLFaultReason(FAULT_INPUT);
+ XMLFault fault = new XMLFault(XMLFaultCode.SENDER, reason);
+ msg.setXMLFault(fault);
+
+ MessageContext mc = new MessageContext();
+ mc.setMEPContext(new MEPContext(mc));
+ mc.setMessage(msg);
+
+ return mc;
+ }
+}
\ No newline at end of file
Modified: webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/handler/context/LogicalMessageContextTests.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/handler/context/LogicalMessageContextTests.java?view=diff&rev=551215&r1=551214&r2=551215
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/handler/context/LogicalMessageContextTests.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/handler/context/LogicalMessageContextTests.java Wed Jun 27 09:08:51 2007
@@ -59,6 +59,11 @@
private final String INPUT = "sample input";
private final String FAULT_INPUT = "sample fault input";
+ private final String sampleSOAP11FaultPayload =
+ "<soapenv:Fault xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\">"
+ + "<faultcode>soapenv:Server</faultcode>" + "<faultstring>" + FAULT_INPUT
+ + "</faultstring>" + "</soapenv:Fault>";
+
public LogicalMessageContextTests(String name) {
super(name);
}
@@ -206,6 +211,31 @@
EchoString echo = (EchoString) obj;
assertTrue("The EchoString object had null input", echo.getInput() != null);
assertTrue("The EchoString object had bad input: " + echo.getInput(), echo.getInput().equals(INPUT));
+ }
+
+
+ public void testConvertMessageToFault() throws Exception {
+ LogicalMessageContext lmc = createSampleContext();
+
+ LogicalMessage msg = lmc.getMessage();
+ assertTrue("The returned LogicalMessage was null", msg != null);
+
+ Source payload = msg.getPayload();
+ assertTrue("The returned payload (Source) was null", payload != null);
+
+ String resultContent = _getStringFromSource(payload);
+ assertTrue("The content returned was null", resultContent != null);
+
+ ByteArrayInputStream bais = new ByteArrayInputStream(sampleSOAP11FaultPayload.getBytes());
+ StreamSource faultSource = new StreamSource(bais);
+
+ msg.setPayload(faultSource);
+
+ Source newFaultSource = msg.getPayload();
+ assertTrue("The new fault content returned was null", faultSource != null);
+
+ String newFaultContent = _getStringFromSource(newFaultSource);
+ assertTrue("The new fault content returned was invalid", newFaultContent.equals(sampleSOAP11FaultPayload));
}
private LogicalMessageContext createSampleContext() throws Exception {
Modified: webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/message/FaultTests.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/message/FaultTests.java?view=diff&rev=551215&r1=551214&r2=551215
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/message/FaultTests.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/message/FaultTests.java Wed Jun 27 09:08:51 2007
@@ -16,16 +16,23 @@
*/
package org.apache.axis2.jaxws.message;
+import java.io.ByteArrayOutputStream;
import java.io.StringReader;
import java.util.Locale;
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamReader;
+import javax.xml.transform.Source;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.stream.StreamResult;
import junit.framework.TestCase;
import org.apache.axiom.om.OMElement;
import org.apache.axiom.soap.impl.builder.StAXSOAPModelBuilder;
+import org.apache.axis2.jaxws.message.factory.BlockFactory;
import org.apache.axis2.jaxws.message.factory.MessageFactory;
+import org.apache.axis2.jaxws.message.factory.SourceBlockFactory;
import org.apache.axis2.jaxws.registry.FactoryRegistry;
/**
@@ -275,6 +282,55 @@
fail(e.toString());
}
}
+
+
+ public void testGetSOAP11XMLFaultAsOM() throws Exception {
+ MessageFactory factory = (MessageFactory) FactoryRegistry.getFactory(MessageFactory.class);
+ Message msg = factory.create(Protocol.soap11);
+
+ XMLFaultReason reason = new XMLFaultReason("sample fault reason");
+ XMLFault fault = new XMLFault(XMLFaultCode.SENDER, reason);
+ msg.setXMLFault(fault);
+
+ OMElement om = msg.getAsOMElement();
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ om.serializeAndConsume(baos);
+
+ String env = new String(baos.toByteArray());
+ assertTrue(env.indexOf("faultcode") > 0);
+ assertTrue(env.indexOf("faultstring") > 0);
+ }
+
+ public void testGetSOAP11XMLFaultAsBlock() throws Exception {
+ MessageFactory factory = (MessageFactory) FactoryRegistry.getFactory(MessageFactory.class);
+ Message msg = factory.create(Protocol.soap11);
+
+ XMLFaultReason reason = new XMLFaultReason("sample fault reason");
+ XMLFault fault = new XMLFault(XMLFaultCode.SENDER, reason);
+ msg.setXMLFault(fault);
+
+ BlockFactory bf = (BlockFactory) FactoryRegistry.getFactory(SourceBlockFactory.class);
+ Block b = msg.getBodyBlock(null, bf);
+
+ Source content = (Source) b.getBusinessObject(true);
+ byte[] bytes = _getBytes(content);
+ String faultContent = new String(bytes);
+
+ System.out.println(">> fault content: " + faultContent);
+ assertTrue(faultContent.indexOf("faultcode") > 0);
+ assertTrue(faultContent.indexOf("faultstring") > 0);
+ }
+
+ private byte[] _getBytes(Source input) throws Exception {
+ TransformerFactory tf = TransformerFactory.newInstance();
+ Transformer t = tf.newTransformer();
+
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ StreamResult output = new StreamResult(baos);
+
+ t.transform(input, output);
+
+ return baos.toByteArray();
+ }
}
-
Modified: webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/sample/AddNumbersHandlerTests.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/sample/AddNumbersHandlerTests.java?view=diff&rev=551215&r1=551214&r2=551215
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/sample/AddNumbersHandlerTests.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/sample/AddNumbersHandlerTests.java Wed Jun 27 09:08:51 2007
@@ -171,7 +171,7 @@
}
// TODO: disabled until handler support is more complete
- public void _testAddNumbersHandlerWithFault() {
+ public void testAddNumbersHandlerWithFault() {
try{
TestLogger.logger.debug("----------------------------------");
TestLogger.logger.debug("test: " + getName());
---------------------------------------------------------------------
To unsubscribe, e-mail: axis-cvs-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-cvs-help@ws.apache.org