Skip to Content

Peer not authenticated exception when connecting SAP Cloud Platform to Office 365 API

I'm implementing an SAP Cloud Platform Java application to connect to the Office 365 API ( using OAuth2 authentication.

When I running it on Apache Tomcat local server I get the response from the server correctly.

When I run the same code on SAP Cloud Platform I get peer not authenticated|

In both cases I get the correct OAuth token.

What am I missing here? The code I'm using is:

privateObject getResponseFromAzure(String url,String methodType){AuthenticationResult result =null;try{
        result = getAccessTokenFromUserCredentials();// OAuth2 bearer token}catch(Exception e1){// TODO Auto-generated catch block
        e1.printStackTrace();}String accessToken = result.getAccessToken();System.out.println("Access Token is - "+ accessToken);HttpClient client =newDefaultHttpClient();HttpRequestBase request =null;if("GET".equals(methodType)){
        request =newHttpGet(url);}elseif("POST".equals(methodType)){
        request =newHttpPost(url);}

    request.addHeader("Authorization","Bearer "+ accessToken);HttpResponse response =null;try{
        response = client.execute(request);}catch(ClientProtocolException e){// TODO Auto-generated catch block
        e.printStackTrace();}catch(IOException e){// TODO Auto-generated catch block
Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

0 Answers