首页 > 解决方案 > 在 apache camel 中禁用自动重定向

问题描述

我试图在骆驼中禁用 HTTP 自动重定向,我在 SpringRouteBuilder 中实现了以下代码,问题是当我永久移动 HTTP/1.1 301 时,它会自动重定向。下面我添加了片段,请让我知道如何继续。

  onException(HttpOperationFailedException.class).process(exchange -> {
        final Exception t = exchange.getProperty(Exchange.EXCEPTION_CAUGHT, Exception.class);
        if (t instanceof HttpOperationFailedException) {

            LOGGER.error("HttpOperationFailedException Problem::::{}",
                    ToStringBuilder.reflectionToString(t, ToStringStyle.DEFAULT_STYLE));
        }
    });
 from(SOURCE_URI).log(LoggingLevel.INFO, "[Service Route:][Request log:] ${body}").routeId(ROUTE_ID)
            .setHeader(Exchange.HTTP_METHOD, Builder.constant("GET")).process(exchange -> {
                exchange.getIn().setBody(EMPTY_REQUEST);
            }).streamCaching().recipientList(header("PartnerUrl"));
}

在下面的文档中提到http://camel.apache.org/http4 响应代码在 300..399 范围内,Camel 将其视为重定向响应,并将抛出带有信息的 HttpOperationFailedException。我期待这个异常,但没有发生异常并被重定向。

标签: apache-camel

解决方案


推荐阅读