Author: antelder
Date: Fri Sep 14 02:26:07 2007
New Revision: 575595
URL: http://svn.apache.org/viewvc?rev=575595&view=rev
Log:
TUSCANY-1686, apply patch from Simon Nash: business exceptions across the Web
Service binding
Modified:
incubator/tuscany/java/sca/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2BindingInvoker.java
incubator/tuscany/java/sca/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2OneWayBindingInvoker.java
incubator/tuscany/java/sca/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2ServiceInOutSyncMessageReceiver.java
incubator/tuscany/java/sca/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/wire/DataTransformationInteceptor.java
Modified:
incubator/tuscany/java/sca/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2BindingInvoker.java
URL:
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2BindingInvoker.java?rev=575595&r1=575594&r2=575595&view=diff
==============================================================================
---
incubator/tuscany/java/sca/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2BindingInvoker.java
(original)
+++
incubator/tuscany/java/sca/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2BindingInvoker.java
Fri Sep 14 02:26:07 2007
@@ -38,6 +38,7 @@
import org.apache.axis2.transport.http.HTTPConstants;
import org.apache.axis2.wsdl.WSDLConstants;
import org.apache.tuscany.sca.assembly.xml.Constants;
+import org.apache.tuscany.sca.interfacedef.util.FaultException;
import org.apache.tuscany.sca.invocation.Invoker;
import org.apache.tuscany.sca.invocation.Message;
import org.apache.tuscany.sca.runtime.ReferenceParameters;
@@ -74,8 +75,14 @@
try {
Object resp = invokeTarget(msg);
msg.setBody(resp);
- } catch (InvocationTargetException e) {
- msg.setFaultBody(e.getCause());
+ } catch (AxisFault e) {
+ if (e.getDetail() != null) {
+ FaultException f = new FaultException(e.getMessage(),
e.getDetail());
+ f.setLogical(e.getDetail().getQName());
+ msg.setFaultBody(f);
+ } else {
+ msg.setFaultBody(e);
+ }
} catch (Throwable e) {
msg.setFaultBody(e);
}
@@ -83,33 +90,28 @@
return msg;
}
- protected Object invokeTarget(Message msg) throws
InvocationTargetException {
- try {
- OperationClient operationClient = createOperationClient(msg);
-
- // ensure connections are tracked so that they can be closed by
the reference binding
- MessageContext requestMC =
operationClient.getMessageContext(WSDLConstants.MESSAGE_LABEL_OUT_VALUE);
-
requestMC.getOptions().setProperty(HTTPConstants.REUSE_HTTP_CLIENT,
Boolean.TRUE);
- requestMC.getOptions().setTimeOutInMilliSeconds(120000L);
+ protected Object invokeTarget(Message msg) throws AxisFault {
+ OperationClient operationClient = createOperationClient(msg);
- operationClient.execute(true);
+ // ensure connections are tracked so that they can be closed by the
reference binding
+ MessageContext requestMC =
operationClient.getMessageContext(WSDLConstants.MESSAGE_LABEL_OUT_VALUE);
+ requestMC.getOptions().setProperty(HTTPConstants.REUSE_HTTP_CLIENT,
Boolean.TRUE);
+ requestMC.getOptions().setTimeOutInMilliSeconds(120000L);
- MessageContext responseMC =
operationClient.getMessageContext(WSDLConstants.MESSAGE_LABEL_IN_VALUE);
+ operationClient.execute(true);
- OMElement response =
responseMC.getEnvelope().getBody().getFirstElement();
+ MessageContext responseMC =
operationClient.getMessageContext(WSDLConstants.MESSAGE_LABEL_IN_VALUE);
- // FIXME: [rfeng] We have to pay performance penality to build the
complete OM as the operationClient.complete() will
- // release the underlying HTTP connection.
- // Force the response to be populated, see
https://issues.apache.org/jira/browse/TUSCANY-1541
- response.build();
+ OMElement response =
responseMC.getEnvelope().getBody().getFirstElement();
- operationClient.complete(requestMC);
+ // FIXME: [rfeng] We have to pay performance penality to build the
complete OM as the operationClient.complete() will
+ // release the underlying HTTP connection.
+ // Force the response to be populated, see
https://issues.apache.org/jira/browse/TUSCANY-1541
+ response.build();
- return response;
+ operationClient.complete(requestMC);
- } catch (AxisFault e) {
- throw new InvocationTargetException(e);
- }
+ return response;
}
@SuppressWarnings("deprecation")
Modified:
incubator/tuscany/java/sca/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2OneWayBindingInvoker.java
URL:
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2OneWayBindingInvoker.java?rev=575595&r1=575594&r2=575595&view=diff
==============================================================================
---
incubator/tuscany/java/sca/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2OneWayBindingInvoker.java
(original)
+++
incubator/tuscany/java/sca/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2OneWayBindingInvoker.java
Fri Sep 14 02:26:07 2007
@@ -43,22 +43,17 @@
}
@Override
- protected Object invokeTarget(Message msg) throws
InvocationTargetException {
- try {
- OperationClient operationClient = createOperationClient(msg);
+ protected Object invokeTarget(Message msg) throws AxisFault {
+ OperationClient operationClient = createOperationClient(msg);
- // ensure connections are tracked so that they can be closed by
the reference binding
- MessageContext requestMC =
operationClient.getMessageContext(WSDLConstants.MESSAGE_LABEL_OUT_VALUE);
-
requestMC.getOptions().setProperty(HTTPConstants.REUSE_HTTP_CLIENT,
Boolean.TRUE);
+ // ensure connections are tracked so that they can be closed by the
reference binding
+ MessageContext requestMC =
operationClient.getMessageContext(WSDLConstants.MESSAGE_LABEL_OUT_VALUE);
+ requestMC.getOptions().setProperty(HTTPConstants.REUSE_HTTP_CLIENT,
Boolean.TRUE);
- operationClient.execute(false);
+ operationClient.execute(false);
- // REVIEW it seems ok to return null
- return null;
-
- } catch (AxisFault e) {
- throw new InvocationTargetException(e);
- }
+ // REVIEW it seems ok to return null
+ return null;
}
}
Modified:
incubator/tuscany/java/sca/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2ServiceInOutSyncMessageReceiver.java
URL:
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2ServiceInOutSyncMessageReceiver.java?rev=575595&r1=575594&r2=575595&view=diff
==============================================================================
---
incubator/tuscany/java/sca/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2ServiceInOutSyncMessageReceiver.java
(original)
+++
incubator/tuscany/java/sca/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2ServiceInOutSyncMessageReceiver.java
Fri Sep 14 02:26:07 2007
@@ -27,6 +27,7 @@
import org.apache.axis2.context.MessageContext;
import org.apache.axis2.receivers.AbstractInOutSyncMessageReceiver;
import org.apache.tuscany.sca.interfacedef.Operation;
+import org.apache.tuscany.sca.interfacedef.util.FaultException;
public class Axis2ServiceInOutSyncMessageReceiver extends
AbstractInOutSyncMessageReceiver {
@@ -62,6 +63,12 @@
} catch (InvocationTargetException e) {
Throwable t = e.getCause();
+ if (t instanceof FaultException &&
((FaultException)t).getFaultInfo() instanceof OMElement) {
+ OMElement faultDetail =
(OMElement)((FaultException)t).getFaultInfo();
+ inMC.setProperty(Constants.FAULT_NAME,
faultDetail.getQName().getLocalPart());
+ AxisFault f = new AxisFault(null, e.getMessage(), "faultNode",
"faultRole", faultDetail);
+ throw f;
+ }
if (t instanceof Exception) {
throw AxisFault.makeFault((Exception)t);
}
Modified:
incubator/tuscany/java/sca/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/wire/DataTransformationInteceptor.java
URL:
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/wire/DataTransformationInteceptor.java?rev=575595&r1=575594&r2=575595&view=diff
==============================================================================
---
incubator/tuscany/java/sca/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/wire/DataTransformationInteceptor.java
(original)
+++
incubator/tuscany/java/sca/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/wire/DataTransformationInteceptor.java
Fri Sep 14 02:26:07 2007
@@ -20,6 +20,8 @@
package org.apache.tuscany.sca.core.databinding.wire;
import java.lang.reflect.InvocationTargetException;
+import java.net.URI;
+import java.net.URISyntaxException;
import java.util.HashMap;
import java.util.Map;
@@ -31,6 +33,7 @@
import org.apache.tuscany.sca.interfacedef.Operation;
import org.apache.tuscany.sca.interfacedef.impl.DataTypeImpl;
import org.apache.tuscany.sca.interfacedef.util.FaultException;
+import org.apache.tuscany.sca.interfacedef.util.XMLType;
import org.apache.tuscany.sca.invocation.Interceptor;
import org.apache.tuscany.sca.invocation.Invoker;
import org.apache.tuscany.sca.invocation.Message;
@@ -130,7 +133,7 @@
for (DataType exType : sourceOperation.getFaultTypes()) {
DataType faultType = getFaultType(exType);
// Match by the QName (XSD element) of the fault type
- if (faultType != null &&
targetFaultType.getLogical().equals(faultType.getLogical())) {
+ if (faultType != null &&
typesMatch(targetFaultType.getLogical(),faultType.getLogical())) {
sourceDataType = exType;
sourceFaultType = faultType;
break;
@@ -182,6 +185,45 @@
return null;
}
return targetHandler.getFaultType(exceptionType);
+ }
+
+ private boolean typesMatch(Object first, Object second) {
+ if (first.equals(second)) {
+ return true;
+ }
+ if (first instanceof XMLType && second instanceof Class) {
+ if
(toJavaClassName((XMLType)first).equals(((Class)second).getName())) {
+ return true;
+ }
+ }
+ if (first instanceof Class && second instanceof XMLType) {
+ if
(((Class)first).getName().equals(toJavaClassName((XMLType)second))) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ private String toJavaClassName(XMLType type) {
+ String result = type.getElementName().getLocalPart();
+ String authority = "";
+ try {
+ URI uri = new URI(type.getElementName().getNamespaceURI());
+ authority = uri.getAuthority();
+ } catch (URISyntaxException e) {
+ }
+ for (int i = 0; i < authority.length(); ) {
+ int j = authority.indexOf(".", i);
+ if (j == -1) {
+ j = authority.length();
+ }
+ result = authority.substring(i, j) + "." + result;
+ if (j < authority.length()) {
+ j += 1;
+ }
+ i = j;
+ }
+ return result;
}
/**
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]