2017-11-24 16 views
0

私はSimpleWebServiceInboundGatewayを使って作業していますが、現在はゲートウェイがチャンネルに要求を入れ、次にチャンネルから消費するフローを持っています。すべてがうまくいくようです。spring-integration SimpleWebServiceInboundGateway

私は多少異なる動作をする複数の異なるソープエンドポイントサービスがある場合、これらのエンドポイントを異なるフローにどのようにマッピングすればよいのでしょうか。 SOAPサービスのWebサービスエンドポイントごとに新しいSimpleWebServiceInboundGatewayを用意し、EndpointMapperを使用してそれぞれにマッピングすることが期待されますか?それともこれを行うためのより良い習慣がありますか?私はそれが複数のSoap Gatewaysを持っていると予想されていたかどうかは確かではありませんでした。

また、フローでws呼び出しを行うために使用されたURI/URLへの簡単なアクセス方法はありますか?私はそれがヘッダーにあるように見えないことに気づいた。ここで

は私のサンプルの構成です:

/** 
* URL mappings used by WS endpoints 
*/ 
public static final String[] WS_URL_MAPPINGS = {"/services/*", "*.wsdl", "*.xsd"}; 
public static final String GATEWAY_INBOUND_CHANNEL_NAME = "wsGatewayInboundChannel"; 
public static final String GATEWAY_OUTBOUND_CHANNEL_NAME = "wsGatewayOutboundChannel"; 


/** 
* Register the servlet mapper, note that it uses MessageDispatcher 
*/ 
@Bean 
public ServletRegistrationBean messageDispatcherServlet(ApplicationContext applicationContext) { 
    MessageDispatcherServlet servlet = new MessageDispatcherServlet(); 
    servlet.setApplicationContext(applicationContext); 
    servlet.setTransformWsdlLocations(true); 
    servlet.setTransformSchemaLocations(true); 
    servlet.setPublishEvents(true); 
    ServletRegistrationBean servletDef = new ServletRegistrationBean(servlet, WS_URL_MAPPINGS); 
    servletDef.setLoadOnStartup(1); 
    return servletDef; 
} 

/** 
* Create a new Direct channels to handle the messages 
*/ 
@Bean 
public MessageChannel wsGatewayInboundChannel() { 
    return MessageChannels.direct(GATEWAY_INBOUND_CHANNEL_NAME).get(); 
} 
@Bean 
public MessageChannel wsGatewayOutboundChannel() { 
    return MessageChannels.direct(GATEWAY_OUTBOUND_CHANNEL_NAME).get(); 
} 

/** 
* Startup the WebServiceInboundGateway Endpoint, this will handle the incoming SOAP requests 
* and place them onto the request channel 
*/ 
@Bean 
public SimpleWebServiceInboundGateway webServiceInboundGateway(
     @Value("${spring.ws.should.track:true}") boolean shouldTrack 
) { 
    SimpleWebServiceInboundGateway wsg = new SimpleWebServiceInboundGateway(); 
    wsg.setRequestChannel(wsGatewayInboundChannel()); 
    wsg.setReplyChannel(wsGatewayOutboundChannel()); 
    wsg.setExtractPayload(false); // Send the full RAW SOAPMessage and not just payload 
    wsg.setLoggingEnabled(true); 
    wsg.setShouldTrack(shouldTrack); 
    wsg.setCountsEnabled(true); 
    return wsg; 
} 


/** 
* Map the allowable service Uri's. 
* 
* although this isn't needed (can map everything using the mapping.setDefaultEndpoint) 
* using this approach ensures that people don't use unexpected uris, probably can 
* find a better way to deal with this in the future 
*/ 
@Bean 
public EndpointMapping uriEndpointMapping(@Qualifier("serviceUris") List<String> serviceUris 
     , PayloadValidatingInterceptor payloadValidatingInterceptor 
     , SimpleWebServiceInboundGateway webServiceInboundGateway) { 
    UriEndpointMapping mapping = new UriEndpointMapping(); 
    mapping.setUsePath(true); 
    Map<String, Object> endpointMap = new HashMap<>(); 
    endpointMap.put("/services/myservice1", webServiceInboundGateway); 

    mapping.setEndpointMap(endpointMap); 
    //mapping.setDefaultEndpoint(webServiceInboundGateway()); 

    return mapping; 
} 


@Bean 
public IntegrationFlow itemLookupFlow(ItemLookupRequestToItemDetailsRequestTransformer requestTransformer 
     , ItemDetailsResponseToItemLookupResponseTransformer responseTransformer) { 
    return IntegrationFlows.from("wsGatewayInboundChannel") 
      .transform(new MyTransformer()) 
      .log(LoggingHandler.Level.INFO) 
      .handle(myBean, "execute") 
      .get(); 
} 

答えて

1

それともこれを行うためのより良い練習がありますか?

なぜ誰もがSpring Integrationを悪い習慣とみなしていますか?状況をイメージ化すると、アプリケーションでSpring Integrationを使用せず、Spring WSのみを使用します。 これで、いくつかのエンドポイントを記述する必要があります。あなたがすること?そうですね、@Endpointや適切なURLマッピングでいくつかのクラスを開発してください。そして、どういうわけかここでは悪い習慣で、フレームワークの要件に従うだけであるとは言いません。

なぜ、別のSimpleWebServiceInboundGatewayさんは行くのが悪いのですか?

私は、異なるエンドポイントは実際に完全に非関連のロジック、異なる変換、ルーティング、そして最後にSOAPアンマーシャリングを意味すると思います。

したがって、別のSpring WS @Endpointクラスとして新しいSimpleWebServiceInboundGatewayとそのダウンストリームフローを考慮してください。

URLを取得するには、カスタムSoapHeaderMapperを挿入する必要があります。私はSoapMessageがその情報を抽出するためにいくつかのフックを持っていると思う。

+0

あなたの考えに感謝Artem、私は主にそれが正しい道であることを確認していました。限られた例があるように私は他人が何をしているのか見たいと思っていました。 – abe