2016-04-27 8 views
2

ここで私が達成しようとしていることがあります。 15分ごとにHTTP APIをポーリングし、これから取得したデータを処理します。 Spring Integrationを使用する予定です。私はこれに新しいです。だからほとんど理解、私はアウトバウンドゲートウェイを作成し、同じのポーラーを追加しましたが、以下のエラーを取得します。Spring統合のTransformerを使用したHTTPサービス(Outbound Gateway)のポーリングとプロセス

また、送信ゲートウェイからデータを処理するためにトランスを使用する方法を教えてもらえますか?

Error creating bean with name 'org.springframework.integration.config.ConsumerEndpointFactoryBean#0': 
Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: 
A poller should not be specified for endpoint 'org.springframework.integration.config.ConsumerEndpointFactoryBean#0', 
since 'in' is a SubscribableChannel (not pollable). 

マイINT-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" 
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd 
     http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd 
     http://www.springframework.org/schema/integration/http http://www.springframework.org/schema/integration/http/spring-integration-http.xsd 
     http://www.springframework.org/schema/oxm http://www.springframework.org/schema/oxm/spring-oxm.xsd" 
    xmlns:int="http://www.springframework.org/schema/integration" 
    xmlns:oxm="http://www.springframework.org/schema/oxm" 
    xmlns:int-http="http://www.springframework.org/schema/integration/http"> 

    <int:annotation-config/> 

    <!-- Inbound/Outbound Channels --> 
    <int:channel id="employeeSearchRequest" /> 
    <int:channel id="employeeSearchResponse" /> 

    <int:channel id="userSearchRequest" /> 
    <int:channel id="userSearchResponse" /> 


    <int-http:inbound-gateway id="inboundEmployeeSearchRequestGateway" 
     supported-methods="GET, POST" 
     request-channel="employeeSearchRequest" 
     reply-channel="employeeSearchResponse"  
     mapped-response-headers="Return-Status, Return-Status-Msg, HTTP_RESPONSE_HEADERS" 
     view-name="/employee" 
     path="/services/employee/{id}/search" 
     reply-timeout="50000"> 

     <int-http:header name="employeeId" expression="#pathVariables.id"/> 

    </int-http:inbound-gateway> 

    <int-http:inbound-gateway id="inboundUserSearchRequestGateway" 
     supported-methods="GET, POST" 
     request-channel="userSearchRequest" 
     reply-channel="userSearchResponse"  
     mapped-response-headers="Return-Status, Return-Status-Msg, HTTP_RESPONSE_HEADERS" 
     view-name="/users" 
     path="https://stackoverflow.com/users/{id}/search" 
     reply-timeout="50000"> 

     <int-http:header name="userId" expression="#pathVariables.id"/> 

    </int-http:inbound-gateway> 

    <!-- Consume WS Sample --> 
    <int:channel id="in" /> 
    <int:channel id="out" /> 

    <int-http:outbound-gateway request-channel="in" reply-channel="out" 
     url="http://echo.jsontest.com/key/value/one/two" http-method="GET" 
     expected-response-type="java.lang.String"> 
     <int:poller fixed-rate="20000"/> 
    </int-http:outbound-gateway> 

    <int:transformer input-channel="in" 
    output-channel="out" ref="hTTPTransformer" /> 

    <!-- Consume WS Sample Ends --> 


    <!-- Note: The default parameter name for favorParameter is "format". For instance, when this flag is true, a request for /services/employee/{id}/search?format=json will result 
      in an MappingJacksonJsonView being resolved, while the Accept header can be the browser-defined text/html,application/xhtml+xml --> 

    <bean class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver"> 
     <property name="order" value="1" /> 
     <property name="contentNegotiationManager"> 
      <bean class="org.springframework.web.accept.ContentNegotiationManagerFactoryBean"> 
       <property name="defaultContentType" value="application/json"/> 
       <property name="favorParameter" value="true"/> 
       <property name="ignoreAcceptHeader" value="true" /> 
       <property name="mediaTypes"> 
        <map> 
         <entry key="json" value="application/json" /> 
         <entry key="xml" value="application/xml" /> 
        </map> 
       </property> 
      </bean> 
     </property> 
     <property name="defaultViews"> 
      <list> 
       <bean 
        class="org.springframework.integration.samples.rest.json.view.ExtendedMappingJacksonJsonView" > 
        <property name="objectMapper" ref="jaxbJacksonObjectMapper"/> 
       </bean> 
       <bean class="org.springframework.web.servlet.view.xml.MarshallingView"> 
        <constructor-arg ref="marshaller"/> 
       </bean> 
      </list> 
     </property> 
    </bean> 

    <oxm:jaxb2-marshaller id="marshaller" context-path="org.springframework.integration.samples.rest.domain" /> 

    <int:service-activator id="employeeServiceActivator" 
        input-channel="employeeSearchRequest" 
        output-channel="employeeSearchResponse" 
        ref="employeeSearchService" 
        method="getEmployee" 
        requires-reply="true" 
        send-timeout="60000"/> 

    <int:service-activator id="userServiceActivator" 
        input-channel="userSearchRequest" 
        output-channel="userSearchResponse" 
        ref="userSearchService" 
        method="getUsers" 
        requires-reply="true" 
        send-timeout="60000"/>     

    <bean id="jaxbJacksonObjectMapper" class="org.springframework.integration.samples.rest.json.JaxbJacksonObjectMapper"/> 

</beans> 

ある誰かが、なぜ私はこのエラーを取得しています教えてもらえますか?事前にみんなありがとう!

+1

ゲートウェイはポーリング用ではありません。ゲートウェイはrequest-Channelのメッセージによってトリガーされます。私の推測では、http-inbound-adapterが必要です。または、おそらくhttp-outbound-adapter - わかりません。 –

+0

@ JensKrogsboellそれを指摘してくれてありがとう。 inbound-channel-adapterを追加すると、それがポーリングされました!可能であれば、このAPIからJSONオブジェクトを取得し、それをトランスフォーマで処理する方法を教えてください。 – Rajkumar

+1

これを見てくださいhttp://stackoverflow.com/questions/25748719/spring-messaging-converting-json-string-to-map –

答えて

1

1 UPDATE:ビーンに対する応答を変換するため、私は、最後

<int:json-to-object-transformer input-channel="out" 
output-channel="testChannel" type="org.springframework.integration.samples.rest.domain.PlaceholderBean"/> 

<int:service-activator method="dummyMethod" input-channel="testChannel" ref="dummyService"/> 

このコードを追加:ポーリング、インバウンド・チャネル・アダプタを追加する

<int-http:outbound-gateway request-channel="in" reply-channel="out" 
     url="http://echo.jsontest.com/key/value/one/two" http-method="GET" 
     expected-response-type="java.lang.String"> 
    </int-http:outbound-gateway> 

<int:inbound-channel-adapter channel="in" expression="''"> 
     <int:poller fixed-delay="60000"></int:poller> 
    </int:inbound-channel-adapter> 

2 UPDATE働いHTTPサービスをポーリングしてデータを取得し、処理することができます!すべての助けに感謝@JensKrogsboell!

関連する問題