activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jstrac...@apache.org
Subject svn commit: r522497 - in /activemq/camel/trunk: camel-core/src/main/java/org/apache/camel/ camel-core/src/main/java/org/apache/camel/component/pojo/ camel-core/src/main/java/org/apache/camel/component/queue/ camel-core/src/main/java/org/apache/camel/im...
Date Mon, 26 Mar 2007 12:31:51 GMT
Author: jstrachan
Date: Mon Mar 26 05:31:49 2007
New Revision: 522497

URL: http://svn.apache.org/viewvc?view=rev&rev=522497
Log:
got the JBI test cases working for invoking a JBI component from Camel and invoking a camel
endpoint from inside JBI; also a minor refactor to Component

Added:
    activemq/camel/trunk/camel-jbi/src/test/java/org/apache/camel/component/jbi/JbiTestSupport.java
  (with props)
    activemq/camel/trunk/camel-jbi/src/test/java/org/apache/camel/component/jbi/SendFromCamelToJbiAndBackToCamelTest.java
  (with props)
    activemq/camel/trunk/camel-jbi/src/test/java/org/apache/camel/component/jbi/SendFromCamelToJbiTest.java
  (with props)
Removed:
    activemq/camel/trunk/camel-jbi/src/test/java/org/apache/camel/component/jbi/JbiTest.java
Modified:
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/Component.java
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/pojo/PojoComponent.java
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/pojo/PojoEndpoint.java
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/pojo/PojoEndpointResolver.java
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/queue/QueueComponent.java
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/queue/QueueEndpoint.java
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultComponent.java
    activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/pojo/PojoRouteTest.java
    activemq/camel/trunk/camel-jbi/pom.xml
    activemq/camel/trunk/camel-jbi/src/main/java/org/apache/camel/component/jbi/CamelJbiComponent.java
    activemq/camel/trunk/camel-jbi/src/main/java/org/apache/camel/component/jbi/CamelJbiEndpoint.java
    activemq/camel/trunk/camel-jbi/src/main/java/org/apache/camel/component/jbi/JbiBinding.java
    activemq/camel/trunk/camel-jbi/src/main/java/org/apache/camel/component/jbi/JbiEndpoint.java

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/Component.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/Component.java?view=diff&rev=522497&r1=522496&r2=522497
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/Component.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/Component.java Mon Mar
26 05:31:49 2007
@@ -26,7 +26,7 @@
     /**
      * The {@link CamelContext} is injected into the component when it is added to it
      */
-    void setContext(CamelContext context);
+    void setCamelContext(CamelContext context);
 
 	
 }

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/pojo/PojoComponent.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/pojo/PojoComponent.java?view=diff&rev=522497&r1=522496&r2=522497
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/pojo/PojoComponent.java
(original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/pojo/PojoComponent.java
Mon Mar 26 05:31:49 2007
@@ -22,46 +22,46 @@
 import java.util.HashMap;
 
 /**
- * Represents the component that manages {@link PojoEndpoint}.  It holds the 
+ * Represents the component that manages {@link PojoEndpoint}.  It holds the
  * list of named pojos that queue endpoints reference.
  *
  * @version $Revision: 519973 $
  */
 public class PojoComponent implements Component<PojoExchange> {
-	
     protected final HashMap<String, Object> registry = new HashMap<String, Object>();
     protected final HashMap<String, PojoEndpoint> activatedEndpoints = new HashMap<String,
PojoEndpoint>();
-    
-	private CamelContext container;
+    private CamelContext container;
+
+    public void registerPojo(String uri, Object pojo) {
+        registry.put(uri, pojo);
+    }
+
+    public Object lookupRegisteredPojo(String uri) {
+        return registry.get(uri);
+    }
 
-	public void registerPojo(String uri, Object pojo) {
-		registry.put(uri, pojo);
-	}
-	public Object lookupRegisteredPojo(String uri) {
-		return registry.get(uri);
-	}
-    
     public void unregisterPojo(String uri) {
         registry.remove(uri);
         unregisterActivation(uri);
     }
-	
-	public void registerActivation(String uri, PojoEndpoint endpoint) {
-		activatedEndpoints.put(uri, endpoint);
-	}
-	public void unregisterActivation(String uri) {
-		activatedEndpoints.remove(uri);
-	}
-	public PojoEndpoint lookupActivation(String uri) {
-		return activatedEndpoints.get(uri);
-	}
-	
-	
-	public void setContext(CamelContext container) {
-		this.container = container;
-	}
-	public CamelContext getContainer() {
-		return container;
-	}
-    
+
+    public void registerActivation(String uri, PojoEndpoint endpoint) {
+        activatedEndpoints.put(uri, endpoint);
+    }
+
+    public void unregisterActivation(String uri) {
+        activatedEndpoints.remove(uri);
+    }
+
+    public PojoEndpoint lookupActivation(String uri) {
+        return activatedEndpoints.get(uri);
+    }
+
+    public void setCamelContext(CamelContext container) {
+        this.container = container;
+    }
+
+    public CamelContext getContainer() {
+        return container;
+    }
 }

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/pojo/PojoEndpoint.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/pojo/PojoEndpoint.java?view=diff&rev=522497&r1=522496&r2=522497
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/pojo/PojoEndpoint.java
(original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/pojo/PojoEndpoint.java
Mon Mar 26 05:31:49 2007
@@ -31,31 +31,33 @@
  * @version $Revision: 519973 $
  */
 public class PojoEndpoint extends DefaultEndpoint<PojoExchange> {
-
     private final Object pojo;
-	private final PojoComponent component;
-    
-	public PojoEndpoint(String uri, CamelContext container, PojoComponent component, Object
pojo) {
+    private final PojoComponent component;
+
+    public PojoEndpoint(String uri, CamelContext container, PojoComponent component, Object
pojo) {
         super(uri, container);
-		this.component = component;
-		this.pojo = pojo;
+        this.component = component;
+        this.pojo = pojo;
     }
 
-	/**
-	 *  This causes us to invoke the endpoint Pojo using reflection.
-	 */
+    /**
+     * This causes us to invoke the endpoint Pojo using reflection.
+     */
     public void onExchange(PojoExchange exchange) {
         PojoInvocation invocation = exchange.getInvocation();
         try {
-			Object response = invocation.getMethod().invoke(pojo, invocation.getArgs());
-			exchange.getOut().setBody(response);
-		} catch (InvocationTargetException e) {
-			exchange.setException(e.getCause());
-		} catch ( RuntimeException e ) {
-			throw e;
-		} catch ( Throwable e ) {
-			throw new RuntimeException(e);
-		}
+            Object response = invocation.getMethod().invoke(pojo, invocation.getArgs());
+            exchange.getOut().setBody(response);
+        }
+        catch (InvocationTargetException e) {
+            exchange.setException(e.getCause());
+        }
+        catch (RuntimeException e) {
+            throw e;
+        }
+        catch (Throwable e) {
+            throw new RuntimeException(e);
+        }
     }
 
     public PojoExchange createExchange() {
@@ -64,40 +66,36 @@
 
     @Override
     protected void doActivate() {
-    	component.registerActivation(getEndpointUri(), this);
+        component.registerActivation(getEndpointUri(), this);
     }
-    
+
     @Override
     protected void doDeactivate() {
-    	component.unregisterActivation(getEndpointUri());
+        component.unregisterActivation(getEndpointUri());
     }
 
     /**
      * Creates a Proxy object that can be used to deliver inbound PojoExchanges.
-     * 
+     *
      * @param interfaces
      * @return
      */
     public Object createInboundProxy(Class interfaces[]) {
-    	final PojoEndpoint endpoint = component.lookupActivation(getEndpointUri());
-    	if( endpoint == null ) 
-			throw new IllegalArgumentException("The endpoint has not been activated yet: "+getEndpointUri());
-    	
-    	return Proxy.newProxyInstance(pojo.getClass().getClassLoader(), interfaces, new InvocationHandler(){
-			public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
-				if( !activated.get() ) {
-					PojoInvocation invocation = new PojoInvocation(proxy, method, args);
-					PojoExchange exchange = createExchange();
-					exchange.setInvocation(invocation);
-					endpoint.getInboundProcessor().onExchange(exchange);
-					Throwable fault = exchange.getException();
-					if ( fault != null ) {
-						throw new InvocationTargetException(fault);
-					}
-					return exchange.getOut().getBody();
-				}
-				throw new IllegalStateException("The endpoint is not active: "+getEndpointUri());
-			}
-		});
+        return Proxy.newProxyInstance(pojo.getClass().getClassLoader(), interfaces, new InvocationHandler()
{
+            public Object invoke(Object proxy, Method method, Object[] args) throws Throwable
{
+                if (!activated.get()) {
+                    throw new IllegalStateException("The endpoint is not active: " + getEndpointUri());
+                }
+                PojoInvocation invocation = new PojoInvocation(proxy, method, args);
+                PojoExchange exchange = createExchange();
+                exchange.setInvocation(invocation);
+                getInboundProcessor().onExchange(exchange);
+                Throwable fault = exchange.getException();
+                if (fault != null) {
+                    throw new InvocationTargetException(fault);
+                }
+                return exchange.getOut().getBody();
+            }
+        });
     }
 }

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/pojo/PojoEndpointResolver.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/pojo/PojoEndpointResolver.java?view=diff&rev=522497&r1=522496&r2=522497
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/pojo/PojoEndpointResolver.java
(original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/pojo/PojoEndpointResolver.java
Mon Mar 26 05:31:49 2007
@@ -41,7 +41,7 @@
 	 */
 	public Component resolveComponent(CamelContext container, String uri) {
 		String id[] = getEndpointId(uri);        
-		return resolveQueueComponent(container, id[0]);
+		return resolvePojoComponent(container, id[0]);
 	}
 
 	/**
@@ -52,12 +52,12 @@
 	 */
 	public PojoEndpoint resolveEndpoint(CamelContext container, String uri) {
 		String id[] = getEndpointId(uri);        
-    	PojoComponent component = resolveQueueComponent(container, id[0]);        
+    	PojoComponent component = resolvePojoComponent(container, id[0]);
         Object pojo = component.lookupRegisteredPojo(id[1]);
 		return new PojoEndpoint(uri, container, component, pojo);
     }
 
-	private PojoComponent resolveQueueComponent(CamelContext container, String componentName)
{
+	private PojoComponent resolvePojoComponent(CamelContext container, String componentName)
{
     	Component rc = container.getComponent(componentName);
     	if( rc == null ) {
     		throw new IllegalArgumentException("Invalid URI, pojo component does not exist: "+componentName);

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/queue/QueueComponent.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/queue/QueueComponent.java?view=diff&rev=522497&r1=522496&r2=522497
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/queue/QueueComponent.java
(original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/queue/QueueComponent.java
Mon Mar 26 05:31:49 2007
@@ -35,7 +35,7 @@
     private HashMap<String, BlockingQueue<E>> registry = new HashMap<String,
BlockingQueue<E>>();
     private CamelContext container;
 
-    public void setContext(CamelContext container) {
+    public void setCamelContext(CamelContext container) {
         this.container = container;
     }
 

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/queue/QueueEndpoint.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/queue/QueueEndpoint.java?view=diff&rev=522497&r1=522496&r2=522497
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/queue/QueueEndpoint.java
(original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/queue/QueueEndpoint.java
Mon Mar 26 05:31:49 2007
@@ -58,7 +58,7 @@
         return (E) new DefaultExchange(getContext());
     }
 
-    public Queue<E> getQueue() {
+    public BlockingQueue<E> getQueue() {
         return queue;
     }
     

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java?view=diff&rev=522497&r1=522496&r2=522497
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
(original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
Mon Mar 26 05:31:49 2007
@@ -51,7 +51,7 @@
             if (components.containsKey(componentName)) {
                 throw new IllegalArgumentException("Component previously added: " + componentName);
             }
-            component.setContext(this);
+            component.setCamelContext(this);
             components.put(componentName, component);
             if (component instanceof EndpointResolver) {
                 resolvers.add((EndpointResolver) component);
@@ -95,7 +95,7 @@
                         throw new IllegalArgumentException("Factory failed to create the
" + componentName + " component, it returned null.");
                     }
                     components.put(componentName, component);
-                    component.setContext(this);
+                    component.setCamelContext(this);
                 }
                 catch (Exception e) {
                     throw new IllegalArgumentException("Factory failed to create the " +
componentName + " component", e);
@@ -134,8 +134,7 @@
                         answer = er.resolveEndpoint(this, uri);
                     }
                     if (answer != null) {
-                        // TODO temporarily disabled caching due to POJO test failure
-                        // endpoints.put(uri, answer);
+                        endpoints.put(uri, answer);
                     }
                 }
                 catch (Exception e) {

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultComponent.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultComponent.java?view=diff&rev=522497&r1=522496&r2=522497
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultComponent.java
(original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultComponent.java
Mon Mar 26 05:31:49 2007
@@ -38,7 +38,7 @@
         return context;
     }
 
-    public void setContext(CamelContext context) {
+    public void setCamelContext(CamelContext context) {
         this.context = context;
     }
 }

Modified: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/pojo/PojoRouteTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/pojo/PojoRouteTest.java?view=diff&rev=522497&r1=522496&r2=522497
==============================================================================
--- activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/pojo/PojoRouteTest.java
(original)
+++ activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/pojo/PojoRouteTest.java
Mon Mar 26 05:31:49 2007
@@ -31,7 +31,7 @@
  */
 public class PojoRouteTest extends TestCase {
 	
-    public void testJmsRoute() throws Exception {
+    public void testPojoRoutes() throws Exception {
 
         CamelContext container = new DefaultCamelContext();
         
@@ -71,8 +71,9 @@
 			proxy = (ISay) endpoint.createInboundProxy(new Class[]{ISay.class});
 			rc = proxy.say();
 			assertEquals("Hello!", rc);
-			
-		} catch (IllegalArgumentException expected) {
+            fail("Should have thrown an exception as we are using an inactive endpoint");
+
+        } catch (IllegalStateException expected) {
 			// since bye is not active.
 		}
 

Modified: activemq/camel/trunk/camel-jbi/pom.xml
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-jbi/pom.xml?view=diff&rev=522497&r1=522496&r2=522497
==============================================================================
--- activemq/camel/trunk/camel-jbi/pom.xml (original)
+++ activemq/camel/trunk/camel-jbi/pom.xml Mon Mar 26 05:31:49 2007
@@ -38,6 +38,13 @@
       <groupId>org.apache.camel</groupId>
       <artifactId>camel-core</artifactId>
     </dependency>
+    <dependency>
+      <groupId>org.apache.camel</groupId>
+      <artifactId>camel-core</artifactId>
+      <type>test-jar</type>
+      <optional>true</optional>
+      <scope>test</scope>
+    </dependency>
 
     <dependency>
       <groupId>org.apache.servicemix</groupId>

Modified: activemq/camel/trunk/camel-jbi/src/main/java/org/apache/camel/component/jbi/CamelJbiComponent.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-jbi/src/main/java/org/apache/camel/component/jbi/CamelJbiComponent.java?view=diff&rev=522497&r1=522496&r2=522497
==============================================================================
--- activemq/camel/trunk/camel-jbi/src/main/java/org/apache/camel/component/jbi/CamelJbiComponent.java
(original)
+++ activemq/camel/trunk/camel-jbi/src/main/java/org/apache/camel/component/jbi/CamelJbiComponent.java
Mon Mar 26 05:31:49 2007
@@ -17,9 +17,15 @@
 import org.apache.camel.Endpoint;
 import org.apache.camel.EndpointResolver;
 import org.apache.servicemix.common.DefaultComponent;
+import org.apache.servicemix.jbi.util.URISupport;
+import org.apache.servicemix.jbi.util.IntrospectionSupport;
 
+import javax.jbi.servicedesc.ServiceEndpoint;
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Map;
+import java.net.URISyntaxException;
+import java.net.URI;
 
 /**
  * Deploys the camel endpoints within JBI
@@ -28,7 +34,7 @@
  */
 public class CamelJbiComponent extends DefaultComponent implements Component<JbiExchange>,
EndpointResolver {
     private JbiBinding binding;
-    private CamelContext context;
+    private CamelContext camelContext;
 
     /**
      * @return List of endpoints
@@ -72,6 +78,38 @@
         this.binding = binding;
     }
 
+
+    @Override
+    protected String[] getEPRProtocols() {
+        return new String[] { "camel" };
+    }
+
+    protected org.apache.servicemix.common.Endpoint getResolvedEPR(ServiceEndpoint ep) throws
Exception {
+        CamelJbiEndpoint endpoint = createEndpoint(ep);
+        endpoint.activate();
+        return endpoint;
+    }
+
+
+    /**
+     * A factory method for creating endpoints from a service endpoint
+     * which is public so that it can be easily unit tested
+     */
+    public CamelJbiEndpoint createEndpoint(ServiceEndpoint ep) throws URISyntaxException
{
+        URI uri = new URI(ep.getEndpointName());
+        Map map = URISupport.parseQuery(uri.getQuery());
+        String camelUri = uri.getSchemeSpecificPart();
+        Endpoint camelEndpoint = getCamelContext().resolveEndpoint(camelUri);
+        CamelJbiEndpoint endpoint = new CamelJbiEndpoint(getServiceUnit(), camelEndpoint,
getBinding());
+
+        IntrospectionSupport.setProperties(endpoint, map);
+
+        // TODO
+        //endpoint.setRole(MessageExchange.Role.PROVIDER);
+
+        return endpoint;
+    }
+
     // Resolve Camel Endpoints
     //-------------------------------------------------------------------------
     public Component resolveComponent(CamelContext context, String uri) throws Exception
{
@@ -85,14 +123,19 @@
 
             // lets expose this endpoint now in JBI
             // TODO there could already be a component registered in JBI for this??
-            CamelJbiEndpoint jbiEndpoint = new CamelJbiEndpoint(camelEndpoint, getBinding());
+            CamelJbiEndpoint jbiEndpoint = new CamelJbiEndpoint(getServiceUnit(), camelEndpoint,
getBinding());
             addEndpoint(jbiEndpoint);
+            jbiEndpoint.activate();
             return camelEndpoint;
         }
         return null;
     }
 
-    public void setContext(CamelContext context) {
-        this.context = context;
+    public CamelContext getCamelContext() {
+        return camelContext;
+    }
+
+    public void setCamelContext(CamelContext camelContext) {
+        this.camelContext = camelContext;
     }
 }

Modified: activemq/camel/trunk/camel-jbi/src/main/java/org/apache/camel/component/jbi/CamelJbiEndpoint.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-jbi/src/main/java/org/apache/camel/component/jbi/CamelJbiEndpoint.java?view=diff&rev=522497&r1=522496&r2=522497
==============================================================================
--- activemq/camel/trunk/camel-jbi/src/main/java/org/apache/camel/component/jbi/CamelJbiEndpoint.java
(original)
+++ activemq/camel/trunk/camel-jbi/src/main/java/org/apache/camel/component/jbi/CamelJbiEndpoint.java
Mon Mar 26 05:31:49 2007
@@ -10,39 +10,54 @@
  * 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.jbi;
 
+import org.apache.servicemix.common.ServiceUnit;
+import org.apache.servicemix.common.endpoints.ProviderEndpoint;
+import org.apache.camel.Endpoint;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
 import javax.jbi.messaging.MessageExchange;
 import javax.jbi.messaging.NormalizedMessage;
 import javax.xml.namespace.QName;
-import org.apache.servicemix.common.endpoints.ProviderEndpoint;
 
 /**
- * The endpoint in the service engine
- * 
+ * A JBI endpoint which when invoked will delegate to a Camel endpoint
+ *
  * @version $Revision: 426415 $
  */
 public class CamelJbiEndpoint extends ProviderEndpoint {
+    private static final transient Log log = LogFactory.getLog(CamelJbiEndpoint.class);
 
-    private static final QName SERVICE_NAME=new QName("http://camel.servicemix.org","CamelEndpointComponent");
-    private JbiEndpoint jbiEndpoint;
+    private static final QName SERVICE_NAME = new QName("http://camel.apache.org/service",
"CamelEndpointComponent");
+    private Endpoint camelEndpoint;
     private JbiBinding binding;
 
-    public CamelJbiEndpoint(JbiEndpoint jbiEndpoint, JbiBinding binding){
-        this.jbiEndpoint=jbiEndpoint;
-        this.binding=binding;
-        this.service=SERVICE_NAME;
-        this.endpoint=jbiEndpoint.getEndpointUri();
+    public CamelJbiEndpoint(ServiceUnit serviceUnit, QName service, String endpoint, JbiBinding
binding) {
+        super(serviceUnit, service, endpoint);
+        this.binding = binding;
+    }
+
+    public CamelJbiEndpoint(ServiceUnit serviceUnit, Endpoint camelEndpoint, JbiBinding binding)
{
+        super(serviceUnit, SERVICE_NAME, camelEndpoint.getEndpointUri());
+        this.camelEndpoint = camelEndpoint;
+        this.binding = binding;
     }
 
-    protected void processInOnly(MessageExchange exchange,NormalizedMessage in) throws Exception{
+    protected void processInOnly(MessageExchange exchange, NormalizedMessage in) throws Exception
{
+        if (log.isDebugEnabled()) {
+            log.debug("Received exchange: " + exchange);
+        }
         // lets use the inbound processor to handle the exchange
-        JbiExchange camelExchange = new JbiExchange(jbiEndpoint.getContext(), binding, exchange);
-        jbiEndpoint.getInboundProcessor().onExchange(camelExchange);
+        JbiExchange camelExchange = new JbiExchange(camelEndpoint.getContext(), binding,
exchange);
+        camelEndpoint.onExchange(camelExchange);
     }
 
-    protected void processInOut(MessageExchange exchange,NormalizedMessage in,NormalizedMessage
out) throws Exception{
+    protected void processInOut(MessageExchange exchange, NormalizedMessage in, NormalizedMessage
out) throws Exception {
+        if (log.isDebugEnabled()) {
+            log.debug("Received exchange: " + exchange);
+        }
         /*
          * ToDo
          */

Modified: activemq/camel/trunk/camel-jbi/src/main/java/org/apache/camel/component/jbi/JbiBinding.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-jbi/src/main/java/org/apache/camel/component/jbi/JbiBinding.java?view=diff&rev=522497&r1=522496&r2=522497
==============================================================================
--- activemq/camel/trunk/camel-jbi/src/main/java/org/apache/camel/component/jbi/JbiBinding.java
(original)
+++ activemq/camel/trunk/camel-jbi/src/main/java/org/apache/camel/component/jbi/JbiBinding.java
Mon Mar 26 05:31:49 2007
@@ -44,18 +44,6 @@
         return normalizedMessage.getContent();
     }
 
-    /**
-     * Creates a JBI {@link MessageExchange} from the given Camel {@link Exchange}
-     *
-     */
-    public MessageExchange makeJbiMessageExchange(Exchange camelExchange, Destination jbiDestination)
throws MessagingException {
-        MessageExchange jbiExchange = createJbiMessageExchange(camelExchange, jbiDestination);
-        NormalizedMessage normalizedMessage = jbiExchange.getMessage("in");
-        normalizedMessage.setContent(getJbiInContent(camelExchange));
-        addJbiHeaders(jbiExchange, normalizedMessage, camelExchange);
-        return jbiExchange;
-    }
-
     public MessageExchange makeJbiMessageExchange(Exchange camelExchange, MessageExchangeFactory
exchangeFactory) throws MessagingException {
         MessageExchange jbiExchange = createJbiMessageExchange(camelExchange, exchangeFactory);
         NormalizedMessage normalizedMessage = jbiExchange.getMessage("in");
@@ -68,13 +56,25 @@
         return jbiExchange;
     }
 
+    /**
+     * Creates a JBI {@link MessageExchange} from the given Camel {@link Exchange}
+     *
+     */
+    public MessageExchange makeJbiMessageExchange(Exchange camelExchange, Destination jbiDestination)
throws MessagingException {
+        MessageExchange jbiExchange = createJbiMessageExchange(camelExchange, jbiDestination);
+        NormalizedMessage normalizedMessage = jbiExchange.getMessage("in");
+        normalizedMessage.setContent(getJbiInContent(camelExchange));
+        addJbiHeaders(jbiExchange, normalizedMessage, camelExchange);
+        return jbiExchange;
+    }
+
     protected MessageExchange createJbiMessageExchange(Exchange camelExchange, MessageExchangeFactory
exchangeFactory) throws MessagingException {
-        // TODO we should deal with other forms of MEM
+        // TODO we should deal with other forms of MEP
         return exchangeFactory.createInOnlyExchange();
     }
 
     protected MessageExchange createJbiMessageExchange(Exchange camelExchange, Destination
jbiDestination) throws MessagingException {
-        // TODO we should deal with other forms of MEM
+        // TODO we should deal with other forms of MEP
         return jbiDestination.createInOnlyExchange();
     }
 

Modified: activemq/camel/trunk/camel-jbi/src/main/java/org/apache/camel/component/jbi/JbiEndpoint.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-jbi/src/main/java/org/apache/camel/component/jbi/JbiEndpoint.java?view=diff&rev=522497&r1=522496&r2=522497
==============================================================================
--- activemq/camel/trunk/camel-jbi/src/main/java/org/apache/camel/component/jbi/JbiEndpoint.java
(original)
+++ activemq/camel/trunk/camel-jbi/src/main/java/org/apache/camel/component/jbi/JbiEndpoint.java
Mon Mar 26 05:31:49 2007
@@ -53,6 +53,9 @@
     @Override
     protected void doActivate() throws Exception {
         super.doActivate();
+
+        // TODO once the inbound is activated we need to register a JBI endpoint
+        
     }
 
     public JbiExchange createExchange() {

Added: activemq/camel/trunk/camel-jbi/src/test/java/org/apache/camel/component/jbi/JbiTestSupport.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-jbi/src/test/java/org/apache/camel/component/jbi/JbiTestSupport.java?view=auto&rev=522497
==============================================================================
--- activemq/camel/trunk/camel-jbi/src/test/java/org/apache/camel/component/jbi/JbiTestSupport.java
(added)
+++ activemq/camel/trunk/camel-jbi/src/test/java/org/apache/camel/component/jbi/JbiTestSupport.java
Mon Mar 26 05:31:49 2007
@@ -0,0 +1,109 @@
+/**
+ *
+ * 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.jbi;
+
+import org.apache.camel.TestSupport;
+import org.apache.camel.Exchange;
+import org.apache.camel.Message;
+import org.apache.camel.CamelContext;
+import org.apache.camel.Endpoint;
+import org.apache.camel.impl.DefaultCamelContext;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.servicemix.jbi.container.ActivationSpec;
+import org.apache.servicemix.jbi.container.SpringJBIContainer;
+
+import javax.xml.namespace.QName;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.CountDownLatch;
+import java.util.List;
+import java.util.ArrayList;
+
+/**
+ * @version $Revision$
+ */
+public abstract class JbiTestSupport extends TestSupport {
+    protected Exchange receivedExchange;
+    protected CamelContext camelContext = new DefaultCamelContext();
+    protected SpringJBIContainer jbiContainer = new SpringJBIContainer();
+    protected CountDownLatch latch = new CountDownLatch(1);
+    protected Endpoint<Exchange> endpoint;
+    protected String startEndpointUri = "jbi:service:serviceNamespace:serviceA";
+
+    /**
+     * Sends an exchange to the endpoint
+     */
+    protected void sendExchange(Object expectedBody) {
+        // now lets fire in a message
+        Exchange exchange = endpoint.createExchange();
+        Message in = exchange.getIn();
+        in.setBody(expectedBody);
+        in.setHeader("cheese", 123);
+        endpoint.onExchange(exchange);
+    }
+
+    protected Object assertReceivedValidExchange(Class type) throws Exception {
+        // lets wait on the message being received
+        boolean received = latch.await(5, TimeUnit.SECONDS);
+        assertTrue("Did not recieve the message!", received);
+
+        assertNotNull(receivedExchange);
+        Message receivedMessage = receivedExchange.getIn();
+
+        assertEquals("cheese header", 123, receivedMessage.getHeader("cheese"));
+        Object body = receivedMessage.getBody();
+        log.debug("Received body: " + body);
+        return body;
+    }
+
+    @Override
+    protected void setUp() throws Exception {
+        jbiContainer.setEmbedded(true);
+
+        CamelJbiComponent component = new CamelJbiComponent();
+
+        List<ActivationSpec> activationSpecList = new ArrayList<ActivationSpec>();
+
+        // lets add the Camel endpoint
+        ActivationSpec activationSpec = new ActivationSpec();
+        activationSpec.setId("camel");
+        activationSpec.setService(new QName("camel", "camel"));
+        activationSpec.setEndpoint("camelEndpoint");
+        activationSpec.setComponent(component);
+        activationSpecList.add(activationSpec);
+
+        appendJbiActivationSpecs(activationSpecList);
+
+        ActivationSpec[] activationSpecs = activationSpecList.toArray(new ActivationSpec[activationSpecList.size()]);
+        jbiContainer.setActivationSpecs(activationSpecs);
+        jbiContainer.afterPropertiesSet();
+
+        // lets configure some componnets
+        camelContext.addComponent("jbi", component);
+
+        // lets add some routes
+        camelContext.setRoutes(createRoutes());
+        endpoint = camelContext.resolveEndpoint(startEndpointUri);
+        assertNotNull("No endpoint found!", endpoint);
+
+        camelContext.activateEndpoints();
+    }
+
+    protected abstract  void appendJbiActivationSpecs(List<ActivationSpec> activationSpecList);
+
+    protected abstract RouteBuilder createRoutes();
+}

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

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

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

Added: activemq/camel/trunk/camel-jbi/src/test/java/org/apache/camel/component/jbi/SendFromCamelToJbiAndBackToCamelTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-jbi/src/test/java/org/apache/camel/component/jbi/SendFromCamelToJbiAndBackToCamelTest.java?view=auto&rev=522497
==============================================================================
--- activemq/camel/trunk/camel-jbi/src/test/java/org/apache/camel/component/jbi/SendFromCamelToJbiAndBackToCamelTest.java
(added)
+++ activemq/camel/trunk/camel-jbi/src/test/java/org/apache/camel/component/jbi/SendFromCamelToJbiAndBackToCamelTest.java
Mon Mar 26 05:31:49 2007
@@ -0,0 +1,83 @@
+/**
+ *
+ * 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.jbi;
+
+import org.apache.servicemix.tck.ReceiverComponent;
+import org.apache.servicemix.tck.MessageList;
+import org.apache.servicemix.tck.SenderComponent;
+import org.apache.servicemix.jbi.container.ActivationSpec;
+import org.apache.servicemix.jbi.resolver.ServiceNameEndpointResolver;
+import org.apache.servicemix.jbi.resolver.URIResolver;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.queue.QueueEndpoint;
+import org.apache.camel.Exchange;
+
+import javax.jbi.messaging.NormalizedMessage;
+import javax.xml.namespace.QName;
+import java.util.List;
+import java.util.Queue;
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * @version $Revision$
+ */
+public class SendFromCamelToJbiAndBackToCamelTest extends JbiTestSupport {
+    protected SenderComponent senderComponent = new SenderComponent();
+
+    public void testCamelInvokingJbi() throws Exception {
+        senderComponent.sendMessages(1);
+
+        QueueEndpoint receiverEndpoint = (QueueEndpoint) camelContext.resolveEndpoint("queue:receiver");
+
+        BlockingQueue<Exchange> queue = receiverEndpoint.getQueue();
+        Exchange exchange = queue.poll(5, TimeUnit.SECONDS);
+
+        assertNotNull("Camel Receiver queue should have received an exchange by now", exchange);
+
+        log.debug("Receiver got exchange: " + exchange + " with body: " + exchange.getIn().getBody());
+    }
+
+    protected RouteBuilder createRoutes() {
+        return new RouteBuilder() {
+            public void configure() {
+                // no routes required
+            }
+        };
+    }
+
+    protected void appendJbiActivationSpecs(List<ActivationSpec> activationSpecList)
{
+        this.startEndpointUri = "queue:receiver";
+
+        ActivationSpec activationSpec = new ActivationSpec();
+        activationSpec.setId("jbiSender");
+        activationSpec.setService(new QName("serviceNamespace", "serviceA"));
+        activationSpec.setEndpoint("endpointA");
+
+        // lets setup the sender to talk directly to camel
+        senderComponent.setResolver(new URIResolver("camel:queue:receiver"));
+        activationSpec.setComponent(senderComponent);
+
+        activationSpecList.add(activationSpec);
+    }
+
+    @Override
+    protected void tearDown() throws Exception {
+        camelContext.deactivateEndpoints();
+    }
+}

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

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

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

Added: activemq/camel/trunk/camel-jbi/src/test/java/org/apache/camel/component/jbi/SendFromCamelToJbiTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-jbi/src/test/java/org/apache/camel/component/jbi/SendFromCamelToJbiTest.java?view=auto&rev=522497
==============================================================================
--- activemq/camel/trunk/camel-jbi/src/test/java/org/apache/camel/component/jbi/SendFromCamelToJbiTest.java
(added)
+++ activemq/camel/trunk/camel-jbi/src/test/java/org/apache/camel/component/jbi/SendFromCamelToJbiTest.java
Mon Mar 26 05:31:49 2007
@@ -0,0 +1,74 @@
+/**
+ *
+ * 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.jbi;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.servicemix.jbi.container.ActivationSpec;
+import org.apache.servicemix.components.util.EchoComponent;
+import org.apache.servicemix.tck.ReceiverComponent;
+import org.apache.servicemix.tck.MessageList;
+
+import javax.xml.namespace.QName;
+import javax.jbi.messaging.NormalizedMessage;
+import java.util.List;
+
+/**
+ * @version $Revision$
+ */
+public class SendFromCamelToJbiTest extends JbiTestSupport {
+    private ReceiverComponent receiverComponent = new ReceiverComponent();
+
+    public void testCamelInvokingJbi() throws Exception {
+        sendExchange("<foo bar='123'/>");
+        MessageList list = receiverComponent.getMessageList();
+
+        list.assertMessagesReceived(1);
+        List messages = list.getMessages();
+        NormalizedMessage message = (NormalizedMessage) messages.get(0);
+        assertNotNull("null message!", message);
+        log.info("Received: " + message);
+
+        assertEquals("cheese header", 123, message.getProperty("cheese"));
+
+    }
+
+    protected RouteBuilder createRoutes() {
+        return new RouteBuilder() {
+            public void configure() {
+                // no routes required
+            }
+        };
+    }
+
+    protected void appendJbiActivationSpecs(List<ActivationSpec> activationSpecList)
{
+        ActivationSpec activationSpec = new ActivationSpec();
+        activationSpec.setId("jbiReceiver");
+        activationSpec.setService(new QName("serviceNamespace", "serviceA"));
+        activationSpec.setEndpoint("endpointA");
+        activationSpec.setComponent(receiverComponent);
+
+        activationSpecList.add(activationSpec);
+    }
+
+    @Override
+    protected void tearDown() throws Exception {
+        camelContext.deactivateEndpoints();
+    }
+}

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

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

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



Mime
View raw message