Return-Path: X-Original-To: apmail-camel-dev-archive@www.apache.org Delivered-To: apmail-camel-dev-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 6710978F4 for ; Fri, 2 Sep 2011 04:12:12 +0000 (UTC) Received: (qmail 22744 invoked by uid 500); 2 Sep 2011 04:12:10 -0000 Delivered-To: apmail-camel-dev-archive@camel.apache.org Received: (qmail 21634 invoked by uid 500); 2 Sep 2011 04:11:52 -0000 Mailing-List: contact dev-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 dev@camel.apache.org Received: (qmail 21615 invoked by uid 99); 2 Sep 2011 04:11:47 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 02 Sep 2011 04:11:47 +0000 X-ASF-Spam-Status: No, hits=-0.7 required=5.0 tests=FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,SPF_PASS,T_TO_NO_BRKTS_FREEMAIL X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of seijoed@gmail.com designates 209.85.210.173 as permitted sender) Received: from [209.85.210.173] (HELO mail-iy0-f173.google.com) (209.85.210.173) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 02 Sep 2011 04:11:40 +0000 Received: by iabz25 with SMTP id z25so3944130iab.32 for ; Thu, 01 Sep 2011 21:11:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=content-type:mime-version:subject:from:in-reply-to:date :content-transfer-encoding:message-id:references:to:x-mailer; bh=od3mw7akd9Sfe7qpjqiy4/1J3x2gzZiyQ5qjiHWDbWY=; b=gJ3mO7zXidWhu314Hz8tmbvmrNmRLnCMcVhxyLH/TEQXDfmgRQCnt7cJdgbquS725G vrGcBE19XlRLteDeBUDeSNN/jQaO9BIdzrpD2Gt/jgnHPv26W7zntIr6ChxPJqVFrjyh +sVM2mBQj+fvx5Ydpz1SjZYW5gKi9jIXeMIGY= Received: by 10.42.148.134 with SMTP id r6mr523108icv.396.1314936678122; Thu, 01 Sep 2011 21:11:18 -0700 (PDT) Received: from [172.20.30.238] ([64.197.120.3]) by mx.google.com with ESMTPS id v16sm1108400ibe.0.2011.09.01.21.11.16 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 01 Sep 2011 21:11:17 -0700 (PDT) Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Apple Message framework v1244.3) Subject: Re: [jira] [Commented] (CAMEL-4371) Add an ability to replace endpoints From: Johan Edstrom In-Reply-To: <1968656924.9095.1314928209834.JavaMail.tomcat@hel.zones.apache.org> Date: Thu, 1 Sep 2011 22:11:15 -0600 Content-Transfer-Encoding: quoted-printable Message-Id: <7E005E72-CD4A-4192-A4D9-1F75B6B710A6@gmail.com> References: <1968656924.9095.1314928209834.JavaMail.tomcat@hel.zones.apache.org> To: dev@camel.apache.org X-Mailer: Apple Mail (2.1244.3) X-Virus-Checked: Checked by ClamAV on apache.org 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: >=20 > [ = https://issues.apache.org/jira/browse/CAMEL-4371?page=3Dcom.atlassian.jira= .plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=3D13095716= #comment-13095716 ]=20 >=20 > Hadrian Zbarcea commented on CAMEL-4371: > ---------------------------------------- >=20 > 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. >=20 > @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. >=20 >> Add an ability to replace endpoints >> ----------------------------------- >>=20 >> 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 >>=20 >> 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 =3D = Collections.emptyMap(); >> @Override >> public Endpoint registerEndpoint(String uri, Endpoint endpoint) { >> CamelContext context =3D endpoint.getCamelContext(); >> for(Entry entry : replacements.entrySet()) { >> if(EndpointHelper.matchEndpoint(uri, entry.getKey())) { >> Endpoint newEndpoint =3D = context.getEndpoint(entry.getValue()); >> return newEndpoint; >> } >> } >> return endpoint; >> } >> public void setReplacements(Map replacements) { >> this.replacements =3D replacements; >> } >> } >> {code} >> Here is it can be used from spring >> {code} >> >> > xmlns:xsi=3D"http://www.w3.org/2001/XMLSchema-instance" >> xsi:schemaLocation=3D" >> 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 =3D camelContext.hasEndpoint("direct:start"); >> MockEndpoint complete =3D (MockEndpoint) = camelContext.hasEndpoint("mock:tick"); >> complete.expectedBodiesReceived("Hello World!"); >> producer.sendBody(start, "Hello World!"); >> complete.assertIsSatisfied(); >> } >> } >> {code} >=20 > -- > This message is automatically generated by JIRA. > For more information on JIRA, see: = http://www.atlassian.com/software/jira >=20 >=20