gpt4 book ai didi

java - 通过 Apache Camel 调用 NTLMv2 安全端点

转载 作者:行者123 更新时间:2023-12-02 12:37:25 25 4
gpt4 key购买 nike

我使用的是 Apache Camel 2.19,并且在使用支持 NTLMv1 的camel-http 模块调用我的端点时能够使用 NTLMv1:

from("activemq:{{queue.feedback}}")
.to("http://localhost:8888/ntlm/secured?authMethodPriority=NTLM
&authMethod=NTLM&authUsername=Zaphod
&authPassword=Beeblebrox&authDomain=Minor
&authHost=LightCity")

问题是我不知道如何使用 NTLMv2 发出请求。official documentation指出:

Note: camel-http is based on HttpClient v3.x and as such has only limited support for what is known as NTLMv1, the early version of the NTLM protocol. It does not support NTLMv2 at all. camel-http4 has support for NTLMv2.

当我尝试使用camel-http4时,它什么也没做:

from("activemq:{{queue.feedback}}")
.to("http4://localhost:8888/ntlm/secured?authMethodPriority=NTLM
&authMethod=NTLM&authUsername=Zaphod
&authPassword=Beeblebrox&authDomain=Minor
&authHost=LightCity")

看来camel-http4根本不知道NTLM。我试图调查camel-http4 repo on GitHub除了文档之外,我找不到任何与 NTLM 相关的内容。

关于如何在 Camel 2.19 中使用 NTLMv2(其他版本的 Camel 也可能很合适)有什么想法吗?

最佳答案

问题出在camel-http4组件中。默认情况下,它使用InputStreamEntity,它不是 HttpEntity 实体的可重复实现,这意味着一旦您读取了流,它就会关闭并且您无法再次读取它。这会导致 MainClientExec 失败:

if (execCount > 1 && !RequestEntityProxy.isRepeatable(request)) {
throw new NonRepeatableRequestException("Cannot retry request with a non-repeatable request entity.");
}

这似乎是一个错误,因此解决方法是在发送请求之前将 InputStreamEntity 转换为 ByteArrayEntity(可重复):

@Component
public class NtlmProcessor implements Processor {

@Override
public void process(Exchange exchange) throws Exception {
HttpEntity httpEntity = exchange.getIn().getBody(HttpEntity.class);

byte[] bytes = EntityUtils.toByteArray(httpEntity);

ByteArrayEntity byteArrayEntity = new ByteArrayEntity(bytes, ContentType.get(httpEntity));

exchange.getOut().setBody(byteArrayEntity);
}
}

关于java - 通过 Apache Camel 调用 NTLMv2 安全端点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45082378/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com