camel-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Ashwin Karpe (JIRA)" <j...@apache.org>
Subject [jira] [Issue Comment Edited] (CAMEL-4371) Add an ability to replace endpoints
Date Thu, 01 Sep 2011 19:44:10 GMT

    [ 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

        

Mime
View raw message