Author: gnodet
Date: Mon Sep 25 04:09:46 2006
New Revision: 449649

URL: http://svn.apache.org/viewvc?view=rev&rev=449649
Log:
SM-577: JSR181 fault messages does not respect WSDL message fault definition

Modified:
    
incubator/servicemix/trunk/servicemix-itests/src/test/java/org/apache/servicemix/itests/Jsr181HttpTest.java
    
incubator/servicemix/trunk/servicemix-itests/src/test/java/org/apache/servicemix/itests/PersonTest.java
    
incubator/servicemix/trunk/servicemix-itests/src/test/java/org/apache/servicemix/itests/beans/Echo.java
    
incubator/servicemix/trunk/servicemix-jsr181/src/main/java/org/apache/servicemix/jsr181/Jsr181ExchangeProcessor.java
    
incubator/servicemix/trunk/servicemix-jsr181/src/main/java/org/apache/servicemix/jsr181/xfire/JbiFaultSerializer.java

Modified: 
incubator/servicemix/trunk/servicemix-itests/src/test/java/org/apache/servicemix/itests/Jsr181HttpTest.java
URL: 
http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-itests/src/test/java/org/apache/servicemix/itests/Jsr181HttpTest.java?view=diff&rev=449649&r1=449648&r2=449649
==============================================================================
--- 
incubator/servicemix/trunk/servicemix-itests/src/test/java/org/apache/servicemix/itests/Jsr181HttpTest.java
 (original)
+++ 
incubator/servicemix/trunk/servicemix-itests/src/test/java/org/apache/servicemix/itests/Jsr181HttpTest.java
 Mon Sep 25 04:09:46 2006
@@ -16,11 +16,21 @@
  */
 package org.apache.servicemix.itests;
 
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
 import java.io.StringWriter;
 
+import javax.servlet.http.HttpServletResponse;
 import javax.wsdl.Definition;
 import javax.wsdl.factory.WSDLFactory;
 
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.HttpMethod;
+import org.apache.commons.httpclient.HttpMethodRetryHandler;
+import org.apache.commons.httpclient.methods.PostMethod;
+import org.apache.commons.httpclient.methods.StringRequestEntity;
+import org.apache.commons.httpclient.params.HttpMethodParams;
+import org.apache.servicemix.jbi.util.FileUtil;
 import org.apache.servicemix.tck.SpringTestSupport;
 import org.apache.xbean.spring.context.ClassPathXmlApplicationContext;
 import org.springframework.context.support.AbstractXmlApplicationContext;
@@ -31,12 +41,38 @@
         return new 
ClassPathXmlApplicationContext("org/apache/servicemix/itests/jsr181http.xml");
     }
     
-    public void test() throws Exception {
+    public void testWSDL() throws Exception {
         WSDLFactory wsdlFactory = WSDLFactory.newInstance();
         Definition def = 
wsdlFactory.newWSDLReader().readWSDL("http://localhost:8194/Service/?wsdl";);
         StringWriter writer = new StringWriter();
         wsdlFactory.newWSDLWriter().writeWSDL(def, writer);
         System.err.println(writer.toString());
+    }
+    
+    public void testRequest() throws Exception {
+        PostMethod method = new PostMethod("http://localhost:8194/Service/";);
+        method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new 
HttpMethodRetryHandler() {
+            public boolean retryMethod(HttpMethod method, IOException 
exception, int executionCount) {
+                return false;
+            }
+        });
+        method.setRequestEntity(new StringRequestEntity(
+                        "<env:Envelope 
xmlns:env='http://www.w3.org/2003/05/soap-envelope'>" + 
+                        "  <env:Body>" + 
+                        "    <echo xmlns='http://servicemix.org/test/'>" + 
+                        "      <req>" + 
+                        "        <msg 
xmlns='http://beans.itests.servicemix.apache.org'>" +
+                        "          world" +
+                        "        </msg>" +
+                        "      </req>" +
+                        "    </echo>" +
+                        "  </env:body" +
+                        "</env:Envelope>"));
+        int state = new HttpClient().executeMethod(method);
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        FileUtil.copyInputStream(method.getResponseBodyAsStream(), baos);
+        System.err.println(baos.toString());
+        assertEquals(HttpServletResponse.SC_OK, state);
     }
 
 }

Modified: 
incubator/servicemix/trunk/servicemix-itests/src/test/java/org/apache/servicemix/itests/PersonTest.java
URL: 
http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-itests/src/test/java/org/apache/servicemix/itests/PersonTest.java?view=diff&rev=449649&r1=449648&r2=449649
==============================================================================
--- 
incubator/servicemix/trunk/servicemix-itests/src/test/java/org/apache/servicemix/itests/PersonTest.java
 (original)
+++ 
incubator/servicemix/trunk/servicemix-itests/src/test/java/org/apache/servicemix/itests/PersonTest.java
 Mon Sep 25 04:09:46 2006
@@ -51,12 +51,36 @@
         method.setRequestEntity(new StringRequestEntity(req));
         new HttpClient().executeMethod(method);
         System.err.println(method.getResponseBodyAsString());;
-        /*
-        Person p = new PersonServiceService().getsoap();
-        GetPerson gp = new GetPerson();
-        gp.setPersonId("gnodet");
-        GetPersonResponse gpr = p.getPerson(gp);
-        */
+    }
+
+    public void testFault() throws Exception {
+        PostMethod method = new 
PostMethod("http://localhost:8192/PersonService/";);
+        String req = "<env:Envelope 
xmlns:env=\"http://schemas.xmlsoap.org/soap/envelope/\"; " +
+                     "              
xmlns:tns=\"http://servicemix.apache.org/samples/wsdl-first/types\";>" +
+                     "  <env:Body>" +
+                     "    <tns:GetPerson>" +
+                     "       <tns:personId></tns:personId>" +
+                     "    </tns:GetPerson>" +
+                     "  </env:Body>" +
+                     "</env:Envelope>";
+        method.setRequestEntity(new StringRequestEntity(req));
+        new HttpClient().executeMethod(method);
+        System.err.println(method.getResponseBodyAsString());;
+    }
+
+    public void testFault2() throws Exception {
+        PostMethod method = new 
PostMethod("http://localhost:8192/PersonService/";);
+        String req = "<env:Envelope 
xmlns:env=\"http://schemas.xmlsoap.org/soap/envelope/\"; " +
+                     "              
xmlns:tns=\"http://servicemix.apache.org/samples/wsdl-first/types\";>" +
+                     "  <env:Body>" +
+                     "    <tns:GetPerson>" +
+                     "       <tns:personI></tns:personId>" +
+                     "    </tns:GetPerson>" +
+                     "  </env:Body>" +
+                     "</env:Envelope>";
+        method.setRequestEntity(new StringRequestEntity(req));
+        new HttpClient().executeMethod(method);
+        System.err.println(method.getResponseBodyAsString());;
     }
 
 }

Modified: 
incubator/servicemix/trunk/servicemix-itests/src/test/java/org/apache/servicemix/itests/beans/Echo.java
URL: 
http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-itests/src/test/java/org/apache/servicemix/itests/beans/Echo.java?view=diff&rev=449649&r1=449648&r2=449649
==============================================================================
--- 
incubator/servicemix/trunk/servicemix-itests/src/test/java/org/apache/servicemix/itests/beans/Echo.java
 (original)
+++ 
incubator/servicemix/trunk/servicemix-itests/src/test/java/org/apache/servicemix/itests/beans/Echo.java
 Mon Sep 25 04:09:46 2006
@@ -21,9 +21,31 @@
 
 @WebService
 public class Echo {
+    
+    public static class Request {
+        private String msg;
+        public String getMsg() {
+            return msg;
+        }
+        public void setMsg(String msg) {
+            this.msg = msg;
+        }
+    }
+
+    public static class Response {
+        private String msg;
+        public String getMsg() {
+            return msg;
+        }
+        public void setMsg(String msg) {
+            this.msg = msg;
+        }
+    }
 
     @WebMethod
-    public String echo(String msg) {
-        return "Hello: " + msg;
+    public Response echo(Request req) {
+        Response r = new Response();
+        r.setMsg("Hello: " + req.getMsg());
+        return r;
     }
 }

Modified: 
incubator/servicemix/trunk/servicemix-jsr181/src/main/java/org/apache/servicemix/jsr181/Jsr181ExchangeProcessor.java
URL: 
http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-jsr181/src/main/java/org/apache/servicemix/jsr181/Jsr181ExchangeProcessor.java?view=diff&rev=449649&r1=449648&r2=449649
==============================================================================
--- 
incubator/servicemix/trunk/servicemix-jsr181/src/main/java/org/apache/servicemix/jsr181/Jsr181ExchangeProcessor.java
 (original)
+++ 
incubator/servicemix/trunk/servicemix-jsr181/src/main/java/org/apache/servicemix/jsr181/Jsr181ExchangeProcessor.java
 Mon Sep 25 04:09:46 2006
@@ -33,7 +33,6 @@
 import javax.xml.transform.TransformerException;
 
 import org.apache.servicemix.common.ExchangeProcessor;
-import org.apache.servicemix.common.xbean.XBeanServiceUnit;
 import org.apache.servicemix.jbi.jaxp.StAXSourceTransformer;
 import org.apache.servicemix.jbi.jaxp.StringSource;
 import org.apache.servicemix.jsr181.xfire.JbiTransport;
@@ -42,6 +41,7 @@
 import org.codehaus.xfire.attachments.JavaMailAttachments;
 import org.codehaus.xfire.attachments.SimpleAttachment;
 import org.codehaus.xfire.exchange.InMessage;
+import org.codehaus.xfire.fault.XFireFault;
 import org.codehaus.xfire.service.OperationInfo;
 import org.codehaus.xfire.service.Service;
 import org.codehaus.xfire.transport.Channel;
@@ -49,6 +49,12 @@
 
 public class Jsr181ExchangeProcessor implements ExchangeProcessor {
 
+    public static final String SOAP_FAULT_CODE = 
"org.apache.servicemix.soap.fault.code";
+    public static final String SOAP_FAULT_SUBCODE = 
"org.apache.servicemix.soap.fault.subcode";
+    public static final String SOAP_FAULT_REASON = 
"org.apache.servicemix.soap.fault.reason";
+    public static final String SOAP_FAULT_NODE = 
"org.apache.servicemix.soap.fault.node";
+    public static final String SOAP_FAULT_ROLE = 
"org.apache.servicemix.soap.fault.role";
+    
     protected DeliveryChannel channel;
     protected Jsr181Endpoint endpoint;
     protected StAXSourceTransformer transformer;
@@ -59,24 +65,12 @@
     }
 
     public void process(MessageExchange exchange) throws Exception {
-        ClassLoader oldCl = Thread.currentThread().getContextClassLoader();
-        try {
-            ClassLoader classLoader = ((XBeanServiceUnit) 
endpoint.getServiceUnit()).getConfigurationClassLoader();
-            Thread.currentThread().setContextClassLoader(classLoader);
-            doProcess(exchange);
-        } finally {
-            Thread.currentThread().setContextClassLoader(oldCl);
-        }
-    }    
-        
-    protected void doProcess(MessageExchange exchange) throws Exception {
         if (exchange.getStatus() == ExchangeStatus.DONE) {
             return;
         } else if (exchange.getStatus() == ExchangeStatus.ERROR) {
             return;
         }
 
-        // TODO: fault should not be serialized as soap
         // TODO: clean this code
         XFire xfire = endpoint.getXFire();
         Service service = endpoint.getXFireService();
@@ -116,6 +110,11 @@
             if (ctx.getExchange().hasFaultMessage() && 
ctx.getExchange().getFaultMessage().getBody() != null) {
                 Fault fault = exchange.createFault();
                 fault.setContent(new StringSource(out.toString()));
+                XFireFault xFault = (XFireFault) 
ctx.getExchange().getFaultMessage().getBody();
+                fault.setProperty(SOAP_FAULT_CODE, xFault.getFaultCode());
+                fault.setProperty(SOAP_FAULT_REASON, xFault.getReason());
+                fault.setProperty(SOAP_FAULT_ROLE, xFault.getRole());
+                fault.setProperty(SOAP_FAULT_SUBCODE, xFault.getSubCode());
                 exchange.setFault(fault);
             } else {
                 NormalizedMessage outMsg = exchange.createMessage();

Modified: 
incubator/servicemix/trunk/servicemix-jsr181/src/main/java/org/apache/servicemix/jsr181/xfire/JbiFaultSerializer.java
URL: 
http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-jsr181/src/main/java/org/apache/servicemix/jsr181/xfire/JbiFaultSerializer.java?view=diff&rev=449649&r1=449648&r2=449649
==============================================================================
--- 
incubator/servicemix/trunk/servicemix-jsr181/src/main/java/org/apache/servicemix/jsr181/xfire/JbiFaultSerializer.java
 (original)
+++ 
incubator/servicemix/trunk/servicemix-jsr181/src/main/java/org/apache/servicemix/jsr181/xfire/JbiFaultSerializer.java
 Mon Sep 25 04:09:46 2006
@@ -48,21 +48,14 @@
     public void writeMessage(OutMessage message, XMLStreamWriter writer, 
MessageContext context) throws XFireFault {
         try {
             XFireFault fault = (XFireFault) message.getBody();
-            writer.writeStartElement("fault");
-            writer.writeStartElement("message");
-            writer.writeCharacters(fault.getMessage());
-            writer.writeEndElement(); // message
             if (fault.hasDetails()) {
                 Element detail = fault.getDetail();
-                writer.writeStartElement("detail");
                 StaxSerializer serializer = new StaxSerializer();
                 List details = detail.getContent();
                 for (int i = 0; i < details.size(); i++) {
                     serializer.writeElement((Element) details.get(i), writer);
                 }
-                writer.writeEndElement(); // detail
-            }
-            if (configuration.isPrintStackTraceInFaults()) {
+            } else {
                 writer.writeStartElement("stack");
                 StringWriter sw = new StringWriter();
                 PrintWriter pw = new PrintWriter(sw);
@@ -71,7 +64,6 @@
                 writer.writeCData(sw.toString());
                 writer.writeEndElement(); // stack
             }
-            writer.writeEndElement(); // fault
         } catch (XMLStreamException e) {
             throw new XFireRuntimeException("Couldn't create fault.", e);
         }


Reply via email to