本文整理汇总了Java中org.springframework.ws.client.core.WebServiceTemplate类的典型用法代码示例。如果您正苦于以下问题:Java WebServiceTemplate类的具体用法?Java WebServiceTemplate怎么用?Java WebServiceTemplate使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
WebServiceTemplate类属于org.springframework.ws.client.core包,在下文中一共展示了WebServiceTemplate类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testInvalidResponse
import org.springframework.ws.client.core.WebServiceTemplate; //导入依赖的package包/类
@Test
@SuppressWarnings("unused")
public void testInvalidResponse() throws IOException
{
WebServiceTemplate webServiceTemplate = new WebServiceTemplate();
webServiceTemplate.setCheckConnectionForFault(false);
MockWebServiceMessageSender messageSender = new MockWebServiceMessageSender();
DefaultResponseGenerator responseGenerator = new DefaultResponseGenerator();
responseGenerator.setNeverCreateEnvelope(true);
SimpleResourceLookup resourceLookup = new SimpleResourceLookup(new ClassPathResource("mock-responses/test/default-response-invalid.xml"));
resourceLookup.setTemplateProcessor(new TemplateProcessor() {
public Resource processTemplate(Resource resource, WebServiceMessage message) throws IOException {
return resource;
}
});
responseGenerator.setResourceLookup(resourceLookup);
messageSender.setRequestProcessors(Arrays.asList(responseGenerator));
webServiceTemplate.setMessageSender(messageSender);
Source source = getValidMessage().getPayloadSource();
StringResult result = new StringResult();
//TODO uncomment
// webServiceTemplate.sendSourceAndReceiveToResult(TEST_URI.toString(), source, result);
}
示例2: setUp
import org.springframework.ws.client.core.WebServiceTemplate; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
super.setUp();
// initialize beans for catching results
webServiceTemplate = applicationContext.getBean("webServiceTemplate", WebServiceTemplate.class);
newReply = getMandatoryBean(OutputChannelReceiver.class, "replyReceiver");
response = getMandatoryBean(OutputChannelReceiver.class, "responseReceiver");
// sample data
source = new StreamSource(new StringReader(xmlBody));
result = new StreamResult(new StringWriter());
// reset from previous test
response.clear();
newReply.clear();
requestInputAction = null;
}
示例3: GOClient
import org.springframework.ws.client.core.WebServiceTemplate; //导入依赖的package包/类
@Builder
private GOClient(
@NonNull final GOClientConfig config,
final GOClientLogger goClientLogger)
{
this.config = config;
this.goClientLogger = goClientLogger != null ? goClientLogger : SLF4JGOClientLogger.instance;
final HttpComponentsMessageSender messageSender = createMessageSender(config.getAuthUsername(), config.getAuthPassword());
final Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
marshaller.setPackagesToScan(de.metas.shipper.gateway.go.schema.ObjectFactory.class.getPackage().getName());
webServiceTemplate = new WebServiceTemplate();
webServiceTemplate.setDefaultUri(config.getUrl());
webServiceTemplate.setMessageSender(messageSender);
webServiceTemplate.setMarshaller(marshaller);
webServiceTemplate.setUnmarshaller(marshaller);
}
示例4: webServiceTemplate
import org.springframework.ws.client.core.WebServiceTemplate; //导入依赖的package包/类
/**
* Instancia un nuevo bean del Tipo {@link WebServiceTemplate}, utilizado
* para realizar llamadas del tipo SOAP.
*
* @return {@link WebServiceTemplate} para realizar llamadas
*/
@Bean
public WebServiceTemplate webServiceTemplate() {
if (!isEnabled()) {
return null;
}
final WebServiceTemplate wst = new WebServiceTemplate();
Jaxb2Marshaller marshaller = getJaxb2Marshaller();
wst.setMarshaller(marshaller);
wst.setUnmarshaller(marshaller);
wst.setFaultMessageResolver(new KarakuFaultMessageResolver(marshaller));
return wst;
}
示例5: testExpectAndReturn
import org.springframework.ws.client.core.WebServiceTemplate; //导入依赖的package包/类
@Test
public void testExpectAndReturn() throws IOException
{
MockWebServiceMessageSender sender = (MockWebServiceMessageSender)new WsMockControl().expectRequest("xml/control-message-test.xml").returnResponse("mock-responses/test/default-response.xml").createMock();
assertNotNull(sender);
assertEquals(2, sender.getRequestProcessors().size());
SimpleResourceLookup lookup1 = (SimpleResourceLookup)((XmlCompareRequestValidator)extractRequestProcessor(sender,0)).getControlResourceLookup();
assertEquals("control-message-test.xml", lookup1.getResultResource().getFilename());
assertTrue(((XmlCompareRequestValidator)extractRequestProcessor(sender, 0)).isIgnoreWhitespace());
SimpleResourceLookup lookup2 = (SimpleResourceLookup)((DefaultResponseGenerator)extractRequestProcessor(sender,1)).getResourceLookup();
assertEquals("default-response.xml", lookup2.getResultResource().getFilename());
WebServiceTemplate template = new WebServiceTemplate();
template.setMessageSender(sender);
StringResult responseResult = new StringResult();
template.sendSourceAndReceiveToResult(URI,createMessage("xml/valid-message.xml").getPayloadSource(), responseResult );
}
示例6: postProcessBeforeInitialization
import org.springframework.ws.client.core.WebServiceTemplate; //导入依赖的package包/类
@Override
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
if (bean instanceof WebServiceTemplate) {
final WebServiceTemplate webServiceTemplate = (WebServiceTemplate)bean;
final ClientInterceptor[] interceptors = webServiceTemplate.getInterceptors();
final ClientInterceptor[] newInterceptors;
if (interceptors != null) {
newInterceptors = Arrays.copyOf(interceptors, interceptors.length+1);
} else {
newInterceptors = new ClientInterceptor[1];
}
newInterceptors[newInterceptors.length-1] = interceptor;
webServiceTemplate.setInterceptors(newInterceptors);
}
return bean;
}
示例7: main
import org.springframework.ws.client.core.WebServiceTemplate; //导入依赖的package包/类
public static void main(String args[]){
ApplicationContext context = new FileSystemXmlApplicationContext(".\\src\\main\\webapp\\WEB-INF\\applicationContext.xml");
//Calculation calculation = (Calculation)context.getBean("calculationBeanHessian");
InvoiceProductRequest request = new InvoiceProductRequest();
request.setInvoiceId(123);
WebServiceTemplate wsTemplate = (WebServiceTemplate) context.getBean("webServiceTemplate");
InvoiceProductResponse response = (InvoiceProductResponse) wsTemplate.marshalSendAndReceive(request);
InvoicedProducts product = response.getInvoicedProduct();
System.out.println(product.getId());
}
示例8: testListServices
import org.springframework.ws.client.core.WebServiceTemplate; //导入依赖的package包/类
@Test
public void testListServices() {
ListMembers request = new ListMembers();
ListMembersResponse result = (ListMembersResponse)new WebServiceTemplate(marshaller).marshalSendAndReceive(
"http://localhost:" + port + "/ws", request);
assertNotNull(result);
assertEquals("MemberList size", 3, result.getMemberList().getMember().size());
}
示例9: getOptionTypeMappings
import org.springframework.ws.client.core.WebServiceTemplate; //导入依赖的package包/类
@Override
protected Map<String, Class<?>> getOptionTypeMappings() {
Map<String, Class<?>> mappings = super.getOptionTypeMappings();
mappings.put("messageSender", WebServiceMessageSender.class);
mappings.put("endpointResolver", EndpointUriResolver.class);
mappings.put("messageFactory", SoapMessageFactory.class);
mappings.put("webServiceTemplate", WebServiceTemplate.class);
return mappings;
}
示例10: prepareMessageSenders
import org.springframework.ws.client.core.WebServiceTemplate; //导入依赖的package包/类
private void prepareMessageSenders(SpringWebserviceConfiguration configuration) {
// Skip this whole thing if none of the relevant config options are set.
if (!(configuration.getTimeout() > -1) && configuration.getSslContextParameters() == null) {
return;
}
WebServiceTemplate webServiceTemplate = configuration.getWebServiceTemplate();
WebServiceMessageSender[] messageSenders = webServiceTemplate.getMessageSenders();
for (int i = 0; i < messageSenders.length; i++) {
WebServiceMessageSender messageSender = messageSenders[i];
if (messageSender instanceof HttpComponentsMessageSender) {
if (configuration.getSslContextParameters() != null) {
LOG.warn("Not applying SSLContextParameters based configuration to HttpComponentsMessageSender. "
+ "If you are using this MessageSender, which you are not by default, you will need "
+ "to configure SSL using the Commons HTTP 3.x Protocol registry.");
}
if (configuration.getTimeout() > -1) {
if (messageSender.getClass().equals(HttpComponentsMessageSender.class)) {
((HttpComponentsMessageSender) messageSender).setReadTimeout(configuration.getTimeout());
} else {
LOG.warn("Not applying timeout configuration to HttpComponentsMessageSender based implementation. "
+ "You are using what appears to be a custom MessageSender, which you are not doing by default. "
+ "You will need configure timeout on your own.");
}
}
} else if (messageSender.getClass().equals(HttpUrlConnectionMessageSender.class)) {
// Only if exact match denoting likely use of default configuration. We don't want to get
// sub-classes that might have been otherwise injected.
messageSenders[i] = new AbstractHttpWebServiceMessageSenderDecorator((HttpUrlConnectionMessageSender) messageSender, configuration, getEndpoint().getCamelContext());
} else {
// For example this will be the case during unit-testing with the net.javacrumbs.spring-ws-test API
LOG.warn("Ignoring the timeout and SSLContextParameters options for {}. You will need to configure "
+ "these options directly on your custom configured WebServiceMessageSender", messageSender);
}
}
}
示例11: webServiceTemplate
import org.springframework.ws.client.core.WebServiceTemplate; //导入依赖的package包/类
@Bean
public WebServiceTemplate webServiceTemplate() {
WebServiceTemplate wst = new WebServiceTemplate();
wst.setMarshaller(marshaller());
wst.setUnmarshaller(unmarshaller());
return wst;
}
示例12: createTemplate
import org.springframework.ws.client.core.WebServiceTemplate; //导入依赖的package包/类
private static WebServiceTemplate createTemplate(SaajSoapMessageFactory factory, Jaxb2Marshaller marshaller, EbmsAktoer remoteParty,
HttpComponentsMessageSender httpSender, ClientInterceptor[] interceptors) {
EbmsContextAwareWebServiceTemplate template = new EbmsContextAwareWebServiceTemplate(factory, remoteParty);
template.setMarshaller(marshaller);
template.setUnmarshaller(marshaller);
template.setFaultMessageResolver(new MessageSenderFaultMessageResolver(marshaller));
template.setMessageSender(httpSender);
template.setInterceptors(interceptors);
return template;
}
示例13: createAndConfigureWebServiceTemplate
import org.springframework.ws.client.core.WebServiceTemplate; //导入依赖的package包/类
private WebServiceTemplate createAndConfigureWebServiceTemplate(final SaajSoapMessage responseMessage,
QName webServiceIdentifier, HttpServletRequest httpServletRequest) {
WebServiceTemplate webServiceTemplate = new WebServiceTemplate(webServiceMessageFactory) {
@Override
protected Object handleError(WebServiceConnection connection, WebServiceMessage request) throws IOException {
HttpResponse httpResponse = ((HttpComponentsConnection) connection).getHttpResponse();
String statusAndCode = httpResponse.getStatusLine().getReasonPhrase() + " - "
+ httpResponse.getStatusLine().getStatusCode();
Charset charset = httpResponse.getEntity().getContentEncoding() != null
&& httpResponse.getEntity().getContentEncoding().getValue() != null ? Charset
.forName(httpResponse.getEntity().getContentEncoding().getValue()) : Charset.defaultCharset();
String response = httpResponse.getEntity() != null ? StreamUtils.copyToString(httpResponse.getEntity()
.getContent(), charset) : "N/A";
throw new WebServiceTransportException("[Status: " + statusAndCode + "] [Reponse " + response + "]");
}
};
webServiceTemplate.setMessageSender(createAndInitWebServiceMessageSender(webServiceIdentifier));
// In case the target endpoint returns a clean SoapFault, the normal response callback is abandoned and the
// FaulMessageResolver is invoked. In this case we want to return the fault unaltered to the client, so we set
// it here as the response.
webServiceTemplate.setFaultMessageResolver(new FaultMessageResolver() {
@Override
public void resolveFault(WebServiceMessage message) throws IOException {
responseMessage.setSaajMessage(((SaajSoapMessage) message).getSaajMessage());
}
});
List<ClientInterceptor> interceptors = new ArrayList<>();
interceptors.add(new HttpRequestHeaderTransfererInterceptor(HttpRequestHeaderTransfererInterceptor
.extractHeaders(httpServletRequest)));
if (config.getCustomClientInterceptors(webServiceIdentifier) != null) {
interceptors.addAll(config.getCustomClientInterceptors(webServiceIdentifier));
}
LOG.debug("Using interceptors:" + Arrays.toString(ClassUtils.toClass(interceptors.toArray())));
webServiceTemplate.setInterceptors(interceptors.toArray(new ClientInterceptor[0]));
return webServiceTemplate;
}
示例14: postProcessBeanFactory
import org.springframework.ws.client.core.WebServiceTemplate; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
Collection<WebServiceTemplate> templates = beanFactory.getBeansOfType(WebServiceTemplate.class).values();
if (templates.size()==0)
{
throw new BeanCreationException("No WebServiceTemplate found in the servlet context.");
}
Collection<AbstractMockWebServiceMessageSender> mockSenders = beanFactory.getBeansOfType(AbstractMockWebServiceMessageSender.class).values();
WebServiceMessageSender[] mockSenderArray = mockSenders.toArray(new WebServiceMessageSender[mockSenders.size()]);
for (WebServiceTemplate template: templates)
{
template.setMessageSenders(mockSenderArray);
}
}
示例15: doTemplateTest
import org.springframework.ws.client.core.WebServiceTemplate; //导入依赖的package包/类
private void doTemplateTest(MockWebServiceMessageSender sender) throws IOException, SAXException {
assertNotNull(sender);
assertEquals(2, sender.getRequestProcessors().size());
WsTestContextHolder.getTestContext().setAttribute("number", 2);
WebServiceTemplate template = new WebServiceTemplate();
template.setMessageSender(sender);
StringResult responseResult = new StringResult();
template.sendSourceAndReceiveToResult(URI,createMessage("xml/valid-message2.xml").getPayloadSource(), responseResult);
Diff diff = XMLUnit.compareXML(new InputStreamReader(new ClassPathResource("xml/resolved-different-response.xml").getInputStream()), responseResult.toString());
assertTrue(diff.toString(), diff.similar());
}