Spring integration 调用SimpleWebServiceInboundGateway.invoke方法时出错
这是我第一次尝试使用Spring集成调用SOAP web服务。下面是我的bean配置类Spring integration 调用SimpleWebServiceInboundGateway.invoke方法时出错,spring-integration,spring-ws,Spring Integration,Spring Ws,这是我第一次尝试使用Spring集成调用SOAP web服务。下面是我的bean配置类 @Configuration @EnableIntegration @PropertySource(value = { "application.properties" }) public class SoapGatewayConfiguration { /** * URL mappings used by WS endpoints */ public stati
@Configuration
@EnableIntegration
@PropertySource(value = { "application.properties" })
public class SoapGatewayConfiguration {
/**
* URL mappings used by WS endpoints
*/
public static final String[] WS_URL_MAPPINGS = { "/services/*", "*.wsdl", "*.xsd" };
public static final String GATEWAY_INBOUND_CHANNEL_NAME = "wsGatewayInboundChannel";
public static final String GATEWAY_OUTBOUND_CHANNEL_NAME = "wsGatewayOutboundChannel";
@Bean
public ServletWebServerFactory servletWebServerFactory() {
TomcatServletWebServerFactory f = new TomcatServletWebServerFactory();
f.setPort(9000);
return f;
}
/**
* Register the servlet mapper, note that it uses MessageDispatcher
*/
@Bean
public ServletRegistrationBean<MessageDispatcherServlet> messageDispatcherServlet(
ApplicationContext applicationContext) {
MessageDispatcherServlet servlet = new MessageDispatcherServlet();
servlet.setApplicationContext(applicationContext);
servlet.setTransformWsdlLocations(true);
servlet.setTransformSchemaLocations(true);
servlet.setPublishEvents(true);
ServletRegistrationBean<MessageDispatcherServlet> servletDef = new ServletRegistrationBean<>(servlet,
WS_URL_MAPPINGS);
servletDef.setLoadOnStartup(1);
return servletDef;
}
/**
* Create a new Direct channels to handle the messages
*/
@Bean
public MessageChannel wsGatewayInboundChannel() {
return MessageChannels.direct(GATEWAY_INBOUND_CHANNEL_NAME).get();
}
@Bean
public MessageChannel wsGatewayOutboundChannel() {
return MessageChannels.direct(GATEWAY_OUTBOUND_CHANNEL_NAME).get();
}
/**
* Startup the WebServiceInboundGateway Endpoint, this will handle the incoming
* SOAP requests and place them onto the request channel
*/
@Bean
@Gateway
public SimpleWebServiceInboundGateway webServiceInboundGateway(
@Value("${spring.ws.request.timeout:1000}") long requestTimeout,
@Value("${spring.ws.reply.timeout:1000}") long replyTimeout,
@Value("${spring.ws.should.track:true}") boolean shouldTrack) {
SimpleWebServiceInboundGateway wsg = new SimpleWebServiceInboundGateway();
wsg.setRequestChannel(wsGatewayInboundChannel());
wsg.setReplyChannel(wsGatewayOutboundChannel());
wsg.setExtractPayload(false); // Send the full RAW SOAPMessage and not just payload
wsg.setLoggingEnabled(true);
wsg.setShouldTrack(shouldTrack);
wsg.setReplyTimeout(replyTimeout); // Do not believe this prop supported currently
wsg.setRequestTimeout(requestTimeout); // Do not believe this prop is supported currently
wsg.setCountsEnabled(true);
return wsg;
}
/**
* You must enable debug logging on
* org.springframework.ws.server.endpoint.interceptor.PayloadLoggingInterceptor
* to see the logs from this interceptor
*/
@Bean
public EndpointInterceptor soapMessageLoggingInterceptor() {
SoapEnvelopeLoggingInterceptor li = new SoapEnvelopeLoggingInterceptor();
li.setLogRequest(true);
li.setLogResponse(true);
li.setLogFault(true);
return li;
}
/**
* Validate the incoming web service against the schema
*
* @throws IOException
*/
@Bean
public AbstractValidatingInterceptor payloadValidatingInterceptor(XsdSchema xsdSchema,
@Value("${spring.ws.soap.validate.request:true}") boolean soapValidateRequest,
@Value("${spring.ws.soap.validate.reply:true}") boolean soapValidateResponse,
@Value("${spring.ws.soap.validate.addErrorDetail:true}") boolean soapAddValidationErrorDetail
) throws IOException {
PayloadValidatingInterceptor interceptor = new PayloadValidatingInterceptor();
interceptor.setXsdSchema(xsdSchema);
interceptor.setValidateRequest(soapValidateRequest);
interceptor.setValidateResponse(soapValidateResponse);
return interceptor;
}
/**
* Map the allowable service Uri's.
*/
@Bean
public EndpointMapping uriEndpointMapping(PayloadValidatingInterceptor payloadValidatingInterceptor,
SimpleWebServiceInboundGateway webServiceInboundGateway,
SoapEnvelopeLoggingInterceptor loggingInterceptor) {
UriEndpointMapping mapping = new UriEndpointMapping();
mapping.setUsePath(true);
mapping.setDefaultEndpoint(webServiceInboundGateway(1000L, 1000L, true));
// mapping.setInterceptors({loggingInterceptor, payloadValidatingInterceptor});
return mapping;
}
@Bean
public Wsdl11Definition defaultWsdl11Definition() {
SimpleWsdl11Definition wsdl11Definition = new SimpleWsdl11Definition();
wsdl11Definition.setWsdl(new ClassPathResource("employees.wsdl.xml"));
return wsdl11Definition;
}
/**
* Expose the xsd at http://localhost:8080/services/mySchema.xsd
**/
@Bean
public XsdSchema mySchema() {
return new SimpleXsdSchema(new ClassPathResource("Employee.xsd"));
}
}
问题:
需要建议我们是否需要在SOAP请求头中设置replyChannel&errorChannel属性?如果是,请告诉我怎么做
编辑1:
下面是@ServiceActivator端点的配置
@ServiceActivator(inputChannel = "wsGatewayOutboundChannel")
public void makeCall(Message<Employee> pr) {
Employee response = pr.getPayload();
System.out.println(response);
}
@ServiceActivator(inputChannel=“wsGatewayOutboundChannel”)
公共无效呼叫(消息pr){
员工响应=pr.getPayload();
System.out.println(响应);
}
您需要确保订阅了wsGatewayInboundChannel。这就是你得到例外的原因
换句话说,WS-Inbound Gateway向通道发送消息,但在通道的另一端没有什么可以处理的。Hello Artem,我确实有一个@ServiceActivator端点配置为侦听wsGatewayOutboundChannel通道,该通道配置为SimpleWebServiceInboundGateway bean中的应答通道(如编辑1所示)。在错误消息中,它抱怨没有临时ReplyChannel的侦听器。我假设它会说wsGatewayOutboundChannel没有订户。请帮助我了解如何配置SimpleWebServiceInboundGateway以获得SOAP服务的响应。好吧,但我指的是
wsGatewayInboundChannel
-此网关发送消息的位置。基本上,您根本不需要回复通道,因为WS-gateway正在等待回复,但根本不发送消息。
Exception in thread "main" org.springframework.integration.MessageDispatchingException: Dispatcher has no subscribers, failedMessage=GenericMessage [payload=SaajSoapMessage findEmployeeByIdRequest, headers={ws_soapAction="", replyChannel=org.springframework.messaging.core.GenericMessagingTemplate$TemporaryReplyChannel@73163d48, history=webServiceInboundGateway, errorChannel=org.springframework.messaging.core.GenericMessagingTemplate$TemporaryReplyChannel@73163d48, id=d40a8603-903c-d5a5-b7a8-96177d1f4114, timestamp=1525316363103}]
@ServiceActivator(inputChannel = "wsGatewayOutboundChannel")
public void makeCall(Message<Employee> pr) {
Employee response = pr.getPayload();
System.out.println(response);
}