camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject camel git commit: CAMEL-8935: camel-spring-ws - Expose more options
Date Mon, 06 Jul 2015 09:47:55 GMT
Repository: camel
Updated Branches:
  refs/heads/master d99acf59f -> 57395f8a1


CAMEL-8935: camel-spring-ws - Expose more options


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/57395f8a
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/57395f8a
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/57395f8a

Branch: refs/heads/master
Commit: 57395f8a15d4591b2c85344834376aa658a1ca42
Parents: d99acf5
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Mon Jul 6 11:53:58 2015 +0200
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Mon Jul 6 11:53:58 2015 +0200

----------------------------------------------------------------------
 .../spring/ws/SpringWebserviceComponent.java    | 51 +++++++++-----------
 .../ws/SpringWebserviceConfiguration.java       | 32 ++++++++----
 .../spring/ws/DefaultMessageFilter-context.xml  |  4 +-
 .../spring/ws/MessageFilter-context.xml         |  4 +-
 4 files changed, 51 insertions(+), 40 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/57395f8a/components/camel-spring-ws/src/main/java/org/apache/camel/component/spring/ws/SpringWebserviceComponent.java
----------------------------------------------------------------------
diff --git a/components/camel-spring-ws/src/main/java/org/apache/camel/component/spring/ws/SpringWebserviceComponent.java
b/components/camel-spring-ws/src/main/java/org/apache/camel/component/spring/ws/SpringWebserviceComponent.java
index 554668a..ea065d0 100644
--- a/components/camel-spring-ws/src/main/java/org/apache/camel/component/spring/ws/SpringWebserviceComponent.java
+++ b/components/camel-spring-ws/src/main/java/org/apache/camel/component/spring/ws/SpringWebserviceComponent.java
@@ -27,6 +27,7 @@ import org.apache.camel.RuntimeCamelException;
 import org.apache.camel.component.spring.ws.bean.CamelEndpointDispatcher;
 import org.apache.camel.component.spring.ws.bean.CamelSpringWSEndpointMapping;
 import org.apache.camel.component.spring.ws.filter.MessageFilter;
+import org.apache.camel.component.spring.ws.filter.impl.BasicMessageFilter;
 import org.apache.camel.component.spring.ws.type.EndpointMappingKey;
 import org.apache.camel.component.spring.ws.type.EndpointMappingType;
 import org.apache.camel.converter.jaxp.XmlConverter;
@@ -36,9 +37,7 @@ import org.apache.camel.util.EndpointHelper;
 import org.apache.camel.util.UnsafeUriCharactersEncoder;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-import org.springframework.ws.WebServiceMessageFactory;
 import org.springframework.ws.client.core.WebServiceTemplate;
-import org.springframework.ws.transport.WebServiceMessageSender;
 import org.springframework.xml.xpath.XPathExpression;
 import org.springframework.xml.xpath.XPathExpressionFactory;
 
@@ -66,10 +65,10 @@ public class SpringWebserviceComponent extends UriEndpointComponent {
     protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object>
parameters) throws Exception {
         SpringWebserviceConfiguration configuration = new SpringWebserviceConfiguration();
         addConsumerConfiguration(remaining, parameters, configuration);
-        addProducerConfiguration(remaining, parameters, configuration);
         addXmlConverterToConfiguration(parameters, configuration);
-        configureMessageFilter(parameters, configuration);
         setProperties(configuration, parameters);
+        configureProducerConfiguration(remaining, configuration);
+        configureMessageFilter(configuration);
         return new SpringWebserviceEndpoint(this, uri, configuration);
     }
 
@@ -93,7 +92,7 @@ public class SpringWebserviceComponent extends UriEndpointComponent {
         }
     }
 
-    private void addProducerConfiguration(String remaining, Map<String, Object> parameters,
SpringWebserviceConfiguration configuration) throws URISyntaxException {
+    private void configureProducerConfiguration(String remaining, SpringWebserviceConfiguration
configuration) throws URISyntaxException {
         if (configuration.getEndpointMapping() == null && configuration.getEndpointDispatcher()
== null) {
             LOG.debug("Building Spring Web Services producer");
             URI webServiceEndpointUri = new URI(UnsafeUriCharactersEncoder.encode(remaining));
@@ -101,25 +100,23 @@ public class SpringWebserviceComponent extends UriEndpointComponent
{
             // Obtain a WebServiceTemplate from the registry when specified by
             // an option on the component, else create a new template with
             // Spring-WS defaults
-            WebServiceTemplate webServiceTemplate = resolveAndRemoveReferenceParameter(parameters,
-                    "webServiceTemplate", WebServiceTemplate.class, new WebServiceTemplate());
-            WebServiceMessageSender messageSender = resolveAndRemoveReferenceParameter(parameters,
-                    "messageSender", WebServiceMessageSender.class, null);
-            WebServiceMessageFactory messageFactory = resolveAndRemoveReferenceParameter(parameters,
-                    "messageFactory", WebServiceMessageFactory.class, null);
+            WebServiceTemplate webServiceTemplate = configuration.getWebServiceTemplate();
+            if (webServiceTemplate == null) {
+                webServiceTemplate = new WebServiceTemplate();
+                configuration.setWebServiceTemplate(webServiceTemplate);
+            }
 
             if (webServiceTemplate.getDefaultUri() == null) {
                 String uri = webServiceEndpointUri.toString();
                 webServiceTemplate.setDefaultUri(uri);
                 configuration.setWebServiceEndpointUri(uri);
             }
-            if (messageSender != null) {
-                webServiceTemplate.setMessageSender(messageSender);
+            if (configuration.getMessageSender() != null) {
+                webServiceTemplate.setMessageSender(configuration.getMessageSender());
             }
-            if (messageFactory != null) {
-                webServiceTemplate.setMessageFactory(messageFactory);
+            if (configuration.getMessageFactory() != null) {
+                webServiceTemplate.setMessageFactory(configuration.getMessageFactory());
             }
-            configuration.setWebServiceTemplate(webServiceTemplate);
         }
     }
 
@@ -168,18 +165,18 @@ public class SpringWebserviceComponent extends UriEndpointComponent
{
      * The bean search mechanism looks for a bean with the name messageFilter.
      * The endpoint's URI search mechanism looks for the URI's key parameter name messageFilter,
for instance like this:
      * spring-ws:http://yourdomain.com?messageFilter=<beanName>
-     * 
-     * @param parameters
-     * @param configuration
      */
-    private void configureMessageFilter(Map<String, Object> parameters, SpringWebserviceConfiguration
configuration) {
-
-        final MessageFilter globalMessageFilter = EndpointHelper.resolveReferenceParameter(
-                                                      getCamelContext(), "messageFilter",
MessageFilter.class, false /*not mandatory*/);
-        final MessageFilter messageFilter = resolveAndRemoveReferenceParameter(
-                                                      parameters, "messageFilter", MessageFilter.class,
globalMessageFilter);
-
-        configuration.setMessageFilter(messageFilter);
+    private void configureMessageFilter(SpringWebserviceConfiguration configuration) {
+        if (configuration.getMessageFilter() == null) {
+            // try to lookup a global filter to use
+            final MessageFilter globalMessageFilter = EndpointHelper.resolveReferenceParameter(getCamelContext(),
"messageFilter", MessageFilter.class, false);
+            if (globalMessageFilter != null) {
+                configuration.setMessageFilter(globalMessageFilter);
+            } else {
+                // use basic as fallback
+                configuration.setMessageFilter(new BasicMessageFilter());
+            }
+        }
     }
 
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/57395f8a/components/camel-spring-ws/src/main/java/org/apache/camel/component/spring/ws/SpringWebserviceConfiguration.java
----------------------------------------------------------------------
diff --git a/components/camel-spring-ws/src/main/java/org/apache/camel/component/spring/ws/SpringWebserviceConfiguration.java
b/components/camel-spring-ws/src/main/java/org/apache/camel/component/spring/ws/SpringWebserviceConfiguration.java
index 1659749..477b4f1 100644
--- a/components/camel-spring-ws/src/main/java/org/apache/camel/component/spring/ws/SpringWebserviceConfiguration.java
+++ b/components/camel-spring-ws/src/main/java/org/apache/camel/component/spring/ws/SpringWebserviceConfiguration.java
@@ -30,6 +30,7 @@ import org.apache.camel.spi.UriParams;
 import org.apache.camel.spi.UriPath;
 import org.apache.camel.util.jsse.SSLContextParameters;
 import org.springframework.util.StringUtils;
+import org.springframework.ws.WebServiceMessageFactory;
 import org.springframework.ws.client.core.WebServiceTemplate;
 import org.springframework.ws.soap.addressing.messageid.MessageIdStrategy;
 import org.springframework.ws.soap.addressing.server.annotation.Action;
@@ -39,17 +40,22 @@ import org.springframework.ws.transport.WebServiceMessageSender;
 public class SpringWebserviceConfiguration {
 
     private XmlConverter xmlConverter;
-    private MessageFilter messageFilter;
 
-    @UriParam(label = "consumer")
-    private EndpointMappingKey endpointMappingKey;
     @UriPath(label = "producer")
     private String webServiceEndpointUri;
 
+    /* Common configuration */
+    @UriParam
+    private MessageFilter messageFilter;
+
     /* Producer configuration */
     @UriParam(label = "producer")
     private WebServiceTemplate webServiceTemplate;
     @UriParam(label = "producer")
+    private WebServiceMessageSender messageSender;
+    @UriParam(label = "producer")
+    private WebServiceMessageFactory messageFactory;
+    @UriParam(label = "producer")
     private String soapAction;
     @UriParam(label = "producer")
     private URI wsAddressingAction;
@@ -62,14 +68,14 @@ public class SpringWebserviceConfiguration {
     @UriParam(label = "producer")
     private URI replyTo;
     @UriParam(label = "producer")
-    private WebServiceMessageSender messageSender;
-    @UriParam(label = "producer")
     private MessageIdStrategy messageIdStrategy;
     @UriParam(label = "producer")
     private int timeout = -1;
 
     /* Consumer configuration */
     @UriParam(label = "consumer")
+    private EndpointMappingKey endpointMappingKey;
+    @UriParam(label = "consumer")
     private CamelSpringWSEndpointMapping endpointMapping;
     @UriParam(label = "consumer")
     private CamelEndpointDispatcher endpointDispatcher;
@@ -91,6 +97,17 @@ public class SpringWebserviceConfiguration {
         this.webServiceTemplate = webServiceTemplate;
     }
 
+    public WebServiceMessageFactory getMessageFactory() {
+        return messageFactory;
+    }
+
+    /**
+     * Option to provide a custom WebServiceMessageFactory. For example when you want Apache
Axiom to handle web service messages instead of SAAJ.
+     */
+    public void setMessageFactory(WebServiceMessageFactory messageFactory) {
+        this.messageFactory = messageFactory;
+    }
+
     public String getWebServiceEndpointUri() {
         return webServiceEndpointUri;
     }
@@ -242,10 +259,7 @@ public class SpringWebserviceConfiguration {
     }
 
     public MessageFilter getMessageFilter() {
-        if (this.messageFilter == null) {
-            this.messageFilter = new BasicMessageFilter();
-        }
-        return this.messageFilter;
+        return messageFilter;
     }
 
     public URI getOutputAction() {

http://git-wip-us.apache.org/repos/asf/camel/blob/57395f8a/components/camel-spring-ws/src/test/resources/org/apache/camel/component/spring/ws/DefaultMessageFilter-context.xml
----------------------------------------------------------------------
diff --git a/components/camel-spring-ws/src/test/resources/org/apache/camel/component/spring/ws/DefaultMessageFilter-context.xml
b/components/camel-spring-ws/src/test/resources/org/apache/camel/component/spring/ws/DefaultMessageFilter-context.xml
index f7d306d..94bf3e3 100644
--- a/components/camel-spring-ws/src/test/resources/org/apache/camel/component/spring/ws/DefaultMessageFilter-context.xml
+++ b/components/camel-spring-ws/src/test/resources/org/apache/camel/component/spring/ws/DefaultMessageFilter-context.xml
@@ -42,12 +42,12 @@
 		<route>
 			<from uri="direct:sendWithLocalFilter" />
 			<to
-				uri="spring-ws:http://localhost/testSender?endpointMapping=#endpointMapping&amp;messageFilter=local&amp;webServiceTemplate=#webServiceTemplate"
/>
+				uri="spring-ws:http://localhost/testSender?endpointMapping=#endpointMapping&amp;messageFilter=#local&amp;webServiceTemplate=#webServiceTemplate"
/>
 		</route>
 		<route>
 			<from uri="direct:sendWithoutFilter" />
 			<to
-				uri="spring-ws:http://localhost/testSender?endpointMapping=#endpointMapping&amp;messageFilter=empty&amp;webServiceTemplate=#webServiceTemplate"
/>
+				uri="spring-ws:http://localhost/testSender?endpointMapping=#endpointMapping&amp;messageFilter=#empty&amp;webServiceTemplate=#webServiceTemplate"
/>
 		</route>
 		<route>
 			<from uri="direct:sendDefault" />

http://git-wip-us.apache.org/repos/asf/camel/blob/57395f8a/components/camel-spring-ws/src/test/resources/org/apache/camel/component/spring/ws/MessageFilter-context.xml
----------------------------------------------------------------------
diff --git a/components/camel-spring-ws/src/test/resources/org/apache/camel/component/spring/ws/MessageFilter-context.xml
b/components/camel-spring-ws/src/test/resources/org/apache/camel/component/spring/ws/MessageFilter-context.xml
index 13c4b9b..13773fd 100644
--- a/components/camel-spring-ws/src/test/resources/org/apache/camel/component/spring/ws/MessageFilter-context.xml
+++ b/components/camel-spring-ws/src/test/resources/org/apache/camel/component/spring/ws/MessageFilter-context.xml
@@ -42,12 +42,12 @@
 		<route>
 			<from uri="direct:sendWithLocalFilter" />
 			<to
-				uri="spring-ws:http://localhost/testSender?endpointMapping=#endpointMapping&amp;messageFilter=local&amp;webServiceTemplate=#webServiceTemplate"
/>
+				uri="spring-ws:http://localhost/testSender?endpointMapping=#endpointMapping&amp;messageFilter=#local&amp;webServiceTemplate=#webServiceTemplate"
/>
 		</route>
 		<route>
 			<from uri="direct:sendWithoutFilter" />
 			<to
-				uri="spring-ws:http://localhost/testSender?endpointMapping=#endpointMapping&amp;messageFilter=empty&amp;webServiceTemplate=#webServiceTemplate"
/>
+				uri="spring-ws:http://localhost/testSender?endpointMapping=#endpointMapping&amp;messageFilter=#empty&amp;webServiceTemplate=#webServiceTemplate"
/>
 		</route>
 	</camelContext>
 


Mime
View raw message