Web Services 端点Spring WS SOAP没有适配器

xeufq47z  于 2022-11-15  发布在  Spring
关注(0)|答案(1)|浏览(192)

我有一个非常奇怪的问题。我尝试发送请求到我的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;
    }
}

Web服务配置:

@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();
    }
}

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

h7wcgrx3

h7wcgrx31#

我遇到了同样的问题。在我的例子中,它与使用JakartaXML绑定有关。当我将它改为Javax而不是Jakarta时,一切都正常。因此,当您在生成的源代码中检查导入时,它应该是smth,如下所示:

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或更低,则guide无需更改即可正常工作,因为Java8仍然附带JAXB实现。
我看到Spring 5不支持Jakarta,他们计划在未来的6版本中添加支持。

相关问题