Pessoal, estou tendo o seguinte problema ao consumir um webservice do gerenciaNet.
Alguém tem ideia do que seja?
package br.comgerencianet;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.URL;
import java.util.Base64;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLSocketFactory;
public class Auth {
public static void main(String[] args) throws Exception {
String client_id = "CÓDIGO AQUI";
String client_secret = "CÓDIGO AQUI";;
String basicAuth = Base64.getEncoder().encodeToString(((client_id+':'+client_secret).getBytes()));
System.setProperty("javax.net.ssl.keyStore", "\r\n"
+ "C:\\Users\\cleit\\OneDrive\\Área de Trabalho\\Cleiton Conceição\\homologacao-273143-ATIVO.p12");
SSLSocketFactory sslsocketfactory = (SSLSocketFactory) SSLSocketFactory.getDefault();
URL url = new URL ("https://sandbox.gerencianet.com.br/v1/authorize"); //Para ambiente de Desenvolvimento
HttpsURLConnection conn = (HttpsURLConnection)url.openConnection();
conn.setDoOutput(true);
conn.setRequestMethod("POST");
conn.setRequestProperty("Content-Type", "application/json");
conn.setRequestProperty("Authorization", "Basic "+ basicAuth);
conn.setSSLSocketFactory(sslsocketfactory);
String input = "{\"grant_type\": \"client_credentials\"}";
OutputStream os = conn.getOutputStream();
os.write(input.getBytes());
os.flush();
InputStreamReader reader = new InputStreamReader(conn.getInputStream());
BufferedReader br = new BufferedReader(reader);
String response;
while ((response = br.readLine()) != null) {
System.out.println(response);
}
conn.disconnect();
}
}
Exception in thread "main" java.net.SocketException: java.security.NoSuchAlgorithmException: Error constructing implementation (algorithm: Default, provider: SunJSSE, class: sun.security.ssl.SSLContextImpl$DefaultSSLContext)
at java.base/javax.net.ssl.DefaultSSLSocketFactory.throwException(SSLSocketFactory.java:267)
at java.base/javax.net.ssl.DefaultSSLSocketFactory.createSocket(SSLSocketFactory.java:274)
at java.base/sun.net.www.protocol.https.HttpsClient.createSocket(HttpsClient.java:422)
at java.base/sun.net.NetworkClient.doConnect(NetworkClient.java:163)
at java.base/sun.net.www.http.HttpClient.openServer(HttpClient.java:531)
at java.base/sun.net.www.http.HttpClient.openServer(HttpClient.java:636)
at java.base/sun.net.www.protocol.https.HttpsClient.<init>(HttpsClient.java:266)
at java.base/sun.net.www.protocol.https.HttpsClient.New(HttpsClient.java:380)
at java.base/sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.getNewHttpClient(AbstractDelegateHttpsURLConnection.java:193)
at java.base/sun.net.www.protocol.http.HttpURLConnection.plainConnect0(HttpURLConnection.java:1242)
at java.base/sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:1128)
at java.base/sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:179)
at java.base/sun.net.www.protocol.http.HttpURLConnection.getOutputStream0(HttpURLConnection.java:1430)
at java.base/sun.net.www.protocol.http.HttpURLConnection.getOutputStream(HttpURLConnection.java:1401)
at java.base/sun.net.www.protocol.https.HttpsURLConnectionImpl.getOutputStream(HttpsURLConnectionImpl.java:220)
at GerenciaNet/br.comgerencianet.Auth.main(Auth.java:32)
Caused by: java.security.NoSuchAlgorithmException: Error constructing implementation (algorithm: Default, provider: SunJSSE, class: sun.security.ssl.SSLContextImpl$DefaultSSLContext)
at java.base/java.security.Provider$Service.newInstance(Provider.java:1868)
at java.base/sun.security.jca.GetInstance.getInstance(GetInstance.java:236)
at java.base/sun.security.jca.GetInstance.getInstance(GetInstance.java:164)
at java.base/javax.net.ssl.SSLContext.getInstance(SSLContext.java:185)
at java.base/javax.net.ssl.SSLContext.getDefault(SSLContext.java:110)
at java.base/javax.net.ssl.SSLSocketFactory.getDefault(SSLSocketFactory.java:83)
at GerenciaNet/br.comgerencianet.Auth.main(Auth.java:21)
Caused by: java.security.KeyManagementException
at java.base/sun.security.ssl.SSLContextImpl$DefaultManagersHolder.<clinit>(SSLContextImpl.java:942)
at java.base/sun.security.ssl.SSLContextImpl$DefaultSSLContext.<init>(SSLContextImpl.java:1111)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499)
at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:480)
at java.base/java.security.Provider$Service.newInstanceOf(Provider.java:1879)
at java.base/java.security.Provider$Service.newInstanceUtil(Provider.java:1886)
at java.base/java.security.Provider$Service.newInstance(Provider.java:1861)
... 6 more
Nessa parte:
System.setProperty("javax.net.ssl.keyStore", "\r\n"
+ "C:\\Users\\cleit\\OneDrive\\Área de Trabalho\\Cleiton Conceição\\homologacao-273143-ATIVO.p12");
Esse \r\n
é necessário mesmo? Acho que seria só assim:
System.setProperty("javax.net.ssl.keyStore", "C:\\Users\\cleit\\OneDrive\\Área de Trabalho\\Cleiton Conceição\\homologacao-273143-ATIVO.p12");
Possivelmente não seja a causa do erro, mas vai que é neh.
2 curtidas
putz, foi isso mesmo!
obrigado!
kkkkkk