0
import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.api.client.WebResource;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.json.JSONObject;

import java.io.IOException;

import static com.oxdeo.serviceclient.constants.*;

public class TokenService {
    protected final Log logger = LogFactory.getLog(TokenService.class);
    private static String bodyStr = "grant_type=client_credentials&client_id=" + coreClientId + "&client_secret=" + coreClientSecret;

    private Client jerseyClient = new Client();

    public String getToken() {
        WebResource webResource = jerseyClient.resource(coreTokenURL);
        ClientResponse clientResponse = webResource.type("application/x-www-form-urlencoded").post(ClientResponse.class, bodyStr);
        logger.info("client response  token: " + clientResponse.getStatus());
        String token = null;
        if (clientResponse.getStatus() == 200) {
            token = parseToken(clientResponse);
        } else {
            logger.error("Unable to get  token. response:" + clientResponse.getStatus());
        }
        return token;
    }

    private String parseToken(ClientResponse clientResponse) {
        String accessToken="";
        String responseStr = clientResponse.getEntity(String.class);
        JSONObject jsonResponse = new JSONObject(responseStr);
        if(clientResponse.getStatus() >=200 && clientResponse.getStatus()  <=204) {
             accessToken = jsonResponse.getString("access_token");
        }
        return accessToken;
    }

}

In the above code I running the local server on Java 1.6 and calling a API to get the token but I am getting the error like:

javax.net.ssl.SSLPeerUnverifiedException peer not authenticated

The API which I am calling may running on Java 8 OR 11, but If I run this code with Java 8 I am able to get the response. What do I need to change here or any configuration to make to return response with Java 6? I tested with the Apache library also but getting the same error with all.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
ANJ
  • 1
  • 1
  • Seems to be a SSL handshaking issue. You might not have the server signing certificate in your Java 6 installation, but it might be included in later Java versions (by default?). It might also depend on if the server certificate is self signed or not. Importing the certificates might do the trick. And then of course the obvious: Java 6 has gone end of life/end of support a long time ago. Don't trust it to run your server applications. – DanielBarbarian Jun 28 '23 at 10:55
  • From this answer, it may work with `6.91 version of JDK` : https://stackoverflow.com/a/32220941/1075282 – Renat Jun 28 '23 at 10:55
  • You might just try `-Djavax.net.ssl.trustStore=` (Usually `$JAVA_HOME/lib/security/jssecacerts` or `$JAVA_HOME/lib/security/cacerts`) Hacky but might work for testing – g00se Jun 28 '23 at 13:48

0 Answers0