【问题标题】:soap service with spring-boot & mtom from an existing wsdl来自现有 wsdl 的带有 spring-boot 和 mtom 的肥皂服务
【发布时间】:2020-02-18 15:23:23
【问题描述】:

按照这个示例 (https://codenotfound.com/spring-ws-example.html),我正在尝试从现有的 WSDL 开始使用 spring-boot 2.2.0.RELEASE 创建一个 SOAP 服务。

关键是在输出类中有一个必须通过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
}

在网上我找到了一个示例 (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>

我该如何解决这个问题?

【问题讨论】:

    标签: java spring-boot wsdl spring-ws mtom


    【解决方案1】:

    已解决:当 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;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-12
      • 1970-01-01
      • 1970-01-01
      • 2020-08-14
      • 1970-01-01
      • 2012-01-02
      相关资源
      最近更新 更多