Spring Web 服务客户端和服务器 - 未找到端点映射

Spring web Services client and server - No Endpoint mapping found

我正在尝试将 Spring 基于 WS 的服务器和 Spring 基于 WS 的客户端连接在一起。在服务器上使用 org.codehaus.mojo:jaxb2-maven-plugin,在客户端使用 org.jvnet.jaxb2.maven2:maven-jaxb2-plugin。

错误:

警告:未找到 [SaajSoapMessage {http://localhost:10301/0301-ws-xmlconfig-service}UserRequest]

的端点映射

这是我的Spring WS 服务器配置:

userDetails.xsd:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
  attributeFormDefault="unqualified" elementFormDefault="qualified"
  targetNamespace="http://localhost:10301/0301-ws-xmlconfig-service">

  <xs:element name="UserDetailsResponse">
    <xs:complexType>
      <xs:sequence>
        <xs:element type="xs:NCName" name="FirstName" />
        <xs:element type="xs:NCName" name="LastName" />
      </xs:sequence>
    </xs:complexType>
  </xs:element>

  <xs:element name="UserRequest">
    <xs:complexType>
      <xs:attribute name="Email">
        <xs:simpleType>
          <xs:restriction base="xs:string">
            <xs:pattern value="[^@]+@[^\.]+\..+" />
          </xs:restriction>
        </xs:simpleType>
      </xs:attribute>
    </xs:complexType>
  </xs:element>

</xs:schema>

UserEndpoint.java:

package net.lkrnac.server;

import localhost._10301._0301_ws_xmlconfig_service.UserDetailsResponse;

import org.springframework.ws.server.endpoint.annotation.Endpoint;
import org.springframework.ws.server.endpoint.annotation.PayloadRoot;
import org.springframework.ws.server.endpoint.annotation.RequestPayload;
import org.springframework.ws.server.endpoint.annotation.ResponsePayload;

@Endpoint
public class UserEndpoint {
  @PayloadRoot(namespace = "http://localhost:10301/0301-ws-xmlconfig-service/", localPart = "getUserDetails")
  @ResponsePayload
  public UserDetailsResponse getUserDetails(@RequestPayload String userEmail) {
    UserDetailsResponse userDetails = null;
    if ("lubos.krnac@gmail.com".equals(userEmail)) {
       userDetails = new UserDetailsResponse();
       userDetails.setFirstName("Lubos");
       userDetails.setLastName("Krnac");
    }
    return userDetails;
  }
}

网络服务-config.xml:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
  xmlns:ws="http://www.springframework.org/schema/web-services"
  xsi:schemaLocation="http://www.springframework.org/schema/web-services http://www.springframework.org/schema/web-services/web-services.xsd
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.1.xsd">

  <context:component-scan base-package="net.lkrnac.server" />

  <ws:annotation-driven />
</beans>

web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns="http://xmlns.jcp.org/xml/ns/javaee"
  xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
  version="2.5">
  <display-name>0301-ws-xmlconfig-service</display-name>
  <servlet>
    <servlet-name>web-service</servlet-name>
    <servlet-class>org.springframework.ws.transport.http.MessageDispatcherServlet
    </servlet-class>
    <init-param>
       <param-name>contextConfigLocation</param-name>
       <param-value>classpath:web-service-config.xml</param-value>
    </init-param>
    <init-param>
       <param-name>transformWsdlLocations</param-name>
       <param-value>true</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
     <servlet-name>web-service</servlet-name>
     <url-pattern>/*</url-pattern>
  </servlet-mapping>
</web-app>

这是我的客户端配置:

WebServiceClient.java:

package net.lkrnac.client;

import javax.annotation.PostConstruct;

import net.lkrnac.model.UserDetailsResponse;
import net.lkrnac.model.UserRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.stereotype.Component;
import org.springframework.ws.client.core.WebServiceTemplate;

@Component
@EnableAutoConfiguration
public class WebServiceClient {
  private static final Logger log = LoggerFactory
      .getLogger(WebServiceClient.class);

  private static final String URL =
      "http://localhost:10301/0301-ws-xmlconfig-service/getUserDetails";
  private WebServiceTemplate webServiceTemplate;

  @Autowired
  public WebServiceClient(WebServiceTemplate webServiceTemplate) {
     this.webServiceTemplate = webServiceTemplate;
  }

  public UserDetailsResponse getUserDetails(String email) {
    UserRequest request = new UserRequest();
    request.setEmail(email);

    UserDetailsResponse userDetails =
        (UserDetailsResponse) webServiceTemplate.marshalSendAndReceive(URL,
            request);
    return userDetails;
  }

  @PostConstruct
  public void test() {
    UserDetailsResponse userDetails =
        this.getUserDetails("lubos.krnac@gmail.com");
    log.debug("User Details: " + userDetails.getFirstName() + " "
        + userDetails.getLastName());
  }
}

网络客户端-config.xml:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:context="http://www.springframework.org/schema/context"
  xmlns:web-services="http://www.springframework.org/schema/web-services"
  xsi:schemaLocation="http://www.springframework.org/schema/web-services http://www.springframework.org/schema/web-services/web-services.xsd
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.1.xsd">

  <context:component-scan base-package="net.lkrnac.client"/>

  <web-services:annotation-driven/>
  <bean id="marshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
     <property name="contextPath" value="net.lkrnac.model"/>
  </bean>

  <bean id="webServiceTemplate" class="org.springframework.ws.client.core.WebServiceTemplate">
     <property name="marshaller" ref="marshaller"/>
     <property name="unmarshaller" ref="marshaller"/>
  </bean>
</beans>

有人知道吗?

日志消息指出端点应匹配 namespace="http://localhost:10301/0301-ws-xmlconfig-service" 并且期望 UserRequest,因此 localPart 应匹配 UserRequest.