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 ch...@apache.org on 2005/07/31 09:11:14 UTC
svn commit: r226611 - in /webservices/axis/trunk/java/modules:
core/src/org/apache/axis2/clientapi/ core/src/org/apache/axis2/context/
core/src/org/apache/axis2/engine/ core/src/org/apache/axis2/transport/
core/src/org/apache/axis2/transport/http/ core...
Author: chinthaka
Date: Sun Jul 31 00:10:07 2005
New Revision: 226611
URL: http://svn.apache.org/viewcvs?rev=226611&view=rev
Log:
- now determines the SOAP version from the transport information
- sends fault message from the correct SOAP version
- added a flag to determine whether to throw an exception or to return SOAP message with Fault in it
Modified:
webservices/axis/trunk/java/modules/core/src/org/apache/axis2/clientapi/InOutMEPClient.java
webservices/axis/trunk/java/modules/core/src/org/apache/axis2/clientapi/MEPClient.java
webservices/axis/trunk/java/modules/core/src/org/apache/axis2/context/MessageContext.java
webservices/axis/trunk/java/modules/core/src/org/apache/axis2/engine/AxisEngine.java
webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/TransportUtils.java
webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/HTTPTransportUtils.java
webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/mail/MailWorker.java
webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/mail/server/MailSorter.java
webservices/axis/trunk/java/modules/samples/project.xml
webservices/axis/trunk/java/modules/samples/test/org/apache/axis2/engine/FaultHandlingTest.java
Modified: webservices/axis/trunk/java/modules/core/src/org/apache/axis2/clientapi/InOutMEPClient.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/core/src/org/apache/axis2/clientapi/InOutMEPClient.java?rev=226611&r1=226610&r2=226611&view=diff
==============================================================================
--- webservices/axis/trunk/java/modules/core/src/org/apache/axis2/clientapi/InOutMEPClient.java (original)
+++ webservices/axis/trunk/java/modules/core/src/org/apache/axis2/clientapi/InOutMEPClient.java Sun Jul 31 00:10:07 2005
@@ -17,8 +17,6 @@
*/
package org.apache.axis2.clientapi;
-import javax.xml.namespace.QName;
-
import org.apache.axis2.AxisFault;
import org.apache.axis2.Constants;
import org.apache.axis2.addressing.EndpointReference;
@@ -39,6 +37,8 @@
import org.apache.axis2.util.threadpool.AxisWorker;
import org.apache.wsdl.WSDLConstants;
+import javax.xml.namespace.QName;
+
/**
* This Class capture handling the In-Out type Method invocations. this provides the
* methods to do blocking and non blocking invocation. The basic API is based on the
@@ -108,21 +108,19 @@
// }
/**
- * This invocation done via this method blocks till the result arrives, using this method does not indicate
- * anyhting about the transport used or the nature of the transport.
+ * This invocation done via this method blocks till the result arrives, using this method does not indicate
+ * anyhting about the transport used or the nature of the transport.
* e.g. invocation done with this method might
* <ol>
- * <li>send request via http and recevie the response via the return path of the same http connection</li>
- * <li>send request via http and recevie the response different http connection</li>
- * <li>send request via a email smtp and recevie the response via a email</li>
+ * <li>send request via http and recevie the response via the return path of the same http connection</li>
+ * <li>send request via http and recevie the response different http connection</li>
+ * <li>send request via a email smtp and recevie the response via a email</li>
* </ol>
- *
*/
- public MessageContext invokeBlocking(
- OperationDescription axisop,
- final MessageContext msgctx)
- throws AxisFault {
+ public MessageContext invokeBlocking(OperationDescription axisop,
+ final MessageContext msgctx)
+ throws AxisFault {
prepareInvocation(axisop, msgctx);
if (useSeparateListener) {
//This mean doing a Request-Response invocation using two channel. If the
@@ -148,7 +146,7 @@
//process the resule of the invocation
if (callback.envelope != null) {
MessageContext resMsgctx =
- new MessageContext(serviceContext.getEngineContext());
+ new MessageContext(serviceContext.getEngineContext());
resMsgctx.setEnvelope(callback.envelope);
return resMsgctx;
} else {
@@ -169,46 +167,46 @@
//find and set the Operation Context
ConfigurationContext sysContext = serviceContext.getEngineContext();
AxisConfiguration registry = sysContext.getAxisConfiguration();
- msgctx.setOperationContext(
- OperationContextFactory.createMEPContext(
- WSDLConstants.MEP_CONSTANT_IN_OUT,
+ msgctx.setOperationContext(OperationContextFactory.createMEPContext(WSDLConstants.MEP_CONSTANT_IN_OUT,
axisop,
serviceContext));
//Send the SOAP Message and receive a response
MessageContext response =
- TwoWayTransportBasedSender.send(msgctx, listenerTransport);
+ TwoWayTransportBasedSender.send(msgctx, listenerTransport);
//check for a fault and return the result
SOAPEnvelope resenvelope = response.getEnvelope();
if (resenvelope.getBody().hasFault()) {
SOAPFault soapFault = resenvelope.getBody().getFault();
Exception ex = soapFault.getException();
- //does the SOAPFault has a detail element for Excpetion
- if(ex != null){
- throw new AxisFault(ex);
- }else{
- //if detail element not present let us throw the exception with Reason
- throw new AxisFault(soapFault.getReason().getText());
+
+ if (isExceptionToBeThrownOnSOAPFault) {
+ //does the SOAPFault has a detail element for Excpetion
+ if (ex != null) {
+ throw new AxisFault(ex);
+ } else {
+ //if detail element not present let us throw the exception with Reason
+ throw new AxisFault(soapFault.getReason().getText());
+ }
}
}
return response;
}
}
- /**
- * This invocation done via this method blocks till the result arrives, using this method does not indicate
- * anyhting about the transport used or the nature of the transport.
- */
- public void invokeNonBlocking(
- final OperationDescription axisop,
- final MessageContext msgctx,
- final Callback callback)
- throws AxisFault {
+ /**
+ * This invocation done via this method blocks till the result arrives, using this method does not indicate
+ * anyhting about the transport used or the nature of the transport.
+ */
+ public void invokeNonBlocking(final OperationDescription axisop,
+ final MessageContext msgctx,
+ final Callback callback)
+ throws AxisFault {
prepareInvocation(axisop, msgctx);
msgctx.setTo(to);
try {
final ConfigurationContext syscontext =
- serviceContext.getEngineContext();
+ serviceContext.getEngineContext();
AxisEngine engine = new AxisEngine(syscontext);
checkTransport(msgctx);
@@ -221,31 +219,27 @@
axisop.setMessageReciever(callbackReceiver);
callbackReceiver.addCallback(messageID, callback);
//set the replyto such that the response will arrive at the transport listener started
- msgctx.setReplyTo(
- ListenerManager.replyToEPR(
- serviceContext
- .getServiceConfig()
- .getName()
- .getLocalPart()
- + "/"
- + axisop.getName().getLocalPart(),
+ msgctx.setReplyTo(ListenerManager.replyToEPR(serviceContext
+ .getServiceConfig()
+ .getName()
+ .getLocalPart()
+ + "/"
+ + axisop.getName().getLocalPart(),
listenerTransport.getName().getLocalPart()));
- //create and set the Operation context
- msgctx.setOperationContext(
- axisop.findOperationContext(msgctx, serviceContext));
+ //create and set the Operation context
+ msgctx.setOperationContext(axisop.findOperationContext(msgctx, serviceContext));
msgctx.setServiceContext(serviceContext);
//send the message
engine.send(msgctx);
} else {
- //here a bloking invocation happens in a new thrad, so the progamming model is
+ //here a bloking invocation happens in a new thrad, so the progamming model is
//non blocking
- serviceContext.getEngineContext().getThreadPool().addWorker(
- new NonBlockingInvocationWorker(callback, axisop, msgctx));
+ serviceContext.getEngineContext().getThreadPool().addWorker(new NonBlockingInvocationWorker(callback, axisop, msgctx));
}
} catch (OMException e) {
throw AxisFault.makeFault(e);
- }
+ }
}
@@ -272,26 +266,25 @@
* @throws AxisFault
*/
- public void setTransportInfo(
- String senderTransport,
- String listenerTransport,
- boolean useSeparateListener)
- throws AxisFault {
+ public void setTransportInfo(String senderTransport,
+ String listenerTransport,
+ boolean useSeparateListener)
+ throws AxisFault {
//here we check for a legal combination, for and example if the sendertransport is http and listner
//transport is smtp the invocation must using seperate transport
if (!useSeparateListener) {
boolean isTransportsEqual =
- senderTransport.equals(listenerTransport);
+ senderTransport.equals(listenerTransport);
boolean isATwoWaytransport =
- Constants.TRANSPORT_HTTP.equals(senderTransport)
+ Constants.TRANSPORT_HTTP.equals(senderTransport)
|| Constants.TRANSPORT_TCP.equals(senderTransport)
|| Constants.TRANSPORT_COMMONS_HTTP.equals(senderTransport);
boolean isCommonsAndHTTP =
- Constants.TRANSPORT_COMMONS_HTTP.equals(senderTransport)
+ Constants.TRANSPORT_COMMONS_HTTP.equals(senderTransport)
&& Constants.TRANSPORT_HTTP.equals(listenerTransport);
if (!isCommonsAndHTTP
- && (!isTransportsEqual || !isATwoWaytransport)) {
- throw new AxisFault(Messages.getMessage("useSeparateListenerLimited"));
+ && (!isTransportsEqual || !isATwoWaytransport)) {
+ throw new AxisFault(Messages.getMessage("useSeparateListenerLimited"));
}
} else {
this.useSeparateListener = useSeparateListener;
@@ -300,34 +293,34 @@
//find and set the transport details
AxisConfiguration axisConfig =
- serviceContext.getEngineContext().getAxisConfiguration();
+ serviceContext.getEngineContext().getAxisConfiguration();
this.listenerTransport =
- axisConfig.getTransportIn(new QName(listenerTransport));
+ axisConfig.getTransportIn(new QName(listenerTransport));
this.senderTransport =
- axisConfig.getTransportOut(new QName(senderTransport));
+ axisConfig.getTransportOut(new QName(senderTransport));
if (this.senderTransport == null) {
- throw new AxisFault(Messages.getMessage("unknownTransport",senderTransport));
+ throw new AxisFault(Messages.getMessage("unknownTransport", senderTransport));
}
if (this.listenerTransport == null) {
- throw new AxisFault(Messages.getMessage("unknownTransport",listenerTransport));
+ throw new AxisFault(Messages.getMessage("unknownTransport", listenerTransport));
}
//if seperate transport is used, start the required listeners
if (useSeparateListener == true) {
if (!serviceContext
- .getEngineContext()
- .getAxisConfiguration()
- .isEngaged(new QName(Constants.MODULE_ADDRESSING))) {
- throw new AxisFault(Messages.getMessage("2channelNeedAddressing"));
+ .getEngineContext()
+ .getAxisConfiguration()
+ .isEngaged(new QName(Constants.MODULE_ADDRESSING))) {
+ throw new AxisFault(Messages.getMessage("2channelNeedAddressing"));
}
- ListenerManager.makeSureStarted(
- listenerTransport,
- serviceContext.getEngineContext());
+ ListenerManager.makeSureStarted(listenerTransport,
+ serviceContext.getEngineContext());
}
}
/**
* Check has the transports are identified correctly
+ *
* @param msgctx
* @throws AxisFault
*/
@@ -337,11 +330,10 @@
}
if (listenerTransport == null) {
listenerTransport =
- serviceContext
+ serviceContext
.getEngineContext()
.getAxisConfiguration()
- .getTransportIn(
- senderTransport.getName());
+ .getTransportIn(senderTransport.getName());
}
if (msgctx.getTransportIn() == null) {
@@ -352,6 +344,7 @@
}
}
+
/**
* This Class act as the Callback that allow users to wait on the result
*/
@@ -367,16 +360,18 @@
error = e;
}
}
+
/**
- * Closing the Call, this will stop the started Transport Listeners. If there are multiple
+ * Closing the Call, this will stop the started Transport Listeners. If there are multiple
* request to send the Call should be kept open closing only when done
*/
public void close() throws AxisFault {
ListenerManager.stop(listenerTransport.getName().getLocalPart());
}
+
/**
- * This Class is the workhorse for a Non Blocking invocation that uses a
- * two way transport
+ * This Class is the workhorse for a Non Blocking invocation that uses a
+ * two way transport
*/
private class NonBlockingInvocationWorker implements AxisWorker {
@@ -384,10 +379,9 @@
private OperationDescription axisop;
private MessageContext msgctx;
- public NonBlockingInvocationWorker(
- Callback callback,
- OperationDescription axisop,
- MessageContext msgctx) {
+ public NonBlockingInvocationWorker(Callback callback,
+ OperationDescription axisop,
+ MessageContext msgctx) {
this.callback = callback;
this.axisop = axisop;
this.msgctx = msgctx;
@@ -395,15 +389,13 @@
public void doWork() {
try {
- msgctx.setOperationContext(
- OperationContextFactory.createMEPContext(
- WSDLConstants.MEP_CONSTANT_IN_OUT,
+ msgctx.setOperationContext(OperationContextFactory.createMEPContext(WSDLConstants.MEP_CONSTANT_IN_OUT,
axisop,
serviceContext));
msgctx.setServiceContext(serviceContext);
//send the request and wait for reponse
MessageContext response =
- TwoWayTransportBasedSender.send(msgctx, listenerTransport);
+ TwoWayTransportBasedSender.send(msgctx, listenerTransport);
//call the callback
SOAPEnvelope resenvelope = response.getEnvelope();
AsyncResult asyncResult = new AsyncResult(response);
Modified: webservices/axis/trunk/java/modules/core/src/org/apache/axis2/clientapi/MEPClient.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/core/src/org/apache/axis2/clientapi/MEPClient.java?rev=226611&r1=226610&r2=226611&view=diff
==============================================================================
--- webservices/axis/trunk/java/modules/core/src/org/apache/axis2/clientapi/MEPClient.java (original)
+++ webservices/axis/trunk/java/modules/core/src/org/apache/axis2/clientapi/MEPClient.java Sun Jul 31 00:10:07 2005
@@ -46,6 +46,14 @@
protected boolean doRestThroughPOST = false;
protected String wsaAction;
+ /*
+ If there is a SOAP Fault in the body of the incoming SOAP Message, system can be configured to
+ throw an exception with the details extracted from the information from the fault message.
+ This boolean variable will enable that facility. If this is false, the response message will just
+ be returned to the application, irrespective of whether it has a Fault or not.
+ */
+ protected boolean isExceptionToBeThrownOnSOAPFault = true;
+
//TODO try to find a better way to handle the GET
public void setRestThroughPOST(boolean b) {
doRestThroughPOST = b;
@@ -65,7 +73,7 @@
}
/**
- * prepare the message context for invocation, here the properties kept in the
+ * prepare the message context for invocation, here the properties kept in the
* MEPClient copied to the MessageContext
*/
protected void prepareInvocation(OperationDescription axisop, MessageContext msgCtx)
@@ -186,6 +194,18 @@
*/
public void setWsaAction(String string) {
wsaAction = string;
+ }
+
+ /**
+ *
+ * @param exceptionToBeThrownOnSOAPFault - If there is a SOAP Fault in the body of the incoming
+ * SOAP Message, system can be configured to throw an exception with the details extracted from
+ * the information from the fault message.
+ * This boolean variable will enable that facility. If this is false, the response message will just
+ * be returned to the application, irrespective of whether it has a Fault or not.
+ */
+ public void setExceptionToBeThrownOnSOAPFault(boolean exceptionToBeThrownOnSOAPFault) {
+ isExceptionToBeThrownOnSOAPFault = exceptionToBeThrownOnSOAPFault;
}
}
Modified: webservices/axis/trunk/java/modules/core/src/org/apache/axis2/context/MessageContext.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/core/src/org/apache/axis2/context/MessageContext.java?rev=226611&r1=226610&r2=226611&view=diff
==============================================================================
--- webservices/axis/trunk/java/modules/core/src/org/apache/axis2/context/MessageContext.java (original)
+++ webservices/axis/trunk/java/modules/core/src/org/apache/axis2/context/MessageContext.java Sun Jul 31 00:10:07 2005
@@ -642,4 +642,8 @@
return soapNamespaceURI;
}
+ public void setSoapNamespaceURI(String soapNamespaceURI) {
+ this.soapNamespaceURI = soapNamespaceURI;
+ }
+
}
Modified: webservices/axis/trunk/java/modules/core/src/org/apache/axis2/engine/AxisEngine.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/core/src/org/apache/axis2/engine/AxisEngine.java?rev=226611&r1=226610&r2=226611&view=diff
==============================================================================
--- webservices/axis/trunk/java/modules/core/src/org/apache/axis2/engine/AxisEngine.java (original)
+++ webservices/axis/trunk/java/modules/core/src/org/apache/axis2/engine/AxisEngine.java Sun Jul 31 00:10:07 2005
@@ -249,14 +249,15 @@
faultContext.setServerSide(true);
SOAPEnvelope envelope = null;
- if (processingContext.getEnvelope() != null && SOAP12Constants
+ if (processingContext.getSOAPVersion() != null && SOAP11Constants
.SOAP_ENVELOPE_NAMESPACE_URI
- .equals(processingContext.getEnvelope().getNamespace().getName())) {
+ .equals(processingContext.getSOAPVersion())) {
envelope =
- OMAbstractFactory.getSOAP12Factory().getDefaultFaultEnvelope();
+ OMAbstractFactory.getSOAP11Factory().getDefaultFaultEnvelope();
} else {
+ // Following will make SOAP 1.2 as the default, too.
envelope =
- OMAbstractFactory.getSOAP11Factory().getDefaultFaultEnvelope();
+ OMAbstractFactory.getSOAP12Factory().getDefaultFaultEnvelope();
}
@@ -315,7 +316,7 @@
// defaulting to SOAP 1.2
soapNamespaceURI = SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI;
} else {
- soapNamespaceURI = SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI;
+ soapNamespaceURI = context.getSOAPVersion();
}
Modified: webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/TransportUtils.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/TransportUtils.java?rev=226611&r1=226610&r2=226611&view=diff
==============================================================================
--- webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/TransportUtils.java (original)
+++ webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/TransportUtils.java Sun Jul 31 00:10:07 2005
@@ -87,6 +87,7 @@
XMLStreamReader xmlreader =
XMLInputFactory.newInstance().createXMLStreamReader(
reader);
+ msgContext.setSoapNamespaceURI(soapNamespaceURI);
builder = new StAXSOAPModelBuilder(xmlreader, soapNamespaceURI);
envelope = (SOAPEnvelope) builder.getDocumentElement();
}
Modified: webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/HTTPTransportUtils.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/HTTPTransportUtils.java?rev=226611&r1=226610&r2=226611&view=diff
==============================================================================
--- webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/HTTPTransportUtils.java (original)
+++ webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/HTTPTransportUtils.java Sun Jul 31 00:10:07 2005
@@ -80,7 +80,7 @@
msgContext.setTo(new EndpointReference(requestURI));
msgContext.setProperty(MessageContext.TRANSPORT_OUT, out);
msgContext.setServerSide(true);
-
+
SOAPEnvelope envelope = null;
StAXBuilder builder = null;
@@ -117,6 +117,7 @@
}
if (contentType.indexOf(SOAP12Constants.SOAP_12_CONTENT_TYPE) > -1) {
//it is SOAP 1.2
+ msgContext.setSoapNamespaceURI(SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI);
builder = new StAXSOAPModelBuilder(xmlreader, SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI);
envelope = (SOAPEnvelope) builder.getDocumentElement();
} else if (contentType.indexOf(SOAP11Constants.SOAP_11_CONTENT_TYPE) > -1) {
@@ -127,12 +128,15 @@
//If the content Type is text/xml (BTW which is the SOAP 1.1 Content type ) and
//the SOAP Action is absent it is rest !!
msgContext.setDoingREST(true);
+ msgContext.setSoapNamespaceURI(SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI);
+
SOAPFactory soapFactory = new SOAP11Factory();
builder = new StAXOMBuilder(xmlreader);
builder.setOmbuilderFactory(soapFactory);
envelope = soapFactory.getDefaultEnvelope();
envelope.getBody().addChild(builder.getDocumentElement());
}else{
+ msgContext.setSoapNamespaceURI(SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI);
builder = new StAXSOAPModelBuilder(xmlreader, SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI);
envelope = (SOAPEnvelope) builder.getDocumentElement();
}
@@ -272,6 +276,7 @@
*/
builder = new MTOMStAXSOAPModelBuilder(reader, mimeHelper, SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI);
} else if (mimeHelper.getAttachmentSpecType().equals(MIMEHelper.SWA_TYPE)) {
+ msgContext.setSoapNamespaceURI(SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI);
builder = new StAXSOAPModelBuilder(reader, SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI);
}
return builder;
Modified: webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/mail/MailWorker.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/mail/MailWorker.java?rev=226611&r1=226610&r2=226611&view=diff
==============================================================================
--- webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/mail/MailWorker.java (original)
+++ webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/mail/MailWorker.java Sun Jul 31 00:10:07 2005
@@ -126,6 +126,7 @@
soapNamespaceURI = SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI;
}
+ msgContext.setSoapNamespaceURI(soapNamespaceURI);
StAXBuilder builder = new StAXSOAPModelBuilder(reader, soapNamespaceURI);
SOAPEnvelope envelope = (SOAPEnvelope) builder.getDocumentElement();
Modified: webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/mail/server/MailSorter.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/mail/server/MailSorter.java?rev=226611&r1=226610&r2=226611&view=diff
==============================================================================
--- webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/mail/server/MailSorter.java (original)
+++ webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/mail/server/MailSorter.java Sun Jul 31 00:10:07 2005
@@ -110,6 +110,7 @@
soapNamespaceURI = SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI;
}
+ msgContext.setSoapNamespaceURI(soapNamespaceURI);
StAXBuilder builder = new StAXSOAPModelBuilder(reader, soapNamespaceURI);
SOAPEnvelope envelope = (SOAPEnvelope) builder.getDocumentElement();
Modified: webservices/axis/trunk/java/modules/samples/project.xml
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/samples/project.xml?rev=226611&r1=226610&r2=226611&view=diff
==============================================================================
--- webservices/axis/trunk/java/modules/samples/project.xml (original)
+++ webservices/axis/trunk/java/modules/samples/project.xml Sun Jul 31 00:10:07 2005
@@ -166,10 +166,11 @@
<exclude>**/*InteropStubTest.java</exclude>
<exclude>**/*EchoRawXMLChunckedTest.java</exclude>
<exclude>**org/apache/axis2/mail/*.java</exclude>
- <exclude>**/*FaultHandlingTest.java</exclude>
+
<!--
<exclude>**/*SOAP12Test.java</exclude>
<exclude>**/*SOAP12TestWithFaults.java</exclude>
+ <exclude>**/*FaultHandlingTest.java</exclude>
<exclude>**/*MailEchoRawXMLTest.java</exclude>
Modified: webservices/axis/trunk/java/modules/samples/test/org/apache/axis2/engine/FaultHandlingTest.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/samples/test/org/apache/axis2/engine/FaultHandlingTest.java?rev=226611&r1=226610&r2=226611&view=diff
==============================================================================
--- webservices/axis/trunk/java/modules/samples/test/org/apache/axis2/engine/FaultHandlingTest.java (original)
+++ webservices/axis/trunk/java/modules/samples/test/org/apache/axis2/engine/FaultHandlingTest.java Sun Jul 31 00:10:07 2005
@@ -1,20 +1,20 @@
package org.apache.axis2.engine;
+import junit.framework.TestCase;
import org.apache.axis2.AxisFault;
import org.apache.axis2.Constants;
import org.apache.axis2.addressing.EndpointReference;
-import org.apache.axis2.context.MessageContext;
-import org.apache.axis2.context.ServiceContext;
-import org.apache.axis2.description.ServiceDescription;
import org.apache.axis2.engine.util.MyInOutMEPClient;
import org.apache.axis2.integration.UtilServer;
import org.apache.axis2.om.OMAbstractFactory;
+import org.apache.axis2.om.OMElement;
import org.apache.axis2.om.impl.OMOutputImpl;
import org.apache.axis2.soap.SOAPEnvelope;
import org.apache.axis2.soap.SOAPFactory;
+import org.apache.axis2.soap.SOAPFault;
import org.apache.axis2.soap.impl.llom.builder.StAXSOAPModelBuilder;
+import org.apache.axis2.soap.impl.llom.soap11.SOAP11Constants;
import org.apache.axis2.soap.impl.llom.soap12.SOAP12Constants;
-import org.apache.axis2.util.Utils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -22,10 +22,8 @@
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
-import java.io.FileReader;
import java.io.File;
-
-import junit.framework.TestCase;
+import java.io.FileReader;
/*
* Copyright 2004,2005 The Apache Software Foundation.
@@ -45,66 +43,99 @@
* author : Eran Chinthaka (chinthaka@apache.org)
*/
-public class FaultHandlingTest extends TestCase{
+public class FaultHandlingTest extends TestCase {
private EndpointReference targetEPR =
new EndpointReference("http://127.0.0.1:"
- + (UtilServer.TESTING_PORT)
+// + (UtilServer.TESTING_PORT)
+ + ("5556")
+ "/axis/services/EchoXMLService/echoOMElement");
private Log log = LogFactory.getLog(getClass());
- private QName serviceName = new QName("EchoXMLService");
private QName operationName = new QName("echoOMElement");
- private QName transportName = new QName("http://localhost/my",
- "NullTransport");
- private AxisConfiguration engineRegistry;
- private MessageContext mc;
- //private Thread thisThread;
- // private SimpleHTTPServer sas;
- private ServiceContext serviceContext;
- private ServiceDescription service;
protected String testResourceDir = "test-resources";
+ MyInOutMEPClient inOutMEPClient;
private boolean finish = false;
- /**
- * @param testName
- */
- public FaultHandlingTest(String testName) {
- }
-
- protected void setUp() throws Exception {
- UtilServer.start();
- service =
- Utils.createSimpleService(serviceName,
- Echo.class.getName(),
- operationName);
- UtilServer.deployService(service);
- serviceContext =
- UtilServer.getConfigurationContext().createServiceContext(service.getName());
+ protected void setUp() {
+ try {
+ UtilServer.start();
+ inOutMEPClient = getMyInOutMEPClient();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
}
-// public void testInvalidSOAPMessage() throws AxisFault, XMLStreamException {
-// SOAPFactory fac = OMAbstractFactory.getSOAP12Factory();
-//
-// SOAPEnvelope soapEnvelope = fac.createSOAPEnvelope();
-// fac.createSOAPHeader(soapEnvelope);
-// fac.createSOAPHeader(soapEnvelope);
-// fac.createSOAPBody(soapEnvelope);
-//
-// MyInOutMEPClient inOutMEPClient = getMyInOutMEPClient();
-//
-// SOAPEnvelope result =
-// inOutMEPClient.invokeBlockingWithEnvelopeOut(operationName.getLocalPart(), soapEnvelope);
-//
-// OMOutputImpl output = new OMOutputImpl(System.out, false);
-// result.serialize(output);
-// output.flush();
-//
-// inOutMEPClient.close();
+ public void testTwoHeadersSOAPMessage() throws AxisFault, XMLStreamException {
+ SOAPFactory fac = OMAbstractFactory.getSOAP12Factory();
+ SOAPEnvelope soapEnvelope = getTwoHeadersSOAPEnvelope(fac);
+ SOAPEnvelope resposeEnvelope = getResponse(soapEnvelope);
+
+ checkSOAPFaultContent(resposeEnvelope);
+ SOAPFault fault = resposeEnvelope.getBody().getFault();
+ assertEquals(fault.getCode().getValue().getText().trim(), SOAP12Constants.FAULT_CODE_SENDER);
+
+ fac = OMAbstractFactory.getSOAP11Factory();
+ soapEnvelope = getTwoHeadersSOAPEnvelope(fac);
+ resposeEnvelope = getResponse(soapEnvelope);
+
+ checkSOAPFaultContent(resposeEnvelope);
+ fault = resposeEnvelope.getBody().getFault();
+ assertEquals(fault.getCode().getValue().getText().trim(), SOAP11Constants.FAULT_CODE_SENDER);
+
+ }
+
+// public void testSOAPFaultSerializing(){
+// try {
+// SOAPEnvelope envelope = createEnvelope("soap/fault/test.xml");
+// SOAPEnvelope response = getResponse(envelope);
+// printElement(response);
+// assertTrue(true);
+// } catch (Exception e) {
+// e.printStackTrace();
+// }
// }
+ private void printElement(OMElement element) throws XMLStreamException {
+ OMOutputImpl output = new OMOutputImpl(System.out, false);
+ element.serializeWithCache(output);
+ output.flush();
+ }
+
+
+
+ private void checkSOAPFaultContent(SOAPEnvelope soapEnvelope) {
+ assertTrue(soapEnvelope.getBody().hasFault());
+ SOAPFault fault = soapEnvelope.getBody().getFault();
+ assertNotNull(fault.getCode());
+ assertNotNull(fault.getCode().getValue());
+ assertNotNull(fault.getReason());
+ assertNotNull(fault.getReason().getText());
+ }
+
+ private SOAPEnvelope getResponse(SOAPEnvelope inEnvelope) {
+ try {
+ inOutMEPClient.setExceptionToBeThrownOnSOAPFault(false);
+ SOAPEnvelope result =
+ inOutMEPClient.invokeBlockingWithEnvelopeOut(operationName.getLocalPart(), inEnvelope);
+ return result;
+ } catch (AxisFault axisFault) {
+ axisFault.printStackTrace();
+ fail("Something wrong in getting the response from " + operationName.getLocalPart() + " service");
+ }
+ return null;
+ }
+
+ private SOAPEnvelope getTwoHeadersSOAPEnvelope(SOAPFactory fac) {
+ SOAPEnvelope soapEnvelope = fac.createSOAPEnvelope();
+ fac.createSOAPHeader(soapEnvelope);
+ fac.createSOAPHeader(soapEnvelope);
+ fac.createSOAPBody(soapEnvelope);
+ return soapEnvelope;
+ }
+
private MyInOutMEPClient getMyInOutMEPClient() throws AxisFault {
MyInOutMEPClient inOutMEPClient = new MyInOutMEPClient();
inOutMEPClient.setSoapVersionURI(SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI);
@@ -131,6 +162,7 @@
protected void tearDown() throws Exception {
UtilServer.stop();
+ inOutMEPClient.close();
}
}