Skip to content

Commit

Permalink
Merged revisions 1374582-1374584,1374709 via svnmerge from
Browse files Browse the repository at this point in the history
https://svn.apache.org/repos/asf/camel/trunk

........
  r1374582 | ningjiang | 2012-08-18 22:02:29 +0800 (Sat, 18 Aug 2012) | 1 line
  
  CAMEL-5518 fix the issue that Camel Proxy,Export ignores camelContextId property in Spring configuration
........
  r1374583 | ningjiang | 2012-08-18 22:03:32 +0800 (Sat, 18 Aug 2012) | 1 line
  
  CAMEL-5519 fix the issue that camel template, endpoint etc ignore camelContextId property
........
  r1374584 | ningjiang | 2012-08-18 22:04:14 +0800 (Sat, 18 Aug 2012) | 1 line
  
  CAMEL-5518 fix a failed test
........
  r1374709 | ningjiang | 2012-08-19 16:24:55 +0800 (Sun, 19 Aug 2012) | 1 line
  
  CAMEL-5518 fix another failed test
........


git-svn-id: https://svn.apache.org/repos/asf/camel/branches/camel-2.10.x@1374891 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
WillemJiang committed Aug 20, 2012
1 parent ab69c97 commit b6d7f7c
Show file tree
Hide file tree
Showing 9 changed files with 212 additions and 13 deletions.
Expand Up @@ -24,6 +24,7 @@
import org.apache.camel.CamelContext;
import org.apache.camel.CamelContextAware;
import org.apache.camel.model.IdentifiedType;
import org.apache.camel.util.ObjectHelper;

@XmlAccessorType(XmlAccessType.FIELD)
public abstract class AbstractCamelFactoryBean<T> extends IdentifiedType implements CamelContextAware {
Expand All @@ -46,13 +47,8 @@ protected CamelContext discoverDefaultCamelContext() {
}

public void afterPropertiesSet() throws Exception {
}

public void destroy() throws Exception {
}

public CamelContext getCamelContext() {
if (camelContext == null && camelContextId != null) {
// Always try to resolved the camel context by using the camelContextId
if (ObjectHelper.isNotEmpty(camelContextId)) {
camelContext = getCamelContextWithId(camelContextId);
if (camelContext == null) {
throw new IllegalStateException("Cannot find CamelContext with id: " + camelContextId);
Expand All @@ -61,6 +57,12 @@ public CamelContext getCamelContext() {
if (camelContext == null) {
camelContext = discoverDefaultCamelContext();
}
}

public void destroy() throws Exception {
}

public CamelContext getCamelContext() {
return camelContext;
}

Expand Down
Expand Up @@ -23,6 +23,7 @@
import org.apache.camel.Producer;
import org.apache.camel.component.bean.ProxyHelper;
import org.apache.camel.spring.util.CamelContextResolverHelper;
import org.apache.camel.util.ObjectHelper;
import org.apache.camel.util.ServiceHelper;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.DisposableBean;
Expand All @@ -46,14 +47,13 @@ public class CamelProxyFactoryBean extends UrlBasedRemoteAccessor implements Fac
@Override
public void afterPropertiesSet() {
if (endpoint == null) {
if (camelContext == null && camelContextId != null) {
if (ObjectHelper.isNotEmpty(camelContextId)) {
camelContext = CamelContextResolverHelper.getCamelContextWithId(applicationContext, camelContextId);
}

if (camelContext == null) {
throw new IllegalArgumentException("camelContext or camelContextId must be specified");
}

if (getServiceUrl() == null && getServiceRef() == null) {
throw new IllegalArgumentException("serviceUrl or serviceRef must be specified.");
}
Expand Down
Expand Up @@ -23,6 +23,7 @@
import org.apache.camel.component.bean.BeanProcessor;
import org.apache.camel.spring.util.CamelContextResolverHelper;
import org.apache.camel.util.CamelContextHelper;
import org.apache.camel.util.ObjectHelper;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.FactoryBean;
Expand Down Expand Up @@ -83,7 +84,8 @@ public void setApplicationContext(ApplicationContext applicationContext) throws
public void afterPropertiesSet() throws Exception {
// lets bind the URI to a pojo
notNull(uri, "uri");
if (camelContext == null && camelContextId != null) {
// Always resolve the camel context by using the camelContextID
if (ObjectHelper.isNotEmpty(camelContextId)) {
camelContext = CamelContextResolverHelper.getCamelContextWithId(applicationContext, camelContextId);
}
notNull(camelContext, "camelContext");
Expand Down
@@ -0,0 +1,40 @@
/**
* 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.spring.produce;

import org.apache.camel.EndpointInject;
import org.apache.camel.ProducerTemplate;
import org.apache.camel.component.mock.MockEndpoint;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit38.AbstractJUnit38SpringContextTests;

@ContextConfiguration
public class ProduceTemplateWithTwoCamelContextTest extends AbstractJUnit38SpringContextTests {
@Autowired
protected ProducerTemplate producer;

@EndpointInject(uri = "mock:result")
protected MockEndpoint result;

public void testProducerTemplate() throws Exception {
result.expectedBodiesReceived("hello");
// lets send a message
producer.sendBody("direct:start", "hello");
result.assertIsSatisfied();
}
}
@@ -0,0 +1,49 @@
/**
* 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.spring.remoting;

import junit.framework.TestCase;

import org.apache.camel.CamelContext;
import org.apache.camel.spring.SpringCamelContext;
import org.springframework.context.support.AbstractXmlApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class SpringRemotingTwoCamelContextTest extends TestCase {

public void testProxyWithTwoCamelContext() throws Exception {
AbstractXmlApplicationContext applicationContext = createApplicationContext();
CamelContext camelContext = SpringCamelContext.springCamelContext(applicationContext);

ISay proxy = applicationContext.getBean("sayProxy1", ISay.class);
String rc = proxy.say();
assertEquals("context-1", rc);

proxy = applicationContext.getBean("sayProxy2", ISay.class);
rc = proxy.say();
assertEquals("context-2", rc);


camelContext.stop();
applicationContext.destroy();
}

protected AbstractXmlApplicationContext createApplicationContext() {
return new ClassPathXmlApplicationContext("org/apache/camel/spring/remoting/spring-with-two-camelcontext.xml");
}

}
Expand Up @@ -23,7 +23,7 @@
">

<!-- START SNIPPET: e1 -->
<camelContext xmlns="http://camel.apache.org/schema/spring">
<camelContext id="myCamel" xmlns="http://camel.apache.org/schema/spring">

<!-- create a proxy that will route to the direct:start endpoint when invoked -->
<proxy id="myProxySender"
Expand Down
@@ -0,0 +1,41 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
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.
-->
<!-- START SNIPPET: example -->
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
">
<template id="camelTemplate" camelContextId="camelContext2" xmlns="http://camel.apache.org/schema/spring"/>

<camelContext id="camelContext1" xmlns="http://camel.apache.org/schema/spring"/>

<camelContext id="camelContext2" xmlns="http://camel.apache.org/schema/spring">
<route>
<from uri="direct:start"/>
<to uri="mock:result"/>
</route>
</camelContext>



</beans>
<!-- END SNIPPET: example -->
Expand Up @@ -29,7 +29,7 @@

<camel:export id="echo" camelContextId="camel" serviceInterface="org.apache.camel.spring.remoting.Echo" serviceRef="echoService" uri="direct:echo"/>

<camelContext xmlns="http://camel.apache.org/schema/spring">
<camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">

</camelContext>

Expand Down
@@ -0,0 +1,65 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
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.
-->
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:camel="http://camel.apache.org/schema/spring"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
">

<camelContext id="context-1" xmlns="http://camel.apache.org/schema/spring">
<route>
<from uri="direct:foo"/>
<to uri="direct:sayImpl"/>
</route>
</camelContext>
<camelContext id="context-2" xmlns="http://camel.apache.org/schema/spring">
<route>
<from uri="direct:foo"/>
<to uri="direct:sayImpl"/>
</route>
</camelContext>

<camel:proxy id="sayProxy1"
serviceInterface="org.apache.camel.spring.remoting.ISay"
serviceUrl="direct:foo"
camelContextId="context-1"/>

<camel:proxy id="sayProxy2"
serviceInterface="org.apache.camel.spring.remoting.ISay"
serviceUrl="direct:foo"
camelContextId="context-2"/>

<bean id="sayService1" class="org.apache.camel.spring.remoting.SayService">
<property name="message" value="context-1" />
</bean>

<bean id="sayService2" class="org.apache.camel.spring.remoting.SayService">
<property name="message" value="context-2" />
</bean>

<camel:export id="say1" uri="direct:sayImpl" serviceRef="sayService1"
serviceInterface="org.apache.camel.spring.remoting.ISay"
camelContextId="context-1"/>

<camel:export id="say2" uri="direct:sayImpl" serviceRef="sayService2"
serviceInterface="org.apache.camel.spring.remoting.ISay"
camelContextId="context-2"/>

</beans>

0 comments on commit b6d7f7c

Please sign in to comment.