cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j...@apache.org
Subject svn commit: r488949 - in /incubator/cxf/trunk: rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/ rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/ rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/handler/ systests/src/test/java/org/...
Date Wed, 20 Dec 2006 08:13:37 GMT
Author: jliu
Date: Wed Dec 20 00:13:36 2006
New Revision: 488949

URL: http://svn.apache.org/viewvc?view=rev&rev=488949
Log:
* CXF-319: Access JAXB Payload from logical handler when using Dispatch
* Register handlers programmatically on a Dispatch client


Added:
    incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/handler/LogicalMessageImplTest.java
  (with props)
Modified:
    incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/DispatchImpl.java
    incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/LogicalMessageImpl.java
    incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/HandlerClientServerTest.java

Modified: incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/DispatchImpl.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/DispatchImpl.java?view=diff&rev=488949&r1=488948&r2=488949
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/DispatchImpl.java
(original)
+++ incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/DispatchImpl.java
Wed Dec 20 00:13:36 2006
@@ -45,6 +45,7 @@
 import org.apache.cxf.jaxws.interceptors.DispatchInInterceptor;
 import org.apache.cxf.jaxws.interceptors.DispatchOutInterceptor;
 import org.apache.cxf.jaxws.support.ContextPropertiesMapping;
+import org.apache.cxf.jaxws.support.JaxWsEndpointImpl;
 import org.apache.cxf.message.Exchange;
 import org.apache.cxf.message.ExchangeImpl;
 import org.apache.cxf.message.Message;
@@ -68,7 +69,8 @@
 
     private Endpoint endpoint;
 
-    DispatchImpl(Bus b, Service.Mode m, Class<T> clazz, Executor e, Endpoint ep) {
       
+    DispatchImpl(Bus b, Service.Mode m, Class<T> clazz, Executor e, Endpoint ep) {
+        super(((JaxWsEndpointImpl)ep).getJaxwsBinding());
         bus = b;
         cl = clazz;
         executor = e;
@@ -78,6 +80,7 @@
     }
 
     DispatchImpl(Bus b, Service.Mode m, JAXBContext ctx, Class<T> clazz, Executor e,
Endpoint ep) {
+        super(((JaxWsEndpointImpl)ep).getJaxwsBinding());
         bus = b;
         executor = e;
         context = ctx;

Modified: incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/LogicalMessageImpl.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/LogicalMessageImpl.java?view=diff&rev=488949&r1=488948&r2=488949
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/LogicalMessageImpl.java
(original)
+++ incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/LogicalMessageImpl.java
Wed Dec 20 00:13:36 2006
@@ -27,6 +27,8 @@
 import javax.xml.transform.Source;
 import javax.xml.ws.LogicalMessage;
 
+import org.apache.cxf.message.Message;
+
 
 public class LogicalMessageImpl implements LogicalMessage {
 
@@ -46,7 +48,13 @@
 
     public Object getPayload(JAXBContext arg0) {
         // TODO - what to do with JAXB context?
-        return msgContext.getWrappedMessage().getContent(List.class).get(0);
+        Message msg = msgContext.getWrappedMessage();
+        if (msg.getContent(List.class) != null) {
+            return msg.getContent(List.class).get(0);
+        } else if (msg.getContent(Object.class) != null) {
+            return msg.getContent(Object.class);
+        }
+        return null;
     }
 
     public void setPayload(Object arg0, JAXBContext arg1) {

Added: incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/handler/LogicalMessageImplTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/handler/LogicalMessageImplTest.java?view=auto&rev=488949
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/handler/LogicalMessageImplTest.java
(added)
+++ incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/handler/LogicalMessageImplTest.java
Wed Dec 20 00:13:36 2006
@@ -0,0 +1,72 @@
+/**
+ * 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.jaxws.handler;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.xml.bind.JAXBContext;
+
+import junit.framework.TestCase;
+
+import org.apache.cxf.message.Message;
+import org.apache.cxf.message.MessageImpl;
+import org.apache.handlers.types.AddNumbers;
+
+public class LogicalMessageImplTest extends TestCase {
+    AddNumbers req;
+    List<Object> args;
+
+    public void setUp() {
+        req = new AddNumbers();        
+        req.setArg0(10);
+        req.setArg1(20);
+        args = new ArrayList<Object>();
+        args.add(req);
+    }
+
+    public void tearDown() {
+    }
+
+    public void xtestGetPayloadOfJAXB() throws Exception {
+        //using Dispatch
+        Message message = new MessageImpl();
+        message.setContent(Object.class, req);
+        LogicalMessageContextImpl lmci = new LogicalMessageContextImpl(message);
+        
+        LogicalMessageImpl lmi = new LogicalMessageImpl(lmci);
+        JAXBContext ctx = JAXBContext.newInstance(AddNumbers.class);
+        
+        Object obj = lmi.getPayload(ctx);
+        assertEquals(req, obj);        
+    }
+    
+    public void testGetPayloadOfList() throws Exception {
+        Message message = new MessageImpl();
+        message.setContent(List.class, args);
+        LogicalMessageContextImpl lmci = new LogicalMessageContextImpl(message);
+        
+        LogicalMessageImpl lmi = new LogicalMessageImpl(lmci);
+        
+        JAXBContext ctx = JAXBContext.newInstance(AddNumbers.class);        
+        Object obj = lmi.getPayload(ctx);
+        assertEquals(req, obj);        
+    }    
+}

Propchange: incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/handler/LogicalMessageImplTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/handler/LogicalMessageImplTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/HandlerClientServerTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/HandlerClientServerTest.java?view=diff&rev=488949&r1=488948&r2=488949
==============================================================================
--- incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/HandlerClientServerTest.java
(original)
+++ incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/HandlerClientServerTest.java
Wed Dec 20 00:13:36 2006
@@ -23,9 +23,13 @@
 import java.util.ArrayList;
 import java.util.List;
 
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBElement;
 import javax.xml.namespace.QName;
 
 import javax.xml.ws.BindingProvider;
+import javax.xml.ws.Dispatch;
+import javax.xml.ws.Service;
 import javax.xml.ws.handler.Handler;
 
 import junit.framework.Test;
@@ -35,6 +39,9 @@
 import org.apache.cxf.systest.common.ClientServerTestBase;
 import org.apache.handlers.AddNumbers;
 import org.apache.handlers.AddNumbersService;
+import org.apache.handlers.types.AddNumbersResponse;
+import org.apache.handlers.types.ObjectFactory;
+
 
 public class HandlerClientServerTest extends ClientServerTestBase {
 
@@ -67,6 +74,34 @@
         assertEquals(200, result);
         int result1 = port.addNumbers(5, 6);
         assertEquals(11, result1);
+    }
+    
+    public void testInvokeFromDispatchWithJAXBPayload() throws Exception {
+        URL wsdl = getClass().getResource("/wsdl/addNumbers.wsdl");
+        assertNotNull(wsdl);
+
+        AddNumbersService service = new AddNumbersService(wsdl, serviceName);
+        assertNotNull(service);
+
+        JAXBContext jc = JAXBContext.newInstance("org.apache.handlers.types");
+        Dispatch<Object> disp = service.createDispatch(portName, jc, Service.Mode.PAYLOAD);
+ 
+        //Add client side handlers programmatically
+        SmallNumberHandler sh = new SmallNumberHandler();
+        List<Handler> newHandlerChain = new ArrayList<Handler>();
+        newHandlerChain.add(sh);
+        ((BindingProvider)disp).getBinding().setHandlerChain(newHandlerChain);
+        
+        org.apache.handlers.types.AddNumbers req = new org.apache.handlers.types.AddNumbers();
       
+        req.setArg0(10);
+        req.setArg1(20);        
+        ObjectFactory factory = new ObjectFactory();        
+        JAXBElement e = factory.createAddNumbers(req);        
+
+        JAXBElement response = (JAXBElement)disp.invoke(e);
+        assertNotNull(response);
+        AddNumbersResponse value = (AddNumbersResponse)response.getValue();
+        assertEquals(200, value.getReturn());
     }
 
 }



Mime
View raw message