Skip to content

Commit ea8c454

Browse files
authored
GH-2818: DSL support for -ws module
Resolves #2818 * Rework to improve fluency * reduce the number of factory methods and use a different spec when an external WST is provided. * Docs and address comments
1 parent 8fb2018 commit ea8c454

15 files changed

+1145
-16
lines changed

spring-integration-ws/src/main/java/org/springframework/integration/ws/AbstractWebServiceOutboundGateway.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -165,10 +165,14 @@ public void setFaultMessageResolver(FaultMessageResolver faultMessageResolver) {
165165
this.webServiceTemplate.setFaultMessageResolver(faultMessageResolver);
166166
}
167167

168+
/**
169+
* Specify the {@link WebServiceMessageSender} to use.
170+
* @param messageSender the sender.
171+
* @deprecated in favor of {@link #setMessageSenders(WebServiceMessageSender...)}
172+
*/
173+
@Deprecated
168174
public void setMessageSender(WebServiceMessageSender messageSender) {
169-
Assert.state(!this.webServiceTemplateExplicitlySet,
170-
() -> "'messageSender' must be specified on the provided: " + this.webServiceTemplate);
171-
this.webServiceTemplate.setMessageSender(messageSender);
175+
setMessageSenders(messageSender);
172176
}
173177

174178
public void setMessageSenders(WebServiceMessageSender... messageSenders) {

spring-integration-ws/src/main/java/org/springframework/integration/ws/MarshallingWebServiceInboundGateway.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -30,13 +30,14 @@
3030
/**
3131
* @author Mark Fisher
3232
* @author Oleg Zhurakousky
33+
* @author Gary Russell
3334
* @since 1.0.2
3435
*/
3536
public class MarshallingWebServiceInboundGateway extends AbstractWebServiceInboundGateway {
3637

37-
private volatile Marshaller marshaller;
38+
private Marshaller marshaller;
3839

39-
private volatile Unmarshaller unmarshaller;
40+
private Unmarshaller unmarshaller;
4041

4142
/**
4243
* Creates a new <code>MarshallingWebServiceInboundGateway</code>.
@@ -58,7 +59,7 @@ public MarshallingWebServiceInboundGateway() {
5859
* @see #MarshallingWebServiceInboundGateway(Marshaller, Unmarshaller)
5960
*/
6061
public MarshallingWebServiceInboundGateway(Marshaller marshaller) {
61-
Assert.notNull(marshaller, "'marshaller' must no be null");
62+
Assert.notNull(marshaller, "'marshaller' must not be null");
6263
Assert.isInstanceOf(Unmarshaller.class, marshaller, "When using this constructor the provided " +
6364
"Marshaller must also implement Unmarshaller");
6465
this.marshaller = marshaller;
@@ -72,19 +73,19 @@ public MarshallingWebServiceInboundGateway(Marshaller marshaller) {
7273
* @param unmarshaller The unmarshaller.
7374
*/
7475
public MarshallingWebServiceInboundGateway(Marshaller marshaller, Unmarshaller unmarshaller) {
75-
Assert.notNull(marshaller, "'marshaller' must no be null");
76-
Assert.notNull(unmarshaller, "'unmarshaller' must no be null");
76+
Assert.notNull(marshaller, "'marshaller' must not be null");
77+
Assert.notNull(unmarshaller, "'unmarshaller' must not be null");
7778
this.marshaller = marshaller;
7879
this.unmarshaller = unmarshaller;
7980
}
8081

8182
public void setMarshaller(Marshaller marshaller) {
82-
Assert.notNull(marshaller, "'marshaller' must no be null");
83+
Assert.notNull(marshaller, "'marshaller' must not be null");
8384
this.marshaller = marshaller;
8485
}
8586

8687
public void setUnmarshaller(Unmarshaller unmarshaller) {
87-
Assert.notNull(unmarshaller, "'unmarshaller' must no be null");
88+
Assert.notNull(unmarshaller, "'unmarshaller' must not be null");
8889
this.unmarshaller = unmarshaller;
8990
}
9091

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*
2+
* Copyright 2020 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.integration.ws.dsl;
18+
19+
import org.springframework.integration.dsl.MessagingGatewaySpec;
20+
import org.springframework.integration.ws.AbstractWebServiceInboundGateway;
21+
import org.springframework.integration.ws.SoapHeaderMapper;
22+
23+
/**
24+
* Base {@link MessagingGatewaySpec} for web services.
25+
*
26+
* @param <S> the target {@link BaseWsInboundGatewaySpec} implementation type.
27+
* @param <E> the target {@link AbstractWebServiceInboundGateway} implementation type.
28+
*
29+
* @author Gary Russell
30+
* @since 5.3
31+
*
32+
*/
33+
public abstract class BaseWsInboundGatewaySpec<
34+
S extends BaseWsInboundGatewaySpec<S, E>, E extends AbstractWebServiceInboundGateway>
35+
extends MessagingGatewaySpec<S, E> {
36+
37+
/**
38+
* Construct an instance.
39+
*/
40+
protected BaseWsInboundGatewaySpec() {
41+
super(null);
42+
}
43+
44+
/**
45+
* Configure the header mapper.
46+
* @param headerMapper the mapper.
47+
* @return the spec.
48+
*/
49+
public S headerMapper(SoapHeaderMapper headerMapper) {
50+
this.target.setHeaderMapper(headerMapper);
51+
return _this();
52+
}
53+
54+
@Override
55+
protected E doGet() {
56+
return assemble(create());
57+
}
58+
59+
protected abstract E create();
60+
61+
protected E assemble(E gateway) {
62+
return gateway;
63+
}
64+
65+
}
Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
/*
2+
* Copyright 2020 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.integration.ws.dsl;
18+
19+
import java.util.HashMap;
20+
import java.util.Map;
21+
22+
import org.springframework.expression.Expression;
23+
import org.springframework.integration.dsl.MessageHandlerSpec;
24+
import org.springframework.integration.util.JavaUtils;
25+
import org.springframework.integration.ws.AbstractWebServiceOutboundGateway;
26+
import org.springframework.integration.ws.SoapHeaderMapper;
27+
import org.springframework.ws.WebServiceMessageFactory;
28+
import org.springframework.ws.client.core.FaultMessageResolver;
29+
import org.springframework.ws.client.core.WebServiceMessageCallback;
30+
import org.springframework.ws.client.core.WebServiceTemplate;
31+
import org.springframework.ws.client.support.destination.DestinationProvider;
32+
import org.springframework.ws.client.support.interceptor.ClientInterceptor;
33+
import org.springframework.ws.transport.WebServiceMessageSender;
34+
35+
/**
36+
* The base {@link MessageHandlerSpec} for {@link AbstractWebServiceOutboundGateway}s.
37+
*
38+
* @param <S> the target {@link BaseWsOutboundGatewaySpec} implementation type.
39+
* @param <E> the target {@link AbstractWebServiceOutboundGateway} implementation type.
40+
*
41+
* @author Gary Russell
42+
* @since 5.3
43+
*
44+
*/
45+
public abstract class BaseWsOutboundGatewaySpec<
46+
S extends BaseWsOutboundGatewaySpec<S, E>, E extends AbstractWebServiceOutboundGateway>
47+
extends MessageHandlerSpec<S, E> {
48+
49+
private final Map<String, Expression> uriVariableExpressions = new HashMap<>();
50+
51+
protected WebServiceTemplate template; // NOSONAR
52+
53+
protected DestinationProvider destinationProvider; // NOSONAR
54+
55+
protected String uri; // NOSONAR
56+
57+
protected WebServiceMessageFactory webServiceMessageFactory; // NOSONAR
58+
59+
private SoapHeaderMapper headerMapper;
60+
61+
private boolean encodeUri = true;
62+
63+
private boolean ignoreEmptyResponses = true;
64+
65+
private WebServiceMessageCallback requestCallback;
66+
67+
protected FaultMessageResolver faultMessageResolver; // NOSONAR
68+
69+
protected WebServiceMessageSender[] messageSenders; // NOSONAR
70+
71+
protected ClientInterceptor[] gatewayInterceptors; // NOSONAR
72+
73+
protected boolean extractPayload = true; // NOSONAR
74+
75+
/**
76+
* Configure with a destination provider;
77+
* @param destinationProvider the destination provider.
78+
* @return the spec.
79+
*/
80+
public S destinationProvider(DestinationProvider destinationProvider) {
81+
this.destinationProvider = destinationProvider;
82+
return _this();
83+
}
84+
85+
/**
86+
* Configure with a URI.
87+
* @param uri the uri.
88+
* @return the spec.
89+
*/
90+
public S uri(String uri) {
91+
this.uri = uri;
92+
return _this();
93+
}
94+
95+
/**
96+
* Configure the header mapper.
97+
* @param headerMapper the mapper.
98+
* @return the spec.
99+
*/
100+
public S headerMapper(SoapHeaderMapper headerMapper) {
101+
this.headerMapper = headerMapper;
102+
return _this();
103+
}
104+
105+
/**
106+
* Set the Map of URI variable expressions to evaluate against the outbound message
107+
* when replacing the variable placeholders in a URI template.
108+
* @param uriVariableExpressions The URI variable expressions.
109+
* @return the spec.
110+
*/
111+
public S uriVariableExpressions(Map<String, Expression> uriVariableExpressions) {
112+
this.uriVariableExpressions.putAll(uriVariableExpressions);
113+
return _this();
114+
}
115+
116+
/**
117+
* Specify whether the URI should be encoded after any <code>uriVariables</code>
118+
* are expanded and before sending the request. The default value is <code>true</code>.
119+
* @param encodeUri true if the URI should be encoded.
120+
* @return the spec.
121+
* @see org.springframework.web.util.UriComponentsBuilder
122+
*/
123+
public S encodeUri(boolean encodeUri) {
124+
this.encodeUri = encodeUri;
125+
return _this();
126+
}
127+
128+
/**
129+
* Specify whether empty String response payloads should be ignored.
130+
* The default is <code>true</code>. Set this to <code>false</code> if
131+
* you want to send empty String responses in reply Messages.
132+
* @param ignoreEmptyResponses true if empty responses should be ignored.
133+
* @return the spec.
134+
*/
135+
public S ignoreEmptyResponses(boolean ignoreEmptyResponses) {
136+
this.ignoreEmptyResponses = ignoreEmptyResponses;
137+
return _this();
138+
}
139+
140+
/**
141+
* Specify the {@link WebServiceMessageCallback} to use.
142+
* @param requestCallback the call back.
143+
* @return the spec.
144+
*/
145+
public S requestCallback(WebServiceMessageCallback requestCallback) {
146+
this.requestCallback = requestCallback;
147+
return _this();
148+
}
149+
150+
@Override
151+
protected E doGet() {
152+
return assemble(create());
153+
}
154+
155+
protected abstract E create();
156+
157+
protected E assemble(E gateway) {
158+
gateway.setUriVariableExpressions(this.uriVariableExpressions);
159+
JavaUtils.INSTANCE
160+
.acceptIfNotNull(this.headerMapper, gateway::setHeaderMapper);
161+
gateway.setEncodeUri(this.encodeUri);
162+
gateway.setIgnoreEmptyResponses(this.ignoreEmptyResponses);
163+
gateway.setRequestCallback(this.requestCallback);
164+
return gateway;
165+
}
166+
167+
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
* Copyright 2020 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.integration.ws.dsl;
18+
19+
import org.springframework.integration.ws.MarshallingWebServiceInboundGateway;
20+
import org.springframework.oxm.Marshaller;
21+
import org.springframework.oxm.Unmarshaller;
22+
23+
/**
24+
* The spec for a {@link MarshallingWebServiceInboundGateway}.
25+
*
26+
* @author Gary Russell
27+
* @since 5.3
28+
*
29+
*/
30+
public class MarshallingWsInboundGatewaySpec extends BaseWsInboundGatewaySpec<MarshallingWsInboundGatewaySpec,
31+
MarshallingWebServiceInboundGateway> {
32+
33+
protected Marshaller gatewayMarshaller; // NOSONAR
34+
35+
protected Unmarshaller gatewayUnmarshaller; // NOSONAR
36+
37+
/**
38+
* Specify a marshaller to use.
39+
* @param marshaller the marshaller.
40+
* @return the spec.
41+
*/
42+
public MarshallingWsInboundGatewaySpec marshaller(Marshaller marshaller) {
43+
this.gatewayMarshaller = marshaller;
44+
return this;
45+
}
46+
47+
/**
48+
* Specify an unmarshaller to use. Required if the {@link #gatewayMarshaller} is not also
49+
* an {@link Unmarshaller}.
50+
* @param unmarshaller the unmarshaller.
51+
* @return the spec.
52+
*/
53+
public MarshallingWsInboundGatewaySpec unmarshaller(Unmarshaller unmarshaller) {
54+
this.gatewayUnmarshaller = unmarshaller;
55+
return this;
56+
}
57+
58+
@Override
59+
protected MarshallingWebServiceInboundGateway create() {
60+
if (this.gatewayUnmarshaller != null) {
61+
return new MarshallingWebServiceInboundGateway(this.gatewayMarshaller, this.gatewayUnmarshaller);
62+
}
63+
else {
64+
return new MarshallingWebServiceInboundGateway(this.gatewayMarshaller);
65+
}
66+
}
67+
68+
}

0 commit comments

Comments
 (0)