java - Spring - RestTemplate Error calling a https rest service (Certificate error) -
i call in tomcat war rest web service. web service invocation this:
public usuariodto validardatostoken(string token, boolean incluirroles) throws modeloexception, daoexception { resttemplate resttemplate = new resttemplate(); userrestvo page = resttemplate.getforobject("https://xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"), userrestvo.class); if (page != null && page.getstatusresult() != null && page.getstatusresult().getstatuscode().equals("ok") && page.getuser() != null) { ------------ return datos; } else { throw new modeloexception(erroresgeneralesenum.error_token_caducado); } } } public authentication authenticatereal(authentication authentication) throws authenticationexception { string username = authentication.getname(); string password = (string) authentication.getcredentials(); usuariodto usuario = null; try { usuario = usuariosservice.validardatostoken(username, true); } catch (exception e) { e.printstacktrace(); logger.getlogger(customauthenticationprovider.class.getname()).error(e); throw new badcredentialsexception("username not found."); } }
the following error produced when web service called. try lot of things notting works:
i think problem certificate dont solve it. ¿do have idea?
org.springframework.web.client.resourceaccessexception: i/o error on request "https://xxxxxxxxxxxxxxxxxxxxxxxx":java.security.nosuchalgorithmexception: error constructing implementation (algorithm: default, provider: sunjsse, class: sun.security.ssl.sslcontextimpl$defaultsslcontext); nested exception java.net.socketexception: java.security.nosuchalgorithmexception: error constructing implementation (algorithm: default, provider: sunjsse, class: sun.security.ssl.sslcontextimpl$defaultsslcontext) @ org.springframework.web.client.resttemplate.doexecute(resttemplate.java:567) @ org.springframework.web.client.resttemplate.execute(resttemplate.java:512) @ org.springframework.web.client.resttemplate.getforobject(resttemplate.java:243) @ custom.service.usuarios.impl.usuariosserviceimpl.validardatostoken(usuariosserviceimpl.java:69) @ sun.reflect.nativemethodaccessorimpl.invoke0(native method) @ sun.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl.java:57) @ sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl.java:43) @ java.lang.reflect.method.invoke(method.java:606) @ org.springframework.aop.support.aoputils.invokejoinpointusingreflection(aoputils.java:317) @ org.springframework.aop.framework.reflectivemethodinvocation.invokejoinpoint(reflectivemethodinvocation.java:190) @ org.springframework.aop.framework.reflectivemethodinvocation.proceed(reflectivemethodinvocation.java:157) @ org.springframework.transaction.interceptor.transactioninterceptor$1.proceedwithinvocation(transactioninterceptor.java:98) @ org.springframework.transaction.interceptor.transactionaspectsupport.invokewithintransaction(transactionaspectsupport.java:262) @ org.springframework.transaction.interceptor.transactioninterceptor.invoke(transactioninterceptor.java:95) @ org.springframework.aop.framework.reflectivemethodinvocation.proceed(reflectivemethodinvocation.java:179) @ org.springframework.aop.framework.jdkdynamicaopproxy.invoke(jdkdynamicaopproxy.java:207) @ com.sun.proxy.$proxy33.validardatostoken(unknown source) @ custom.view.filter.customauthenticationprovider.authenticatereal(customauthenticationprovider.java:48) @ custom.view.filter.customauthenticationprovider.authenticate(customauthenticationprovider.java:37) @ org.springframework.security.authentication.providermanager.authenticate(providermanager.java:156) @ custom.view.filter.usernamepasswordauthenticationfilter.attemptauthentication(usernamepasswordauthenticationfilter.java:103) @ org.springframework.security.web.authentication.abstractauthenticationprocessingfilter.dofilter(abstractauthenticationprocessingfilter.java:211) @ org.springframework.security.web.filterchainproxy$virtualfilterchain.dofilter(filterchainproxy.java:342) @ org.springframework.security.web.authentication.logout.logoutfilter.dofilter(logoutfilter.java:110) @ org.springframework.security.web.filterchainproxy$virtualfilterchain.dofilter(filterchainproxy.java:342) @ org.springframework.security.web.context.request.async.webasyncmanagerintegrationfilter.dofilterinternal(webasyncmanagerintegrationfilter.java:50) @ org.springframework.web.filter.onceperrequestfilter.dofilter(onceperrequestfilter.java:107) @ org.springframework.security.web.filterchainproxy$virtualfilterchain.dofilter(filterchainproxy.java:342) @ org.springframework.security.web.context.securitycontextpersistencefilter.dofilter(securitycontextpersistencefilter.java:87) @ org.springframework.security.web.filterchainproxy$virtualfilterchain.dofilter(filterchainproxy.java:342) @ org.springframework.security.web.filterchainproxy.dofilterinternal(filterchainproxy.java:192) @ org.springframework.security.web.filterchainproxy.dofilter(filterchainproxy.java:160) @ org.springframework.web.filter.delegatingfilterproxy.invokedelegate(delegatingfilterproxy.java:344) @ org.springframework.web.filter.delegatingfilterproxy.dofilter(delegatingfilterproxy.java:261) @ org.apache.catalina.core.applicationfilterchain.internaldofilter(applicationfilterchain.java:243) @ org.apache.catalina.core.applicationfilterchain.dofilter(applicationfilterchain.java:210) @ org.apache.catalina.core.standardwrappervalve.invoke(standardwrappervalve.java:225) @ org.apache.catalina.core.standardcontextvalve.invoke(standardcontextvalve.java:123) @ org.apache.catalina.authenticator.authenticatorbase.invoke(authenticatorbase.java:472) @ org.apache.catalina.core.standardhostvalve.invoke(standardhostvalve.java:168) @ org.apache.catalina.valves.errorreportvalve.invoke(errorreportvalve.java:98) @ org.apache.catalina.valves.accesslogvalve.invoke(accesslogvalve.java:927) @ org.apache.catalina.core.standardenginevalve.invoke(standardenginevalve.java:118) @ org.apache.catalina.connector.coyoteadapter.service(coyoteadapter.java:407) @ org.apache.coyote.http11.abstracthttp11processor.process(abstracthttp11processor.java:1002) @ org.apache.coyote.abstractprotocol$abstractconnectionhandler.process(abstractprotocol.java:579) @ org.apache.tomcat.util.net.jioendpoint$socketprocessor.run(jioendpoint.java:312) @ java.util.concurrent.threadpoolexecutor.runworker(threadpoolexecutor.java:1145) @ java.util.concurrent.threadpoolexecutor$worker.run(threadpoolexecutor.java:615) @ java.lang.thread.run(thread.java:745) caused by: java.net.socketexception: java.security.nosuchalgorithmexception: error constructing implementation (algorithm: default, provider: sunjsse, class: sun.security.ssl.sslcontextimpl$defaultsslcontext) @ javax.net.ssl.defaultsslsocketfactory.throwexception(sslsocketfactory.java:198) @ javax.net.ssl.defaultsslsocketfactory.createsocket(sslsocketfactory.java:205) @ sun.net.www.protocol.https.httpsclient.createsocket(httpsclient.java:409) @ sun.net.networkclient.doconnect(networkclient.java:162) @ sun.net.www.http.httpclient.openserver(httpclient.java:432) @ sun.net.www.http.httpclient.openserver(httpclient.java:527) @ sun.net.www.protocol.https.httpsclient.(httpsclient.java:275) @ sun.net.www.protocol.https.httpsclient.new(httpsclient.java:371) @ sun.net.www.protocol.https.abstractdelegatehttpsurlconnection.getnewhttpclient(abstractdelegatehttpsurlconnection.java:191) @ sun.net.www.protocol.http.httpurlconnection.plainconnect(httpurlconnection.java:932) @ sun.net.www.protocol.https.abstractdelegatehttpsurlconnection.connect(abstractdelegatehttpsurlconnection.java:177) @ sun.net.www.protocol.https.httpsurlconnectionimpl.connect(httpsurlconnectionimpl.java:153) @ org.springframework.http.client.simplebufferingclienthttprequest.executeinternal(simplebufferingclienthttprequest.java:75) @ org.springframework.http.client.abstractbufferingclienthttprequest.executeinternal(abstractbufferingclienthttprequest.java:48) @ org.springframework.http.client.abstractclienthttprequest.execute(abstractclienthttprequest.java:53) @ org.springframework.web.client.resttemplate.doexecute(resttemplate.java:551) caused by: java.io.ioexception: invalid keystore format @ sun.security.provider.javakeystore.engineload(javakeystore.java:650) @ sun.security.provider.javakeystore$jks.engineload(javakeystore.java:55) @ java.security.keystore.load(keystore.java:1214) @ sun.security.ssl.trustmanagerfactoryimpl.getcacertskeystore(trustmanagerfactoryimpl.java:221) @ sun.security.ssl.sslcontextimpl$defaultsslcontext.getdefaulttrustmanager(sslcontextimpl.java:528) @ sun.security.ssl.sslcontextimpl$defaultsslcontext.(sslcontextimpl.java:495) @ sun.reflect.nativeconstructoraccessorimpl.newinstance0(native method) @ sun.reflect.nativeconstructoraccessorimpl.newinstance(nativeconstructoraccessorimpl.java:57) @ sun.reflect.delegatingconstructoraccessorimpl.newinstance(delegatingconstructoraccessorimpl.java:45) @ java.lang.reflect.constructor.newinstance(constructor.java:526) @ java.security.provider$service.newinstance(provider.java:1240) ... 64 more
from code dont see specific ssl configuration resttemplate. since dont know version of spring (and related httpclient), suggest try starting following code , see happens:
public void tryme() throws clientprotocolexception, ioexception { string urloverhttps = "https:xxxxxxx"; closeablehttpclient httpclient = httpclients.custom() .setsslhostnameverifier(new noophostnameverifier()) .build(); httpcomponentsclienthttprequestfactory reqfactory = new httpcomponentsclienthttprequestfactory(); reqfactory.sethttpclient(httpclient); responseentity<string> response = new resttemplate(reqfactory).exchange( urloverhttps, httpmethod.get, null, string.class); string responsecode = response.getstatuscode(); }
this should in theory bypass certs check. requires httpclient 4.4. said, dont expose many details of current configuration can wild guess here.
Comments
Post a Comment