2017-07-04 3 views
1

Ich versuche, einen Rest-Service zu konsumieren und erhalten Sie eine JSON zurück und konvertieren Sie es in eine Liste von Objekten. aber ich erhalte die untenstehenden Informationen. Ich bin neu bei EIP und es gibt nicht viele Tutorials dafür in Java dsl. Ich habe 2 Kanäle konfiguriert, einen zum Senden einer Anfrage und einen zum Empfangen der Nutzdaten zurück.Spring Integration HTTP Outbound Gateway Post Anfrage mit Java DSL

Exception in thread "main" org.springframework.beans.factory.BeanNotOfRequiredTypeException: Bean named 'httpPostAtms' is expected to be of type 'org.springframework.messaging.MessageChannel' but was actually of type 'org.springframework.integration.dsl.StandardIntegrationFlow' 
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:378) 
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) 
at org.springframework.integration.support.channel.BeanFactoryChannelResolver.resolveDestination(BeanFactoryChannelResolver.java:89) 
at org.springframework.integration.support.channel.BeanFactoryChannelResolver.resolveDestination(BeanFactoryChannelResolver.java:46) 
at org.springframework.integration.gateway.MessagingGatewaySupport.getRequestChannel(MessagingGatewaySupport.java:344) 
at org.springframework.integration.gateway.MessagingGatewaySupport.doSendAndReceive(MessagingGatewaySupport.java:433) 
at org.springframework.integration.gateway.MessagingGatewaySupport.sendAndReceive(MessagingGatewaySupport.java:422) 
at org.springframework.integration.gateway.GatewayProxyFactoryBean.invokeGatewayMethod(GatewayProxyFactoryBean.java:474) 
at org.springframework.integration.gateway.GatewayProxyFactoryBean.doInvoke(GatewayProxyFactoryBean.java:429) 
at org.springframework.integration.gateway.GatewayProxyFactoryBean.invoke(GatewayProxyFactoryBean.java:420) 
at org.springframework.integration.gateway.GatewayCompletableFutureProxyFactoryBean.invoke(GatewayCompletableFutureProxyFactoryBean.java:65) 
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) 
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:213) 
at com.sun.proxy.$Proxy70.getAllAtms(Unknown Source) 
at com.backbase.atm.IngAtmApplication.main(IngAtmApplication.java:25) 

Ich bin mit SI mit Frühlings-Boot-

@IntegrationComponentScan 
@Configuration 
@EnableIntegration 
@ComponentScan 
public class InfrastructorConfig { 

    @Bean 
    public PollableChannel requestChannel() { 
     return new PriorityChannel() ; 
    } 

    @Bean 
    public MessageChannel replyChannel() { 
     return new DirectChannel() ; 
    } 

    @Bean(name = PollerMetadata.DEFAULT_POLLER) 
    public PollerMetadata poller() { 
     return Pollers.fixedRate(500).get(); 
    } 

    @Bean 
    public IntegrationFlow httpPostAtms() { 

     return IntegrationFlows.from("requestChannel") 
       .handle(Http.outboundGateway("https://www.ing.nl/api/locator/atms/") 
         .httpMethod(HttpMethod.POST) 
         .extractPayload(true)) 
       .<String, String>transform(p -> p.substring(5)) 
       .transform(Transformers.fromJson(Atm[].class)) 
       .channel("responseChannel") 
       .get(); 

     } 

    } 

Das Gateway

package com.backbase.atm.service; 

import java.util.List; 

import org.springframework.integration.annotation.Gateway; 
import org.springframework.integration.annotation.MessagingGateway; 
import org.springframework.messaging.handler.annotation.Payload; 

import com.backbase.atm.model.Atm; 

@MessagingGateway 
public interface IntegrationService { 

    @Gateway(requestChannel = "httpPostAtms") 
    @Payload("new java.util.Date()") 
    List<Atm> getAllAtms(); 
} 

Anwendung Starten

package com.backbase.atm; 

import java.util.ArrayList; 
import java.util.List; 

import org.springframework.boot.CommandLineRunner; 
import org.springframework.boot.SpringApplication; 
import org.springframework.boot.autoconfigure.SpringBootApplication; 
import org.springframework.context.ConfigurableApplicationContext; 
import org.springframework.context.annotation.Bean; 
import com.backbase.atm.service.IntegrationService; 


@SpringBootApplication 
public class IngAtmApplication { 


    public static void main(String[] args) { 
     ConfigurableApplicationContext ctx = SpringApplication.run(IngAtmApplication.class, args); 
     ctx.getBean(IntegrationService.class).getAllAtms(); 
     ctx.close(); 
    } 

Antwort

1

Sie haben requestChannel Bean Namen im Gateway d zu verwenden, Definition. Im Moment haben Sie dort einen IntegrationFlow Bean-Namen, aber das ist falsch.

Denken Sie immer daran, dass alles in der Spring Integration über Kanäle verbunden ist.

+0

Das funktioniert !!! Beim Versuch, die JSON-Antwort nach dem Entfernen der ersten paar Zeichen in ein Objekt zu konvertieren, erhalte ich die Fehlermeldung "Ausnahme im Thread" main "java.lang.ClassCastException: org.springframework.http.ResponseEntity kann nicht in java.lang umgewandelt werden. String \t unter com.backbase.atm.config.InfrastructorConfig $$ Lambda $ 7/64989209.Transform (Unbekannte Quelle) 'meine Annahme war, dass ich die Payload als String mit 'p' empfangen würde. Oder sollte der Typschluss etwas anderes sein? – androgirl

+0

Verwenden Sie 'expectedResponseType (String.class)' geben Sie nicht das ganze 'ResponseEntity' –

+0

zurück, das den Trick gemacht hat. Vielen Dank!!! – androgirl

Verwandte Themen