You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by wt...@apache.org on 2009/01/19 02:48:42 UTC
svn commit: r735592 [1/2] - in /activemq/camel/trunk: ./
components/camel-cxf/src/main/java/org/apache/camel/component/cxf/
components/camel-cxf/src/main/java/org/apache/camel/component/cxf/converter/
components/camel-cxf/src/main/java/org/apache/camel...
Author: wtam
Date: Sun Jan 18 17:48:41 2009
New Revision: 735592
URL: http://svn.apache.org/viewvc?rev=735592&view=rev
Log:
[CAMEL-1256] Clean up camel-cxf, [CAMEL-1239] add set bus option for looking up bus from registry for no-spring endpint, [CAMEL-1254]camel-cxf: URI option for serviceClass does not support lookup in registry
Added:
activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfPayload.java (with props)
activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfSpringEndpoint.java (with props)
activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/DefaultCxfBinding.java (with props)
Removed:
activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CamelInvoker.java
activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/MessageInvoker.java
activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/feature/MessageInvokerInterceptor.java
activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/interceptors/FakeBindingOperationInfo.java
activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/invoker/
Modified:
activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfBinding.java
activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfComponent.java
activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfConsumer.java
activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfEndpoint.java
activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfExchange.java
activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfHeaderFilterStrategy.java
activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfMessage.java
activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfProducer.java
activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfSoapBinding.java
activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfSoapProducer.java
activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/DataFormat.java
activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/converter/CxfConverter.java
activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/feature/AbstractDataFormatFeature.java
activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/feature/MessageDataFormatFeature.java
activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/feature/PayLoadDataFormatFeature.java
activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/interceptors/AbstractMessageInInterceptor.java
activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/interceptors/AbstractMessageOutInterceptor.java
activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/interceptors/DOMInInterceptor.java
activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/interceptors/DOMOutInterceptor.java
activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/interceptors/FaultOutInterceptor.java
activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/interceptors/RawMessageContentRedirectInterceptor.java
activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/interceptors/SoapMessageInInterceptor.java
activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/interceptors/SoapMessageOutInterceptor.java
activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/interceptors/XMLMessageInInterceptor.java
activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/interceptors/XMLMessageOutInterceptor.java
activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/spring/CxfEndpointBean.java
activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/transport/CamelConduit.java
activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/util/CxfEndpointUtils.java
activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/util/CxfHeaderHelper.java
activemq/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfEndpointTest.java
activemq/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfGreeterPayLoadWithFeatureRouterTest.java
activemq/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfPayLoadMessageRouterTest.java
activemq/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfPayLoadSoapHeaderTest.java
activemq/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfProducerContextTest.java
activemq/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfProducerTest.java
activemq/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfWsdlFirstTest.java
activemq/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/util/CxfEndpointUtilsTest.java
activemq/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/util/CxfEndpointUtilsWithSpringTest.java
activemq/camel/trunk/pom.xml
Modified: activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfBinding.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfBinding.java?rev=735592&r1=735591&r2=735592&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfBinding.java (original)
+++ activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfBinding.java Sun Jan 18 17:48:41 2009
@@ -16,177 +16,101 @@
*/
package org.apache.camel.component.cxf;
-import java.io.InputStream;
-import java.util.HashMap;
-import java.util.List;
import java.util.Map;
-import java.util.Set;
-import javax.xml.ws.BindingProvider;
-import javax.xml.ws.handler.MessageContext;
-import javax.xml.ws.handler.MessageContext.Scope;
-
-import org.apache.camel.NoTypeConversionAvailableException;
-import org.apache.camel.component.cxf.util.CxfHeaderHelper;
-import org.apache.camel.spi.HeaderFilterStrategy;
-import org.apache.cxf.endpoint.Client;
-import org.apache.cxf.helpers.CastUtils;
-import org.apache.cxf.jaxws.context.WrappedMessageContext;
-import org.apache.cxf.message.Message;
+import org.apache.cxf.message.Exchange;
/**
- * The binding/mapping of Camel messages to Apache CXF and back again
- *
+ * An strategy interface for implementing binding between CXF {@link Exchange}
+ * and Camel {@link org.apache.camel.Exchange}.
+ *
* @version $Revision$
+ * @since 2.0
*/
-public final class CxfBinding {
- private CxfBinding() {
- // Helper class
- }
- public static Object extractBodyFromCxf(CxfExchange exchange, Message message) {
- // TODO how do we choose a format?
- return getBody(message);
- }
-
- protected static Object getBody(Message message) {
- Set<Class<?>> contentFormats = message.getContentFormats();
- if (contentFormats != null) {
- for (Class<?> contentFormat : contentFormats) {
- Object answer = message.getContent(contentFormat);
- if (answer != null) {
- return answer;
- }
- }
- }
- return null;
- }
-
- public static Message createCxfMessage(HeaderFilterStrategy strategy, CxfExchange exchange) {
-
- Message answer = exchange.getInMessage();
- CxfMessage in = exchange.getIn();
-
- // Check the body if the POJO parameter list first
- try {
- List body = in.getBody(List.class);
- // just set the operation's parameter
- answer.setContent(List.class, body);
- CxfHeaderHelper.propagateCamelToCxf(strategy, in.getHeaders(), answer);
- } catch (NoTypeConversionAvailableException ex) {
- // CXF uses StAX which is based on the stream API to parse the XML,
- // so the CXF transport is also based on the stream API.
- // And the interceptors are also based on the stream API,
- // so let's use an InputStream to host the CXF on wire message.
- try {
- InputStream body = in.getBody(InputStream.class);
- answer.setContent(InputStream.class, body);
- } catch (NoTypeConversionAvailableException ex2) {
- // ignore
- }
- // TODO do we propagate header the same way in non-POJO mode?
- // CxfHeaderHelper.propagateCamelToCxf(strategy, in.getHeaders(), answer);
- }
-
- //Ensure there is a request context, which is needed by propogateContext() below
- Map<String, Object> requestContext = CastUtils.cast((Map)answer.get(Client.REQUEST_CONTEXT));
- if (requestContext == null) {
- requestContext = new HashMap<String, Object>();
- }
- if (exchange.getExchange() != null) {
- requestContext.putAll(exchange.getExchange());
- }
- if (exchange.getProperties() != null) {
- //Allows other components to pass properties into cxf request context
- requestContext.putAll(exchange.getProperties());
- }
- answer.put(Client.REQUEST_CONTEXT, requestContext);
-
- return answer;
- }
-
- public static void storeCxfResponse(HeaderFilterStrategy strategy, CxfExchange exchange,
- Message response) {
- CxfMessage out = exchange.getOut();
- if (response != null) {
- CxfHeaderHelper.propagateCxfToCamel(strategy, response, out.getHeaders());
- out.setMessage(response);
- DataFormat dataFormat = (DataFormat) exchange.getProperty(CxfExchange.DATA_FORMAT);
- if (dataFormat.equals(DataFormat.MESSAGE)) {
- out.setBody(response.getContent(InputStream.class));
- }
- if (dataFormat.equals(DataFormat.PAYLOAD)) {
- out.setBody(response);
- }
- }
- }
-
- // Copy the Camel message to CXF message
- public static void copyMessage(HeaderFilterStrategy strategy,
- org.apache.camel.Message camelMessage, org.apache.cxf.message.Message cxfMessage) {
-
- CxfHeaderHelper.propagateCamelToCxf(strategy, camelMessage.getHeaders(), cxfMessage);
- try {
- InputStream is = camelMessage.getBody(InputStream.class);
- if (is != null) {
- cxfMessage.setContent(InputStream.class, is);
- }
- } catch (NoTypeConversionAvailableException ex) {
- Object result = camelMessage.getBody();
- if (result instanceof InputStream) {
- cxfMessage.setContent(InputStream.class, result);
- } else {
- cxfMessage.setContent(result.getClass(), result);
- }
- }
- }
-
- public static void storeCXfResponseContext(Message response, Map<String, Object> context) {
- if (context != null) {
- MessageContext messageContext = new WrappedMessageContext(context, null, Scope.HANDLER);
- response.put(Client.RESPONSE_CONTEXT, messageContext);
-
- }
- }
-
- public static void storeCxfResponse(CxfExchange exchange, Object response) {
- CxfMessage out = exchange.getOut();
- if (response != null) {
- out.setBody(response);
- }
- }
-
- public static void storeCxfFault(CxfExchange exchange, Message message) {
- CxfMessage fault = exchange.getFault();
- if (fault != null) {
- fault.setBody(getBody(message));
- }
- }
-
-
- public static Map<String, Object> propogateContext(Message message, Map<String, Object> context) {
- Map<String, Object> requestContext = CastUtils.cast((Map)message.get(Client.REQUEST_CONTEXT));
- Map<String, Object> responseContext = CastUtils.cast((Map)message.get(Client.RESPONSE_CONTEXT));
- // TODO map the JAXWS properties to cxf
- if (requestContext != null) {
- Map<String, Object> realMap = new HashMap<String, Object>();
- WrappedMessageContext ctx = new WrappedMessageContext(realMap,
- null,
- Scope.APPLICATION);
- ctx.putAll(requestContext);
- requestContext = realMap;
-
- }
-
- if (responseContext == null) {
- responseContext = new HashMap<String, Object>();
- } else {
- // clear the response context
- responseContext.clear();
- }
- context.put(Client.REQUEST_CONTEXT, requestContext);
- context.put(Client.RESPONSE_CONTEXT, responseContext);
- return responseContext;
+public interface CxfBinding {
+
+ /**
+ * <p>
+ * Populate a CXF Exchange from a Camel Exchange. The resulted CXF Exchange is an
+ * <b>outgoing request</b> to be sent to CXF server. This method is called by
+ * {@link CxfProducer#process(org.apache.camel.Exchange)} to process a Camel Exchange
+ * for invoking an CXF web service operation. Note that information is populated
+ * to CXF Exchange and the request context, which are passed as arguments to the
+ * CXF API's Client.invoke() method. The arguments to the web service operation
+ * are extracted from the Camel IN message body by CxfProducer.
+ * </p>
+ *
+ * <p>
+ * Exchange is passed in this direction: Camel route => CxfProducer => <b>apply this
+ * binding method </b>=> CXF server
+ * </p>
+ *
+ * @param cxfExchange exchange to be populated
+ * @param camelExchange exchange that contains a request
+ * @param requestContext a map contains request contexts. <b>This parameter must not
+ * be null</b>. The Client.invoke() method does not allow caller to
+ * pass in a CXF Message. The request context are copied to the CXF Message by the
+ * Client.invoke() method. This is how caller can set properties on the CXF message.
+ *
+ */
+ void populateCxfRequestFromExchange(Exchange cxfExchange,
+ org.apache.camel.Exchange camelExchange,
+ Map<String, Object> requestContext);
+
+ /**
+ * <p>
+ * Populate a Camel Exchange from a CXF Exchange, which is a an <b>incoming response</b>
+ * from a CXF server. This method is called by {@link CxfProducer} after it makes an
+ * invocation to the Client.invoke() method. It calls this method to translate the
+ * CXF response message to Camel message.
+ * </p>
+ *
+ * <p>
+ * Exchange is passed in this direction: Camel route <= <b>apply this binding method</b>
+ * <= CxfProducer <= CXF Server
+ * </p>
+ * @param camelExchange exchanged to be populated
+ * @param cxfExchange exchange that contains a response
+ * @param responseContext map contains response context from CXF
+ */
+ void populateExchangeFromCxfResponse(org.apache.camel.Exchange camelExchange,
+ Exchange cxfExchange, Map<String, Object> responseContext);
+
+ /**
+ * <p>
+ * Populate a Camel Exchange from a CXF Exchange, which is an <b>incoming request</b>
+ * from a CXF client. This method is called by {@link CxfConsumer} to handle a
+ * CXF request arrives at an endpoint. It translates a CXF request to a Camel
+ * Exchange for Camel route to process the exchange.
+ * </p>
+ *
+ * <p>
+ * Exchange is passed in this direction: CXF Endpoint => CxfConsumer => <b>apply this
+ * binding method </b> => Camel route
+ * </p>
+ * @param cxfExchange CXF exchange that contains a request
+ * @param camelExchange Camel exchange to be populated
+ */
+ void populateExchangeFromCxfRequest(Exchange cxfExchange,
+ org.apache.camel.Exchange camelExchange);
+
+
+ /**
+ * <p>
+ * Populate a CXF Exchange from a Camel Exchange. The resulted CXF Exchange is an
+ * <b>outgoing response</b> to be sent back to the CXF client. This method is called
+ * by {@link CxfConsumer} to translate a Camel Exchange to a CXF response Exchange.
+ * </p>
+ *
+ * <p>
+ * Exchange is passed in this direction: CXF Endpoint <= <b>apply this binding method</b>
+ * <= CxfConsumer <= Camel route
+ * </p>
+ * @param camelExchange Camel exchange that contains an out message
+ * @param cxfExchange CXF exchange to be populated
+ */
+ void populateCxfResponseFromExchange(org.apache.camel.Exchange camelExchange,
+ Exchange cxfExchange);
- }
}
Modified: activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfComponent.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfComponent.java?rev=735592&r1=735591&r2=735592&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfComponent.java (original)
+++ activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfComponent.java Sun Jan 18 17:48:41 2009
@@ -20,18 +20,16 @@
import org.apache.camel.CamelContext;
import org.apache.camel.Endpoint;
-import org.apache.camel.HeaderFilterStrategyAware;
+import org.apache.camel.component.cxf.spring.CxfEndpointBean;
import org.apache.camel.impl.DefaultComponent;
-import org.apache.camel.spi.HeaderFilterStrategy;
+import org.apache.camel.util.CamelContextHelper;
/**
- * Defines the <a href="http://activemq.apache.org/camel/cxf.html">CXF Component</a>
-
+ * Defines the <a href="http://activemq.apache.org/camel/cxf.html">CXF Component</a>
+ *
* @version $Revision$
*/
-public class CxfComponent extends DefaultComponent implements HeaderFilterStrategyAware {
-
- private HeaderFilterStrategy headerFilterStrategy = new CxfHeaderFilterStrategy();
+public class CxfComponent extends DefaultComponent {
public CxfComponent() {
}
@@ -39,23 +37,36 @@
public CxfComponent(CamelContext context) {
super(context);
}
-
+
+ /**
+ * Create a {@link CxfEndpoint} which, can be a Spring bean endpoint having
+ * URI format cxf:bean:<i>beanId</i> or transport address endpoint having URI format
+ * cxf://<i>transportAddress</i>.
+ */
@Override
- protected Endpoint createEndpoint(String uri, String remaining, Map parameters) throws Exception {
- // Now we need to add the address, endpoint name, WSDL url or the SEI to build up an endpoint
- CxfEndpoint result = new CxfEndpoint(uri, remaining, this);
- setProperties(result, parameters);
- // We can check the endpoint integration here
+ protected Endpoint createEndpoint(String uri, String remaining,
+ Map parameters) throws Exception {
+
+ CxfEndpoint result = null;
+
+ if (remaining.startsWith(CxfConstants.SPRING_CONTEXT_ENDPOINT)) {
+ // Get the bean from the Spring context
+ String beanId = remaining.substring(CxfConstants.SPRING_CONTEXT_ENDPOINT.length());
+ if (beanId.startsWith("//")) {
+ beanId = beanId.substring(2);
+ }
+
+ CxfEndpointBean bean = CamelContextHelper.mandatoryLookup(getCamelContext(), beanId,
+ CxfEndpointBean.class);
+
+ result = new CxfSpringEndpoint(this, beanId, bean);
+
+ } else {
+ // endpoint URI does not specify a bean
+ result = new CxfEndpoint(this, remaining);
+ }
+
return result;
}
-
- public HeaderFilterStrategy getHeaderFilterStrategy() {
- return headerFilterStrategy;
- }
-
- public void setHeaderFilterStrategy(HeaderFilterStrategy strategy) {
- headerFilterStrategy = strategy;
- }
-
-
+
}
Modified: activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfConsumer.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfConsumer.java?rev=735592&r1=735591&r2=735592&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfConsumer.java (original)
+++ activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfConsumer.java Sun Jan 18 17:48:41 2009
@@ -16,95 +16,95 @@
*/
package org.apache.camel.component.cxf;
-import javax.xml.ws.WebServiceProvider;
import org.apache.camel.Processor;
-import org.apache.camel.component.cxf.feature.MessageDataFormatFeature;
-import org.apache.camel.component.cxf.feature.PayLoadDataFormatFeature;
-import org.apache.camel.component.cxf.spring.CxfEndpointBean;
-import org.apache.camel.component.cxf.util.CxfEndpointUtils;
import org.apache.camel.impl.DefaultConsumer;
-import org.apache.cxf.Bus;
-import org.apache.cxf.BusFactory;
-import org.apache.cxf.bus.spring.SpringBusFactory;
-import org.apache.cxf.common.classloader.ClassLoaderUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
import org.apache.cxf.endpoint.Server;
import org.apache.cxf.frontend.ServerFactoryBean;
+import org.apache.cxf.interceptor.Fault;
+import org.apache.cxf.message.Exchange;
+import org.apache.cxf.service.invoker.Invoker;
/**
- * A consumer of exchanges for a service in CXF
+ * A Consumer of exchanges for a service in CXF. CxfConsumer acts a CXF
+ * service to receive requests, convert them, and forward them to Camel
+ * route for processing. It is also responsible for converting and sending
+ * back responses to CXF client.
*
* @version $Revision$
*/
public class CxfConsumer extends DefaultConsumer {
- private CxfEndpoint endpoint;
+ private static final Log LOG = LogFactory.getLog(CxfConsumer.class);
private Server server;
public CxfConsumer(CxfEndpoint endpoint, Processor processor) throws Exception {
-
super(endpoint, processor);
- Bus bus = null;
- this.endpoint = endpoint;
- boolean isWebServiceProvider = false;
- if (endpoint.getApplicationContext() != null) {
- bus = endpoint.getCxfEndpointBean().getBus();
- if (CxfEndpointUtils.getSetDefaultBus(endpoint)) {
- BusFactory.setThreadDefaultBus(bus);
- }
- } else {
- // now we just use the default bus here
- bus = BusFactory.getThreadDefaultBus();
- }
-
- Class serviceClass = CxfEndpointUtils.getServiceClass(endpoint);
- ServerFactoryBean svrBean = CxfEndpointUtils.getServerFactoryBean(serviceClass);
- isWebServiceProvider = CxfEndpointUtils.hasAnnotation(serviceClass,
- WebServiceProvider.class);
-
- if (endpoint.isSpringContextEndpoint()) {
- endpoint.configure(svrBean);
- } else { // setup the serverFactoryBean with the URI parameters
- svrBean.setAddress(endpoint.getAddress());
- if (endpoint.getWsdlURL() != null) {
- svrBean.setWsdlURL(endpoint.getWsdlURL());
- }
- }
-
- svrBean.setServiceClass(serviceClass);
- if (CxfEndpointUtils.getServiceName(endpoint) != null) {
- svrBean.setServiceName(CxfEndpointUtils.getServiceName(endpoint));
- }
- if (CxfEndpointUtils.getServiceName(endpoint) != null) {
- svrBean.setEndpointName(CxfEndpointUtils.getPortName(endpoint));
- }
-
- DataFormat dataFormat = CxfEndpointUtils.getDataFormat(endpoint);
-
- svrBean.setInvoker(new CamelInvoker(this));
-
- // apply feature here
- if (!dataFormat.equals(DataFormat.POJO) && !isWebServiceProvider) {
-
- if (dataFormat.equals(DataFormat.PAYLOAD)) {
- svrBean.getFeatures().add(new PayLoadDataFormatFeature());
- // adding the logging feature here for debug
- //features.add(new LoggingFeature());
- } else if (dataFormat.equals(DataFormat.MESSAGE)) {
- svrBean.getFeatures().add(new MessageDataFormatFeature());
- //features.add(new LoggingFeature());
+ // create server
+ ServerFactoryBean svrBean = endpoint.createServerFactoryBean();
+ svrBean.setInvoker(new Invoker() {
+
+ // we receive a CXF request when this method is called
+ public Object invoke(Exchange cxfExchange, Object o) {
+
+ if (LOG.isTraceEnabled()) {
+ LOG.trace("Received CXF Request: " + cxfExchange);
+ }
+
+ // get CXF binding
+ CxfEndpoint endpoint = (CxfEndpoint)getEndpoint();
+ CxfBinding binding = endpoint.getCxfBinding();
+
+ // create a Camel exchange
+ org.apache.camel.Exchange camelExchange = endpoint.createExchange();
+
+ // set data format mode in Camel exchange
+ DataFormat dataFormat = endpoint.getDataFormat();
+ camelExchange.setProperty(DataFormat.class.getName(), dataFormat);
+ if (LOG.isTraceEnabled()) {
+ LOG.trace("Set Exchange property: " + DataFormat.class.getName()
+ + "=" + dataFormat);
+ }
+
+ // bind the CXF request into a Camel exchange
+ binding.populateExchangeFromCxfRequest(cxfExchange, camelExchange);
+
+ // send Camel exchange to the target processor
+ try {
+ getProcessor().process(camelExchange);
+ } catch (Exception e) {
+ throw new Fault(e);
+ }
+
+ // check failure
+ if (camelExchange.isFailed()) {
+ Throwable t = (Throwable)camelExchange.getFault().getBody();
+ if (t instanceof Fault) {
+ throw (Fault)t;
+ } else if (t == null) {
+ t = camelExchange.getException();
+ }
+ throw new Fault(t);
+ }
+
+ // bind the Camel response into a CXF response
+ if (camelExchange.getPattern().isOutCapable()) {
+ binding.populateCxfResponseFromExchange(camelExchange, cxfExchange);
+ }
+
+ // response should have been set in outMessage's content
+ return null;
}
- }
- svrBean.setBus(bus);
- svrBean.setStart(false);
- server = svrBean.create();
-
+
+ });
+ server = svrBean.create();
}
-
+
@Override
protected void doStart() throws Exception {
super.doStart();
-
server.start();
}
@@ -113,9 +113,5 @@
server.stop();
super.doStop();
}
-
- public CxfEndpoint getEndpoint() {
- return endpoint;
- }
-
+
}
Modified: activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfEndpoint.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfEndpoint.java?rev=735592&r1=735591&r2=735592&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfEndpoint.java (original)
+++ activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfEndpoint.java Sun Jan 18 17:48:41 2009
@@ -16,58 +16,72 @@
*/
package org.apache.camel.component.cxf;
+import java.lang.reflect.Proxy;
+import java.util.List;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import javax.xml.ws.WebServiceProvider;
+
+import org.apache.camel.CamelException;
import org.apache.camel.Consumer;
import org.apache.camel.Exchange;
import org.apache.camel.ExchangePattern;
+import org.apache.camel.HeaderFilterStrategyAware;
import org.apache.camel.Processor;
import org.apache.camel.Producer;
-import org.apache.camel.component.cxf.spring.CxfEndpointBean;
+import org.apache.camel.component.cxf.feature.MessageDataFormatFeature;
+import org.apache.camel.component.cxf.feature.PayLoadDataFormatFeature;
+import org.apache.camel.component.cxf.util.CxfEndpointUtils;
import org.apache.camel.impl.DefaultEndpoint;
import org.apache.camel.spi.HeaderFilterStrategy;
-import org.apache.camel.spring.SpringCamelContext;
-import org.apache.cxf.configuration.spring.ConfigurerImpl;
+import org.apache.camel.util.ObjectHelper;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.cxf.Bus;
+import org.apache.cxf.BusFactory;
+import org.apache.cxf.common.classloader.ClassLoaderUtils;
+import org.apache.cxf.endpoint.Client;
+import org.apache.cxf.endpoint.ClientImpl;
+import org.apache.cxf.endpoint.Endpoint;
+import org.apache.cxf.frontend.ClientFactoryBean;
+import org.apache.cxf.frontend.ClientProxy;
+import org.apache.cxf.frontend.ClientProxyFactoryBean;
+import org.apache.cxf.frontend.ServerFactoryBean;
+import org.apache.cxf.headers.Header;
+import org.apache.cxf.jaxws.JaxWsClientFactoryBean;
+import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;
import org.apache.cxf.message.Message;
-import org.springframework.context.ApplicationContext;
-
/**
- * Defines the <a href="http://activemq.apache.org/camel/cxf.html">CXF Endpoint</a>
+ * Defines the <a href="http://activemq.apache.org/camel/cxf.html">CXF Endpoint</a>.
+ * It contains a list of properties for CXF endpoint including {@link DataFormat},
+ * {@link CxfBinding}, and {@link HeaderFilterStrategy}. The default DataFormat
+ * mode is {@link DataFormat#POJO}.
*
* @version $Revision$
*/
public class CxfEndpoint extends DefaultEndpoint {
- private final CxfComponent component;
- private final String address;
+
+ private static final Log LOG = LogFactory.getLog(CxfEndpoint.class);
+
private String wsdlURL;
private String serviceClass;
private String portName;
private String serviceName;
- private String dataFormat;
- private String beanId;
- private String serviceClassInstance;
+ private DataFormat dataFormat = DataFormat.POJO;
private boolean isWrapped;
- private boolean isSpringContextEndpoint;
private boolean inOut = true;
- private Boolean isSetDefaultBus;
- private ConfigurerImpl configurer;
- private CxfEndpointBean cxfEndpointBean;
-
- public CxfEndpoint(String uri, String address, CxfComponent component) {
- super(uri, component);
- this.component = component;
- this.address = address;
- if (address.startsWith(CxfConstants.SPRING_CONTEXT_ENDPOINT)) {
- isSpringContextEndpoint = true;
- // Get the bean from the Spring context
- beanId = address.substring(CxfConstants.SPRING_CONTEXT_ENDPOINT.length());
- if (beanId.startsWith("//")) {
- beanId = beanId.substring(2);
- }
- SpringCamelContext context = (SpringCamelContext) this.getCamelContext();
- configurer = new ConfigurerImpl(context.getApplicationContext());
- cxfEndpointBean = (CxfEndpointBean) context.getApplicationContext().getBean(beanId);
- assert cxfEndpointBean != null;
- }
+ private Bus bus;
+ private CxfBinding cxfBinding;
+ private HeaderFilterStrategy headerFilterStrategy;
+ private boolean hasWSProviderAnnotation;
+ private boolean hasWebServiceAnnotation;
+ private AtomicBoolean cxfBindingInitialized = new AtomicBoolean(false);
+ private AtomicBoolean getBusHasBeenCalled = new AtomicBoolean(false);
+ private boolean isSetDefaultBus;
+
+ public CxfEndpoint(CxfComponent cxfComponent, String remaining) {
+ super(remaining, cxfComponent);
}
public Producer createProducer() throws Exception {
@@ -77,44 +91,189 @@
public Consumer createConsumer(Processor processor) throws Exception {
return new CxfConsumer(this, processor);
}
-
- public Exchange createExchange() {
- return new CxfExchange(this, getExchangePattern());
- }
-
+
+ @Override
public Exchange createExchange(ExchangePattern pattern) {
return new CxfExchange(this, pattern);
}
+
+ public boolean isSingleton() {
+ return true;
+ }
+
+ /**
+ * Populate server factory bean
+ */
+ protected void setupServerFactoryBean(ServerFactoryBean sfb, Class<?> cls) {
+ hasWSProviderAnnotation = CxfEndpointUtils.hasAnnotation(cls,
+ WebServiceProvider.class);
+
+ // address
+ sfb.setAddress(getEndpointUri());
+
+ // service class
+ sfb.setServiceClass(cls);
+
+ // wsdl url
+ if (getWsdlURL() != null) {
+ sfb.setWsdlURL(getWsdlURL());
+ }
+
+ // service name qname
+ if (getServiceName() != null) {
+ sfb.setServiceName(CxfEndpointUtils.getQName(getServiceName()));
+ }
+
+ // port qname
+ if (getPortName() != null) {
+ sfb.setEndpointName(CxfEndpointUtils.getQName(getPortName()));
+ }
- public CxfExchange createExchange(Message inMessage) {
- return new CxfExchange(this, getExchangePattern(), inMessage);
+ // apply feature here
+ if (!webServiceProviderAnnotated()) {
+ if (getDataFormat() == DataFormat.PAYLOAD) {
+ sfb.getFeatures().add(new PayLoadDataFormatFeature());
+ } else if (getDataFormat() == DataFormat.MESSAGE) {
+ sfb.getFeatures().add(new MessageDataFormatFeature());
+ }
+ } else {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Ignore DataFormat mode " + getDataFormat()
+ + " since SEI class is annotated with WebServiceProvider");
+ }
+ }
+
+ sfb.setBus(getBus());
+ sfb.setStart(false);
}
- /* Override the defaultEndpoint exchange create method */
- public Exchange createExchange(Exchange exchange) {
- if (exchange instanceof CxfExchange) {
- return exchange;
+ /**
+ *
+ * Create a client factory bean object. Notice that the serviceClass <b>must</b> be
+ * an interface.
+ */
+ protected ClientProxyFactoryBean createClientFactoryBean(Class<?> cls) throws CamelException {
+ // quick null point check for serviceClass
+ ObjectHelper.notNull(cls, "Please provide endpoint service interface class");
+
+ hasWebServiceAnnotation = CxfEndpointUtils.hasWebServiceAnnotation(cls);
+ if (hasWebServiceAnnotation) {
+ return new JaxWsProxyFactoryBean(new JaxWsClientFactoryBean() {
+ @Override
+ protected void createClient(Endpoint ep) {
+ setClient(new CamelCxfClientImpl(getBus(), ep));
+ }
+ });
} else {
- Exchange answer = createExchange();
- answer.copyFrom(exchange);
- return answer;
+ return new ClientProxyFactoryBean(new ClientFactoryBean() {
+ @Override
+ protected void createClient(Endpoint ep) {
+ setClient(new CamelCxfClientImpl(getBus(), ep));
+ }
+ });
}
}
- public String getDataFormat() {
- return dataFormat;
+ protected Bus doGetBus() {
+ return BusFactory.getThreadDefaultBus();
}
+
+ /**
+ *
+ * Populate a client factory bean
+ */
+ protected void setupClientFactoryBean(ClientProxyFactoryBean factoryBean, Class<?> cls) {
+ // quick null point check for serviceClass
+ ObjectHelper.notNull(cls, "Please provide endpoint service interface class");
+
+ // service class
+ factoryBean.setServiceClass(cls);
+
+ // address
+ factoryBean.setAddress(getEndpointUri());
+
+ // wsdl url
+ if (getWsdlURL() != null) {
+ factoryBean.setWsdlURL(getWsdlURL());
+ }
+
+ // service name qname
+ if (getServiceName() != null) {
+ factoryBean.setServiceName(CxfEndpointUtils.getQName(getServiceName()));
+ }
+
+ // port name qname
+ if (getPortName() != null) {
+ factoryBean.setEndpointName(CxfEndpointUtils.getQName(getPortName()));
+ }
- public void setDataFormat(String format) {
- dataFormat = format;
+ // apply feature here
+ if (getDataFormat() == DataFormat.MESSAGE) {
+ factoryBean.getFeatures().add(new MessageDataFormatFeature());
+ } else if (getDataFormat() == DataFormat.PAYLOAD) {
+ factoryBean.getFeatures().add(new PayLoadDataFormatFeature());
+ }
+
+ factoryBean.setBus(getBus());
+
+ }
+
+ // Package private methods
+ // -------------------------------------------------------------------------
+
+ /**
+ * Create a CXF client object
+ */
+ Client createClient() throws Exception {
+
+ // get service class
+ ObjectHelper.notEmpty(getServiceClass(), CxfConstants.SERVICE_CLASS);
+ Class<?> cls = ClassLoaderUtils.loadClass(getServiceClass(), getClass());
+
+ // create client factory bean
+ ClientProxyFactoryBean factoryBean = createClientFactoryBean(cls);
+
+ // setup client factory bean
+ setupClientFactoryBean(factoryBean, cls);
+
+ return ((ClientProxy)Proxy.getInvocationHandler(factoryBean.create())).getClient();
+ }
+
+
+ /**
+ * Create a CXF server factory bean
+ */
+ ServerFactoryBean createServerFactoryBean() throws Exception {
+
+ // get service class
+ ObjectHelper.notEmpty(getServiceClass(), CxfConstants.SERVICE_CLASS);
+ Class<?> cls = ClassLoaderUtils.loadClass(getServiceClass(), getClass());
+
+ // create server factory bean
+ ServerFactoryBean answer = CxfEndpointUtils.getServerFactoryBean(cls);
+
+ // setup server factory bean
+ setupServerFactoryBean(answer, cls);
+ return answer;
+ }
+
+ boolean webServiceProviderAnnotated() {
+ return hasWSProviderAnnotation;
+ }
+
+ boolean webServiceAnnotated() {
+ return hasWebServiceAnnotation;
}
+
+ // Properties
+ // -------------------------------------------------------------------------
- public boolean isSpringContextEndpoint() {
- return isSpringContextEndpoint;
+ public DataFormat getDataFormat() {
+ return dataFormat;
}
- public String getAddress() {
- return address;
+ public void setDataFormat(DataFormat format) {
+ dataFormat = format;
}
public String getWsdlURL() {
@@ -124,29 +283,17 @@
public void setWsdlURL(String url) {
wsdlURL = url;
}
-
- public void setSetDefaultBus(Boolean set) {
- isSetDefaultBus = set;
- }
-
- public Boolean isSetDefaultBus() {
- return isSetDefaultBus;
- }
-
+
public String getServiceClass() {
return serviceClass;
}
- public void setServiceClass(String className) {
+ public void setServiceClass(String className) {
serviceClass = className;
}
- public String getServiceClassInstance() {
- return serviceClassInstance;
- }
-
- public void setServiceClassInstance(String classInstance) {
- serviceClassInstance = classInstance;
+ public void setServiceClass(Object instance) {
+ serviceClass = instance.getClass().getName();
}
public void setPortName(String port) {
@@ -181,38 +328,93 @@
isWrapped = wrapped;
}
-
- public CxfComponent getComponent() {
- return component;
+ public void setCxfBinding(CxfBinding cxfBinding) {
+ this.cxfBinding = cxfBinding;
}
- public boolean isSingleton() {
- return true;
+ public CxfBinding getCxfBinding() {
+ if (cxfBinding == null) {
+ cxfBinding = new DefaultCxfBinding();
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Create default CXF Binding " + cxfBinding);
+ }
+ }
+
+ if (!cxfBindingInitialized.getAndSet(true)
+ && cxfBinding instanceof HeaderFilterStrategyAware) {
+ ((HeaderFilterStrategyAware)cxfBinding)
+ .setHeaderFilterStrategy(getHeaderFilterStrategy());
+ }
+ return cxfBinding;
}
- public String getBeanId() {
- return beanId;
+ public void setHeaderFilterStrategy(HeaderFilterStrategy headerFilterStrategy) {
+ this.headerFilterStrategy = headerFilterStrategy;
}
- public CxfEndpointBean getCxfEndpointBean() {
- return cxfEndpointBean;
+ public HeaderFilterStrategy getHeaderFilterStrategy() {
+ if (headerFilterStrategy == null) {
+ headerFilterStrategy = new CxfHeaderFilterStrategy();
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Create CXF default header filter strategy "
+ + headerFilterStrategy);
+ }
+ }
+ return headerFilterStrategy;
}
- public void configure(Object beanInstance) {
- configurer.configureBean(beanId, beanInstance);
+ public void setBus(Bus bus) {
+ this.bus = bus;
}
- public ApplicationContext getApplicationContext() {
- if (getCamelContext() instanceof SpringCamelContext) {
- SpringCamelContext context = (SpringCamelContext) getCamelContext();
- return context.getApplicationContext();
- } else {
- return null;
+ public Bus getBus() {
+ if (bus == null) {
+ bus = doGetBus();
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Using ThreadDefaultBus " + bus);
+ }
}
+
+ if (!getBusHasBeenCalled.getAndSet(true) && isSetDefaultBus) {
+ BusFactory.setThreadDefaultBus(bus);
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Set bus " + bus + " as thread default bus");
+ }
+ }
+ return bus;
}
- public HeaderFilterStrategy getHeaderFilterStrategy() {
- return component.getHeaderFilterStrategy();
+ public void setSetDefaultBus(boolean isSetDefaultBus) {
+ this.isSetDefaultBus = isSetDefaultBus;
+ }
+
+ public boolean isSetDefaultBus() {
+ return isSetDefaultBus;
+ }
+
+ /**
+ * We need to override the {@link ClientImpl#setParameters} method
+ * to insert parameters into CXF Message for {@link DataFormat#PAYLOAD}
+ * mode.
+ */
+ private class CamelCxfClientImpl extends ClientImpl {
+
+ public CamelCxfClientImpl(Bus bus, Endpoint ep) {
+ super(bus, ep);
+ }
+
+ @Override
+ protected void setParameters(Object[] params, Message message) {
+ if (DataFormat.PAYLOAD == message.get(DataFormat.class)) {
+ CxfPayload<?> payload = (CxfPayload<?>)params[0];
+ message.put(List.class, payload.getBody());
+ message.put(Header.HEADER_LIST, payload.getHeaders());
+ } else {
+ super.setParameters(params, message);
+ }
+ }
+
+
}
}
Modified: activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfExchange.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfExchange.java?rev=735592&r1=735591&r2=735592&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfExchange.java (original)
+++ activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfExchange.java Sun Jan 18 17:48:41 2009
@@ -16,145 +16,38 @@
*/
package org.apache.camel.component.cxf;
-import org.apache.camel.CamelContext;
+
import org.apache.camel.ExchangePattern;
+import org.apache.camel.Message;
import org.apache.camel.impl.DefaultExchange;
-import org.apache.cxf.message.Exchange;
-import org.apache.cxf.message.Message;
-import org.apache.cxf.transport.Conduit;
-import org.apache.cxf.transport.Destination;
/**
- * An {@link Exchange} for working with Apache CXF which exposes the underlying
- * CXF messages via {@link #getInMessage()} and {@link #getOutMessage()} along with the
- * {@link #getExchange()}
- *
+ *
* @version $Revision$
*/
public class CxfExchange extends DefaultExchange {
- public static final String DATA_FORMAT = "DATA_FORMAT";
- private Exchange exchange;
-
- public CxfExchange(CamelContext context, ExchangePattern pattern, Exchange exchange) {
- super(context, pattern);
- this.exchange = exchange;
- // TO avoid the NPE here
- if (exchange != null) {
- if (exchange.getOutMessage() != null) {
- setOut(new CxfMessage(exchange.getOutMessage()));
- }
- if (exchange.getInMessage() != null) {
- setIn(new CxfMessage(exchange.getInMessage()));
- }
- if (exchange.getInFaultMessage() != null) {
- setFault(new CxfMessage(exchange.getInFaultMessage()));
- }
- }
- }
-
- public CxfExchange(CxfEndpoint endpoint, ExchangePattern pattern) {
- super(endpoint, pattern);
- }
-
- public CxfExchange(CxfExchange exchange) {
- super(exchange);
- this.exchange = exchange.getExchange();
- }
-
- public CxfExchange(CxfEndpoint endpoint, ExchangePattern pattern, Message inMessage) {
- this(endpoint, pattern);
- this.exchange = inMessage.getExchange();
-
- setIn(new CxfMessage(inMessage));
- if (exchange != null) {
- if (exchange.getOutMessage() != null) {
- setOut(new CxfMessage(exchange.getOutMessage()));
- }
- if (exchange.getInFaultMessage() != null) {
- setFault(new CxfMessage(exchange.getInFaultMessage()));
- }
- }
- }
-
- @Override
- public org.apache.camel.Exchange newInstance() {
- return new CxfExchange(this);
- }
-
- @Override
- public CxfMessage getIn() {
- return (CxfMessage) super.getIn();
- }
-
- @Override
- public CxfMessage getOut() {
- return (CxfMessage) super.getOut();
- }
-
- @Override
- public CxfMessage getOut(boolean lazyCreate) {
- return (CxfMessage) super.getOut(lazyCreate);
- }
-
- @Override
- public CxfMessage getFault() {
- return (CxfMessage) super.getFault();
- }
-
- @Override
- protected org.apache.camel.Message createFaultMessage() {
- return new CxfMessage();
- }
-
-
- public void setExchange(Exchange exchange) {
- this.exchange = exchange;
- }
-
- // Expose CXF APIs directly on the exchange
- //-------------------------------------------------------------------------
/**
- * Returns the underlying CXF message exchange for an inbound exchange
- * or null for outbound messages
- *
- * @return the inbound message exchange
+ * @param cxfEndpoint
+ * @param pattern
*/
- public Exchange getExchange() {
- return exchange;
- }
-
- public Message getInMessage() {
- return getIn().getMessage();
- }
-
- public Message getOutMessage() {
- return getOut().getMessage();
+ public CxfExchange(CxfEndpoint cxfEndpoint, ExchangePattern pattern) {
+ super(cxfEndpoint, pattern);
}
- public Message getOutFaultMessage() {
- return getExchange().getOutFaultMessage();
- }
-
- public Message getInFaultMessage() {
- return getExchange().getInFaultMessage();
- }
-
- public Destination getDestination() {
- return getExchange().getDestination();
- }
-
- public Conduit getConduit(Message message) {
- return getExchange().getConduit(message);
+ @Override
+ protected Message createInMessage() {
+ return new CxfMessage();
}
@Override
- protected CxfMessage createInMessage() {
+ protected Message createOutMessage() {
return new CxfMessage();
}
-
+
@Override
- protected CxfMessage createOutMessage() {
+ protected Message createFaultMessage() {
return new CxfMessage();
}
+
}
Modified: activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfHeaderFilterStrategy.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfHeaderFilterStrategy.java?rev=735592&r1=735591&r2=735592&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfHeaderFilterStrategy.java (original)
+++ activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfHeaderFilterStrategy.java Sun Jan 18 17:48:41 2009
@@ -17,8 +17,12 @@
package org.apache.camel.component.cxf;
import org.apache.camel.impl.DefaultHeaderFilterStrategy;
+import org.apache.cxf.endpoint.Client;
+import org.apache.cxf.message.Message;
/**
+ * The default CXF header filter strategy.
+ *
* @version $Revision$
*/
public class CxfHeaderFilterStrategy extends DefaultHeaderFilterStrategy {
@@ -30,6 +34,18 @@
protected void initialize() {
getOutFilter().add(CxfConstants.OPERATION_NAME);
getOutFilter().add(CxfConstants.OPERATION_NAMESPACE);
+
+ // Request and response context Maps will be passed to CXF Client APIs
+ getOutFilter().add(Client.REQUEST_CONTEXT);
+ getOutFilter().add(Client.RESPONSE_CONTEXT);
+
+ // protocol headers are stored as a Map. DefaultCxfBinding
+ // read the Map and send each entry to the filter. Therefore,
+ // we need to filter the header of this name.
+ getOutFilter().add(Message.PROTOCOL_HEADERS);
+ getInFilter().add(Message.PROTOCOL_HEADERS);
+
+
}
}
Modified: activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfMessage.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfMessage.java?rev=735592&r1=735591&r2=735592&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfMessage.java (original)
+++ activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfMessage.java Sun Jan 18 17:48:41 2009
@@ -18,92 +18,22 @@
import org.apache.camel.NoTypeConversionAvailableException;
import org.apache.camel.impl.DefaultMessage;
-import org.apache.cxf.message.Message;
import org.apache.cxf.message.MessageContentsList;
-import org.apache.cxf.message.MessageImpl;
/**
- * An Apache CXF {@link Message} which provides access to the underlying CXF
- * features
- *
- * @version $Revision$
+ * A simple CxfMessage object.
*/
public class CxfMessage extends DefaultMessage {
- private Message cxfMessage;
-
- public CxfMessage() {
- this(new MessageImpl());
- }
-
- public CxfMessage(Message cxfMessage) {
- if (cxfMessage == null) {
- this.cxfMessage = new MessageImpl();
- } else {
- this.cxfMessage = cxfMessage;
- }
- }
-
- @Override
- public void copyFrom(org.apache.camel.Message that) {
- setMessageId(that.getMessageId());
- setBody(that.getBody());
- if (that.getBody() instanceof Message) {
- setMessage((Message)that.getBody());
- }
- getHeaders().putAll(that.getHeaders());
- if (that instanceof CxfMessage) {
- CxfMessage orig = (CxfMessage) that;
- setMessage(orig.getMessage());
- }
- }
-
- @Override
- public String toString() {
- if (cxfMessage != null) {
- return "CxfMessage: " + cxfMessage;
- } else {
- return "CxfMessage: " + getBody();
- }
- }
-
- @Override
- public CxfExchange getExchange() {
- return (CxfExchange)super.getExchange();
- }
/**
- * Returns the underlying CXF message
- *
- * @return the CXF message
- */
- public Message getMessage() {
- return cxfMessage;
- }
-
- public void setMessage(Message cxfMessage) {
- this.cxfMessage = cxfMessage;
- }
-
+ * If the body is a {@link MessageContentsList}, this getBody method
+ * applies converters to the first element of the MessageContentsList
+ * and returns the value.
+ * */
@Override
- public CxfMessage newInstance() {
- return new CxfMessage();
- }
-
- @Override
- protected Object createBody() {
- return CxfBinding.extractBodyFromCxf(getExchange(), cxfMessage);
- }
-
- @Override
- public void setBody(Object body) {
- super.setBody(body);
- if (body instanceof Message) {
- setMessage((Message) body);
- }
- }
-
public <T> T getBody(Class<T> type) {
- if (!(MessageContentsList.class.isAssignableFrom(type)) && getBody() instanceof MessageContentsList) {
+ if (!(MessageContentsList.class.isAssignableFrom(type))
+ && getBody() instanceof MessageContentsList) {
// if the body is the MessageContentsList then try to convert its payload
// to make it easier for end-users to use camel-cxf
MessageContentsList list = (MessageContentsList)getBody();
@@ -114,7 +44,7 @@
if (answer != null) {
return answer;
}
- } catch (NoTypeConversionAvailableException ex) {
+ } catch (NoTypeConversionAvailableException e) {
// ignore
}
}
Added: activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfPayload.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfPayload.java?rev=735592&view=auto
==============================================================================
--- activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfPayload.java (added)
+++ activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfPayload.java Sun Jan 18 17:48:41 2009
@@ -0,0 +1,54 @@
+/**
+ * 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.util.List;
+
+import org.w3c.dom.Element;
+
+/**
+ * CxfMessage body type when {@link DataFormat#PAYLOAD} is used.
+ *
+ * @version $Revision$
+ */
+public class CxfPayload<T> {
+
+ private List<Element> body;
+ private List<T> headers;
+
+ public CxfPayload(List<T> headers, List<Element> body) {
+ this.headers = headers;
+ this.body = body;
+ }
+
+ public List<Element> getBody() {
+ return body;
+ }
+
+ public List<T> getHeaders() {
+ return headers;
+ }
+
+ public String toString() {
+ StringBuffer buf = new StringBuffer();
+ buf.append(getClass().getName());
+ buf.append(" headers: " + headers);
+ buf.append("body: " + body);
+ return buf.toString();
+ }
+
+}
Propchange: activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfPayload.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfPayload.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified: activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfProducer.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfProducer.java?rev=735592&r1=735591&r2=735592&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfProducer.java (original)
+++ activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfProducer.java Sun Jan 18 17:48:41 2009
@@ -16,257 +16,205 @@
*/
package org.apache.camel.component.cxf;
-import java.lang.reflect.Proxy;
-import java.util.ArrayList;
+import java.io.InputStream;
+import java.util.Collection;
import java.util.HashMap;
+import java.util.Iterator;
import java.util.List;
import java.util.Map;
import javax.xml.namespace.QName;
+import javax.xml.ws.handler.MessageContext.Scope;
-import org.apache.camel.CamelException;
import org.apache.camel.Exchange;
-import org.apache.camel.RuntimeCamelException;
-import org.apache.camel.component.cxf.feature.MessageDataFormatFeature;
-import org.apache.camel.component.cxf.feature.PayLoadDataFormatFeature;
-import org.apache.camel.component.cxf.invoker.CxfClient;
-import org.apache.camel.component.cxf.invoker.CxfClientFactoryBean;
-import org.apache.camel.component.cxf.invoker.InvokingContext;
-import org.apache.camel.component.cxf.invoker.InvokingContextFactory;
-import org.apache.camel.component.cxf.spring.CxfEndpointBean;
-import org.apache.camel.component.cxf.util.CxfEndpointUtils;
import org.apache.camel.impl.DefaultProducer;
import org.apache.camel.util.ObjectHelper;
-import org.apache.cxf.Bus;
-import org.apache.cxf.BusFactory;
-import org.apache.cxf.bus.spring.SpringBusFactory;
-import org.apache.cxf.common.classloader.ClassLoaderUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
import org.apache.cxf.endpoint.Client;
-import org.apache.cxf.endpoint.Endpoint;
-import org.apache.cxf.frontend.ClientProxy;
-import org.apache.cxf.frontend.ClientProxyFactoryBean;
-import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;
+import org.apache.cxf.jaxws.context.WrappedMessageContext;
import org.apache.cxf.message.ExchangeImpl;
-import org.apache.cxf.message.Message;
-import org.apache.cxf.message.MessageContentsList;
-import org.apache.cxf.message.MessageImpl;
import org.apache.cxf.service.model.BindingOperationInfo;
/**
- * Sends messages from Camel into the CXF endpoint
+ * CxfProducer binds a Camel exchange to a CXF exchange, acts an a CXF
+ * client, and sends the request to a CXF to a server. Any response will
+ * be bound to Camel exchange.
*
* @version $Revision$
*/
public class CxfProducer extends DefaultProducer {
- private CxfEndpoint endpoint;
+ private static final Log LOG = LogFactory.getLog(CxfProducer.class);
private Client client;
- private DataFormat dataFormat;
+ /**
+ * Constructor to create a CxfProducer. It will create a CXF client
+ * object.
+ *
+ * @param endpoint a CxfEndpoint that creates this producer
+ * @throws Exception any exception thrown during the creation of a
+ * CXF client
+ */
public CxfProducer(CxfEndpoint endpoint) throws Exception {
super(endpoint);
- this.endpoint = endpoint;
- dataFormat = CxfEndpointUtils.getDataFormat(endpoint);
- if (dataFormat.equals(DataFormat.POJO)) {
- client = createClientFromClientFactoryBean(null);
- } else {
- // Create CxfClient for message or payload type
- client = createClientForStreamMessage();
- }
- }
-
- private Client createClientForStreamMessage() throws Exception {
- CxfClientFactoryBean cfb = new CxfClientFactoryBean();
- Class serviceClass = null;
- try {
- serviceClass = CxfEndpointUtils.getServiceClass(endpoint);
- } catch (ClassNotFoundException e) {
- throw new CamelException(e);
- }
-
- boolean jsr181Enabled = CxfEndpointUtils.hasWebServiceAnnotation(serviceClass);
- cfb.setJSR181Enabled(jsr181Enabled);
-
- return createClientFromClientFactoryBean(jsr181Enabled ? new JaxWsProxyFactoryBean(cfb)
- : new ClientProxyFactoryBean(cfb));
+ client = endpoint.createClient();
}
- // If cfb is null, we will try to find the right cfb to use.
- private Client createClientFromClientFactoryBean(ClientProxyFactoryBean cfb) throws Exception {
- Bus bus = null;
- if (endpoint.getApplicationContext() != null) {
- bus = endpoint.getCxfEndpointBean().getBus();
- if (CxfEndpointUtils.getSetDefaultBus(endpoint)) {
- BusFactory.setThreadDefaultBus(bus);
- }
- } else {
- // now we just use the default bus here
- bus = BusFactory.getThreadDefaultBus();
+ /**
+ * This processor binds Camel exchange to a CXF exchange and
+ * invokes the CXF client.
+ */
+ public void process(Exchange camelExchange) throws Exception {
+
+ if (LOG.isTraceEnabled()) {
+ LOG.trace("Process exchange: " + camelExchange);
}
- Class serviceClass = CxfEndpointUtils.getServiceClass(endpoint);
- // We need to choose the right front end to create the clientFactoryBean
- if (cfb == null) {
- cfb = CxfEndpointUtils.getClientFactoryBean(serviceClass);
+ // create CXF exchange
+ ExchangeImpl cxfExchange = new ExchangeImpl();
+
+ // get CXF binding
+ CxfEndpoint endpoint = (CxfEndpoint)getEndpoint();
+ CxfBinding binding = endpoint.getCxfBinding();
+
+ // create invocation context
+ Map<String, Object> requestContext = new WrappedMessageContext(
+ new HashMap<String, Object>(), null, Scope.APPLICATION);
+ Map<String, Object> responseContext = new HashMap<String, Object>();
+
+
+ // set data format mode in exchange
+ DataFormat dataFormat = endpoint.getDataFormat();
+ camelExchange.setProperty(DataFormat.class.getName(), dataFormat);
+ if (LOG.isTraceEnabled()) {
+ LOG.trace("Set Camel Exchange property: " + DataFormat.class.getName()
+ + "=" + dataFormat);
}
- if (endpoint.isSpringContextEndpoint()) {
- endpoint.configure(cfb);
- } else { // set up the clientFactoryBean by using URI information
- cfb.setAddress(endpoint.getAddress());
- if (null != endpoint.getServiceClass()) {
- cfb.setServiceClass(ObjectHelper.loadClass(endpoint.getServiceClass()));
- }
- if (null != endpoint.getWsdlURL()) {
- cfb.setWsdlURL(endpoint.getWsdlURL());
- }
+ // set data format mode in the request context
+ requestContext.put(DataFormat.class.getName(), dataFormat);
- if (endpoint.getWsdlURL() != null) {
- cfb.setWsdlURL(endpoint.getWsdlURL());
+ // don't let CXF ClientImpl close the input stream
+ if (dataFormat == DataFormat.MESSAGE) {
+ cxfExchange.put(Client.KEEP_CONDUIT_ALIVE, true);
+ if (LOG.isTraceEnabled()) {
+ LOG.trace("Set CXF Exchange property: " + Client.KEEP_CONDUIT_ALIVE
+ + "=" + true);
}
}
- cfb.setServiceClass(serviceClass);
- if (CxfEndpointUtils.getServiceName(endpoint) != null) {
- cfb.setServiceName(CxfEndpointUtils.getServiceName(endpoint));
- }
- if (CxfEndpointUtils.getPortName(endpoint) != null) {
- cfb.setEndpointName(CxfEndpointUtils.getPortName(endpoint));
+ // bind the request CXF exchange
+ binding.populateCxfRequestFromExchange(cxfExchange, camelExchange,
+ requestContext);
+
+ // get binding operation info
+ BindingOperationInfo boi = getBindingOperationInfo(camelExchange);
+ if (LOG.isTraceEnabled()) {
+ LOG.trace("BOI = " + boi);
}
- if (dataFormat.equals(DataFormat.MESSAGE)) {
- cfb.getFeatures().add(new MessageDataFormatFeature());
- } else if (dataFormat.equals(DataFormat.PAYLOAD)) {
- cfb.getFeatures().add(new PayLoadDataFormatFeature());
+ ObjectHelper.notNull(boi, "You should set '" + CxfConstants.OPERATION_NAME
+ + "' in header.");
+
+ if (!endpoint.isWrapped() && boi != null) {
+ if (boi.isUnwrappedCapable()) {
+ boi = boi.getUnwrappedOperation();
+ if (LOG.isTraceEnabled()) {
+ LOG.trace("Unwrapped BOI " + boi);
+ }
+ }
}
- cfb.setBus(bus);
- return ((ClientProxy)Proxy.getInvocationHandler(cfb.create())).getClient();
- }
-
- public void process(Exchange exchange) throws Exception {
- CxfExchange cxfExchange = (CxfExchange) endpoint.createExchange(exchange);
- process(cxfExchange);
- exchange.copyFrom(cxfExchange);
-
+ Map<String, Object> invocationContext = new HashMap<String, Object>();
+ invocationContext.put(Client.RESPONSE_CONTEXT, responseContext);
+ invocationContext.put(Client.REQUEST_CONTEXT,
+ ((WrappedMessageContext)requestContext).getWrappedMap());
+
+ // send the CXF request
+ client.invoke(boi, getParams(endpoint, camelExchange),
+ invocationContext, cxfExchange);
+
+ // bind the CXF response to Camel exchange
+ if (!boi.getOperationInfo().isOneWay()) {
+ binding.populateExchangeFromCxfResponse(camelExchange, cxfExchange,
+ responseContext);
+ }
}
- public void process(CxfExchange exchange) throws Exception {
- Message inMessage = CxfBinding.createCxfMessage(endpoint.getHeaderFilterStrategy(), exchange);
- exchange.setProperty(CxfExchange.DATA_FORMAT, dataFormat);
-
- if (dataFormat.equals(DataFormat.POJO)) {
- // InputStream is = m.getContent(InputStream.class);
- // now we just deal with the POJO invocations
- List parameters = inMessage.getContent(List.class);
- if (parameters == null) {
- parameters = new ArrayList();
- }
- String operationName = exchange.getIn().getHeader(CxfConstants.OPERATION_NAME, String.class);
- String operationNameSpace = exchange.getIn().getHeader(CxfConstants.OPERATION_NAMESPACE,
- String.class);
- // Get context from message
- Map<String, Object> context = new HashMap<String, Object>();
- Map<String, Object> responseContext = CxfBinding.propogateContext(inMessage, context);
- Message response = new MessageImpl();
- if (operationName != null) {
- // we need to check out the operation Namespace
- Object[] result = null;
- // call for the client with the parameters
- result = invokeClient(operationNameSpace, operationName, parameters, context);
- if (result != null) {
- response.setContent(List.class, new MessageContentsList(result));
- } else {
- response.setContent(List.class, new MessageContentsList());
- }
- // copy the response context to the response
- CxfBinding.storeCXfResponseContext(response, responseContext);
- CxfBinding.storeCxfResponse(endpoint.getHeaderFilterStrategy(), exchange, response);
-
+ /**
+ * Get the parameters for the web service operation
+ */
+ private Object[] getParams(CxfEndpoint endpoint, Exchange exchange) {
+
+ Object[] params = null;
+ if (endpoint.getDataFormat() == DataFormat.POJO) {
+ List<?> list = exchange.getIn().getBody(List.class);
+ if (list != null) {
+ params = list.toArray();
} else {
- throw new RuntimeCamelException("Can't find the operation name in the message!");
+ params = new Object[0];
}
- } else {
- // get the invocation context
- org.apache.cxf.message.Exchange ex = exchange.getExchange();
- if (ex == null) {
- ex = (org.apache.cxf.message.Exchange)exchange.getProperty(CxfConstants.CXF_EXCHANGE);
- exchange.setExchange(ex);
- }
- if (ex == null) {
- ex = new ExchangeImpl();
- exchange.setExchange(ex);
- }
- assert ex != null;
- InvokingContext invokingContext = ex.get(InvokingContext.class);
- if (invokingContext == null) {
- invokingContext = InvokingContextFactory.createContext(dataFormat);
- ex.put(InvokingContext.class, invokingContext);
- }
- Map<Class, Object> params = invokingContext.getRequestContent(inMessage);
- // invoke the stream message with the exchange context
- CxfClient cxfClient = (CxfClient)client;
- // need to get the binding object to create the message
- BindingOperationInfo boi = ex.get(BindingOperationInfo.class);
- Message response = null;
- if (boi == null) {
- // it should be the raw message
- response = new MessageImpl();
+ } else if (endpoint.getDataFormat() == DataFormat.PAYLOAD) {
+ params = new Object[1];
+ params[0] = exchange.getIn().getBody();
+ } else if (endpoint.getDataFormat() == DataFormat.MESSAGE) {
+ params = new Object[1];
+ params[0] = exchange.getIn().getBody(InputStream.class);
+ }
+
+ if (LOG.isTraceEnabled()) {
+ if (params instanceof Object[]) {
+ for (int i = 0; i < params.length; i++) {
+ LOG.trace("params[" + i + "] = " + params[i]);
+ }
} else {
- // create the message here
- Endpoint ep = ex.get(Endpoint.class);
- response = ep.getBinding().createMessage();
+ LOG.trace("params = " + params);
}
- response.setExchange(ex);
- // invoke the message prepare the context
- Map<String, Object> context = new HashMap<String, Object>();
- Map<String, Object> responseContext = CxfBinding.propogateContext(inMessage, context);
-
- Object result = cxfClient.dispatch(params, context, ex);
- ex.setOutMessage(response);
- invokingContext.setResponseContent(response, result);
- // copy the response context to the response
- CxfBinding.storeCXfResponseContext(response, responseContext);
- CxfBinding.storeCxfResponse(endpoint.getHeaderFilterStrategy(), exchange, response);
-
-
}
-
+
+ return params;
}
- @Override
- protected void doStart() throws Exception {
- super.doStart();
- }
+ /**
+ * Get operation name from header and use it to lookup and return a
+ * {@link BindingOperationInfo}.
+ */
+ private BindingOperationInfo getBindingOperationInfo(Exchange ex) {
- @Override
- protected void doStop() throws Exception {
- super.doStop();
- }
+ BindingOperationInfo answer = null;
+ String lp = ex.getIn().getHeader(CxfConstants.OPERATION_NAME, String.class);
+
+ if (lp == null) {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Try to find a default operation. You should set '"
+ + CxfConstants.OPERATION_NAME + "' in header.");
+ }
+ Collection<BindingOperationInfo> bois =
+ client.getEndpoint().getEndpointInfo().getBinding().getOperations();
+
+ Iterator<BindingOperationInfo> iter = bois.iterator();
+ if (iter.hasNext()) {
+ answer = iter.next();
+ }
+
+ } else {
+ String ns = ex.getIn().getHeader(CxfConstants.OPERATION_NAMESPACE, String.class);
+ if (ns == null) {
+ ns = client.getEndpoint().getService().getName().getNamespaceURI();
+ if (LOG.isTraceEnabled()) {
+ LOG.trace("Operation namespace not in header. Set it to: " + ns);
+ }
+ }
- private Object[] invokeClient(String operationNameSpace, String operationName, List parameters,
- Map<String, Object> context) throws Exception {
+ QName qname = new QName(ns, lp);
- QName operationQName = null;
- if (operationNameSpace == null) {
- operationQName = new QName(client.getEndpoint().getService().getName().getNamespaceURI(),
- operationName);
- } else {
- operationQName = new QName(operationNameSpace, operationName);
- }
- BindingOperationInfo op = client.getEndpoint().getEndpointInfo().getBinding()
- .getOperation(operationQName);
- if (op == null) {
- throw new RuntimeCamelException("No operation found in the CXF client, the operation is "
- + operationQName);
- }
- if (!endpoint.isWrapped()) {
- if (op.isUnwrappedCapable()) {
- op = op.getUnwrappedOperation();
+ if (LOG.isTraceEnabled()) {
+ LOG.trace("Operation qname = " + qname.toString());
}
+
+ answer = client.getEndpoint().getEndpointInfo().getBinding().getOperation(qname);
}
- Object[] result = client.invoke(op, parameters.toArray(), context);
-
- return result;
+ return answer;
}
}
Modified: activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfSoapBinding.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfSoapBinding.java?rev=735592&r1=735591&r2=735592&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfSoapBinding.java (original)
+++ activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfSoapBinding.java Sun Jan 18 17:48:41 2009
@@ -17,14 +17,11 @@
package org.apache.camel.component.cxf;
import java.io.InputStream;
-import java.util.List;
-import java.util.Map;
import javax.xml.transform.Source;
import org.apache.camel.NoTypeConversionAvailableException;
import org.apache.camel.component.cxf.util.CxfHeaderHelper;
-import org.apache.camel.impl.DefaultHeaderFilterStrategy;
import org.apache.camel.spi.HeaderFilterStrategy;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
Modified: activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfSoapProducer.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfSoapProducer.java?rev=735592&r1=735591&r2=735592&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfSoapProducer.java (original)
+++ activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfSoapProducer.java Sun Jan 18 17:48:41 2009
@@ -39,7 +39,6 @@
import org.apache.cxf.Bus;
import org.apache.cxf.common.classloader.ClassLoaderUtils;
import org.apache.cxf.endpoint.ClientImpl;
-import org.apache.cxf.frontend.ClientFactoryBean;
import org.apache.cxf.frontend.ClientProxy;
import org.apache.cxf.frontend.ClientProxyFactoryBean;
import org.apache.cxf.interceptor.InterceptorChain;
Added: activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfSpringEndpoint.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfSpringEndpoint.java?rev=735592&view=auto
==============================================================================
--- activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfSpringEndpoint.java (added)
+++ activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfSpringEndpoint.java Sun Jan 18 17:48:41 2009
@@ -0,0 +1,231 @@
+/**
+ * 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.lang.reflect.Proxy;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.xml.namespace.QName;
+
+import org.apache.camel.component.cxf.spring.CxfEndpointBean;
+import org.apache.camel.component.cxf.util.CxfEndpointUtils;
+import org.apache.camel.spring.SpringCamelContext;
+import org.apache.camel.util.IntrospectionSupport;
+import org.apache.camel.util.ObjectHelper;
+import org.apache.cxf.Bus;
+import org.apache.cxf.common.classloader.ClassLoaderUtils;
+import org.apache.cxf.configuration.spring.ConfigurerImpl;
+import org.apache.cxf.endpoint.Client;
+import org.apache.cxf.frontend.ClientProxy;
+import org.apache.cxf.frontend.ClientProxyFactoryBean;
+import org.apache.cxf.frontend.ServerFactoryBean;
+
+/**
+ * Defines the <a href="http://activemq.apache.org/camel/cxf.html">CXF Endpoint</a>
+ *
+ * @version $Revision$
+ */
+public class CxfSpringEndpoint extends CxfEndpoint {
+
+ private CxfEndpointBean bean;
+ private String beanId;
+ private ConfigurerImpl configurer;
+ private String serviceNamespace;
+ private String serviceLocalName;
+ private String endpointLocalName;
+ private String endpointNamespace;
+
+ public CxfSpringEndpoint(CxfComponent cxfComponent, String beanId,
+ CxfEndpointBean bean) throws Exception {
+
+ super(cxfComponent, bean.getAddress());
+ this.beanId = beanId;
+ this.bean = bean;
+
+ // set properties from bean which can be overridden by endpoint URI
+ setPropertiesBean();
+
+ // create configurer
+ configurer = new ConfigurerImpl(((SpringCamelContext)getCamelContext())
+ .getApplicationContext());
+ }
+
+ /**
+ * Read properties from the CxfEndpointBean and copy them to the
+ * properties of this class. Note that the properties values can
+ * be overridden by values in URI query as the DefaultComponent
+ * will perform "setProperties" later (after the constructor).
+ */
+ private void setPropertiesBean() throws Exception {
+ if (bean.getProperties() != null) {
+ Map<String, Object> copy = new HashMap<String, Object>();
+ copy.putAll(bean.getProperties());
+
+ // pass the copy the method modifies the properties map
+ IntrospectionSupport.setProperties(getCamelContext().getTypeConverter(),
+ this, copy);
+ }
+ }
+
+ /**
+ *
+ * A help to get the service class. The serviceClass classname in URI
+ * query takes precedence over the serviceClass in CxfEndpointBean.
+ */
+ private Class<?> getSEIClass() throws ClassNotFoundException {
+
+ // get service class
+ Class<?> answer = null;
+ if (getServiceClass() != null) {
+ // classname is specified in URI which overrides the bean properties
+ answer = ClassLoaderUtils.loadClass(getServiceClass(), getClass());
+ } else {
+ answer = bean.getServiceClass();
+ }
+ return answer;
+ }
+
+ protected Bus doGetBus() {
+ return bean.getBus();
+ }
+
+ public CxfEndpointBean getBean() {
+ return bean;
+ }
+
+ public String getBeanId() {
+ return beanId;
+ }
+
+ // Package private methods
+ // -------------------------------------------------------------------------
+
+ /**
+ * Create a CXF Client
+ */
+ @Override
+ Client createClient() throws Exception {
+
+ // get service class
+ Class<?> cls = getSEIClass();
+ ObjectHelper.notNull(cls, CxfConstants.SERVICE_CLASS);
+
+ // create client factory bean
+ ClientProxyFactoryBean factoryBean = createClientFactoryBean(cls);
+
+ // configure client factory bean by CXF configurer
+ configure(factoryBean);
+
+ // setup client factory bean
+ setupClientFactoryBean(factoryBean, cls);
+
+ // fill in values that have not been filled.
+ QName serviceQName = null;
+ try {
+ serviceQName = factoryBean.getServiceName();
+ } catch (IllegalStateException e) {
+ // It throws IllegalStateException if serviceName has not been set.
+ }
+
+ if (serviceQName == null && getServiceLocalName() != null) {
+ factoryBean.setServiceName(new QName(getServiceNamespace(), getServiceLocalName()));
+ }
+ if (factoryBean.getEndpointName() == null && getEndpointLocalName() != null) {
+ factoryBean.setEndpointName(new QName(getEndpointNamespace(), getEndpointLocalName()));
+ }
+
+ return ((ClientProxy)Proxy.getInvocationHandler(factoryBean.create())).getClient();
+ }
+
+
+ /**
+ * Create a service factory bean
+ */
+ @Override
+ ServerFactoryBean createServerFactoryBean() throws Exception {
+
+ // get service class
+ Class<?> cls = getSEIClass();
+ ObjectHelper.notNull(cls, CxfConstants.SERVICE_CLASS);
+
+ // create server factory bean
+ ServerFactoryBean answer = CxfEndpointUtils.getServerFactoryBean(cls);
+
+ // configure server factory bean by CXF configurer
+ configure(answer);
+
+ // setup server factory bean
+ setupServerFactoryBean(answer, cls);
+
+ // fill in values that have not been filled.
+ if (answer.getServiceName() == null && getServiceLocalName() != null) {
+ answer.setServiceName(new QName(getServiceNamespace(), getServiceLocalName()));
+ }
+ if (answer.getEndpointName() == null && getEndpointLocalName() != null) {
+ answer.setEndpointName(new QName(getEndpointNamespace(), getEndpointLocalName()));
+ }
+
+ return answer;
+ }
+
+ void configure(Object beanInstance) {
+ configurer.configureBean(beanId, beanInstance);
+ }
+
+ // Properties
+ // -------------------------------------------------------------------------
+
+ public void setServiceNamespace(String serviceNamespace) {
+ this.serviceNamespace = serviceNamespace;
+ }
+
+
+ public String getServiceNamespace() {
+ return serviceNamespace;
+ }
+
+
+ public void setServiceLocalName(String serviceLocalName) {
+ this.serviceLocalName = serviceLocalName;
+ }
+
+
+ public String getServiceLocalName() {
+ return serviceLocalName;
+ }
+
+ public String getEndpointLocalName() {
+ return endpointLocalName;
+ }
+
+ public void setEndpointLocalName(String endpointLocalName) {
+ this.endpointLocalName = endpointLocalName;
+ }
+
+
+ public void setEndpointNamespace(String endpointNamespace) {
+ this.endpointNamespace = endpointNamespace;
+ }
+
+
+ public String getEndpointNamespace() {
+ return endpointNamespace;
+ }
+
+
+}
Propchange: activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfSpringEndpoint.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfSpringEndpoint.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified: activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/DataFormat.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/DataFormat.java?rev=735592&r1=735591&r2=735592&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/DataFormat.java (original)
+++ activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/DataFormat.java Sun Jan 18 17:48:41 2009
@@ -41,20 +41,6 @@
* must be included in the endpoint. Streaming is not available for this
* data format.
*/
- POJO,
-
- /**
- * For UNKNOWN cases.
- */
- UNKNOWN;
-
-
-
- public static DataFormat asEnum(String value) {
- try {
- return valueOf(value.toUpperCase());
- } catch (Exception e) {
- return UNKNOWN;
- }
- }
+ POJO
+
}