Received fatal Alert: handshake_failure when class is run by Schedule - JDK7

Asked

Viewed 362 times

2

I have a class that integrates with Woocommerce, when I run the class when I raise the project not httpCliente error ( 4.5.3) I get Httpresponse 200 ok, I have two registered api,

https://www.ssllabs.com/ssltest/analyze.html?d=antioquiabooks.com and 2° https://www.ssllabs.com/ssltest/analyze.html?d=cafearabesco.com

both have the same TLS and cipherSuites that is acceptable, but when Schedule runs the second integration api of the handshake_failure error, I’ve tried every way I’ve looked at stackoverflow and the Oracle website.

My socket code.

         builder = new SSLContextBuilder();
         builder.loadTrustMaterial(null, new TrustSelfSignedStrategy());

         SSLConnectionSocketFactory sslConnectionSocketFactory = new SSLConnectionSocketFactory(builder.build(),new String[] {"TLSv1","TLSv1.1","TLSv1.2"},
                 null,NoopHostnameVerifier.INSTANCE); // EVITAR 
            // com cipherSuites da o mesmo erro

         Registry<ConnectionSocketFactory> registry = RegistryBuilder.<ConnectionSocketFactory>create()
                    .register("http", new PlainConnectionSocketFactory())
                    .register("https", sslConnectionSocketFactory)
                    .build();

         PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager(registry);
         cm.setMaxTotal(100);
         this.httpClient = HttpClients.custom()
                    .setSSLSocketFactory(sslConnectionSocketFactory)
                    .setConnectionManager(cm)
                    .build();

        this.mapper = new ObjectMapper();

The mistake happens when I get to that part

try {
            HttpHost https = new HttpHost(httpHost.replace("https://", ""), 443, "https");//host e numero da porta https

            HttpResponse httpResponse = httpClient.execute(https, httpRequest); // AQUI

When executed by Schedule at the specified time

<bean id="cronSincronizarPedidoApi" class="org.springframework.scheduling.quartz.CronTriggerBean">
    <property name="jobDetail" ref="sincronizarPedido" />
    <property name="cronExpression" value="0 56 6-20/2 * * ?" /><!-- Programado para cada 2h entre 6h e 20h-->
</bean>

Note: I tried to replace JCE but it didn’t work either ,

With JDK8 solves the error but and a large ERP system can not change the version of java use JDK7.

I also don’t know if when running Schedule compiles only class data, not going up files needed when going up "Run project" .

LOGS

java.lang.RuntimeException: javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure
at br.com.erp.web.rest.woocommerce.DefaultHttpClient.getEntityAndReleaseConnection(DefaultHttpClient.java:183)
at br.com.erp.web.rest.woocommerce.DefaultHttpClient.getAll(DefaultHttpClient.java:100)
at br.com.erp.web.rest.woocommerce.WooCommerceAPI.allProduct(WooCommerceAPI.java:63)
at br.com.erp.web.rest.woocommerce.WooCommerceAPI.getAll(WooCommerceAPI.java:50)
at br.com.controlese.schedule.ScheduleSincronizarPedidoVenda.sincronizarPedido(ScheduleSincronizarPedidoVenda.java:120)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.springframework.util.MethodInvoker.invoke(MethodInvoker.java:269)
at org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean$MethodInvokingJob.executeInternal(MethodInvokingJobDetailFactoryBean.java:272)
at org.springframework.scheduling.quartz.QuartzJobBean.execute(QuartzJobBean.java:86)
at org.quartz.core.JobRunShell.run(JobRunShell.java:216)
at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:549)


Caused by: javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure
at sun.security.ssl.Alerts.getSSLException(Alerts.java:192)
at sun.security.ssl.Alerts.getSSLException(Alerts.java:154)
at sun.security.ssl.SSLSocketImpl.recvAlert(SSLSocketImpl.java:1977)
at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:1093)
at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1328)
at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1355)
at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1339)
at org.apache.http.conn.ssl.SSLConnectionSocketFactory.createLayeredSocket(SSLConnectionSocketFactory.java:396)
at org.apache.http.conn.ssl.SSLConnectionSocketFactory.connectSocket(SSLConnectionSocketFactory.java:355)
at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:142)
at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:359)
at org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:381)
at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:237)
at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:185)
at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:89)
at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:111)
at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:185)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:118)
at br.com.erp.web.rest.woocommerce.DefaultHttpClient.getEntityAndReleaseConnection(DefaultHttpClient.java:172)
... 13 more
  • Well my solution was using the protocol Cipher Suites "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA" and in my class Runschedulesonstartup that this config for when I climb the project run the Schedule and outside the given time, i decoded my Schedule because it was only scheduled to run at the given time and climb together the java running , the Schedule and do not know why not more but the handshake_failure error for the given site

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.