@Test public void testSendAndReceive() { WebServiceTemplate ws = new WebServiceTemplate(marshaller); GetCountryRequest request = new GetCountryRequest(); request.setName("Spain"); assertThat(ws.marshalSendAndReceive("http://localhost:" + port + "/ws", request)).isNotNull(); } }
@Override protected Object doHandle(String uri, Message<?> requestMessage, WebServiceMessageCallback requestCallback) { return getWebServiceTemplate() .marshalSendAndReceive(uri, requestMessage.getPayload(), new PassThroughRequestMessageCallback(requestCallback, requestMessage)); }
public static void main(String[] args) { WebServiceTemplate webServiceTemplate = new WebServiceTemplate(); Jaxb2Marshaller jaxb2Marshaller = new Jaxb2Marshaller(); jaxb2Marshaller.setClassesToBeBound(UserIdRequest.class, UserResponse.class, User.class); webServiceTemplate.setMarshaller(jaxb2Marshaller); webServiceTemplate.setUnmarshaller(jaxb2Marshaller); //构造 SOAP 请求 UserIdRequest userIdRequest = new UserIdRequest(); userIdRequest.setUserId(1L); userIdRequest.setTimestamp(Instant.now().toEpochMilli()); UserResponse userResponse = (UserResponse) webServiceTemplate.marshalSendAndReceive("http://localhost:8080/web-services/user", userIdRequest); System.out.println(userResponse); }
public void setMessageSender(WebServiceMessageSender messageSender) { Assert.state(!this.webServiceTemplateExplicitlySet, () -> "'messageSender' must be specified on the provided: " + this.webServiceTemplate); this.webServiceTemplate.setMessageSender(messageSender); }
/** * Configure the provided {@link WebServiceTemplate} instance using this builder. * @param <T> the type of web service template * @param webServiceTemplate the {@link WebServiceTemplate} to configure * @return the web service template instance * @see #build() * @see #build(Class) */ public <T extends WebServiceTemplate> T configure(T webServiceTemplate) { Assert.notNull(webServiceTemplate, "WebServiceTemplate must not be null"); configureMessageSenders(webServiceTemplate); PropertyMapper map = PropertyMapper.get().alwaysApplyingWhenNonNull(); applyCustomizers(webServiceTemplate, this.internalCustomizers); map.from(this.marshaller).to(webServiceTemplate::setMarshaller); map.from(this.unmarshaller).to(webServiceTemplate::setUnmarshaller); map.from(this.destinationProvider).to(webServiceTemplate::setDestinationProvider); map.from(this.transformerFactoryClass) .to(webServiceTemplate::setTransformerFactoryClass); map.from(this.messageFactory).to(webServiceTemplate::setMessageFactory); if (!CollectionUtils.isEmpty(this.interceptors)) { Set<ClientInterceptor> merged = new LinkedHashSet<>(this.interceptors); if (webServiceTemplate.getInterceptors() != null) { merged.addAll(Arrays.asList(webServiceTemplate.getInterceptors())); } webServiceTemplate.setInterceptors(merged.toArray(new ClientInterceptor[0])); } applyCustomizers(webServiceTemplate, this.customizers); return webServiceTemplate; }
public AbstractWebServiceOutboundGateway(DestinationProvider destinationProvider, WebServiceMessageFactory messageFactory) { Assert.notNull(destinationProvider, "DestinationProvider must not be null"); this.webServiceTemplate = new WebServiceTemplate(messageFactory); this.destinationProvider = destinationProvider; // we always call WebServiceTemplate methods with an explicit URI argument, // but in case the WebServiceTemplate is accessed directly we'll set this: this.webServiceTemplate.setDestinationProvider(destinationProvider); this.uri = null; }
@Bean public WebServiceTemplate webServiceTemplate() { WebServiceTemplate webServiceTemplate = new WebServiceTemplate(); webServiceTemplate.setMarshaller(jaxb2Marshaller()); webServiceTemplate.setUnmarshaller(jaxb2Marshaller()); webServiceTemplate.setDefaultUri(defaultUri); return webServiceTemplate; } }
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)); // 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 = 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 (configuration.getMessageSender() != null) { webServiceTemplate.setMessageSender(configuration.getMessageSender()); } if (configuration.getMessageFactory() != null) { webServiceTemplate.setMessageFactory(configuration.getMessageFactory()); } } }
@Bean public WebServiceTemplate webServiceTemplate() { WebServiceTemplate template = new WebServiceTemplate(); template.setMessageSender(httpComponentsMessageSender()); return template; }
public AbstractWebServiceOutboundGateway(final String uri, WebServiceMessageFactory messageFactory) { Assert.hasText(uri, "URI must not be empty"); this.webServiceTemplate = new WebServiceTemplate(messageFactory); this.destinationProvider = null; this.uri = uri; }
/** Sets the default URI used by the gateway. */ public final void setDefaultUri(String uri) { webServiceTemplate.setDefaultUri(uri); }
/** * Sets the provided Marshaller and Unmarshaller on this gateway's WebServiceTemplate. * Neither may be null. * @param marshaller The marshaller. * @param unmarshallerArg The unmarshaller. */ private void configureMarshallers(Marshaller marshaller, @Nullable Unmarshaller unmarshallerArg) { Unmarshaller unmarshaller = unmarshallerArg; Assert.notNull(marshaller, "marshaller must not be null"); if (unmarshaller == null) { Assert.isInstanceOf(Unmarshaller.class, marshaller, "Marshaller [" + marshaller + "] does not implement the Unmarshaller interface. " + "Please set an Unmarshaller explicitly by using one of the constructors that accepts " + "both Marshaller and Unmarshaller arguments."); unmarshaller = (Unmarshaller) marshaller; } Assert.notNull(unmarshaller, "unmarshaller must not be null"); getWebServiceTemplate().setMarshaller(marshaller); getWebServiceTemplate().setUnmarshaller(unmarshaller); }
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.ws.client.core.WebServiceTemplate; class ClientConnection { @Autowired private WebServiceTemplate webServiceTemplate; public synchronized Object sendRequestAndReceive(Object xmlRequest, final String uri) { webServiceTemplate.setDefaultUri(uri); Object object = webServiceTemplate.marshalSendAndReceive(xmlRequest); return object; } }
public BookingServiceWithStrongCoupling() { this.bookingDao = new SimpleBookingDao(); WebServiceTemplate template = new WebServiceTemplate(); template.setDefaultUri(System.getProperty( "meal.preference.service.uri")); this.mealPreferenceWebServiceInvoker = template; }
/** * Creates a new {@code MarshallingMethodEndpointAdapter} with the given marshaller and unmarshaller. * * @param marshaller the marshaller to use * @param unmarshaller the unmarshaller to use * @since 2.0.3 */ public WebServiceTemplate(Marshaller marshaller, Unmarshaller unmarshaller) { Assert.notNull(marshaller, "marshaller must not be null"); Assert.notNull(unmarshaller, "unmarshaller must not be null"); this.setMarshaller(marshaller); this.setUnmarshaller(unmarshaller); initDefaultStrategies(); }
/** * Sets the {@code Marshaller} used by the gateway. Setting this property is only required if the marshalling * functionality of {@code WebServiceTemplate} is to be used. * * @see WebServiceTemplate#marshalSendAndReceive */ public final void setMarshaller(Marshaller marshaller) { webServiceTemplate.setMarshaller(marshaller); }
/** * Sets the {@code Unmarshaller} used by the gateway. Setting this property is only required if the marshalling * functionality of {@code WebServiceTemplate} is to be used. * * @see WebServiceTemplate#marshalSendAndReceive */ public final void setUnmarshaller(Unmarshaller unmarshaller) { webServiceTemplate.setUnmarshaller(unmarshaller); }
SaajSoapMessageFactory messageFactory = new SaajSoapMessageFactory(MessageFactory.newInstance()); messageFactory.afterPropertiesSet(); WebServiceTemplate webServiceTemplate = new WebServiceTemplate(messageFactory); Jaxb2Marshaller marshaller = new Jaxb2Marshaller(); marshaller.setContextPath("models"); marshaller.afterPropertiesSet(); webServiceTemplate.setMarshaller(marshaller); webServiceTemplate.afterPropertiesSet();
public void setInterceptors(ClientInterceptor... interceptors) { Assert.state(!this.webServiceTemplateExplicitlySet, () -> "'interceptors' must be specified on the provided: " + this.webServiceTemplate); this.webServiceTemplate.setInterceptors(interceptors); }
setDefaultUri("https://myServer/soapws/ws/"); Source requestSource = new ResourceSource(new ClassPathResource("MyRequest.xml")); StringResult result = new StringResult(); WebServiceTemplate template = getWebServiceTemplate(); HttpsUrlConnectionMessageSender sender = new HttpsUrlConnectionMessageSender(); sender.setTrustManagers(new TrustManager[] { new UnTrustworthyTrustManager() }); template.setMessageSender(sender); template.sendSourceAndReceiveToResult(requestSource, result); System.out.println(result);