泽西似乎在客户端请求中添加了端口到url

时间:2013-03-17 21:26:50

标签: java ssl client jersey

我使用一些基本的Java代码通过Jersey发送RESTful请求,由于某种原因,Jersey将:443端口附加到我所有URL的末尾,导致CAS失败(代理票据在其他地方生成)对于特定的URL;添加端口中断此。)

有没有办法告诉Jersey不要将443端口作为URL的一部分发送?

编辑:fyi我之前删除了我之前的票,然后才意识到问题确实存在于泽西岛内。

Edit2:在下面添加了代码;我不得不删除一些项目,但这基本上是我使用的。它是一种通用方法,可以使用我们正在使用的特定API;我添加了doNotSend模式来测试url; url从没有:443返回,但是当它通过Jersey执行时,它有:443,它会抛出CAS身份验证。

// Create a trust manager that does not validate certificate chains
TrustManager[] trustAllCerts = new TrustManager[]{new X509TrustManager(){
    public X509Certificate[] getAcceptedIssuers(){return null;}
    public void checkClientTrusted(X509Certificate[] certs, String authType){}
    public void checkServerTrusted(X509Certificate[] certs, String authType){}
}};
try {
    SSLContext sc = SSLContext.getInstance("TLS");
    sc.init(null, trustAllCerts, new SecureRandom());
    HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
} catch (Exception e) {
    ;
}

Client client = Client.create();

String url = Configuration.getOption(CONFIG_REST_URL) + actionPath;
if (dontSendMode) {
    GGResponse r = new GGResponse();
    r.setUrl(url);
    return r;
}
if (StringUtils.isNotEmpty(proxy_ticket)) {
    if (url.contains("?")) {
        url += "&";
    } else {
        url += "?";
    }
    url += String.format("ticket=%s", proxy_ticket);
}
WebResource.Builder resourceBuilder = client
        .resource(url)
        .accept("application/json");

ClientResponse response = null;
if (method.equalsIgnoreCase("GET")) {
    response = resourceBuilder.get(ClientResponse.class);
}
if (method.equalsIgnoreCase("POST")) {
    response = resourceBuilder.post(ClientResponse.class, json);
}
if (method.equalsIgnoreCase("DELETE")) {
    response = resourceBuilder.delete(ClientResponse.class);
}
if (method.equalsIgnoreCase("PUT")) {
    response = resourceBuilder.put(ClientResponse.class, json);
}

String output = null;
String etagResponse = null;
String error = null;

if (response != null && response.getStatus() == 200) {
    output = response.getEntity(String.class);
} else {
    System.out.println(error);
}

0 个答案:

没有答案