You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by ri...@apache.org on 2007/02/26 00:37:58 UTC

svn commit: r511660 - in /incubator/tuscany/branches/sca-java-integration: sca/extensions/axis2/binding/src/main/java/org/apache/tuscany/binding/axis2/ sca/kernel/core/src/main/java/org/apache/tuscany/core/databinding/impl/ sca/kernel/spi/src/main/java...

Author: rineholt
Date: Sun Feb 25 15:37:57 2007
New Revision: 511660

URL: http://svn.apache.org/viewvc?view=rev&rev=511660
Log:
[sca-java-integration] Business exceptions croos axis web services binding with iTest

Modified:
    incubator/tuscany/branches/sca-java-integration/sca/extensions/axis2/binding/src/main/java/org/apache/tuscany/binding/axis2/Axis2TargetInvoker.java
    incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src/main/java/org/apache/tuscany/core/databinding/impl/DataBindingInteceptor.java
    incubator/tuscany/branches/sca-java-integration/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/idl/ServiceFaultException.java
    incubator/tuscany/branches/sca-java-integration/testing/sca/itest/exceptionXbindingWSTest/src/test/java/org/apache/tuscany/sca/test/exceptions/IntraCompositeTestCase.java

Modified: incubator/tuscany/branches/sca-java-integration/sca/extensions/axis2/binding/src/main/java/org/apache/tuscany/binding/axis2/Axis2TargetInvoker.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/branches/sca-java-integration/sca/extensions/axis2/binding/src/main/java/org/apache/tuscany/binding/axis2/Axis2TargetInvoker.java?view=diff&rev=511660&r1=511659&r2=511660
==============================================================================
--- incubator/tuscany/branches/sca-java-integration/sca/extensions/axis2/binding/src/main/java/org/apache/tuscany/binding/axis2/Axis2TargetInvoker.java (original)
+++ incubator/tuscany/branches/sca-java-integration/sca/extensions/axis2/binding/src/main/java/org/apache/tuscany/binding/axis2/Axis2TargetInvoker.java Sun Feb 25 15:37:57 2007
@@ -22,6 +22,7 @@
 import javax.xml.namespace.QName;
 
 import org.apache.tuscany.spi.component.WorkContext;
+import org.apache.tuscany.spi.idl.ServiceFaultException;
 import org.apache.tuscany.spi.model.Scope;
 import org.apache.tuscany.spi.wire.InvocationRuntimeException;
 import org.apache.tuscany.spi.wire.Message;
@@ -42,7 +43,8 @@
 import org.apache.axis2.wsdl.WSDLConstants;
 
 /**
- * Axis2TargetInvoker uses an Axis2 OperationClient to invoke a remote web service
+ * Axis2TargetInvoker uses an Axis2 OperationClient to invoke a remote web
+ * service
  */
 public class Axis2TargetInvoker implements TargetInvoker {
 
@@ -56,8 +58,11 @@
 
     private WorkContext workContext;
 
-    public Axis2TargetInvoker(ServiceClient serviceClient, QName wsdlOperationName, Options options,
-                              SOAPFactory soapFactory, WorkContext workContext) {
+    public Axis2TargetInvoker(ServiceClient serviceClient,
+                              QName wsdlOperationName,
+                              Options options,
+                              SOAPFactory soapFactory,
+                              WorkContext workContext) {
         this.wsdlOperationName = wsdlOperationName;
         this.options = options;
         this.soapFactory = soapFactory;
@@ -67,7 +72,7 @@
 
     /**
      * Invoke a WS operation
-     *
+     * 
      * @param payload
      * @param sequence
      * @return
@@ -75,16 +80,28 @@
      */
     public Object invokeTarget(final Object payload, final short sequence) throws InvocationTargetException {
         try {
-            Object[] args = (Object[]) payload;
+            Object[] args = (Object[])payload;
             OperationClient operationClient = createOperationClient(args);
 
             operationClient.execute(true);
 
             MessageContext responseMC = operationClient.getMessageContext(WSDLConstants.MESSAGE_LABEL_IN_VALUE);
+
             return responseMC.getEnvelope().getBody().getFirstElement();
 
         } catch (AxisFault e) {
-            throw new InvocationTargetException(e);
+            // convert exception to an exception independent on Axis runtime.
+            Throwable cause = e.getCause();
+            cause = cause == null ? e : cause;
+            ServiceFaultException serviceFaultException =
+                new ServiceFaultException(e.getMessage(), e.getDetail(), cause);
+            OMElement detail = e.getDetail();
+            if (null != detail) {
+                detail.getQName();
+                serviceFaultException.setLogical(detail.getQName());
+            }
+            throw new InvocationTargetException(serviceFaultException);
+
         }
 
     }
@@ -96,37 +113,40 @@
             SOAPBody body = env.getBody();
             for (Object bc : args) {
                 if (bc instanceof OMElement) {
-                    body.addChild((OMElement) bc);
+                    body.addChild((OMElement)bc);
                 } else {
                     throw new IllegalArgumentException(
-                        "Can't handle mixed payloads betweem OMElements and other types.");
+                                                       "Can't handle mixed payloads betweem OMElements and other types.");
                 }
             }
         }
         MessageContext requestMC = new MessageContext();
         requestMC.setEnvelope(env);
-        // Axis2 operationClients can not be shared so create a new one for each request
+        // Axis2 operationClients can not be shared so create a new one for each
+        // request
         OperationClient operationClient = serviceClient.createClient(wsdlOperationName);
-        
-        
-        if(workContext != null){
-            String conversationId = (String) workContext.getIdentifier(Scope.CONVERSATION);
-            if(conversationId != null && conversationId.length()!=0){
-                EndpointReference fromEPR= new EndpointReference(AddressingConstants.Final.WSA_ANONYMOUS_URL);
+
+        if (workContext != null) {
+            String conversationId = (String)workContext.getIdentifier(Scope.CONVERSATION);
+            if (conversationId != null && conversationId.length() != 0) {
+                EndpointReference fromEPR = new EndpointReference(AddressingConstants.Final.WSA_ANONYMOUS_URL);
                 fromEPR.addReferenceParameter(WebServiceBindingDefinition.CONVERSATION_ID_REFPARM_QN, conversationId);
                 options.setFrom(fromEPR);
-                requestMC.setFrom(fromEPR); //who knows why two ways ?
-            
-                //For now do this the brute force method. Need to figure out how to do axis addressing .. configure mar in flow.
+                requestMC.setFrom(fromEPR); // who knows why two ways ?
+
+                // For now do this the brute force method. Need to figure out
+                // how to do axis addressing .. configure mar in flow.
                 SOAPEnvelope sev = requestMC.getEnvelope();
                 SOAPHeader sh = sev.getHeader();
-                OMElement el= fromEPR.toOM(AddressingConstants.Final.WSA_NAMESPACE,AddressingConstants.WSA_FROM,AddressingConstants.WSA_DEFAULT_PREFIX);
+                OMElement el =
+                    fromEPR.toOM(AddressingConstants.Final.WSA_NAMESPACE,
+                                 AddressingConstants.WSA_FROM,
+                                 AddressingConstants.WSA_DEFAULT_PREFIX);
                 sh.addChild(el);
             }
 
         }
 
-                
         operationClient.setOptions(options);
         operationClient.addMessageContext(requestMC);
         return operationClient;
@@ -144,7 +164,7 @@
 
     public Axis2TargetInvoker clone() throws CloneNotSupportedException {
         try {
-            return (Axis2TargetInvoker) super.clone();
+            return (Axis2TargetInvoker)super.clone();
         } catch (CloneNotSupportedException e) {
             // will not happen
             return null;

Modified: incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src/main/java/org/apache/tuscany/core/databinding/impl/DataBindingInteceptor.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src/main/java/org/apache/tuscany/core/databinding/impl/DataBindingInteceptor.java?view=diff&rev=511660&r1=511659&r2=511660
==============================================================================
--- incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src/main/java/org/apache/tuscany/core/databinding/impl/DataBindingInteceptor.java (original)
+++ incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src/main/java/org/apache/tuscany/core/databinding/impl/DataBindingInteceptor.java Sun Feb 25 15:37:57 2007
@@ -19,14 +19,18 @@
 
 package org.apache.tuscany.core.databinding.impl;
 
+import java.lang.reflect.InvocationTargetException;
 import java.util.HashMap;
 import java.util.Map;
 
+import javax.xml.namespace.QName;
+
 import org.apache.tuscany.spi.component.CompositeComponent;
 import org.apache.tuscany.spi.databinding.DataBinding;
 import org.apache.tuscany.spi.databinding.ExceptionHandler;
 import org.apache.tuscany.spi.databinding.Mediator;
 import org.apache.tuscany.spi.databinding.TransformationException;
+import org.apache.tuscany.spi.idl.ServiceFaultException;
 import org.apache.tuscany.spi.model.DataType;
 import org.apache.tuscany.spi.model.Operation;
 import org.apache.tuscany.spi.wire.Interceptor;
@@ -68,7 +72,9 @@
     /**
      * @see org.apache.tuscany.spi.wire.Interceptor#invoke(org.apache.tuscany.spi.wire.Message)
      */
-    /* (non-Javadoc)
+    /*
+     * (non-Javadoc)
+     * 
      * @see org.apache.tuscany.spi.wire.Interceptor#invoke(org.apache.tuscany.spi.wire.Message)
      */
     public Message invoke(Message msg) {
@@ -93,21 +99,36 @@
 
         if (resultMsg.isFault()) {
 
-            // FIXME: We need to figure out what fault type it is and then transform it
+            // FIXME: We need to figure out what fault type it is and then
+            // transform it
             // back the source fault type
             // throw new InvocationRuntimeException((Throwable) result);
 
             if ((result instanceof Exception) && !(result instanceof RuntimeException)) {
                 // FIXME: How to match fault data to a fault type for the
                 // operation?
+
+                // If the result is from an InvocationTargetException look at
+                // the actual cause.
+                if (result instanceof InvocationTargetException) {
+                    result = ((InvocationTargetException)result).getCause();
+                }
                 DataType targetDataType = null;
                 for (DataType exType : targetOperation.getFaultTypes()) {
                     if (((Class)exType.getPhysical()).isInstance(result)) {
-                        targetDataType = exType;
-                        break;
+                        if (result instanceof ServiceFaultException) {
+                            if (((ServiceFaultException)result).isMatchingType(exType.getLogical())) {
+                                targetDataType = exType;
+                                break;
+                            }
+
+                        } else {
+                            targetDataType = exType;
+                            break;
+                        }
                     }
                 }
-                
+
                 if (targetDataType == null) {
                     // Not a business exception
                     return resultMsg;

Modified: incubator/tuscany/branches/sca-java-integration/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/idl/ServiceFaultException.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/branches/sca-java-integration/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/idl/ServiceFaultException.java?view=diff&rev=511660&r1=511659&r2=511660
==============================================================================
--- incubator/tuscany/branches/sca-java-integration/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/idl/ServiceFaultException.java (original)
+++ incubator/tuscany/branches/sca-java-integration/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/idl/ServiceFaultException.java Sun Feb 25 15:37:57 2007
@@ -19,16 +19,19 @@
 
 package org.apache.tuscany.spi.idl;
 
+import javax.xml.namespace.QName;
+
 import org.apache.tuscany.api.TuscanyException;
 
 /**
- * The generic java exception to wrap service faults 
+ * The generic java exception to wrap service faults
  * 
  * @version $Rev$ $Date$
  */
 public class ServiceFaultException extends TuscanyException {
     private static final long serialVersionUID = -8002583655240625792L;
     private Object faultInfo;
+    private QName logical;
 
     /**
      * @param message
@@ -54,6 +57,26 @@
      */
     public Object getFaultInfo() {
         return faultInfo;
+    }
+
+    public QName getLogical() {
+        return logical;
+    }
+
+    public void setLogical(QName logical) {
+        this.logical = logical;
+    }
+
+    public boolean isMatchingType(Object type) {
+        if (logical == null)
+            return false;
+
+        if ((type instanceof QName) && logical.equals(type)) {
+            return true;
+        }
+        if (type instanceof XMLType && logical.equals(((XMLType)type).getElementName()))
+            return true;
+        return false;
     }
 
 }

Modified: incubator/tuscany/branches/sca-java-integration/testing/sca/itest/exceptionXbindingWSTest/src/test/java/org/apache/tuscany/sca/test/exceptions/IntraCompositeTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/branches/sca-java-integration/testing/sca/itest/exceptionXbindingWSTest/src/test/java/org/apache/tuscany/sca/test/exceptions/IntraCompositeTestCase.java?view=diff&rev=511660&r1=511659&r2=511660
==============================================================================
--- incubator/tuscany/branches/sca-java-integration/testing/sca/itest/exceptionXbindingWSTest/src/test/java/org/apache/tuscany/sca/test/exceptions/IntraCompositeTestCase.java (original)
+++ incubator/tuscany/branches/sca-java-integration/testing/sca/itest/exceptionXbindingWSTest/src/test/java/org/apache/tuscany/sca/test/exceptions/IntraCompositeTestCase.java Sun Feb 25 15:37:57 2007
@@ -50,7 +50,7 @@
 
     }
 
-    public void _testInvalidSymbolSDOException() {
+    public void testInvalidSymbolSDOException() {
         try {
             stockTrader.testInvalidSymbolSDOException();
             fail("Expected InvalidSymbolSDOException");



---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-commits-help@ws.apache.org