任何人都可以有一个用于Rest Template的NTLM身份验证示例,或者请让我知道做错了什么?
String[] args ={"username",password","HOST", "DOMAIN"};
restTemplate.setRequestFactory(buildHttpComponentsClientHttpRequestFactory(args));
responseFromCRM = restTemplate.postForObject(crmUserCreateUrl, customerUserProfile, CustomerUserProfile.class);
private static HttpComponentsClientHttpRequestFactory buildHttpComponentsClientHttpRequestFactory(String[] args) {
PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager();
cm.setMaxTotal(128);
cm.setDefaultMaxPerRoute(24);
RequestConfig.Builder requestBuilder = RequestConfig.custom().setConnectTimeout(5000).setSocketTimeout(10000);
Registry<AuthSchemeProvider> authSchemeRegistry = RegistryBuilder.<AuthSchemeProvider> create().register(AuthSchemes.NTLM, new NTLMSchemeFactory())
.register(AuthSchemes.SPNEGO, new SPNegoSchemeFactory()).build();
CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
credentialsProvider.setCredentials(AuthScope.ANY, new NTCredentials(args[0], args[1], args[2], args[3]));
HttpClientBuilder builder = HttpClientBuilder.create().setConnectionManager(cm).setDefaultRequestConfig(requestBuilder.build())
.setDefaultAuthSchemeRegistry(authSchemeRegistry).setDefaultCredentialsProvider(credentialsProvider);
return new HttpComponentsClientHttpRequestFactory(builder.build());
}
我跑步时收到以下错误消息
INFO | jvm 1 |主| 2018/12/04 14:55:31.456 | org.springframework.web.util.NestedServletException:处理程序派发失败;嵌套的异常是java.lang.LinkageError:违反加载器约束:解决方法“ org.springframework.http.client.HttpComponentsClientHttpRequestFactory。(Lorg / apache / http / client / HttpClient;)V”时,类加载器(de / hybris的实例)当前类的uk / co / frw / storefront / controllers / pages / AbstractRegisterPageController的/ tomcat / HybrisWebappLoader $ HybrisWebappClassLoader)和方法的定义类org的类加载器(de / hybris / bootstrap / loader / PlatformInPlaceClassLoader的实例) / springframework / http / client / HttpComponentsClientHttpRequestFactory,对于签名中使用的org / apache / http / client / HttpClient类型具有不同的Class对象