繁体   English   中英

端点 Spring WS SOAP 没有适配器

[英]No adapter for endpoint Spring WS SOAP

我有一个非常奇怪的问题。 我正在尝试向我的 SOAP 应用程序发送请求,我得到了这个日志(logging-level=trace):

2022-06-18 12:08:33.341 DEBUG 11612 --- [nio-8080-exec-1] yloadRootAnnotationMethodEndpointMapping : Looking up endpoint for [{localhost/soap}GetAllUser]
2022-06-18 12:08:33.341 DEBUG 11612 --- [nio-8080-exec-1] o.s.w.soap.server.SoapMessageDispatcher  : Endpoint mapping [org.springframework.ws.server.endpoint.mapping.PayloadRootAnnotationMethodEndpointMapping@113c4ad6] maps request to endpoint [public localhost.soap.GetAllUserResponse com.driypeen.userServiceSOAP.endpoint.UserEndpoint.getAllUsers(localhost.soap.GetAllUserRequest)]
Testing endpoint adapter [org.springframework.ws.server.endpoint.adapter.DefaultMethodEndpointAdapter@1f6f0fe2]
2022-06-18 12:08:33.343 TRACE 11612 --- [nio-8080-exec-1] o.s.w.s.e.a.DefaultMethodEndpointAdapter : Testing if argument resolver [org.springframework.ws.server.endpoint.adapter.method.dom.DomPayloadMethodProcessor@352c3d70] supports [class localhost.soap.GetAllUserRequest]
2022-06-18 12:08:33.344 TRACE 11612 --- [nio-8080-exec-1] o.s.w.s.e.a.DefaultMethodEndpointAdapter : Testing if argument resolver [org.springframework.ws.server.endpoint.adapter.method.MessageContextMethodArgumentResolver@4c13ca07] supports [class localhost.soap.GetAllUserRequest]
2022-06-18 12:08:33.344 TRACE 11612 --- [nio-8080-exec-1] o.s.w.s.e.a.DefaultMethodEndpointAdapter : Testing if argument resolver [org.springframework.ws.server.endpoint.adapter.method.SourcePayloadMethodProcessor@7d17906] supports [class localhost.soap.GetAllUserRequest]
2022-06-18 12:08:33.344 TRACE 11612 --- [nio-8080-exec-1] o.s.w.s.e.a.DefaultMethodEndpointAdapter : Testing if argument resolver [org.springframework.ws.server.endpoint.adapter.method.XPathParamMethodArgumentResolver@97beeaf] supports [class localhost.soap.GetAllUserRequest]
2022-06-18 12:08:33.345 TRACE 11612 --- [nio-8080-exec-1] o.s.w.s.e.a.DefaultMethodEndpointAdapter : Testing if argument resolver [org.springframework.ws.soap.server.endpoint.adapter.method.SoapMethodArgumentResolver@5d68954d] supports [class localhost.soap.GetAllUserRequest]
2022-06-18 12:08:33.345 TRACE 11612 --- [nio-8080-exec-1] o.s.w.s.e.a.DefaultMethodEndpointAdapter : Testing if argument resolver [org.springframework.ws.soap.server.endpoint.adapter.method.SoapHeaderElementMethodArgumentResolver@f793f15] supports [class localhost.soap.GetAllUserRequest]
2022-06-18 12:08:33.345 TRACE 11612 --- [nio-8080-exec-1] o.s.w.s.e.a.DefaultMethodEndpointAdapter : Testing if argument resolver [org.springframework.ws.server.endpoint.adapter.method.jaxb.XmlRootElementPayloadMethodProcessor@3ec7eb5] supports [class localhost.soap.GetAllUserRequest]
2022-06-18 12:08:33.351 TRACE 11612 --- [nio-8080-exec-1] o.s.w.s.e.a.DefaultMethodEndpointAdapter : Testing if argument resolver [org.springframework.ws.server.endpoint.adapter.method.jaxb.JaxbElementPayloadMethodProcessor@5534e6f1] supports [class localhost.soap.GetAllUserRequest]
2022-06-18 12:08:33.352 TRACE 11612 --- [nio-8080-exec-1] o.s.w.s.e.a.DefaultMethodEndpointAdapter : Testing if argument resolver [org.springframework.ws.server.endpoint.adapter.method.dom.JDomPayloadMethodProcessor@4c6fc3e7] supports [class localhost.soap.GetAllUserRequest]
2022-06-18 12:08:33.352 TRACE 11612 --- [nio-8080-exec-1] o.s.w.s.e.a.DefaultMethodEndpointAdapter : Testing if argument resolver [org.springframework.ws.server.endpoint.adapter.method.StaxPayloadMethodArgumentResolver@aa8dce8] supports [class localhost.soap.GetAllUserRequest]
2022-06-18 12:08:33.353 DEBUG 11612 --- [nio-8080-exec-1] o.s.w.soap.server.SoapMessageDispatcher  : Testing endpoint adapter [org.springframework.ws.server.endpoint.adapter.PayloadEndpointAdapter@ab2009f]
2022-06-18 12:08:33.353 DEBUG 11612 --- [nio-8080-exec-1] s.e.SoapFaultAnnotationExceptionResolver : Resolving exception from endpoint [public localhost.soap.GetAllUserResponse com.driypeen.userServiceSOAP.endpoint.UserEndpoint.getAllUsers(localhost.soap.GetAllUserRequest)]: java.lang.IllegalStateException: No adapter for endpoint [public localhost.soap.GetAllUserResponse com.driypeen.userServiceSOAP.endpoint.UserEndpoint.getAllUsers(localhost.soap.GetAllUserRequest)]: Is your endpoint annotated with @Endpoint, or does it implement a supported interface like MessageHandler or PayloadEndpoint?
2022-06-18 12:08:33.354 DEBUG 11612 --- [nio-8080-exec-1] o.s.w.s.s.e.SimpleSoapExceptionResolver  : Resolving exception from endpoint [public localhost.soap.GetAllUserResponse com.driypeen.userServiceSOAP.endpoint.UserEndpoint.getAllUsers(localhost.soap.GetAllUserRequest)]: java.lang.IllegalStateException: No adapter for endpoint [public localhost.soap.GetAllUserResponse com.driypeen.userServiceSOAP.endpoint.UserEndpoint.getAllUsers(localhost.soap.GetAllUserRequest)]: Is your endpoint annotated with @Endpoint, or does it implement a supported interface like MessageHandler or PayloadEndpoint?
2022-06-18 12:08:33.370 DEBUG 11612 --- [nio-8080-exec-1] o.s.w.soap.server.SoapMessageDispatcher  : Endpoint invocation resulted in exception - responding with Fault

原来是服务端找到了端点,却没有找到适配器? 所以,我写了这个:

    @Autowired
    List<EndpointAdapter> adapters;

    @PostConstruct
    public void a () {
        log.info("ADAPTERS:");
        adapters.forEach(System.out::println);
    }

并得到这个输出:

2022-06-18 12:07:03.106  INFO 11612 --- [           main] c.d.u.endpoint.UserEndpoint              : ADAPTERS:
org.springframework.ws.server.endpoint.adapter.DefaultMethodEndpointAdapter@1f6f0fe2
org.springframework.ws.server.endpoint.adapter.PayloadEndpointAdapter@ab2009f

我的 XSD 文件包含以下内容:

    <xs:element name="GetAllUserRequest">
        <xs:complexType>
            <xs:sequence>
            </xs:sequence>
        </xs:complexType>
    </xs:element>

    <xs:element name="GetAllUserResponse">
        <xs:complexType>
            <xs:sequence>
                <xs:element name="users" type="tns:UserWithoutRole" minOccurs="0" maxOccurs="unbounded"/>
            </xs:sequence>
        </xs:complexType>
    </xs:element>

生成的类如下所示:

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(
    name = ""
)
@XmlRootElement(
    name = "GetAllUserRequest"
)
public class GetAllUserRequest {
    public GetAllUserRequest() {
    }
}

我的请求:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
                  xmlns:gs="localhost/soap">
    <soapenv:Header/>
    <soapenv:Body>
        <gs:GetAllUser/>
    </soapenv:Body>
</soapenv:Envelope>

端点类:

@Endpoint
@Slf4j
public class UserEndpoint {
    private static final String NAMESPACE_URI = "localhost/soap";

    private UserService userService;

    @Autowired
    public void setUserService(UserService userService) {
        this.userService = userService;
    }

    @Autowired
    List<EndpointAdapter> adapters;

    @PostConstruct
    public void a () {
        log.info("ADAPTERS:");
        adapters.forEach(System.out::println);
    }

    @PayloadRoot(localPart = "GetAllUser", namespace = NAMESPACE_URI)
    @ResponsePayload
    public GetAllUserResponse getAllUsers(@RequestPayload GetAllUserRequest request) {
        log.info("GET ALL USERS");

        GetAllUserResponse response = new GetAllUserResponse();
        response.getUsers().addAll(userService.findAll());

        return response;
    }
}

网络服务配置:

@EnableWs
@Configuration
public class WebServiceConfig extends WsConfigurerAdapter {
    @Bean
    public ServletRegistrationBean messageDispatcherServlet(ApplicationContext applicationContext) {
        MessageDispatcherServlet servlet = new MessageDispatcherServlet();
        servlet.setApplicationContext(applicationContext);
        servlet.setTransformWsdlLocations(true);
        return new ServletRegistrationBean(servlet, "/ws/*");
    }

    @Bean(name = "soap")
    public DefaultWsdl11Definition defaultWsdl11Definition(XsdSchema countriesSchema) {
        DefaultWsdl11Definition wsdl11Definition = new DefaultWsdl11Definition();
        wsdl11Definition.setPortTypeName("SoapPort");
        wsdl11Definition.setLocationUri("/ws");
        wsdl11Definition.setTargetNamespace("localhost/soap");
        wsdl11Definition.setSchema(countriesSchema);
        return wsdl11Definition;
    }

    @Bean
    public XsdSchema countriesSchema() {
        return new SimpleXsdSchema(new ClassPathResource("userServiceSOAP.xsd"));
    }

    @Bean
    public EndpointAdapter messageEndpointAdapter() {
        return new PayloadEndpointAdapter();
    }
}

为什么没有一个适配器支持我的端点? 谢谢!

我遇到了同样的问题。 就我而言,它与使用Jakarta XML 绑定有关。 当我将其更改为Javax 而不是 Jakarta 时,一切正常。 因此,当您在生成的源中检查导入时,它应该是这样的:

import javax.xml.bind.annotation.XmlRootElement;

下面列出了 Java 8+ 的其他依赖项:

<!-- https://mvnrepository.com/artifact/javax.xml.bind/jaxb-api -->
    <dependency>
        <groupId>javax.xml.bind</groupId>
        <artifactId>jaxb-api</artifactId>
        <version>2.3.1</version>
    </dependency>

    <!-- https://mvnrepository.com/artifact/javax.activation/activation -->
    <dependency>
        <groupId>javax.activation</groupId>
        <artifactId>activation</artifactId>
        <version>1.1</version>
    </dependency>

    <!-- https://mvnrepository.com/artifact/org.glassfish.jaxb/jaxb-runtime -->
    <dependency>
        <groupId>org.glassfish.jaxb</groupId>
        <artifactId>jaxb-runtime</artifactId>
        <version>2.3.1</version>
    </dependency>

请注意,如果您的 Java 版本为 8 或更低,则本指南无需更改即可正常工作,因为 Java 8 仍然附带 JAXB 实现。

我看到 Spring 5 不支持 Jakarta,他们计划在未来的 6 版本中添加支持。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM