Return-Path: Delivered-To: apmail-activemq-commits-archive@www.apache.org Received: (qmail 48205 invoked from network); 23 Mar 2007 17:59:03 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 23 Mar 2007 17:59:03 -0000 Received: (qmail 97031 invoked by uid 500); 23 Mar 2007 17:59:08 -0000 Delivered-To: apmail-activemq-commits-archive@activemq.apache.org Received: (qmail 97011 invoked by uid 500); 23 Mar 2007 17:59:08 -0000 Mailing-List: contact commits-help@activemq.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@activemq.apache.org Delivered-To: mailing list commits@activemq.apache.org Received: (qmail 96989 invoked by uid 99); 23 Mar 2007 17:59:08 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 23 Mar 2007 10:59:08 -0700 X-ASF-Spam-Status: No, hits=-99.5 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 23 Mar 2007 10:58:58 -0700 Received: by eris.apache.org (Postfix, from userid 65534) id 20D761A9838; Fri, 23 Mar 2007 10:58:38 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r521831 - in /activemq/camel/trunk: camel-core/src/main/java/org/apache/camel/ camel-core/src/main/java/org/apache/camel/impl/ camel-jbi/ camel-jbi/src/main/java/org/apache/camel/component/jbi/ camel-jbi/src/test/java/org/apache/camel/compo... Date: Fri, 23 Mar 2007 17:58:37 -0000 To: commits@activemq.apache.org From: jstrachan@apache.org X-Mailer: svnmailer-1.1.0 Message-Id: <20070323175838.20D761A9838@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: jstrachan Date: Fri Mar 23 10:58:36 2007 New Revision: 521831 URL: http://svn.apache.org/viewvc?view=rev&rev=521831 Log: a very rough first cut at a Camel <-> JBI bridge Added: activemq/camel/trunk/camel-jbi/src/main/java/org/apache/camel/component/jbi/FromJbiProcessor.java (with props) activemq/camel/trunk/camel-jbi/src/main/java/org/apache/camel/component/jbi/JbiException.java (with props) activemq/camel/trunk/camel-jbi/src/main/java/org/apache/camel/component/jbi/ToJbiProcessor.java (with props) activemq/camel/trunk/camel-jbi/src/main/java/org/apache/camel/component/jbi/ToJbiProcessor2.java (with props) activemq/camel/trunk/camel-jbi/src/test/java/org/apache/camel/component/jbi/JbiTest.java (with props) Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/CamelContext.java activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.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/CamelContext.java URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/CamelContext.java?view=diff&rev=521831&r1=521830&r2=521831 ============================================================================== --- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/CamelContext.java (original) +++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/CamelContext.java Fri Mar 23 10:58:36 2007 @@ -21,6 +21,7 @@ import java.util.List; import java.util.Map; +import java.util.Collection; import java.util.concurrent.Callable; /** @@ -76,6 +77,12 @@ */ public void deactivateEndpoints() ; + + /** + * Returns the collection of all active endpoints currently registered + */ + Collection getEndpoints(); + // Route Management Methods //----------------------------------------------------------------------- public List getRoutes() ; @@ -95,6 +102,5 @@ public ExchangeConverter getExchangeConverter(); public TypeConverter getTypeConverter(); - } 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=521831&r1=521830&r2=521831 ============================================================================== --- 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 Fri Mar 23 10:58:36 2007 @@ -17,26 +17,16 @@ */ package org.apache.camel.impl; +import org.apache.camel.*; +import org.apache.camel.builder.RouteBuilder; + import java.util.ArrayList; import java.util.HashMap; -import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import java.util.Collection; import java.util.concurrent.Callable; -import org.apache.camel.CamelContext; -import org.apache.camel.Component; -import org.apache.camel.Endpoint; -import org.apache.camel.EndpointResolver; -import org.apache.camel.Exchange; -import org.apache.camel.ExchangeConverter; -import org.apache.camel.Processor; -import org.apache.camel.ResolveEndpointFailedException; -import org.apache.camel.Route; -import org.apache.camel.RouteFactory; -import org.apache.camel.TypeConverter; -import org.apache.camel.builder.RouteBuilder; - /** * Represents the context used to configure routes and the policies to use. * @@ -44,11 +34,12 @@ * @org.apache.xbean.XBean element="container" rootElement="true" */ public class DefaultCamelContext implements CamelContext { - private EndpointResolver endpointResolver; - private ExchangeConverter exchangeConverter; + private Map endpoints = new HashMap(); private Map components = new HashMap(); private List routes; private TypeConverter typeConverter; + private EndpointResolver endpointResolver; + private ExchangeConverter exchangeConverter; /** * Adds a component to the container. @@ -112,33 +103,46 @@ // Endpoint Management Methods //----------------------------------------------------------------------- + public Collection getEndpoints() { + synchronized (endpoints) { + return new ArrayList(endpoints.values()); + } + } + /** * Resolves the given URI to an endpoint */ public Endpoint resolveEndpoint(String uri) { - EndpointResolver er = getEndpointResolver(); - try { - return er.resolveEndpoint(this, uri); - } - catch (Exception e) { - throw new ResolveEndpointFailedException(uri, e); + Endpoint answer; + synchronized (endpoints) { + answer = endpoints.get(uri); + } + if (answer == null) { + EndpointResolver er = getEndpointResolver(); + try { + answer = er.resolveEndpoint(this, uri); + } + catch (Exception e) { + throw new ResolveEndpointFailedException(uri, e); + } } + return answer; } /** * Activates all the starting endpoints in that were added as routes. */ public void activateEndpoints() throws Exception { - for (Route route : routes) { + for (Route route : routes) { route.getEndpoint().activate(route.getProcessor()); - } + } } /** * Deactivates all the starting endpoints in that were added as routes. */ public void deactivateEndpoints() { - for (Route route : routes) { + for (Route route : routes) { route.getEndpoint().deactivate(); } } @@ -169,11 +173,12 @@ } public void addRoutes(List routes) { - if( this.routes == null ) { - this.routes = new ArrayList(routes); - } else { - this.routes.addAll(routes); - } + if (this.routes == null) { + this.routes = new ArrayList(routes); + } + else { + this.routes.addAll(routes); + } } public void addRoutes(RouteBuilder builder) { Modified: activemq/camel/trunk/camel-jbi/pom.xml URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-jbi/pom.xml?view=diff&rev=521831&r1=521830&r2=521831 ============================================================================== --- activemq/camel/trunk/camel-jbi/pom.xml (original) +++ activemq/camel/trunk/camel-jbi/pom.xml Fri Mar 23 10:58:36 2007 @@ -71,4 +71,22 @@ + + + + maven-surefire-plugin + + false + true + + **/*Test.* + + + + **/JbiTest.* + + + + + 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=521831&r1=521830&r2=521831 ============================================================================== --- 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 Fri Mar 23 10:58:36 2007 @@ -3,70 +3,96 @@ * 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 java.util.List; +import org.apache.camel.CamelContext; +import org.apache.camel.Component; +import org.apache.camel.Endpoint; +import org.apache.camel.EndpointResolver; import org.apache.servicemix.common.DefaultComponent; +import java.util.ArrayList; +import java.util.List; + /** * Deploys the camel endpoints within JBI - * + * * @version $Revision: 426415 $ */ -public class CamelJbiComponent extends DefaultComponent{ - - private CamelJbiEndpoint[] endpoints; +public class CamelJbiComponent extends DefaultComponent implements Component, EndpointResolver { private JbiBinding binding; - - /** - * @return the endpoints - */ - public CamelJbiEndpoint[] getEndpoints(){ - return this.endpoints; - } - - /** - * @param endpoints the endpoints to set - */ - public void setEndpoints(CamelJbiEndpoint[] endpoints){ - this.endpoints=endpoints; - } + private CamelContext context; /** * @return List of endpoints * @see org.apache.servicemix.common.DefaultComponent#getConfiguredEndpoints() */ - @Override protected List getConfiguredEndpoints(){ - return asList(getEndpoints()); + @Override + protected List getConfiguredEndpoints() { + // TODO need to register to the context for new endpoints... + List answer = new ArrayList(); +// Collection endpoints = camelContext.getEndpoints(); +// for (Endpoint endpoint : endpoints) { +// answer.add(createJbiEndpoint(endpoint)); +// } + return answer; } + /** * @return Class[] * @see org.apache.servicemix.common.DefaultComponent#getEndpointClasses() */ - @Override protected Class[] getEndpointClasses(){ - return new Class[] { CamelJbiEndpoint.class }; + @Override + protected Class[] getEndpointClasses() { + return new Class[]{CamelJbiEndpoint.class}; } /** * @return the binding */ - public JbiBinding getBinding(){ - return this.binding; + public JbiBinding getBinding() { + if (binding == null) { + binding = new JbiBinding(); + } + return binding; } /** * @param binding the binding to set */ - public void setBinding(JbiBinding binding){ - this.binding=binding; + public void setBinding(JbiBinding binding) { + this.binding = binding; + } + + // Resolve Camel Endpoints + //------------------------------------------------------------------------- + public Component resolveComponent(CamelContext context, String uri) throws Exception { + return null; + } + + public Endpoint resolveEndpoint(CamelContext context, String uri) throws Exception { + if (uri.startsWith("jbi:")) { + uri = uri.substring("jbi:".length()); + JbiEndpoint camelEndpoint = new JbiEndpoint(uri, context, getComponentContext(), getBinding()); + + // 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()); + addEndpoint(jbiEndpoint); + return camelEndpoint; + } + return null; + } + + public void setContext(CamelContext context) { + this.context = context; } } 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=521831&r1=521830&r2=521831 ============================================================================== --- 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 Fri Mar 23 10:58:36 2007 @@ -23,7 +23,7 @@ * * @version $Revision: 426415 $ */ -public class CamelJbiEndpoint extends ProviderEndpoint{ +public class CamelJbiEndpoint extends ProviderEndpoint { private static final QName SERVICE_NAME=new QName("http://camel.servicemix.org","CamelEndpointComponent"); private JbiEndpoint jbiEndpoint; @@ -37,7 +37,9 @@ } protected void processInOnly(MessageExchange exchange,NormalizedMessage in) throws Exception{ - jbiEndpoint.onExchange(new JbiExchange(jbiEndpoint.getContext(), binding, exchange)); + // lets use the inbound processor to handle the exchange + JbiExchange camelExchange = new JbiExchange(jbiEndpoint.getContext(), binding, exchange); + jbiEndpoint.getInboundProcessor().onExchange(camelExchange); } protected void processInOut(MessageExchange exchange,NormalizedMessage in,NormalizedMessage out) throws Exception{ Added: activemq/camel/trunk/camel-jbi/src/main/java/org/apache/camel/component/jbi/FromJbiProcessor.java URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-jbi/src/main/java/org/apache/camel/component/jbi/FromJbiProcessor.java?view=auto&rev=521831 ============================================================================== --- activemq/camel/trunk/camel-jbi/src/main/java/org/apache/camel/component/jbi/FromJbiProcessor.java (added) +++ activemq/camel/trunk/camel-jbi/src/main/java/org/apache/camel/component/jbi/FromJbiProcessor.java Fri Mar 23 10:58:36 2007 @@ -0,0 +1,46 @@ +/** + * + * 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.MessageExchangeListener; +import org.apache.camel.Processor; +import org.apache.camel.CamelContext; + +import javax.jbi.messaging.MessageExchange; +import javax.jbi.messaging.MessagingException; + +/** + * @version $Revision$ + */ +public class FromJbiProcessor implements MessageExchangeListener { + + private CamelContext context; + private JbiBinding binding; + private Processor processor; + + public FromJbiProcessor(CamelContext context, JbiBinding binding, Processor processor) { + this.context = context; + this.binding = binding; + this.processor = processor; + } + + public void onMessageExchange(MessageExchange messageExchange) throws MessagingException { + JbiExchange exchange = new JbiExchange(context, binding, messageExchange); + processor.onExchange(exchange); + } +} Propchange: activemq/camel/trunk/camel-jbi/src/main/java/org/apache/camel/component/jbi/FromJbiProcessor.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: activemq/camel/trunk/camel-jbi/src/main/java/org/apache/camel/component/jbi/FromJbiProcessor.java ------------------------------------------------------------------------------ svn:keywords = Date Author Id Revision HeadURL Propchange: activemq/camel/trunk/camel-jbi/src/main/java/org/apache/camel/component/jbi/FromJbiProcessor.java ------------------------------------------------------------------------------ svn:mime-type = text/plain 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=521831&r1=521830&r2=521831 ============================================================================== --- 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 Fri Mar 23 10:58:36 2007 @@ -17,7 +17,16 @@ */ package org.apache.camel.component.jbi; +import org.apache.camel.Exchange; +import org.apache.servicemix.client.Destination; + +import javax.jbi.messaging.MessageExchange; +import javax.jbi.messaging.MessagingException; import javax.jbi.messaging.NormalizedMessage; +import javax.jbi.messaging.MessageExchangeFactory; +import javax.xml.transform.Source; +import java.util.Map; +import java.util.Set; /** * The binding of how Camel messages get mapped to JBI and back again @@ -32,4 +41,46 @@ // TODO we may wish to turn this into a POJO such as a JAXB/DOM 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"); + 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 + return exchangeFactory.createInOnlyExchange(); + } + + protected MessageExchange createJbiMessageExchange(Exchange camelExchange, Destination jbiDestination) throws MessagingException { + // TODO we should deal with other forms of MEM + return jbiDestination.createInOnlyExchange(); + } + + protected Source getJbiInContent(Exchange camelExchange) { + return camelExchange.getIn().getBody(Source.class); + } + + protected void addJbiHeaders(MessageExchange jbiExchange, NormalizedMessage normalizedMessage, Exchange camelExchange) { + Set> entries = camelExchange.getIn().getHeaders().entrySet(); + for (Map.Entry entry : entries) { + normalizedMessage.setProperty(entry.getKey(), entry.getValue()); + } + } } + 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=521831&r1=521830&r2=521831 ============================================================================== --- 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 Fri Mar 23 10:58:36 2007 @@ -19,33 +19,40 @@ import org.apache.camel.CamelContext; import org.apache.camel.Endpoint; +import org.apache.camel.Exchange; import org.apache.camel.Processor; import org.apache.camel.impl.DefaultEndpoint; +import org.apache.servicemix.client.Destination; +import org.apache.servicemix.client.ServiceMixClient; + +import javax.jbi.messaging.MessagingException; +import javax.jbi.component.ComponentContext; /** * Represents an {@link Endpoint} for interacting with JBI * * @version $Revision$ */ -public class JbiEndpoint extends DefaultEndpoint { - private JbiBinding binding; +public class JbiEndpoint extends DefaultEndpoint { + private final JbiBinding binding; + private ToJbiProcessor toJbiProcessor; - protected JbiEndpoint(String endpointUri, CamelContext container) { + public JbiEndpoint(String endpointUri, CamelContext container, ComponentContext componentContext, JbiBinding binding) { super(endpointUri, container); + this.binding = binding; + toJbiProcessor = new ToJbiProcessor(binding, componentContext, endpointUri); } - public void onExchange(JbiExchange exchange) { - // TODO - // lets create a JBI MessageExchange and dispatch into JBI... + /** + * Sends a message into JBI + */ + public void onExchange(Exchange exchange) { + toJbiProcessor.onExchange(exchange); } @Override protected void doActivate() throws Exception { super.doActivate(); - - Processor processor = getInboundProcessor(); - - // lets now wire up the processor to the JBI stuff... } public JbiExchange createExchange() { @@ -53,18 +60,6 @@ } public JbiBinding getBinding() { - if (binding == null) { - binding = new JbiBinding(); - } return binding; - } - - /** - * Sets the binding on how Camel messages get mapped to JBI - * - * @param binding the new binding to use - */ - public void setBinding(JbiBinding binding) { - this.binding = binding; } } Added: activemq/camel/trunk/camel-jbi/src/main/java/org/apache/camel/component/jbi/JbiException.java URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-jbi/src/main/java/org/apache/camel/component/jbi/JbiException.java?view=auto&rev=521831 ============================================================================== --- activemq/camel/trunk/camel-jbi/src/main/java/org/apache/camel/component/jbi/JbiException.java (added) +++ activemq/camel/trunk/camel-jbi/src/main/java/org/apache/camel/component/jbi/JbiException.java Fri Mar 23 10:58:36 2007 @@ -0,0 +1,39 @@ +/** + * + * 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.RuntimeCamelException; + +import javax.jbi.messaging.MessagingException; + +/** + * @version $Revision$ + */ +public class JbiException extends RuntimeCamelException { + public JbiException(Throwable cause) { + super(cause); + } + + public JbiException(String message) { + super(message); + } + + public JbiException(String message, Throwable cause) { + super(message, cause); + } +} Propchange: activemq/camel/trunk/camel-jbi/src/main/java/org/apache/camel/component/jbi/JbiException.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: activemq/camel/trunk/camel-jbi/src/main/java/org/apache/camel/component/jbi/JbiException.java ------------------------------------------------------------------------------ svn:keywords = Date Author Id Revision HeadURL Propchange: activemq/camel/trunk/camel-jbi/src/main/java/org/apache/camel/component/jbi/JbiException.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: activemq/camel/trunk/camel-jbi/src/main/java/org/apache/camel/component/jbi/ToJbiProcessor.java URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-jbi/src/main/java/org/apache/camel/component/jbi/ToJbiProcessor.java?view=auto&rev=521831 ============================================================================== --- activemq/camel/trunk/camel-jbi/src/main/java/org/apache/camel/component/jbi/ToJbiProcessor.java (added) +++ activemq/camel/trunk/camel-jbi/src/main/java/org/apache/camel/component/jbi/ToJbiProcessor.java Fri Mar 23 10:58:36 2007 @@ -0,0 +1,58 @@ +/** + * + * 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.Exchange; +import org.apache.camel.Processor; +import org.apache.servicemix.jbi.resolver.URIResolver; + +import javax.jbi.component.ComponentContext; +import javax.jbi.messaging.DeliveryChannel; +import javax.jbi.messaging.MessageExchange; +import javax.jbi.messaging.MessageExchangeFactory; +import javax.jbi.messaging.MessagingException; + +/** + * A @{link Processor} which takes a Camel {@link Exchange} and invokes it into JBI using the straight JBI API + * + * @version $Revision$ + */ +public class ToJbiProcessor implements Processor { + private JbiBinding binding; + private ComponentContext componentContext; + private String destinationUri; + + public ToJbiProcessor(JbiBinding binding, ComponentContext componentContext, String destinationUri) { + this.binding = binding; + this.componentContext = componentContext; + this.destinationUri = destinationUri; + } + + public void onExchange(Exchange exchange) { + try { + DeliveryChannel deliveryChannel = componentContext.getDeliveryChannel(); + MessageExchangeFactory exchangeFactory = deliveryChannel.createExchangeFactory(); + MessageExchange messageExchange = binding.makeJbiMessageExchange(exchange, exchangeFactory); + URIResolver.configureExchange(messageExchange, componentContext, destinationUri); + deliveryChannel.sendSync(messageExchange); + } + catch (MessagingException e) { + throw new JbiException(e); + } + } +} Propchange: activemq/camel/trunk/camel-jbi/src/main/java/org/apache/camel/component/jbi/ToJbiProcessor.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: activemq/camel/trunk/camel-jbi/src/main/java/org/apache/camel/component/jbi/ToJbiProcessor.java ------------------------------------------------------------------------------ svn:keywords = Date Author Id Revision HeadURL Propchange: activemq/camel/trunk/camel-jbi/src/main/java/org/apache/camel/component/jbi/ToJbiProcessor.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: activemq/camel/trunk/camel-jbi/src/main/java/org/apache/camel/component/jbi/ToJbiProcessor2.java URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-jbi/src/main/java/org/apache/camel/component/jbi/ToJbiProcessor2.java?view=auto&rev=521831 ============================================================================== --- activemq/camel/trunk/camel-jbi/src/main/java/org/apache/camel/component/jbi/ToJbiProcessor2.java (added) +++ activemq/camel/trunk/camel-jbi/src/main/java/org/apache/camel/component/jbi/ToJbiProcessor2.java Fri Mar 23 10:58:36 2007 @@ -0,0 +1,53 @@ +/** + * + * 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.Exchange; +import org.apache.camel.Processor; +import org.apache.servicemix.client.ServiceMixClient; +import org.apache.servicemix.client.Destination; + +import javax.jbi.messaging.MessageExchange; +import javax.jbi.messaging.MessagingException; + +/** + * A @{link Processor} which takes a Camel {@link Exchange} and invokes it into JBI using the @{link ServiceMixClient} + * + * @version $Revision$ + */ +public class ToJbiProcessor2 implements Processor { + private JbiBinding binding; + private ServiceMixClient client; + private Destination destination; + + public ToJbiProcessor2(JbiBinding binding, ServiceMixClient client, Destination destination) { + this.binding = binding; + this.client = client; + this.destination = destination; + } + + public void onExchange(Exchange exchange) { + try { + MessageExchange messageExchange = binding.makeJbiMessageExchange(exchange, destination); + client.sendSync(messageExchange); + } + catch (MessagingException e) { + throw new JbiException(e); + } + } +} Propchange: activemq/camel/trunk/camel-jbi/src/main/java/org/apache/camel/component/jbi/ToJbiProcessor2.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: activemq/camel/trunk/camel-jbi/src/main/java/org/apache/camel/component/jbi/ToJbiProcessor2.java ------------------------------------------------------------------------------ svn:keywords = Date Author Id Revision HeadURL Propchange: activemq/camel/trunk/camel-jbi/src/main/java/org/apache/camel/component/jbi/ToJbiProcessor2.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: activemq/camel/trunk/camel-jbi/src/test/java/org/apache/camel/component/jbi/JbiTest.java URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-jbi/src/test/java/org/apache/camel/component/jbi/JbiTest.java?view=auto&rev=521831 ============================================================================== --- activemq/camel/trunk/camel-jbi/src/test/java/org/apache/camel/component/jbi/JbiTest.java (added) +++ activemq/camel/trunk/camel-jbi/src/test/java/org/apache/camel/component/jbi/JbiTest.java Fri Mar 23 10:58:36 2007 @@ -0,0 +1,115 @@ +/** + * + * 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 junit.framework.TestCase; +import org.apache.servicemix.jbi.container.JBIContainer; +import org.apache.servicemix.jbi.container.ActivationSpec; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.camel.CamelContext; +import org.apache.camel.*; +import org.apache.camel.Processor; +import org.apache.camel.Exchange; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.impl.DefaultCamelContext; + +import javax.xml.namespace.QName; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; + +/** + * @version $Revision$ + */ +public class JbiTest extends TestCase { + private static final transient Log log = LogFactory.getLog(JbiTest.class); + + public void testCamelInvokingJbi() throws Exception { + sendExchange(""); + } + + + protected Exchange receivedExchange; + protected CamelContext camelContext = new DefaultCamelContext(); + protected JBIContainer jbiContainer = new JBIContainer(); + protected CountDownLatch latch = new CountDownLatch(1); + protected Endpoint 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(); + ActivationSpec activationSpec = new ActivationSpec(); + activationSpec.setComponentName("camel"); + activationSpec.setService(new QName("camel")); + activationSpec.setComponent(component); + activationSpec.setEndpoint("camelEndpoint"); + activationSpec.setId("camel"); + jbiContainer.activateComponent(component, activationSpec); + + // lets configure some componnets + camelContext.addComponent("jbi", component); + + // lets add some routes + camelContext.setRoutes(new RouteBuilder() { + public void configure() { + from("jbi:service:test.a").to("jbi:service:test.b"); + from("jbi:service:test.b").process(new Processor() { + public void onExchange(Exchange e) { + System.out.println("Received exchange: " + e.getIn()); + receivedExchange = e; + latch.countDown(); + } + }); + } + }); + endpoint = camelContext.resolveEndpoint("jbi:service:test.a"); + assertNotNull("No endpoint found!", endpoint); + + camelContext.activateEndpoints(); + } + + @Override + protected void tearDown() throws Exception { + camelContext.deactivateEndpoints(); + } +} Propchange: activemq/camel/trunk/camel-jbi/src/test/java/org/apache/camel/component/jbi/JbiTest.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: activemq/camel/trunk/camel-jbi/src/test/java/org/apache/camel/component/jbi/JbiTest.java ------------------------------------------------------------------------------ svn:keywords = Date Author Id Revision HeadURL Propchange: activemq/camel/trunk/camel-jbi/src/test/java/org/apache/camel/component/jbi/JbiTest.java ------------------------------------------------------------------------------ svn:mime-type = text/plain