腾讯信鸽(Xg-Push-SDK-JAVA-1.1.6)在weblogic下无法推送消息

问题表现:

在tomcat下推送成功,而换到weblogic下推送,会响应提示失败,以下是响应的Json:

 

{"err_msg":"common param missing, check access_id, timestamp and sign","ret_code":-1}   

根据响应的错误提示,发现好像是参数没有接收到,没办法了,只好翻下SDK包里的推送消息的源码,关键推送代码如下:

protected JSONObject callRestful(String url, Map<String, Object> params) 
	{
		String temp;
		String ret="";
		JSONObject jsonRet=null;
		String sign = generateSign("POST", url, params);
		if(sign.isEmpty()) return new JSONObject("{\"ret_code\":-1,\"err_msg\":\"generateSign error\"}");
		params.put("sign", sign);
		try{
			URL u = new URL(url);
			HttpURLConnection conn = (HttpURLConnection)u.openConnection();
			conn.setRequestMethod("POST");
			conn.setConnectTimeout(10000);
			conn.setDoOutput(true);
			conn.setDoInput(true);
			conn.setUseCaches(false);
			StringBuffer param = new StringBuffer();
			for (String key: params.keySet())
			{
				param.append(key).append("=").append(URLEncoder.encode(params.get(key).toString(), "UTF-8")).append("&");
			}
			conn.getOutputStream().write(param.toString().getBytes("UTF-8"));
			conn.getOutputStream().flush();
			conn.getOutputStream().close();
			InputStreamReader isr = new InputStreamReader(conn.getInputStream());  
            BufferedReader br = new BufferedReader(isr);  
            while((temp = br.readLine()) != null){  
                ret += temp;  
            }     
            br.close();  
            isr.close();
            conn.disconnect();
            jsonRet = new JSONObject(ret);
		} catch(java.net.SocketTimeoutException e) {
			jsonRet = new JSONObject("{\"ret_code\":-1,\"err_msg\":\"call restful timeout\"}");
		} catch(Exception e) {
			jsonRet = new JSONObject("{\"ret_code\":-1,\"err_msg\":\"call restful error\"}");
		}
		return jsonRet;
	}

 通过源码我们发现信鸽服务器端SDK是通过HttpURLConnection进行post请求来实现推送消息的动作。

在网上搜索之后,结论是在weblogic上使用HttpsURLConniection时,会默认使用weblogic自己的类weblogic.net.http.SOAPHttpsURLConnection,导致出现问题,而在tomcat下默认的实现类是HttpsURLConnection

在网上看了几篇先关的技术文章后,总结有两个解决办法:

 

1.在WEBLOGIC没有对使用的SSL实现类进行配置的情况下,在程序中如果正常使用java.net.URL的不带 URLStreamHandler 参数的构造方法new 一个URL对象的话,url.openConnection()默认是返回SOAPHttpsURLConnection类型对象,如果我们使用带有 URLStreamHandler参数的构造方法,如下:

 

		URL url = new URL(null,"https://www.etrade.com",
		new com.sun.net.ssl.internal.www.protocol.https.Handler());// 指定了handler后openConnection()返回了HttpsURLConnection类型对象
		HttpsURLConnection conn = (HttpsURLConnection)url.openConnection();

 

 

以上可以在程序中解决返回的HttpURLConnection对象的具体类型。

 

2.对于单机的Weblogic,在startWeblogic.sh文件中添加一行参数:

MEM_ARGS="${MEM_ARGS} -DUseSunHttpHandler=true"

这个参数的目的就是告诉WebLogic使用Sun的HttpHandler而不要使用WebLogic自己的。这样配置后使用url.openConnection()就会返回HttpsURLConnection类型对象了。

    

如果是配置了集群,则不必在启动脚本中增加参数,可以在weblogic控制台中针对特定server配置此参数

 

总结:方法一测试了下有点问题...weblogic环境就没再去测试了。方法二没有问题。

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

山下青城

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值