You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@camel.apache.org by "Sergey Zhemzhitsky (JIRA)" <ji...@apache.org> on 2011/08/23 15:46:29 UTC

[jira] [Created] (CAMEL-4371) Add an ability to replace endpoints

Add an ability to replace endpoints
-----------------------------------

                 Key: CAMEL-4371
                 URL: https://issues.apache.org/jira/browse/CAMEL-4371
             Project: Camel
          Issue Type: Improvement
          Components: camel-core
    Affects Versions: 2.8.0
            Reporter: Sergey Zhemzhitsky


Sometimes it can be useful to replace endpoints in the camel context. For example, in unit tests it will not be necessary to define multiple properties file for different environments with placeholders.

Here is the endpoint strategy to replace endpoints

{code}
package org.apache.camel.impl;

public class ReplaceEndpointStrategy implements EndpointStrategy {

    private Map<String, String> replacements = Collections.emptyMap();

    @Override
    public Endpoint registerEndpoint(String uri, Endpoint endpoint) {
        CamelContext context = endpoint.getCamelContext();

        for(Entry<String, String> entry : replacements.entrySet()) {
            if(EndpointHelper.matchEndpoint(uri, entry.getKey())) {
                Endpoint newEndpoint = context.getEndpoint(entry.getValue());
                return newEndpoint;
            }
        }

        return endpoint;
    }

    public void setReplacements(Map<String, String> replacements) {
        this.replacements = replacements;
    }

}
{code}

Here is it can be used from spring

{code}
<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
        http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
    ">

    <bean class="org.apache.camel.impl.ReplaceEndpointStrategy">
        <property name="replacements">
            <map>
                <entry key="timer://test*" value="direct://start" />
                <entry key="log://timer*" value="mock://tick" />
            </map>
        </property>
    </bean>

    <camelContext xmlns="http://camel.apache.org/schema/spring">
        <route>
            <from uri="timer://testTimer" />
            <to uri="log://timerTick" />
        </route>
    </camelContext>

</beans>
{code}

And the unit test
{code}
package org.apache.camel.impl;

import static org.junit.Assert.assertNotNull;

import org.apache.camel.CamelContext;
import org.apache.camel.Endpoint;
import org.apache.camel.ProducerTemplate;
import org.apache.camel.component.mock.MockEndpoint;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration
public class ReplaceEndpointStrategyTest {

    @Autowired
    private CamelContext camelContext;

    @Autowired
    private ProducerTemplate producer;

    @Test
    public void registerEndpoint() throws Exception {
        assertNotNull("direct:start is null", camelContext.hasEndpoint("direct:start"));
        assertNotNull("mock:tick is null", camelContext.hasEndpoint("mock:tick"));
    }

    @Test
    public void route() throws Exception {
        Endpoint start = camelContext.hasEndpoint("direct:start");
        MockEndpoint complete = (MockEndpoint) camelContext.hasEndpoint("mock:tick");

        complete.expectedBodiesReceived("Hello World!");
        producer.sendBody(start, "Hello World!");
        complete.assertIsSatisfied();
    }

}
{code}

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Commented] (CAMEL-4371) Add an ability to replace endpoints

Posted by "Ashwin Karpe (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CAMEL-4371?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13095970#comment-13095970 ] 

Ashwin Karpe commented on CAMEL-4371:
-------------------------------------

@Hadrian, @Claus,

I looked over the AdviceWithRouteBuilder and it seems quite powerful and capable.

Please advise if an event based approach is warranted under the circumstances...

Cheers,

Ashwin... 

> Add an ability to replace endpoints
> -----------------------------------
>
>                 Key: CAMEL-4371
>                 URL: https://issues.apache.org/jira/browse/CAMEL-4371
>             Project: Camel
>          Issue Type: Improvement
>          Components: camel-core
>    Affects Versions: 2.8.0
>            Reporter: Sergey Zhemzhitsky
>            Assignee: Ashwin Karpe
>
> Sometimes it can be useful to replace endpoints in the camel context. For example, in unit tests it will not be necessary to define multiple properties files for different environments with placeholders.
> Here is the endpoint strategy to replace endpoints
> {code}
> package org.apache.camel.impl;
> public class ReplaceEndpointStrategy implements EndpointStrategy {
>     private Map<String, String> replacements = Collections.emptyMap();
>     @Override
>     public Endpoint registerEndpoint(String uri, Endpoint endpoint) {
>         CamelContext context = endpoint.getCamelContext();
>         for(Entry<String, String> entry : replacements.entrySet()) {
>             if(EndpointHelper.matchEndpoint(uri, entry.getKey())) {
>                 Endpoint newEndpoint = context.getEndpoint(entry.getValue());
>                 return newEndpoint;
>             }
>         }
>         return endpoint;
>     }
>     public void setReplacements(Map<String, String> replacements) {
>         this.replacements = replacements;
>     }
> }
> {code}
> Here is it can be used from spring
> {code}
> <?xml version="1.0" encoding="UTF-8"?>
> <beans xmlns="http://www.springframework.org/schema/beans"
>     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>     xsi:schemaLocation="
>         http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
>         http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
>     ">
>     <bean class="org.apache.camel.impl.ReplaceEndpointStrategy">
>         <property name="replacements">
>             <map>
>                 <entry key="timer://test*" value="direct://start" />
>                 <entry key="log://timer*" value="mock://tick" />
>             </map>
>         </property>
>     </bean>
>     <camelContext xmlns="http://camel.apache.org/schema/spring">
>         <route>
>             <from uri="timer://testTimer" />
>             <to uri="log://timerTick" />
>         </route>
>     </camelContext>
> </beans>
> {code}
> And the unit test
> {code}
> package org.apache.camel.impl;
> import static org.junit.Assert.assertNotNull;
> import org.apache.camel.CamelContext;
> import org.apache.camel.Endpoint;
> import org.apache.camel.ProducerTemplate;
> import org.apache.camel.component.mock.MockEndpoint;
> import org.junit.Test;
> import org.junit.runner.RunWith;
> import org.springframework.beans.factory.annotation.Autowired;
> import org.springframework.test.context.ContextConfiguration;
> import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
> @RunWith(SpringJUnit4ClassRunner.class)
> @ContextConfiguration
> public class ReplaceEndpointStrategyTest {
>     @Autowired
>     private CamelContext camelContext;
>     @Autowired
>     private ProducerTemplate producer;
>     @Test
>     public void registerEndpoint() throws Exception {
>         assertNotNull("direct:start is null", camelContext.hasEndpoint("direct:start"));
>         assertNotNull("mock:tick is null", camelContext.hasEndpoint("mock:tick"));
>     }
>     @Test
>     public void route() throws Exception {
>         Endpoint start = camelContext.hasEndpoint("direct:start");
>         MockEndpoint complete = (MockEndpoint) camelContext.hasEndpoint("mock:tick");
>         complete.expectedBodiesReceived("Hello World!");
>         producer.sendBody(start, "Hello World!");
>         complete.assertIsSatisfied();
>     }
> }
> {code}

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Commented] (CAMEL-4371) Add an ability to replace endpoints

Posted by "Ashwin Karpe (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CAMEL-4371?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13095955#comment-13095955 ] 

Ashwin Karpe commented on CAMEL-4371:
-------------------------------------

Hi Hadrian,

I see your point with mutating route segments. It does imply poor design and needs to be addressed differently.

@Claus, I am checking out the advice approach. My primary reluctance to go down that road was based on trying to make the mutation event driven, thereby  issuing endpoint change request only upon explicit event requests, rather than checking periodically via an advice (less overhead).

Please et me know if an event based endpoint mutation approach on the camel context is something you find interesting 

Cheers,

Ashwin...

> Add an ability to replace endpoints
> -----------------------------------
>
>                 Key: CAMEL-4371
>                 URL: https://issues.apache.org/jira/browse/CAMEL-4371
>             Project: Camel
>          Issue Type: Improvement
>          Components: camel-core
>    Affects Versions: 2.8.0
>            Reporter: Sergey Zhemzhitsky
>            Assignee: Ashwin Karpe
>
> Sometimes it can be useful to replace endpoints in the camel context. For example, in unit tests it will not be necessary to define multiple properties files for different environments with placeholders.
> Here is the endpoint strategy to replace endpoints
> {code}
> package org.apache.camel.impl;
> public class ReplaceEndpointStrategy implements EndpointStrategy {
>     private Map<String, String> replacements = Collections.emptyMap();
>     @Override
>     public Endpoint registerEndpoint(String uri, Endpoint endpoint) {
>         CamelContext context = endpoint.getCamelContext();
>         for(Entry<String, String> entry : replacements.entrySet()) {
>             if(EndpointHelper.matchEndpoint(uri, entry.getKey())) {
>                 Endpoint newEndpoint = context.getEndpoint(entry.getValue());
>                 return newEndpoint;
>             }
>         }
>         return endpoint;
>     }
>     public void setReplacements(Map<String, String> replacements) {
>         this.replacements = replacements;
>     }
> }
> {code}
> Here is it can be used from spring
> {code}
> <?xml version="1.0" encoding="UTF-8"?>
> <beans xmlns="http://www.springframework.org/schema/beans"
>     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>     xsi:schemaLocation="
>         http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
>         http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
>     ">
>     <bean class="org.apache.camel.impl.ReplaceEndpointStrategy">
>         <property name="replacements">
>             <map>
>                 <entry key="timer://test*" value="direct://start" />
>                 <entry key="log://timer*" value="mock://tick" />
>             </map>
>         </property>
>     </bean>
>     <camelContext xmlns="http://camel.apache.org/schema/spring">
>         <route>
>             <from uri="timer://testTimer" />
>             <to uri="log://timerTick" />
>         </route>
>     </camelContext>
> </beans>
> {code}
> And the unit test
> {code}
> package org.apache.camel.impl;
> import static org.junit.Assert.assertNotNull;
> import org.apache.camel.CamelContext;
> import org.apache.camel.Endpoint;
> import org.apache.camel.ProducerTemplate;
> import org.apache.camel.component.mock.MockEndpoint;
> import org.junit.Test;
> import org.junit.runner.RunWith;
> import org.springframework.beans.factory.annotation.Autowired;
> import org.springframework.test.context.ContextConfiguration;
> import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
> @RunWith(SpringJUnit4ClassRunner.class)
> @ContextConfiguration
> public class ReplaceEndpointStrategyTest {
>     @Autowired
>     private CamelContext camelContext;
>     @Autowired
>     private ProducerTemplate producer;
>     @Test
>     public void registerEndpoint() throws Exception {
>         assertNotNull("direct:start is null", camelContext.hasEndpoint("direct:start"));
>         assertNotNull("mock:tick is null", camelContext.hasEndpoint("mock:tick"));
>     }
>     @Test
>     public void route() throws Exception {
>         Endpoint start = camelContext.hasEndpoint("direct:start");
>         MockEndpoint complete = (MockEndpoint) camelContext.hasEndpoint("mock:tick");
>         complete.expectedBodiesReceived("Hello World!");
>         producer.sendBody(start, "Hello World!");
>         complete.assertIsSatisfied();
>     }
> }
> {code}

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

Re: [jira] [Commented] (CAMEL-4371) Add an ability to replace endpoints

Posted by Johan Edstrom <se...@gmail.com>.
If you are doing this in service mix, there is a far easier and much more dynamic way of doing this.

What you do is a factory service, this you can write an interface via constructors for in tests, if you after that basically
have the same structure/route but different locations and say CXF strategies, use a managed service factory.

/je

On Sep 1, 2011, at 7:50 PM, Hadrian Zbarcea (JIRA) wrote:

> 
>   [ https://issues.apache.org/jira/browse/CAMEL-4371?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13095716#comment-13095716 ] 
> 
> Hadrian Zbarcea commented on CAMEL-4371:
> ----------------------------------------
> 
> Hi Sergey, I do understand your problem, but I don't think your proposal is the right solution. What you want is already possible in Camel in more than way. Adding this would mean adding yet another way of achieving the same result, arguably not even in the best way. Hard-coding an endpoint URIs in code and then replacing it at runtime with another URI is really not a good practice. Better give them symbolic names that reflect semantics. Until somebody convinces me otherwise I am -1 on this change.
> 
> @Ashwin, one problem with what I think you propose is identifying the boundaries of the route segment. Another point is that if you have to mutate parts of the route, I would argue that there's something wrong with the route design.
> 
>> Add an ability to replace endpoints
>> -----------------------------------
>> 
>>               Key: CAMEL-4371
>>               URL: https://issues.apache.org/jira/browse/CAMEL-4371
>>           Project: Camel
>>        Issue Type: Improvement
>>        Components: camel-core
>>  Affects Versions: 2.8.0
>>          Reporter: Sergey Zhemzhitsky
>>          Assignee: Ashwin Karpe
>> 
>> Sometimes it can be useful to replace endpoints in the camel context. For example, in unit tests it will not be necessary to define multiple properties files for different environments with placeholders.
>> Here is the endpoint strategy to replace endpoints
>> {code}
>> package org.apache.camel.impl;
>> public class ReplaceEndpointStrategy implements EndpointStrategy {
>>   private Map<String, String> replacements = Collections.emptyMap();
>>   @Override
>>   public Endpoint registerEndpoint(String uri, Endpoint endpoint) {
>>       CamelContext context = endpoint.getCamelContext();
>>       for(Entry<String, String> entry : replacements.entrySet()) {
>>           if(EndpointHelper.matchEndpoint(uri, entry.getKey())) {
>>               Endpoint newEndpoint = context.getEndpoint(entry.getValue());
>>               return newEndpoint;
>>           }
>>       }
>>       return endpoint;
>>   }
>>   public void setReplacements(Map<String, String> replacements) {
>>       this.replacements = replacements;
>>   }
>> }
>> {code}
>> Here is it can be used from spring
>> {code}
>> <?xml version="1.0" encoding="UTF-8"?>
>> <beans xmlns="http://www.springframework.org/schema/beans"
>>   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>>   xsi:schemaLocation="
>>       http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
>>       http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
>>   ">
>>   <bean class="org.apache.camel.impl.ReplaceEndpointStrategy">
>>       <property name="replacements">
>>           <map>
>>               <entry key="timer://test*" value="direct://start" />
>>               <entry key="log://timer*" value="mock://tick" />
>>           </map>
>>       </property>
>>   </bean>
>>   <camelContext xmlns="http://camel.apache.org/schema/spring">
>>       <route>
>>           <from uri="timer://testTimer" />
>>           <to uri="log://timerTick" />
>>       </route>
>>   </camelContext>
>> </beans>
>> {code}
>> And the unit test
>> {code}
>> package org.apache.camel.impl;
>> import static org.junit.Assert.assertNotNull;
>> import org.apache.camel.CamelContext;
>> import org.apache.camel.Endpoint;
>> import org.apache.camel.ProducerTemplate;
>> import org.apache.camel.component.mock.MockEndpoint;
>> import org.junit.Test;
>> import org.junit.runner.RunWith;
>> import org.springframework.beans.factory.annotation.Autowired;
>> import org.springframework.test.context.ContextConfiguration;
>> import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
>> @RunWith(SpringJUnit4ClassRunner.class)
>> @ContextConfiguration
>> public class ReplaceEndpointStrategyTest {
>>   @Autowired
>>   private CamelContext camelContext;
>>   @Autowired
>>   private ProducerTemplate producer;
>>   @Test
>>   public void registerEndpoint() throws Exception {
>>       assertNotNull("direct:start is null", camelContext.hasEndpoint("direct:start"));
>>       assertNotNull("mock:tick is null", camelContext.hasEndpoint("mock:tick"));
>>   }
>>   @Test
>>   public void route() throws Exception {
>>       Endpoint start = camelContext.hasEndpoint("direct:start");
>>       MockEndpoint complete = (MockEndpoint) camelContext.hasEndpoint("mock:tick");
>>       complete.expectedBodiesReceived("Hello World!");
>>       producer.sendBody(start, "Hello World!");
>>       complete.assertIsSatisfied();
>>   }
>> }
>> {code}
> 
> --
> This message is automatically generated by JIRA.
> For more information on JIRA, see: http://www.atlassian.com/software/jira
> 
> 


[jira] [Commented] (CAMEL-4371) Add an ability to replace endpoints

Posted by "Hadrian Zbarcea (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CAMEL-4371?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13095716#comment-13095716 ] 

Hadrian Zbarcea commented on CAMEL-4371:
----------------------------------------

Hi Sergey, I do understand your problem, but I don't think your proposal is the right solution. What you want is already possible in Camel in more than way. Adding this would mean adding yet another way of achieving the same result, arguably not even in the best way. Hard-coding an endpoint URIs in code and then replacing it at runtime with another URI is really not a good practice. Better give them symbolic names that reflect semantics. Until somebody convinces me otherwise I am -1 on this change.

@Ashwin, one problem with what I think you propose is identifying the boundaries of the route segment. Another point is that if you have to mutate parts of the route, I would argue that there's something wrong with the route design.

> Add an ability to replace endpoints
> -----------------------------------
>
>                 Key: CAMEL-4371
>                 URL: https://issues.apache.org/jira/browse/CAMEL-4371
>             Project: Camel
>          Issue Type: Improvement
>          Components: camel-core
>    Affects Versions: 2.8.0
>            Reporter: Sergey Zhemzhitsky
>            Assignee: Ashwin Karpe
>
> Sometimes it can be useful to replace endpoints in the camel context. For example, in unit tests it will not be necessary to define multiple properties files for different environments with placeholders.
> Here is the endpoint strategy to replace endpoints
> {code}
> package org.apache.camel.impl;
> public class ReplaceEndpointStrategy implements EndpointStrategy {
>     private Map<String, String> replacements = Collections.emptyMap();
>     @Override
>     public Endpoint registerEndpoint(String uri, Endpoint endpoint) {
>         CamelContext context = endpoint.getCamelContext();
>         for(Entry<String, String> entry : replacements.entrySet()) {
>             if(EndpointHelper.matchEndpoint(uri, entry.getKey())) {
>                 Endpoint newEndpoint = context.getEndpoint(entry.getValue());
>                 return newEndpoint;
>             }
>         }
>         return endpoint;
>     }
>     public void setReplacements(Map<String, String> replacements) {
>         this.replacements = replacements;
>     }
> }
> {code}
> Here is it can be used from spring
> {code}
> <?xml version="1.0" encoding="UTF-8"?>
> <beans xmlns="http://www.springframework.org/schema/beans"
>     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>     xsi:schemaLocation="
>         http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
>         http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
>     ">
>     <bean class="org.apache.camel.impl.ReplaceEndpointStrategy">
>         <property name="replacements">
>             <map>
>                 <entry key="timer://test*" value="direct://start" />
>                 <entry key="log://timer*" value="mock://tick" />
>             </map>
>         </property>
>     </bean>
>     <camelContext xmlns="http://camel.apache.org/schema/spring">
>         <route>
>             <from uri="timer://testTimer" />
>             <to uri="log://timerTick" />
>         </route>
>     </camelContext>
> </beans>
> {code}
> And the unit test
> {code}
> package org.apache.camel.impl;
> import static org.junit.Assert.assertNotNull;
> import org.apache.camel.CamelContext;
> import org.apache.camel.Endpoint;
> import org.apache.camel.ProducerTemplate;
> import org.apache.camel.component.mock.MockEndpoint;
> import org.junit.Test;
> import org.junit.runner.RunWith;
> import org.springframework.beans.factory.annotation.Autowired;
> import org.springframework.test.context.ContextConfiguration;
> import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
> @RunWith(SpringJUnit4ClassRunner.class)
> @ContextConfiguration
> public class ReplaceEndpointStrategyTest {
>     @Autowired
>     private CamelContext camelContext;
>     @Autowired
>     private ProducerTemplate producer;
>     @Test
>     public void registerEndpoint() throws Exception {
>         assertNotNull("direct:start is null", camelContext.hasEndpoint("direct:start"));
>         assertNotNull("mock:tick is null", camelContext.hasEndpoint("mock:tick"));
>     }
>     @Test
>     public void route() throws Exception {
>         Endpoint start = camelContext.hasEndpoint("direct:start");
>         MockEndpoint complete = (MockEndpoint) camelContext.hasEndpoint("mock:tick");
>         complete.expectedBodiesReceived("Hello World!");
>         producer.sendBody(start, "Hello World!");
>         complete.assertIsSatisfied();
>     }
> }
> {code}

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Work started] (CAMEL-4371) Add an ability to replace endpoints

Posted by "Ashwin Karpe (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/CAMEL-4371?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Work on CAMEL-4371 started by Ashwin Karpe.

> Add an ability to replace endpoints
> -----------------------------------
>
>                 Key: CAMEL-4371
>                 URL: https://issues.apache.org/jira/browse/CAMEL-4371
>             Project: Camel
>          Issue Type: Improvement
>          Components: camel-core
>    Affects Versions: 2.8.0
>            Reporter: Sergey Zhemzhitsky
>            Assignee: Ashwin Karpe
>
> Sometimes it can be useful to replace endpoints in the camel context. For example, in unit tests it will not be necessary to define multiple properties files for different environments with placeholders.
> Here is the endpoint strategy to replace endpoints
> {code}
> package org.apache.camel.impl;
> public class ReplaceEndpointStrategy implements EndpointStrategy {
>     private Map<String, String> replacements = Collections.emptyMap();
>     @Override
>     public Endpoint registerEndpoint(String uri, Endpoint endpoint) {
>         CamelContext context = endpoint.getCamelContext();
>         for(Entry<String, String> entry : replacements.entrySet()) {
>             if(EndpointHelper.matchEndpoint(uri, entry.getKey())) {
>                 Endpoint newEndpoint = context.getEndpoint(entry.getValue());
>                 return newEndpoint;
>             }
>         }
>         return endpoint;
>     }
>     public void setReplacements(Map<String, String> replacements) {
>         this.replacements = replacements;
>     }
> }
> {code}
> Here is it can be used from spring
> {code}
> <?xml version="1.0" encoding="UTF-8"?>
> <beans xmlns="http://www.springframework.org/schema/beans"
>     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>     xsi:schemaLocation="
>         http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
>         http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
>     ">
>     <bean class="org.apache.camel.impl.ReplaceEndpointStrategy">
>         <property name="replacements">
>             <map>
>                 <entry key="timer://test*" value="direct://start" />
>                 <entry key="log://timer*" value="mock://tick" />
>             </map>
>         </property>
>     </bean>
>     <camelContext xmlns="http://camel.apache.org/schema/spring">
>         <route>
>             <from uri="timer://testTimer" />
>             <to uri="log://timerTick" />
>         </route>
>     </camelContext>
> </beans>
> {code}
> And the unit test
> {code}
> package org.apache.camel.impl;
> import static org.junit.Assert.assertNotNull;
> import org.apache.camel.CamelContext;
> import org.apache.camel.Endpoint;
> import org.apache.camel.ProducerTemplate;
> import org.apache.camel.component.mock.MockEndpoint;
> import org.junit.Test;
> import org.junit.runner.RunWith;
> import org.springframework.beans.factory.annotation.Autowired;
> import org.springframework.test.context.ContextConfiguration;
> import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
> @RunWith(SpringJUnit4ClassRunner.class)
> @ContextConfiguration
> public class ReplaceEndpointStrategyTest {
>     @Autowired
>     private CamelContext camelContext;
>     @Autowired
>     private ProducerTemplate producer;
>     @Test
>     public void registerEndpoint() throws Exception {
>         assertNotNull("direct:start is null", camelContext.hasEndpoint("direct:start"));
>         assertNotNull("mock:tick is null", camelContext.hasEndpoint("mock:tick"));
>     }
>     @Test
>     public void route() throws Exception {
>         Endpoint start = camelContext.hasEndpoint("direct:start");
>         MockEndpoint complete = (MockEndpoint) camelContext.hasEndpoint("mock:tick");
>         complete.expectedBodiesReceived("Hello World!");
>         producer.sendBody(start, "Hello World!");
>         complete.assertIsSatisfied();
>     }
> }
> {code}

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Issue Comment Edited] (CAMEL-4371) Add an ability to replace endpoints

Posted by "Ashwin Karpe (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CAMEL-4371?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13095555#comment-13095555 ] 

Ashwin Karpe edited comment on CAMEL-4371 at 9/1/11 7:43 PM:
-------------------------------------------------------------

Hi Sergey,

This is an interesting use case. I am planning to put together a RouteMutationStrategy that would cover not only endpoint mutation, but also ability to mutate segments of route. The strategy will have a default implementation and will be both pluggable as well as extensible.

Cheers,

Ashwin... 

      was (Author: akarpe):
    Hi Sergey,

This is an interesting use case. I planning to put together a RouteMutationStrategy that would cover not only endpoint mutation, but also ability to mutate segments of route. The strategy will have a default implementation and will be both pluggable as well as extensible.

Cheers,

Ashwin... 
  
> Add an ability to replace endpoints
> -----------------------------------
>
>                 Key: CAMEL-4371
>                 URL: https://issues.apache.org/jira/browse/CAMEL-4371
>             Project: Camel
>          Issue Type: Improvement
>          Components: camel-core
>    Affects Versions: 2.8.0
>            Reporter: Sergey Zhemzhitsky
>            Assignee: Ashwin Karpe
>
> Sometimes it can be useful to replace endpoints in the camel context. For example, in unit tests it will not be necessary to define multiple properties files for different environments with placeholders.
> Here is the endpoint strategy to replace endpoints
> {code}
> package org.apache.camel.impl;
> public class ReplaceEndpointStrategy implements EndpointStrategy {
>     private Map<String, String> replacements = Collections.emptyMap();
>     @Override
>     public Endpoint registerEndpoint(String uri, Endpoint endpoint) {
>         CamelContext context = endpoint.getCamelContext();
>         for(Entry<String, String> entry : replacements.entrySet()) {
>             if(EndpointHelper.matchEndpoint(uri, entry.getKey())) {
>                 Endpoint newEndpoint = context.getEndpoint(entry.getValue());
>                 return newEndpoint;
>             }
>         }
>         return endpoint;
>     }
>     public void setReplacements(Map<String, String> replacements) {
>         this.replacements = replacements;
>     }
> }
> {code}
> Here is it can be used from spring
> {code}
> <?xml version="1.0" encoding="UTF-8"?>
> <beans xmlns="http://www.springframework.org/schema/beans"
>     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>     xsi:schemaLocation="
>         http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
>         http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
>     ">
>     <bean class="org.apache.camel.impl.ReplaceEndpointStrategy">
>         <property name="replacements">
>             <map>
>                 <entry key="timer://test*" value="direct://start" />
>                 <entry key="log://timer*" value="mock://tick" />
>             </map>
>         </property>
>     </bean>
>     <camelContext xmlns="http://camel.apache.org/schema/spring">
>         <route>
>             <from uri="timer://testTimer" />
>             <to uri="log://timerTick" />
>         </route>
>     </camelContext>
> </beans>
> {code}
> And the unit test
> {code}
> package org.apache.camel.impl;
> import static org.junit.Assert.assertNotNull;
> import org.apache.camel.CamelContext;
> import org.apache.camel.Endpoint;
> import org.apache.camel.ProducerTemplate;
> import org.apache.camel.component.mock.MockEndpoint;
> import org.junit.Test;
> import org.junit.runner.RunWith;
> import org.springframework.beans.factory.annotation.Autowired;
> import org.springframework.test.context.ContextConfiguration;
> import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
> @RunWith(SpringJUnit4ClassRunner.class)
> @ContextConfiguration
> public class ReplaceEndpointStrategyTest {
>     @Autowired
>     private CamelContext camelContext;
>     @Autowired
>     private ProducerTemplate producer;
>     @Test
>     public void registerEndpoint() throws Exception {
>         assertNotNull("direct:start is null", camelContext.hasEndpoint("direct:start"));
>         assertNotNull("mock:tick is null", camelContext.hasEndpoint("mock:tick"));
>     }
>     @Test
>     public void route() throws Exception {
>         Endpoint start = camelContext.hasEndpoint("direct:start");
>         MockEndpoint complete = (MockEndpoint) camelContext.hasEndpoint("mock:tick");
>         complete.expectedBodiesReceived("Hello World!");
>         producer.sendBody(start, "Hello World!");
>         complete.assertIsSatisfied();
>     }
> }
> {code}

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Commented] (CAMEL-4371) Add an ability to replace endpoints

Posted by "Sergey Zhemzhitsky (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CAMEL-4371?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13095823#comment-13095823 ] 

Sergey Zhemzhitsky commented on CAMEL-4371:
-------------------------------------------

Hi Claus,

Advice with seems very powerful. I will try to use it for testing purpose.

@Hadrian, as Claus mentioned it's should be possible to use advice with.

I think this issue should be resolved, because in the camel 2.9 AdviceWithRouteBuilder will be capable to replace route inputs too and in earlier versions of camel, a custom AdviceWithTask can be developed to replace route inputs.

> Add an ability to replace endpoints
> -----------------------------------
>
>                 Key: CAMEL-4371
>                 URL: https://issues.apache.org/jira/browse/CAMEL-4371
>             Project: Camel
>          Issue Type: Improvement
>          Components: camel-core
>    Affects Versions: 2.8.0
>            Reporter: Sergey Zhemzhitsky
>            Assignee: Ashwin Karpe
>
> Sometimes it can be useful to replace endpoints in the camel context. For example, in unit tests it will not be necessary to define multiple properties files for different environments with placeholders.
> Here is the endpoint strategy to replace endpoints
> {code}
> package org.apache.camel.impl;
> public class ReplaceEndpointStrategy implements EndpointStrategy {
>     private Map<String, String> replacements = Collections.emptyMap();
>     @Override
>     public Endpoint registerEndpoint(String uri, Endpoint endpoint) {
>         CamelContext context = endpoint.getCamelContext();
>         for(Entry<String, String> entry : replacements.entrySet()) {
>             if(EndpointHelper.matchEndpoint(uri, entry.getKey())) {
>                 Endpoint newEndpoint = context.getEndpoint(entry.getValue());
>                 return newEndpoint;
>             }
>         }
>         return endpoint;
>     }
>     public void setReplacements(Map<String, String> replacements) {
>         this.replacements = replacements;
>     }
> }
> {code}
> Here is it can be used from spring
> {code}
> <?xml version="1.0" encoding="UTF-8"?>
> <beans xmlns="http://www.springframework.org/schema/beans"
>     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>     xsi:schemaLocation="
>         http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
>         http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
>     ">
>     <bean class="org.apache.camel.impl.ReplaceEndpointStrategy">
>         <property name="replacements">
>             <map>
>                 <entry key="timer://test*" value="direct://start" />
>                 <entry key="log://timer*" value="mock://tick" />
>             </map>
>         </property>
>     </bean>
>     <camelContext xmlns="http://camel.apache.org/schema/spring">
>         <route>
>             <from uri="timer://testTimer" />
>             <to uri="log://timerTick" />
>         </route>
>     </camelContext>
> </beans>
> {code}
> And the unit test
> {code}
> package org.apache.camel.impl;
> import static org.junit.Assert.assertNotNull;
> import org.apache.camel.CamelContext;
> import org.apache.camel.Endpoint;
> import org.apache.camel.ProducerTemplate;
> import org.apache.camel.component.mock.MockEndpoint;
> import org.junit.Test;
> import org.junit.runner.RunWith;
> import org.springframework.beans.factory.annotation.Autowired;
> import org.springframework.test.context.ContextConfiguration;
> import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
> @RunWith(SpringJUnit4ClassRunner.class)
> @ContextConfiguration
> public class ReplaceEndpointStrategyTest {
>     @Autowired
>     private CamelContext camelContext;
>     @Autowired
>     private ProducerTemplate producer;
>     @Test
>     public void registerEndpoint() throws Exception {
>         assertNotNull("direct:start is null", camelContext.hasEndpoint("direct:start"));
>         assertNotNull("mock:tick is null", camelContext.hasEndpoint("mock:tick"));
>     }
>     @Test
>     public void route() throws Exception {
>         Endpoint start = camelContext.hasEndpoint("direct:start");
>         MockEndpoint complete = (MockEndpoint) camelContext.hasEndpoint("mock:tick");
>         complete.expectedBodiesReceived("Hello World!");
>         producer.sendBody(start, "Hello World!");
>         complete.assertIsSatisfied();
>     }
> }
> {code}

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Updated] (CAMEL-4371) Add an ability to replace endpoints

Posted by "Sergey Zhemzhitsky (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/CAMEL-4371?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Sergey Zhemzhitsky updated CAMEL-4371:
--------------------------------------

    Description: 
Sometimes it can be useful to replace endpoints in the camel context. For example, in unit tests it will not be necessary to define multiple properties files for different environments with placeholders.

Here is the endpoint strategy to replace endpoints

{code}
package org.apache.camel.impl;

public class ReplaceEndpointStrategy implements EndpointStrategy {

    private Map<String, String> replacements = Collections.emptyMap();

    @Override
    public Endpoint registerEndpoint(String uri, Endpoint endpoint) {
        CamelContext context = endpoint.getCamelContext();

        for(Entry<String, String> entry : replacements.entrySet()) {
            if(EndpointHelper.matchEndpoint(uri, entry.getKey())) {
                Endpoint newEndpoint = context.getEndpoint(entry.getValue());
                return newEndpoint;
            }
        }

        return endpoint;
    }

    public void setReplacements(Map<String, String> replacements) {
        this.replacements = replacements;
    }

}
{code}

Here is it can be used from spring

{code}
<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
        http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
    ">

    <bean class="org.apache.camel.impl.ReplaceEndpointStrategy">
        <property name="replacements">
            <map>
                <entry key="timer://test*" value="direct://start" />
                <entry key="log://timer*" value="mock://tick" />
            </map>
        </property>
    </bean>

    <camelContext xmlns="http://camel.apache.org/schema/spring">
        <route>
            <from uri="timer://testTimer" />
            <to uri="log://timerTick" />
        </route>
    </camelContext>

</beans>
{code}

And the unit test
{code}
package org.apache.camel.impl;

import static org.junit.Assert.assertNotNull;

import org.apache.camel.CamelContext;
import org.apache.camel.Endpoint;
import org.apache.camel.ProducerTemplate;
import org.apache.camel.component.mock.MockEndpoint;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration
public class ReplaceEndpointStrategyTest {

    @Autowired
    private CamelContext camelContext;

    @Autowired
    private ProducerTemplate producer;

    @Test
    public void registerEndpoint() throws Exception {
        assertNotNull("direct:start is null", camelContext.hasEndpoint("direct:start"));
        assertNotNull("mock:tick is null", camelContext.hasEndpoint("mock:tick"));
    }

    @Test
    public void route() throws Exception {
        Endpoint start = camelContext.hasEndpoint("direct:start");
        MockEndpoint complete = (MockEndpoint) camelContext.hasEndpoint("mock:tick");

        complete.expectedBodiesReceived("Hello World!");
        producer.sendBody(start, "Hello World!");
        complete.assertIsSatisfied();
    }

}
{code}

  was:
Sometimes it can be useful to replace endpoints in the camel context. For example, in unit tests it will not be necessary to define multiple properties file for different environments with placeholders.

Here is the endpoint strategy to replace endpoints

{code}
package org.apache.camel.impl;

public class ReplaceEndpointStrategy implements EndpointStrategy {

    private Map<String, String> replacements = Collections.emptyMap();

    @Override
    public Endpoint registerEndpoint(String uri, Endpoint endpoint) {
        CamelContext context = endpoint.getCamelContext();

        for(Entry<String, String> entry : replacements.entrySet()) {
            if(EndpointHelper.matchEndpoint(uri, entry.getKey())) {
                Endpoint newEndpoint = context.getEndpoint(entry.getValue());
                return newEndpoint;
            }
        }

        return endpoint;
    }

    public void setReplacements(Map<String, String> replacements) {
        this.replacements = replacements;
    }

}
{code}

Here is it can be used from spring

{code}
<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
        http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
    ">

    <bean class="org.apache.camel.impl.ReplaceEndpointStrategy">
        <property name="replacements">
            <map>
                <entry key="timer://test*" value="direct://start" />
                <entry key="log://timer*" value="mock://tick" />
            </map>
        </property>
    </bean>

    <camelContext xmlns="http://camel.apache.org/schema/spring">
        <route>
            <from uri="timer://testTimer" />
            <to uri="log://timerTick" />
        </route>
    </camelContext>

</beans>
{code}

And the unit test
{code}
package org.apache.camel.impl;

import static org.junit.Assert.assertNotNull;

import org.apache.camel.CamelContext;
import org.apache.camel.Endpoint;
import org.apache.camel.ProducerTemplate;
import org.apache.camel.component.mock.MockEndpoint;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration
public class ReplaceEndpointStrategyTest {

    @Autowired
    private CamelContext camelContext;

    @Autowired
    private ProducerTemplate producer;

    @Test
    public void registerEndpoint() throws Exception {
        assertNotNull("direct:start is null", camelContext.hasEndpoint("direct:start"));
        assertNotNull("mock:tick is null", camelContext.hasEndpoint("mock:tick"));
    }

    @Test
    public void route() throws Exception {
        Endpoint start = camelContext.hasEndpoint("direct:start");
        MockEndpoint complete = (MockEndpoint) camelContext.hasEndpoint("mock:tick");

        complete.expectedBodiesReceived("Hello World!");
        producer.sendBody(start, "Hello World!");
        complete.assertIsSatisfied();
    }

}
{code}


> Add an ability to replace endpoints
> -----------------------------------
>
>                 Key: CAMEL-4371
>                 URL: https://issues.apache.org/jira/browse/CAMEL-4371
>             Project: Camel
>          Issue Type: Improvement
>          Components: camel-core
>    Affects Versions: 2.8.0
>            Reporter: Sergey Zhemzhitsky
>
> Sometimes it can be useful to replace endpoints in the camel context. For example, in unit tests it will not be necessary to define multiple properties files for different environments with placeholders.
> Here is the endpoint strategy to replace endpoints
> {code}
> package org.apache.camel.impl;
> public class ReplaceEndpointStrategy implements EndpointStrategy {
>     private Map<String, String> replacements = Collections.emptyMap();
>     @Override
>     public Endpoint registerEndpoint(String uri, Endpoint endpoint) {
>         CamelContext context = endpoint.getCamelContext();
>         for(Entry<String, String> entry : replacements.entrySet()) {
>             if(EndpointHelper.matchEndpoint(uri, entry.getKey())) {
>                 Endpoint newEndpoint = context.getEndpoint(entry.getValue());
>                 return newEndpoint;
>             }
>         }
>         return endpoint;
>     }
>     public void setReplacements(Map<String, String> replacements) {
>         this.replacements = replacements;
>     }
> }
> {code}
> Here is it can be used from spring
> {code}
> <?xml version="1.0" encoding="UTF-8"?>
> <beans xmlns="http://www.springframework.org/schema/beans"
>     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>     xsi:schemaLocation="
>         http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
>         http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
>     ">
>     <bean class="org.apache.camel.impl.ReplaceEndpointStrategy">
>         <property name="replacements">
>             <map>
>                 <entry key="timer://test*" value="direct://start" />
>                 <entry key="log://timer*" value="mock://tick" />
>             </map>
>         </property>
>     </bean>
>     <camelContext xmlns="http://camel.apache.org/schema/spring">
>         <route>
>             <from uri="timer://testTimer" />
>             <to uri="log://timerTick" />
>         </route>
>     </camelContext>
> </beans>
> {code}
> And the unit test
> {code}
> package org.apache.camel.impl;
> import static org.junit.Assert.assertNotNull;
> import org.apache.camel.CamelContext;
> import org.apache.camel.Endpoint;
> import org.apache.camel.ProducerTemplate;
> import org.apache.camel.component.mock.MockEndpoint;
> import org.junit.Test;
> import org.junit.runner.RunWith;
> import org.springframework.beans.factory.annotation.Autowired;
> import org.springframework.test.context.ContextConfiguration;
> import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
> @RunWith(SpringJUnit4ClassRunner.class)
> @ContextConfiguration
> public class ReplaceEndpointStrategyTest {
>     @Autowired
>     private CamelContext camelContext;
>     @Autowired
>     private ProducerTemplate producer;
>     @Test
>     public void registerEndpoint() throws Exception {
>         assertNotNull("direct:start is null", camelContext.hasEndpoint("direct:start"));
>         assertNotNull("mock:tick is null", camelContext.hasEndpoint("mock:tick"));
>     }
>     @Test
>     public void route() throws Exception {
>         Endpoint start = camelContext.hasEndpoint("direct:start");
>         MockEndpoint complete = (MockEndpoint) camelContext.hasEndpoint("mock:tick");
>         complete.expectedBodiesReceived("Hello World!");
>         producer.sendBody(start, "Hello World!");
>         complete.assertIsSatisfied();
>     }
> }
> {code}

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Issue Comment Edited] (CAMEL-4371) Add an ability to replace endpoints

Posted by "Ashwin Karpe (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CAMEL-4371?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13095970#comment-13095970 ] 

Ashwin Karpe edited comment on CAMEL-4371 at 9/2/11 1:32 PM:
-------------------------------------------------------------

@Hadrian, @Claus,

I looked over the AdviceWithRouteBuilder and it seems quite powerful and capable.

It is a bit clunky and does need to be explicitly invoked. Please advise if a simpler event based approach is warranted under the circumstances...

Cheers,

Ashwin... 

      was (Author: akarpe):
    @Hadrian, @Claus,

I looked over the AdviceWithRouteBuilder and it seems quite powerful and capable.

Please advise if an event based approach is warranted under the circumstances...

Cheers,

Ashwin... 
  
> Add an ability to replace endpoints
> -----------------------------------
>
>                 Key: CAMEL-4371
>                 URL: https://issues.apache.org/jira/browse/CAMEL-4371
>             Project: Camel
>          Issue Type: Improvement
>          Components: camel-core
>    Affects Versions: 2.8.0
>            Reporter: Sergey Zhemzhitsky
>            Assignee: Ashwin Karpe
>
> Sometimes it can be useful to replace endpoints in the camel context. For example, in unit tests it will not be necessary to define multiple properties files for different environments with placeholders.
> Here is the endpoint strategy to replace endpoints
> {code}
> package org.apache.camel.impl;
> public class ReplaceEndpointStrategy implements EndpointStrategy {
>     private Map<String, String> replacements = Collections.emptyMap();
>     @Override
>     public Endpoint registerEndpoint(String uri, Endpoint endpoint) {
>         CamelContext context = endpoint.getCamelContext();
>         for(Entry<String, String> entry : replacements.entrySet()) {
>             if(EndpointHelper.matchEndpoint(uri, entry.getKey())) {
>                 Endpoint newEndpoint = context.getEndpoint(entry.getValue());
>                 return newEndpoint;
>             }
>         }
>         return endpoint;
>     }
>     public void setReplacements(Map<String, String> replacements) {
>         this.replacements = replacements;
>     }
> }
> {code}
> Here is it can be used from spring
> {code}
> <?xml version="1.0" encoding="UTF-8"?>
> <beans xmlns="http://www.springframework.org/schema/beans"
>     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>     xsi:schemaLocation="
>         http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
>         http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
>     ">
>     <bean class="org.apache.camel.impl.ReplaceEndpointStrategy">
>         <property name="replacements">
>             <map>
>                 <entry key="timer://test*" value="direct://start" />
>                 <entry key="log://timer*" value="mock://tick" />
>             </map>
>         </property>
>     </bean>
>     <camelContext xmlns="http://camel.apache.org/schema/spring">
>         <route>
>             <from uri="timer://testTimer" />
>             <to uri="log://timerTick" />
>         </route>
>     </camelContext>
> </beans>
> {code}
> And the unit test
> {code}
> package org.apache.camel.impl;
> import static org.junit.Assert.assertNotNull;
> import org.apache.camel.CamelContext;
> import org.apache.camel.Endpoint;
> import org.apache.camel.ProducerTemplate;
> import org.apache.camel.component.mock.MockEndpoint;
> import org.junit.Test;
> import org.junit.runner.RunWith;
> import org.springframework.beans.factory.annotation.Autowired;
> import org.springframework.test.context.ContextConfiguration;
> import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
> @RunWith(SpringJUnit4ClassRunner.class)
> @ContextConfiguration
> public class ReplaceEndpointStrategyTest {
>     @Autowired
>     private CamelContext camelContext;
>     @Autowired
>     private ProducerTemplate producer;
>     @Test
>     public void registerEndpoint() throws Exception {
>         assertNotNull("direct:start is null", camelContext.hasEndpoint("direct:start"));
>         assertNotNull("mock:tick is null", camelContext.hasEndpoint("mock:tick"));
>     }
>     @Test
>     public void route() throws Exception {
>         Endpoint start = camelContext.hasEndpoint("direct:start");
>         MockEndpoint complete = (MockEndpoint) camelContext.hasEndpoint("mock:tick");
>         complete.expectedBodiesReceived("Hello World!");
>         producer.sendBody(start, "Hello World!");
>         complete.assertIsSatisfied();
>     }
> }
> {code}

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Issue Comment Edited] (CAMEL-4371) Add an ability to replace endpoints

Posted by "Ashwin Karpe (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CAMEL-4371?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13095955#comment-13095955 ] 

Ashwin Karpe edited comment on CAMEL-4371 at 9/2/11 1:11 PM:
-------------------------------------------------------------

Hi Hadrian,

I see your point with mutating route segments. It does imply poor design and needs to be addressed differently.

@Claus, I am checking out the advice approach. My primary reluctance to go down that road was based on trying to make the mutation event driven, thereby  issuing endpoint change request only upon explicit event, rather than checking along via an advice (less overhead).

Please et me know if an event based endpoint mutation approach on the camel context is something you find interesting 

Cheers,

Ashwin...

      was (Author: akarpe):
    Hi Hadrian,

I see your point with mutating route segments. It does imply poor design and needs to be addressed differently.

@Claus, I am checking out the advice approach. My primary reluctance to go down that road was based on trying to make the mutation event driven, thereby  issuing endpoint change request only upon explicit event requests, rather than checking periodically via an advice (less overhead).

Please et me know if an event based endpoint mutation approach on the camel context is something you find interesting 

Cheers,

Ashwin...
  
> Add an ability to replace endpoints
> -----------------------------------
>
>                 Key: CAMEL-4371
>                 URL: https://issues.apache.org/jira/browse/CAMEL-4371
>             Project: Camel
>          Issue Type: Improvement
>          Components: camel-core
>    Affects Versions: 2.8.0
>            Reporter: Sergey Zhemzhitsky
>            Assignee: Ashwin Karpe
>
> Sometimes it can be useful to replace endpoints in the camel context. For example, in unit tests it will not be necessary to define multiple properties files for different environments with placeholders.
> Here is the endpoint strategy to replace endpoints
> {code}
> package org.apache.camel.impl;
> public class ReplaceEndpointStrategy implements EndpointStrategy {
>     private Map<String, String> replacements = Collections.emptyMap();
>     @Override
>     public Endpoint registerEndpoint(String uri, Endpoint endpoint) {
>         CamelContext context = endpoint.getCamelContext();
>         for(Entry<String, String> entry : replacements.entrySet()) {
>             if(EndpointHelper.matchEndpoint(uri, entry.getKey())) {
>                 Endpoint newEndpoint = context.getEndpoint(entry.getValue());
>                 return newEndpoint;
>             }
>         }
>         return endpoint;
>     }
>     public void setReplacements(Map<String, String> replacements) {
>         this.replacements = replacements;
>     }
> }
> {code}
> Here is it can be used from spring
> {code}
> <?xml version="1.0" encoding="UTF-8"?>
> <beans xmlns="http://www.springframework.org/schema/beans"
>     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>     xsi:schemaLocation="
>         http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
>         http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
>     ">
>     <bean class="org.apache.camel.impl.ReplaceEndpointStrategy">
>         <property name="replacements">
>             <map>
>                 <entry key="timer://test*" value="direct://start" />
>                 <entry key="log://timer*" value="mock://tick" />
>             </map>
>         </property>
>     </bean>
>     <camelContext xmlns="http://camel.apache.org/schema/spring">
>         <route>
>             <from uri="timer://testTimer" />
>             <to uri="log://timerTick" />
>         </route>
>     </camelContext>
> </beans>
> {code}
> And the unit test
> {code}
> package org.apache.camel.impl;
> import static org.junit.Assert.assertNotNull;
> import org.apache.camel.CamelContext;
> import org.apache.camel.Endpoint;
> import org.apache.camel.ProducerTemplate;
> import org.apache.camel.component.mock.MockEndpoint;
> import org.junit.Test;
> import org.junit.runner.RunWith;
> import org.springframework.beans.factory.annotation.Autowired;
> import org.springframework.test.context.ContextConfiguration;
> import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
> @RunWith(SpringJUnit4ClassRunner.class)
> @ContextConfiguration
> public class ReplaceEndpointStrategyTest {
>     @Autowired
>     private CamelContext camelContext;
>     @Autowired
>     private ProducerTemplate producer;
>     @Test
>     public void registerEndpoint() throws Exception {
>         assertNotNull("direct:start is null", camelContext.hasEndpoint("direct:start"));
>         assertNotNull("mock:tick is null", camelContext.hasEndpoint("mock:tick"));
>     }
>     @Test
>     public void route() throws Exception {
>         Endpoint start = camelContext.hasEndpoint("direct:start");
>         MockEndpoint complete = (MockEndpoint) camelContext.hasEndpoint("mock:tick");
>         complete.expectedBodiesReceived("Hello World!");
>         producer.sendBody(start, "Hello World!");
>         complete.assertIsSatisfied();
>     }
> }
> {code}

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Assigned] (CAMEL-4371) Add an ability to replace endpoints

Posted by "Ashwin Karpe (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/CAMEL-4371?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Ashwin Karpe reassigned CAMEL-4371:
-----------------------------------

    Assignee: Ashwin Karpe

> Add an ability to replace endpoints
> -----------------------------------
>
>                 Key: CAMEL-4371
>                 URL: https://issues.apache.org/jira/browse/CAMEL-4371
>             Project: Camel
>          Issue Type: Improvement
>          Components: camel-core
>    Affects Versions: 2.8.0
>            Reporter: Sergey Zhemzhitsky
>            Assignee: Ashwin Karpe
>
> Sometimes it can be useful to replace endpoints in the camel context. For example, in unit tests it will not be necessary to define multiple properties files for different environments with placeholders.
> Here is the endpoint strategy to replace endpoints
> {code}
> package org.apache.camel.impl;
> public class ReplaceEndpointStrategy implements EndpointStrategy {
>     private Map<String, String> replacements = Collections.emptyMap();
>     @Override
>     public Endpoint registerEndpoint(String uri, Endpoint endpoint) {
>         CamelContext context = endpoint.getCamelContext();
>         for(Entry<String, String> entry : replacements.entrySet()) {
>             if(EndpointHelper.matchEndpoint(uri, entry.getKey())) {
>                 Endpoint newEndpoint = context.getEndpoint(entry.getValue());
>                 return newEndpoint;
>             }
>         }
>         return endpoint;
>     }
>     public void setReplacements(Map<String, String> replacements) {
>         this.replacements = replacements;
>     }
> }
> {code}
> Here is it can be used from spring
> {code}
> <?xml version="1.0" encoding="UTF-8"?>
> <beans xmlns="http://www.springframework.org/schema/beans"
>     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>     xsi:schemaLocation="
>         http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
>         http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
>     ">
>     <bean class="org.apache.camel.impl.ReplaceEndpointStrategy">
>         <property name="replacements">
>             <map>
>                 <entry key="timer://test*" value="direct://start" />
>                 <entry key="log://timer*" value="mock://tick" />
>             </map>
>         </property>
>     </bean>
>     <camelContext xmlns="http://camel.apache.org/schema/spring">
>         <route>
>             <from uri="timer://testTimer" />
>             <to uri="log://timerTick" />
>         </route>
>     </camelContext>
> </beans>
> {code}
> And the unit test
> {code}
> package org.apache.camel.impl;
> import static org.junit.Assert.assertNotNull;
> import org.apache.camel.CamelContext;
> import org.apache.camel.Endpoint;
> import org.apache.camel.ProducerTemplate;
> import org.apache.camel.component.mock.MockEndpoint;
> import org.junit.Test;
> import org.junit.runner.RunWith;
> import org.springframework.beans.factory.annotation.Autowired;
> import org.springframework.test.context.ContextConfiguration;
> import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
> @RunWith(SpringJUnit4ClassRunner.class)
> @ContextConfiguration
> public class ReplaceEndpointStrategyTest {
>     @Autowired
>     private CamelContext camelContext;
>     @Autowired
>     private ProducerTemplate producer;
>     @Test
>     public void registerEndpoint() throws Exception {
>         assertNotNull("direct:start is null", camelContext.hasEndpoint("direct:start"));
>         assertNotNull("mock:tick is null", camelContext.hasEndpoint("mock:tick"));
>     }
>     @Test
>     public void route() throws Exception {
>         Endpoint start = camelContext.hasEndpoint("direct:start");
>         MockEndpoint complete = (MockEndpoint) camelContext.hasEndpoint("mock:tick");
>         complete.expectedBodiesReceived("Hello World!");
>         producer.sendBody(start, "Hello World!");
>         complete.assertIsSatisfied();
>     }
> }
> {code}

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Commented] (CAMEL-4371) Add an ability to replace endpoints

Posted by "Ashwin Karpe (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CAMEL-4371?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13095555#comment-13095555 ] 

Ashwin Karpe commented on CAMEL-4371:
-------------------------------------

Hi Sergey,

This is an interesting use case. I planning to put together a RouteMutationStrategy that would cover not only endpoint mutation, but also ability to mutate segments of route. The strategy will have a default implementation and will be both pluggable as well as extensible.

Cheers,

Ashwin... 

> Add an ability to replace endpoints
> -----------------------------------
>
>                 Key: CAMEL-4371
>                 URL: https://issues.apache.org/jira/browse/CAMEL-4371
>             Project: Camel
>          Issue Type: Improvement
>          Components: camel-core
>    Affects Versions: 2.8.0
>            Reporter: Sergey Zhemzhitsky
>            Assignee: Ashwin Karpe
>
> Sometimes it can be useful to replace endpoints in the camel context. For example, in unit tests it will not be necessary to define multiple properties files for different environments with placeholders.
> Here is the endpoint strategy to replace endpoints
> {code}
> package org.apache.camel.impl;
> public class ReplaceEndpointStrategy implements EndpointStrategy {
>     private Map<String, String> replacements = Collections.emptyMap();
>     @Override
>     public Endpoint registerEndpoint(String uri, Endpoint endpoint) {
>         CamelContext context = endpoint.getCamelContext();
>         for(Entry<String, String> entry : replacements.entrySet()) {
>             if(EndpointHelper.matchEndpoint(uri, entry.getKey())) {
>                 Endpoint newEndpoint = context.getEndpoint(entry.getValue());
>                 return newEndpoint;
>             }
>         }
>         return endpoint;
>     }
>     public void setReplacements(Map<String, String> replacements) {
>         this.replacements = replacements;
>     }
> }
> {code}
> Here is it can be used from spring
> {code}
> <?xml version="1.0" encoding="UTF-8"?>
> <beans xmlns="http://www.springframework.org/schema/beans"
>     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>     xsi:schemaLocation="
>         http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
>         http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
>     ">
>     <bean class="org.apache.camel.impl.ReplaceEndpointStrategy">
>         <property name="replacements">
>             <map>
>                 <entry key="timer://test*" value="direct://start" />
>                 <entry key="log://timer*" value="mock://tick" />
>             </map>
>         </property>
>     </bean>
>     <camelContext xmlns="http://camel.apache.org/schema/spring">
>         <route>
>             <from uri="timer://testTimer" />
>             <to uri="log://timerTick" />
>         </route>
>     </camelContext>
> </beans>
> {code}
> And the unit test
> {code}
> package org.apache.camel.impl;
> import static org.junit.Assert.assertNotNull;
> import org.apache.camel.CamelContext;
> import org.apache.camel.Endpoint;
> import org.apache.camel.ProducerTemplate;
> import org.apache.camel.component.mock.MockEndpoint;
> import org.junit.Test;
> import org.junit.runner.RunWith;
> import org.springframework.beans.factory.annotation.Autowired;
> import org.springframework.test.context.ContextConfiguration;
> import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
> @RunWith(SpringJUnit4ClassRunner.class)
> @ContextConfiguration
> public class ReplaceEndpointStrategyTest {
>     @Autowired
>     private CamelContext camelContext;
>     @Autowired
>     private ProducerTemplate producer;
>     @Test
>     public void registerEndpoint() throws Exception {
>         assertNotNull("direct:start is null", camelContext.hasEndpoint("direct:start"));
>         assertNotNull("mock:tick is null", camelContext.hasEndpoint("mock:tick"));
>     }
>     @Test
>     public void route() throws Exception {
>         Endpoint start = camelContext.hasEndpoint("direct:start");
>         MockEndpoint complete = (MockEndpoint) camelContext.hasEndpoint("mock:tick");
>         complete.expectedBodiesReceived("Hello World!");
>         producer.sendBody(start, "Hello World!");
>         complete.assertIsSatisfied();
>     }
> }
> {code}

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Commented] (CAMEL-4371) Add an ability to replace endpoints

Posted by "Claus Ibsen (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CAMEL-4371?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13095783#comment-13095783 ] 

Claus Ibsen commented on CAMEL-4371:
------------------------------------

The advice with can do a lot of route manipulation for testing purposes.
http://camel.apache.org/advicewith.html

I recommend to leverage this approach.

> Add an ability to replace endpoints
> -----------------------------------
>
>                 Key: CAMEL-4371
>                 URL: https://issues.apache.org/jira/browse/CAMEL-4371
>             Project: Camel
>          Issue Type: Improvement
>          Components: camel-core
>    Affects Versions: 2.8.0
>            Reporter: Sergey Zhemzhitsky
>            Assignee: Ashwin Karpe
>
> Sometimes it can be useful to replace endpoints in the camel context. For example, in unit tests it will not be necessary to define multiple properties files for different environments with placeholders.
> Here is the endpoint strategy to replace endpoints
> {code}
> package org.apache.camel.impl;
> public class ReplaceEndpointStrategy implements EndpointStrategy {
>     private Map<String, String> replacements = Collections.emptyMap();
>     @Override
>     public Endpoint registerEndpoint(String uri, Endpoint endpoint) {
>         CamelContext context = endpoint.getCamelContext();
>         for(Entry<String, String> entry : replacements.entrySet()) {
>             if(EndpointHelper.matchEndpoint(uri, entry.getKey())) {
>                 Endpoint newEndpoint = context.getEndpoint(entry.getValue());
>                 return newEndpoint;
>             }
>         }
>         return endpoint;
>     }
>     public void setReplacements(Map<String, String> replacements) {
>         this.replacements = replacements;
>     }
> }
> {code}
> Here is it can be used from spring
> {code}
> <?xml version="1.0" encoding="UTF-8"?>
> <beans xmlns="http://www.springframework.org/schema/beans"
>     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>     xsi:schemaLocation="
>         http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
>         http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
>     ">
>     <bean class="org.apache.camel.impl.ReplaceEndpointStrategy">
>         <property name="replacements">
>             <map>
>                 <entry key="timer://test*" value="direct://start" />
>                 <entry key="log://timer*" value="mock://tick" />
>             </map>
>         </property>
>     </bean>
>     <camelContext xmlns="http://camel.apache.org/schema/spring">
>         <route>
>             <from uri="timer://testTimer" />
>             <to uri="log://timerTick" />
>         </route>
>     </camelContext>
> </beans>
> {code}
> And the unit test
> {code}
> package org.apache.camel.impl;
> import static org.junit.Assert.assertNotNull;
> import org.apache.camel.CamelContext;
> import org.apache.camel.Endpoint;
> import org.apache.camel.ProducerTemplate;
> import org.apache.camel.component.mock.MockEndpoint;
> import org.junit.Test;
> import org.junit.runner.RunWith;
> import org.springframework.beans.factory.annotation.Autowired;
> import org.springframework.test.context.ContextConfiguration;
> import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
> @RunWith(SpringJUnit4ClassRunner.class)
> @ContextConfiguration
> public class ReplaceEndpointStrategyTest {
>     @Autowired
>     private CamelContext camelContext;
>     @Autowired
>     private ProducerTemplate producer;
>     @Test
>     public void registerEndpoint() throws Exception {
>         assertNotNull("direct:start is null", camelContext.hasEndpoint("direct:start"));
>         assertNotNull("mock:tick is null", camelContext.hasEndpoint("mock:tick"));
>     }
>     @Test
>     public void route() throws Exception {
>         Endpoint start = camelContext.hasEndpoint("direct:start");
>         MockEndpoint complete = (MockEndpoint) camelContext.hasEndpoint("mock:tick");
>         complete.expectedBodiesReceived("Hello World!");
>         producer.sendBody(start, "Hello World!");
>         complete.assertIsSatisfied();
>     }
> }
> {code}

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira