Title: [1011] trunk/etc: Add a Jbi Proxy for Jsr181 Component.

Diff

Modified: trunk/etc/project.properties (1010 => 1011)

--- trunk/etc/project.properties	2005-12-05 15:49:44 UTC (rev 1010)
+++ trunk/etc/project.properties	2005-12-05 16:11:03 UTC (rev 1011)
@@ -199,6 +199,9 @@
 xbean_version=2.1-SNAPSHOT
 xfire_version=1.0-20051129.225317
 xfire_jaxws_version=1.0-20051130.145319
+#xfire_version=1.0-SNAPSHOT
+#xfire_jaxws_version=1.0-SNAPSHOT
+xfire_xmlschema_version=20051110
 xml_apis_version=1.3.02
 xmlbeans_version=2.0.0
 xml_parser_apis_version=2.2.1

Modified: trunk/servicemix-jsr181/project.xml (1010 => 1011)

--- trunk/servicemix-jsr181/project.xml	2005-12-05 15:49:44 UTC (rev 1010)
+++ trunk/servicemix-jsr181/project.xml	2005-12-05 16:11:03 UTC (rev 1011)
@@ -214,6 +214,11 @@
         <artifactId>mx4j-remote</artifactId>
         <version>${mx4j_version}</version>
       </dependency>
+    <dependency>
+      <groupId>xfire</groupId>
+      <artifactId>XmlSchema</artifactId>
+      <version>${xfire_xmlschema_version}</version>
+    </dependency>
 
 
       <!-- Testing only -->
@@ -289,6 +294,16 @@
     </dependencies>  
 
     <build>
+        <unitTest>
+            <includes>
+                <include>**/*Test.*</include>
+            </includes>
+            <excludes>
+                <!-- Only works with xfire 1.0-SNAPSHOT -->
+                <exclude>**/Jsr181OverrideTest.*</exclude>
+                <exclude>**/JbiProxyTest.*</exclude>
+            </excludes>
+        </unitTest>
         <resources>
             <resource>
                 <directory>src/main/resources</directory>

Modified: trunk/servicemix-jsr181/src/main/java/org/servicemix/jsr181/Jsr181Endpoint.java (1010 => 1011)

--- trunk/servicemix-jsr181/src/main/java/org/servicemix/jsr181/Jsr181Endpoint.java	2005-12-05 15:49:44 UTC (rev 1010)
+++ trunk/servicemix-jsr181/src/main/java/org/servicemix/jsr181/Jsr181Endpoint.java	2005-12-05 16:11:03 UTC (rev 1011)
@@ -47,6 +47,7 @@
 import org.codehaus.xfire.service.Service;
 import org.codehaus.xfire.service.binding.BeanInvoker;
 import org.codehaus.xfire.service.binding.ObjectServiceFactory;
+import org.codehaus.xfire.soap.SoapConstants;
 import org.codehaus.xfire.transport.Transport;
 import org.codehaus.xfire.transport.TransportManager;
 import org.codehaus.xfire.xmlbeans.XmlBeansTypeRegistry;
@@ -236,6 +237,8 @@
         String svcNamespace = (service != null) ? service.getNamespaceURI() : null;
         Map props = new HashMap();
         props.put(ObjectServiceFactory.PORT_TYPE, interfaceName);
+        props.put(ObjectServiceFactory.STYLE, SoapConstants.STYLE_WRAPPED);
+        props.put(ObjectServiceFactory.USE, SoapConstants.USE_LITERAL);
         xfireService = factory.create(serviceClass, svcLocalName, svcNamespace, props);
         xfireService.setInvoker(new BeanInvoker(getPojo()));
         xfire.getServiceRegistry().register(xfireService);
@@ -245,7 +248,7 @@
         this.description = generateWsdl();
         
         // Check service name and endpoint name
-        QName serviceName = xfireService.getServiceInfo().getName();
+        QName serviceName = xfireService.getName();
         QName interfName = xfireService.getServiceInfo().getPortType();
         String endpointName = null;
         if (service == null) {

Modified: trunk/servicemix-jsr181/src/main/java/org/servicemix/jsr181/Jsr181ExchangeProcessor.java (1010 => 1011)

--- trunk/servicemix-jsr181/src/main/java/org/servicemix/jsr181/Jsr181ExchangeProcessor.java	2005-12-05 15:49:44 UTC (rev 1010)
+++ trunk/servicemix-jsr181/src/main/java/org/servicemix/jsr181/Jsr181ExchangeProcessor.java	2005-12-05 16:11:03 UTC (rev 1011)
@@ -38,6 +38,7 @@
 import org.codehaus.xfire.MessageContext;
 import org.codehaus.xfire.XFire;
 import org.codehaus.xfire.exchange.InMessage;
+import org.codehaus.xfire.exchange.RobustInOutExchange;
 import org.codehaus.xfire.service.Service;
 import org.codehaus.xfire.transport.Channel;
 import org.codehaus.xfire.transport.Transport;
@@ -74,7 +75,9 @@
         ctx.setXFire(xfire);
         ctx.setService(service);
         ctx.setProperty(Channel.BACKCHANNEL_URI, out);
+        ctx.setExchange(new RobustInOutExchange(ctx));
         InMessage msg = new InMessage();
+        ctx.getExchange().setInMessage(msg);
         NormalizedMessage in = exchange.getMessage("in");
         msg.setXMLStreamReader(getXMLStreamReader(in.getContent()));
         c.receive(ctx, msg);

Modified: trunk/servicemix-jsr181/src/main/java/org/servicemix/jsr181/xfire/JbiChannel.java (1010 => 1011)

--- trunk/servicemix-jsr181/src/main/java/org/servicemix/jsr181/xfire/JbiChannel.java	2005-12-05 15:49:44 UTC (rev 1010)
+++ trunk/servicemix-jsr181/src/main/java/org/servicemix/jsr181/xfire/JbiChannel.java	2005-12-05 16:11:03 UTC (rev 1011)
@@ -110,7 +110,7 @@
                     InMessage inMessage = new InMessage(XMLInputFactory.newInstance().createXMLStreamReader(outSrc), getUri());
                     getEndpoint().onReceive(context, inMessage);
                 } else {
-                    
+                    // TODO
                 }
                 
                 

Added: trunk/servicemix-jsr181/src/main/java/org/servicemix/jsr181/xfire/JbiProxy.java (1010 => 1011)

--- trunk/servicemix-jsr181/src/main/java/org/servicemix/jsr181/xfire/JbiProxy.java	2005-12-05 15:49:44 UTC (rev 1010)
+++ trunk/servicemix-jsr181/src/main/java/org/servicemix/jsr181/xfire/JbiProxy.java	2005-12-05 16:11:03 UTC (rev 1011)
@@ -0,0 +1,145 @@
+/** 
+ * 
+ * Copyright 2005 LogicBlaze, Inc. http://www.logicblaze.com
+ * 
+ * Licensed 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.servicemix.jsr181.xfire;
+
+import javax.jbi.JBIException;
+import javax.jbi.component.ComponentContext;
+import javax.jbi.servicedesc.ServiceEndpoint;
+import javax.wsdl.Definition;
+import javax.wsdl.factory.WSDLFactory;
+import javax.xml.namespace.QName;
+
+import org.codehaus.xfire.XFire;
+import org.codehaus.xfire.client.Client;
+import org.codehaus.xfire.client.XFireProxyFactory;
+import org.codehaus.xfire.transport.Transport;
+import org.w3c.dom.Document;
+
+public class JbiProxy {
+    
+    protected XFire xfire;
+    protected ComponentContext context;
+    protected QName interfaceName;
+    protected QName serviceName;
+    protected String endpointName;
+    protected Object proxy;
+    protected Class serviceClass;
+    protected Definition description;
+    protected ServiceEndpoint endpoint;
+    
+    public static Object create(XFire xfire,
+                                ComponentContext context,
+                                QName interfaceName,
+                                QName serviceName,
+                                String endpointName,
+                                Class serviceClass) throws Exception {
+        JbiProxy p = new JbiProxy(xfire, context, serviceClass, interfaceName, serviceName, endpointName);
+        return p.getProxy();
+    }
+    
+    public JbiProxy(XFire xfire,
+                    ComponentContext context,
+                    Class serviceClass,
+                    Definition description) throws Exception {
+        this.xfire = xfire;
+        this.context = context;
+        this.serviceClass = serviceClass;
+        this.description = description;
+    }
+    
+    public JbiProxy(XFire xfire,
+                    ComponentContext context,
+                    Class serviceClass,
+                    QName interfaceName,
+                    QName serviceName,
+                    String endpointName) throws Exception {
+        this.xfire = xfire;
+        this.context = context;
+        this.interfaceName = interfaceName;
+        this.serviceName = serviceName;
+        this.endpointName = endpointName;
+        this.serviceClass = serviceClass;
+    }
+    
+    public Object getProxy() throws Exception {
+        if (proxy == null) {
+            Transport transport = xfire.getTransportManager().getTransportForUri("jbi://");
+            Client client = new Client(transport, getDescription(), serviceClass);
+            if (interfaceName != null) {
+                client.getService().setProperty(JbiChannel.JBI_INTERFACE_NAME, interfaceName);
+            }
+            if (serviceName != null) {
+                client.getService().setProperty(JbiChannel.JBI_SERVICE_NAME, serviceName);
+            }
+            if (endpoint != null) {
+                client.getService().setProperty(JbiChannel.JBI_ENDPOINT, endpoint);
+            }
+            XFireProxyFactory xpf = new XFireProxyFactory(xfire);
+            proxy = xpf.create(client);
+        }
+        return proxy;
+    }
+    
+    public Definition getDescription() throws Exception {
+        if (this.description == null) {
+            ServiceEndpoint[] endpoints = getEndpoints();
+            if (endpoints == null || endpoints.length == 0) {
+                throw new IllegalStateException("No endpoints found for interface " + interfaceName + ", serviceName " + serviceName + " and endpoint " + endpointName);
+            }
+            ServiceEndpoint endpoint = chooseEndpoint(endpoints);
+            if (endpoint == null) {
+                throw new IllegalStateException("No suitable endpoint found");
+            }
+            if (serviceName != null && endpointName != null) {
+                this.endpoint = endpoint;
+            }
+            Document doc = context.getEndpointDescriptor(endpoint);
+            this.description = WSDLFactory.newInstance().newWSDLReader().readWSDL(null, doc);
+        }
+        return this.description;
+    }
+    
+    protected ServiceEndpoint[] getEndpoints() throws JBIException {
+        ServiceEndpoint[] endpoints;
+        if (endpointName != null && serviceName != null) {
+            ServiceEndpoint endpoint = context.getEndpoint(serviceName, endpointName);
+            if (endpoint == null) {
+                endpoints = new ServiceEndpoint[0];
+            } else {
+                this.endpoint = endpoint;
+                endpoints = new ServiceEndpoint[] { endpoint };
+            }
+        } else if (serviceName != null) {
+            endpoints = context.getEndpointsForService(serviceName);
+        } else if (interfaceName != null) {
+            endpoints = context.getEndpoints(interfaceName);
+        } else {
+            throw new IllegalStateException("One of interfaceName or serviceName should be provided");
+        }
+        return endpoints;
+    }
+    
+    protected ServiceEndpoint chooseEndpoint(ServiceEndpoint[] endpoints) throws JBIException {
+        for (int i = 0; i < endpoints.length; i++) {
+            if (context.getEndpointDescriptor(endpoints[i]) != null) {
+                return endpoints[i];
+            }
+        }
+        return null;
+    }
+}
\ No newline at end of file

Modified: trunk/servicemix-jsr181/src/test/java/org/servicemix/jsr181/Jsr181ComponentTest.java (1010 => 1011)

--- trunk/servicemix-jsr181/src/test/java/org/servicemix/jsr181/Jsr181ComponentTest.java	2005-12-05 15:49:44 UTC (rev 1010)
+++ trunk/servicemix-jsr181/src/test/java/org/servicemix/jsr181/Jsr181ComponentTest.java	2005-12-05 16:11:03 UTC (rev 1011)
@@ -20,6 +20,7 @@
 import java.io.File;
 import java.net.URL;
 
+import javax.jbi.messaging.ExchangeStatus;
 import javax.jbi.messaging.InOut;
 import javax.naming.InitialContext;
 import javax.xml.namespace.QName;
@@ -34,7 +35,6 @@
 import org.servicemix.jbi.jaxp.StringSource;
 
 import test.EchoService;
-import test.EchoService2;
 
 public class Jsr181ComponentTest extends TestCase {
 
@@ -79,11 +79,17 @@
         me.setInterfaceName(new QName("http://test", "EchoServicePortType"));
         me.getInMessage().setContent(new StringSource("<echo xmlns='http://test'><in0>world</in0></echo>"));
         client.sendSync(me);
-        if (me.getFault() != null) {
-            logger.info("!!! FAULT !!!!");
-            logger.info(new SourceTransformer().toString(me.getFault().getContent()));
+        if (me.getStatus() == ExchangeStatus.ERROR) {
+            if (me.getFault() != null) {
+                fail("Received fault: " + new SourceTransformer().toString(me.getFault().getContent()));
+            } else if (me.getError() != null) {
+                throw me.getError();
+            } else {
+                fail("Received ERROR status");
+            }
+        } else {
+            logger.info(new SourceTransformer().toString(me.getOutMessage().getContent()));
         }
-        logger.info(new SourceTransformer().toString(me.getOutMessage().getContent()));
     }
     
     
@@ -108,11 +114,17 @@
         me.setInterfaceName(new QName("http://test", "EchoService2PortType"));
         me.getInMessage().setContent(new StringSource("<echo xmlns='http://test'><in0>world</in0></echo>"));
         client.sendSync(me);
-        if (me.getFault() != null) {
-            logger.info("!!! FAULT !!!!");
-            logger.info(new SourceTransformer().toString(me.getFault().getContent()));
+        if (me.getStatus() == ExchangeStatus.ERROR) {
+            if (me.getFault() != null) {
+                fail("Received fault: " + new SourceTransformer().toString(me.getFault().getContent()));
+            } else if (me.getError() != null) {
+                throw me.getError();
+            } else {
+                fail("Received ERROR status");
+            }
+        } else {
+            logger.info(new SourceTransformer().toString(me.getOutMessage().getContent()));
         }
-        logger.info(new SourceTransformer().toString(me.getOutMessage().getContent()));
     }
     
     public void testDeployUndeploy() throws Exception {
@@ -199,38 +211,6 @@
         }
     }
     
-    /*
-     * These test currently fail
-     * 
-    public void testWithSpecifiedNamesWithAnnotations() throws Exception {
-        QName svcName = new QName("svcUri", "service");
-        QName itfName = new QName("itfUri", "interface");
-        String epName = "endpoint";
-        Jsr181SpringComponent component = new Jsr181SpringComponent();
-        Jsr181Endpoint endpoint = new Jsr181Endpoint();
-        endpoint.setService(svcName);
-        endpoint.setInterfaceName(itfName);
-        endpoint.setEndpoint(epName);
-        endpoint.setPojo(new EchoService());
-        component.setEndpoints(new Jsr181Endpoint[] { endpoint });
-        container.activateComponent(component, "JSR181Component");
-    }
-    
-    public void testWithSpecifiedNamesWithoutAnnotations() throws Exception {
-        QName svcName = new QName("svcUri", "service");
-        QName itfName = new QName("itfUri", "interface");
-        String epName = "endpoint";
-        Jsr181SpringComponent component = new Jsr181SpringComponent();
-        Jsr181Endpoint endpoint = new Jsr181Endpoint();
-        endpoint.setService(svcName);
-        endpoint.setInterfaceName(itfName);
-        endpoint.setEndpoint(epName);
-        endpoint.setPojo(new EchoService2());
-        component.setEndpoints(new Jsr181Endpoint[] { endpoint });
-        container.activateComponent(component, "JSR181Component");
-    }
-    */
-    
     protected String getServiceUnitPath(String name) {
         URL url = "" + "/xbean.xml");
         File path = new File(url.getFile());

Added: trunk/servicemix-jsr181/src/test/java/org/servicemix/jsr181/Jsr181OverrideTest.java (1010 => 1011)

--- trunk/servicemix-jsr181/src/test/java/org/servicemix/jsr181/Jsr181OverrideTest.java	2005-12-05 15:49:44 UTC (rev 1010)
+++ trunk/servicemix-jsr181/src/test/java/org/servicemix/jsr181/Jsr181OverrideTest.java	2005-12-05 16:11:03 UTC (rev 1011)
@@ -0,0 +1,78 @@
+/** 
+ * 
+ * Copyright 2005 LogicBlaze, Inc. http://www.logicblaze.com
+ * 
+ * Licensed 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.servicemix.jsr181;
+
+import javax.naming.InitialContext;
+import javax.xml.namespace.QName;
+
+import junit.framework.TestCase;
+
+import org.servicemix.jbi.container.JBIContainer;
+
+import test.EchoService;
+import test.EchoService2;
+
+public class Jsr181OverrideTest extends TestCase {
+
+    protected JBIContainer container;
+    
+    protected void setUp() throws Exception {
+        container = new JBIContainer();
+        container.setUseMBeanServer(false);
+        container.setCreateMBeanServer(false);
+        container.setMonitorInstallationDirectory(false);
+        container.setNamingContext(new InitialContext());
+        container.setEmbedded(true);
+        container.init();
+    }
+    
+    protected void tearDown() throws Exception {
+        if (container != null) {
+            container.shutDown();
+        }
+    }
+    
+    public void testWithSpecifiedNamesWithAnnotations() throws Exception {
+        QName svcName = new QName("svcUri", "service");
+        QName itfName = new QName("itfUri", "interface");
+        String epName = "endpoint";
+        Jsr181SpringComponent component = new Jsr181SpringComponent();
+        Jsr181Endpoint endpoint = new Jsr181Endpoint();
+        endpoint.setService(svcName);
+        endpoint.setInterfaceName(itfName);
+        endpoint.setEndpoint(epName);
+        endpoint.setPojo(new EchoService());
+        component.setEndpoints(new Jsr181Endpoint[] { endpoint });
+        container.activateComponent(component, "JSR181Component");
+    }
+    
+    public void testWithSpecifiedNamesWithoutAnnotations() throws Exception {
+        QName svcName = new QName("svcUri", "service");
+        QName itfName = new QName("itfUri", "interface");
+        String epName = "endpoint";
+        Jsr181SpringComponent component = new Jsr181SpringComponent();
+        Jsr181Endpoint endpoint = new Jsr181Endpoint();
+        endpoint.setService(svcName);
+        endpoint.setInterfaceName(itfName);
+        endpoint.setEndpoint(epName);
+        endpoint.setPojo(new EchoService2());
+        component.setEndpoints(new Jsr181Endpoint[] { endpoint });
+        container.activateComponent(component, "JSR181Component");
+    }
+    
+}

Modified: trunk/servicemix-jsr181/src/test/java/org/servicemix/jsr181/Jsr181SpringTest.java (1010 => 1011)

--- trunk/servicemix-jsr181/src/test/java/org/servicemix/jsr181/Jsr181SpringTest.java	2005-12-05 15:49:44 UTC (rev 1010)
+++ trunk/servicemix-jsr181/src/test/java/org/servicemix/jsr181/Jsr181SpringTest.java	2005-12-05 16:11:03 UTC (rev 1011)
@@ -17,6 +17,7 @@
  **/
 package org.servicemix.jsr181;
 
+import javax.jbi.messaging.ExchangeStatus;
 import javax.jbi.messaging.InOut;
 import javax.xml.namespace.QName;
 
@@ -37,13 +38,19 @@
         DefaultServiceMixClient client = new DefaultServiceMixClient(jbi);
         InOut me = client.createInOutExchange();
         me.setInterfaceName(new QName("http://test", "EchoService2PortType"));
-        me.getInMessage().setContent(new StringSource("<echo xmlns='http://test'><in0>world</in0></echo>"));
+        me.getInMessage().setContent(new StringSource("<echo xmlns='http://test'><echoin0>world</echoin0></echo>"));
         client.sendSync(me);
-        if (me.getFault() != null) {
-            logger.info("!!! FAULT !!!!");
-            logger.info(new SourceTransformer().toString(me.getFault().getContent()));
+        if (me.getStatus() == ExchangeStatus.ERROR) {
+            if (me.getFault() != null) {
+                fail("Received fault: " + new SourceTransformer().toString(me.getFault().getContent()));
+            } else if (me.getError() != null) {
+                throw me.getError();
+            } else {
+                fail("Received ERROR status");
+            }
+        } else {
+            logger.info(new SourceTransformer().toString(me.getOutMessage().getContent()));
         }
-        logger.info(new SourceTransformer().toString(me.getOutMessage().getContent()));
     }
     
     protected AbstractXmlApplicationContext createBeanFactory() {

Added: trunk/servicemix-jsr181/src/test/java/org/servicemix/jsr181/xfire/JbiProxyTest.java (1010 => 1011)

--- trunk/servicemix-jsr181/src/test/java/org/servicemix/jsr181/xfire/JbiProxyTest.java	2005-12-05 15:49:44 UTC (rev 1010)
+++ trunk/servicemix-jsr181/src/test/java/org/servicemix/jsr181/xfire/JbiProxyTest.java	2005-12-05 16:11:03 UTC (rev 1011)
@@ -0,0 +1,128 @@
+/** 
+ * 
+ * Copyright 2005 LogicBlaze, Inc. http://www.logicblaze.com
+ * 
+ * Licensed 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.servicemix.jsr181.xfire;
+
+import javax.jbi.component.ComponentContext;
+import javax.jbi.messaging.ExchangeStatus;
+import javax.jbi.messaging.InOut;
+import javax.naming.InitialContext;
+import javax.xml.namespace.QName;
+
+import junit.framework.TestCase;
+
+import org.codehaus.xfire.XFire;
+import org.codehaus.xfire.XFireFactory;
+import org.servicemix.client.DefaultServiceMixClient;
+import org.servicemix.jbi.container.JBIContainer;
+import org.servicemix.jbi.jaxp.StringSource;
+import org.servicemix.jsr181.Jsr181Endpoint;
+import org.servicemix.jsr181.Jsr181SpringComponent;
+
+public class JbiProxyTest extends TestCase {
+
+    protected JBIContainer container;
+    
+    protected void setUp() throws Exception {
+        container = new JBIContainer();
+        container.setUseMBeanServer(false);
+        container.setCreateMBeanServer(false);
+        container.setMonitorInstallationDirectory(false);
+        container.setNamingContext(new InitialContext());
+        container.setEmbedded(true);
+        container.setFlowName("st");
+        container.init();
+    }
+    
+    protected void tearDown() throws Exception {
+        if (container != null) {
+            container.shutDown();
+        }
+    }
+    
+    public void testProxy() throws Exception {
+        container.start();
+
+        Jsr181SpringComponent component1 = new Jsr181SpringComponent();
+        Jsr181Endpoint endpoint1 = new Jsr181Endpoint();
+        endpoint1.setPojo(new EchoService());
+        component1.setEndpoints(new Jsr181Endpoint[] { endpoint1 });
+        container.activateComponent(component1, "JSR181Component-1");
+        
+        Jsr181SpringComponent component2 = new Jsr181SpringComponent();
+        Jsr181Endpoint endpoint2 = new Jsr181Endpoint();
+        endpoint2.setPojo(new ProxyPojoService());
+        endpoint2.setServiceInterface(ProxyPojo.class.getName());
+        component2.setEndpoints(new Jsr181Endpoint[] { endpoint2 });
+        container.activateComponent(component2, "JSR181Component-2");
+        
+        DefaultServiceMixClient client = new DefaultServiceMixClient(container);
+        InOut me = client.createInOutExchange();
+        me.setInterfaceName(new QName("http://xfire.jsr181.servicemix.org", "ProxyPojoPortType"));
+        me.getInMessage().setContent(new StringSource("<echo xmlns='http://jsr181.servicemix.org'><echoin0>world</echoin0></echo>"));
+        client.sendSync(me);
+        assertTrue(me.getStatus() == ExchangeStatus.ACTIVE);
+        client.done(me);
+    }
+    
+    public static interface Echo {
+        String echo(String msg);
+    }
+    
+    public static class EchoService implements Echo {
+        public String echo(String msg) {
+            return msg;
+        }
+    }
+    
+    public static interface ProxyPojo {
+        String echo(String s);
+    }
+    
+    public static class ProxyPojoService implements ProxyPojo {
+        private ComponentContext context;
+        private Echo proxy;
+
+        public ComponentContext getContext() {
+            return context;
+        }
+
+        public void setContext(ComponentContext context) throws Exception {
+            this.context = context;
+            if (context != null) {
+                try {
+                    XFire xfire = XFireFactory.newInstance().getXFire();
+                    QName service = new QName("http://xfire.jsr181.servicemix.org", "EchoService");
+                    proxy = (Echo) JbiProxy.create(xfire, context, null, service, null, Echo.class);
+                } catch (Exception e) {
+                    e.printStackTrace();
+                    throw e;
+                } catch (Error e) {
+                    e.printStackTrace();
+                    throw e;
+                }
+            } else {
+                proxy = null;
+            }
+        }
+        
+        public String echo(String s) {
+            return proxy.echo(s);
+        }
+    }
+    
+}

Reply via email to