0

我正在实施一个 SAP Cloud Platform Java 应用程序以使用 OAuth2 身份验证连接到 Office 365 API ( https://outlook.office.com/ )。当我在 Apache Tomcat 本地服务器上运行它时,我正确地得到了服务器的响应。当我在 SAP Cloud Platform 上运行相同的代码时,我得到 javax.net.ssl.SSLPeerUnverifiedException: peer not authenticated| 在这两种情况下,我都得到了正确的 OAuth 令牌。我在这里想念什么?我正在使用的代码是:

private Object 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 = new DefaultHttpClient();

    HttpRequestBase request = null;
    if ("GET".equals(methodType)) {
        request = new HttpGet(url);
    } else if ("POST".equals(methodType)) {
        request = new HttpPost(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
        e.printStackTrace();
    }
4

1 回答 1

0

在 SCP 中创建一个目的地。在目标服务中上传根证书和中间证书。这是用户界面的一部分。

使用目标而不是直接连接从您的 java 应用程序连接。示例代码位于https://help.sap.com/viewer/cca91383641e40ffbe03bdc78f00f681/Cloud/en-US/e592cf6cbb57101495d3c28507d20f1b.html

于 2017-08-18T07:03:51.227 回答