servicemix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gno...@apache.org
Subject svn commit: r427510 - in /incubator/servicemix/trunk/servicemix-jsr181/src: main/java/org/apache/servicemix/jsr181/ main/java/org/apache/servicemix/jsr181/xfire/ test/java/org/apache/servicemix/jsr181/
Date Tue, 01 Aug 2006 09:59:08 GMT
Author: gnodet
Date: Tue Aug  1 02:59:07 2006
New Revision: 427510

URL: http://svn.apache.org/viewvc?rev=427510&view=rev
Log:
SM-506: Improve jsr181 proxy to use a service factory

Added:
    incubator/servicemix/trunk/servicemix-jsr181/src/main/java/org/apache/servicemix/jsr181/xfire/ServiceFactoryHelper.java
Modified:
    incubator/servicemix/trunk/servicemix-jsr181/src/main/java/org/apache/servicemix/jsr181/EndpointDeliveryChannel.java
    incubator/servicemix/trunk/servicemix-jsr181/src/main/java/org/apache/servicemix/jsr181/Jsr181Endpoint.java
    incubator/servicemix/trunk/servicemix-jsr181/src/main/java/org/apache/servicemix/jsr181/xfire/JbiChannel.java
    incubator/servicemix/trunk/servicemix-jsr181/src/main/java/org/apache/servicemix/jsr181/xfire/JbiProxy.java
    incubator/servicemix/trunk/servicemix-jsr181/src/test/java/org/apache/servicemix/jsr181/Jsr181ComplexPojoTest.java

Modified: incubator/servicemix/trunk/servicemix-jsr181/src/main/java/org/apache/servicemix/jsr181/EndpointDeliveryChannel.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-jsr181/src/main/java/org/apache/servicemix/jsr181/EndpointDeliveryChannel.java?rev=427510&r1=427509&r2=427510&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-jsr181/src/main/java/org/apache/servicemix/jsr181/EndpointDeliveryChannel.java
(original)
+++ incubator/servicemix/trunk/servicemix-jsr181/src/main/java/org/apache/servicemix/jsr181/EndpointDeliveryChannel.java
Tue Aug  1 02:59:07 2006
@@ -18,8 +18,6 @@
 
 import javax.jbi.messaging.DeliveryChannel;
 import javax.jbi.messaging.ExchangeStatus;
-import javax.jbi.messaging.InOptionalOut;
-import javax.jbi.messaging.InOut;
 import javax.jbi.messaging.MessageExchange;
 import javax.jbi.messaging.MessageExchangeFactory;
 import javax.jbi.messaging.MessagingException;

Modified: incubator/servicemix/trunk/servicemix-jsr181/src/main/java/org/apache/servicemix/jsr181/Jsr181Endpoint.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-jsr181/src/main/java/org/apache/servicemix/jsr181/Jsr181Endpoint.java?rev=427510&r1=427509&r2=427510&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-jsr181/src/main/java/org/apache/servicemix/jsr181/Jsr181Endpoint.java
(original)
+++ incubator/servicemix/trunk/servicemix-jsr181/src/main/java/org/apache/servicemix/jsr181/Jsr181Endpoint.java
Tue Aug  1 02:59:07 2006
@@ -19,12 +19,10 @@
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
-import java.lang.reflect.Constructor;
 import java.lang.reflect.Method;
 import java.net.URL;
 import java.security.InvalidParameterException;
 import java.util.HashMap;
-import java.util.Iterator;
 import java.util.Map;
 
 import javax.jbi.component.ComponentContext;
@@ -46,20 +44,12 @@
 import org.apache.servicemix.common.xbean.XBeanServiceUnit;
 import org.apache.servicemix.jsr181.xfire.JbiFaultSerializer;
 import org.apache.servicemix.jsr181.xfire.JbiTransport;
+import org.apache.servicemix.jsr181.xfire.ServiceFactoryHelper;
 import org.codehaus.xfire.XFire;
-import org.codehaus.xfire.aegis.AegisBindingProvider;
-import org.codehaus.xfire.aegis.type.DefaultTypeMappingRegistry;
-import org.codehaus.xfire.aegis.type.TypeMappingRegistry;
-import org.codehaus.xfire.annotations.AnnotationServiceFactory;
-import org.codehaus.xfire.annotations.WebAnnotations;
-import org.codehaus.xfire.annotations.commons.CommonsWebAttributes;
-import org.codehaus.xfire.annotations.jsr181.Jsr181WebAnnotations;
 import org.codehaus.xfire.service.Service;
 import org.codehaus.xfire.service.binding.ObjectServiceFactory;
 import org.codehaus.xfire.service.invoker.BeanInvoker;
 import org.codehaus.xfire.soap.SoapConstants;
-import org.codehaus.xfire.transport.TransportManager;
-import org.codehaus.xfire.xmlbeans.XmlBeansTypeRegistry;
 import org.springframework.core.io.Resource;
 import org.w3c.dom.Document;
 import org.xml.sax.SAXException;
@@ -74,33 +64,6 @@
  */
 public class Jsr181Endpoint extends Endpoint {
 
-    private static final Map knownTypeMappings;
-    private static final Map knownAnnotations;
-    
-    static {
-        knownTypeMappings = new HashMap();
-        knownTypeMappings.put("default", new DefaultTypeMappingRegistry(true));
-        knownTypeMappings.put("xmlbeans", new XmlBeansTypeRegistry());
-        try {
-            Class cl = Class.forName("org.codehaus.xfire.jaxb2.JaxbTypeRegistry");
-            Object tr = cl.newInstance();
-            knownTypeMappings.put("jaxb2", tr);
-        } catch (Throwable e) {
-            // we are in jdk 1.4, do nothing
-        }
-        
-        knownAnnotations = new HashMap();
-        knownAnnotations.put("jsr181", new Jsr181WebAnnotations());
-        knownAnnotations.put("commons", new CommonsWebAttributes());
-        try {
-            Class cl = Class.forName("org.codehaus.xfire.annotations.jsr181.Jsr181WebAnnotations");
-            Object wa = cl.newInstance();
-            knownAnnotations.put("java5", wa);
-        } catch (Throwable e) {
-            // we are in jdk 1.4, do nothing
-        }
-    }
-    
     protected Object pojo;
     protected String pojoClass;
     protected String annotations;
@@ -197,66 +160,14 @@
             Class cl = Class.forName(pojoClass, true, classLoader);
             pojo = cl.newInstance();
         }
-        // Determine annotations
-        WebAnnotations wa = null;
-        String selectedAnnotations = null;
-        if (annotations != null) {
-            selectedAnnotations = annotations;
-            if (!annotations.equals("none")) {
-                wa = (WebAnnotations) knownAnnotations.get(annotations);
-                if (wa == null) {
-                    throw new Exception("Unrecognized annotations: " + annotations);
-                }
-            }
-        } else {
-            for (Iterator it = knownAnnotations.entrySet().iterator(); it.hasNext();) {
-                Map.Entry entry = (Map.Entry) it.next();
-                WebAnnotations w = (WebAnnotations) entry.getValue();
-                if (w.hasWebServiceAnnotation(pojo.getClass())) {
-                    selectedAnnotations = (String) entry.getKey();
-                    wa = w;
-                    break;
-                }
-            }
-        }
-        // Determine TypeMappingRegistry
-        TypeMappingRegistry tm = null;
-        String selectedTypeMapping = null;
-        if (typeMapping == null) {
-            selectedTypeMapping = (wa == null) ? "default" : "jaxb2";
-        } else {
-            selectedTypeMapping = typeMapping;
-        }
-        tm = (TypeMappingRegistry) knownTypeMappings.get(selectedTypeMapping);
-        if (tm == null) {
-            throw new Exception("Unrecognized typeMapping: " + typeMapping);
-        }
         // Create factory
         XFire xfire = getXFire();
-        ObjectServiceFactory factory = null;
+        ObjectServiceFactory factory = ServiceFactoryHelper.findServiceFactory(xfire, pojo.getClass(),
annotations, typeMapping);
         Class serviceClass = pojo.getClass();
         if (serviceInterface != null) {
             serviceClass = Class.forName(serviceInterface);
         }
-        if (wa == null) {
-            factory = new ObjectServiceFactory(xfire.getTransportManager(),
-                                               new AegisBindingProvider(tm));
-        } else if (selectedAnnotations.equals("java5") && selectedTypeMapping.equals("jaxb2"))
{
-            try {
-                Class clazz = Class.forName("org.codehaus.xfire.jaxws.JAXWSServiceFactory");
-                Constructor ct = clazz.getDeclaredConstructor(new Class[] { TransportManager.class
});
-                factory = (ObjectServiceFactory) ct.newInstance(new Object[] { xfire.getTransportManager()
});
-            } catch (Exception e) {
-                factory = new AnnotationServiceFactory(wa, 
-                        xfire.getTransportManager(), 
-                        new AegisBindingProvider(tm));
-            }
-        } else {
-            factory = new AnnotationServiceFactory(wa, 
-                                                   xfire.getTransportManager(), 
-                                                   new AegisBindingProvider(tm));
-        }
-        
+
         this.definition = loadDefinition();
         if (definition != null) {
             if (definition.getServices().size() != 1) {
@@ -307,9 +218,6 @@
         props.put(ObjectServiceFactory.PORT_TYPE, interfaceName);
         props.put(ObjectServiceFactory.STYLE, SoapConstants.STYLE_WRAPPED);
         props.put(ObjectServiceFactory.USE, SoapConstants.USE_LITERAL);
-        factory.getSoap11Transports().clear();
-        factory.getSoap12Transports().clear();
-        factory.getSoap11Transports().add(JbiTransport.JBI_BINDING);
         xfireService = factory.create(serviceClass, svcLocalName, svcNamespace, props);
         xfireService.setInvoker(new BeanInvoker(getPojo()));
         xfireService.setFaultSerializer(new JbiFaultSerializer(getConfiguration()));

Modified: incubator/servicemix/trunk/servicemix-jsr181/src/main/java/org/apache/servicemix/jsr181/xfire/JbiChannel.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-jsr181/src/main/java/org/apache/servicemix/jsr181/xfire/JbiChannel.java?rev=427510&r1=427509&r2=427510&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-jsr181/src/main/java/org/apache/servicemix/jsr181/xfire/JbiChannel.java
(original)
+++ incubator/servicemix/trunk/servicemix-jsr181/src/main/java/org/apache/servicemix/jsr181/xfire/JbiChannel.java
Tue Aug  1 02:59:07 2006
@@ -68,7 +68,7 @@
     }
 
     public void send(MessageContext context, OutMessage message) throws XFireException {
-        if (message.getUri().equals(Channel.BACKCHANNEL_URI)) {
+        if (Channel.BACKCHANNEL_URI.equals(message.getUri())) {
             final OutputStream out = (OutputStream) context.getProperty(Channel.BACKCHANNEL_URI);
             if (out != null) {
                 try {
@@ -144,4 +144,4 @@
         return src;
     }
     
-}
\ No newline at end of file
+}

Modified: incubator/servicemix/trunk/servicemix-jsr181/src/main/java/org/apache/servicemix/jsr181/xfire/JbiProxy.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-jsr181/src/main/java/org/apache/servicemix/jsr181/xfire/JbiProxy.java?rev=427510&r1=427509&r2=427510&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-jsr181/src/main/java/org/apache/servicemix/jsr181/xfire/JbiProxy.java
(original)
+++ incubator/servicemix/trunk/servicemix-jsr181/src/main/java/org/apache/servicemix/jsr181/xfire/JbiProxy.java
Tue Aug  1 02:59:07 2006
@@ -26,6 +26,8 @@
 import org.codehaus.xfire.XFire;
 import org.codehaus.xfire.client.Client;
 import org.codehaus.xfire.client.XFireProxyFactory;
+import org.codehaus.xfire.service.Service;
+import org.codehaus.xfire.service.ServiceFactory;
 import org.w3c.dom.Document;
 
 public class JbiProxy {
@@ -76,7 +78,9 @@
     
     public Object getProxy() throws Exception {
         if (proxy == null) {
-            JBIClient client = new JBIClient(xfire, getDescription(), serviceClass);
+            ServiceFactory factory = ServiceFactoryHelper.findServiceFactory(xfire, serviceClass,
null, null);
+            Service service = factory.create(serviceClass, null, getDescription(), null);
+            JBIClient client = new JBIClient(xfire, service);
             if (interfaceName != null) {
                 client.getService().setProperty(JbiChannel.JBI_INTERFACE_NAME, interfaceName);
             }
@@ -142,11 +146,12 @@
     
     protected static class JBIClient extends Client {
 
-        public JBIClient(XFire xfire, Definition description, Class serviceClass) throws
Exception {
-            super();
+        public JBIClient(XFire xfire, Service service) throws Exception {
+            super(xfire.getTransportManager().getTransport(JbiTransport.JBI_BINDING),
+                  service, 
+                  null);
             setXFire(xfire);
-            initFromDefinition(JbiTransport.JBI_BINDING, description, serviceClass);
         }
         
     }
-}
\ No newline at end of file
+}

Added: incubator/servicemix/trunk/servicemix-jsr181/src/main/java/org/apache/servicemix/jsr181/xfire/ServiceFactoryHelper.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-jsr181/src/main/java/org/apache/servicemix/jsr181/xfire/ServiceFactoryHelper.java?rev=427510&view=auto
==============================================================================
--- incubator/servicemix/trunk/servicemix-jsr181/src/main/java/org/apache/servicemix/jsr181/xfire/ServiceFactoryHelper.java
(added)
+++ incubator/servicemix/trunk/servicemix-jsr181/src/main/java/org/apache/servicemix/jsr181/xfire/ServiceFactoryHelper.java
Tue Aug  1 02:59:07 2006
@@ -0,0 +1,127 @@
+package org.apache.servicemix.jsr181.xfire;
+
+import java.lang.reflect.Constructor;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+import org.codehaus.xfire.XFire;
+import org.codehaus.xfire.aegis.AegisBindingProvider;
+import org.codehaus.xfire.aegis.type.DefaultTypeMappingRegistry;
+import org.codehaus.xfire.aegis.type.TypeMappingRegistry;
+import org.codehaus.xfire.annotations.AnnotationServiceFactory;
+import org.codehaus.xfire.annotations.WebAnnotations;
+import org.codehaus.xfire.annotations.commons.CommonsWebAttributes;
+import org.codehaus.xfire.service.binding.ObjectServiceFactory;
+import org.codehaus.xfire.transport.TransportManager;
+import org.codehaus.xfire.xmlbeans.XmlBeansTypeRegistry;
+
+public class ServiceFactoryHelper {
+    
+    public static final String TM_DEFAULT = "default";
+    public static final String TM_XMLBEANS = "xmlbeans";
+    public static final String TM_JAXB2 = "jaxb2";
+    
+    public static final String AN_JSR181 = "jsr181";
+    public static final String AN_JAVA5 = "java5";
+    public static final String AN_COMMONS = "commons";
+    public static final String AN_NONE = "none";
+
+    private static final Map knownTypeMappings;
+    private static final Map knownAnnotations;
+    
+    static {
+        knownTypeMappings = new HashMap();
+        knownTypeMappings.put(TM_DEFAULT, new DefaultTypeMappingRegistry(true));
+        knownTypeMappings.put(TM_XMLBEANS, new XmlBeansTypeRegistry());
+        try {
+            Class cl = Class.forName("org.codehaus.xfire.jaxb2.JaxbTypeRegistry");
+            Object tr = cl.newInstance();
+            knownTypeMappings.put(TM_JAXB2, tr);
+        } catch (Throwable e) {
+            // we are in jdk 1.4, do nothing
+        }
+        
+        knownAnnotations = new HashMap();
+        knownAnnotations.put(AN_COMMONS, new CommonsWebAttributes());
+        try {
+            Class cl = Class.forName("org.codehaus.xfire.annotations.jsr181.Jsr181WebAnnotations");
+            Object wa = cl.newInstance();
+            knownAnnotations.put(AN_JAVA5, wa);
+        } catch (Throwable e) {
+            // we are in jdk 1.4, do nothing
+        }
+    }
+    
+    public static ObjectServiceFactory findServiceFactory(
+                        XFire xfire,
+                        Class serviceClass,
+                        String annotations, 
+                        String typeMapping) throws Exception {
+        // jsr181 is synonymous to java5
+        if (annotations != null && AN_JSR181.equals(annotations)) {
+            annotations = AN_JAVA5;
+        }
+        // Determine annotations
+        WebAnnotations wa = null;
+        String selectedAnnotations = null;
+        if (annotations != null) {
+            selectedAnnotations = annotations;
+            if (!annotations.equals(AN_NONE)) {
+                wa = (WebAnnotations) knownAnnotations.get(annotations);
+                if (wa == null) {
+                    throw new Exception("Unrecognized annotations: " + annotations);
+                }
+            }
+        } else {
+            for (Iterator it = knownAnnotations.entrySet().iterator(); it.hasNext();) {
+                Map.Entry entry = (Map.Entry) it.next();
+                WebAnnotations w = (WebAnnotations) entry.getValue();
+                if (w.hasWebServiceAnnotation(serviceClass)) {
+                    selectedAnnotations = (String) entry.getKey();
+                    wa = w;
+                    break;
+                }
+            }
+        }
+        // Determine TypeMappingRegistry
+        TypeMappingRegistry tm = null;
+        String selectedTypeMapping = null;
+        if (typeMapping == null) {
+            selectedTypeMapping = (wa == null) ? TM_DEFAULT : TM_JAXB2;
+        } else {
+            selectedTypeMapping = typeMapping;
+        }
+        tm = (TypeMappingRegistry) knownTypeMappings.get(selectedTypeMapping);
+        if (tm == null) {
+            throw new Exception("Unrecognized typeMapping: " + typeMapping);
+        }
+        // Create factory
+        ObjectServiceFactory factory = null;
+        if (wa == null) {
+            factory = new ObjectServiceFactory(xfire.getTransportManager(),
+                                               new AegisBindingProvider(tm));
+        } else if (selectedAnnotations.equals(AN_JAVA5) && 
+                   selectedTypeMapping.equals(TM_JAXB2)) {
+            try {
+                Class clazz = Class.forName("org.codehaus.xfire.jaxws.JAXWSServiceFactory");
+                Constructor ct = clazz.getDeclaredConstructor(new Class[] { TransportManager.class
});
+                factory = (ObjectServiceFactory) ct.newInstance(new Object[] { xfire.getTransportManager()
});
+            } catch (Exception e) {
+                factory = new AnnotationServiceFactory(wa, 
+                        xfire.getTransportManager(), 
+                        new AegisBindingProvider(tm));
+            }
+        } else {
+            factory = new AnnotationServiceFactory(wa, 
+                                                   xfire.getTransportManager(), 
+                                                   new AegisBindingProvider(tm));
+        }
+        // Register only JBI transport in the factory
+        factory.getSoap11Transports().clear();
+        factory.getSoap12Transports().clear();
+        factory.getSoap11Transports().add(JbiTransport.JBI_BINDING);
+        return factory;
+    }
+    
+}

Modified: incubator/servicemix/trunk/servicemix-jsr181/src/test/java/org/apache/servicemix/jsr181/Jsr181ComplexPojoTest.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-jsr181/src/test/java/org/apache/servicemix/jsr181/Jsr181ComplexPojoTest.java?rev=427510&r1=427509&r2=427510&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-jsr181/src/test/java/org/apache/servicemix/jsr181/Jsr181ComplexPojoTest.java
(original)
+++ incubator/servicemix/trunk/servicemix-jsr181/src/test/java/org/apache/servicemix/jsr181/Jsr181ComplexPojoTest.java
Tue Aug  1 02:59:07 2006
@@ -175,12 +175,13 @@
         me.setInterfaceName(new QName("http://jsr181.servicemix.apache.org", "ComplexPojoPortType"));
         me.getInMessage().setContent(new StringSource("<hel lo>world</hello"));
         client.sendSync(me);
-        assertEquals(ExchangeStatus.ERROR, me.getStatus());
+        assertEquals(ExchangeStatus.ACTIVE, me.getStatus());
         assertNotNull(me.getFault());
         Node n = transformer.toDOMNode(me.getFault());
         System.err.println(transformer.toString(n));
         assertNotNull(textValueOfXPath(n, "//message"));
         assertNull(textValueOfXPath(n, "//stack"));
+        client.done(me);
         
         ((Jsr181LifeCycle) component.getLifeCycle()).getConfiguration().setPrintStackTraceInFaults(true);
         
@@ -188,12 +189,13 @@
         me.setInterfaceName(new QName("http://jsr181.servicemix.apache.org", "ComplexPojoPortType"));
         me.getInMessage().setContent(new StringSource("<hel lo>world</hello"));
         client.sendSync(me);
-        assertEquals(ExchangeStatus.ERROR, me.getStatus());
+        assertEquals(ExchangeStatus.ACTIVE, me.getStatus());
         assertNotNull(me.getFault());
         n = transformer.toDOMNode(me.getFault());
         System.err.println(transformer.toString(n));
         assertNotNull(textValueOfXPath(n, "//message"));
         assertNotNull(textValueOfXPath(n, "//stack"));
+        client.done(me);
         
         // Wait all acks being processed
         Thread.sleep(100);



Mime
View raw message