【问题标题】:Spring-boot web-service endpoint class not workingSpring-boot Web 服务端点类不起作用
【发布时间】:2016-09-28 14:23:39
【问题描述】:

尝试使用 Maven 创建带有肥皂网络服务的 spring-boot 项目。 项目设置正确,没有任何编译时间问题。

已使用 spring-boot-web-services 依赖项。 启动应用程序时,我可以正确看到 wsdl,但是当我使用带有适当输入的 chrome wizdler 进行操作时,我得到了失败。 甚至看不到端点类中存在的打印语句。

需要确认我是否根据 WSDL 为注解 @PayloadRoot、@RequestPayload 和 @ResponsePayload 提供了正确的值。

下面是我的 WSDL 和 Endpoint 类:

WSDL 文件

<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:msc="http://schemas.microsoft.com/ws/2005/12/wsdl/contract" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:tns="schemas.corporate.com/col/2014/01" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:wsa10="http://www.w3.org/2005/08/addressing" xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata" xmlns:wsap="http://schemas.xmlsoap.org/ws/2004/08/addressing/policy" xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:wsx="http://schemas.xmlsoap.org/ws/2004/09/mex" xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="VaultNotificationService" targetNamespace="schemas.corporate.com/col/2014/01">
   <wsp:Policy wsu:Id="BasicHttpBinding_IVaultNotificationService_policy">
      <wsp:ExactlyOne>
         <wsp:All>
            <sp:TransportBinding xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy">
               <wsp:Policy>
                  <sp:TransportToken>
                     <wsp:Policy>
                        <sp:HttpsToken RequireClientCertificate="false" />
                     </wsp:Policy>
                  </sp:TransportToken>
                  <sp:AlgorithmSuite>
                     <wsp:Policy>
                        <sp:Basic256 />
                     </wsp:Policy>
                  </sp:AlgorithmSuite>
                  <sp:Layout>
                     <wsp:Policy>
                        <sp:Strict />
                     </wsp:Policy>
                  </sp:Layout>
               </wsp:Policy>
            </sp:TransportBinding>
         </wsp:All>
      </wsp:ExactlyOne>
   </wsp:Policy>
   <wsdl:types>
      <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tns="urn:CorporateServices" elementFormDefault="qualified" targetNamespace="urn:CorporateServices">
         <xs:element name="OrderUpdate">
            <xs:complexType>
               <xs:sequence>
                  <xs:element minOccurs="0" maxOccurs="unbounded" form="unqualified" name="OrderUpdateItemList" type="tns:OrderUpdateItem" />
               </xs:sequence>
            </xs:complexType>
         </xs:element>
         <xs:complexType name="OrderUpdateItem">
            <xs:sequence>
               <xs:element minOccurs="0" maxOccurs="1" form="unqualified" name="Order_ID" type="xs:string" />
               <xs:element minOccurs="0" maxOccurs="1" form="unqualified" name="Order_InternalID" type="xs:string" />
               <xs:element minOccurs="0" maxOccurs="1" form="unqualified" name="Order_Status" type="xs:string" />
            </xs:sequence>
         </xs:complexType>
         <xs:element name="OrderUpdateResponse">
            <xs:complexType>
               <xs:sequence>
                  <xs:element minOccurs="0" maxOccurs="unbounded" form="unqualified" name="OrderUpdateItemList" type="tns:OrderUpdateItem" />
               </xs:sequence>
            </xs:complexType>
         </xs:element>
      </xs:schema>
   </wsdl:types>
   <wsdl:message name="UpdateRequest">
      <wsdl:part xmlns:q1="urn:CorporateServices" name="parameters" element="q1:OrderUpdate" />
   </wsdl:message>
   <wsdl:message name="UpdateResponse">
      <wsdl:part xmlns:q2="urn:CorporateServices" name="parameters" element="q2:OrderUpdateResponse" />
   </wsdl:message>
   <wsdl:portType name="IVaultNotificationService">
      <wsdl:operation name="Update">
         <wsdl:input wsaw:Action="schemas.corporate.com/col/2014/01/IVaultNotificationService/Update" name="UpdateRequest" message="tns:UpdateRequest" />
         <wsdl:output wsaw:Action="schemas.corporate.com/col/2014/01/IVaultNotificationService/UpdateResponse" name="UpdateResponse" message="tns:UpdateResponse" />
      </wsdl:operation>
   </wsdl:portType>
   <wsdl:binding name="BasicHttpBinding_IVaultNotificationService" type="tns:IVaultNotificationService">
      <wsp:PolicyReference URI="#BasicHttpBinding_IVaultNotificationService_policy" />
      <soap:binding transport="http://schemas.xmlsoap.org/soap/http" />
      <wsdl:operation name="Update">
         <soap:operation soapAction="schemas.corporate.com/col/2014/01/IVaultNotificationService/Update" style="document" />
         <wsdl:input name="UpdateRequest">
            <soap:body use="literal" />
         </wsdl:input>
         <wsdl:output name="UpdateResponse">
            <soap:body use="literal" />
         </wsdl:output>
      </wsdl:operation>
   </wsdl:binding>
   <wsdl:service name="VaultNotificationService">
      <wsdl:port name="BasicHttpBinding_IVaultNotificationService" binding="tns:BasicHttpBinding_IVaultNotificationService">
         <soap:address location="https://app.sit.col.corporate.com/VaultNotificationService.svc" />
      </wsdl:port>
   </wsdl:service>
</wsdl:definitions>

端点类

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
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;

import colservices.OrderUpdate;
import colservices.OrderUpdateItem;
import colservices.OrderUpdateResponse;

@Endpoint
public class OrderUpdateEndpoint {

    private final IVaultNotificationService vaultNotificationService;

    @Autowired
    public OrderUpdateEndpoint(IVaultNotificationService vaultNotificationService) {
        this.vaultNotificationService = vaultNotificationService;
    }

    @PayloadRoot(namespace = "urn:CorporateServices", localPart = "UpdateRequest")
    @ResponsePayload
    public OrderUpdateResponse updateOrderStatus(@RequestPayload OrderUpdate request) {
    System.out.println("Enetered in endpoint");
        List<OrderUpdateItem> orderUpdateItemList = vaultNotificationService
                .updateOrdersStatus(request.getOrderUpdateItemList());

        OrderUpdateResponse response = new OrderUpdateResponse();
        response.getOrderUpdateItemList().addAll(orderUpdateItemList);

        return response;
    }

}

请让我知道我错过了什么。

应用配置

import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.ClassPathResource;
import org.springframework.ws.config.annotation.EnableWs;
import org.springframework.ws.config.annotation.WsConfigurerAdapter;
import org.springframework.ws.transport.http.MessageDispatcherServlet;
import org.springframework.ws.wsdl.wsdl11.SimpleWsdl11Definition;
import org.springframework.ws.wsdl.wsdl11.Wsdl11Definition;

@EnableWs
@Configuration
public class ApplicationConfig extends WsConfigurerAdapter {

    @Bean
    public ServletRegistrationBean dispatcherServlet(ApplicationContext applicationContext) {
        MessageDispatcherServlet servlet = new MessageDispatcherServlet();
        servlet.setApplicationContext(applicationContext);
        servlet.setTransformWsdlLocations(true);
        return new ServletRegistrationBean(servlet, "/services/*");
    }

    @Bean(name = "orderStatusUpdator")
    public Wsdl11Definition defaultWsdl11Definition() {
        SimpleWsdl11Definition wsdl11Definition = new SimpleWsdl11Definition();
        wsdl11Definition.setWsdl(new ClassPathResource("vaultNotificationService.wsdl"));
        return wsdl11Definition;
    }
}

应用程序

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class Application {

    public static void main(String[] args) {
        System.out.println("entering application");
        SpringApplication.run(Application.class, args);
    }
}

【问题讨论】:

  • 在 Endpoint 类 OrderUpdateEndpoint 中,“Enetered in endpoint”语句没有被打印出来,它无法解决我认为的方法。
  • 添加您的应用程序类。
  • 添加了ApplicationConfig和Application类
  • 里面没有任何与肥皂有关的东西。所以什么都不会发生。您需要配置MessageDispatcherServlet 并在您的班级中至少拥有@EnableWs。否则什么都不会发生。
  • 已经在 ApplicationConfig 类中创建了 MessageDispatcherServlet 并且还使用了@Enablews

标签: spring web-services spring-boot


【解决方案1】:

正在处理以下更改:

1) WSDL 中的更改来自

<soap:address location="https://app.sit.col.corporate.com/VaultNotificationService.svc" />

 <soap:address location="https://app.sit.col.travelex.com/services" />

原因:

i) /services/ URI 用作基础 uri

ii) 作为 servlet.setTransformWsdlLocations(true),此位置将根据用户请求自动转换。

2) 移动了端点类所在的父包中的应用程序类,以允许组件扫描工作。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-11-13
    • 2021-09-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-31
    • 1970-01-01
    相关资源
    最近更新 更多