[英]soap service with spring-boot & mtom from an existing wsdl
Following this example ( https://codenotfound.com/spring-ws-example.html ) I'm trying to create a SOAP
service with spring-boot 2.2.0.RELEASE
starting from an existing WSDL
.
关键是在 output class 中有一个字段必须通过MTOM
发送,我无法让它正常工作。 通过我的代码的以下摘录,将返回一个响应,其中包含字段<data>
中的base64
。
//Configuration bean class
@EnableWs
@Configuration
public class WebServiceConfig extends WsConfigurerAdapter {
@Bean
public ServletRegistrationBean<Servlet> messageDispatcherServlet(ApplicationContext applicationContext) {
MessageDispatcherServlet servlet = new MessageDispatcherServlet();
servlet.setApplicationContext(applicationContext);
return new ServletRegistrationBean<>(servlet, "/ServiceWS/*");
}
@Bean(name = "DeliveryService")
public Wsdl11Definition defaultWsdl11Definition() {
return new SimpleWsdl11Definition(new ClassPathResource("/wsdl/DeliveryService.wsdl"));
}
// other stuff
}
// Endpoint class
@Endpoint
public class DeliverDocumentEndpoint {
@PayloadRoot(namespace = "http://pb.com/service/ws/delivery", localPart = "DeliverDocument")
@ResponsePayload
public DeliverDocumentResponse deliverDocument(@RequestPayload DeliverDocument request) throws DeliveryFault {
// DO STUFF WITH MTOM
}
}
// Field int output bean, via code generation
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "ComposedDocument", propOrder = {"data"})
public class ComposedDocument {
@XmlElement(required = true)
@XmlMimeType("application/octet-stream")
protected DataHandler data;
// getter and setter
}
查看 web 我找到了一个示例( https://github.com/spring-projects/spring-ws-samples/tree/master/mtom ),我在我的解决方案中添加了另一个@Configuration
bean,
@EnableWs
@Configuration
public class MtomServerConfiguration extends WsConfigurationSupport {
@Bean
@Override
public DefaultMethodEndpointAdapter defaultMethodEndpointAdapter() {
List<MethodArgumentResolver> argumentResolvers = new ArrayList<>();
argumentResolvers.add(methodProcessor());
List<MethodReturnValueHandler> returnValueHandlers = new ArrayList<>();
returnValueHandlers.add(methodProcessor());
DefaultMethodEndpointAdapter adapter = new DefaultMethodEndpointAdapter();
adapter.setMethodArgumentResolvers(argumentResolvers);
adapter.setMethodReturnValueHandlers(returnValueHandlers);
return adapter;
}
@Bean
public MarshallingPayloadMethodProcessor methodProcessor() {
return new MarshallingPayloadMethodProcessor(marshaller());
}
@Bean
public Jaxb2Marshaller marshaller() {
Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
marshaller.setContextPath("com.pb.service.ws.model");
marshaller.setMtomEnabled(true);
return marshaller;
}
}
但是通过这种方法,我得到了这个错误:
<SOAP-ENV:Fault>
<faultcode>SOAP-ENV:Server</faultcode>
<faultstring xml:lang="en">
No adapter for endpoint
[public com.pb.service.ws.delivery.DeliverDocumentResponse it.m2sc.ws.endpoint.DeliverDocumentEndpoint.deliverDocument(com.pb.service.ws.delivery.DeliverDocument)
throws com.pb.service.ws.delivery.DeliveryFault]:
Is your endpoint annotated with @Endpoint, or does it implement a supported interface like MessageHandler or PayloadEndpoint?
</faultstring>
</SOAP-ENV:Fault>
我该如何解决这个问题?
已解决:当 generate-sources 插件运行时,生成的源被分成 3 个不同的包。 我不得不像这样将它们全部列出给 Jaxb2Marshaller:
@Bean
public Jaxb2Marshaller marshaller() {
Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
marshaller.setPackagesToScan("com.pb.service.ws.common", "com.pb.service.ws.delivery", "com.pb.service.ws.model");
marshaller.setMtomEnabled(true);
return marshaller;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.