2017-06-19 9 views
-1

私はSpringブートを使用してSOAP WSを生成しています。私はこれを開発するために契約の最初の哲学を使用しています。 8090/CMD-サービス/コマンド:SpringブートSOAP WSエンドポイント

私は

@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, "/cmd-service/*"); 
     } 

     @Bean(name = "command") 
     public DefaultWsdl11Definition defaultWsdl11Definition(XsdSchema commandSchema) { 
      DefaultWsdl11Definition wsdl11Definition = new DefaultWsdl11Definition(); 
      wsdl11Definition.setPortTypeName("CommandServicePort"); 
      wsdl11Definition.setLocationUri("/cmd-service"); 
      wsdl11Definition.setTargetNamespace("www.google.com"); 
      wsdl11Definition.setSchema(commandSchema); 
      return wsdl11Definition; 
     } 

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

エンドポイント・コード

@Endpoint 
public class CommandEndPoint { 

    private static final String NAMESPACE_URI = "www.google.com"; 
    @PayloadRoot(namespace = NAMESPACE_URI, localPart = "CommandRequest") 
    @ResponsePayload 
    public JAXBElement<CommandResponse> command(
      @RequestPayload CommandRequest commandRequest) { 
       } 

} 

上記のコードは、ローカルホストに1つのWebサービスを公開し

<?xml version="1.0" encoding="UTF-8"?> 
<xs:schema elementFormDefault="qualified" 
      targetNamespace="www.google.com" version="1.0" 
      xmlns:tns="www.google.com" 
      xmlns:xs="http://www.w3.org/2001/XMLSchema"> 

<xs:element name="CommandRequest" type="tns:CommandRequest"/> 
<xs:complexType name="CommandRequest"> 
       <xs:sequence> 
        <xs:element minOccurs="0" name="enterpriseId" type="xs:string"/> 
        <xs:element minOccurs="0" name="pwd" type="xs:string"/> 
        <xs:element minOccurs="0" name="command" type="xs:string"/> 
       </xs:sequence> 
</xs:complexType> 
<xs:element name="CommandResponse" type="tns:CommandResponse"/> 
    <xs:complexType name="CommandResponse"> 
       <xs:sequence> 
        <xs:element name="code" type="xs:int"/> 
        <xs:element minOccurs="0" name="message" type="xs:string"/>   
       </xs:sequence> 
    </xs:complexType> 
</xs:schema> 

Configurationクラススキーマ次ています。 wsdl。

同じスキーマを使用して、2つの異なるwsdl(1.localhost:8090/service1/command.wsdlと2. localhost:8090/service2/command.wsdl)を公開します。どのような体は私にこの問題を解決する方法を提案することができますか?

答えて

0

MessageDispatcherServletを拡張し、列挙型RequestTypeStore.RequestTypeを設定することで、この問題を解決できました。

@EnableWs 

@ConfigurationパブリッククラスWebServiceConfigはWsConfigurerAdapterを拡張{

@Bean 
MessageDispatcherServlet servlet() { 
    return new MessageDispatcherServlet() { 
     @Autowired 
     private RequestTypeStore requestStore; 
     public void service(ServletRequest req, ServletResponse resp) throws ServletException, IOException { 

      HttpServletRequest httpReq = (HttpServletRequest) req; 
      String URI = httpReq.getRequestURI(); 
      if(httpReq.getRequestURI().contains("/dns-service")) { 
       requestStore.setType(RequestType.DNS_COMMAND); 
      } 
      else if (httpReq.getRequestURI().contains("/registry-service")) { 
       requestStore.setType(RequestType.REGISTRY_COMMAND); 
      } 
      else { 
       requestStore.setType(RequestType.UNKNOWN_COMMAND); 
      } 
      super.service(req, resp); 

     } 

    }; 
} 

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


@Bean(name = "registry-command") 
public DefaultWsdl11Definition defaultWsdl11Definition(XsdSchema commandSchema) { 
    DefaultWsdl11Definition wsdl11Definition = new DefaultWsdl11Definition(); 
    wsdl11Definition.setPortTypeName("CommandServicePort"); 
    wsdl11Definition.setLocationUri("/registry-service"); 
    wsdl11Definition.setTargetNamespace("www.google.com"); 
    wsdl11Definition.setSchema(commandSchema); 
    wsdl11Definition.setRequestSuffix(""); 
    return wsdl11Definition; 
} 

@Bean(name = "dns-command") 
public DefaultWsdl11Definition defaultWsdl11DefinitionDNS(XsdSchema commandSchema) { 
    DefaultWsdl11Definition wsdl11Definition = new DefaultWsdl11Definition(); 
    wsdl11Definition.setPortTypeName("CommandServicePort2"); 
    wsdl11Definition.setLocationUri("/dns-service"); 
    wsdl11Definition.setTargetNamespace("www.google.com"); 
    wsdl11Definition.setSchema(commandSchema); 
    return wsdl11Definition; 
} 

} 

RequestTypeStore実装は以下の通りである:

@Component 
@Scope(value = "request", proxyMode = ScopedProxyMode.TARGET_CLASS) 
public class RequestTypeStore { 

    public enum RequestType { DNS_COMMAND,REGISTRY_COMMAND,UNKNOWN_COMMAND}; 
    private RequestType type; 
    public RequestType getType() { 
     return type; 
    } 
    public void setType(RequestType type) { 
     this.type = type; 
    } 
関連する問題