专栏首页Jerry的SAP技术分享使用java代码连接ABAP Netweaver系统

使用java代码连接ABAP Netweaver系统

2014-11-22

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 里介绍的方法之后,

问题消失

solution

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

本文参与腾讯云自媒体分享计划,欢迎正在阅读的你也加入,一起分享。

我来说两句

0 条评论
登录 后参与评论

相关文章

  • 汶川大地震中的SAP成都研究院

    5·12汶川地震,发生于北京时间(UTC+8)2008年5月12日(星期一)14时28分04秒,此次地震的面波震级 里氏震级达8.0Ms、矩震级达8.3Mw,地...

    Jerry Wang
  • 将Fiddler的服务器证书导入到Java的cacerts证书库里

    我在将Fiddler作为Java应用的代理时,在使用Java代码连接Fiddler时遇到了SSL证书相关的错误:

    Jerry Wang
  • 最简单的教程:在Ubuntu操作系统里安装Docker

    Docker 是一个开源的应用容器引擎,让开发者可以打包他们的应用以及依赖包到一个可移植的容器中,然后发布到任何流行的 Linux 机器上,也可以实现虚拟化。容...

    Jerry Wang
  • 构建一个pip安装的车辆路径显示的Python包

    專 欄 ❈treelake,Python中文社区专栏作者。 简书: http://www.jianshu.com/u/66f24f2c0f36 ❈ 最近有一些...

    Python中文社区
  • Knative 入门系列1:knative 概述

    Knative 是一个基于 Kubernetes 的,用于构建、部署和管理现代 serverless 应用的平台。Getting Started with Kn...

    崔秀龙
  • uni-app页面生命周期

    onLoad 监听页面加载 onShow 监听页面显示 onReady 监听页面初次渲染完成

    达达前端
  • java lambda 深入浅出

    标注为@FunctionalInterface的接口是函数式接口,该接口只有一个自定义方法。注意,只要接口只要包含一个抽象方法,编译器就默认该接口为函数式接口。

    luoxn28
  • 宁波银行上海分行参与组织举办第二期“国资大讲坛”论坛

    近日,第二期“国资大讲坛”活动在中国金融信息中心顺利举行。本次活动由国务院国资委新闻中心指导,上海国有资本运营研究院、中国金融信息中心、中国企业改革与发展研究会...

    安徽云际文化传媒
  • Nuro要用无人小货车搞定最后一公里,还宣布完成9200万美元融资

    夏乙 编译整理 量子位 出品 | 公众号 QbitAI 神神秘秘一年多,硅谷无人车创业公司Nuro.ai的产品终于亮相了。 和国内外主流自动驾驶测试车摆在一起,...

    量子位
  • 实时流处理系统的用例

    本文阐述了为什么比起Hadoop之类的知名技术,类似Apache Storm这样的系统更加有用。 让我们以经典的笔记本品牌实时情感分析(SENTIMENT A...

    CSDN技术头条

扫码关注云+社区

领取腾讯云代金券

玩转腾讯云 有奖征文活动