Я пытаюсь вызвать метод POST для службы REST с помощью HttpRequestExecutingMessageHandler в Spring Integration.
Я уже попробовал решение, предоставленное на Не удалось записать запрос: не найден подходящий HttpMessageConverter для типа запроса и типа контента [application / x-java-serialized-object]
Ниже приведена моя конфигурация: у меня есть аннотации @EnableIntegration и @IntegrationComponentScan для класса конфигурации бина. Я убедился, что на пути к классу у меня есть банка данных для привязки данных Джексона. Я могу получить правильный ответ, используя POSTMAN.
@Bean
public MessageChannel rtpRequestChannel() {
MessageChannel rtpRequestPostOperationRequestChannel = new DirectChannel();
return rtpRequestPostOperationRequestChannel;
}
@Bean
public MessageChannel rtpResponseChannel() {
MessageChannel rtpRequestPostOperationResponseChannel = new DirectChannel();
return rtpRequestPostOperationResponseChannel;
}
@ServiceActivator(inputChannel = "rtpRequestChannel")
@Bean
public MessageHandler httResponseMessageHandler(MessageChannel rtpResponseChannel) {
HttpRequestExecutingMessageHandler handler = new HttpRequestExecutingMessageHandler(
"http://myhost:8080/services/v1-0/request");
handler.setHttpMethod(HttpMethod.POST);
handler.setOutputChannel(rtpResponseChannel);
handler.setExpectedResponseType(RTPResponse.class);
return handler;
}
Ниже приведен POJO для конечной точки активатора сервиса.
@Service
public class RTPRequestServiceClient implements IRTPRequestServiceClient {
@Override
@ServiceActivator(inputChannel="rtpRequestChannel")
public void makeCall(Message<RtpResponse> pr) {
RtpResponse response = pr.getPayload();
System.out.println(response);
}
Мой запрос POJO:
public class RTPRequest implements Serializable {
private static final long serialVersionUID = 567078627620810886L;
private final String id;
private final String paymentAmountCcy;
private final String paymentAmount;
@JsonCreator
public RTPRequest(@JsonProperty("id") String id,
@JsonProperty("paymentAmountCcy") String paymentAmountCcy,
@JsonProperty("paymentAmount") String paymentAmount) {
this.id = id;
this.paymentAmountCcy = paymentAmountCcy;
this.paymentAmount = paymentAmount;
}
// getters ommited for brevity
}
Мой ответ: POJO:
public class RTPResponse implements Serializable {
/**
*
*/
private static final long serialVersionUID = -3504586520124861349L;
private String id;
private String responseId;
@JsonCreator
public RTPResponse(@JsonProperty("id") String id, @JsonProperty("responseId") String responseId) {
super();
this.id = id;
this.responseId = responseId;
}
// getters ommited for brevity
}
Я отправляю запрос следующим образом:
RTPRequest body = new RTPRequest(....);
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(IntegrationBeanConfiguration.class);
MessageChannel rtpRequestChannel = (MessageChannel) context.getBean("rtpRequestChannel");
rtpRequestChannel
.send(
MessageBuilder.withPayload(body)
.setHeader("accept","application/json")
.setHeader("Sender","API_GATEWAY")
.setHeader("ClientId","DIGITAL")
.build()
);
Я новичок в интеграции Spring http. Я предполагал, что объект RTPRequest будет преобразован в JSON с помощью цепочки преобразователей сообщений по умолчанию HttpRequestExecutingMessageHandler и привязки данных Джексона в classpath.
Пожалуйста, сообщите.