activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jstrac...@apache.org
Subject svn commit: r525898 - in /activemq/camel/trunk/camel-cxf/src: main/java/org/apache/camel/component/cxf/ main/resources/META-INF/services/org/apache/camel/component/ test/java/org/apache/camel/component/cxf/
Date Thu, 05 Apr 2007 17:19:44 GMT
Author: jstrachan
Date: Thu Apr  5 10:19:42 2007
New Revision: 525898

URL: http://svn.apache.org/viewvc?view=rev&rev=525898
Log:
added Williams's patch with thanks; for now I've made a new CxfInvoke* set of components/endpoints;
I'm not too keen on the name yet - but we can refactor later when the dust settles on this
:)

Added:
    activemq/camel/trunk/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfConstants.java
  (with props)
    activemq/camel/trunk/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfInvokeComponent.java
  (contents, props changed)
      - copied, changed from r525829, activemq/camel/trunk/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfComponent.java
    activemq/camel/trunk/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfInvokeConsumer.java
  (contents, props changed)
      - copied, changed from r525829, activemq/camel/trunk/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfConsumer.java
    activemq/camel/trunk/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfInvokeEndpoint.java
  (contents, props changed)
      - copied, changed from r525829, activemq/camel/trunk/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfEndpoint.java
    activemq/camel/trunk/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfInvokeProducer.java
  (contents, props changed)
      - copied, changed from r525829, activemq/camel/trunk/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfProducer.java
    activemq/camel/trunk/camel-cxf/src/main/resources/META-INF/services/org/apache/camel/component/cxf-invoke
    activemq/camel/trunk/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfInvokeTest.java
  (with props)
    activemq/camel/trunk/camel-cxf/src/test/java/org/apache/camel/component/cxf/HelloService.java
  (with props)
    activemq/camel/trunk/camel-cxf/src/test/java/org/apache/camel/component/cxf/HelloServiceImpl.java
  (with props)
Modified:
    activemq/camel/trunk/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfBinding.java
    activemq/camel/trunk/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfTest.java

Modified: activemq/camel/trunk/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfBinding.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfBinding.java?view=diff&rev=525898&r1=525897&r2=525898
==============================================================================
--- activemq/camel/trunk/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfBinding.java
(original)
+++ activemq/camel/trunk/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfBinding.java
Thu Apr  5 10:19:42 2007
@@ -29,6 +29,7 @@
  * @version $Revision$
  */
 public class CxfBinding {
+
     public Object extractBodyFromCxf(CxfExchange exchange, Message message) {
         //  TODO how do we choose a format?
         return getBody(message);
@@ -73,6 +74,13 @@
         if (response != null) {
             out.setMessage(response);
             out.setBody(getBody(response));
+        }
+    }
+
+    public void storeCxfResponse(CxfExchange exchange, Object response) {
+        CxfMessage out = exchange.getOut();
+        if (response != null) {
+            out.setBody(response);
         }
     }
 }

Added: activemq/camel/trunk/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfConstants.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfConstants.java?view=auto&rev=525898
==============================================================================
--- activemq/camel/trunk/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfConstants.java
(added)
+++ activemq/camel/trunk/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfConstants.java
Thu Apr  5 10:19:42 2007
@@ -0,0 +1,31 @@
+/**
+ /**
+ *
+ * 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.camel.component.cxf;
+
+/**
+ * Constants used in this module
+ *
+ * @version $Revision$
+ */
+public interface CxfConstants {
+    String METHOD = "method";
+    String SEI = "sei";
+    String IMPL = "impl";
+}
+

Propchange: activemq/camel/trunk/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfConstants.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: activemq/camel/trunk/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfConstants.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: activemq/camel/trunk/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfConstants.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Copied: activemq/camel/trunk/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfInvokeComponent.java
(from r525829, activemq/camel/trunk/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfComponent.java)
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfInvokeComponent.java?view=diff&rev=525898&p1=activemq/camel/trunk/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfComponent.java&r1=525829&p2=activemq/camel/trunk/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfInvokeComponent.java&r2=525898
==============================================================================
--- activemq/camel/trunk/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfComponent.java
(original)
+++ activemq/camel/trunk/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfInvokeComponent.java
Thu Apr  5 10:19:42 2007
@@ -17,63 +17,69 @@
  */
 package org.apache.camel.component.cxf;
 
-import java.net.URI;
-import java.util.Map;
-
 import org.apache.camel.CamelContext;
 import org.apache.camel.Endpoint;
 import org.apache.camel.impl.DefaultComponent;
 import org.apache.cxf.Bus;
-import org.apache.cxf.BusException;
 import org.apache.cxf.bus.CXFBusFactory;
-import org.apache.cxf.service.model.EndpointInfo;
-import org.apache.cxf.transport.DestinationFactoryManager;
-import org.apache.cxf.transport.local.LocalTransportFactory;
-import org.xmlsoap.schemas.wsdl.http.AddressType;
+
+import java.net.URI;
+import java.util.Map;
+import java.util.Properties;
 
 /**
  * @version $Revision$
  */
-public class CxfComponent extends DefaultComponent<CxfExchange> {
-    private LocalTransportFactory localTransportFactory;
+public class CxfInvokeComponent extends DefaultComponent<CxfExchange> {
+    private Bus bus;
 
-    public CxfComponent() {
+    public CxfInvokeComponent() {
+        bus = CXFBusFactory.getDefaultBus();
     }
 
-    public CxfComponent(CamelContext context) {
+    public CxfInvokeComponent(CamelContext context) {
         super(context);
+        bus = CXFBusFactory.getDefaultBus();
     }
 
     @Override
     protected Endpoint<CxfExchange> createEndpoint(String uri, String remaining, Map
parameters) throws Exception {
-        URI u = new URI(remaining);
+        return new CxfInvokeEndpoint(getAddress(remaining), this, getQueryAsProperties(new
URI(remaining)));
+    }
 
-        // TODO this is a hack!!!
-        EndpointInfo endpointInfo = new EndpointInfo(null, "http://schemas.xmlsoap.org/soap/http");
-        AddressType a = new AddressType();
-        a.setLocation(remaining);
-        endpointInfo.addExtensor(a);
-
-        return new CxfEndpoint(uri, this, endpointInfo);
-    }
-
-    public LocalTransportFactory getLocalTransportFactory() throws BusException {
-        if (localTransportFactory == null) {
-            localTransportFactory = findLocalTransportFactory();
-            if (localTransportFactory == null) {
-                localTransportFactory = new LocalTransportFactory();
+    /**
+     * Read query parameters from uri
+     *
+     * @param u
+     * @return parameter value pairs as properties
+     */
+    protected Properties getQueryAsProperties(URI u) {
+        Properties retval = new Properties();
+        if (u.getQuery() != null) {
+            String[] parameters = u.getQuery().split("&");
+            for (int i = 0; i < parameters.length; i++) {
+                String[] s = parameters[i].split("=");
+                retval.put(s[0], s[1]);
             }
         }
-        return localTransportFactory;
+        return retval;
     }
 
-    public void setLocalTransportFactory(LocalTransportFactory localTransportFactory) {
-        this.localTransportFactory = localTransportFactory;
+    /**
+     * Remove query from uri
+     *
+     * @param uri
+     * @return substring before  the "?" character
+     */
+    protected String getAddress(String uri) {
+        int index = uri.indexOf("?");
+        if (-1 != index) {
+            return uri.substring(0, index);
+        }
+        return uri;
     }
 
-    protected LocalTransportFactory findLocalTransportFactory() throws BusException {
-        Bus bus = CXFBusFactory.getDefaultBus();
-        DestinationFactoryManager dfm = bus.getExtension(DestinationFactoryManager.class);
-        return (LocalTransportFactory) dfm.getDestinationFactory(LocalTransportFactory.TRANSPORT_ID);
+    public Bus getBus() {
+        return bus;
     }
-}
+}
\ No newline at end of file

Propchange: activemq/camel/trunk/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfInvokeComponent.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: activemq/camel/trunk/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfInvokeComponent.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: activemq/camel/trunk/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfInvokeComponent.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Copied: activemq/camel/trunk/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfInvokeConsumer.java
(from r525829, activemq/camel/trunk/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfConsumer.java)
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfInvokeConsumer.java?view=diff&rev=525898&p1=activemq/camel/trunk/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfConsumer.java&r1=525829&p2=activemq/camel/trunk/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfInvokeConsumer.java&r2=525898
==============================================================================
--- activemq/camel/trunk/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfConsumer.java
(original)
+++ activemq/camel/trunk/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfInvokeConsumer.java
Thu Apr  5 10:19:42 2007
@@ -19,49 +19,55 @@
 
 import org.apache.camel.Processor;
 import org.apache.camel.impl.DefaultConsumer;
+import org.apache.cxf.endpoint.ServerImpl;
+import org.apache.cxf.frontend.ServerFactoryBean;
 import org.apache.cxf.message.Message;
-import org.apache.cxf.transport.Destination;
-import org.apache.cxf.transport.MessageObserver;
-import org.apache.cxf.transport.local.LocalTransportFactory;
 
 /**
  * A consumer of exchanges for a service in CXF
  *
  * @version $Revision$
  */
-public class CxfConsumer extends DefaultConsumer<CxfExchange> {
-    private CxfEndpoint endpoint;
-    private final LocalTransportFactory transportFactory;
-    private Destination destination;
+public class CxfInvokeConsumer extends DefaultConsumer<CxfExchange> {
+    protected CxfInvokeEndpoint cxfEndpoint;
+    private ServerImpl server;
 
-    public CxfConsumer(CxfEndpoint endpoint, Processor<CxfExchange> processor, LocalTransportFactory
transportFactory) {
+    public CxfInvokeConsumer(CxfInvokeEndpoint endpoint, Processor<CxfExchange> processor)
{
         super(endpoint, processor);
-        this.endpoint = endpoint;
-        this.transportFactory = transportFactory;
+        this.cxfEndpoint = endpoint;
     }
 
     @Override
     protected void doStart() throws Exception {
         super.doStart();
+        // TODO we need to add custom cxf message observer and wire the
+        // incomingCxfMessage method.  Also, custom cxf interceptors are
+        // needed in order to object SOAP/XML message.  Currently, the
+        // CXF service invoker will invoke the service class.
+        if (server != null) {
+            // start a cxf service
+            ServerFactoryBean svrBean = new ServerFactoryBean();
+            svrBean.setAddress(getEndpoint().getEndpointUri());
+            svrBean.setServiceClass(Class.forName(cxfEndpoint.getProperty(CxfConstants.IMPL)));
+            svrBean.setBus(cxfEndpoint.getBus());
 
-        destination = transportFactory.getDestination(endpoint.getEndpointInfo());
-        destination.setMessageObserver(new MessageObserver() {
-            public void onMessage(Message message) {
-                incomingCxfMessage(message);
-            }
-        });
+            server = (ServerImpl) svrBean.create();
+            server.start();
+        }
     }
 
     @Override
     protected void doStop() throws Exception {
-        if (destination != null) {
-            destination.shutdown();
+        if (server != null) {
+            server.stop();
+            server = null;
         }
         super.doStop();
     }
 
+    // TODO this method currently is not being called.
     protected void incomingCxfMessage(Message message) {
-        CxfExchange exchange = endpoint.createExchange(message);
+        CxfExchange exchange = cxfEndpoint.createExchange(message);
         getProcessor().process(exchange);
     }
-}
+}
\ No newline at end of file

Propchange: activemq/camel/trunk/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfInvokeConsumer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: activemq/camel/trunk/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfInvokeConsumer.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: activemq/camel/trunk/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfInvokeConsumer.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Copied: activemq/camel/trunk/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfInvokeEndpoint.java
(from r525829, activemq/camel/trunk/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfEndpoint.java)
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfInvokeEndpoint.java?view=diff&rev=525898&p1=activemq/camel/trunk/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfEndpoint.java&r1=525829&p2=activemq/camel/trunk/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfInvokeEndpoint.java&r2=525898
==============================================================================
--- activemq/camel/trunk/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfEndpoint.java
(original)
+++ activemq/camel/trunk/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfInvokeEndpoint.java
Thu Apr  5 10:19:42 2007
@@ -17,38 +17,38 @@
  */
 package org.apache.camel.component.cxf;
 
+import java.util.Properties;
+
 import org.apache.camel.Consumer;
 import org.apache.camel.Processor;
 import org.apache.camel.Producer;
 import org.apache.camel.impl.DefaultEndpoint;
-import org.apache.cxf.BusException;
+import org.apache.cxf.Bus;
 import org.apache.cxf.message.Message;
-import org.apache.cxf.service.model.EndpointInfo;
-import org.apache.cxf.transport.local.LocalTransportFactory;
 
 /**
  * The endpoint in the service engine
  *
  * @version $Revision$
  */
-public class CxfEndpoint extends DefaultEndpoint<CxfExchange> {
+public class CxfInvokeEndpoint extends DefaultEndpoint<CxfExchange> {
     private CxfBinding binding;
-    private final CxfComponent component;
-    private final EndpointInfo endpointInfo;
+    private final CxfInvokeComponent component;
     private boolean inOut = true;
+    private Properties properties;
 
-    public CxfEndpoint(String uri, CxfComponent component, EndpointInfo endpointInfo) {
+    public CxfInvokeEndpoint(String uri, CxfInvokeComponent component, Properties properties)
{
         super(uri, component);
         this.component = component;
-        this.endpointInfo = endpointInfo;
+        this.properties = properties;
     }
 
     public Producer<CxfExchange> createProducer() throws Exception {
-        return startService(new CxfProducer(this, getLocalTransportFactory()));
+        return startService(new CxfInvokeProducer(this));
     }
 
     public Consumer<CxfExchange> createConsumer(Processor<CxfExchange> processor)
throws Exception {
-        return startService(new CxfConsumer(this, processor, getLocalTransportFactory()));
+        return startService(new CxfInvokeConsumer(this, processor));
     }
 
     public CxfExchange createExchange() {
@@ -78,15 +78,15 @@
         this.inOut = inOut;
     }
 
-    public LocalTransportFactory getLocalTransportFactory() throws BusException {
-        return component.getLocalTransportFactory();
+    public CxfInvokeComponent getComponent() {
+        return component;
     }
-
-    public EndpointInfo getEndpointInfo() {
-        return endpointInfo;
+    
+    public String getProperty(String key) {
+        return properties.getProperty(key);
     }
 
-    public CxfComponent getComponent() {
-        return component;
+    public Bus getBus() {
+        return component.getBus();
     }
 }

Propchange: activemq/camel/trunk/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfInvokeEndpoint.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: activemq/camel/trunk/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfInvokeEndpoint.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: activemq/camel/trunk/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfInvokeEndpoint.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Copied: activemq/camel/trunk/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfInvokeProducer.java
(from r525829, activemq/camel/trunk/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfProducer.java)
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfInvokeProducer.java?view=diff&rev=525898&p1=activemq/camel/trunk/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfProducer.java&r1=525829&p2=activemq/camel/trunk/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfInvokeProducer.java&r2=525898
==============================================================================
--- activemq/camel/trunk/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfProducer.java
(original)
+++ activemq/camel/trunk/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfInvokeProducer.java
Thu Apr  5 10:19:42 2007
@@ -19,107 +19,63 @@
 
 import org.apache.camel.RuntimeCamelException;
 import org.apache.camel.impl.DefaultProducer;
-import org.apache.cxf.message.ExchangeImpl;
-import org.apache.cxf.message.Message;
-import org.apache.cxf.message.MessageImpl;
-import org.apache.cxf.service.model.EndpointInfo;
-import org.apache.cxf.transport.Conduit;
-import org.apache.cxf.transport.Destination;
-import org.apache.cxf.transport.MessageObserver;
-import org.apache.cxf.transport.local.LocalConduit;
-import org.apache.cxf.transport.local.LocalTransportFactory;
+import org.apache.cxf.endpoint.Client;
+import org.apache.cxf.frontend.ClientFactoryBean;
 
-import java.io.IOException;
-import java.util.concurrent.CountDownLatch;
+import java.util.List;
 
 /**
  * Sends messages from Camel into the CXF endpoint
  *
  * @version $Revision$
  */
-public class CxfProducer extends DefaultProducer<CxfExchange> {
-    private CxfEndpoint endpoint;
-    private final LocalTransportFactory transportFactory;
-    private Destination destination;
-    private Conduit conduit;
-    private ResultFuture future = new ResultFuture();
+public class CxfInvokeProducer extends DefaultProducer<CxfExchange> {
+    private CxfInvokeEndpoint cxfEndpoint;
+    private Client client;
 
-    public CxfProducer(CxfEndpoint endpoint, LocalTransportFactory transportFactory) {
+    public CxfInvokeProducer(CxfInvokeEndpoint endpoint) {
         super(endpoint);
-        this.endpoint = endpoint;
-        this.transportFactory = transportFactory;
+        cxfEndpoint = endpoint;
     }
 
     public void process(CxfExchange exchange) {
+        List params = exchange.getIn().getBody(List.class);
+        Object[] response = null;
         try {
-            CxfBinding binding = endpoint.getBinding();
-            MessageImpl m = binding.createCxfMessage(exchange);
-            ExchangeImpl e = new ExchangeImpl();
-            e.setInMessage(m);
-            m.put(LocalConduit.DIRECT_DISPATCH, Boolean.TRUE);
-            m.setDestination(destination);
-            synchronized (conduit) {
-                conduit.send(m);
-
-                // now lets wait for the response
-                if (endpoint.isInOut()) {
-                    Message response = future.getResponse();
-
-                    // TODO - why do we need to ignore the returned message and get the out
message from the exchange!
-                    response = e.getOutMessage();
-                    binding.storeCxfResponse(exchange, response);
-                }
-            }
-        }
-        catch (IOException e) {
+            response = client.invoke(cxfEndpoint.getProperty(CxfConstants.METHOD), params.toArray());
+        }                                                           
+        catch (Exception e) {
             throw new RuntimeCamelException(e);
         }
-    }
 
-    @Override
-    protected void doStart() throws Exception {
-        super.doStart();
-        EndpointInfo endpointInfo = endpoint.getEndpointInfo();
-        destination = transportFactory.getDestination(endpointInfo);
-
-        // Set up a listener for the response
-        conduit = transportFactory.getConduit(endpointInfo);
-        conduit.setMessageObserver(future);
+        CxfBinding binding = cxfEndpoint.getBinding();
+        binding.storeCxfResponse(exchange, response);
     }
 
     @Override
-    protected void doStop() throws Exception {
-        super.doStop();
+    protected void doStart() throws Exception {
+        // TODO Add support for sending message inputstream.  Currently, we only handle
+        // method invocation with pojo.
 
-        if (conduit != null) {
-            conduit.close();
+        // TODO Add support for endpoints associated with a WSDL
+        if (client == null) {
+            ClientFactoryBean cfBean = new ClientFactoryBean();
+            cfBean.setAddress(getEndpoint().getEndpointUri());
+            cfBean.setBus(cxfEndpoint.getBus());
+            cfBean.setServiceClass(Class.forName(cxfEndpoint.getProperty(CxfConstants.SEI)));
+            client = cfBean.create();
         }
     }
 
-    protected class ResultFuture implements MessageObserver {
-        Message response;
-        CountDownLatch latch = new CountDownLatch(1);
-
-        public Message getResponse() {
-            while (response == null) {
-                try {
-                    latch.await();
-                }
-                catch (InterruptedException e) {
-                    // ignore
-                }
-            }
-            return response;
+    @Override
+    protected void doStop() throws Exception {
+        if (client != null) {
+            client.getConduit().close();
+            client = null;
         }
 
-        public synchronized void onMessage(Message message) {
-            try {
-                message.remove(LocalConduit.DIRECT_DISPATCH);
-                this.response = message;
-            }
-            finally {
-                latch.countDown();
-            }
-        }
+        super.doStop();
     }
 }
+
+

Propchange: activemq/camel/trunk/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfInvokeProducer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: activemq/camel/trunk/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfInvokeProducer.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: activemq/camel/trunk/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfInvokeProducer.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: activemq/camel/trunk/camel-cxf/src/main/resources/META-INF/services/org/apache/camel/component/cxf-invoke
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-cxf/src/main/resources/META-INF/services/org/apache/camel/component/cxf-invoke?view=auto&rev=525898
==============================================================================
--- activemq/camel/trunk/camel-cxf/src/main/resources/META-INF/services/org/apache/camel/component/cxf-invoke
(added)
+++ activemq/camel/trunk/camel-cxf/src/main/resources/META-INF/services/org/apache/camel/component/cxf-invoke
Thu Apr  5 10:19:42 2007
@@ -0,0 +1 @@
+class=org.apache.camel.component.cxf.CxfInvokeComponent

Added: activemq/camel/trunk/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfInvokeTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfInvokeTest.java?view=auto&rev=525898
==============================================================================
--- activemq/camel/trunk/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfInvokeTest.java
(added)
+++ activemq/camel/trunk/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfInvokeTest.java
Thu Apr  5 10:19:42 2007
@@ -0,0 +1,91 @@
+/**
+ *
+ * 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.camel.component.cxf;
+
+import junit.framework.TestCase;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.camel.CamelContext;
+import org.apache.camel.Processor;
+import org.apache.camel.util.CamelClient;
+import org.apache.camel.impl.DefaultCamelContext;
+import org.apache.cxf.endpoint.ServerImpl;
+import org.apache.cxf.frontend.ServerFactoryBean;
+import org.apache.cxf.bus.CXFBusFactory;
+
+import java.util.List;
+import java.util.ArrayList;
+
+/**
+ * @version $Revision$
+ */
+public class CxfInvokeTest extends TestCase {
+    private static final transient Log log = LogFactory.getLog(CxfInvokeTest.class);
+    protected CamelContext camelContext = new DefaultCamelContext();
+    protected CamelClient<CxfExchange> client = new CamelClient<CxfExchange>(camelContext);
+
+    final private String transportAddress = "http://localhost:28080/test";
+    final private String testMessage = "Hello World!";
+    private ServerImpl server;
+
+    @Override
+    protected void setUp() throws Exception {
+
+        // start a service
+        ServerFactoryBean svrBean = new ServerFactoryBean();
+
+        svrBean.setAddress(transportAddress);
+        svrBean.setServiceClass(HelloServiceImpl.class);
+        svrBean.setBus(CXFBusFactory.getDefaultBus());
+
+        server = (ServerImpl)svrBean.create();
+        server.start();
+    }
+
+    @Override
+    protected void tearDown() throws Exception {
+        if (server != null) {
+            server.stop();
+        }
+    }
+
+    public void testInvokeOfServer() throws Exception {
+
+        CxfExchange exchange =
+            client.send(getUri(),
+                        new Processor<CxfExchange>() {
+                            public void process(final CxfExchange exchange) {
+                                final List<String> params = new ArrayList<String>();
+                                params.add(testMessage);
+                                exchange.getIn().setBody(params);
+                            }
+                        });
+
+        org.apache.camel.Message out = exchange.getOut();
+
+        Object[] output = (Object[])out.getBody();
+        log.info("Received output text: " + output[0]);
+
+        assertEquals("reply body on Camel", testMessage, output[0]);
+    }
+
+    private String getUri() {
+        return "cxf-invoke:" + transportAddress
+            + "?sei=org.apache.camel.component.cxf.HelloService&method=echo";
+    }
+}

Propchange: activemq/camel/trunk/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfInvokeTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: activemq/camel/trunk/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfInvokeTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: activemq/camel/trunk/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfInvokeTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: activemq/camel/trunk/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfTest.java?view=diff&rev=525898&r1=525897&r2=525898
==============================================================================
--- activemq/camel/trunk/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfTest.java
(original)
+++ activemq/camel/trunk/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfTest.java
Thu Apr  5 10:19:42 2007
@@ -27,6 +27,8 @@
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.cxf.Bus;
+import org.apache.cxf.frontend.ServerFactoryBean;
+import org.apache.cxf.endpoint.ServerImpl;
 import org.apache.cxf.bus.CXFBusFactory;
 import org.apache.cxf.message.Message;
 import org.apache.cxf.message.MessageImpl;
@@ -44,7 +46,7 @@
 import java.io.InputStream;
 import java.io.OutputStream;
 import java.util.Map;
-import java.util.Set;
+import java.util.*;
 
 /**
  * @version $Revision$
@@ -52,104 +54,55 @@
 public class CxfTest extends TestCase {
     private static final transient Log log = LogFactory.getLog(CxfTest.class);
     protected CamelContext camelContext = new DefaultCamelContext();
-    protected CamelClient client = new CamelClient(camelContext);
+    protected CamelClient<CxfExchange> client = new CamelClient<CxfExchange>(camelContext);
 
-    public void testInvokeOfServer() throws Exception {
-        // lets register a service
-        EndpointInfo ei = new EndpointInfo(null, "http://schemas.xmlsoap.org/soap/http");
-        AddressType a = new AddressType();
-        a.setLocation("http://localhost/test");
-        ei.addExtensor(a);
-
-        Bus bus = CXFBusFactory.getDefaultBus();
-        DestinationFactoryManager dfm = bus.getExtension(DestinationFactoryManager.class);
-        DestinationFactory factory = dfm.getDestinationFactory(LocalTransportFactory.TRANSPORT_ID);
-
-        Destination destination = factory.getDestination(ei);
-        destination.setMessageObserver(new EchoObserver());
-
-        // now lets invoke it via Camel
-        CxfExchange exchange = (CxfExchange) client.send("cxf:http://localhost/test", new
Processor<Exchange>() {
-            public void process(Exchange exchange) {
-                exchange.getIn().setHeader("requestHeader", "foo");
-                exchange.getIn().setBody("<hello>world</hello>");
-            }
-        });
+    final private String transportAddress = "http://localhost:28080/test";
+    final private String testMessage = "Hello World!";
+    private ServerImpl server;
+    
+    @Override
+    protected void setUp() throws Exception {
+        
+        // start a service
+        ServerFactoryBean svrBean = new ServerFactoryBean();
+
+        svrBean.setAddress(transportAddress);
+        svrBean.setServiceClass(HelloServiceImpl.class);
+        svrBean.setBus(CXFBusFactory.getDefaultBus());
 
-        org.apache.camel.Message out = exchange.getOut();
-        Message cxfOutMessage = exchange.getOutMessage();
-        log.info("Received output message: " + out + " and CXF out: " + cxfOutMessage);
+        server = (ServerImpl)svrBean.create();
+        server.start();
+    }
+    
+    @Override
+    protected void tearDown() throws Exception {
+        if (server != null) {
+            server.stop();
+        }
+    }
+    
+    public void testInvokeOfServer() throws Exception {
 
-        assertEquals("replyHeader on CXF", "foo2", cxfOutMessage.get("replyHeader"));
-        assertEquals("replyHeader on Camel", "foo2", out.getHeader("replyHeader"));
+        CxfExchange exchange = (CxfExchange) 
+            client.send(getUri(),
+                        new Processor<CxfExchange>() {
+                            public void process(final CxfExchange exchange) {
+                                final List<String> params = new ArrayList<String>();
+                                params.add(testMessage);
+                                exchange.getIn().setBody(params);
+                            }
+                        });
 
-        String output = out.getBody(String.class);
-        log.info("Received output text: " + output);
-    }
+        org.apache.camel.Message out = exchange.getOut();
 
-    protected class EchoObserver implements MessageObserver {
-        public void onMessage(Message message) {
-            try {
-                log.info("Received message: " + message + " with content types: " + message.getContentFormats());
-
-                Conduit backChannel = message.getDestination().getBackChannel(message, null,
null);
-                message.remove(LocalConduit.DIRECT_DISPATCH);
-
-                TypeConverter converter = camelContext.getTypeConverter();
-                String request = converter.convertTo(String.class, message.getContent(InputStream.class));
-                log.info("Request body: " + request);
-
-                org.apache.cxf.message.Exchange exchange = message.getExchange();
-                MessageImpl reply = new MessageImpl();
-                reply.put("foo", "bar");
-                assertEquals("foo header", "bar", reply.get("foo"));
-
-                reply.put("replyHeader", message.get("requestHeader") + "2");
-
-                Set<Map.Entry<String, Object>> entries = reply.entrySet();
-                assertEquals("entrySet.size()", 2, entries.size());
-
-                //reply.setContent(String.class, "<reply>true</reply>");
-                InputStream payload = converter.convertTo(InputStream.class, "<reply>true</reply>");
-                reply.setContent(InputStream.class, payload);
-                exchange.setOutMessage(reply);
-
-                log.info("sending reply: " + reply);
-                backChannel.send(message);
-
-/*
-                backChannel.send(message);
-
-                OutputStream out = message.getContent(OutputStream.class);
-                InputStream in = message.getContent(InputStream.class);
-
-                copy(in, out, 1024);
-
-                out.close();
-                in.close();
-*/
-            }
-            catch (Exception e) {
-                log.error("Caught: " + e, e);
-                fail("Caught: " + e);
-            }
-        }
+        Object[] output = (Object[])out.getBody();
+        log.info("Received output text: " + output[0]);
+        
+        assertEquals("reply body on Camel", testMessage, output[0]);
     }
 
-    private static void copy(final InputStream input, final OutputStream output, final int
bufferSize)
-            throws IOException {
-        try {
-            final byte[] buffer = new byte[bufferSize];
-
-            int n = input.read(buffer);
-            while (-1 != n) {
-                output.write(buffer, 0, n);
-                n = input.read(buffer);
-            }
-        }
-        finally {
-            input.close();
-            output.close();
-        }
+    private String getUri() {
+        return "cxf:" + transportAddress 
+            + "?sei=org.apache.camel.component.cxf.HelloService&method=echo";
     }
 }

Added: activemq/camel/trunk/camel-cxf/src/test/java/org/apache/camel/component/cxf/HelloService.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-cxf/src/test/java/org/apache/camel/component/cxf/HelloService.java?view=auto&rev=525898
==============================================================================
--- activemq/camel/trunk/camel-cxf/src/test/java/org/apache/camel/component/cxf/HelloService.java
(added)
+++ activemq/camel/trunk/camel-cxf/src/test/java/org/apache/camel/component/cxf/HelloService.java
Thu Apr  5 10:19:42 2007
@@ -0,0 +1,28 @@
+/**
+ /**
+ * 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.camel.component.cxf;
+
+public interface HelloService {
+    String sayHello();
+
+    void ping();
+
+    String echo(String text);
+}
\ No newline at end of file

Propchange: activemq/camel/trunk/camel-cxf/src/test/java/org/apache/camel/component/cxf/HelloService.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: activemq/camel/trunk/camel-cxf/src/test/java/org/apache/camel/component/cxf/HelloService.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: activemq/camel/trunk/camel-cxf/src/test/java/org/apache/camel/component/cxf/HelloService.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: activemq/camel/trunk/camel-cxf/src/test/java/org/apache/camel/component/cxf/HelloServiceImpl.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-cxf/src/test/java/org/apache/camel/component/cxf/HelloServiceImpl.java?view=auto&rev=525898
==============================================================================
--- activemq/camel/trunk/camel-cxf/src/test/java/org/apache/camel/component/cxf/HelloServiceImpl.java
(added)
+++ activemq/camel/trunk/camel-cxf/src/test/java/org/apache/camel/component/cxf/HelloServiceImpl.java
Thu Apr  5 10:19:42 2007
@@ -0,0 +1,35 @@
+/**
+ /**
+ * 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.camel.component.cxf;
+
+public class HelloServiceImpl implements HelloService {
+    public String echo(String text) {
+        return text;
+    }
+
+    public void ping() {
+
+    }
+
+    public String sayHello() {
+        return "hello";
+    }
+}
+

Propchange: activemq/camel/trunk/camel-cxf/src/test/java/org/apache/camel/component/cxf/HelloServiceImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: activemq/camel/trunk/camel-cxf/src/test/java/org/apache/camel/component/cxf/HelloServiceImpl.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: activemq/camel/trunk/camel-cxf/src/test/java/org/apache/camel/component/cxf/HelloServiceImpl.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message