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 gd...@apache.org on 2007/06/08 18:22:19 UTC
svn commit: r545548 - in /webservices/axis2/trunk/java/modules:
integration/test/org/apache/axis2/integration/ kernel/src/org/apache/axis2/
kernel/src/org/apache/axis2/addressing/
kernel/src/org/apache/axis2/transport/local/ kernel/src/org/apache/axis2...
Author: gdaniels
Date: Fri Jun 8 09:22:17 2007
New Revision: 545548
URL: http://svn.apache.org/viewvc?view=rev&rev=545548
Log:
** NOTE ** This commit goes along with http://svn.apache.org/viewvc?view=rev&rev=545542, so we will require a new Axiom SNAPSHOT for the new test to pass.
* Rejigger the local transport so it serializes, rather than rethrows, AxisFaults that come from the receiving AxisEngine. Transports, IMO, should not have to do this job - will comment on this on axis-dev.
* Add robust-in-only as a supported default MEP for LocalTestCase
* Fix AXIS2-2752, improve AxisFault JavaDoc, check in test.
Added:
webservices/axis2/trunk/java/modules/kernel/test/org/apache/axis2/faults/
webservices/axis2/trunk/java/modules/kernel/test/org/apache/axis2/faults/FaultSerializationTest.java
Modified:
webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/integration/LocalTestCase.java
webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/AxisFault.java
webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/addressing/AddressingHelper.java
webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/local/LocalTransportReceiver.java
webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/util/MessageContextBuilder.java
Modified: webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/integration/LocalTestCase.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/integration/LocalTestCase.java?view=diff&rev=545548&r1=545547&r2=545548
==============================================================================
--- webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/integration/LocalTestCase.java (original)
+++ webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/integration/LocalTestCase.java Fri Jun 8 09:22:17 2007
@@ -37,6 +37,7 @@
import org.apache.axis2.rpc.client.RPCServiceClient;
import org.apache.axis2.transport.local.LocalTransportReceiver;
import org.apache.axis2.transport.local.LocalTransportSender;
+import org.apache.axiom.soap.SOAP12Constants;
/**
* LocalTestCase is an extendable base class which provides common functionality
@@ -79,6 +80,8 @@
new RawXMLINOnlyMessageReceiver());
serverConfig.addMessageReceiver(WSDL2Constants.MEP_URI_IN_OUT,
new RawXMLINOutMessageReceiver());
+ serverConfig.addMessageReceiver(WSDL2Constants.MEP_URI_ROBUST_IN_ONLY,
+ new RawXMLINOutMessageReceiver());
///////////////////////////////////////////////////////////////////////
// And client side
@@ -133,12 +136,7 @@
* @throws AxisFault if there's a problem
*/
protected ServiceClient getClient() throws AxisFault {
- TransportOutDescription td = new TransportOutDescription("local");
- td.setSender(sender);
-
- Options opts = new Options();
- opts.setTransportOut(td);
-
+ Options opts = getOptions();
ServiceClient client = new ServiceClient(clientCtx, null);
client.setOptions(opts);
return client;
@@ -153,12 +151,7 @@
* @throws AxisFault if there's a problem
*/
protected RPCServiceClient getRPCClient() throws AxisFault {
- TransportOutDescription td = new TransportOutDescription("local");
- td.setSender(sender);
-
- Options opts = new Options();
- opts.setTransportOut(td);
-
+ Options opts = getOptions();
RPCServiceClient client = new RPCServiceClient(clientCtx, null);
client.setOptions(opts);
return client;
@@ -174,18 +167,28 @@
* @throws AxisFault if there's a problem
*/
protected ServiceClient getClient(String serviceName, String operationName) throws AxisFault {
- TransportOutDescription td = new TransportOutDescription("local");
- td.setSender(sender);
-
- Options opts = new Options();
- opts.setTransportOut(td);
-
String url = LocalTransportReceiver.CONFIG_CONTEXT.getServiceContextPath()+"/"+serviceName;
+ Options opts = getOptions();
opts.setTo(new EndpointReference(url));
opts.setAction(operationName);
ServiceClient client = new ServiceClient(clientCtx, null);
client.setOptions(opts);
return client;
+ }
+
+ /**
+ * Get an Options object initialized with the right transport info, defaulting to SOAP 1.2
+ *
+ * @return pre-initialized Options object
+ */
+ protected Options getOptions() {
+ TransportOutDescription td = new TransportOutDescription("local");
+ td.setSender(sender);
+
+ Options opts = new Options();
+ opts.setTransportOut(td);
+ opts.setSoapVersionURI(SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI);
+ return opts;
}
}
Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/AxisFault.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/AxisFault.java?view=diff&rev=545548&r1=545547&r2=545548
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/AxisFault.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/AxisFault.java Fri Jun 8 09:22:17 2007
@@ -26,7 +26,6 @@
import org.apache.axiom.soap.SOAPFaultRole;
import org.apache.axiom.soap.SOAPHeaderBlock;
import org.apache.axiom.soap.SOAPFaultSubCode;
-import org.apache.axiom.soap.SOAP12Constants;
import org.apache.axis2.context.MessageContext;
import javax.xml.namespace.QName;
@@ -91,7 +90,7 @@
private SOAPFaultDetail soapFaultDetail;
/**
- * If not null, the messageContext represents the fault as it
+ * If not null, this MessageContext represents the fault as it
* should be returned. This is used by higher-level layers
* that want to generate the message themselves so that
* processing may take place before they return control (e.g. JAX-WS.)
@@ -114,7 +113,9 @@
/**
- * @param message
+ * Constructor.
+ *
+ * @param message the human-readable text describing the fault
*/
public AxisFault(String message) {
this.message = message;
@@ -122,17 +123,26 @@
}
/**
- * These are the absolute minimum to construct a meaningful SOAPFault from user's information
+ * Constructor
*
* @param faultCode - fault code of the message as a QName
* @param faultReason - the reason for the fault. The language will be defaulted to 'en'
- * @param cause
+ * @param cause embedded fault which caused this one
*/
public AxisFault(QName faultCode, String faultReason, Throwable cause) {
this(faultReason, cause);
setFaultCode(faultCode);
}
+ /**
+ * Constructor
+ *
+ * @param faultCode a QName for the fault code
+ * @param faultReason the reason for the fault. The language will be defaulted to 'en'
+ * @param faultNode a URL identifying the SOAP node generating this fault, or null
+ * @param faultRole a URL identifying the SOAP role active when generating this fault, or null
+ * @param faultDetail arbitrary XML containing application-specific fault data
+ */
public AxisFault(QName faultCode, String faultReason, String faultNode, String faultRole,
OMElement faultDetail) {
this(faultReason, faultCode);
@@ -146,10 +156,11 @@
* in this class to get and set things.
* Any of the parameters can be null
*
- * @param soapFaultCode
- * @param soapFaultReason
- * @param soapFaultNode
- * @param soapFaultRole
+ * @param soapFaultCode the fault code
+ * @param soapFaultReason the fault reason
+ * @param soapFaultNode the SOAPFaultNode representing the source node for this fault
+ * @param soapFaultRole the SOAPFaultRole representing the source role for this fault
+ * @param soapFaultDetail the SOAPFaultDetail containing any application-specific info
*/
public AxisFault(SOAPFaultCode soapFaultCode, SOAPFaultReason soapFaultReason,
SOAPFaultNode soapFaultNode, SOAPFaultRole soapFaultRole,
@@ -192,6 +203,8 @@
// cause = new Exception(exceptionElement.getText());
// }
+ // TODO - Wha? Details can have multiple elements, why take the first child here?
+ // TODO - Review the API for details
// setting the first child element of the fault detail as this.detail
this.detail = soapFaultDetail.getFirstElement();
@@ -230,6 +243,8 @@
}
/**
+ * Constructor.
+ *
* @param messageText - this will appear as the Text in the Reason information item of SOAP Fault
* @param faultCode - this will appear as the Value in the Code information item of SOAP Fault
*/
@@ -239,8 +254,10 @@
}
/**
- * @param messageText - this will appear as the Text in the Reason information item of SOAP Fault
- * @param faultCode - this will appear as the Value in the Code information item of SOAP Fault
+ * Constructor
+ *
+ * @param messageText this will appear as the Text in the Reason information item of SOAP Fault
+ * @param faultCode this will appear as the Value in the Code information item of SOAP Fault
*/
public AxisFault(String messageText, QName faultCode) {
this(messageText);
@@ -248,8 +265,10 @@
}
/**
- * @param message
- * @param cause
+ * Constructor
+ *
+ * @param message this will appear as the Text in the Reason information item of SOAP Fault
+ * @param cause the embedded Throwable that caused this fault
*/
public AxisFault(String message, Throwable cause) {
super(message, cause);
@@ -285,7 +304,7 @@
* that contains the actual fault representation.
*
* @param message A string that's really only useful for logging.
- * @param faultMessageContext
+ * @param faultMessageContext A MessageContext which must contain SOAP fault info
*/
public AxisFault(String message, MessageContext faultMessageContext) {
this(message);
@@ -443,7 +462,7 @@
/**
* Set the entire detail element of the fault
*
- * @param detail
+ * @param detail an OMElement which MUST be
*/
public void setDetail(OMElement detail) {
this.detail = detail;
@@ -460,7 +479,9 @@
}
/**
- * Set the faulting node uri. SOAP1.2
+ * Set the faulting node uri. (SOAP1.2)
+ *
+ * @param nodeURI a String containing a URI indicating which SOAP Node faulted
*/
public void setNodeURI(String nodeURI) {
this.nodeURI = nodeURI;
@@ -540,8 +561,9 @@
}
/**
- * Set the (OPTIONAL) action value for the fault message
- * @param faultAction
+ * Set the (OPTIONAL) action value for the fault message
+ *
+ * @param faultAction a String containing an action URI for the fault
*/
public void setFaultAction(String faultAction) {
this.faultAction = faultAction;
Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/addressing/AddressingHelper.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/addressing/AddressingHelper.java?view=diff&rev=545548&r1=545547&r2=545548
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/addressing/AddressingHelper.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/addressing/AddressingHelper.java Fri Jun 8 09:22:17 2007
@@ -58,7 +58,7 @@
* spec.
*
* @param messageContext
- * @see isReplyRedirected
+ * @see #isReplyRedirected(org.apache.axis2.context.MessageContext)
*/
public static boolean isFaultRedirected(MessageContext messageContext) {
EndpointReference faultTo = messageContext.getFaultTo();
Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/local/LocalTransportReceiver.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/local/LocalTransportReceiver.java?view=diff&rev=545548&r1=545547&r2=545548
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/local/LocalTransportReceiver.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/local/LocalTransportReceiver.java Fri Jun 8 09:22:17 2007
@@ -21,6 +21,8 @@
import org.apache.axiom.soap.SOAPEnvelope;
import org.apache.axis2.AxisFault;
import org.apache.axis2.Constants;
+import org.apache.axis2.util.Utils;
+import org.apache.axis2.util.MessageContextBuilder;
import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.builder.BuilderUtil;
import org.apache.axis2.context.ConfigurationContext;
@@ -48,37 +50,51 @@
this.sender = sender;
}
- public void processMessage(InputStream in, EndpointReference to, String action) throws AxisFault {
+ public void processMessage(InputStream in, EndpointReference to, String action)
+ throws AxisFault {
+ MessageContext msgCtx = confContext.createMessageContext();
+ TransportInDescription tIn = confContext.getAxisConfiguration().getTransportIn(
+ Constants.TRANSPORT_LOCAL);
+ TransportOutDescription tOut = confContext.getAxisConfiguration().getTransportOut(
+ Constants.TRANSPORT_LOCAL);
try {
- TransportInDescription tIn = confContext.getAxisConfiguration().getTransportIn(
- Constants.TRANSPORT_LOCAL);
- TransportOutDescription tOut = confContext.getAxisConfiguration().getTransportOut(
- Constants.TRANSPORT_LOCAL);
tOut.setSender(new LocalResponder(sender));
- MessageContext msgCtx = confContext.createMessageContext();
msgCtx.setTransportIn(tIn);
msgCtx.setTransportOut(tOut);
+ msgCtx.setProperty(MessageContext.TRANSPORT_OUT, sender.getResponse());
msgCtx.setTo(to);
msgCtx.setWSAAction(action);
msgCtx.setServerSide(true);
- msgCtx.setProperty(MessageContext.TRANSPORT_OUT, sender.getResponse());
InputStreamReader streamReader = new InputStreamReader(in);
- OMXMLParserWrapper builder = BuilderUtil.getBuilder(streamReader);
+ OMXMLParserWrapper builder;
+ try {
+ builder = BuilderUtil.getBuilder(streamReader);
+ } catch (XMLStreamException e) {
+ throw AxisFault.makeFault(e);
+ }
SOAPEnvelope envelope = (SOAPEnvelope) builder.getDocumentElement();
msgCtx.setEnvelope(envelope);
- AxisEngine engine = new AxisEngine(confContext);
-
- engine.receive(msgCtx);
- } catch (XMLStreamException e) {
- throw AxisFault.makeFault(e);
- } catch (FactoryConfigurationError e) {
- throw AxisFault.makeFault(e);
+ AxisEngine.receive(msgCtx);
+ } catch (AxisFault e) {
+ // write the fault back.
+ try {
+ MessageContext faultContext =
+ MessageContextBuilder.createFaultMessageContext(msgCtx, e);
+
+ faultContext.setTransportOut(tOut);
+ faultContext.setProperty(MessageContext.TRANSPORT_OUT, sender.getResponse());
+
+ AxisEngine.sendFault(faultContext);
+ } catch (AxisFault axisFault) {
+ // can't handle this, so just throw it
+ throw axisFault;
+ }
}
}
}
Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/util/MessageContextBuilder.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/util/MessageContextBuilder.java?view=diff&rev=545548&r1=545547&r2=545548
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/util/MessageContextBuilder.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/util/MessageContextBuilder.java Fri Jun 8 09:22:17 2007
@@ -428,12 +428,12 @@
SOAPProcessingException soapException = null;
AxisFault axisFault = null;
- if (e != null) {
- if (e instanceof AxisFault) {
- axisFault = (AxisFault) e;
- } else if (e.getCause() instanceof AxisFault) {
- axisFault = (AxisFault) e.getCause();
- }
+ if (e == null) return envelope;
+
+ if (e instanceof AxisFault) {
+ axisFault = (AxisFault) e;
+ } else if (e.getCause() instanceof AxisFault) {
+ axisFault = (AxisFault) e.getCause();
}
if (axisFault != null) {
@@ -450,8 +450,6 @@
if (axisFault.getCause() instanceof SOAPProcessingException) {
soapException = (SOAPProcessingException) axisFault.getCause();
}
- } else {
- // we have recd an instance of just the Exception class
}
// user can set the fault information to the message context or to the AxisFault itself.
@@ -460,7 +458,6 @@
Object faultCode = context.getProperty(SOAP12Constants.SOAP_FAULT_CODE_LOCAL_NAME);
String soapFaultCode = "";
-
if (faultCode != null) {
fault.setCode((SOAPFaultCode) faultCode);
} else if (soapException != null) {
@@ -502,46 +499,36 @@
if(faultCode == null && !context.isSOAP11()){
fault.getCode().getValue().setText(soapFaultCode);
}
- Object faultReason = context.getProperty(SOAP12Constants.SOAP_FAULT_REASON_LOCAL_NAME);
- String message = "";
+ SOAPFaultReason faultReason = (SOAPFaultReason)context.getProperty(
+ SOAP12Constants.SOAP_FAULT_REASON_LOCAL_NAME);
+ if (faultReason == null && axisFault != null) {
+ faultReason = axisFault.getFaultReasonElement();
+ }
if (faultReason != null) {
- fault.setReason((SOAPFaultReason) faultReason);
- if(context.isSOAP11()) {
- message = fault.getReason().getText();
- } else {
- message = fault.getReason().getFirstSOAPText().getText();
- }
- } else if (soapException != null) {
- message = soapException.getMessage();
- } else if (axisFault != null) {
- if (axisFault.getFaultReasonElement() != null) {
- fault.setReason(axisFault.getFaultReasonElement());
- } else {
+ fault.setReason(faultReason);
+ } else {
+ String message = "";
+ if (soapException != null) {
+ message = soapException.getMessage();
+ } else if (axisFault != null) {
+ // Couldn't find FaultReasonElement, try reason string
message = axisFault.getReason();
- if (message == null || "".equals(message)) {
- message = getFaultReasonFromException(e, context);
- }
}
- } else {
- if (e != null && (message == null || "".equals(message))) {
+
+ if (message == null || "".equals(message)) {
message = getFaultReasonFromException(e, context);
}
- }
- // defaulting to reason, unknown, if no reason is available
- if (faultReason == null) {
- message = ("".equals(message) || (message == null))
- ? "unknown"
- : message;
- if(context.isSOAP11()) {
+ if (message == null || "".equals(message)) message = "unknown";
+
+ if (context.isSOAP11()) {
fault.getReason().setText(message);
} else {
fault.getReason().getFirstSOAPText().setLang("en-US");
fault.getReason().getFirstSOAPText().setText(message);
}
}
-
Object faultRole = context.getProperty(SOAP12Constants.SOAP_FAULT_ROLE_LOCAL_NAME);
if (faultRole != null) {
Added: webservices/axis2/trunk/java/modules/kernel/test/org/apache/axis2/faults/FaultSerializationTest.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/test/org/apache/axis2/faults/FaultSerializationTest.java?view=auto&rev=545548
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/test/org/apache/axis2/faults/FaultSerializationTest.java (added)
+++ webservices/axis2/trunk/java/modules/kernel/test/org/apache/axis2/faults/FaultSerializationTest.java Fri Jun 8 09:22:17 2007
@@ -0,0 +1,73 @@
+/*
+ * Copyright 2007 The Apache Software Foundation.
+ *
+ * Licensed 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.faults;
+
+import junit.framework.TestCase;
+import org.apache.axiom.soap.SOAPFactory;
+import org.apache.axiom.soap.SOAPFaultCode;
+import org.apache.axiom.soap.SOAPFaultValue;
+import org.apache.axiom.soap.SOAP12Constants;
+import org.apache.axiom.soap.SOAPFaultReason;
+import org.apache.axiom.soap.SOAPFaultText;
+import org.apache.axiom.soap.SOAPFaultDetail;
+import org.apache.axiom.om.OMAbstractFactory;
+import org.apache.axiom.om.OMElement;
+import org.apache.axis2.AxisFault;
+import org.apache.axis2.transport.TransportUtils;
+import org.apache.axis2.context.MessageContext;
+import org.apache.axis2.context.ConfigurationContextFactory;
+import org.apache.axis2.context.ConfigurationContext;
+import org.apache.axis2.util.MessageContextBuilder;
+
+import javax.xml.namespace.QName;
+import java.io.ByteArrayOutputStream;
+
+public class FaultSerializationTest extends TestCase {
+ public void testFaultSerialization() throws Exception {
+ final String REASON = "ReasonValue";
+
+ SOAPFactory soapFactory = OMAbstractFactory.getSOAP12Factory();
+ SOAPFaultCode soapFaultCode = soapFactory.createSOAPFaultCode();
+ SOAPFaultValue soapFaultValue = soapFactory.createSOAPFaultValue(soapFaultCode);
+ soapFaultValue.setText(new QName(SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI, "Sender"));
+
+ SOAPFaultReason soapFaultReason = soapFactory.createSOAPFaultReason();
+ SOAPFaultText soapFaultText = soapFactory.createSOAPFaultText(soapFaultReason);
+ soapFaultText.setText(REASON);
+
+ SOAPFaultDetail soapFaultDetail = soapFactory.createSOAPFaultDetail();
+ QName qName = new QName("http://mycompany.com", "FaultException", "ex");
+ OMElement exception = soapFactory.createOMElement(qName, soapFaultDetail);
+ exception.setText("Detail text");
+ AxisFault fault = new AxisFault(soapFaultCode, soapFaultReason, null, null,
+ soapFaultDetail);
+
+ ConfigurationContext cc = ConfigurationContextFactory.createDefaultConfigurationContext();
+ MessageContext ctx = cc.createMessageContext();
+ SOAPFactory fac = OMAbstractFactory.getSOAP12Factory();
+ ctx.setEnvelope(fac.getDefaultEnvelope());
+ MessageContext faultCtx = MessageContextBuilder.createFaultMessageContext(ctx, fault);
+
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ TransportUtils.writeMessage(faultCtx, bos);
+
+ String result = new String(bos.toByteArray());
+
+ // For right now, just making sure we have a test for AXIS2-2752
+ // Confirm reason was correctly processed
+ assertTrue("Incorrect or missing reason!", result.indexOf(REASON) > -1);
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: axis-cvs-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-cvs-help@ws.apache.org