servicemix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gno...@apache.org
Subject svn commit: r358002 - /incubator/servicemix/trunk/servicemix-wsn2005/src/main/java/org/servicemix/wsn/component/WSNEndpoint.java
Date Tue, 20 Dec 2005 14:46:42 GMT
Author: gnodet
Date: Tue Dec 20 06:46:38 2005
New Revision: 358002

URL: http://svn.apache.org/viewcvs?rev=358002&view=rev
Log:
Add simple fault processing to WSN endpoints (need to test with soap binding)

Modified:
    incubator/servicemix/trunk/servicemix-wsn2005/src/main/java/org/servicemix/wsn/component/WSNEndpoint.java

Modified: incubator/servicemix/trunk/servicemix-wsn2005/src/main/java/org/servicemix/wsn/component/WSNEndpoint.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-wsn2005/src/main/java/org/servicemix/wsn/component/WSNEndpoint.java?rev=358002&r1=358001&r2=358002&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-wsn2005/src/main/java/org/servicemix/wsn/component/WSNEndpoint.java
(original)
+++ incubator/servicemix/trunk/servicemix-wsn2005/src/main/java/org/servicemix/wsn/component/WSNEndpoint.java
Tue Dec 20 06:46:38 2005
@@ -1,6 +1,7 @@
 package org.servicemix.wsn.component;
 
 import java.io.StringWriter;
+import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
 import java.util.ArrayList;
 import java.util.Arrays;
@@ -9,6 +10,8 @@
 import javax.jbi.component.ComponentContext;
 import javax.jbi.messaging.DeliveryChannel;
 import javax.jbi.messaging.ExchangeStatus;
+import javax.jbi.messaging.Fault;
+import javax.jbi.messaging.InOnly;
 import javax.jbi.messaging.MessageExchange;
 import javax.jbi.messaging.NormalizedMessage;
 import javax.jbi.messaging.MessageExchange.Role;
@@ -17,8 +20,11 @@
 import javax.jws.WebMethod;
 import javax.jws.WebService;
 import javax.xml.bind.JAXBContext;
+import javax.xml.bind.annotation.XmlRootElement;
 import javax.xml.namespace.QName;
+import javax.xml.ws.WebFault;
 
+import org.oasis_open.docs.wsrf.bf_1.BaseFaultType;
 import org.servicemix.common.Endpoint;
 import org.servicemix.common.ExchangeProcessor;
 import org.servicemix.jbi.jaxp.StringSource;
@@ -61,6 +67,7 @@
 		}
 		endpointInterface = Class.forName(ws.endpointInterface());
 		List<Class> classes = new ArrayList<Class>();
+		classes.add(JbiFault.class);
 		for (Method mth : endpointInterface.getMethods()) {
 			WebMethod wm = (WebMethod) mth.getAnnotation(WebMethod.class);
 			if (wm != null) {
@@ -84,6 +91,7 @@
 		return this;
 	}
 
+	@SuppressWarnings("unchecked")
 	public void process(MessageExchange exchange) throws Exception {
 		if (exchange.getStatus() == ExchangeStatus.DONE) {
 			return;
@@ -104,8 +112,33 @@
 		if (webMethod ==  null) {
 			throw new IllegalStateException("Could not determine invoked web method");
 		}
-		Object output = webMethod.invoke(pojo, new Object[] { input });
-		if (webMethod.getAnnotation(Oneway.class) != null) {
+		boolean oneWay = webMethod.getAnnotation(Oneway.class) != null;
+		Object output;
+		try {
+			output = webMethod.invoke(pojo, new Object[] { input });
+		} catch (InvocationTargetException e) {
+			if (e.getCause() instanceof Exception) {
+				WebFault fa = (WebFault) e.getCause().getClass().getAnnotation(WebFault.class);
+				if (exchange instanceof InOnly == false && fa != null) {
+					BaseFaultType info = (BaseFaultType) e.getCause().getClass().getMethod("getFaultInfo",
null).invoke(e.getCause(), null);
+					Fault fault = exchange.createFault();
+					exchange.setFault(fault);
+					exchange.setError((Exception) e.getCause());
+					StringWriter writer = new StringWriter();
+					jaxbContext.createMarshaller().marshal(new JbiFault(info), writer);
+					fault.setContent(new StringSource(writer.toString()));
+					channel.send(exchange);
+					return;
+				} else {
+					throw (Exception) e.getCause();
+				}
+			} else if (e.getCause() instanceof Error) {
+				throw (Error) e.getCause();
+			} else {
+				throw new RuntimeException(e.getCause());
+			}
+		}
+		if (oneWay) {
 			exchange.setStatus(ExchangeStatus.DONE);
 			channel.send(exchange);
 		} else {
@@ -118,6 +151,22 @@
 		}
 	}
 	
+	@XmlRootElement(name = "Fault")
+	public static class JbiFault {
+		private BaseFaultType info;
+		public JbiFault() {
+		}
+		public JbiFault(BaseFaultType info) {
+			this.info = info;
+		}
+		public BaseFaultType getInfo() {
+			return info;
+		}
+		public void setInfo(BaseFaultType info) {
+			this.info = info;
+		}
+	}
+	
 	protected Method getWebServiceMethod(QName interfaceName, QName operation) throws Exception
{
 		WebService ws = getWebServiceAnnotation();
 		if (ws == null) {
@@ -133,6 +182,7 @@
 		return null;
 	}
 
+	@SuppressWarnings("unchecked")
 	protected WebService getWebServiceAnnotation() {
 		for (Class cl = pojo.getClass(); cl != null; cl = cl.getSuperclass()) {
 			WebService ws = (WebService) cl.getAnnotation(WebService.class);



Mime
View raw message