Skip to content

Commit 752b98f

Browse files
authored
Spring WS docs and code cleanup. (#15382)
* Spring WS docs and code cleanup. * Missing files from compilation * Adding .gitignore entry for camel-ignite build leftovers on MacOS
1 parent 5171dac commit 752b98f

File tree

13 files changed

+74
-94
lines changed

13 files changed

+74
-94
lines changed

components/camel-ignite/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ignite

components/camel-spring-ws/src/main/docs/spring-ws-component.adoc

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*{component-header}*
1717

1818
The Spring WS component allows you to integrate with
19-
http://static.springsource.org/spring-ws/sites/1.5/[Spring Web
19+
https://docs.spring.io/spring-ws/docs/4.0.x/reference/html/[Spring Web
2020
Services]. It offers both _client_-side support, for accessing web
2121
services, and _server_-side support for creating your own contract-first
2222
web services.
@@ -59,21 +59,23 @@ the header of the message.
5959

6060
|`uri` |To map web service requests that target a specific URI.
6161

62+
|`uripath` |To map web service requests that target a specific path in URI.
63+
6264
|`xpathresult` |Used to map web service requests based on the evaluation of an XPath
6365
`expression` against the incoming message. The result of the evaluation
6466
should match the XPath result specified in the endpoint URI.
6567

6668
|`beanname` |Allows you to reference an
6769
`org.apache.camel.component.spring.ws.bean.CamelEndpointDispatcher`
6870
object to integrate with existing (legacy)
69-
http://static.springsource.org/spring-ws/sites/1.5/reference/html/server.html#server-endpoint-mapping[endpoint
71+
https://docs.spring.io/spring-ws/docs/4.0.x/reference/html/#server-endpoint-mapping[endpoint
7072
mappings] like `PayloadRootQNameEndpointMapping`,
7173
`SoapActionEndpointMapping`, etc.
7274
|=======================================================================
7375

7476
As a consumer, the *address* should contain a value relevant to the
7577
specified mapping-type (e.g. a SOAP action, XPath expression). As a
76-
producer, the address should be set to the URI of the web service your
78+
producer, the address should be set to the URI of the web service your
7779
calling upon.
7880

7981

@@ -161,16 +163,16 @@ Likewise, the spring-ws consumer will also enrich the Camel Message with
161163
the SOAP header.
162164

163165
For example, see this
164-
https://svn.apache.org/repos/asf/camel/trunk/components/camel-spring-ws/src/test/java/org/apache/camel/component/spring/ws/SoapHeaderTest.java[unit
166+
https://github.com/apache/camel/blob/main/components/camel-spring-ws/src/test/java/org/apache/camel/component/spring/ws/SoapHeaderTest.java[unit
165167
test].
166168

167169
=== The header and attachment propagation
168170

169171
Spring WS Camel supports propagation of the headers and attachments into
170-
Spring-WS WebServiceMessage response. The
171-
endpoint will use so-called "hook" the MessageFilter (default
172-
implementation is provided by BasicMessageFilter) to propagate the
173-
exchange headers and attachments into WebServiceMessage response. Now
172+
Spring-WS `WebServiceMessage` response. The
173+
endpoint will use so-called "hook" the `MessageFilter` (default
174+
implementation is provided by `BasicMessageFilter`) to propagate the
175+
exchange headers and attachments into `WebServiceMessage` response. Now
174176
you can use
175177

176178
[source,java]
@@ -188,7 +190,7 @@ a QName class directly and put any key into header.
188190

189191
=== How to transform the soap header using a stylesheet
190192

191-
The header transformation filter (HeaderTransformationMessageFilter.java)
193+
The header transformation filter (`HeaderTransformationMessageFilter`)
192194
can be used to transform the soap header for a soap request. If you want to use
193195
the header transformation filter, see the below example:
194196

@@ -212,9 +214,9 @@ Use the bead defined above in the camel endpoint
212214
=== The custom header and attachment filtering
213215

214216
If you need to provide your custom processing of either headers or
215-
attachments, extend existing BasicMessageFilter and override the
217+
attachments, extend existing `BasicMessageFilter` and override the
216218
appropriate methods or write a brand-new implementation of the
217-
MessageFilter interface.
219+
`MessageFilter` interface.
218220
To use your custom filter, add this into your spring context:
219221

220222
You can specify either a global a or a local message filter as
@@ -275,20 +277,13 @@ Spring configuration:
275277
</bean>
276278
</property>
277279
</bean>
278-
279-
<!-- force use of Sun SAAJ implementation, https://static.springsource.org/spring-ws/sites/1.5/faq.html#saaj-jboss -->
280-
<bean id="messageFactory" class="org.springframework.ws.soap.saaj.SaajSoapMessageFactory">
281-
<property name="messageFactory">
282-
<bean class="com.sun.xml.messaging.saaj.soap.ver1_1.SOAPMessageFactory1_1Impl"/>
283-
</property>
284-
</bean>
285280
---------------------------------------------------------------------------------------------------------------------
286281

287282
=== Exposing web services
288283

289284
To expose a web service using this component, you first need to
290285
set up a
291-
http://static.springsource.org/spring-ws/sites/1.5/reference/html/server.html[MessageDispatcher]
286+
https://docs.spring.io/spring-ws/docs/4.0.x/reference/html/#_the_messagedispatcher[MessageDispatcher]
292287
to look for endpoint mappings in a Spring XML file. If you plan on
293288
running inside a servlet container, you probably want to use a
294289
`MessageDispatcherServlet` configured in `web.xml`.
@@ -335,7 +330,7 @@ _spring-ws-servlet.xml_
335330
----------------------------------------------------------------------------------------------------
336331

337332
More information on setting up Spring-WS can be found in
338-
http://static.springsource.org/spring-ws/sites/1.5/reference/html/tutorial.html[Writing
333+
https://docs.spring.io/spring-ws/docs/4.0.x/reference/html/#tutorial[Writing
339334
Contract-First Web Services]. Basically paragraph 3.6 "Implementing the
340335
Endpoint" is handled by this component (specifically paragraph 3.6.2
341336
"Routing the Message to the Endpoint" is where `CamelEndpointMapping`
@@ -389,9 +384,9 @@ from("spring-ws:xpathresult:abc?expression=//foobar&endpointMapping=#endpointMap
389384

390385
For every endpoint with mapping-type `beanname` one bean of type
391386
`CamelEndpointDispatcher` with a corresponding name is required in the
392-
Registry/ApplicationContext. This bean acts as a bridge between the
387+
`Registry`/`ApplicationContext`. This bean acts as a bridge between the
393388
Camel endpoint and an existing
394-
http://static.springsource.org/spring-ws/sites/1.5/reference/html/server.html#server-endpoint-mapping[endpoint
389+
https://docs.spring.io/spring-ws/docs/4.0.x/reference/html/#server-endpoint-mapping[endpoint
395390
mapping] like `PayloadRootQNameEndpointMapping`.
396391

397392
[NOTE]

components/camel-spring-ws/src/main/java/org/apache/camel/component/spring/ws/SpringWebserviceComponent.java

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -75,20 +75,19 @@ private void addConsumerConfiguration(
7575
if (type != null) {
7676
LOG.debug("Building Spring Web Services consumer of type {}", type);
7777
String lookupKey = getLookupKey(remaining, type);
78+
configuration.setEndpointMappingType(type);
79+
configuration.setEndpointMappingLookupKey(lookupKey);
7880
if (EndpointMappingType.BEANNAME.equals(type)) {
7981
addEndpointDispatcherToConfiguration(configuration, lookupKey);
8082
} else {
8183
addEndpointMappingToConfiguration(parameters, configuration);
84+
if (type.equals(EndpointMappingType.XPATHRESULT)) {
85+
String expression = getAndRemoveParameter(parameters, "expression", String.class);
86+
configuration.setExpression(expression);
87+
XPathExpression xPathExpression = createXPathExpression(expression);
88+
configuration.setxPathExpression(xPathExpression);
89+
}
8290
}
83-
XPathExpression xPathExpression = null;
84-
if (type.equals(EndpointMappingType.XPATHRESULT)) {
85-
String expression = getAndRemoveParameter(parameters, "expression", String.class);
86-
configuration.setExpression(expression);
87-
xPathExpression = createXPathExpression(expression);
88-
configuration.setxPathExpression(xPathExpression);
89-
}
90-
configuration.setEndpointMappingType(type);
91-
configuration.setEndpointMappingLookupKey(lookupKey);
9291
}
9392
}
9493

@@ -131,8 +130,7 @@ private XPathExpression createXPathExpression(String xpathExpression) {
131130
if (xpathExpression == null) {
132131
throw new RuntimeCamelException("Expression parameter is required when using XPath endpoint mapping");
133132
}
134-
XPathExpression expression = XPathExpressionFactory.createXPathExpression(xpathExpression);
135-
return expression;
133+
return XPathExpressionFactory.createXPathExpression(xpathExpression);
136134
}
137135

138136
private void addEndpointMappingToConfiguration(
@@ -159,7 +157,7 @@ private void addEndpointDispatcherToConfiguration(SpringWebserviceConfiguration
159157
/**
160158
* Configures the messageFilter's factory. The factory is looked up in the endpoint's URI and then in the Spring's
161159
* context. The bean search mechanism looks for a bean with the name messageFilter. The endpoint's URI search
162-
* mechanism looks for the URI's key parameter name messageFilter, for instance like this:
160+
* mechanism looks for the URI's key parameter name messageFilter, for instance, like this:
163161
* spring-ws:http://yourdomain.com?messageFilter=<beanName>
164162
*/
165163
private void configureMessageFilter(SpringWebserviceConfiguration configuration) {

components/camel-spring-ws/src/main/java/org/apache/camel/component/spring/ws/SpringWebserviceConsumer.java

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@
4646

4747
public class SpringWebserviceConsumer extends DefaultConsumer implements MessageEndpoint {
4848

49-
private SpringWebserviceEndpoint endpoint;
50-
private SpringWebserviceConfiguration configuration;
49+
private final SpringWebserviceEndpoint endpoint;
50+
private final SpringWebserviceConfiguration configuration;
5151

5252
public SpringWebserviceConsumer(Endpoint endpoint, Processor processor) {
5353
super(endpoint, processor);
@@ -70,7 +70,7 @@ public void invoke(MessageContext messageContext) throws Exception {
7070
populateExchangeFromMessageContext(messageContext, exchange);
7171

7272
// populate camel exchange with breadcrumb from transport header
73-
if (getEndpoint().getCamelContext().isUseBreadcrumb()) {
73+
if (Boolean.TRUE.equals(getEndpoint().getCamelContext().isUseBreadcrumb())) {
7474
populateExchangeWithBreadcrumbFromMessageContext(messageContext, exchange);
7575
}
7676

@@ -94,8 +94,7 @@ public void invoke(MessageContext messageContext) throws Exception {
9494
}
9595

9696
private void populateExchangeWithBreadcrumbFromMessageContext(MessageContext messageContext, Exchange exchange) {
97-
if (messageContext.getRequest() instanceof SaajSoapMessage) {
98-
SaajSoapMessage saajSoap = (SaajSoapMessage) messageContext.getRequest();
97+
if (messageContext.getRequest() instanceof SaajSoapMessage saajSoap) {
9998
populateExchangeWithBreadcrumbFromSaajMessage(exchange, saajSoap);
10099
} else {
101100
populateExchangeWithBreadcrumbFromMessageContext(exchange, messageContext);
@@ -171,8 +170,7 @@ private void populateExchangeWithPropertiesFromMessageContext(
171170
* @param request the WebService Request
172171
*/
173172
private void extractSourceFromSoapHeader(Map<String, Object> headers, WebServiceMessage request) {
174-
if (request instanceof SoapMessage) {
175-
SoapMessage soapMessage = (SoapMessage) request;
173+
if (request instanceof SoapMessage soapMessage) {
176174
SoapHeader soapHeader = soapMessage.getSoapHeader();
177175

178176
if (soapHeader != null) {
@@ -203,12 +201,12 @@ private void extractAttachmentsFromRequest(
203201

204202
DefaultAttachmentMessage dam = null;
205203

206-
if (request instanceof MimeMessage) {
207-
Iterator<Attachment> attachmentsIterator = ((MimeMessage) request).getAttachments();
204+
if (request instanceof MimeMessage mimeMessage) {
205+
Iterator<Attachment> attachmentsIterator = mimeMessage.getAttachments();
208206
while (attachmentsIterator.hasNext()) {
209207
Attachment attachment = attachmentsIterator.next();
210208
if (dam == null) {
211-
// this is just a wrapper which will set data on the IN
209+
// this is just a wrapper that will set data on the IN
212210
dam = new DefaultAttachmentMessage(exchange.getIn());
213211
}
214212
dam.addAttachment(attachment.getContentId(), attachment.getDataHandler());

components/camel-spring-ws/src/main/java/org/apache/camel/component/spring/ws/bean/CamelDirectConnection.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
public class CamelDirectConnection implements WebServiceConnection {
3535
private static final Logger LOG = LoggerFactory.getLogger(CamelDirectConnection.class);
3636
private CamelContext camelContext;
37-
private URI destination;
37+
private final URI destination;
3838

3939
public CamelDirectConnection(CamelContext camelContext, URI uri) throws URISyntaxException {
4040
this.camelContext = camelContext;

components/camel-spring-ws/src/main/java/org/apache/camel/component/spring/ws/bean/CamelEndpointMapping.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public class CamelEndpointMapping extends AbstractEndpointMapping
8383

8484
private static final String DOUBLE_QUOTE = "\"";
8585
private static final String URI_PATH_WILDCARD = "*";
86-
private Map<EndpointMappingKey, MessageEndpoint> endpoints = new ConcurrentHashMap<>();
86+
private final Map<EndpointMappingKey, MessageEndpoint> endpoints = new ConcurrentHashMap<>();
8787
private TransformerFactory transformerFactory;
8888
private CamelContext camelContext;
8989

@@ -157,8 +157,7 @@ protected final EndpointInvocationChain createEndpointInvocationChain(
157157
}
158158

159159
private String getSoapAction(MessageContext messageContext) {
160-
if (messageContext.getRequest() instanceof SoapMessage) {
161-
SoapMessage request = (SoapMessage) messageContext.getRequest();
160+
if (messageContext.getRequest() instanceof SoapMessage request) {
162161
String soapAction = request.getSoapAction();
163162
if (StringUtils.hasLength(soapAction) && soapAction.startsWith(DOUBLE_QUOTE) && soapAction.endsWith(DOUBLE_QUOTE)) {
164163
return soapAction.substring(1, soapAction.length() - 1);

components/camel-spring-ws/src/main/java/org/apache/camel/component/spring/ws/bean/CamelSpringWSEndpointMapping.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import org.springframework.ws.server.endpoint.MessageEndpoint;
2222

2323
/**
24-
* Allows to register different spring-ws endpoints for camel.
24+
* Allows registering different spring-ws endpoints for camel.
2525
*/
2626
public interface CamelSpringWSEndpointMapping extends EndpointMapping {
2727

components/camel-spring-ws/src/main/java/org/apache/camel/component/spring/ws/bean/WSACamelEndpointMapping.java

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,10 @@
3131
import org.springframework.ws.soap.addressing.core.MessageAddressingProperties;
3232
import org.springframework.ws.soap.addressing.messageid.MessageIdStrategy;
3333
import org.springframework.ws.soap.addressing.server.AbstractAddressingEndpointMapping;
34-
import org.springframework.ws.soap.addressing.server.AnnotationActionEndpointMapping;
3534
import org.springframework.ws.transport.WebServiceMessageSender;
3635

36+
import static org.springframework.ws.soap.addressing.server.AbstractActionEndpointMapping.DEFAULT_OUTPUT_ACTION_SUFFIX;
37+
3738
/**
3839
* Provides support for full WS-Addressing. Supported are faultAction and response action. For more details look at @see
3940
* {@link AbstractAddressingEndpointMapping}. Implementation of the
@@ -45,32 +46,26 @@ public class WSACamelEndpointMapping extends AbstractAddressingEndpointMapping i
4546

4647
private static final Logger LOG = LoggerFactory.getLogger(WSACamelEndpointMapping.class);
4748

48-
private Map<EndpointMappingKey, MessageEndpoint> endpoints = new ConcurrentHashMap<>();
49+
private final Map<EndpointMappingKey, MessageEndpoint> endpoints = new ConcurrentHashMap<>();
4950

50-
private String outputActionSuffix = AnnotationActionEndpointMapping.DEFAULT_OUTPUT_ACTION_SUFFIX;
51+
private String outputActionSuffix = DEFAULT_OUTPUT_ACTION_SUFFIX;
5152

52-
private String faultActionSuffix = AnnotationActionEndpointMapping.DEFAULT_OUTPUT_ACTION_SUFFIX;
53+
private String faultActionSuffix = DEFAULT_OUTPUT_ACTION_SUFFIX;
5354

5455
@Override
5556
protected Object getEndpointInternal(MessageAddressingProperties map) {
5657
// search the endpoint with compositeKeyFirst
5758
for (Map.Entry<EndpointMappingKey, MessageEndpoint> endpointEntry : endpoints.entrySet()) {
5859
EndpointMappingKey key = endpointEntry.getKey();
59-
String compositeOrSimpleKey = null;
60-
switch (key.getType()) {
61-
case ACTION:
62-
compositeOrSimpleKey = getActionCompositeLookupKey(map);
63-
break;
64-
case TO:
65-
compositeOrSimpleKey = getToCompositeLookupKey(map);
66-
break;
67-
default:
68-
throw new RuntimeCamelException(
69-
"Invalid mapping type specified. Supported types are: spring-ws:action:<WS-Addressing Action>(optional:<WS-Addressing To>?<params...>\n)"
70-
+ "spring-ws:to:<WS-Addressing To>(optional:<WS-Addressing Action>?<params...>)");
71-
}
60+
String compositeOrSimpleKey = switch (key.getType()) {
61+
case ACTION -> getActionCompositeLookupKey(map);
62+
case TO -> getToCompositeLookupKey(map);
63+
default -> throw new RuntimeCamelException(
64+
"Invalid mapping type specified. Supported types are: spring-ws:action:<WS-Addressing Action>(optional:<WS-Addressing To>?<params...>\n)"
65+
+ "spring-ws:to:<WS-Addressing To>(optional:<WS-Addressing Action>?<params...>)");
66+
};
7267
// lookup for specific endpoint
73-
if (compositeOrSimpleKey != null && key.getLookupKey().equals(compositeOrSimpleKey)) {
68+
if (key.getLookupKey().equals(compositeOrSimpleKey)) {
7469
LOG.debug("Found mapping for key {}", key);
7570
return endpointEntry.getValue();
7671
}
@@ -97,7 +92,7 @@ protected Object getEndpointInternal(MessageAddressingProperties map) {
9792
+ "spring-ws:to:<WS-Addressing To>(optional:<WS-Addressing Action>?<params...>)");
9893
}
9994
// look up for less specific endpoint
100-
if (simpleKey != null && key.getLookupKey().equals(simpleKey)) {
95+
if (key.getLookupKey().equals(simpleKey)) {
10196
LOG.debug("Found mapping for key {}", key);
10297
return endpointEntry.getValue();
10398
}
@@ -106,7 +101,7 @@ protected Object getEndpointInternal(MessageAddressingProperties map) {
106101
}
107102

108103
/**
109-
* Generate a lookupKey for a given WS-Addressing message using action property. The possible combination are:
104+
* Generate a lookupKey for a given WS-Addressing message using action property. The possible combination is:
110105
* <ul>
111106
* <li>wsaAction</li>
112107
* <li>wsaAction:wsaGetTo</li>
@@ -222,7 +217,7 @@ private SpringWebserviceEndpoint getSpringWebserviceEndpoint(Object endpoint) {
222217
protected URI getDefaultResponseAction(Object endpoint, MessageAddressingProperties requestMap) {
223218
URI requestAction = requestMap.getAction();
224219
if (requestAction != null) {
225-
return URI.create(requestAction.toString() + getOutputActionSuffix());
220+
return URI.create(requestAction + getOutputActionSuffix());
226221
} else {
227222
return null;
228223
}
@@ -231,7 +226,7 @@ protected URI getDefaultResponseAction(Object endpoint, MessageAddressingPropert
231226
protected URI getDefaultFaultAction(Object endpoint, MessageAddressingProperties requestMap) {
232227
URI requestAction = requestMap.getAction();
233228
if (requestAction != null) {
234-
return URI.create(requestAction.toString() + getFaultActionSuffix());
229+
return URI.create(requestAction + getFaultActionSuffix());
235230
} else {
236231
return null;
237232
}
@@ -257,7 +252,7 @@ public String getOutputActionSuffix() {
257252
/**
258253
* Sets the suffix to add to request <code>Action</code>s for reply messages.
259254
*
260-
* @see #DEFAULT_OUTPUT_ACTION_SUFFIX
255+
* @see org.springframework.ws.soap.addressing.server.AbstractActionEndpointMapping#DEFAULT_OUTPUT_ACTION_SUFFIX
261256
*/
262257
public void setOutputActionSuffix(String outputActionSuffix) {
263258
Assert.hasText(outputActionSuffix, "'outputActionSuffix' must not be empty");
@@ -274,7 +269,7 @@ public String getFaultActionSuffix() {
274269
/**
275270
* Sets the suffix to add to request <code>Action</code>s for reply fault messages.
276271
*
277-
* @see #DEFAULT_FAULT_ACTION_SUFFIX
272+
* @see org.springframework.ws.soap.addressing.server.AbstractActionEndpointMapping#DEFAULT_FAULT_ACTION_SUFFIX
278273
*/
279274
public void setFaultActionSuffix(String faultActionSuffix) {
280275
Assert.hasText(faultActionSuffix, "'faultActionSuffix' must not be empty");

0 commit comments

Comments
 (0)