如何在Mobilefirst适配器中使用System.setProperty

时间:2016-01-08 18:25:35

标签: java jax-rs ibm-mobilefirst mobilefirst-adapters

我需要能够在Mobilefirst Java适配器(7.1)中设置系统属性。当我添加它时,它似乎没有像在eclipse中的独立Java应用程序中那样起作用。关于如何获得相同功能的任何想法?

更新:我道歉......应该添加代码示例....

你可以看到我在下面提到的setProperties ....似乎都没有生效。第一个应该转储一堆调试信息......第二个不会打印任何东西......但是会修复TLSv1.2的另一个问题。

public String getHTTPRequest(String baseURL, String authHeader) {

    logger.info("In getHTTPRequest");
    logger.info("Parms: URL = " + baseURL + " auth = " + authHeader);
    System.setProperty("javax.net.debug", "ssl:handshake:verbose");
    System.setProperty("jsse.enableSNIExtension", "false");

    String json = "";

    try {

        SSLContext context = SSLContext.getInstance("TLSv1.2");
        context.init(null, null, null);

        SSLConnectionSocketFactory sslCF = new SSLConnectionSocketFactory(context, new HostnameVerifier() {
                @Override
                public boolean verify(String hostname, SSLSession session) {
                    // or add your own test here
                    return true;
                }
            });

        //CloseableHttpClient httpClient = HttpClientBuilder.create().setSSLSocketFactory(sslCF).build();
        HttpClientBuilder clientBuilder = HttpClientBuilder.create().setSslcontext(context);
        CloseableHttpClient httpClient = clientBuilder.build();
        HttpGet request = new HttpGet(new URI(baseURL));
        request.addHeader("Authorization", authHeader);

        CloseableHttpResponse httpResponse = httpClient.execute(request);
        json = EntityUtils.toString(httpResponse.getEntity());
        System.out.println(" Response = " + json);

    } catch (Exception e) {
        logger.info(" Exception in getHTTPRequest = " + e.toString());
    }
    return json;
}

1 个答案:

答案 0 :(得分:0)

评论部分的解决方案:

  

我将set属性值添加到jvm.options文件中,但似乎有效.... -Djsse.enableSNIExtension=false