cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dand...@apache.org
Subject svn commit: r463023 - in /incubator/cxf/trunk/rt: core/src/main/java/org/apache/cxf/service/invoker/ frontend/jaxws/src/main/java/org/apache/cxf/jaxws/ frontend/jaxws/src/test/java/org/apache/cxf/jaxws/ frontend/jaxws/src/test/java/org/apache/cxf/jaxws...
Date Wed, 11 Oct 2006 22:52:45 GMT
Author: dandiep
Date: Wed Oct 11 15:52:44 2006
New Revision: 463023

URL: http://svn.apache.org/viewvc?view=rev&rev=463023
Log:
o CXF-115: Add constructor to provide service to EndpointImpl.
  It actually provides a servicefactory as we need to grab information
  from it.
o Add the ability to provide Exchange as a parameter to an invocation.
  This is a feature in XFire and is really handy in places where you're 
  writing a simple service which gets a Source and needs additional
  info from the Exchange.

Modified:
    incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/service/invoker/AbstractInvoker.java
    incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/EndpointImpl.java
    incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/JAXWSMethodInvoker.java
    incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/CodeFirstTest.java
    incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/EndpointImplTest.java
    incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/provider/ProviderTest.java
    incubator/cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/service/factory/DefaultServiceConfiguration.java
    incubator/cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/service/factory/ServerFactoryBean.java
    incubator/cxf/trunk/rt/frontend/simple/src/test/java/org/apache/cxf/service/factory/HelloService.java
    incubator/cxf/trunk/rt/frontend/simple/src/test/java/org/apache/cxf/service/factory/ReflectionServiceFactoryTest.java

Modified: incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/service/invoker/AbstractInvoker.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/service/invoker/AbstractInvoker.java?view=diff&rev=463023&r1=463022&r2=463023
==============================================================================
--- incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/service/invoker/AbstractInvoker.java
(original)
+++ incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/service/invoker/AbstractInvoker.java
Wed Oct 11 15:52:44 2006
@@ -23,7 +23,6 @@
 import java.lang.reflect.Method;
 import java.lang.reflect.Proxy;
 import java.util.ArrayList;
-import java.util.Arrays;
 import java.util.List;
 
 import org.apache.cxf.helpers.CastUtils;
@@ -53,18 +52,26 @@
         m = matchMethod(m, serviceObject);
         List<Object> params = CastUtils.cast((List<?>)o);
 
+        return invoke(exchange, serviceObject, m, params);
+    }
+
+    protected Object invoke(Exchange exchange, final Object serviceObject, Method m, List<Object>
params) {
         Object res;
         try {
             Object[] paramArray = params.toArray();
+            
+            insertExchange(m, paramArray, exchange);
+            
             res = m.invoke(serviceObject, paramArray);
             if (exchange.isOneWay()) {
                 return null;
             }
+            
             List<Object> retList = new ArrayList<Object>();
             if (!((Class)m.getReturnType()).getName().equals("void")) {
                 retList.add(res);
             }
-            return Arrays.asList(retList.toArray());
+            return retList;
         } catch (InvocationTargetException e) {
             Throwable t = e.getCause();
             if (t == null) {
@@ -76,6 +83,26 @@
         }
     }
 
+    public Object[] insertExchange(Method method, Object[] params, Exchange context) {
+        Object[] newParams = params;
+        for (int i = 0; i < method.getParameterTypes().length; i++) {
+            if (method.getParameterTypes()[i].equals(Exchange.class)) {
+                newParams = new Object[params.length + 1];
+
+                for (int j = 0; j < newParams.length; j++) {
+                    if (j == i) {
+                        newParams[j] = context;
+                    } else if (j > i) {
+                        newParams[j] = params[j - 1];
+                    } else {
+                        newParams[j] = params[j];
+                    }
+                }
+            }
+        }
+        return newParams;
+    }
+    
     /**
      * Creates and returns a service object depending on the scope.
      */

Modified: incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/EndpointImpl.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/EndpointImpl.java?view=diff&rev=463023&r1=463022&r2=463023
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/EndpointImpl.java
(original)
+++ incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/EndpointImpl.java
Wed Oct 11 15:52:44 2006
@@ -67,6 +67,20 @@
     private JaxWsImplementorInfo implInfo;
     private ReflectionServiceFactoryBean serviceFactory;
     
+    public EndpointImpl(Bus b, Object implementor, JaxWsServiceFactoryBean serviceFactory)
{
+        this.bus = b;
+        this.serviceFactory = serviceFactory;
+        this.implInfo = serviceFactory.getJaxWsImplementorInfo();
+        this.service = serviceFactory.getService();
+        this.implementor = implementor;
+        
+        if (this.service == null) {
+            service = serviceFactory.create();
+        }
+        
+        doInit = true;
+    }
+    
     @SuppressWarnings("unchecked")
     public EndpointImpl(Bus b, Object i, String uri) {
         bus = b;

Modified: incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/JAXWSMethodInvoker.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/JAXWSMethodInvoker.java?view=diff&rev=463023&r1=463022&r2=463023
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/JAXWSMethodInvoker.java
(original)
+++ incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/JAXWSMethodInvoker.java
Wed Oct 11 15:52:44 2006
@@ -21,70 +21,33 @@
 
 import java.lang.reflect.Array;
 import java.lang.reflect.GenericArrayType;
-import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
 import java.lang.reflect.ParameterizedType;
 import java.lang.reflect.Type;
-import java.util.ArrayList;
-import java.util.Arrays;
 import java.util.List;
 
 import javax.xml.ws.Holder;
 
-import org.apache.cxf.interceptor.Fault;
 import org.apache.cxf.message.Exchange;
-import org.apache.cxf.service.Service;
-import org.apache.cxf.service.factory.MethodDispatcher;
-import org.apache.cxf.service.invoker.Invoker;
-import org.apache.cxf.service.model.BindingOperationInfo;
+import org.apache.cxf.service.invoker.BeanInvoker;
 
-public class JAXWSMethodInvoker implements Invoker {
-
-    private Object bean;
+public class JAXWSMethodInvoker extends BeanInvoker {
 
     public JAXWSMethodInvoker(Object bean) {
-        super();
-        this.bean = bean;
+        super(bean);
     }
 
     @SuppressWarnings("unchecked")
-    public Object invoke(Exchange exchange, Object o) {
-        BindingOperationInfo bop = exchange.get(BindingOperationInfo.class);
-        MethodDispatcher md = (MethodDispatcher) exchange.get(Service.class).get(
-                        MethodDispatcher.class.getName());
-        Method m = md.getMethod(bop);
-        
-        List<Object> params = (List<Object>) o;
-
+    protected Object invoke(Exchange exchange, final Object serviceObject, Method m, List<Object>
params) {
         checkHolder(m, params, exchange);
-        Object res;
-        try {
-            Object[] paramArray = params.toArray();
-            res = m.invoke(bean, paramArray);
-            if (exchange.isOneWay()) {
-                return null;
-            }
-            List<Object> retList = new ArrayList<Object>();
-            if (!((Class) m.getReturnType()).getName().equals("void")) {
-                retList.add(res);
-            }
-            for (int i = 0; i < paramArray.length; i++) {
-                if (paramArray[i] instanceof Holder) {
-                    retList.add(((Holder) paramArray[i]).value);
-                }
-            }
-            return Arrays.asList(retList.toArray());
-        } catch (IllegalAccessException e) {
-            throw new Fault(e);
-        } catch (IllegalArgumentException e) {
-            throw new Fault(e);
-        } catch (InvocationTargetException e) {
-            Throwable target = e;
-            if (e.getCause() instanceof Exception) {
-                target = e.getCause();
+
+        List<Object> res = (List<Object>) super.invoke(exchange, serviceObject,
m, params);
+        for (Object o : params) {
+            if (o instanceof Holder) {
+                res.add(((Holder) o).value);
             }
-            throw new Fault(target);
         }
+        return res;
     }
 
     @SuppressWarnings("unchecked")
@@ -92,37 +55,31 @@
         if (method != null) {
 
             Type[] para = method.getGenericParameterTypes();
-            for (int i = 0; i < para.length; i++) {               
+            for (int i = 0; i < para.length; i++) {
                 if (para[i] instanceof ParameterizedType) {
-                    ParameterizedType paramType = (ParameterizedType) para[i];
-                    if (((Class) paramType.getRawType()).getName().equals("javax.xml.ws.Holder"))
{
-                        
+                    ParameterizedType paramType = (ParameterizedType)para[i];
+                    if (((Class)paramType.getRawType()).getName().equals("javax.xml.ws.Holder"))
{
+
                         Object rawType = paramType.getActualTypeArguments()[0];
                         Class rawClass = null;
                         if (rawType instanceof GenericArrayType) {
-                            rawClass = (Class) ((GenericArrayType) rawType).getGenericComponentType();
+                            rawClass = (Class)((GenericArrayType)rawType).getGenericComponentType();
                             rawClass = Array.newInstance(rawClass, 0).getClass();
-                        } else if (rawType instanceof Class) {     
-                            rawClass = (Class) rawType;
+                        } else if (rawType instanceof Class) {
+                            rawClass = (Class)rawType;
                         } else if (rawType instanceof ParameterizedType) {
                             rawClass = (Class)((ParameterizedType)rawType).getRawType();
                         }
-                       // param = new Holder((Class) rawClass);
-                        
-                        
+                        // param = new Holder((Class) rawClass);
+
                         if (i >= params.size()) {
                             params.add(new Holder());
                         } else {
                             params.set(i, new Holder(params.get(i)));
                         }
                     }
-
-                } 
-                
+                }
             }
-
         }
-
     }
-
 }

Modified: incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/CodeFirstTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/CodeFirstTest.java?view=diff&rev=463023&r1=463022&r2=463023
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/CodeFirstTest.java
(original)
+++ incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/CodeFirstTest.java
Wed Oct 11 15:52:44 2006
@@ -108,7 +108,7 @@
     public void testEndpoint() throws Exception {
         Hello service = new Hello();
 
-        EndpointImpl ep = new EndpointImpl(getBus(), service, null);
+        EndpointImpl ep = new EndpointImpl(getBus(), service, (String) null);
         ep.publish("http://localhost:9090/hello");
 
         Node res = invoke("http://localhost:9090/hello", 

Modified: incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/EndpointImplTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/EndpointImplTest.java?view=diff&rev=463023&r1=463022&r2=463023
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/EndpointImplTest.java
(original)
+++ incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/EndpointImplTest.java
Wed Oct 11 15:52:44 2006
@@ -25,7 +25,9 @@
 
 import javax.xml.ws.WebServiceContext;
 
+import org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean;
 import org.apache.cxf.message.Message;
+import org.apache.cxf.service.invoker.BeanInvoker;
 import org.apache.cxf.transport.Conduit;
 import org.apache.cxf.transport.MessageObserver;
 import org.apache.hello_world_soap_http.GreeterImpl;
@@ -49,6 +51,30 @@
         
         assertNotNull(ctx);
         
+    }
+    
+
+    public void testEndpointServiceConstructor() throws Exception {   
+        GreeterImpl greeter = new GreeterImpl();
+        JaxWsServiceFactoryBean serviceFactory = new JaxWsServiceFactoryBean();
+        serviceFactory.setBus(getBus());
+        serviceFactory.setInvoker(new BeanInvoker(greeter));
+        serviceFactory.setServiceClass(GreeterImpl.class);
+        
+        EndpointImpl endpoint = new EndpointImpl(getBus(), greeter, serviceFactory);
+ 
+        WebServiceContext ctx = greeter.getContext();
+        assertNull(ctx);
+        try {
+            String address = "http://localhost:8080/test";
+            endpoint.publish(address);
+        } catch (IllegalArgumentException ex) {
+            //assertTrue(ex.getCause() instanceof BusException);
+            //assertEquals("BINDING_INCOMPATIBLE_ADDRESS_EXC", ((BusException)ex.getCause()).getCode());
+        }
+        ctx = greeter.getContext();
+        
+        assertNotNull(ctx);
     }
 
     static class EchoObserver implements MessageObserver {

Modified: incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/provider/ProviderTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/provider/ProviderTest.java?view=diff&rev=463023&r1=463022&r2=463023
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/provider/ProviderTest.java
(original)
+++ incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/provider/ProviderTest.java
Wed Oct 11 15:52:44 2006
@@ -26,7 +26,7 @@
 
 public class ProviderTest extends AbstractJaxWsTest {
     public void testInvocation() throws Exception {
-        EndpointImpl ep = new EndpointImpl(getBus(), new PayloadProvider(), null);
+        EndpointImpl ep = new EndpointImpl(getBus(), new PayloadProvider(), (String) null);
         ep.publish("http://localhost:9000/Provider");
         
         Node response = invoke("http://localhost:9000/Provider",

Modified: incubator/cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/service/factory/DefaultServiceConfiguration.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/service/factory/DefaultServiceConfiguration.java?view=diff&rev=463023&r1=463022&r2=463023
==============================================================================
--- incubator/cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/service/factory/DefaultServiceConfiguration.java
(original)
+++ incubator/cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/service/factory/DefaultServiceConfiguration.java
Wed Oct 11 15:52:44 2006
@@ -26,6 +26,7 @@
 
 import org.apache.cxf.common.util.ParamReader;
 import org.apache.cxf.helpers.ServiceUtils;
+import org.apache.cxf.message.Exchange;
 import org.apache.cxf.service.Service;
 import org.apache.cxf.service.model.InterfaceInfo;
 import org.apache.cxf.service.model.OperationInfo;
@@ -126,7 +127,14 @@
 
     @Override
     public Boolean isInParam(Method method, int j) {
-        return j >= 0;
+        if (j >= 0) {
+            Class c = method.getParameterTypes()[j];
+            if (Exchange.class.equals(c)) {
+                return false;
+            }
+            return true;
+        }
+        return false;
     }
 
     @Override

Modified: incubator/cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/service/factory/ServerFactoryBean.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/service/factory/ServerFactoryBean.java?view=diff&rev=463023&r1=463022&r2=463023
==============================================================================
--- incubator/cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/service/factory/ServerFactoryBean.java
(original)
+++ incubator/cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/service/factory/ServerFactoryBean.java
Wed Oct 11 15:52:44 2006
@@ -52,7 +52,7 @@
         super();
         bindingFactory = new SoapBindingInfoFactoryBean();
     }
-
+    
     public Server create() {
         try {
             service = serviceFactory.getService();

Modified: incubator/cxf/trunk/rt/frontend/simple/src/test/java/org/apache/cxf/service/factory/HelloService.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/simple/src/test/java/org/apache/cxf/service/factory/HelloService.java?view=diff&rev=463023&r1=463022&r2=463023
==============================================================================
--- incubator/cxf/trunk/rt/frontend/simple/src/test/java/org/apache/cxf/service/factory/HelloService.java
(original)
+++ incubator/cxf/trunk/rt/frontend/simple/src/test/java/org/apache/cxf/service/factory/HelloService.java
Wed Oct 11 15:52:44 2006
@@ -18,8 +18,11 @@
  */
 package org.apache.cxf.service.factory;
 
+import org.apache.cxf.message.Exchange;
+
 public interface HelloService {
     String sayHello();
     void ping();
-    String echo(String text);
+    String echoWithExchange(Exchange ex, String text);
+    String echo(String text);    
 }

Modified: incubator/cxf/trunk/rt/frontend/simple/src/test/java/org/apache/cxf/service/factory/ReflectionServiceFactoryTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/simple/src/test/java/org/apache/cxf/service/factory/ReflectionServiceFactoryTest.java?view=diff&rev=463023&r1=463022&r2=463023
==============================================================================
--- incubator/cxf/trunk/rt/frontend/simple/src/test/java/org/apache/cxf/service/factory/ReflectionServiceFactoryTest.java
(original)
+++ incubator/cxf/trunk/rt/frontend/simple/src/test/java/org/apache/cxf/service/factory/ReflectionServiceFactoryTest.java
Wed Oct 11 15:52:44 2006
@@ -81,7 +81,7 @@
         ServiceInfo si = service.getServiceInfo();
         InterfaceInfo intf = si.getInterface();
         
-        assertEquals(3, intf.getOperations().size());
+        assertEquals(4, intf.getOperations().size());
         
         String ns = si.getName().getNamespaceURI();
         OperationInfo sayHelloOp = intf.getOperation(new QName(ns, "sayHello"));
@@ -100,6 +100,10 @@
         MessagePartInfo mpi = messageParts.get(0);
         assertEquals("out", mpi.getName().getLocalPart());
         assertEquals(String.class, mpi.getProperty(Class.class.getName()));
+
+        
+        OperationInfo op = si.getInterface().getOperation(new QName(ns, "echoWithExchange"));
+        assertEquals(1, op.getInput().getMessageParts().size());
     }
     
     public void testWrappedBuild() throws Exception {
@@ -108,7 +112,7 @@
         ServiceInfo si = service.getServiceInfo();
         InterfaceInfo intf = si.getInterface();
         
-        assertEquals(3, intf.getOperations().size());
+        assertEquals(4, intf.getOperations().size());
         
         String ns = si.getName().getNamespaceURI();
         OperationInfo sayHelloOp = intf.getOperation(new QName(ns, "sayHello"));
@@ -179,7 +183,7 @@
         assertEquals("HelloServiceSoapBinding", b.getName().getLocalPart());
         assertEquals("document", sb.getStyle());
         
-        assertEquals(3, b.getOperations().size());
+        assertEquals(4, b.getOperations().size());
         
         BindingOperationInfo bop = b.getOperations().iterator().next();
         SoapOperationInfo sop = bop.getExtensor(SoapOperationInfo.class);



Mime
View raw message