Return-Path: X-Original-To: apmail-camel-issues-archive@minotaur.apache.org Delivered-To: apmail-camel-issues-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id C789FD96F for ; Fri, 6 Jul 2012 08:57:36 +0000 (UTC) Received: (qmail 55458 invoked by uid 500); 6 Jul 2012 08:57:36 -0000 Delivered-To: apmail-camel-issues-archive@camel.apache.org Received: (qmail 55396 invoked by uid 500); 6 Jul 2012 08:57:36 -0000 Mailing-List: contact issues-help@camel.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@camel.apache.org Delivered-To: mailing list issues@camel.apache.org Received: (qmail 55379 invoked by uid 99); 6 Jul 2012 08:57:36 -0000 Received: from issues-vm.apache.org (HELO issues-vm) (140.211.11.160) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 06 Jul 2012 08:57:36 +0000 Received: from isssues-vm.apache.org (localhost [127.0.0.1]) by issues-vm (Postfix) with ESMTP id B3F9D14035F for ; Fri, 6 Jul 2012 08:57:35 +0000 (UTC) Date: Fri, 6 Jul 2012 08:57:33 +0000 (UTC) From: "Claus Ibsen (JIRA)" To: issues@camel.apache.org Message-ID: <1026382414.13277.1341565055739.JavaMail.jiratomcat@issues-vm> Subject: [jira] [Resolved] (CAMEL-4371) Add an ability to replace endpoints MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 [ https://issues.apache.org/jira/browse/CAMEL-4371?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ] Claus Ibsen resolved CAMEL-4371. -------------------------------- Resolution: Won't Fix Fix Version/s: 2.10.0 The current functionality in adwice with and whatnot can already do this > 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 > Fix For: 2.10.0 > > > 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 replacements = Collections.emptyMap(); > @Override > public Endpoint registerEndpoint(String uri, Endpoint endpoint) { > CamelContext context = endpoint.getCamelContext(); > for(Entry entry : replacements.entrySet()) { > if(EndpointHelper.matchEndpoint(uri, entry.getKey())) { > Endpoint newEndpoint = context.getEndpoint(entry.getValue()); > return newEndpoint; > } > } > return endpoint; > } > public void setReplacements(Map replacements) { > this.replacements = replacements; > } > } > {code} > Here is it can be used from spring > {code} > > 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 > "> > > > > > > > > > > > > > > > > {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. If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa For more information on JIRA, see: http://www.atlassian.com/software/jira