You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by dk...@apache.org on 2007/02/23 22:23:05 UTC

svn commit: r511105 - in /incubator/cxf/trunk: rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/ rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/soap/ rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/handler/ systests/src/t...

Author: dkulp
Date: Fri Feb 23 13:23:04 2007
New Revision: 511105

URL: http://svn.apache.org/viewvc?view=rev&rev=511105
Log:
CXF-429 - tests from Jarek Gawor
* Fix writing if SOAPMesageHandler doesn't use the soap message.

Added:
    incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxws/ClientServerGreeterTest.java   (with props)
    incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxws/ServerGreeter.java   (with props)
    incubator/cxf/trunk/testutils/src/main/java/org/apache/cxf/greeter_control/
    incubator/cxf/trunk/testutils/src/main/java/org/apache/cxf/greeter_control/GreeterHandler.java   (with props)
    incubator/cxf/trunk/testutils/src/main/java/org/apache/cxf/greeter_control/GreeterImpl.java   (with props)
    incubator/cxf/trunk/testutils/src/main/java/org/apache/cxf/greeter_control/handlers.xml   (with props)
Modified:
    incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/HandlerChainBuilder.java
    incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/soap/SOAPHandlerInterceptor.java
    incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/handler/HandlerChainBuilderTest.java

Modified: incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/HandlerChainBuilder.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/HandlerChainBuilder.java?view=diff&rev=511105&r1=511104&r2=511105
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/HandlerChainBuilder.java (original)
+++ incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/HandlerChainBuilder.java Fri Feb 23 13:23:04 2007
@@ -49,8 +49,6 @@
 
     private Bus bus;
 
-    private boolean handlerInitEnabled;
-
     public HandlerChainBuilder(Bus aBus) {
         bus = aBus;
     }
@@ -92,14 +90,6 @@
         return sortedHandlers;
     }
 
-    public void setHandlerInitEnabled(boolean b) {
-        handlerInitEnabled = b;
-    }
-
-    public boolean isHandlerInitEnabled() {
-        return handlerInitEnabled;
-    }
-
     protected ClassLoader getHandlerClassLoader() {
         return getClass().getClassLoader();
     }
@@ -138,9 +128,6 @@
     } 
     
     private void configureHandler(Handler handler, PortComponentHandlerType h) {
-        if (!handlerInitEnabled) {
-            return;
-        }
 
         if (h.getInitParam().size() == 0) {
             return;

Modified: incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/soap/SOAPHandlerInterceptor.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/soap/SOAPHandlerInterceptor.java?view=diff&rev=511105&r1=511104&r2=511105
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/soap/SOAPHandlerInterceptor.java (original)
+++ incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/soap/SOAPHandlerInterceptor.java Fri Feb 23 13:23:04 2007
@@ -41,6 +41,7 @@
 import javax.xml.ws.handler.MessageContext;
 import javax.xml.ws.handler.soap.SOAPHandler;
 
+import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 
 import org.apache.cxf.binding.soap.SoapFault;
@@ -53,6 +54,7 @@
 import org.apache.cxf.jaxws.handler.AbstractProtocolHandlerInterceptor;
 import org.apache.cxf.message.Message;
 import org.apache.cxf.phase.Phase;
+import org.apache.cxf.staxutils.StaxUtils;
 import org.apache.cxf.staxutils.W3CDOMStreamWriter;
 
 public class SOAPHandlerInterceptor extends
@@ -96,6 +98,8 @@
         }
         
         if (getInvoker(message).isOutbound()) {
+            XMLStreamWriter origWriter = message.getContent(XMLStreamWriter.class);
+            
             try {
                 // Replace stax writer with DomStreamWriter
                 W3CDOMStreamWriter writer = new W3CDOMStreamWriter();
@@ -118,7 +122,11 @@
                     OutputStream os = message.getContent(OutputStream.class);
                     soapMessage.writeTo(os);
                     os.flush();
-                } 
+                } else {
+                    XMLStreamWriter xtw = message.getContent(XMLStreamWriter.class);
+                    Document doc = ((W3CDOMStreamWriter)xtw).getDocument();
+                    StaxUtils.writeDocument(doc, origWriter, false);
+                }
                 
             } catch (IOException ioe) {
                 throw new SoapFault(new org.apache.cxf.common.i18n.Message(
@@ -127,6 +135,10 @@
             } catch (SOAPException soape) {
                 throw new SoapFault(new org.apache.cxf.common.i18n.Message(
                         "SOAPHANDLERINTERCEPTOR_EXCEPTION", BUNDLE), soape,
+                        message.getVersion().getSender());
+            } catch (XMLStreamException e) {
+                throw new SoapFault(new org.apache.cxf.common.i18n.Message(
+                        "SOAPHANDLERINTERCEPTOR_EXCEPTION", BUNDLE), e,
                         message.getVersion().getSender());
             }
         } else {

Modified: incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/handler/HandlerChainBuilderTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/handler/HandlerChainBuilderTest.java?view=diff&rev=511105&r1=511104&r2=511105
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/handler/HandlerChainBuilderTest.java (original)
+++ incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/handler/HandlerChainBuilderTest.java Fri Feb 23 13:23:04 2007
@@ -46,9 +46,6 @@
 
     HandlerChainBuilder builder = new HandlerChainBuilder(EasyMock.createNiceMock(Bus.class));
 
-    public void setUp() {
-        builder.setHandlerInitEnabled(true);
-    }
 
     public void testChainSorting() {
         List<Handler> sortedHandlerChain = builder.sortHandlers(Arrays.asList(allHandlers));

Added: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxws/ClientServerGreeterTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxws/ClientServerGreeterTest.java?view=auto&rev=511105
==============================================================================
--- incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxws/ClientServerGreeterTest.java (added)
+++ incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxws/ClientServerGreeterTest.java Fri Feb 23 13:23:04 2007
@@ -0,0 +1,61 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.cxf.systest.jaxws;
+
+import java.lang.reflect.UndeclaredThrowableException;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import org.apache.cxf.greeter_control.Greeter;
+import org.apache.cxf.greeter_control.GreeterService;
+import org.apache.cxf.systest.common.ClientServerSetupBase;
+
+public class ClientServerGreeterTest extends TestCase {
+
+    public static Test suite() throws Exception {
+        TestSuite suite = new TestSuite(ClientServerGreeterTest.class);
+        return new ClientServerSetupBase(suite) {
+            public void startServers() throws Exception {
+                assertTrue("server did not launch correctly",
+                           launchServer(ServerGreeter.class));
+            }
+        };
+    }
+    
+    public void testInvocation() throws Exception {
+
+        GreeterService service = new GreeterService();
+        assertNotNull(service);
+
+        try {
+            Greeter greeter = service.getGreeterPort();
+            
+            String greeting = greeter.greetMe("Bonjour");
+            assertNotNull("no response received from service", greeting);
+            assertEquals("Hello Bonjour", greeting);
+
+        } catch (UndeclaredThrowableException ex) {
+            throw (Exception)ex.getCause();
+        }
+    }
+
+}

Propchange: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxws/ClientServerGreeterTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxws/ClientServerGreeterTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxws/ServerGreeter.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxws/ServerGreeter.java?view=auto&rev=511105
==============================================================================
--- incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxws/ServerGreeter.java (added)
+++ incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxws/ServerGreeter.java Fri Feb 23 13:23:04 2007
@@ -0,0 +1,46 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.cxf.systest.jaxws;
+
+import javax.xml.ws.Endpoint;
+
+import org.apache.cxf.greeter_control.GreeterImpl;
+import org.apache.cxf.systest.common.TestServerBase;
+
+public class ServerGreeter extends TestServerBase {
+
+    protected void run() {
+        Object implementor = new GreeterImpl();
+        String address = "http://localhost:9020/SoapContext/GreeterPort";
+        Endpoint.publish(address, implementor);
+    }
+
+    public static void main(String[] args) {
+        try {
+            ServerGreeter s = new ServerGreeter();
+            s.start();
+        } catch (Exception ex) {
+            ex.printStackTrace();
+            System.exit(-1);
+        } finally {
+            System.out.println("done!");
+        }
+    }
+}

Propchange: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxws/ServerGreeter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxws/ServerGreeter.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/cxf/trunk/testutils/src/main/java/org/apache/cxf/greeter_control/GreeterHandler.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/testutils/src/main/java/org/apache/cxf/greeter_control/GreeterHandler.java?view=auto&rev=511105
==============================================================================
--- incubator/cxf/trunk/testutils/src/main/java/org/apache/cxf/greeter_control/GreeterHandler.java (added)
+++ incubator/cxf/trunk/testutils/src/main/java/org/apache/cxf/greeter_control/GreeterHandler.java Fri Feb 23 13:23:04 2007
@@ -0,0 +1,68 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cxf.greeter_control;
+
+import java.util.Set;
+import javax.annotation.PostConstruct;
+import javax.annotation.PreDestroy;
+import javax.annotation.Resource;
+import javax.xml.namespace.QName;
+import javax.xml.ws.handler.MessageContext;
+import javax.xml.ws.handler.soap.SOAPHandler;
+import javax.xml.ws.handler.soap.SOAPMessageContext;
+
+
+public class GreeterHandler implements SOAPHandler<SOAPMessageContext> {
+    
+    @Resource(name = "greeting")
+    private String greeting;
+    
+    public GreeterHandler() {
+        System.out.println(this + " Construct");
+    }
+
+    @PostConstruct
+    public void init() {
+        System.out.println(this + " PostConstruct");
+    }
+
+    @PreDestroy
+    public void destroy() {
+        System.out.println(this + " PreDestroy");
+    }
+
+    public boolean handleMessage(SOAPMessageContext smc) {
+        System.out.println(this + " handleMessage(): " + greeting);
+        return true;
+    }
+       
+    public boolean handleFault(SOAPMessageContext smc) {
+        System.out.println(this + " handleFault()");
+        return true;
+    }
+    
+    public void close(MessageContext messageContext) {
+        System.out.println(this + " close()");
+    }
+    
+    public Set<QName> getHeaders() {
+        return null;
+    }
+    
+}

Propchange: incubator/cxf/trunk/testutils/src/main/java/org/apache/cxf/greeter_control/GreeterHandler.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/cxf/trunk/testutils/src/main/java/org/apache/cxf/greeter_control/GreeterHandler.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/cxf/trunk/testutils/src/main/java/org/apache/cxf/greeter_control/GreeterImpl.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/testutils/src/main/java/org/apache/cxf/greeter_control/GreeterImpl.java?view=auto&rev=511105
==============================================================================
--- incubator/cxf/trunk/testutils/src/main/java/org/apache/cxf/greeter_control/GreeterImpl.java (added)
+++ incubator/cxf/trunk/testutils/src/main/java/org/apache/cxf/greeter_control/GreeterImpl.java Fri Feb 23 13:23:04 2007
@@ -0,0 +1,83 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.cxf.greeter_control;
+
+import java.util.concurrent.Future;
+
+import javax.jws.HandlerChain;
+import javax.jws.WebService;
+import javax.xml.ws.AsyncHandler;
+import javax.xml.ws.Response;
+
+import org.apache.cxf.greeter_control.types.GreetMeResponse;
+import org.apache.cxf.greeter_control.types.PingMeResponse;
+import org.apache.cxf.greeter_control.types.SayHiResponse;
+
+@WebService(serviceName = "GreeterService",
+            portName = "GreeterPort",
+            endpointInterface = "org.apache.cxf.greeter_control.Greeter",
+            targetNamespace = "http://cxf.apache.org/greeter_control")
+@HandlerChain(file = "handlers.xml")
+public class GreeterImpl implements Greeter {
+
+    public String greetMe(String me) {
+        return "Hello " + me;
+    }
+
+    public String sayHi() {
+        return "Bonjour";
+    }
+
+    public void greetMeOneWay(String requestType) {
+        System.out.println("*********  greetMeOneWay: " + requestType);
+    }
+
+    public void pingMe() throws PingMeFault {
+    }
+
+    public Future<?> greetMeAsync(String requestType, AsyncHandler<GreetMeResponse> asyncHandler) {
+        return null;
+        /*not called */
+    }
+
+    public Response<GreetMeResponse> greetMeAsync(String requestType) {
+        return null;
+        /*not called */
+    }
+
+    public Future<?> sayHiAsync(AsyncHandler<SayHiResponse> asyncHandler) {
+        return null;
+        /*not called */
+    }
+
+    public Response<SayHiResponse> sayHiAsync() {
+        return null;
+        /*not called */
+    }
+
+    public Response<PingMeResponse> pingMeAsync() {
+        return null;
+    }
+    
+    public Future<?> pingMeAsync(AsyncHandler<PingMeResponse> asyncHandler) {
+        return null;
+    }
+
+}

Propchange: incubator/cxf/trunk/testutils/src/main/java/org/apache/cxf/greeter_control/GreeterImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/cxf/trunk/testutils/src/main/java/org/apache/cxf/greeter_control/GreeterImpl.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/cxf/trunk/testutils/src/main/java/org/apache/cxf/greeter_control/handlers.xml
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/testutils/src/main/java/org/apache/cxf/greeter_control/handlers.xml?view=auto&rev=511105
==============================================================================
--- incubator/cxf/trunk/testutils/src/main/java/org/apache/cxf/greeter_control/handlers.xml (added)
+++ incubator/cxf/trunk/testutils/src/main/java/org/apache/cxf/greeter_control/handlers.xml Fri Feb 23 13:23:04 2007
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<jws:handler-chains xmlns:jws="http://java.sun.com/xml/ns/javaee">
+  <jws:handler-chain>
+    <jws:handler>
+      <jws:handler-name>GreeterHandler</jws:handler-name>
+      <jws:handler-class>org.apache.cxf.greeter_control.GreeterHandler</jws:handler-class>
+    </jws:handler>
+  </jws:handler-chain>
+</jws:handler-chains>

Propchange: incubator/cxf/trunk/testutils/src/main/java/org/apache/cxf/greeter_control/handlers.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/cxf/trunk/testutils/src/main/java/org/apache/cxf/greeter_control/handlers.xml
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: incubator/cxf/trunk/testutils/src/main/java/org/apache/cxf/greeter_control/handlers.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml