ssl - Liberty 配置文件和 Apache HttpClient 4.2.1

标签 ssl apache-httpclient-4.x websphere-liberty

不知道其他人有没有看到这个,但我不知道这是怎么回事...... 我正在使用 Liberty Profile 8.5.5.1 和 IBM JDK 7 pxi3270sr5-20130619_01(SR5)

我有一个类需要向另一台服务器(基于 PHP)发出 URL 请求。所以我写了一个 HttpHelper 类来调用 apache HttpClient 类。如果我从一个普通的 Java 应用程序调用我的助手,我没有问题。当我在 Liberty 中运行完全相同的代码时,我收到 javax.net.ssl.SSLSocket 的 ClassNotFound 错误

这是我调用 apache 类的代码...

    public class HttpClientHelper
    {
    static Logger LOGGER = Logger.getLogger(HttpClientHelper.class.getName());
    static String cname = HttpClientHelper.class.getName();
    static HttpClientHelper _instance = null;
    static PoolingClientConnectionManager _cm = null;

    private HttpClientHelper()
    {
     SchemeRegistry schemeRegistry = new SchemeRegistry();
     schemeRegistry.register(
     new Scheme("http", 80, PlainSocketFactory.getSocketFactory()));

     _cm = new PoolingClientConnectionManager(schemeRegistry);

     _cm.setMaxTotal(200);

     _cm.setDefaultMaxPerRoute(20);

    HttpHost shost = new HttpHost("joomla32.cal2.net", 80);
    _cm.setMaxPerRoute(new HttpRoute(shost), 50);
   }
   protected static HttpClientHelper getInstance() {
if (_instance == null) {
  _instance = new HttpClientHelper();
}
return _instance;
    }

    public static String getUrlBody(String url) {
    String method = "getUrlBody(String url)";
    LOGGER.entering(cname, method, url);
getInstance();
String val = null;
DefaultHttpClient httpclient = null;
try {
  HttpContext context = new BasicHttpContext();

  httpclient = new DefaultHttpClient(_cm);
  HttpGet httpget = new HttpGet(url);
  HttpResponse response = httpclient.execute(httpget, context);
  HttpEntity entity = response.getEntity();

  System.out.println(response.getStatusLine());
  val = EntityUtils.toString(entity);
  EntityUtils.consume(entity);

} catch (Exception e) {
  LOGGER.logp(Level.WARNING, cname, method, e.getMessage(), url);
}catch(Error e){
    LOGGER.logp(Level.INFO,cname,method,e.getMessage());
    e.printStackTrace();

}
finally{

    LOGGER.exiting(cname, method, val);
}
return val;
     }
    }

\

在 httpclient.execute(httpget,context); 处抛出错误

我已尝试将 ssl 更新添加到 IBM JDK,但没有成功。 ssl.SocketFactory.provider=com.ibm.jsse2.SSLSocketFactoryImpl ssl.ServerSocketFactory.provider=com.ibm.jsse2.SSLServerSocketFactoryImpl

任何帮助将不胜感激

最佳答案

想通了... 我的 HttpClient Helper 类作为功能的一部分打包在一个包中。该包没有导入 javax.net.ssl,因此该类找不到它。呵呵。

关于ssl - Liberty 配置文件和 Apache HttpClient 4.2.1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20652314/

相关文章:

postgresql - Keycloak 无法连接到 Postgres : "SSL connection is required"

java - 退出 HttpClient session

noclassdeffounderror - 创建 DefaultHttpClient 导致 NoClassDefFoundError

java - SRVE9967W : The manifest class path xercesImpl. 在 jar 文件中找不到 jar

Tomcat SSL - IllegalStateException : SSL session ID not available

ssl - Fiddler https 错误 : "because they do not possess a common algorithm"

php - Symfony 使用 Swift Mailer 和 o2switch 发送电子邮件

java - Android 9.0 (Pie) 不支持异步任务

WebSphere liberty wasJmsServer 死信队列

ibm-mobilefirst - 在 Worklight Console 中找不到运行时