axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ntha...@apache.org
Subject svn commit: r818164 - in /webservices/axis2/trunk/java/modules: jaxws-integration/test/org/apache/axis2/jaxws/provider/ jaxws-integration/test/org/apache/axis2/jaxws/provider/om/ jaxws/src/org/apache/axis2/jaxws/ jaxws/src/org/apache/axis2/jaxws/client...
Date Wed, 23 Sep 2009 16:55:02 GMT
Author: nthaker
Date: Wed Sep 23 16:55:01 2009
New Revision: 818164

URL: http://svn.apache.org/viewvc?rev=818164&view=rev
Log:
AXIS2-4506

Modified:
    webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/provider/OMProviderTests.java
    webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/provider/om/OMProvider.java
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/Constants.java
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/client/ClientUtils.java
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/client/dispatch/BaseDispatch.java
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/core/controller/impl/AxisInvocationController.java
    webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/client/Options.java

Modified: webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/provider/OMProviderTests.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/provider/OMProviderTests.java?rev=818164&r1=818163&r2=818164&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/provider/OMProviderTests.java
(original)
+++ webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/provider/OMProviderTests.java
Wed Sep 23 16:55:01 2009
@@ -3,14 +3,18 @@
 import org.apache.axiom.om.OMElement;
 import org.apache.axiom.soap.SOAPEnvelope;
 import org.apache.axiom.soap.impl.builder.StAXSOAPModelBuilder;
+import org.apache.axis2.jaxws.Constants;
 
 import javax.xml.namespace.QName;
 import javax.xml.stream.XMLInputFactory;
 import javax.xml.stream.XMLStreamReader;
+import javax.xml.ws.BindingProvider;
 import javax.xml.ws.Dispatch;
 import javax.xml.ws.Service;
+import javax.xml.ws.WebServiceException;
 import javax.xml.ws.Service.Mode;
 import javax.xml.ws.soap.SOAPBinding;
+import javax.xml.ws.soap.SOAPFaultException;
 
 import java.io.StringReader;
 
@@ -41,6 +45,7 @@
 
 
         private static String request = "<invokeOp>Hello Provider OM</invokeOp>";
+        private static String SOAPFaultRequest ="<invokeOp>SOAPFault</invokeOp>";
         private static XMLInputFactory inputFactory = XMLInputFactory.newInstance();
         
    public static Test suite() {
@@ -78,4 +83,52 @@
         assertTrue(responseText.contains("Hello Dispatch OM"));
         
     }
+    
+    /**
+     * Test sending a SOAP 1.2 request in MESSAGE mode
+     */
+    public void testOMElementDispatchMessageModeSOAPFaultException() throws Exception {
+        // Create the JAX-WS client needed to send the request
+        Service service = Service.create(serviceName);
+        service.addPort(portName, SOAPBinding.SOAP11HTTP_BINDING, endpointUrl);
+        Dispatch<OMElement> dispatch = service.createDispatch(
+                portName, OMElement.class, Mode.MESSAGE);
+        
+        StringReader sr = new StringReader(SOAP11_ENVELOPE_HEAD+SOAPFaultRequest+SOAP11_ENVELOPE_TAIL);
+        XMLStreamReader inputReader = inputFactory.createXMLStreamReader(sr);
+        StAXSOAPModelBuilder builder = new StAXSOAPModelBuilder(inputReader, null); 
+        SOAPEnvelope om = (SOAPEnvelope) builder.getDocumentElement();
+        OMElement response = null;
+        try{
+        	response = dispatch.invoke(om);
+        	String responseText = response.toStringWithConsume();
+        }catch(Exception e){
+        	assertTrue(e instanceof SOAPFaultException);
+        }
+        assertTrue(response ==null);
+    }
+    
+    public void testOMElementDispatchMessageModeSOAPFault() throws Exception {
+        // Create the JAX-WS client needed to send the request
+        Service service = Service.create(serviceName);
+        service.addPort(portName, SOAPBinding.SOAP11HTTP_BINDING, endpointUrl);
+        Dispatch<OMElement> dispatch = service.createDispatch(
+                portName, OMElement.class, Mode.MESSAGE);
+        BindingProvider bp = (BindingProvider)dispatch;
+        bp.getRequestContext().put(Constants.THROW_EXCEPTION_IF_SOAP_FAULT, Boolean.FALSE);
+       
+        StringReader sr = new StringReader(SOAP11_ENVELOPE_HEAD+SOAPFaultRequest+SOAP11_ENVELOPE_TAIL);
+        XMLStreamReader inputReader = inputFactory.createXMLStreamReader(sr);
+        StAXSOAPModelBuilder builder = new StAXSOAPModelBuilder(inputReader, null); 
+        SOAPEnvelope om = (SOAPEnvelope) builder.getDocumentElement();
+        OMElement response = null;
+        try{
+        	response = dispatch.invoke(om);
+        	String responseText = response.toStringWithConsume();
+        }catch(Exception e){
+        	fail();
+        }
+        assertTrue(response !=null);
+        assertTrue(response instanceof OMElement);
+    }
 }

Modified: webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/provider/om/OMProvider.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/provider/om/OMProvider.java?rev=818164&r1=818163&r2=818164&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/provider/om/OMProvider.java
(original)
+++ webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/provider/om/OMProvider.java
Wed Sep 23 16:55:01 2009
@@ -22,6 +22,16 @@
 import org.apache.axiom.soap.SOAPEnvelope;
 import org.apache.axiom.soap.impl.builder.StAXSOAPModelBuilder;
 
+import javax.xml.namespace.QName;
+import javax.xml.soap.Detail;
+import javax.xml.soap.MessageFactory;
+import javax.xml.soap.Name;
+import javax.xml.soap.SOAPBody;
+import javax.xml.soap.SOAPConstants;
+import javax.xml.soap.SOAPElement;
+import javax.xml.soap.SOAPFactory;
+import javax.xml.soap.SOAPFault;
+import javax.xml.soap.SOAPMessage;
 import javax.xml.stream.XMLInputFactory;
 import javax.xml.stream.XMLStreamReader;
 import javax.xml.ws.Provider;
@@ -29,6 +39,7 @@
 import javax.xml.ws.ServiceMode;
 import javax.xml.ws.WebServiceException;
 import javax.xml.ws.WebServiceProvider;
+import javax.xml.ws.soap.SOAPFaultException;
 
 import java.io.StringReader;
 
@@ -55,11 +66,14 @@
 
     private static String response = "<invokeOp>Hello Dispatch OM</invokeOp>";
     private static XMLInputFactory inputFactory = XMLInputFactory.newInstance();
-    public OMElement invoke(OMElement om) {
+    public OMElement invoke(OMElement om) throws SOAPFaultException{
         try{
             StringReader sr = null;
            if(om!=null){
              String requestText = om.toStringWithConsume();
+             if(requestText.contains("SOAPFault")){
+            	 throwSOAPFaultException();
+             }
              if((requestText.contains("Hello Provider OM"))){
                  sr = new StringReader(SOAP11_ENVELOPE_HEAD+response+SOAP11_ENVELOPE_TAIL);
              }
@@ -78,5 +92,31 @@
             throw new WebServiceException(e);
         }
     }
+    
+    private void throwSOAPFaultException() throws SOAPFaultException {
+        try {
+            MessageFactory mf = MessageFactory.newInstance();
+            SOAPFactory sf = SOAPFactory.newInstance();
+            
+            SOAPMessage m = mf.createMessage();
+            SOAPBody body = m.getSOAPBody();
+            SOAPFault fault = body.addFault();
+            QName faultCode = new QName(SOAPConstants.URI_NS_SOAP_1_1_ENVELOPE, "Client");

+            fault.setFaultCode(faultCode);
+            fault.setFaultString("sample fault");
+            Detail detail = fault.addDetail();
+            Name deName = sf.createName("detailEntry");
+            SOAPElement detailEntry = detail.addDetailEntry(deName);
+            detailEntry.addTextNode("sample detail");
+            fault.setFaultActor("sample actor");
+            
+            SOAPFaultException sfe = new SOAPFaultException(fault);
+            throw sfe;
+        } catch (SOAPFaultException e) {
+            throw e;
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        }
+    }
 
 }

Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/Constants.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/Constants.java?rev=818164&r1=818163&r2=818164&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/Constants.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/Constants.java Wed
Sep 23 16:55:01 2009
@@ -102,4 +102,10 @@
      * messages.
      */
     public static final String SOAP_HTTP_BINDING ="SOAP_HTTP_BINDING";
+    
+    /**
+     * This constant will be used to determine if a Exception will be throw by
+     * JAX-WS layer when a SOAP Fault is received on response. 
+     */
+    public static final String THROW_EXCEPTION_IF_SOAP_FAULT = "jaxws.response.throwExceptionIfSOAPFault";
 }

Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/client/ClientUtils.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/client/ClientUtils.java?rev=818164&r1=818163&r2=818164&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/client/ClientUtils.java
(original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/client/ClientUtils.java
Wed Sep 23 16:55:01 2009
@@ -19,7 +19,13 @@
 
 package org.apache.axis2.jaxws.client;
 
+import javax.xml.ws.Dispatch;
+import javax.xml.ws.Service.Mode;
+
+import org.apache.axiom.om.OMElement;
 import org.apache.axis2.jaxws.BindingProvider;
+import org.apache.axis2.jaxws.client.dispatch.BaseDispatch;
+import org.apache.axis2.jaxws.client.dispatch.XMLDispatch;
 import org.apache.axis2.jaxws.core.MessageContext;
 import org.apache.axis2.jaxws.description.OperationDescription;
 import org.apache.commons.logging.Log;
@@ -76,5 +82,34 @@
 
         return null;
     }
-
+    /**
+     * The operation is used to make sure Option is property configured for ThrowingExceptionOnFault
+     * @param msgContext
+     */
+    public static boolean getExceptionToBeThrownOnSOAPFault(org.apache.axis2.context.MessageContext
msgContext){
+    	if(log.isDebugEnabled()){
+    		log.debug("start getExceptionToBeThrownOnSOAPFault(MsgContext)");
+    	}
+    	BindingProvider bp = (BindingProvider)msgContext.getProperty(BindingProvider.BINDING_PROVIDER);
+    	if(bp == null){
+    		return true;
+    	}
+    	//ThrowExceptionIfSOAPFault should be checked only for message Mode.
+    	if(bp instanceof BaseDispatch){
+    		if(((BaseDispatch)bp).getMode()!= Mode.MESSAGE){
+    			if(log.isDebugEnabled()){
+    	    		log.debug("throwExceptionIfSOAPFault will not be checked as Dispatch is not set
to Mode.MESSAGE");
+    	    		log.debug("End getExceptionToBeThrownOnSOAPFault(MsgContext)");
+    	    	}
+    			return true;
+    		}
+    	}
+        Object value = msgContext.getProperty(org.apache.axis2.jaxws.Constants.THROW_EXCEPTION_IF_SOAP_FAULT);
+        boolean throwExceptionIfSOAPFault = (value!=null && value instanceof Boolean)?(Boolean)value:Boolean.TRUE;
+    	if(log.isDebugEnabled()){
+    		log.debug("throwExceptionIfSOAPFault ="+throwExceptionIfSOAPFault);
+    		log.debug("End getExceptionToBeThrownOnSOAPFault(MsgContext)");
+    	}
+        return throwExceptionIfSOAPFault;
+    }
 }

Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/client/dispatch/BaseDispatch.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/client/dispatch/BaseDispatch.java?rev=818164&r1=818163&r2=818164&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/client/dispatch/BaseDispatch.java
(original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/client/dispatch/BaseDispatch.java
Wed Sep 23 16:55:01 2009
@@ -23,6 +23,7 @@
 import org.apache.axis2.client.ServiceClient;
 import org.apache.axis2.jaxws.BindingProvider;
 import org.apache.axis2.jaxws.ExceptionFactory;
+import org.apache.axis2.jaxws.client.ClientUtils;
 import org.apache.axis2.jaxws.client.async.AsyncResponse;
 import org.apache.axis2.jaxws.core.InvocationContext;
 import org.apache.axis2.jaxws.core.InvocationContextFactory;
@@ -180,7 +181,7 @@
             ApplicationContextMigratorUtil.performMigrationFromMessageContext(
                     Constants.APPLICATION_CONTEXT_MIGRATOR_LIST_ID,
                     getResponseContext(), responseMsgCtx);
-
+            
             if (hasFaultResponse(responseMsgCtx)) {
                 WebServiceException wse = BaseDispatch.getFaultResponse(responseMsgCtx);
                 throw wse;
@@ -640,6 +641,12 @@
      * @return
      */
     public boolean hasFaultResponse(MessageContext msgCtx) {
+    	if(!msgCtx.getAxisMessageContext().getOptions().isExceptionToBeThrownOnSOAPFault()){
+        	if(log.isDebugEnabled()){
+        		log.debug("msgCtx.Options.isExceptionToBeThrownOnSOAPFault set to false; Exception
will not be thrown on fault");
+        	}
+    		return false;
+    	}
         if (msgCtx.getMessage() != null && msgCtx.getMessage().isFault())
             return true;
         else if (msgCtx.getLocalException() != null)

Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/core/controller/impl/AxisInvocationController.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/core/controller/impl/AxisInvocationController.java?rev=818164&r1=818163&r2=818164&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/core/controller/impl/AxisInvocationController.java
(original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/core/controller/impl/AxisInvocationController.java
Wed Sep 23 16:55:01 2009
@@ -19,6 +19,7 @@
 
 package org.apache.axis2.jaxws.core.controller.impl;
 
+import org.apache.axiom.om.OMElement;
 import org.apache.axis2.AxisFault;
 import org.apache.axis2.Constants.Configuration;
 import org.apache.axis2.addressing.EndpointReference;
@@ -31,6 +32,7 @@
 import org.apache.axis2.jaxws.client.async.AsyncResponse;
 import org.apache.axis2.jaxws.client.async.CallbackFuture;
 import org.apache.axis2.jaxws.client.async.PollingFuture;
+import org.apache.axis2.jaxws.client.dispatch.XMLDispatch;
 import org.apache.axis2.jaxws.core.InvocationContext;
 import org.apache.axis2.jaxws.core.MessageContext;
 import org.apache.axis2.jaxws.description.OperationDescription;
@@ -50,8 +52,11 @@
 
 import javax.xml.namespace.QName;
 import javax.xml.ws.AsyncHandler;
+import javax.xml.ws.Dispatch;
 import javax.xml.ws.Response;
 import javax.xml.ws.WebServiceException;
+import javax.xml.ws.Service.Mode;
+
 import java.net.MalformedURLException;
 import java.net.URL;
 import java.util.concurrent.Future;
@@ -549,7 +554,15 @@
         try {
             // Pre-Execute logging and setup
             preExecute(opClient, block, msgContext);
-
+            //check if Exception should be thrown on SOAPFault
+            if(log.isDebugEnabled()){
+            	log.debug("Read throwExceptionIfSOAPFault property");
+            }
+            boolean exceptionToBeThrownOnSOAPFault= ClientUtils.getExceptionToBeThrownOnSOAPFault(msgContext);
+            if(log.isDebugEnabled()){
+            	log.debug("throwExceptionIfSOAPFault property set on OperationClient.options
"+ exceptionToBeThrownOnSOAPFault);
+            }
+            opClient.getOptions().setExceptionToBeThrownOnSOAPFault(exceptionToBeThrownOnSOAPFault);
             // Invoke the OperationClient
             opClient.execute(block);
         } catch (Throwable e) {

Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/client/Options.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/client/Options.java?rev=818164&r1=818163&r2=818164&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/client/Options.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/client/Options.java Wed
Sep 23 16:55:01 2009
@@ -531,7 +531,7 @@
      */
     public boolean isExceptionToBeThrownOnSOAPFault() {
         if (isExceptionToBeThrownOnSOAPFault == null && parent != null) {
-            isExceptionToBeThrownOnSOAPFault = parent.isExceptionToBeThrownOnSOAPFault;
+            isExceptionToBeThrownOnSOAPFault = parent.isExceptionToBeThrownOnSOAPFault();
         }
 
         return isExceptionToBeThrownOnSOAPFault == null



Mime
View raw message