Author: ningjiang
Date: Fri Sep 9 12:30:08 2011
New Revision: 1167131
URL: http://svn.apache.org/viewvc?rev=1167131&view=rev
Log:
CAMEL-4430 Using the ClientFactoryBean instead of ProxyFactoryBean to create
the Client for the CxfProducer
Modified:
camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfBlueprintEndpoint.java
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
Modified:
camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfBlueprintEndpoint.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfBlueprintEndpoint.java?rev=1167131&r1=1167130&r2=1167131&view=diff
==============================================================================
---
camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfBlueprintEndpoint.java
(original)
+++
camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfBlueprintEndpoint.java
Fri Sep 9 12:30:08 2011
@@ -66,45 +66,6 @@ public class CxfBlueprintEndpoint extend
// Package private methods
//
-------------------------------------------------------------------------
- /**
- * Create a CXF client object
- */
- Client createClient() throws Exception {
-
- // get service class
- if (getDataFormat().equals(DataFormat.POJO)) {
- ObjectHelper.notNull(getServiceClass(),
CxfConstants.SERVICE_CLASS);
- }
-
- if (getWsdlURL() == null && getServiceClass() == null) {
- // no WSDL and serviceClass specified, set our default serviceClass
-
setServiceClass(org.apache.camel.component.cxf.DefaultSEI.class.getName());
- setDefaultOperationNamespace(CxfConstants.DISPATCH_NAMESPACE);
-
setDefaultOperationName(CxfConstants.DISPATCH_DEFAULT_OPERATION_NAMESPACE);
- if (getDataFormat().equals(DataFormat.PAYLOAD)) {
- setSkipPayloadMessagePartCheck(true);
- }
- }
-
- Class<?> cls = null;
- if (getServiceClass() != null) {
- //Fool CXF classes to load their settings and bindings from the
CXF bundle
- cls = getServiceClass();
- // create client factory bean
- ClientProxyFactoryBean factoryBean = createClientFactoryBean(cls);
- // setup client factory bean
- setupClientFactoryBean(factoryBean, cls);
- return ((ClientProxy)
Proxy.getInvocationHandler(factoryBean.create())).getClient();
- } else {
- checkName(getPortName(), "endpoint/port name");
- checkName(getServiceName(), "service name");
-
- ClientFactoryBean factoryBean = createClientFactoryBean();
- // setup client factory bean
- setupClientFactoryBean(factoryBean);
- return factoryBean.create();
- }
- }
protected void checkName(Object value, String name) {
if (ObjectHelper.isEmpty(value)) {
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=1167131&r1=1167130&r2=1167131&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
Fri Sep 9 12:30:08 2011
@@ -17,6 +17,7 @@
package org.apache.camel.component.cxf;
import java.lang.reflect.Proxy;
+import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
@@ -26,6 +27,14 @@ import javax.xml.namespace.QName;
import javax.xml.ws.WebServiceProvider;
import javax.xml.ws.handler.Handler;
+import org.apache.cxf.common.injection.ResourceInjector;
+import org.apache.cxf.jaxws.context.WebServiceContextResourceResolver;
+import org.apache.cxf.jaxws.handler.AnnotationHandlerChainBuilder;
+import org.apache.cxf.jaxws.support.JaxWsEndpointImpl;
+import org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean;
+import org.apache.cxf.resource.DefaultResourceManager;
+import org.apache.cxf.resource.ResourceManager;
+import org.apache.cxf.resource.ResourceResolver;
import org.w3c.dom.Element;
import org.apache.camel.CamelContext;
@@ -256,21 +265,21 @@ public class CxfEndpoint extends Default
* Create a client factory bean object. Notice that the serviceClass
<b>must</b> be
* an interface.
*/
- protected ClientProxyFactoryBean createClientFactoryBean(Class<?> cls)
throws CamelException {
+ protected ClientFactoryBean createClientFactoryBean(Class<?> cls) throws
CamelException {
if (CxfEndpointUtils.hasWebServiceAnnotation(cls)) {
- return new JaxWsProxyFactoryBean(new JaxWsClientFactoryBean() {
+ return new JaxWsClientFactoryBean() {
@Override
protected Client createClient(Endpoint ep) {
return new CamelCxfClientImpl(getBus(), ep);
}
- });
+ };
} else {
- return new ClientProxyFactoryBean(new ClientFactoryBean() {
+ return new ClientFactoryBean() {
@Override
protected Client createClient(Endpoint ep) {
return new CamelCxfClientImpl(getBus(), ep);
}
- });
+ };
}
}
@@ -305,83 +314,47 @@ public class CxfEndpoint extends Default
return busFactory.createBus();
}
- /**
- * Populate a client factory bean
- */
- protected void setupClientFactoryBean(ClientProxyFactoryBean factoryBean,
Class<?> cls) {
- // service class
- factoryBean.setServiceClass(cls);
-
- factoryBean.setInInterceptors(in);
- factoryBean.setOutInterceptors(out);
- factoryBean.setOutFaultInterceptors(outFault);
- factoryBean.setInFaultInterceptors(inFault);
- factoryBean.setFeatures(features);
-
- if (factoryBean instanceof JaxWsProxyFactoryBean && handlers != null) {
- ((JaxWsProxyFactoryBean)factoryBean).setHandlers(handlers);
- }
- if (getTransportId() != null) {
- factoryBean.setTransportId(getTransportId());
- }
- if (getBindingId() != null) {
- factoryBean.setBindingId(getBindingId());
- }
-
- // address
- factoryBean.setAddress(getAddress());
-
- // wsdl url
- if (getWsdlURL() != null) {
- factoryBean.setWsdlURL(getWsdlURL());
- }
+ protected void setupHandlers(ClientFactoryBean factoryBean, Client client)
{
- // service name qname
- if (getServiceName() != null) {
- factoryBean.setServiceName(getServiceName());
- }
-
- // port name qname
- if (getPortName() != null) {
- factoryBean.setEndpointName(getPortName());
- }
-
- // apply feature here
- if (getDataFormat() == DataFormat.MESSAGE) {
- factoryBean.getFeatures().add(new MessageDataFormatFeature());
- } else if (getDataFormat() == DataFormat.PAYLOAD) {
- factoryBean.getFeatures().add(new PayLoadDataFormatFeature());
- factoryBean.setDataBinding(new HybridSourceDataBinding());
- }
-
- if (loggingFeatureEnabled) {
- factoryBean.getFeatures().add(new LoggingFeature());
- }
-
- // set the document-literal wrapped style
- if (getWrappedStyle() != null) {
- factoryBean.getServiceFactory().setWrapped(getWrappedStyle());
- }
-
- // set the properties on CxfProxyFactoryBean
- if (getProperties() != null) {
- if (factoryBean.getProperties() != null) {
- // add to existing properties
- factoryBean.getProperties().putAll(getProperties());
- } else {
- factoryBean.setProperties(getProperties());
+ if (factoryBean instanceof JaxWsClientFactoryBean && handlers != null)
{
+ AnnotationHandlerChainBuilder builder = new
AnnotationHandlerChainBuilder();
+ JaxWsServiceFactoryBean sf =
(JaxWsServiceFactoryBean)factoryBean.getServiceFactory();
+ List<Handler> chain = new ArrayList<Handler>(handlers);
+
+
chain.addAll(builder.buildHandlerChainFromClass(sf.getServiceClass(),
+
sf.getEndpointInfo().getName(),
+
sf.getServiceQName(),
+
factoryBean.getBindingId()));
+
+ if (!chain.isEmpty()) {
+ ResourceManager resourceManager =
getBus().getExtension(ResourceManager.class);
+ List<ResourceResolver> resolvers =
resourceManager.getResourceResolvers();
+ resourceManager = new DefaultResourceManager(resolvers);
+ resourceManager.addResourceResolver(new
WebServiceContextResourceResolver());
+ ResourceInjector injector = new
ResourceInjector(resourceManager);
+ for (Handler h : chain) {
+ if (Proxy.isProxyClass(h.getClass()) && getServiceClass()
!= null) {
+ injector.inject(h, getServiceClass());
+ injector.construct(h, getServiceClass());
+ } else {
+ injector.inject(h);
+ injector.construct(h);
+ }
+ }
}
- LOG.debug("ClientProxyFactoryBean: {} added properties: {}",
factoryBean, properties);
- }
- factoryBean.setBus(getBus());
+
((JaxWsEndpointImpl)client.getEndpoint()).getJaxwsBinding().setHandlerChain(chain);
+ }
}
- protected void setupClientFactoryBean(ClientFactoryBean factoryBean) {
+ protected void setupClientFactoryBean(ClientFactoryBean factoryBean,
Class<?> cls) {
+ if (cls != null) {
+ factoryBean.setServiceClass(cls);
+ }
factoryBean.setInInterceptors(in);
factoryBean.setOutInterceptors(out);
factoryBean.setOutFaultInterceptors(outFault);
- factoryBean.setInFaultInterceptors(inFault);
+ factoryBean.setInFaultInterceptors(inFault);
factoryBean.setFeatures(features);
factoryBean.setTransportId(transportId);
factoryBean.setBindingId(bindingId);
@@ -451,17 +424,22 @@ public class CxfEndpoint extends Default
if (getServiceClass() != null) {
cls = getServiceClass();
// create client factory bean
- ClientProxyFactoryBean factoryBean = createClientFactoryBean(cls);
+ ClientFactoryBean factoryBean = createClientFactoryBean(cls);
// setup client factory bean
setupClientFactoryBean(factoryBean, cls);
- return ((ClientProxy)
Proxy.getInvocationHandler(factoryBean.create())).getClient();
+ Client client = factoryBean.create();
+ // setup the handlers
+ setupHandlers(factoryBean, client);
+ return client;
} else {
+ // create the client without service class
+
checkName(portName, "endpoint/port name");
checkName(serviceName, "service name");
ClientFactoryBean factoryBean = createClientFactoryBean();
// setup client factory bean
- setupClientFactoryBean(factoryBean);
+ setupClientFactoryBean(factoryBean, null);
return factoryBean.create();
}
}
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=1167131&r1=1167130&r2=1167131&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
Fri Sep 9 12:30:08 2011
@@ -110,7 +110,7 @@ public class CxfSpringEndpoint extends C
if (cls != null) {
// create client factory bean
- ClientProxyFactoryBean factoryBean = createClientFactoryBean(cls);
+ ClientFactoryBean factoryBean = createClientFactoryBean(cls);
// setup client factory bean
setupClientFactoryBean(factoryBean, cls);
@@ -130,13 +130,16 @@ public class CxfSpringEndpoint extends C
factoryBean.setEndpointName(new QName(getEndpointNamespace(),
getEndpointLocalName()));
}
- return
((ClientProxy)Proxy.getInvocationHandler(factoryBean.create())).getClient();
+ Client client = factoryBean.create();
+ // setup the handlers
+ setupHandlers(factoryBean, client);
+ return client;
} else {
ClientFactoryBean factoryBean = createClientFactoryBean();
// setup client factory bean
- setupClientFactoryBean(factoryBean);
+ setupClientFactoryBean(factoryBean, null);
// fill in values that have not been filled.
QName serviceQName = null;