You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ni...@apache.org on 2009/07/08 16:33:48 UTC
svn commit: r792163 - in /camel/trunk/components/camel-cxf/src:
main/java/org/apache/camel/component/cxf/
test/java/org/apache/camel/component/cxf/ test/resources/
test/resources/org/apache/camel/component/cxf/
Author: ningjiang
Date: Wed Jul 8 14:33:47 2009
New Revision: 792163
URL: http://svn.apache.org/viewvc?rev=792163&view=rev
Log:
CAMEL-1810 applied patch with thanks to Seumas
Added:
camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/WSDLServiceFactoryBean.java (with props)
camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CXFWsdlOnlyTest.java (with props)
camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/WsdlOnlyBeans.xml (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/CxfSpringEndpoint.java
camel/trunk/components/camel-cxf/src/test/resources/person.wsdl
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=792163&r1=792162&r2=792163&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 Wed Jul 8 14:33:47 2009
@@ -17,6 +17,7 @@
package org.apache.camel.component.cxf;
import java.lang.reflect.Proxy;
+import java.util.HashMap;
import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;
@@ -40,6 +41,7 @@
import org.apache.cxf.BusFactory;
import org.apache.cxf.common.classloader.ClassLoaderUtils;
import org.apache.cxf.common.util.ClassHelper;
+import org.apache.cxf.configuration.security.AuthorizationPolicy;
import org.apache.cxf.endpoint.Client;
import org.apache.cxf.endpoint.ClientImpl;
import org.apache.cxf.endpoint.Endpoint;
@@ -148,9 +150,66 @@
* Create a client factory bean object. Notice that the serviceClass <b>must</b> be
* an interface.
*/
- protected ClientProxyFactoryBean createClientFactoryBean(Class<?> cls) throws CamelException {
+ protected ClientProxyFactoryBean createClientFactoryBean(Class<?> cls) throws CamelException {
+ if (cls == null && !getDataFormat().equals(DataFormat.POJO)) {
+ return new ClientProxyFactoryBean(new ClientFactoryBean(new WSDLServiceFactoryBean()) {
+ @Override
+ protected void createClient(Endpoint ep) {
+ setClient(new CamelCxfClientImpl(getBus(), ep));
+ }
+
+ protected void initializeAnnotationInterceptors(Endpoint ep, Class<?> cls) {
+ // Do nothing here
+ }
+
+ })
+ { // Override the ClientProxyFactoryBean's create method
+ // Don't create the proxy object
+ public Object create() {
+
+ if (getProperties() == null) {
+ setProperties(new HashMap<String, Object>());
+ }
+
+ if (getUsername() != null) {
+ AuthorizationPolicy authPolicy = new AuthorizationPolicy();
+ authPolicy.setUserName(getUsername());
+ authPolicy.setPassword(getPassword());
+ getProperties().put(AuthorizationPolicy.class.getName(), authPolicy);
+ }
+
+ initFeatures();
+ getClientFactoryBean().setProperties(getProperties());
+
+ if (bus != null) {
+ getClientFactoryBean().setBus(bus);
+ }
+
+ if (getDataBinding() != null) {
+ getClientFactoryBean().setDataBinding(getDataBinding());
+ }
+
+ Client c = getClientFactoryBean().create();
+ if (getInInterceptors() != null) {
+ c.getInInterceptors().addAll(getInInterceptors());
+ }
+ if (getOutInterceptors() != null) {
+ c.getOutInterceptors().addAll(getOutInterceptors());
+ }
+ if (getInFaultInterceptors() != null) {
+ c.getInFaultInterceptors().addAll(getInFaultInterceptors());
+ }
+ if (getOutFaultInterceptors() != null) {
+ c.getOutFaultInterceptors().addAll(getOutFaultInterceptors());
+ }
+
+ return c;
+ }
+ };
+ }
+
// quick null point check for serviceClass
- ObjectHelper.notNull(cls, "Please provide endpoint service interface class");
+ //ObjectHelper.notNull(cls, "Please provide endpoint service interface class");
if (CxfEndpointUtils.hasWebServiceAnnotation(cls)) {
return new JaxWsProxyFactoryBean(new JaxWsClientFactoryBean() {
@@ -179,7 +238,7 @@
*/
protected void setupClientFactoryBean(ClientProxyFactoryBean factoryBean, Class<?> cls) {
// quick null point check for serviceClass
- ObjectHelper.notNull(cls, "Please provide endpoint service interface class");
+ //ObjectHelper.notNull(cls, "Please provide endpoint service interface class");
// service class
factoryBean.setServiceClass(cls);
@@ -248,7 +307,10 @@
// Shouldn't use CxfEndpointUtils.getServerFactoryBean(cls) as it is for
// CxfSoapComponent
ServerFactoryBean answer = null;
- if (CxfEndpointUtils.hasWebServiceAnnotation(cls)) {
+
+ if (cls == null) {
+ answer = new ServerFactoryBean(new WSDLServiceFactoryBean());
+ } else if (CxfEndpointUtils.hasWebServiceAnnotation(cls)) {
answer = new JaxWsServerFactoryBean();
} else {
answer = new ServerFactoryBean();
Modified: camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfSpringEndpoint.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfSpringEndpoint.java?rev=792163&r1=792162&r2=792163&view=diff
==============================================================================
--- camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfSpringEndpoint.java (original)
+++ camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfSpringEndpoint.java Wed Jul 8 14:33:47 2009
@@ -105,8 +105,11 @@
Client createClient() throws Exception {
// get service class
- Class<?> cls = getSEIClass();
- ObjectHelper.notNull(cls, CxfConstants.SERVICE_CLASS);
+ Class<?> cls = getSEIClass();
+
+ if (getDataFormat().equals(DataFormat.POJO)) {
+ ObjectHelper.notNull(cls, CxfConstants.SERVICE_CLASS);
+ }
// create client factory bean
ClientProxyFactoryBean factoryBean = createClientFactoryBean(cls);
@@ -132,6 +135,10 @@
factoryBean.setEndpointName(new QName(getEndpointNamespace(), getEndpointLocalName()));
}
+ if (cls == null) {
+ return (Client)factoryBean.create();
+ }
+
return ((ClientProxy)Proxy.getInvocationHandler(factoryBean.create())).getClient();
}
@@ -143,14 +150,20 @@
ServerFactoryBean createServerFactoryBean() throws Exception {
// get service class
- Class<?> cls = getSEIClass();
- ObjectHelper.notNull(cls, CxfConstants.SERVICE_CLASS);
+ Class<?> cls = getSEIClass();
// create server factory bean
// Shouldn't use CxfEndpointUtils.getServerFactoryBean(cls) as it is for
// CxfSoapComponent
ServerFactoryBean answer = null;
- if (CxfEndpointUtils.hasWebServiceAnnotation(cls)) {
+
+ if (cls == null) {
+ if (!getDataFormat().equals(DataFormat.POJO)) {
+ answer = new ServerFactoryBean(new WSDLServiceFactoryBean());
+ } else {
+ ObjectHelper.notNull(cls, CxfConstants.SERVICE_CLASS);
+ }
+ } else if (CxfEndpointUtils.hasWebServiceAnnotation(cls)) {
answer = new JaxWsServerFactoryBean();
} else {
answer = new ServerFactoryBean();
Added: camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/WSDLServiceFactoryBean.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/WSDLServiceFactoryBean.java?rev=792163&view=auto
==============================================================================
--- camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/WSDLServiceFactoryBean.java (added)
+++ camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/WSDLServiceFactoryBean.java Wed Jul 8 14:33:47 2009
@@ -0,0 +1,101 @@
+/**
+ * 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.
+ */
+package org.apache.camel.component.cxf;
+
+import javax.xml.namespace.QName;
+
+import org.apache.cxf.binding.AbstractBindingFactory;
+import org.apache.cxf.binding.soap.interceptor.CheckFaultInterceptor;
+import org.apache.cxf.binding.soap.interceptor.MustUnderstandInterceptor;
+import org.apache.cxf.binding.soap.interceptor.ReadHeadersInterceptor;
+import org.apache.cxf.binding.soap.interceptor.SoapActionInInterceptor;
+import org.apache.cxf.binding.soap.interceptor.SoapHeaderInterceptor;
+import org.apache.cxf.binding.soap.interceptor.SoapHeaderOutFilterInterceptor;
+import org.apache.cxf.binding.soap.interceptor.SoapOutInterceptor;
+import org.apache.cxf.binding.soap.interceptor.SoapPreProtocolOutInterceptor;
+import org.apache.cxf.interceptor.AttachmentInInterceptor;
+import org.apache.cxf.interceptor.AttachmentOutInterceptor;
+import org.apache.cxf.interceptor.StaxInInterceptor;
+import org.apache.cxf.interceptor.StaxOutInterceptor;
+import org.apache.cxf.interceptor.URIMappingInterceptor;
+import org.apache.cxf.service.Service;
+import org.apache.cxf.service.factory.ReflectionServiceFactoryBean;
+import org.apache.cxf.service.model.EndpointInfo;
+import org.apache.cxf.service.model.ServiceInfo;
+import org.apache.cxf.wsdl11.WSDLServiceFactory;
+
+public class WSDLServiceFactoryBean extends ReflectionServiceFactoryBean {
+ private QName serviceName;
+ private QName endpointName;
+
+ @Override
+ public Service create() {
+
+ WSDLServiceFactory factory = new WSDLServiceFactory(getBus(), getWsdlURL(), getServiceQName());
+
+ setService(factory.create());
+ initializeDefaultInterceptors();
+ //disable the date interceptors
+ updateEndpointInfors();
+ createEndpoints();
+
+ return getService();
+ }
+
+
+ private void updateEndpointInfors() {
+ Service service = getService();
+
+ for (ServiceInfo inf : service.getServiceInfos()) {
+ for (EndpointInfo ei : inf.getEndpoints()) {
+ //setup the endpoint address
+ ei.setAddress("local://" + ei.getService().getName().toString() + "/" + ei.getName().getLocalPart());
+ // working as the dispatch mode, the binding factory will not add interceptor
+ //ei.getBinding().setProperty(AbstractBindingFactory.DATABINDING_DISABLED, Boolean.TRUE);
+ }
+ }
+
+ }
+
+ protected void checkServiceClassAnnotations(Class<?> sc) {
+ // do nothing here
+ }
+
+ public void setServiceName(QName name) {
+ serviceName = name;
+ }
+
+ public String getServiceName() {
+ return serviceName.toString();
+ }
+
+ public QName getServiceQName() {
+ return serviceName;
+ }
+
+ public QName getEndpointName() {
+ // get the endpoint name if it is not set
+ if (endpointName == null) {
+ endpointName = getService().getEndpoints().keySet().iterator().next();
+ }
+ return endpointName;
+ }
+
+ public void setEndpointName(QName name) {
+ endpointName = name;
+ }
+}
Propchange: camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/WSDLServiceFactoryBean.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/WSDLServiceFactoryBean.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CXFWsdlOnlyTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CXFWsdlOnlyTest.java?rev=792163&view=auto
==============================================================================
--- camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CXFWsdlOnlyTest.java (added)
+++ camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CXFWsdlOnlyTest.java Wed Jul 8 14:33:47 2009
@@ -0,0 +1,100 @@
+/**
+ * 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.
+ */
+package org.apache.camel.component.cxf;
+
+import java.net.URL;
+
+import javax.xml.namespace.QName;
+import javax.xml.ws.Endpoint;
+import javax.xml.ws.Holder;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.component.cxf.spring.CxfEndpointBean;
+import org.apache.camel.test.junit4.CamelSpringTestSupport;
+import org.apache.camel.util.ObjectHelper;
+import org.apache.camel.wsdl_first.Person;
+import org.apache.camel.wsdl_first.PersonImpl;
+import org.apache.camel.wsdl_first.PersonService;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+
+
+public class CXFWsdlOnlyTest extends CamelSpringTestSupport {
+
+ protected ClassPathXmlApplicationContext createApplicationContext() {
+ return new ClassPathXmlApplicationContext("org/apache/camel/component/cxf/WsdlOnlyBeans.xml");
+ }
+
+ protected void assertValidContext(CamelContext context) {
+ assertNotNull("No context found!", context);
+ }
+
+ @BeforeClass
+ public static void startService() {
+ Object implementor = new PersonImpl();
+ String address = "http://localhost:9000/PersonService/";
+ Endpoint.publish(address, implementor);
+
+ address = "http://localhost:9001/PersonService/";
+ Endpoint.publish(address, implementor);
+ }
+
+ @Test
+ public void testCreateWSDLOnly() {
+ CxfEndpointBean ep = getMandatoryBean(CxfEndpointBean.class, "serviceEndpoint");
+
+ }
+
+ @Test
+ public void testRoutes() throws Exception {
+ URL wsdlURL = getClass().getClassLoader().getResource("person.wsdl");
+ PersonService ss = new PersonService(wsdlURL, new QName("http://camel.apache.org/wsdl-first",
+ "PersonService"));
+ Person client = ss.getSoap();
+ Holder<String> personId = new Holder<String>();
+ personId.value = "hello";
+ Holder<String> ssn = new Holder<String>();
+ Holder<String> name = new Holder<String>();
+ client.getPerson(personId, ssn, name);
+ System.out.println("NAME: " + name.value);
+ assertEquals("Bonjour", name.value);
+
+ Person client2 = ss.getSoap2();
+ Holder<String> personId2 = new Holder<String>();
+ personId2.value = "hello";
+ Holder<String> ssn2 = new Holder<String>();
+ Holder<String> name2 = new Holder<String>();
+ client.getPerson(personId2, ssn2, name2);
+ System.out.println("NAME: " + name2.value);
+ assertEquals("Bonjour", name2.value);
+ }
+
+ public <T> T getMandatoryBean(Class<T> type, String name) {
+ Object value = applicationContext.getBean(name);
+ assertNotNull("No spring bean found for name <" + name + ">", value);
+ if (type.isInstance(value)) {
+ return type.cast(value);
+ } else {
+ fail("Spring bean <" + name + "> is not an instanceof " + type.getName() + " but is of type "
+ + ObjectHelper.className(value));
+ return null;
+ }
+ }
+
+}
Propchange: camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CXFWsdlOnlyTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CXFWsdlOnlyTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/WsdlOnlyBeans.xml
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/WsdlOnlyBeans.xml?rev=792163&view=auto
==============================================================================
--- camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/WsdlOnlyBeans.xml (added)
+++ camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/WsdlOnlyBeans.xml Wed Jul 8 14:33:47 2009
@@ -0,0 +1,79 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:cxf="http://camel.apache.org/schema/cxf"
+ xmlns:camel="http://camel.apache.org/schema/spring"
+ xsi:schemaLocation="
+ http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
+ http://camel.apache.org/schema/cxf http://camel.apache.org/schema/cxf/camel-cxf.xsd
+ http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
+ ">
+
+
+ <cxf:cxfEndpoint id="routerEndpoint" address="http://localhost:8092/PersonService/"
+ wsdlURL="person.wsdl"
+ endpointName="person:soap"
+ serviceName="person:PersonService"
+ xmlns:person="http://camel.apache.org/wsdl-first">
+ </cxf:cxfEndpoint>
+
+
+ <cxf:cxfEndpoint id="serviceEndpoint" address="http://localhost:9000/PersonService/"
+ wsdlURL="person.wsdl"
+ endpointName="person:soap"
+ serviceName="person:PersonService"
+ xmlns:person="http://camel.apache.org/wsdl-first">
+ </cxf:cxfEndpoint>
+
+ <cxf:cxfEndpoint id="routerEndpoint2" address="http://localhost:8093/PersonService/"
+ wsdlURL="person.wsdl"
+ endpointName="person:soap"
+ serviceName="person:PersonService"
+ xmlns:person="http://camel.apache.org/wsdl-first">
+ </cxf:cxfEndpoint>
+
+
+ <cxf:cxfEndpoint id="serviceEndpoint2" address="http://localhost:9001/PersonService/"
+ wsdlURL="person.wsdl"
+ endpointName="person:soap"
+ serviceName="person:PersonService"
+ xmlns:person="http://camel.apache.org/wsdl-first">
+ </cxf:cxfEndpoint>
+
+
+ <!-- setup our error handler as the deal letter channel -->
+ <bean id="errorHandler" class="org.apache.camel.builder.DeadLetterChannelBuilder">
+ <property name="deadLetterUri" value="mock:error"/>
+ </bean>
+
+ <bean id="processor" class="org.apache.camel.processor.Logger"/>
+
+ <camelContext errorHandlerRef="errorHandler" id="camel" xmlns="http://camel.apache.org/schema/spring">
+ <route>
+ <from uri="cxf:bean:routerEndpoint?dataFormat=MESSAGE" />
+ <to uri="cxf:bean:serviceEndpoint?dataFormat=MESSAGE" />
+ <process ref="processor"/>
+ </route>
+ <route>
+ <from uri="cxf:bean:routerEndpoint2?dataFormat=PAYLOAD" />
+ <to uri="cxf:bean:serviceEndpoint2?dataFormat=PAYLOAD" />
+ <process ref="processor"/>
+ </route>
+ </camelContext>
+</beans>
Propchange: camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/WsdlOnlyBeans.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/WsdlOnlyBeans.xml
------------------------------------------------------------------------------
svn:keywords = Rev Date
Propchange: camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/WsdlOnlyBeans.xml
------------------------------------------------------------------------------
svn:mime-type = text/xml
Modified: camel/trunk/components/camel-cxf/src/test/resources/person.wsdl
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cxf/src/test/resources/person.wsdl?rev=792163&r1=792162&r2=792163&view=diff
==============================================================================
--- camel/trunk/components/camel-cxf/src/test/resources/person.wsdl (original)
+++ camel/trunk/components/camel-cxf/src/test/resources/person.wsdl Wed Jul 8 14:33:47 2009
@@ -103,6 +103,9 @@
<wsdl:port binding="tns:PersonSOAPBinding" name="soap">
<soap:address location="http://localhost:8092/PersonService/" />
</wsdl:port>
+ <wsdl:port binding="tns:PersonSOAPBinding" name="soap2">
+ <soap:address location="http://localhost:8093/PersonService/" />
+ </wsdl:port>
</wsdl:service>
</wsdl:definitions>