Skip to content

Commit

Permalink
spring-projectsGH-2818: DSL support for -ws module
Browse files Browse the repository at this point in the history
  • Loading branch information
garyrussell committed Feb 20, 2020
1 parent 8fb2018 commit 5789d74
Show file tree
Hide file tree
Showing 11 changed files with 993 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -165,6 +165,12 @@ public void setFaultMessageResolver(FaultMessageResolver faultMessageResolver) {
this.webServiceTemplate.setFaultMessageResolver(faultMessageResolver);
}

/**
* Specify the {@link WebServiceMessageSender} to use.
* @param messageSender the sender.
* @deprecated in favor of {@link #setMessageSenders(WebServiceMessageSender...)}
*/
@Deprecated
public void setMessageSender(WebServiceMessageSender messageSender) {
Assert.state(!this.webServiceTemplateExplicitlySet,
() -> "'messageSender' must be specified on the provided: " + this.webServiceTemplate);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -30,13 +30,14 @@
/**
* @author Mark Fisher
* @author Oleg Zhurakousky
* @author Gary Russell
* @since 1.0.2
*/
public class MarshallingWebServiceInboundGateway extends AbstractWebServiceInboundGateway {

private volatile Marshaller marshaller;
private Marshaller marshaller;

private volatile Unmarshaller unmarshaller;
private Unmarshaller unmarshaller;

/**
* Creates a new <code>MarshallingWebServiceInboundGateway</code>.
Expand All @@ -58,7 +59,7 @@ public MarshallingWebServiceInboundGateway() {
* @see #MarshallingWebServiceInboundGateway(Marshaller, Unmarshaller)
*/
public MarshallingWebServiceInboundGateway(Marshaller marshaller) {
Assert.notNull(marshaller, "'marshaller' must no be null");
Assert.notNull(marshaller, "'marshaller' must not be null");
Assert.isInstanceOf(Unmarshaller.class, marshaller, "When using this constructor the provided " +
"Marshaller must also implement Unmarshaller");
this.marshaller = marshaller;
Expand All @@ -72,19 +73,19 @@ public MarshallingWebServiceInboundGateway(Marshaller marshaller) {
* @param unmarshaller The unmarshaller.
*/
public MarshallingWebServiceInboundGateway(Marshaller marshaller, Unmarshaller unmarshaller) {
Assert.notNull(marshaller, "'marshaller' must no be null");
Assert.notNull(unmarshaller, "'unmarshaller' must no be null");
Assert.notNull(marshaller, "'marshaller' must not be null");
Assert.notNull(unmarshaller, "'unmarshaller' must not be null");
this.marshaller = marshaller;
this.unmarshaller = unmarshaller;
}

public void setMarshaller(Marshaller marshaller) {
Assert.notNull(marshaller, "'marshaller' must no be null");
Assert.notNull(marshaller, "'marshaller' must not be null");
this.marshaller = marshaller;
}

public void setUnmarshaller(Unmarshaller unmarshaller) {
Assert.notNull(unmarshaller, "'unmarshaller' must no be null");
Assert.notNull(unmarshaller, "'unmarshaller' must not be null");
this.unmarshaller = unmarshaller;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* Copyright 2020 the original author or authors.
*
* Licensed 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
*
* https://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.springframework.integration.ws.dsl;

import org.springframework.integration.dsl.MessagingGatewaySpec;
import org.springframework.integration.ws.AbstractWebServiceInboundGateway;
import org.springframework.integration.ws.SoapHeaderMapper;

/**
* Base {@link MessagingGatewaySpec} for web services.
*
* @param <S> the target {@link BaseWsInboundGatewaySpec} implementation type.
* @param <E> the target {@link AbstractWebServiceInboundGateway} implementation type.
*
* @author Gary Russell
* @since 5.3
*
*/
public class BaseWsInboundGatewaySpec<
S extends BaseWsInboundGatewaySpec<S, E>, E extends AbstractWebServiceInboundGateway>
extends MessagingGatewaySpec<S, E> {

/**
* Construct an instance for the gateway.
* @param gateway the gateway.
*/
protected BaseWsInboundGatewaySpec(E gateway) {
super(gateway);
}

/**
* Configure the header mapper.
* @param headerMapper the mapper.
* @return the spec.
*/
public S headerMapper(SoapHeaderMapper headerMapper) {
this.target.setHeaderMapper(headerMapper);
return _this();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
/*
* Copyright 2020 the original author or authors.
*
* Licensed 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
*
* https://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.springframework.integration.ws.dsl;

import java.util.Map;

import org.springframework.expression.Expression;
import org.springframework.integration.dsl.MessageHandlerSpec;
import org.springframework.integration.ws.AbstractWebServiceOutboundGateway;
import org.springframework.integration.ws.SoapHeaderMapper;
import org.springframework.ws.WebServiceMessageFactory;
import org.springframework.ws.client.core.FaultMessageResolver;
import org.springframework.ws.client.core.WebServiceMessageCallback;
import org.springframework.ws.client.core.WebServiceTemplate;
import org.springframework.ws.client.support.interceptor.ClientInterceptor;
import org.springframework.ws.transport.WebServiceMessageSender;

/**
* The base {@link MessageHandlerSpec} for {@link AbstractWebServiceOutboundGateway}s.
*
* @param <S> the target {@link BaseWsOutboundGatewaySpec} implementation type.
* @param <E> the target {@link AbstractWebServiceOutboundGateway} implementation type.
*
* @author Gary Russell
* @since 5.3
*
*/
public class BaseWsOutboundGatewaySpec<
S extends BaseWsOutboundGatewaySpec<S, E>, E extends AbstractWebServiceOutboundGateway>
extends MessageHandlerSpec<S, E> {

/**
* Configure the header mapper.
* @param headerMapper the mapper.
* @return the spec.
*/
public S headerMapper(SoapHeaderMapper headerMapper) {
this.target.setHeaderMapper(headerMapper);
return _this();
}

/**
* Set the Map of URI variable expressions to evaluate against the outbound message
* when replacing the variable placeholders in a URI template.
* @param uriVariableExpressions The URI variable expressions.
* @return the spec.
*/
public S uriVariableExpressions(Map<String, Expression> uriVariableExpressions) {
this.target.setUriVariableExpressions(uriVariableExpressions);
return _this();
}

/**
* Specify whether the URI should be encoded after any <code>uriVariables</code>
* are expanded and before sending the request. The default value is <code>true</code>.
* @param encodeUri true if the URI should be encoded.
* @return the spec.
* @see org.springframework.web.util.UriComponentsBuilder
*/
public S encodeUri(boolean encodeUri) {
this.target.setEncodeUri(encodeUri);
return _this();
}

/**
* Specify whether empty String response payloads should be ignored.
* The default is <code>true</code>. Set this to <code>false</code> if
* you want to send empty String responses in reply Messages.
* @param ignoreEmptyResponses true if empty responses should be ignored.
* @return the spec.
*/
public S ignoreEmptyResponses(boolean ignoreEmptyResponses) {
this.target.setIgnoreEmptyResponses(ignoreEmptyResponses);
return _this();
}

/**
* Specify the {@link WebServiceTemplate} to use.
* @param webServiceTemplate the template.
* @return the spec.
*/
public S webServiceTemplate(WebServiceTemplate webServiceTemplate) {
this.target.setWebServiceTemplate(webServiceTemplate);
return _this();
}

/**
* Specify the {@link WebServiceMessageFactory} to use.
* @param messageFactory the message factory.
* @return the spec.
*/
public S messageFactory(WebServiceMessageFactory messageFactory) {
this.target.setMessageFactory(messageFactory);
return _this();
}

/**
* Specify the {@link WebServiceMessageCallback} to use.
* @param requestCallback the call back.
* @return the spec.
*/
public S requestCallback(WebServiceMessageCallback requestCallback) {
this.target.setRequestCallback(requestCallback);
return _this();
}

/**
* Specify the {@link FaultMessageResolver} to use.
* @param faultMessageResolver the resolver.
* @return the spec.
*/
public S faultMessageResolver(FaultMessageResolver faultMessageResolver) {
this.target.setFaultMessageResolver(faultMessageResolver);
return _this();
}

/**
* Specify the {@link WebServiceMessageSender}s to use.
* @param messageSenders the senders.
* @return the spec.
*/
public S messageSenders(WebServiceMessageSender... messageSenders) {
this.target.setMessageSenders(messageSenders);
return _this();
}

/**
* Specify the {@link ClientInterceptor}s to use.
* @param interceptors the interceptors.
* @return the spec.
*/
public S interceptors(ClientInterceptor... interceptors) {
this.target.setInterceptors(interceptors);
return _this();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*
* Copyright 2020 the original author or authors.
*
* Licensed 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
*
* https://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.springframework.integration.ws.dsl;

import org.springframework.integration.ws.MarshallingWebServiceInboundGateway;
import org.springframework.oxm.Marshaller;
import org.springframework.oxm.Unmarshaller;

/**
* The spec for a {@link MarshallingWebServiceInboundGateway}.
*
* @author Gary Russell
* @since 5.3
*
*/
public class MarshallingWsInboundGatewaySpec extends BaseWsInboundGatewaySpec<MarshallingWsInboundGatewaySpec,
MarshallingWebServiceInboundGateway> {

protected MarshallingWsInboundGatewaySpec() {
super(new MarshallingWebServiceInboundGateway());
}

/**
* Construct an instance with the provided {@link Marshaller} (which must also implement
* {@link Unmarshaller}).
* @param marshaller the marshaller.
*/
protected MarshallingWsInboundGatewaySpec(Marshaller marshaller) {
super(new MarshallingWebServiceInboundGateway(marshaller));
}

/**
* Construct an instance with the provided arguments.
* @param marshaller the marshaller.
* @param unmarshaller the unmarshaller.
*/
protected MarshallingWsInboundGatewaySpec(Marshaller marshaller, Unmarshaller unmarshaller) {
super(new MarshallingWebServiceInboundGateway(marshaller, unmarshaller));
}

/**
* Specify a marshaller to use.
* @param marshaller the marshaller.
* @return the spec.
*/
public MarshallingWsInboundGatewaySpec marshaller(Marshaller marshaller) {
this.target.setMarshaller(marshaller);
return this;
}

/**
* Specify an unmarshaller to use.
* @param unmarshaller the unmarshaller.
* @return the spec.
*/
public MarshallingWsInboundGatewaySpec unmarshaller(Unmarshaller unmarshaller) {
this.target.setUnmarshaller(unmarshaller);
return this;
}

}
Loading

0 comments on commit 5789d74

Please sign in to comment.