Http Outbound Gateway Post с полезной нагрузкой - PullRequest
0 голосов
/ 01 мая 2018

Я использую поток интеграции для отправки запроса POST. Я хотел бы знать, как я могу указать тело запроса?

IntegrationFlow myFlow() {
    return IntegrationFlows.from("requestChannel")
            .handle(Http.outboundGateway(uri)
                    .httpMethod(HttpMethod.POST)
                    .expectedResponseType(String.class)
            )
            .handle("myAssembler", "myFonction")
            .channel("responseChannel")
            .get();
}

1 Ответ

0 голосов
/ 01 мая 2018

Тело запроса в этом случае определяется из сообщения запроса payload:

private HttpEntity<?> generateHttpRequest(Message<?> message, HttpMethod httpMethod) {
    Assert.notNull(message, "message must not be null");
    return (this.extractPayload) ? this.createHttpEntityFromPayload(message, httpMethod)
            : this.createHttpEntityFromMessage(message, httpMethod);
}

Где это createHttpEntityFromPayload() так:

private HttpEntity<?> createHttpEntityFromPayload(Message<?> message, HttpMethod httpMethod) {
    Object payload = message.getPayload();
    if (payload instanceof HttpEntity<?>) {
        // payload is already an HttpEntity, just return it as-is
        return (HttpEntity<?>) payload;
    }
    HttpHeaders httpHeaders = this.mapHeaders(message);
    if (!shouldIncludeRequestBody(httpMethod)) {
        return new HttpEntity<>(httpHeaders);
    }
    // otherwise, we are creating a request with a body and need to deal with the content-type header as well
    if (httpHeaders.getContentType() == null) {
        MediaType contentType = (payload instanceof String)
                ? resolveContentType((String) payload, this.charset)
                : resolveContentType(payload);
        httpHeaders.setContentType(contentType);
    }
    if (MediaType.APPLICATION_FORM_URLENCODED.equals(httpHeaders.getContentType()) ||
            MediaType.MULTIPART_FORM_DATA.equals(httpHeaders.getContentType())) {
        if (!(payload instanceof MultiValueMap)) {
            payload = this.convertToMultiValueMap((Map<?, ?>) payload);
        }
    }
    return new HttpEntity<>(payload, httpHeaders);
}

Это должно дать вам некоторые идеи, какие payload вы можете отправить на requestChannel.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...