前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >使用java代码连接ABAP Netweaver系统

使用java代码连接ABAP Netweaver系统

作者头像
Jerry Wang
发布2019-07-01 11:21:06
7400
发布2019-07-01 11:21:06
举报

2014-11-22

代码语言:javascript
复制
package com.sap.test;

import java.io.FileNotFoundException;
import java.io.IOException;
import org.apache.commons.codec.binary.Base64;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.mime.HttpMultipartMode;
import org.apache.http.entity.mime.MultipartEntityBuilder;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;
@SuppressWarnings("deprecation")
public class test
{
     final private static String POST_PREFIX = "https://ldai2ag3.wdf.sap.corp:44356/sap/crm/zajax?sap-client=001&query=";
     private static String getRequestURL(String str) {
     String url = POST_PREFIX + str;
      url = url + "&sid=" + Math.random();
     return url;
     }
     private static void sendHTTPPostRequest(String str) throws FileNotFoundException {
          HttpClient httpclient = new DefaultHttpClient();
          String raw = "WANGJER:Saptest1";
          String encoded = Base64.encodeBase64String(raw.getBytes());
          HttpPost httppost = new HttpPost(getRequestURL(str));
          MultipartEntityBuilder builder = MultipartEntityBuilder.create();
          builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);

          builder.addTextBody("firstName", "Jerry");
          builder.addTextBody("lastName", "Wang");
          try {
                    httppost.addHeader("Content-Type","multipart/form-data; boundary=assdsfdffafasf");
                    httppost.addHeader("User-Agent","Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)");
                    httppost.addHeader("Authorization", "Basic " + encoded);

                    HttpResponse httpresponse = httpclient.execute(httppost);
                    HttpEntity resEntity = httpresponse.getEntity();
                    String response = EntityUtils.toString(resEntity);
                    System.out.println(response);
            }
            catch (IOException e) {
                    System.out.println(e.getLocalizedMessage());
                    e.printStackTrace();
                    System.out.println("error!");
                    }
              }
       public static void main(String[] args) throws ClientProtocolException, IOException {
              sendHTTPPostRequest("a");
       }
}

错误callstack 如下:

sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target at sun.security.ssl.Alerts.getSSLException(Unknown Source) at sun.security.ssl.SSLSocketImpl.fatal(Unknown Source) at sun.security.ssl.Handshaker.fatalSE(Unknown Source) at sun.security.ssl.Handshaker.fatalSE(Unknown Source) at sun.security.ssl.ClientHandshaker.serverCertificate(Unknown Source) at sun.security.ssl.ClientHandshaker.processMessage(Unknown Source) at sun.security.ssl.Handshaker.processLoop(Unknown Source) at sun.security.ssl.Handshaker.process_record(Unknown Source) at sun.security.ssl.SSLSocketImpl.readRecord(Unknown Source) at sun.security.ssl.SSLSocketImpl.performInitialHandshake(Unknown Source) at sun.security.ssl.SSLSocketImpl.startHandshake(Unknown Source) at sun.security.ssl.SSLSocketImpl.startHandshake(Unknown Source) at org.apache.http.conn.ssl.SSLSocketFactory.connectSocket(SSLSocketFactory.java:535) at org.apache.http.conn.ssl.SSLSocketFactory.connectSocket(SSLSocketFactory.java:403) at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:177) at org.apache.http.impl.conn.ManagedClientConnectionImpl.open(ManagedClientConnectionImpl.java:304) at org.apache.http.impl.client.DefaultRequestDirector.tryConnect(DefaultRequestDirector.java:611) at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:446) at org.apache.http.impl.client.AbstractHttpClient.doExecute(AbstractHttpClient.java:863) at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:82) at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:106) at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:57) at multipleForm.sendHTTPPostRequest(multipleForm.java:95) at multipleForm.main(multipleForm.java:110) Caused by: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target at sun.security.validator.PKIXValidator.doBuild(Unknown Source) at sun.security.validator.PKIXValidator.engineValidate(Unknown Source) at sun.security.validator.Validator.validate(Unknown Source) at sun.security.ssl.X509TrustManagerImpl.validate(Unknown Source) at sun.security.ssl.X509TrustManagerImpl.checkTrusted(Unknown Source) at sun.security.ssl.X509TrustManagerImpl.checkServerTrusted(Unknown Source) … 20 more Caused by: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target at sun.security.provider.certpath.SunCertPathBuilder.engineBuild(Unknown Source) at java.security.cert.CertPathBuilder.build(Unknown Source) … 26 more error!

使用link http://code.naishe.in/2011/07/looks-like-article-no-more-unable-to.html 里介绍的方法之后,

问题消失

clipboard1
clipboard1

solution

No more ‘unable to find valid certification path to requested target’.pdf

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2019年06月29日,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 2014-11-22
  • solution
相关产品与服务
SSL 证书
腾讯云 SSL 证书(SSL Certificates)为您提供 SSL 证书的申请、管理、部署等服务,为您提供一站式 HTTPS 解决方案。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档