servicemix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ff...@apache.org
Subject svn commit: r597579 - in /servicemix/branches/servicemix-4.0/camel: ./ src/main/java/org/apache/servicemix/camel/ src/test/java/org/apache/servicemix/camel/
Date Fri, 23 Nov 2007 07:32:19 GMT
Author: ffang
Date: Thu Nov 22 23:32:15 2007
New Revision: 597579

URL: http://svn.apache.org/viewvc?rev=597579&view=rev
Log:
[SM-1133] verify how camel is used as core of jax-ws process

Added:
    servicemix/branches/servicemix-4.0/camel/src/test/java/org/apache/servicemix/camel/HelloService.java
  (with props)
    servicemix/branches/servicemix-4.0/camel/src/test/java/org/apache/servicemix/camel/HelloServiceImpl.java
  (with props)
    servicemix/branches/servicemix-4.0/camel/src/test/java/org/apache/servicemix/camel/SmxToCxfTest.java
  (with props)
Modified:
    servicemix/branches/servicemix-4.0/camel/pom.xml
    servicemix/branches/servicemix-4.0/camel/src/main/java/org/apache/servicemix/camel/ServiceMixComponent.java
    servicemix/branches/servicemix-4.0/camel/src/main/java/org/apache/servicemix/camel/ServiceMixConsumer.java
    servicemix/branches/servicemix-4.0/camel/src/main/java/org/apache/servicemix/camel/ServiceMixEndpoint.java
    servicemix/branches/servicemix-4.0/camel/src/main/java/org/apache/servicemix/camel/ServiceMixExchange.java
    servicemix/branches/servicemix-4.0/camel/src/main/java/org/apache/servicemix/camel/ServiceMixMessage.java
    servicemix/branches/servicemix-4.0/camel/src/main/java/org/apache/servicemix/camel/ServiceMixProducer.java

Modified: servicemix/branches/servicemix-4.0/camel/pom.xml
URL: http://svn.apache.org/viewvc/servicemix/branches/servicemix-4.0/camel/pom.xml?rev=597579&r1=597578&r2=597579&view=diff
==============================================================================
--- servicemix/branches/servicemix-4.0/camel/pom.xml (original)
+++ servicemix/branches/servicemix-4.0/camel/pom.xml Thu Nov 22 23:32:15 2007
@@ -34,10 +34,16 @@
     <version>4.0-SNAPSHOT</version>
     <name>ServiceMix Camel</name>
 
+    <properties>
+        <cxf.version>2.0.3-incubator</cxf.version>
+        <jaxb-impl.version>2.0.1</jaxb-impl.version>
+        <jaxb-api.version>2.0</jaxb-api.version>
+    </properties>
+
     <dependencies>
         <dependency>
             <groupId>org.apache.servicemix.nmr</groupId>
-            <artifactId>org.apache.servicemix.nmr.api</artifactId>
+            <artifactId>org.apache.servicemix.nmr.osgi</artifactId>
             <version>${project.version}</version>
         </dependency>
         <dependency>
@@ -46,10 +52,56 @@
             <version>${camel.version}</version>
         </dependency>
         <dependency>
+            <groupId>org.apache.camel</groupId>
+            <artifactId>camel-core</artifactId>
+            <version>${camel.version}</version>
+            <type>test-jar</type>
+        </dependency>
+        <dependency>
+	    <groupId>org.apache.camel</groupId>
+	    <artifactId>camel-spring</artifactId>
+            <version>${camel.version}</version>
+	</dependency>
+
+        <dependency>
+            <groupId>org.apache.camel</groupId>
+            <artifactId>camel-cxf</artifactId>
+            <version>${camel.version}</version>
+        </dependency>
+
+	<dependency>
+            <groupId>org.apache.camel</groupId>
+            <artifactId>camel-http</artifactId>
+            <version>${camel.version}</version>
+        </dependency>
+
+	<dependency>
+	    <groupId>org.apache.camel</groupId>
+	    <artifactId>camel-spring</artifactId>
+            <version>${camel.version}</version>
+	    <type>test-jar</type>
+	</dependency>
+        <dependency>
             <groupId>junit</groupId>
             <artifactId>junit</artifactId>
             <version>${junit.version}</version>
             <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.servicemix.bundles</groupId>
+	    <artifactId>org.apache.servicemix.bundles.jaxb-impl</artifactId>
+	    <version>${jaxb-impl.version}-${pom.version}</version>
+        </dependency>
+        
+        <dependency>
+            <groupId>org.apache.servicemix.bundles</groupId>
+            <artifactId>org.apache.servicemix.bundles.jaxb-api</artifactId>
+            <version>${jaxb-api.version}-${pom.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.servicemix.bundles</groupId>
+            <artifactId>org.apache.servicemix.bundles.cxf</artifactId>
+            <version>${cxf.version}-${pom.version}</version>
         </dependency>
     </dependencies>
 

Modified: servicemix/branches/servicemix-4.0/camel/src/main/java/org/apache/servicemix/camel/ServiceMixComponent.java
URL: http://svn.apache.org/viewvc/servicemix/branches/servicemix-4.0/camel/src/main/java/org/apache/servicemix/camel/ServiceMixComponent.java?rev=597579&r1=597578&r2=597579&view=diff
==============================================================================
--- servicemix/branches/servicemix-4.0/camel/src/main/java/org/apache/servicemix/camel/ServiceMixComponent.java
(original)
+++ servicemix/branches/servicemix-4.0/camel/src/main/java/org/apache/servicemix/camel/ServiceMixComponent.java
Thu Nov 22 23:32:15 2007
@@ -42,7 +42,7 @@
     }
 
     protected Endpoint createEndpoint(String uri, String remaining, Map parameters) throws
Exception {
-        return new ServiceMixEndpoint(this, uri);
+        return new ServiceMixEndpoint(this, uri, remaining);
     }
 
     public void registerEndpoint(org.apache.servicemix.nmr.api.Endpoint endpoint, Map<String,
?> properties) {

Modified: servicemix/branches/servicemix-4.0/camel/src/main/java/org/apache/servicemix/camel/ServiceMixConsumer.java
URL: http://svn.apache.org/viewvc/servicemix/branches/servicemix-4.0/camel/src/main/java/org/apache/servicemix/camel/ServiceMixConsumer.java?rev=597579&r1=597578&r2=597579&view=diff
==============================================================================
--- servicemix/branches/servicemix-4.0/camel/src/main/java/org/apache/servicemix/camel/ServiceMixConsumer.java
(original)
+++ servicemix/branches/servicemix-4.0/camel/src/main/java/org/apache/servicemix/camel/ServiceMixConsumer.java
Thu Nov 22 23:32:15 2007
@@ -21,6 +21,7 @@
 import org.apache.servicemix.nmr.api.Channel;
 import org.apache.servicemix.nmr.api.Exchange;
 import org.apache.servicemix.nmr.api.Status;
+import org.apache.servicemix.nmr.api.service.ServiceHelper;
 
 /**
  * Created by IntelliJ IDEA.
@@ -29,7 +30,7 @@
  * Time: 8:59:46 AM
  * To change this template use File | Settings | File Templates.
  */
-public class ServiceMixConsumer extends DefaultConsumer implements org.apache.servicemix.nmr.api.Endpoint
{
+public class ServiceMixConsumer extends DefaultConsumer<ServiceMixExchange> implements
org.apache.servicemix.nmr.api.Endpoint {
 
     private Channel channel;
 
@@ -43,11 +44,15 @@
 
     protected void doStart() throws Exception {
         super.doStart();
-        getEndpoint().getComponent().registerEndpoint(this, null);
+        getEndpoint().getComponent().registerEndpoint(this, 
+        		ServiceHelper.createMap(org.apache.servicemix.nmr.api.Endpoint.NAME, 
+        				getEndpoint().getEndpointName()));
     }
 
     protected void doStop() throws Exception {
-        getEndpoint().getComponent().unregisterEndpoint(this, null);
+        getEndpoint().getComponent().unregisterEndpoint(this, 
+        		ServiceHelper.createMap(org.apache.servicemix.nmr.api.Endpoint.NAME, 
+        				getEndpoint().getEndpointName()));
         super.doStop();
     }
 
@@ -56,10 +61,18 @@
     }
 
     public void process(Exchange exchange) {
-        if (exchange.getStatus() == Status.Active) {
+    	if (exchange.getStatus() == Status.Active) {
             try {
-                getAsyncProcessor().process(new ServiceMixExchange(exchange));
+            	ServiceMixExchange smExchange = getEndpoint().createExchange(exchange.getIn(),
exchange);
+                getAsyncProcessor().process(smExchange);
+                exchange.setStatus(Status.Done);
+                
+                //there is a bug in camel cxf so the smExchange.getOut().getBody() is null;
+                // fixed in my working copy
+                exchange.getOut().setBody(smExchange.getOut().getBody());
+                channel.send(exchange);
             } catch (Exception e) {
+            	e.printStackTrace();
                 exchange.setError(e);
                 exchange.setStatus(Status.Error);
                 channel.send(exchange);

Modified: servicemix/branches/servicemix-4.0/camel/src/main/java/org/apache/servicemix/camel/ServiceMixEndpoint.java
URL: http://svn.apache.org/viewvc/servicemix/branches/servicemix-4.0/camel/src/main/java/org/apache/servicemix/camel/ServiceMixEndpoint.java?rev=597579&r1=597578&r2=597579&view=diff
==============================================================================
--- servicemix/branches/servicemix-4.0/camel/src/main/java/org/apache/servicemix/camel/ServiceMixEndpoint.java
(original)
+++ servicemix/branches/servicemix-4.0/camel/src/main/java/org/apache/servicemix/camel/ServiceMixEndpoint.java
Thu Nov 22 23:32:15 2007
@@ -16,11 +16,14 @@
  */
 package org.apache.servicemix.camel;
 
+
 import org.apache.camel.impl.DefaultEndpoint;
+import org.apache.camel.ExchangePattern;
 import org.apache.camel.Producer;
 import org.apache.camel.Consumer;
 import org.apache.camel.Processor;
-import org.apache.camel.Component;
+import org.apache.servicemix.nmr.api.Exchange;
+
 
 /**
  * Created by IntelliJ IDEA.
@@ -31,8 +34,11 @@
  */
 public class ServiceMixEndpoint extends DefaultEndpoint {
 
-    public ServiceMixEndpoint(ServiceMixComponent component, String uri) {
+	private String endpointName;
+	
+    public ServiceMixEndpoint(ServiceMixComponent component, String uri, String endpointName)
{
         super(uri, component);
+        this.setEndpointName(endpointName);
     }
 
     public ServiceMixComponent getComponent() {
@@ -50,4 +56,25 @@
     public Consumer createConsumer(Processor processor) throws Exception {
         return new ServiceMixConsumer(this, processor);
     }
+    
+    public ServiceMixExchange createExchange(Exchange exchange) {
+        return new ServiceMixExchange(getContext(), getExchangePattern(), exchange);
+    }
+
+    public ServiceMixExchange createExchange(ExchangePattern pattern, Exchange exchange)
{
+        return new ServiceMixExchange(getContext(), pattern, exchange);
+    }
+
+    public ServiceMixExchange createExchange(org.apache.servicemix.nmr.api.Message inMessage,
Exchange exchange) {
+        return new ServiceMixExchange(getContext(), getExchangePattern(), inMessage, exchange);
+    }
+
+
+	public void setEndpointName(String endpointName) {
+		this.endpointName = endpointName;
+	}
+
+	public String getEndpointName() {
+		return endpointName;
+	}
 }

Modified: servicemix/branches/servicemix-4.0/camel/src/main/java/org/apache/servicemix/camel/ServiceMixExchange.java
URL: http://svn.apache.org/viewvc/servicemix/branches/servicemix-4.0/camel/src/main/java/org/apache/servicemix/camel/ServiceMixExchange.java?rev=597579&r1=597578&r2=597579&view=diff
==============================================================================
--- servicemix/branches/servicemix-4.0/camel/src/main/java/org/apache/servicemix/camel/ServiceMixExchange.java
(original)
+++ servicemix/branches/servicemix-4.0/camel/src/main/java/org/apache/servicemix/camel/ServiceMixExchange.java
Thu Nov 22 23:32:15 2007
@@ -16,11 +16,12 @@
  */
 package org.apache.servicemix.camel;
 
-import org.apache.camel.Exchange;
+
 import org.apache.camel.ExchangePattern;
-import org.apache.camel.Message;
+
 import org.apache.camel.CamelContext;
-import org.apache.camel.spi.UnitOfWork;
+import org.apache.camel.impl.DefaultExchange;
+
 
 import java.util.Map;
 
@@ -31,22 +32,43 @@
  * Time: 8:50:07 AM
  * To change this template use File | Settings | File Templates.
  */
-public class ServiceMixExchange implements Exchange {
+public class ServiceMixExchange extends DefaultExchange {
 
     private org.apache.servicemix.nmr.api.Exchange exchange;
-    private ServiceMixMessage in;
-    private ServiceMixMessage out;
-    private ServiceMixMessage fault;
+  
 
-    public ServiceMixExchange(org.apache.servicemix.nmr.api.Exchange exchange) {
+    public ServiceMixExchange(org.apache.servicemix.nmr.api.Exchange exchange, CamelContext
camelContext) {
+    	super(camelContext);
         this.exchange = exchange;
+        setIn(new ServiceMixMessage(exchange.getIn()));
+        setOut(new ServiceMixMessage(exchange.getOut()));
+        if (exchange.getFault() != null) {
+            setFault(new ServiceMixMessage(exchange.getFault()));
+        }    
     }
 
-    public ExchangePattern getPattern() {
-        return null;  //To change body of implemented methods use File | Settings | File
Templates.
-    }
+    public ServiceMixExchange(CamelContext context, ExchangePattern pattern, org.apache.servicemix.nmr.api.Exchange
exchange) {
+        super(context, pattern);        
+        this.exchange = exchange;
+        setIn(new ServiceMixMessage(exchange.getIn()));
+        setOut(new ServiceMixMessage(exchange.getOut()));
+        if (exchange.getFault() != null) {
+            setFault(new ServiceMixMessage(exchange.getFault()));
+        }
+    }
+
+    public ServiceMixExchange(CamelContext context, ExchangePattern exchangePattern, org.apache.servicemix.nmr.api.Message
inMessage,
+    		org.apache.servicemix.nmr.api.Exchange exchange) {
+    	super(context, exchangePattern);
+    	setIn(new ServiceMixMessage(exchange.getIn()));
+        setOut(new ServiceMixMessage(exchange.getOut()));
+        if (exchange.getFault() != null) {
+            setFault(new ServiceMixMessage(exchange.getFault()));
+        }
+    	this.exchange = exchange;
+	}
 
-    public Object getProperty(String name) {
+	public Object getProperty(String name) {
         return exchange.getProperty(name);
     }
 
@@ -55,7 +77,7 @@
     }
 
     public void setProperty(String name, Object value) {
-        exchange.setProperty(name, value);
+    	exchange.setProperty(name, value);
     }
 
     public Object removeProperty(String name) {
@@ -68,75 +90,40 @@
         return exchange.getProperties();
     }
 
-    public Message getIn() {
-        return null;
-    }
-
-    public Message getOut() {
-        return null;  //To change body of implemented methods use File | Settings | File
Templates.
-    }
 
-    public Message getOut(boolean lazyCreate) {
-        return null;  //To change body of implemented methods use File | Settings | File
Templates.
+    public ServiceMixMessage getIn() {
+        return (ServiceMixMessage) super.getIn();
     }
 
-    public Message getFault() {
-        return null;  //To change body of implemented methods use File | Settings | File
Templates.
-    }
 
-    public Message getFault(boolean lazyCreate) {
-        return null;  //To change body of implemented methods use File | Settings | File
Templates.
+    public ServiceMixMessage getOut() {
+        return (ServiceMixMessage) super.getOut();
     }
 
-    public Throwable getException() {
-        return null;  //To change body of implemented methods use File | Settings | File
Templates.
-    }
 
-    public void setException(Throwable e) {
-        //To change body of implemented methods use File | Settings | File Templates.
+    public ServiceMixMessage getOut(boolean lazyCreate) {
+        return (ServiceMixMessage) super.getOut(lazyCreate);
     }
 
-    public boolean isFailed() {
-        return false;  //To change body of implemented methods use File | Settings | File
Templates.
-    }
 
-    public CamelContext getContext() {
-        return null;  //To change body of implemented methods use File | Settings | File
Templates.
+    public ServiceMixMessage getFault() {
+        return (ServiceMixMessage) super.getFault();
     }
+    
 
-    public Exchange copy() {
-        return null;  //To change body of implemented methods use File | Settings | File
Templates.
+    @Override
+    protected ServiceMixMessage createInMessage() {
+        return new ServiceMixMessage();
     }
 
-    public void copyFrom(Exchange source) {
-        //To change body of implemented methods use File | Settings | File Templates.
+    @Override
+    protected ServiceMixMessage createOutMessage() {
+        return new ServiceMixMessage();
     }
-
-    public UnitOfWork getUnitOfWork() {
-        return null;  //To change body of implemented methods use File | Settings | File
Templates.
+    
+    @Override
+    protected org.apache.camel.Message createFaultMessage() {
+        return new ServiceMixMessage();
     }
 
-    public String getExchangeId() {
-        return null;  //To change body of implemented methods use File | Settings | File
Templates.
-    }
-
-    public void setExchangeId(String id) {
-        //To change body of implemented methods use File | Settings | File Templates.
-    }
-
-    public void setUnitOfWork(UnitOfWork unitOfWork) {
-        //To change body of implemented methods use File | Settings | File Templates.
-    }
-
-    public Exchange newInstance() {
-        return null;  //To change body of implemented methods use File | Settings | File
Templates.
-    }
-
-    public void setIn(Message message) {
-        //To change body of implemented methods use File | Settings | File Templates.
-    }
-
-    public void setOut(Message message) {
-        //To change body of implemented methods use File | Settings | File Templates.
-    }
 }

Modified: servicemix/branches/servicemix-4.0/camel/src/main/java/org/apache/servicemix/camel/ServiceMixMessage.java
URL: http://svn.apache.org/viewvc/servicemix/branches/servicemix-4.0/camel/src/main/java/org/apache/servicemix/camel/ServiceMixMessage.java?rev=597579&r1=597578&r2=597579&view=diff
==============================================================================
--- servicemix/branches/servicemix-4.0/camel/src/main/java/org/apache/servicemix/camel/ServiceMixMessage.java
(original)
+++ servicemix/branches/servicemix-4.0/camel/src/main/java/org/apache/servicemix/camel/ServiceMixMessage.java
Thu Nov 22 23:32:15 2007
@@ -18,6 +18,7 @@
 
 import org.apache.camel.Message;
 import org.apache.camel.Exchange;
+import org.apache.camel.impl.DefaultMessage;
 import org.apache.camel.util.UuidGenerator;
 
 import java.util.Map;
@@ -29,7 +30,7 @@
  * Time: 9:06:27 AM
  * To change this template use File | Settings | File Templates.
  */
-public class ServiceMixMessage implements Message {
+public class ServiceMixMessage extends DefaultMessage {
 
     private static final UuidGenerator DEFALT_ID_GENERATOR = new UuidGenerator();
 
@@ -38,7 +39,16 @@
     private String messageId = DEFALT_ID_GENERATOR.generateId();
 
     public ServiceMixMessage(ServiceMixExchange exchange, org.apache.servicemix.nmr.api.Message
message) {
+    	this.exchange = exchange;
         this.message = message;
+    }
+    
+    public ServiceMixMessage(org.apache.servicemix.nmr.api.Message message) {
+    	this.message = message;
+    }
+    
+    public ServiceMixMessage() {
+    	
     }
 
     public String getMessageId() {

Modified: servicemix/branches/servicemix-4.0/camel/src/main/java/org/apache/servicemix/camel/ServiceMixProducer.java
URL: http://svn.apache.org/viewvc/servicemix/branches/servicemix-4.0/camel/src/main/java/org/apache/servicemix/camel/ServiceMixProducer.java?rev=597579&r1=597578&r2=597579&view=diff
==============================================================================
--- servicemix/branches/servicemix-4.0/camel/src/main/java/org/apache/servicemix/camel/ServiceMixProducer.java
(original)
+++ servicemix/branches/servicemix-4.0/camel/src/main/java/org/apache/servicemix/camel/ServiceMixProducer.java
Thu Nov 22 23:32:15 2007
@@ -16,9 +16,13 @@
  */
 package org.apache.servicemix.camel;
 
+import org.apache.camel.component.cxf.CxfConstants;
 import org.apache.camel.impl.DefaultProducer;
 import org.apache.camel.Exchange;
-import org.apache.camel.Endpoint;
+import org.apache.servicemix.nmr.api.Channel;
+import org.apache.servicemix.nmr.api.NMR;
+import org.apache.servicemix.nmr.api.Pattern;
+import org.apache.servicemix.nmr.api.service.ServiceHelper;
 
 /**
  * Created by IntelliJ IDEA.
@@ -27,7 +31,7 @@
  * Time: 8:59:25 AM
  * To change this template use File | Settings | File Templates.
  */
-public class ServiceMixProducer extends DefaultProducer {
+public class ServiceMixProducer extends DefaultProducer<ServiceMixExchange> {
 
     public ServiceMixProducer(ServiceMixEndpoint endpoint) {
         super(endpoint);
@@ -38,6 +42,27 @@
     }
 
     public void process(Exchange exchange) throws Exception {
-        //To change body of implemented methods use File | Settings | File Templates.
+    	
+    	NMR nmr = getEndpoint().getComponent().getNmr();
+    	Channel client = nmr.createChannel();
+    	
+    	// there is a bug in camel cxf exchange.getPattern().getWsdlUri() is always inonly
+    	// fix it in my working copy
+        org.apache.servicemix.nmr.api.Exchange e = client.createExchange(
+        		Pattern.fromWsdlUri(exchange.getPattern().getWsdlUri()));
+        
+        try {
+        	e.setTarget(nmr.getEndpointRegistry().lookup(
+        		ServiceHelper.createMap(org.apache.servicemix.nmr.api.Endpoint.NAME, 
+        				getEndpoint().getEndpointName())));
+        } catch (Exception ex) {
+        	ex.printStackTrace();
+        }
+        e.getIn().setBody(exchange.getIn().getBody());
+        e.getIn().setHeader(CxfConstants.OPERATION_NAME, 
+        		exchange.getIn().getHeader(CxfConstants.OPERATION_NAME));
+        client.sendSync(e);
+        exchange.getOut().setBody(e.getOut().getBody());
+        
     }
 }

Added: servicemix/branches/servicemix-4.0/camel/src/test/java/org/apache/servicemix/camel/HelloService.java
URL: http://svn.apache.org/viewvc/servicemix/branches/servicemix-4.0/camel/src/test/java/org/apache/servicemix/camel/HelloService.java?rev=597579&view=auto
==============================================================================
--- servicemix/branches/servicemix-4.0/camel/src/test/java/org/apache/servicemix/camel/HelloService.java
(added)
+++ servicemix/branches/servicemix-4.0/camel/src/test/java/org/apache/servicemix/camel/HelloService.java
Thu Nov 22 23:32:15 2007
@@ -0,0 +1,26 @@
+/*
+ * 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.servicemix.camel;
+
+public interface HelloService {
+    String sayHello();
+
+    void ping();
+
+    String echo(String text);
+}
\ No newline at end of file

Propchange: servicemix/branches/servicemix-4.0/camel/src/test/java/org/apache/servicemix/camel/HelloService.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: servicemix/branches/servicemix-4.0/camel/src/test/java/org/apache/servicemix/camel/HelloService.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: servicemix/branches/servicemix-4.0/camel/src/test/java/org/apache/servicemix/camel/HelloServiceImpl.java
URL: http://svn.apache.org/viewvc/servicemix/branches/servicemix-4.0/camel/src/test/java/org/apache/servicemix/camel/HelloServiceImpl.java?rev=597579&view=auto
==============================================================================
--- servicemix/branches/servicemix-4.0/camel/src/test/java/org/apache/servicemix/camel/HelloServiceImpl.java
(added)
+++ servicemix/branches/servicemix-4.0/camel/src/test/java/org/apache/servicemix/camel/HelloServiceImpl.java
Thu Nov 22 23:32:15 2007
@@ -0,0 +1,34 @@
+/*
+ * 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.servicemix.camel;
+
+public class HelloServiceImpl implements HelloService {
+    public String echo(String text) {        
+        System.out.println("call for echo with " + text);
+        return text + " echo";
+    }
+
+    public void ping() {
+
+    }
+
+    public String sayHello() {
+        return "hello";
+    }
+}
+

Propchange: servicemix/branches/servicemix-4.0/camel/src/test/java/org/apache/servicemix/camel/HelloServiceImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: servicemix/branches/servicemix-4.0/camel/src/test/java/org/apache/servicemix/camel/HelloServiceImpl.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: servicemix/branches/servicemix-4.0/camel/src/test/java/org/apache/servicemix/camel/SmxToCxfTest.java
URL: http://svn.apache.org/viewvc/servicemix/branches/servicemix-4.0/camel/src/test/java/org/apache/servicemix/camel/SmxToCxfTest.java?rev=597579&view=auto
==============================================================================
--- servicemix/branches/servicemix-4.0/camel/src/test/java/org/apache/servicemix/camel/SmxToCxfTest.java
(added)
+++ servicemix/branches/servicemix-4.0/camel/src/test/java/org/apache/servicemix/camel/SmxToCxfTest.java
Thu Nov 22 23:32:15 2007
@@ -0,0 +1,123 @@
+/*
+ * 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.servicemix.camel;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.impl.DefaultCamelContext;
+import org.apache.cxf.Bus;
+import org.apache.cxf.BusFactory;
+import org.apache.cxf.bus.CXFBusFactory;
+import org.apache.cxf.endpoint.ServerImpl;
+import org.apache.cxf.frontend.ClientFactoryBean;
+import org.apache.cxf.frontend.ClientProxyFactoryBean;
+import org.apache.cxf.frontend.ServerFactoryBean;
+import org.apache.servicemix.nmr.api.NMR;
+import org.apache.servicemix.nmr.core.ServiceMix;
+import org.w3c.dom.Document;
+
+
+
+public class SmxToCxfTest extends ContextTestSupport {
+    protected static final String ROUTER_ADDRESS = "http://localhost:9000/router";
+    protected static final String SERVICE_ADDRESS = "local://smx/helloworld";
+    protected static final String SERVICE_CLASS = "serviceClass=org.apache.servicemix.camel.HelloService";
+    
+    private String routerEndpointURI = "cxf://" + ROUTER_ADDRESS + "?" + SERVICE_CLASS +
"&dataFormat=POJO";
+    private String serviceEndpointURI = "cxf://" + SERVICE_ADDRESS + "?" + SERVICE_CLASS
+ "&dataFormat=POJO";
+    
+    private ServerImpl server;
+    private CamelContext camelContext;
+    private ServiceMixComponent smxComponent;
+    private NMR nmr;
+    
+    
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();        
+                
+        startService();
+    }
+    
+    protected void startService() {
+        //start a service
+        ServerFactoryBean svrBean = new ServerFactoryBean();
+
+        svrBean.setAddress(SERVICE_ADDRESS);
+        svrBean.setServiceClass(HelloService.class);
+        svrBean.setServiceBean(new HelloServiceImpl());
+        svrBean.setBus(CXFBusFactory.getDefaultBus());
+
+        server = (ServerImpl)svrBean.create();
+        server.start();
+    }
+    
+    @Override
+    protected void tearDown() throws Exception {
+        if (server != null) {
+            server.stop();
+        }
+    }
+  
+    protected RouteBuilder createRouteBuilder() {
+        return new RouteBuilder() {
+            public void configure() {
+            	from(routerEndpointURI).to("smx:testEndpoint");// like what do in binding component
+            	from("smx:testEndpoint").to(serviceEndpointURI);// like what do in se
+            }
+        };
+    }
+    
+    protected CamelContext createCamelContext() throws Exception {
+    	camelContext = new DefaultCamelContext();
+    	
+    	smxComponent = new ServiceMixComponent();
+    	nmr = new ServiceMix();
+    	((ServiceMix)nmr).init();
+    	smxComponent.setNmr(nmr);
+    	camelContext.addComponent("smx", smxComponent);
+        return camelContext;
+    }
+
+    
+    public void testInvokingServiceFromCXFClient() throws Exception {  
+        Bus bus = BusFactory.getDefaultBus();
+        
+        ClientProxyFactoryBean proxyFactory = new ClientProxyFactoryBean();
+        ClientFactoryBean clientBean = proxyFactory.getClientFactoryBean();
+        clientBean.setAddress(ROUTER_ADDRESS);        
+        clientBean.setServiceClass(HelloService.class);
+        clientBean.setBus(bus);        
+        
+        //this test works if patch for CAMEL-243 get applied
+        /*HelloService client = (HelloService) proxyFactory.create();
+        String result = client.echo("hello world");
+        assertEquals("we should get the right answer from router", "hello world echo", result);*/
+        
+                
+    }
+    
+    class PojoInvokeDispatchProcessor implements Processor {
+        public void process(Exchange exchange) throws Exception {
+            System.out.println("PojoInvokeDispatchProcessor " + exchange.getIn().getBody());
+            
+        }
+    }
+}
\ No newline at end of file

Propchange: servicemix/branches/servicemix-4.0/camel/src/test/java/org/apache/servicemix/camel/SmxToCxfTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: servicemix/branches/servicemix-4.0/camel/src/test/java/org/apache/servicemix/camel/SmxToCxfTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date



Mime
View raw message