2014-07-22 3 views
0

다음은 현재 웹 서비스에 대한 나의 공동 구성입니다. 각 서비스에 대해 별도의 게이트웨이와 헤더를 추가하여 라우팅 할 라우터를 알려주는 헤더를 추가 할 수 있습니다. 간결함을 위해 일부 구성을 생략했습니다. 나 또한 이것이 다른 흐름으로 수행 될 수 있다는 것을 이해한다. 그러나 다른 작업 부분 (버전 관리, 비추천 등)이 있으므로이 방법으로 설정하고 나중에 사용자 지정 라우터를 사용해야한다.게이트웨이에서 헤더 값 설정

<bean 
     class="org.springframework.ws.server.endpoint.mapping.UriEndpointMapping"> 
     <property name="mappings"> 
      <props> 
       <!-- TODO use config property for host --> 
       <prop key="${service.endpoint.url}/SNTWS/service/CompanyService">SOAPCompanyGateway</prop> 
       <prop key="${service.endpoint.url}/SNTWS/service/ContactService">SOAPContactGateway</prop> 

      </props> 
     </property> 
    </bean> 

    <!-- define gateways for each service endpoint --> 

    <int-ws:inbound-gateway id="SOAPCompanyGateway" 
     request-channel="SOAPCompanyRequestChannel" marshaller="SOAPMarshaller" 
     unmarshaller="SOAPMarshaller" /> 

    <int-ws:inbound-gateway id="SOAPContactGateway" 
     request-channel="SOAPContactRequestChannel" marshaller="SOAPMarshaller" 
     unmarshaller="SOAPMarshaller" /> 

    <bean id="SOAPMarshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller"> 
     <property name="contextPaths"> 
      <list> 
       <!-- list all schema versions that we wish to accept --> 
       <value>com.predictivesolutions.schema.v1_1</value> 
       <value>com.predictivesolutions.schema.v2_0</value> 
      </list> 
     </property> 
    </bean> 


    <!-- these header enrichers add the service header and send all the messages 
     to the same output channel, add specific service headers in this section 
     before all messages are placed on a common channel. THe values of the header 
     must match the service-activator input-channel --> 

    <int:header-enricher input-channel="SOAPContactRequestChannel" 
     output-channel="SOAPRequestChannel"> 
     <int:header name="service" value="ContactService" /> 
    </int:header-enricher> 

    <int:header-enricher input-channel="SOAPCompanyRequestChannel" 
     output-channel="SOAPRequestChannel"> 
     <int:header name="service" value="CompanyService" /> 
    </int:header-enricher> 

    <!-- set another header with the package name, which is used to determine 
     version. THis is necessary (along with service header) to route messages 
     to the appropriate versioned service. This code is the same regardless of 
     service type. --> 
    <int:header-enricher input-channel="SOAPRequestChannel" 
     output-channel="SOAPRequestChannelWithHeaders"> 
     <int:header name="version" 
      expression="payload.getClass().getPackage().getName().substring(payload.getClass().getPackage().getName().lastIndexOf('.')+1)" /> 
    </int:header-enricher> 

이유는 내가 별도의 게이트웨이 및 헤더가 풍부해야하기 때문에 메시지에 적절한 서비스 헤더를 설정할 수 있습니다. 모든 메시지는 SOAPRequestChannel에 배치되어 버전을 가져옵니다.

이상적으로 구성을 줄이기 위해 모든 끝점 매핑에 대해 하나의 게이트웨이를 갖고 싶습니다. 마지막 부분이 서비스 이름이라는 것을 알고 있기 때문에 URL에서 헤더를 설정할 수 있습니다.

나는 이것을 수행하기위한 아이디어를 찾고있다. Spel을 사용하여 URL 경로에 액세스 할 수 있습니까? 당신도 그 uri 값을 기반으로 라우팅을 수행 할 수 있다는 데

<int:header-enricher> 
    <int:header name="uri" 
     expression="T(org.springframework.ws.transport.context.TransportContextHolder).transportContext.connection.uri" /> 
</int:header-enricher> 

각각 두 <int-ws:inbound-gateway><int:header-enricher>의 제거 할 수 :

답변

1

예, 당신은 URI를 사용하는 것을 할 수 있습니다.