我正在使用setErrText(getString(R.string.your_err_txt),yourEdt);
向本地服务发出POST请求。
服务如下: -
HttpRequestExecutingMessageHandler
用户类是: -
@RestController
@RequestMapping("/accountbalance")
public class AccountBalanceController {
@Autowired
private AccountBalanceDetailsRepo accountBalanceDetailsRepo;
@RequestMapping(method = RequestMethod.POST, path = "/exp")
public List<AccountBalanceDetails> getAccounts(@RequestBody User name) {
System.out.println(">>>>>>>>>>> " + name);
return accountBalanceDetailsRepo.findAll();
}
}
spring integration config是:
public class User implements Serializable {
private String name;
private Integer age;
//getters and setters
}
在主课程中,我向@Bean
public HttpRequestExecutingMessageHandler httpOutBound(@Qualifier("httpOutChannel") DirectChannel outputChannel) {
HttpRequestExecutingMessageHandler httpRequestExecutingMessageHandler = new
HttpRequestExecutingMessageHandler("http://localhost:8080/accountbalance/exp");
httpRequestExecutingMessageHandler.setHttpMethod(HttpMethod.POST);
httpRequestExecutingMessageHandler.setExpectedResponseType(ArrayList.class);
httpRequestExecutingMessageHandler.setMessageConverters(Arrays.asList(new SerializingHttpMessageConverter()));
httpRequestExecutingMessageHandler.setOutputChannel(outputChannel);
return httpRequestExecutingMessageHandler;
}
@Bean
public IntegrationFlow httpFlow(@Qualifier("httpReqChannel") DirectChannel directChannel,
HttpRequestExecutingMessageHandler messageHandler) {
return IntegrationFlows.from(directChannel).handle(messageHandler).get();
}
@Bean
public DirectChannel httpReqChannel() {
return new DirectChannel();
}
@Bean
public DirectChannel httpOutChannel() {
return new DirectChannel();
}
@Bean
public IntegrationFlow httpOutFlow(@Qualifier("httpOutChannel") DirectChannel directChannel) {
return IntegrationFlows.from(directChannel).handle(msg -> System.out.println(">>>>> "+ msg)).get();
}
频道发送消息,如下所示: -
httpReqChannel
我收到以下异常: -
User user = new User();
user.setAge(29);
user.setName("Amar");
directChannel.send(MessageBuilder.withPayload(user).build())
我在这里做错了什么???
答案 0 :(得分:1)
如果您谈论JSON,请考虑添加适当的转换器,但不仅如此:
httpRequestExecutingMessageHandler.setMessageConverters(Arrays.asList(new SerializingHttpMessageConverter()
或者,老实说,只是不要覆盖默认设置。只需使用适当的content-type
标题。