jeudi 26 février 2015

SSL I/O error on GET request, RestTemplate

I'm trying set up ssl between api and applications. I have problem when I'm calling from my application to api, I'm getting error like :



SEVERE: Servlet.service() for servlet [spring] in context with path [/panel] threw exception [Request processing failed; nested exception is org.springframework.web.client.ResourceAccessException: I/O error on GET request for "https://localhost:8442/acquirer/list":Remote host closed connection during handshake; nested exception is javax.net.ssl.SSLHandshakeException: Remote host closed connection during handshake] with root cause java.io.EOFException: SSL peer shut down incorrectly at sun.security.ssl.InputRecord.read(InputRecord.java:482) at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:934)



Im deploying this two applications on two TomcatServers, and i set up server.xml like :



"Connector SSLEnabled="true" clientAuth="true" keystoreFile="/home/user/foobar.jks" keystorePass="foobarpwd" maxThreads="200" port="8442" protocol="HTTP/1.1" scheme="https" secure="true" sslProtocol="TLS" truststoreFile="/home/user/cacerts.jks" truststorePass="cacertspassword" />"



This is my rest client configuration:



@Configuration
@PropertySource("classpath:config/local/general.properties")
public class RestClientConfig {

@Bean
public RestOperations restOperations(
ClientHttpRequestFactory clientHttpRequestFactory) throws Exception {
return new RestTemplate(clientHttpRequestFactory);
}

@Bean
public ClientHttpRequestFactory clientHttpRequestFactory(
HttpClient httpClient) {
return new HttpComponentsClientHttpRequestFactory(httpClient);
}

@Bean
public HttpClient httpClient(@Value("${general.file}") String file,
@Value("${general.pass}") String password) throws Exception {
KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
FileInputStream instream = new FileInputStream(new File(file));
try {
trustStore.load(instream, password.toCharArray());
} finally {
instream.close();
}

SSLContext sslcontext = SSLContexts.custom()
.loadTrustMaterial(trustStore, new TrustSelfSignedStrategy())
.build();
SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(
sslcontext, new String[] { "TLSv1.2" }, null,
BROWSER_COMPATIBLE_HOSTNAME_VERIFIER);
return HttpClients.custom().setSSLSocketFactory(sslsf).build();
}

@Bean
public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() {
return new PropertySourcesPlaceholderConfigurer();
}
}


And my application controller:



@Autowired
private RestOperations rest;

@PostAuthorize("hasRole('aml_list')")
@RequestMapping(value = "/stoplist/list", method = RequestMethod.GET)
public String list(Model model, RedirectAttributes redirectAttributes) {

/* RestTemplate restTemplate = new RestTemplate();*/
ResponseEntity<StopList[]> responseStopList = rest
.getForEntity(url+GET_STOPLISTS, StopList[].class);
List<StopList> stopLists = Arrays.asList(responseStopList.getBody());
model.addAttribute("stopLists", stopLists);
model.addAttribute("statuses", stopListStatusService.getStatuses());
return "stoplist/list";
}


Someone can help me ? How to fix it ? and How can I send certificate with http request?


Aucun commentaire:

Enregistrer un commentaire