Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unknown response type exception [INT-4426] #8368

Closed
spring-operator opened this issue Mar 6, 2018 · 2 comments
Closed

Unknown response type exception [INT-4426] #8368

spring-operator opened this issue Mar 6, 2018 · 2 comments
Assignees
Labels
in: http status: declined There won't be a fix for some reason type: bug

Comments

@spring-operator
Copy link
Contributor

Alex Khimach opened INT-4426 and commented

An AbstractHttpRequestExecutingMessageHandler lost build() operation:
In spring-integration-http-5.0.*.RELEASE.jar method:

public class HttpRequestExecutingMessageHandler extends AbstractHttpRequestExecutingMessageHandler {


	@Override
	protected Object handleRequestMessage(Message<?> requestMessage) {
// some code.....
		return exchange(() -> generateUri(requestMessage), httpMethod, httpRequest, expectedResponseType,
				requestMessage);
	}
// some code.....
	@Override
	protected Object exchange(Supplier<URI> uriSupplier, HttpMethod httpMethod, HttpEntity<?> httpRequest,
			Object expectedResponseType, Message<?> requestMessage) {
// some code.....
			return getReply(httpResponse);
// some code.....
	}
// some code.....
}

protected Object getReply(ResponseEntity<?> httpResponse) {
{
// Lost build operation..
    return replyBuilder.copyHeaders(headers);
}

In spring-integration-http-4.2.4.RELEASE.

rotected Object handleRequestMessage(Message<?> requestMessage) {
{
// Old code.....
    return replyBuilder.copyHeaders(headers).build();
}

This cause "Unknown response type exception". result should have "Message" type but it had "MessageBuilder" type:

    public <T> T sendRequest(Object request) throws HttpRequestException {
        Message<Object> message = MessageBuilder.withPayload(request)
                .setHeader(HttpHeaders.CONTENT_TYPE, contentType)
                .build();
        Object result = handleRequestMessage(message);
        if (result instanceof Message) {
            return getResponse(((Message) result).getPayload());
        }
        throw new HttpRequestException("Unknown response type exception");
    }

Affects: 5.0.3

@spring-operator
Copy link
Contributor Author

Artem Bilan commented

You know I can't find that sendRequest() code in the Framework. Looks like your own custom code. And then it isn't clear why just don't check for the AbstractIntegrationMessageBuilder as well and don't call its build() if you need.

The idea behind returning a AbstractIntegrationMessageBuilder now is to pursue some optimization on the AbstractMessageProducingHandler when we build an output message.

This is not a bug on the Framework level and has been done deliberately as a breaking change and that's why it made it into the major project revision - 5.0.

So, if you do your own code like that, very tied to the Framework internal logic, you just need to follow it and handle all the possible cases.
See AbstractMessageProducingHandler for more info:

protected Message<?> createOutputMessage(Object output, MessageHeaders requestHeaders) {
	AbstractIntegrationMessageBuilder<?> builder = null;
	if (output instanceof Message<?>) {
		if (this.noHeadersPropagation || !shouldCopyRequestHeaders()) {
			return (Message<?>) output;
		}
		builder = this.getMessageBuilderFactory().fromMessage((Message<?>) output);
	}
	else if (output instanceof AbstractIntegrationMessageBuilder) {
		builder = (AbstractIntegrationMessageBuilder<?>) output;
	}
	else {
		builder = this.getMessageBuilderFactory().withPayload(output);
	}
	if (!this.noHeadersPropagation && shouldCopyRequestHeaders()) {
		if (this.selectiveHeaderPropagation) {
			Map<String, Object> headersToCopy = new HashMap<>(requestHeaders);
				headersToCopy.entrySet()
					.removeIf(entry -> PatternMatchUtils.simpleMatch(this.notPropagatedHeaders, entry.getKey()));

			builder.copyHeadersIfAbsent(headersToCopy);
		}
		else {
			builder.copyHeadersIfAbsent(requestHeaders);
		}
	}
	return builder.build();
}

Thanks for understanding.

@spring-operator
Copy link
Contributor Author

Alex Khimach commented

Thanks for quick response.
I fixed my code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: http status: declined There won't be a fix for some reason type: bug
Projects
None yet
Development

No branches or pull requests

2 participants