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.