即使删除作业,也要删除jenkins作业API时出现以下错误,但没有从resttemplate.exchange处获取响应 org.springframework.web.client.ResourceAccessException:POST请求“ https://XXXXXXX.com/ciname/job/jobname/doDelete”时发生I / O错误:读取超时;嵌套异常是java.net.SocketTimeoutException:读取超时
这仅在远程服务器上发生,并且在本地服务器上工作得很好
我的休息模板 公共类JenkinAuthRestTemplate扩展了RestTemplate {
public JenkinAuthRestTemplate(String password, int readTimeOut, int connectTimeOut) {
addAuthentication(password, readTimeOut, connectTimeOut);
}
private void addAuthentication(String password, int readTimeOut, int connectTimeOut) {
SSLContext sslContext = null;
try {
sslContext = SSLContexts.custom().loadTrustMaterial(null, new TrustSelfSignedStrategy()).build();
} catch (KeyManagementException | NoSuchAlgorithmException | KeyStoreException e) {
e.printStackTrace();
}
SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslContext, new HostnameVerifier() {
@Override
public boolean verify(String hostname, SSLSession session) {
return true;
}
});
HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory();
requestFactory.setConnectTimeout(readTimeOut);
requestFactory.setReadTimeout(connectTimeOut);
requestFactory.setHttpClient(HttpClients.custom().setSSLSocketFactory(sslsf).build());
List<ClientHttpRequestInterceptor> interceptors = Collections
.<ClientHttpRequestInterceptor> singletonList(new BasicAuthorizationInterceptor(password));
setRequestFactory(new InterceptingClientHttpRequestFactory(requestFactory, interceptors));
}
private static class BasicAuthorizationInterceptor implements ClientHttpRequestInterceptor {
private final String password;
public BasicAuthorizationInterceptor(String password) {
this.password = (password == null ? "" : password);
}
@Override
public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution)
throws IOException {
request.getHeaders().add("Authorization", "Basic " + (this.password));
return execution.execute(request, body);
}
}
}
我的deleteJob
JenkinAuthRestTemplate restTemplate = new JenkinAuthRestTemplate( jentoc.getTocken(endpoint,5000,5000);
ResponseEntity response = restTemplate.exchange(endpoint,HttpMethod.POST,null,String.class);
尝试增加超时,但是它们导致400错误的请求错误。一直在努力寻找问题所在。