The CamelContext API have that method String resolvePropertyPlaceholders(String text) throws Exception;
So you do *not* need to depend on DefaultCamelContext, but just CamelContext interface. On Tue, Aug 30, 2011 at 11:19 AM, <ningji...@apache.org> wrote: > Author: ningjiang > Date: Tue Aug 30 09:19:11 2011 > New Revision: 1163153 > > URL: http://svn.apache.org/viewvc?rev=1163153&view=rev > Log: > CAMEL-3510 cxf namespace supports Camel properties placeholder out of the box > > Added: > > camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/spring/testEndpoint.properties > (with props) > Modified: > > camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfEndpoint.java > > camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/spring/CxfEndpointBeanDefinitionParser.java > > camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/spring/CxfEndpointBeansRouterTest.java > > camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/spring/CxfEndpointBeansRouter.xml > > Modified: > camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfEndpoint.java > URL: > http://svn.apache.org/viewvc/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfEndpoint.java?rev=1163153&r1=1163152&r2=1163153&view=diff > ============================================================================== > --- > camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfEndpoint.java > (original) > +++ > camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfEndpoint.java > Tue Aug 30 09:19:11 2011 > @@ -27,14 +27,10 @@ import javax.xml.namespace.QName; > import javax.xml.ws.WebServiceProvider; > import javax.xml.ws.handler.Handler; > > +import org.apache.camel.*; > +import org.apache.camel.impl.DefaultCamelContext; > import org.w3c.dom.Element; > > -import org.apache.camel.CamelContext; > -import org.apache.camel.CamelException; > -import org.apache.camel.Consumer; > -import org.apache.camel.Processor; > -import org.apache.camel.Producer; > -import org.apache.camel.Service; > import org.apache.camel.component.cxf.common.header.CxfHeaderFilterStrategy; > import org.apache.camel.component.cxf.common.message.CxfConstants; > import org.apache.camel.component.cxf.feature.MessageDataFormatFeature; > @@ -90,6 +86,8 @@ public class CxfEndpoint extends Default > private Class<?> serviceClass; > private QName portName; > private QName serviceName; > + private String portNameString; > + private String serviceNameString; > private String defaultOperationName; > private String defaultOperationNamespace; > // This is for invoking the CXFClient with wrapped parameters of > unwrapped parameters > @@ -189,11 +187,11 @@ public class CxfEndpoint extends Default > if (sfb instanceof JaxWsServerFactoryBean && handlers != null) { > ((JaxWsServerFactoryBean)sfb).setHandlers(handlers); > } > - if (transportId != null) { > - sfb.setTransportId(transportId); > + if (getTransportId() != null) { > + sfb.setTransportId(getTransportId()); > } > - if (bindingId != null) { > - sfb.setBindingId(bindingId); > + if (getBindingId() != null) { > + sfb.setBindingId(getBindingId()); > } > > // wsdl url > @@ -319,11 +317,11 @@ public class CxfEndpoint extends Default > if (factoryBean instanceof JaxWsProxyFactoryBean && handlers != null) > { > ((JaxWsProxyFactoryBean)factoryBean).setHandlers(handlers); > } > - if (transportId != null) { > - factoryBean.setTransportId(transportId); > + if (getTransportId() != null) { > + factoryBean.setTransportId(getTransportId()); > } > - if (bindingId != null) { > - factoryBean.setBindingId(bindingId); > + if (getBindingId() != null) { > + factoryBean.setBindingId(getBindingId()); > } > > // address > @@ -502,6 +500,18 @@ public class CxfEndpoint extends Default > return answer; > } > > + protected String resolvePropertyPlaceholders(String str) { > + try { > + if (getCamelContext() != null) { > + return > ((DefaultCamelContext)getCamelContext()).resolvePropertyPlaceholders(str); > + } else { > + return str; > + } > + } catch (Exception ex) { > + throw new RuntimeCamelException(ex); > + } > + } > + > // Properties > // > ------------------------------------------------------------------------- > > @@ -514,7 +524,7 @@ public class CxfEndpoint extends Default > } > > public String getPublishedEndpointUrl() { > - return publishedEndpointUrl; > + return resolvePropertyPlaceholders(publishedEndpointUrl); > } > > public void setPublishedEndpointUrl(String url) { > @@ -522,7 +532,7 @@ public class CxfEndpoint extends Default > } > > public String getWsdlURL() { > - return wsdlURL; > + return resolvePropertyPlaceholders(wsdlURL); > } > > public void setWsdlURL(String url) { > @@ -542,11 +552,11 @@ public class CxfEndpoint extends Default > } > > public void setServiceClass(String type) throws ClassNotFoundException { > - serviceClass = ClassLoaderUtils.loadClass(type, getClass()); > + serviceClass = > ClassLoaderUtils.loadClass(resolvePropertyPlaceholders(type), getClass()); > } > > public void setServiceNameString(String service) { > - serviceName = QName.valueOf(service); > + serviceNameString = service; > } > > public void setServiceName(QName service) { > @@ -554,10 +564,16 @@ public class CxfEndpoint extends Default > } > > public QName getServiceName() { > + if (serviceName == null && serviceNameString != null) { > + serviceName = > QName.valueOf(resolvePropertyPlaceholders(serviceNameString)); > + } > return serviceName; > } > > public QName getPortName() { > + if (portName == null && portNameString != null) { > + portName = > QName.valueOf(resolvePropertyPlaceholders(portNameString)); > + } > return portName; > } > > @@ -566,7 +582,7 @@ public class CxfEndpoint extends Default > } > > public void setEndpointNameString(String port) { > - portName = QName.valueOf(port); > + portNameString = port; > } > > public void setEndpointName(QName port) { > @@ -574,7 +590,7 @@ public class CxfEndpoint extends Default > } > > public String getDefaultOperationName() { > - return defaultOperationName; > + return resolvePropertyPlaceholders(defaultOperationName); > } > > public void setDefaultOperationName(String name) { > @@ -582,7 +598,7 @@ public class CxfEndpoint extends Default > } > > public String getDefaultOperationNamespace() { > - return defaultOperationNamespace; > + return resolvePropertyPlaceholders(defaultOperationNamespace); > } > > public void setDefaultOperationNamespace(String namespace) { > @@ -737,7 +753,7 @@ public class CxfEndpoint extends Default > } > > public String getAddress() { > - return address; > + return resolvePropertyPlaceholders(address); > } > > public void setMtomEnabled(boolean mtomEnabled) { > @@ -859,7 +875,7 @@ public class CxfEndpoint extends Default > } > > public String getTransportId() { > - return transportId; > + return resolvePropertyPlaceholders(transportId); > } > > public void setTransportId(String transportId) { > @@ -867,7 +883,7 @@ public class CxfEndpoint extends Default > } > > public String getBindingId() { > - return bindingId; > + return resolvePropertyPlaceholders(bindingId); > } > > public void setBindingId(String bindingId) { > > Modified: > camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/spring/CxfEndpointBeanDefinitionParser.java > URL: > http://svn.apache.org/viewvc/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/spring/CxfEndpointBeanDefinitionParser.java?rev=1163153&r1=1163152&r2=1163153&view=diff > ============================================================================== > --- > camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/spring/CxfEndpointBeanDefinitionParser.java > (original) > +++ > camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/spring/CxfEndpointBeanDefinitionParser.java > Tue Aug 30 09:19:11 2011 > @@ -35,7 +35,8 @@ public class CxfEndpointBeanDefinitionPa > } > > private boolean isSpringPlaceHolder(String value) { > - if (value != null && value.startsWith("${") && value.endsWith("}")) { > + if (value != null && (value.startsWith("${") && value.endsWith("}")) > + || value.startsWith("{{") && value.endsWith("}}")) { > return true; > } > return false; > > Modified: > camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/spring/CxfEndpointBeansRouterTest.java > URL: > http://svn.apache.org/viewvc/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/spring/CxfEndpointBeansRouterTest.java?rev=1163153&r1=1163152&r2=1163153&view=diff > ============================================================================== > --- > camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/spring/CxfEndpointBeansRouterTest.java > (original) > +++ > camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/spring/CxfEndpointBeansRouterTest.java > Tue Aug 30 09:19:11 2011 > @@ -30,6 +30,8 @@ import org.apache.cxf.transport.http.HTT > > import org.junit.Test; > > +import javax.xml.namespace.QName; > + > public class CxfEndpointBeansRouterTest extends > AbstractSpringBeanTestSupport { > > protected String[] getApplicationContextFiles() { > @@ -67,5 +69,21 @@ public class CxfEndpointBeansRouterTest > ex instanceof org.apache.cxf.interceptor.Fault > || ex instanceof HTTPException); > } > + > + @Test > + public void testCxfBeanWithCamelPropertiesHolder() throws Exception { > + // get the camelContext from application context > + CamelContext camelContext = (CamelContext) ctx.getBean("camel"); > + CxfEndpoint testEndpoint = > (CxfEndpoint)camelContext.getEndpoint("cxf:bean:testEndpoint"); > + QName endpointName = > QName.valueOf("{http://org.apache.camel.component.cxf}myEndpoint"); > + QName serviceName = > QName.valueOf("{http://org.apache.camel.component.cxf}myService"); > + > + assertEquals("Got a wrong address", > "http://localhost:9000/testEndpoint", testEndpoint.getAddress()); > + assertEquals("Got a wrong bindingId", > "http://schemas.xmlsoap.org/wsdl/soap12/", testEndpoint.getBindingId()); > + assertEquals("Got a wrong transportId", > "http://cxf.apache.org/transports/http", testEndpoint.getTransportId()); > + assertEquals("Got a wrong endpointName", endpointName, > testEndpoint.getPortName()); > + assertEquals("Got a wrong WsdlURL", "wsdl/test.wsdl", > testEndpoint.getWsdlURL()); > + assertEquals("Got a wrong serviceName", serviceName, > testEndpoint.getServiceName()); > + } > > } > > Modified: > camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/spring/CxfEndpointBeansRouter.xml > URL: > http://svn.apache.org/viewvc/camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/spring/CxfEndpointBeansRouter.xml?rev=1163153&r1=1163152&r2=1163153&view=diff > ============================================================================== > --- > camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/spring/CxfEndpointBeansRouter.xml > (original) > +++ > camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/spring/CxfEndpointBeansRouter.xml > Tue Aug 30 09:19:11 2011 > @@ -32,8 +32,13 @@ > <cxf:cxfEndpoint id="routerEndpoint" > address="http://localhost:${CXFTestSupport.port1}/CxfEndpointBeansRouterTest/router" > serviceClass="org.apache.camel.component.cxf.HelloService"/> > > + <cxf:cxfEndpoint id="serviceEndpoint" > address="http://localhost:${CXFTestSupport.port2}/CxfEndpointBeansRouterTest/service" > + serviceClass="org.apache.camel.component.cxf.HelloService"/> > > - <cxf:cxfEndpoint id="serviceEndpoint" > address="http://localhost:${CXFTestSupport.port2}/CxfEndpointBeansRouterTest/helloworld" > + <cxf:cxfEndpoint id="testEndpoint" address="{{address}}" > + bindingId="{{bindingId}}" transportId="{{transportId}}" > + serviceName="{{serviceName}}" endpointName="{{endpointName}}" > + wsdlURL="{{wsdlURL}}" > serviceClass="org.apache.camel.component.cxf.HelloService"/> > > <!-- Setting the http conduit policy --> > @@ -46,6 +51,7 @@ > <bean id="myProcessor" > class="org.apache.camel.component.cxf.spring.MyProcessor"/> > > <camelContext id="camel" xmlns="http://camel.apache.org/schema/spring"> > + <propertyPlaceholder id="properties" > location="org/apache/camel/component/cxf/spring/testEndpoint.properties"/> > <route> > <from uri="cxf:bean:routerEndpoint" /> > <process ref="myProcessor" /> > > Added: > camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/spring/testEndpoint.properties > URL: > http://svn.apache.org/viewvc/camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/spring/testEndpoint.properties?rev=1163153&view=auto > ============================================================================== > --- > camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/spring/testEndpoint.properties > (added) > +++ > camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/spring/testEndpoint.properties > Tue Aug 30 09:19:11 2011 > @@ -0,0 +1,26 @@ > +# > +# > +# 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. > +# > +# > +address=http://localhost:9000/testEndpoint > +bindingId=http://schemas.xmlsoap.org/wsdl/soap12/ > +transportId=http://cxf.apache.org/transports/http > +serviceName={http://org.apache.camel.component.cxf}myService > +endpointName={http://org.apache.camel.component.cxf}myEndpoint > +wsdlURL=wsdl/test.wsdl > \ No newline at end of file > > Propchange: > camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/spring/testEndpoint.properties > ------------------------------------------------------------------------------ > svn:eol-style = native > > Propchange: > camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/spring/testEndpoint.properties > ------------------------------------------------------------------------------ > svn:keywords = Rev Date > > Propchange: > camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/spring/testEndpoint.properties > ------------------------------------------------------------------------------ > svn:mime-type = text/plain > > > -- Claus Ibsen ----------------- FuseSource Email: cib...@fusesource.com Web: http://fusesource.com Twitter: davsclaus, fusenews Blog: http://davsclaus.blogspot.com/ Author of Camel in Action: http://www.manning.com/ibsen/