HttpGet在SE应用程序中工作但不在Container中工作

时间:2015-08-27 12:48:52

标签: java

我的测试应用程序在从SE应用程序运行时有效,但在基于Web的应用程序中使用相同的代码时,它拒绝工作。

示例代码:

SSLContextBuilder builder = new SSLContextBuilder();
        builder.loadTrustMaterial(null, new TrustSelfSignedStrategy());
        SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(builder.build());

        HttpHost target = new HttpHost("test.test.com", 443, "https");
        HttpHost proxy = new HttpHost("41.41.41.41", 3128, "http");

        final RequestConfig requestConfig = RequestConfig.custom()
                .setConnectTimeout(5000)
                .setConnectionRequestTimeout(5000)
                .setSocketTimeout(5000).setProxy(proxy)
                .build();

        CloseableHttpClient httpclient = HttpClients.custom()
                .setSSLSocketFactory(sslsf)
                .setDefaultRequestConfig(requestConfig)
                .build();

        HttpGet httpGet = new HttpGet(validateUrl);
        httpGet.setHeader("Authorization", "Basic " + authenticationStringEncrypted);
        CloseableHttpResponse response = httpclient.execute(target, httpGet);

在Web应用程序中,它到达了这一部分:

CloseableHttpClient httpclient = HttpClients.custom()
                .setSSLSocketFactory(sslsf)
                .setDefaultRequestConfig(requestConfig)
                .build();

然后它停止,没有抛出异常,并且这个块被try-catch包围,使用multicatch来捕获所有异常。

} catch (NoSuchAlgorithmException | KeyManagementException | KeyStoreException | IOException ex) {
        ex.printStackTrace();
    }

基于Web的应用程序部署到glassfish 4.1。

0 个答案:

没有答案