Author: ffang
Date: Thu Feb 19 07:47:31 2009
New Revision: 745768
URL: http://svn.apache.org/viewvc?rev=745768&view=rev
Log:
[SM-1808]Back port the patch of SMXCOMP-455 to SMX 3.2 branch
Added:
servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/main/java/org/apache/servicemix/camel/JbiComponent.java
(with props)
Modified:
servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/main/java/org/apache/servicemix/camel/CamelJbiComponent.java
servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/main/java/org/apache/servicemix/camel/CamelProviderEndpoint.java
servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/main/java/org/apache/servicemix/camel/CamelSpringDeployer.java
servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/main/java/org/apache/servicemix/camel/JbiEndpoint.java
servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/main/java/org/apache/servicemix/camel/JbiException.java
servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/test/java/org/apache/servicemix/camel/JbiEndpointWithMepSpecifiedTest.java
servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/test/java/org/apache/servicemix/camel/JbiTestSupport.java
servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/test/java/org/apache/servicemix/camel/SendFromCamelToJbiAndBackToCamelTest.java
servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/test/java/org/apache/servicemix/camel/TwoServicemixCamelSusTest.java
Modified:
servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/main/java/org/apache/servicemix/camel/CamelJbiComponent.java
URL:
http://svn.apache.org/viewvc/servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/main/java/org/apache/servicemix/camel/CamelJbiComponent.java?rev=745768&r1=745767&r2=745768&view=diff
==============================================================================
---
servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/main/java/org/apache/servicemix/camel/CamelJbiComponent.java
(original)
+++
servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/main/java/org/apache/servicemix/camel/CamelJbiComponent.java
Thu Feb 19 07:47:31 2009
@@ -25,42 +25,31 @@
import java.util.concurrent.ScheduledThreadPoolExecutor;
import javax.jbi.servicedesc.ServiceEndpoint;
-import javax.xml.namespace.QName;
-import org.apache.camel.CamelContext;
-import org.apache.camel.Component;
import org.apache.camel.Endpoint;
-import org.apache.camel.Exchange;
-import org.apache.camel.FailedToCreateProducerException;
import org.apache.camel.Processor;
import org.apache.servicemix.common.BaseServiceUnitManager;
import org.apache.servicemix.common.DefaultComponent;
import org.apache.servicemix.common.Deployer;
-import org.apache.servicemix.id.IdGenerator;
-import org.apache.servicemix.jbi.resolver.URIResolver;
import org.apache.servicemix.jbi.util.IntrospectionSupport;
import org.apache.servicemix.jbi.util.URISupport;
/**
* Deploys the camel endpoints within JBI
- *
+ *
* @version $Revision: 426415 $
*/
-public class CamelJbiComponent extends DefaultComponent implements
Component<Exchange> {
+public class CamelJbiComponent extends DefaultComponent {
protected CamelSpringDeployer deployer;
- private JbiBinding binding;
-
- private CamelContext camelContext;
-
private ScheduledExecutorService executorService;
- private IdGenerator idGenerator;
+ private List<JbiComponent> jbiComponents = new ArrayList<JbiComponent>();
/*
* (non-Javadoc)
- *
+ *
* @see org.servicemix.common.BaseComponent#createServiceUnitManager()
*/
@Override
@@ -87,24 +76,6 @@
return new Class[] {CamelProviderEndpoint.class,
CamelConsumerEndpoint.class};
}
- /**
- * @return the 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;
- }
-
@Override
protected String[] getEPRProtocols() {
return new String[] {"camel"};
@@ -112,18 +83,45 @@
@Override
protected org.apache.servicemix.common.Endpoint
getResolvedEPR(ServiceEndpoint ep) throws Exception {
- CamelProviderEndpoint endpoint = createEndpoint(ep);
- endpoint.activate();
+ org.apache.servicemix.common.Endpoint endpoint = null;
+ // extract the su name camel:su1:seda:queque
+ JbiComponent jbiComponent = null;
+ String uriString = "";
+ String endpointName = ep.getEndpointName();
+ String names[] = endpointName.split(":");
+ if (names.length > 2) {
+ jbiComponent = getJbiComponent(names[1]);
+
+ } else {
+ throw new IllegalStateException("Can't find the su name from the
endpoint name");
+ }
+ if (jbiComponent != null) {
+ // skip the su-name part
+ int index = 0;
+ for (String name : names) {
+ if (index == 0) {
+ uriString = name;
+ }
+ if (index > 1) {
+ uriString += ":" + name;
+ }
+ index++;
+ }
+ endpoint = createEndpoint(uriString, jbiComponent);
+ endpoint.activate();
+ } else {
+ throw new IllegalStateException("Can't find the JbiComponent");
+ }
return endpoint;
}
- public CamelProviderEndpoint createEndpoint(ServiceEndpoint ep) throws
URISyntaxException {
- URI uri = new URI(ep.getEndpointName());
+ public CamelProviderEndpoint createEndpoint(String uriString, JbiComponent
jbiComponent) throws URISyntaxException {
+ URI uri = new URI(uriString);
Map map = URISupport.parseQuery(uri.getQuery());
String camelUri = uri.getSchemeSpecificPart();
- Endpoint camelEndpoint = getCamelContext().getEndpoint(camelUri);
- Processor processor = createCamelProcessor(camelEndpoint);
- CamelProviderEndpoint endpoint = new
CamelProviderEndpoint(getServiceUnit(), camelEndpoint, getBinding(), processor);
+ Endpoint camelEndpoint =
jbiComponent.getCamelContext().getEndpoint(camelUri);
+ Processor processor = jbiComponent.createCamelProcessor(camelEndpoint);
+ CamelProviderEndpoint endpoint = new
CamelProviderEndpoint(getServiceUnit(), camelEndpoint,
jbiComponent.getBinding(), processor);
IntrospectionSupport.setProperties(endpoint, map);
@@ -133,22 +131,26 @@
return endpoint;
}
- // Resolve Camel Endpoints
- //
-------------------------------------------------------------------------
- public Endpoint<Exchange> createEndpoint(String uri) {
- if (uri.startsWith("jbi:")) {
- uri = uri.substring("jbi:".length());
- return new JbiEndpoint(this, uri);
- }
- return null;
+ public synchronized void addJbiComponent(JbiComponent jbiComponent) {
+ jbiComponents.add(jbiComponent);
}
- public CamelContext getCamelContext() {
- return camelContext;
+ public synchronized void removeJbiComponent(String suName) {
+ JbiComponent component = getJbiComponent(suName);
+ if (component != null) {
+ jbiComponents.remove(component);
+ }
}
- public void setCamelContext(CamelContext camelContext) {
- this.camelContext = camelContext;
+ public synchronized JbiComponent getJbiComponent(String suName) {
+ JbiComponent result = null;
+ for (JbiComponent component : jbiComponents) {
+ if (suName.equals(component.getSuName())) {
+ result = component;
+ break;
+ }
+ }
+ return result;
}
public ScheduledExecutorService getExecutorService() {
@@ -160,11 +162,9 @@
/**
* Activating a JBI endpoint created by a camel consumer.
- *
- * @returns a JBI endpoint created for the given Camel endpoint
+ *
*/
- public CamelProviderEndpoint activateJbiEndpoint(Endpoint camelEndpoint,
Processor processor) throws Exception {
- CamelProviderEndpoint jbiEndpoint =
createJbiEndpointFromCamel(camelEndpoint, processor);
+ public void activateJbiEndpoint(CamelProviderEndpoint jbiEndpoint) throws
Exception {
// the following method will activate the new dynamic JBI endpoint
if (deployer != null) {
@@ -173,7 +173,7 @@
} else {
addEndpoint(jbiEndpoint);
}
- return jbiEndpoint;
+
}
public void deactivateJbiEndpoint(CamelProviderEndpoint jbiEndpoint)
throws Exception {
@@ -181,86 +181,11 @@
// jbiEndpoint.deactivate();
}
- protected CamelProviderEndpoint createJbiEndpointFromCamel(Endpoint
camelEndpoint, Processor processor) {
- CamelProviderEndpoint jbiEndpoint;
- String endpointUri = camelEndpoint.getEndpointUri();
- if (camelEndpoint instanceof JbiEndpoint) {
- QName service = null;
- String endpoint = null;
- if (endpointUri.startsWith("name:")) {
- endpoint = endpointUri.substring("name:".length());
- service = CamelProviderEndpoint.SERVICE_NAME;
- } else if (endpointUri.startsWith("endpoint:")) {
- String uri = endpointUri.substring("endpoint:".length());
- // lets decode "serviceNamespace sep serviceName sep
- // endpointName
- String[] parts;
- try {
- parts = URIResolver.split3(uri);
- } catch (IllegalArgumentException e) {
- throw new IllegalArgumentException(
- "Expected syntax
jbi:endpoint:[serviceNamespace][sep][serviceName][sep][endpointName] "
- + "where sep = '/' or ':' depending on the
serviceNamespace, but was given: "
- + endpointUri + ". Cause: " + e, e);
- }
- service = new QName(parts[0], parts[1]);
- endpoint = parts[2];
- } else if (endpointUri.startsWith("service:")) {
- String uri = endpointUri.substring("service:".length());
- // lets decode "serviceNamespace sep serviceName
- String[] parts;
- try {
- parts = URIResolver.split2(uri);
- } catch (IllegalArgumentException e) {
- throw new IllegalArgumentException(
- "Expected syntax
jbi:endpoint:[serviceNamespace][sep][serviceName] "
- + "where sep = '/' or ':' depending on the
serviceNamespace, but was given: "
- + endpointUri + ". Cause: " + e, e);
- }
- service = new QName(parts[0], parts[1]);
- endpoint = createEndpointName();
- } else {
- throw new IllegalArgumentException(
- "Expected syntax
jbi:endpoint:[serviceNamespace][sep][serviceName][sep][endpointName] "
- + "or jbi:service:[serviceNamespace][sep][serviceName
or jbi:name:[endpointName] but was given: "
- + endpointUri);
- }
- jbiEndpoint = new CamelProviderEndpoint(getServiceUnit(), service,
endpoint, camelEndpoint, getBinding(), processor);
- } else {
- jbiEndpoint = new CamelProviderEndpoint(getServiceUnit(),
camelEndpoint, getBinding(), processor);
- }
- return jbiEndpoint;
- }
-
- protected String createEndpointName() {
- if (idGenerator == null) {
- idGenerator = new IdGenerator("camel");
- }
- return idGenerator.generateSanitizedId();
- }
-
- /**
- * Returns a JBI endpoint created for the given Camel endpoint
- */
- public CamelProviderEndpoint createJbiEndpointFromCamel(Endpoint
camelEndpoint) {
- Processor processor = createCamelProcessor(camelEndpoint);
- return createJbiEndpointFromCamel(camelEndpoint, processor);
- }
-
- protected Processor createCamelProcessor(Endpoint camelEndpoint) {
- Processor processor = null;
- try {
- processor = camelEndpoint.createProducer();
- } catch (Exception e) {
- throw new FailedToCreateProducerException(camelEndpoint, e);
- }
- return processor;
- }
/**
* Should we expose the Camel JBI onto the NMR. <p/> We may wish to add
some
* policy stuff etc.
- *
+ *
* @param endpoint
* the camel endpoint
* @return true if the endpoint should be exposed in the NMR
Modified:
servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/main/java/org/apache/servicemix/camel/CamelProviderEndpoint.java
URL:
http://svn.apache.org/viewvc/servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/main/java/org/apache/servicemix/camel/CamelProviderEndpoint.java?rev=745768&r1=745767&r2=745768&view=diff
==============================================================================
---
servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/main/java/org/apache/servicemix/camel/CamelProviderEndpoint.java
(original)
+++
servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/main/java/org/apache/servicemix/camel/CamelProviderEndpoint.java
Thu Feb 19 07:47:31 2009
@@ -60,7 +60,7 @@
public void process(MessageExchange exchange) throws Exception {
// The component acts as a provider, this means that another component
has requested our service
// As this exchange is active, this is either an in or a fault (out
are sent by this component)
-
+
if (exchange.getRole() == MessageExchange.Role.PROVIDER) {
// Exchange is finished
if (exchange.getStatus() == ExchangeStatus.DONE) {
@@ -92,7 +92,7 @@
}
JbiExchange camelExchange = new
JbiExchange(camelEndpoint.getCamelContext(), binding, exchange);
camelProcessor.process(camelExchange);
- if (camelExchange.isFailed()
+ if (camelExchange.isFailed()
&& (camelExchange.getFault(false) == null ||
camelExchange.getFault(false).getBody() == null)) {
Throwable t = camelExchange.getException();
Exception e;
@@ -113,7 +113,7 @@
}
JbiExchange camelExchange = new
JbiExchange(camelEndpoint.getCamelContext(), binding, exchange);
camelProcessor.process(camelExchange);
- if (camelExchange.isFailed()
+ if (camelExchange.isFailed()
&& (camelExchange.getFault(false) == null ||
camelExchange.getFault(false).getBody() == null)) {
Throwable t = camelExchange.getException();
Exception e;
@@ -134,7 +134,7 @@
}
}
}
- // This is not compliant with the default MEPs
+ // This is not complaint with the default MEPs
} else {
throw new IllegalStateException("Provider exchange is ACTIVE, but
no in or fault is provided");
}
Modified:
servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/main/java/org/apache/servicemix/camel/CamelSpringDeployer.java
URL:
http://svn.apache.org/viewvc/servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/main/java/org/apache/servicemix/camel/CamelSpringDeployer.java?rev=745768&r1=745767&r2=745768&view=diff
==============================================================================
---
servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/main/java/org/apache/servicemix/camel/CamelSpringDeployer.java
(original)
+++
servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/main/java/org/apache/servicemix/camel/CamelSpringDeployer.java
Thu Feb 19 07:47:31 2009
@@ -47,7 +47,8 @@
@Override
protected AbstractXmlApplicationContext
createXmlApplicationContext(String configLocation) {
ApplicationContext parentAppContext =
createParentApplicationContext(getXmlPreprocessors());
- return new FileSystemXmlApplicationContext(new String[]
{configLocation}, false, parentAppContext, getXmlPreprocessors());
+ return new FileSystemXmlApplicationContext(new String[]
{configLocation}, false,
+ parentAppContext,
getXmlPreprocessors());
}
};
@@ -65,11 +66,17 @@
return "camel-context";
}
+ public void undeploy(ServiceUnit su) throws DeploymentException {
+ // Remove the jbiComponent form CamelJbiComponent
+ component.removeJbiComponent(su.getName());
+ super.undeploy(su);
+ }
+
/*
* (non-Javadoc)
*
* @see org.apache.servicemix.common.Deployer#deploy(java.lang.String,
- * java.lang.String)
+ * java.lang.String)
*/
@Override
public ServiceUnit deploy(String suName, String serviceUnitRootPath)
throws DeploymentException {
@@ -81,7 +88,7 @@
// lets install the context class loader
ServiceUnit serviceUnit = super.deploy(suName, serviceUnitRootPath);
-//
Thread.currentThread().setContextClassLoader(serviceUnit.getConfigurationClassLoader());
+ //
Thread.currentThread().setContextClassLoader(serviceUnit.getConfigurationClassLoader());
return serviceUnit;
}
@@ -92,27 +99,32 @@
@Override
protected List getServices(Kernel kernel) {
try {
- List<org.apache.servicemix.common.Endpoint> services = new
ArrayList<org.apache.servicemix.common.Endpoint>(activatedEndpoints);
+ List<org.apache.servicemix.common.Endpoint> services =
+ new
ArrayList<org.apache.servicemix.common.Endpoint>(activatedEndpoints);
activatedEndpoints.clear();
ApplicationContext applicationContext =
springLoader.getApplicationContext();
SpringCamelContext camelContext =
SpringCamelContext.springCamelContext(applicationContext);
+ JbiComponent jbiComponent = camelContext.getComponent("jbi",
JbiComponent.class);
// now lets iterate through all the endpoints
Collection<Endpoint> endpoints =
camelContext.getSingletonEndpoints();
- for (Endpoint endpoint : endpoints) {
- if (component.isEndpointExposedOnNmr(endpoint)) {
-
services.add(component.createJbiEndpointFromCamel(endpoint));
+ if (jbiComponent != null) {
+ // set the SU Name
+ jbiComponent.setSuName(serviceUnitName);
+ for (Endpoint endpoint : endpoints) {
+ if (component.isEndpointExposedOnNmr(endpoint)) {
+
services.add(jbiComponent.createJbiEndpointFromCamel(endpoint));
+ }
}
+ // lets add a control bus endpoint to ensure we have at least
+ // one endpoint to deploy
+ BeanComponent beanComponent =
camelContext.getComponent("bean", BeanComponent.class);
+ Endpoint endpoint = beanComponent.createEndpoint(new
CamelControlBus(camelContext),
+ "camel:" +
serviceUnitName + "-controlBus");
+
services.add(jbiComponent.createJbiEndpointFromCamel(endpoint));
}
-
- // lets add a control bus endpoint to ensure we have at least one
endpoint to deploy
- BeanComponent beanComponent = camelContext.getComponent("bean",
BeanComponent.class);
- Endpoint endpoint = beanComponent.createEndpoint(new
CamelControlBus(camelContext),
- "camel:" +
serviceUnitName + "-controlBus");
- services.add(component.createJbiEndpointFromCamel(endpoint));
-
return services;
} catch (Exception e) {
throw new RuntimeException(e);
@@ -130,7 +142,8 @@
*/
protected ApplicationContext createParentApplicationContext(List
xmlProcessors) {
GenericApplicationContext answer = new GenericApplicationContext();
- answer.getBeanFactory().registerSingleton("jbi", component);
+ answer.getBeanFactory().registerSingleton("servicemix-camel",
component);
+ answer.getBeanFactory().registerSingleton("jbi", new
JbiComponent(component));
answer.setClassLoader(Thread.currentThread().getContextClassLoader());
answer.start();
answer.refresh();
Added:
servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/main/java/org/apache/servicemix/camel/JbiComponent.java
URL:
http://svn.apache.org/viewvc/servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/main/java/org/apache/servicemix/camel/JbiComponent.java?rev=745768&view=auto
==============================================================================
---
servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/main/java/org/apache/servicemix/camel/JbiComponent.java
(added)
+++
servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/main/java/org/apache/servicemix/camel/JbiComponent.java
Thu Feb 19 07:47:31 2009
@@ -0,0 +1,172 @@
+/*
+ * 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 javax.xml.namespace.QName;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.Component;
+import org.apache.camel.Endpoint;
+import org.apache.camel.Exchange;
+import org.apache.camel.FailedToCreateProducerException;
+import org.apache.camel.Processor;
+import org.apache.servicemix.id.IdGenerator;
+import org.apache.servicemix.jbi.resolver.URIResolver;
+
+public class JbiComponent implements Component<Exchange> {
+ private final CamelJbiComponent camelJbiComponent;
+ private JbiBinding binding;
+ private CamelContext camelContext;
+ private IdGenerator idGenerator;
+ private String suName;
+
+ public JbiComponent(CamelJbiComponent component) {
+ camelJbiComponent = component;
+ camelJbiComponent.addJbiComponent(this);
+ }
+
+ public CamelContext getCamelContext() {
+ return camelContext;
+ }
+
+ public void setCamelContext(CamelContext context) {
+ camelContext = context;
+ }
+
+ public CamelJbiComponent getCamelJbiComponent() {
+ return camelJbiComponent;
+ }
+
+ public void setSuName(String su) {
+ suName = su;
+ }
+
+ public String getSuName() {
+ return suName;
+ }
+
+ /**
+ * @return the 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;
+ }
+
+ // Resolve Camel Endpoints
+ //
-------------------------------------------------------------------------
+ public Endpoint<Exchange> createEndpoint(String uri) {
+ if (uri.startsWith("jbi:")) {
+ uri = uri.substring("jbi:".length());
+ return new JbiEndpoint(this, uri);
+ }
+ return null;
+ }
+
+
+ protected CamelProviderEndpoint createJbiEndpointFromCamel(
+ Endpoint camelEndpoint, Processor processor) {
+ CamelProviderEndpoint jbiEndpoint;
+ String endpointUri = camelEndpoint.getEndpointUri();
+ if (camelEndpoint instanceof JbiEndpoint) {
+ QName service = null;
+ String endpoint = null;
+ if (endpointUri.startsWith("name:")) {
+ endpoint = endpointUri.substring("name:".length());
+ service = CamelProviderEndpoint.SERVICE_NAME;
+ } else if (endpointUri.startsWith("endpoint:")) {
+ String uri = endpointUri.substring("endpoint:".length());
+ // lets decode "serviceNamespace sep serviceName sep
+ // endpointName
+ String[] parts;
+ try {
+ parts = URIResolver.split3(uri);
+ } catch (IllegalArgumentException e) {
+ throw new IllegalArgumentException(
+ "Expected syntax
jbi:endpoint:[serviceNamespace][sep][serviceName][sep][endpointName] "
+ + "where sep = '/' or ':' depending on the
serviceNamespace, but was given: "
+ + endpointUri + ". Cause: " + e, e);
+ }
+ service = new QName(parts[0], parts[1]);
+ endpoint = parts[2];
+ } else if (endpointUri.startsWith("service:")) {
+ String uri = endpointUri.substring("service:".length());
+ // lets decode "serviceNamespace sep serviceName
+ String[] parts;
+ try {
+ parts = URIResolver.split2(uri);
+ } catch (IllegalArgumentException e) {
+ throw new IllegalArgumentException(
+ "Expected syntax
jbi:endpoint:[serviceNamespace][sep][serviceName] "
+ + "where sep = '/' or ':' depending on the
serviceNamespace, but was given: "
+ + endpointUri + ". Cause: " + e, e);
+ }
+ service = new QName(parts[0], parts[1]);
+ endpoint = createEndpointName();
+ } else {
+ throw new IllegalArgumentException(
+ "Expected syntax
jbi:endpoint:[serviceNamespace][sep][serviceName][sep][endpointName] "
+ + "or jbi:service:[serviceNamespace][sep][serviceName or
jbi:name:[endpointName] but was given: "
+ + endpointUri);
+ }
+ jbiEndpoint = new
CamelProviderEndpoint(getCamelJbiComponent().getServiceUnit(), service,
+ endpoint, camelEndpoint,
getBinding(), processor);
+ } else {
+ jbiEndpoint = new
CamelProviderEndpoint(getCamelJbiComponent().getServiceUnit(), camelEndpoint,
+ getBinding(), processor);
+ }
+ return jbiEndpoint;
+ }
+
+ protected String createEndpointName() {
+ if (idGenerator == null) {
+ idGenerator = new IdGenerator("camel");
+ }
+ return idGenerator.generateSanitizedId();
+ }
+
+ /**
+ * Returns a JBI endpoint created for the given Camel endpoint
+ */
+ public CamelProviderEndpoint createJbiEndpointFromCamel(Endpoint
camelEndpoint) {
+ Processor processor = createCamelProcessor(camelEndpoint);
+ return createJbiEndpointFromCamel(camelEndpoint, processor);
+ }
+
+ protected Processor createCamelProcessor(Endpoint camelEndpoint) {
+ Processor processor = null;
+ try {
+ processor = camelEndpoint.createProducer();
+ } catch (Exception e) {
+ throw new FailedToCreateProducerException(camelEndpoint, e);
+ }
+ return processor;
+ }
+
+
+
+}
Propchange:
servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/main/java/org/apache/servicemix/camel/JbiComponent.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/main/java/org/apache/servicemix/camel/JbiComponent.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified:
servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/main/java/org/apache/servicemix/camel/JbiEndpoint.java
URL:
http://svn.apache.org/viewvc/servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/main/java/org/apache/servicemix/camel/JbiEndpoint.java?rev=745768&r1=745767&r2=745768&view=diff
==============================================================================
---
servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/main/java/org/apache/servicemix/camel/JbiEndpoint.java
(original)
+++
servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/main/java/org/apache/servicemix/camel/JbiEndpoint.java
Thu Feb 19 07:47:31 2009
@@ -48,9 +48,9 @@
private JbiProducer producer;
- private final CamelJbiComponent jbiComponent;
+ private final JbiComponent jbiComponent;
- public JbiEndpoint(CamelJbiComponent jbiComponent, String uri) {
+ public JbiEndpoint(JbiComponent jbiComponent, String uri) {
super(uri, jbiComponent);
this.jbiComponent = jbiComponent;
parseUri(uri);
@@ -76,7 +76,7 @@
@Override
public void start() throws Exception {
consumer = new CamelConsumerEndpoint(jbiComponent.getBinding(),
JbiEndpoint.this);
- jbiComponent.addEndpoint(consumer);
+ jbiComponent.getCamelJbiComponent().addEndpoint(consumer);
super.start();
}
@Override
@@ -85,7 +85,7 @@
log.debug("Camel producer for " + super.getEndpoint() + " has
already been stopped");
} else {
log.debug("Stopping Camel producer for " +
super.getEndpoint());
- jbiComponent.removeEndpoint(consumer);
+ jbiComponent.getCamelJbiComponent().removeEndpoint(consumer);
super.stop();
}
}
@@ -148,13 +148,14 @@
@Override
protected void doStart() throws Exception {
super.doStart();
- jbiEndpoint =
jbiComponent.activateJbiEndpoint(JbiEndpoint.this, processor);
+ jbiEndpoint =
jbiComponent.createJbiEndpointFromCamel(JbiEndpoint.this, processor);
+
jbiComponent.getCamelJbiComponent().activateJbiEndpoint(jbiEndpoint);
}
@Override
protected void doStop() throws Exception {
if (jbiEndpoint != null) {
- jbiComponent.deactivateJbiEndpoint(jbiEndpoint);
+
jbiComponent.getCamelJbiComponent().deactivateJbiEndpoint(jbiEndpoint);
}
super.doStop();
}
Modified:
servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/main/java/org/apache/servicemix/camel/JbiException.java
URL:
http://svn.apache.org/viewvc/servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/main/java/org/apache/servicemix/camel/JbiException.java?rev=745768&r1=745767&r2=745768&view=diff
==============================================================================
---
servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/main/java/org/apache/servicemix/camel/JbiException.java
(original)
+++
servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/main/java/org/apache/servicemix/camel/JbiException.java
Thu Feb 19 07:47:31 2009
@@ -22,6 +22,9 @@
* @version $Revision: 563665 $
*/
public class JbiException extends RuntimeCamelException {
+
+ private static final long serialVersionUID = -939254443652090476L;
+
public JbiException(Throwable cause) {
super(cause);
}
Modified:
servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/test/java/org/apache/servicemix/camel/JbiEndpointWithMepSpecifiedTest.java
URL:
http://svn.apache.org/viewvc/servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/test/java/org/apache/servicemix/camel/JbiEndpointWithMepSpecifiedTest.java?rev=745768&r1=745767&r2=745768&view=diff
==============================================================================
---
servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/test/java/org/apache/servicemix/camel/JbiEndpointWithMepSpecifiedTest.java
(original)
+++
servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/test/java/org/apache/servicemix/camel/JbiEndpointWithMepSpecifiedTest.java
Thu Feb 19 07:47:31 2009
@@ -33,26 +33,26 @@
* Tests to check correct handling of the ?mep=xxx setting on a Camel JBI
endpoint
*/
public class JbiEndpointWithMepSpecifiedTest extends JbiTestSupport {
-
+
private MyReceiverComponent component;
-
+
@Override
protected void setUp() throws Exception {
component = new MyReceiverComponent();
super.setUp();
}
-
+
public void testCamelInOutSendJbiInOnly() throws Exception {
client.send("direct:a", new DefaultExchange(camelContext) {
-
+
@Override
public ExchangePattern getPattern() {
//let's explicitly send an in-out Exchange
return ExchangePattern.InOut;
}
-
+
});
- assertEquals(1, component.count);
+ assertEquals(1, component.getCount());
}
@Override
@@ -73,15 +73,15 @@
}
};
}
-
+
private class MyReceiverComponent extends ReceiverComponent {
-
+
private int count;
-
+
public int getCount() {
return count;
}
-
+
@Override
public void onMessageExchange(MessageExchange exchange) throws
MessagingException {
if (exchange instanceof InOnly) {
@@ -89,7 +89,7 @@
done(exchange);
} else {
fail(exchange, new Exception("Unexpected MEP: " +
exchange.getPattern()));
- }
+ }
}
}
}
Modified:
servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/test/java/org/apache/servicemix/camel/JbiTestSupport.java
URL:
http://svn.apache.org/viewvc/servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/test/java/org/apache/servicemix/camel/JbiTestSupport.java?rev=745768&r1=745767&r2=745768&view=diff
==============================================================================
---
servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/test/java/org/apache/servicemix/camel/JbiTestSupport.java
(original)
+++
servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/test/java/org/apache/servicemix/camel/JbiTestSupport.java
Thu Feb 19 07:47:31 2009
@@ -47,7 +47,7 @@
* @version $Revision: 563665 $
*/
public abstract class JbiTestSupport extends TestSupport {
-
+
protected Exchange receivedExchange;
protected CamelContext camelContext = new DefaultCamelContext();
@@ -63,7 +63,7 @@
protected String startEndpointUri =
"jbi:endpoint:serviceNamespace:serviceA:endpointA";
protected ProducerTemplate<Exchange> client =
camelContext.createProducerTemplate();
-
+
protected ServiceMixClient servicemixClient;
/**
@@ -117,7 +117,7 @@
protected void setUp() throws Exception {
configureContainer(jbiContainer);
List<ActivationSpec> activationSpecList = new
ArrayList<ActivationSpec>();
-
+
// lets add the Camel endpoint
CamelJbiComponent component = new CamelJbiComponent();
activationSpecList.add(createActivationSpec(component, new
QName("camel", "camel"), "camelEndpoint"));
@@ -125,15 +125,15 @@
// and provide a callback method for adding more services
appendJbiActivationSpecs(activationSpecList);
jbiContainer.setActivationSpecs(activationSpecList.toArray(new
ActivationSpec[activationSpecList.size()]));
-
+
jbiContainer.afterPropertiesSet();
-
+
exchangeCompletedListener = new ExchangeCompletedListener();
jbiContainer.addListener(exchangeCompletedListener);
// allow for additional configuration of the compenent (e.g. deploying
SU)
configureComponent(component);
-
+
// lets add some routes
RouteBuilder builder = createRoutes();
if (builder != null) {
@@ -146,24 +146,24 @@
protected void configureComponent(CamelJbiComponent component) throws
Exception {
// add the ServiceMix Camel component to the CamelContext
- camelContext.addComponent("jbi", component);
+ camelContext.addComponent("jbi", new JbiComponent(component));
}
protected void configureContainer(final JBIContainer container) throws
Exception {
container.setEmbedded(true);
}
-
+
public ServiceMixClient getServicemixClient() throws JBIException {
if (servicemixClient == null) {
servicemixClient = new DefaultServiceMixClient(jbiContainer);
}
return servicemixClient;
}
-
+
protected ActivationSpec createActivationSpec(Object component, QName
service) {
return createActivationSpec(component, service, "endpoint");
}
-
+
protected ActivationSpec createActivationSpec(Object component, QName
service, String endpointName) {
ActivationSpec spec = new ActivationSpec(component);
spec.setService(service);
@@ -178,7 +178,7 @@
camelContext.stop();
super.tearDown();
}
-
+
protected MockEndpoint getMockEndpoint(String uri) {
return (MockEndpoint)camelContext.getEndpoint(uri);
}
Modified:
servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/test/java/org/apache/servicemix/camel/SendFromCamelToJbiAndBackToCamelTest.java
URL:
http://svn.apache.org/viewvc/servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/test/java/org/apache/servicemix/camel/SendFromCamelToJbiAndBackToCamelTest.java?rev=745768&r1=745767&r2=745768&view=diff
==============================================================================
---
servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/test/java/org/apache/servicemix/camel/SendFromCamelToJbiAndBackToCamelTest.java
(original)
+++
servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/test/java/org/apache/servicemix/camel/SendFromCamelToJbiAndBackToCamelTest.java
Thu Feb 19 07:47:31 2009
@@ -62,6 +62,13 @@
};
}
+ protected void configureComponent(CamelJbiComponent component) throws
Exception {
+ // add the ServiceMix Camel component to the CamelContext
+ JbiComponent jbiComponent = new JbiComponent(component);
+ jbiComponent.setSuName("su_test");
+ camelContext.addComponent("jbi", jbiComponent);
+ }
+
@Override
protected void appendJbiActivationSpecs(
List<ActivationSpec> activationSpecList) {
@@ -73,7 +80,7 @@
activationSpec.setEndpoint("endpointA");
// lets setup the sender to talk directly to camel
- senderComponent.setResolver(new URIResolver("camel:seda:receiver"));
+ senderComponent.setResolver(new
URIResolver("camel:su_test:seda:receiver"));
activationSpec.setComponent(senderComponent);
activationSpecList.add(activationSpec);
Modified:
servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/test/java/org/apache/servicemix/camel/TwoServicemixCamelSusTest.java
URL:
http://svn.apache.org/viewvc/servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/test/java/org/apache/servicemix/camel/TwoServicemixCamelSusTest.java?rev=745768&r1=745767&r2=745768&view=diff
==============================================================================
---
servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/test/java/org/apache/servicemix/camel/TwoServicemixCamelSusTest.java
(original)
+++
servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/test/java/org/apache/servicemix/camel/TwoServicemixCamelSusTest.java
Thu Feb 19 07:47:31 2009
@@ -22,25 +22,21 @@
import org.apache.camel.CamelContext;
-public class TwoServicemixCamelSusTest extends
- NonJbiCamelEndpointsIntegrationTest {
-
- private void deploySu(CamelJbiComponent component, String suName)
- throws Exception {
+public class TwoServicemixCamelSusTest extends
NonJbiCamelEndpointsIntegrationTest {
+
+ private void deploySu(CamelJbiComponent component, String suName) throws
Exception {
String serviceUnitConfiguration = suName + "-src/camel-context.xml";
URL url = getClass().getResource(serviceUnitConfiguration);
File path = new File(new URI(url.toString()));
path = path.getParentFile();
// Deploy and start su
- component.getServiceUnitManager()
- .deploy(suName, path.getAbsolutePath());
+ component.getServiceUnitManager().deploy(suName,
path.getAbsolutePath());
component.getServiceUnitManager().init(suName, path.getAbsolutePath());
component.getServiceUnitManager().start(suName);
}
- private void undeploySu(CamelJbiComponent component, String suName)
- throws Exception {
+ private void undeploySu(CamelJbiComponent component, String suName) throws
Exception {
String serviceUnitConfiguration = suName + "-src/camel-context.xml";
URL url = getClass().getResource(serviceUnitConfiguration);
File path = new File(new URI(url.toString()));
@@ -49,8 +45,7 @@
// Stop and undeploy
component.getServiceUnitManager().stop(suName);
component.getServiceUnitManager().shutDown(suName);
- component.getServiceUnitManager().undeploy(suName,
- path.getAbsolutePath());
+ component.getServiceUnitManager().undeploy(suName,
path.getAbsolutePath());
}
public void testComponentInstallation() throws Exception {
@@ -60,13 +55,16 @@
// deploy two sus here
deploySu(component, "su3");
- CamelContext su3CamelContext = component.getCamelContext();
+ JbiComponent jbiComponent = component.getJbiComponent("su3");
+ assertNotNull("JbiComponent should not be null ", jbiComponent);
+ CamelContext su3CamelContext = jbiComponent.getCamelContext();
assertNotNull("We should get a camel context here ", su3CamelContext);
deploySu(component, "su6");
- CamelContext su6CamelContext = component.getCamelContext();
+ jbiComponent = component.getJbiComponent("su6");
+ assertNotNull("JbiComponent should not be null ", jbiComponent);
+ CamelContext su6CamelContext = jbiComponent.getCamelContext();
assertNotNull("We should get a camel context here ", su6CamelContext);
- assertTrue("Here should be two different camel contexts",
- !su3CamelContext.equals(su6CamelContext));
+ assertTrue("Here should be two different camel contexts",
!su3CamelContext.equals(su6CamelContext));
// deploy two sus here
undeploySu(component, "su3");