weblogic.net.http.SOAPHttpsURLConnection cannot be cast to javax.net.ssl.HttpsURLConnection
来源:互联网 发布:淘宝哪家杂货铺好 编辑:程序博客网 时间:2024/06/06 03:27
0、代码如下:
public static JSONObject httpsRequest(String requestUrl, String requestMethod, String outputStr) {JSONObject jsonObject = null;try {// 创建SSLContext对象,并使用我们指定的信任管理器初始化TrustManager[] tm = { new MyX509TrustManager() };SSLContext sslContext = SSLContext.getInstance("SSL", "SunJSSE");sslContext.init(null, tm, new java.security.SecureRandom());// 从上述SSLContext对象中得到SSLSocketFactory对象SSLSocketFactory ssf = sslContext.getSocketFactory(); log.info("CommonUtil ===========1111111111111=========== ");URL url = new URL(requestUrl);//1URL url = new URL(null,requestUrl,new com.sun.net.ssl.internal.www.protocol.https.Handler());//2URL url = new URL(null,requestUrl,new sun.net.www.protocol.https.Handler());log.info("CommonUtil ===========22222222222=========== ");//SOAPHttpsURLConnection cc = null;HttpsURLConnection conn = (HttpsURLConnection) url.openConnection();conn.setSSLSocketFactory(ssf);conn.setDoOutput(true);conn.setDoInput(true);conn.setUseCaches(false);// 设置请求方式(GET/POST)conn.setRequestMethod(requestMethod);
1、程序在tomcat上没问题,在weblogic上跑报错,日志错误为:
####<2015-12-11 上午09时32分21秒 CST> <Error> <com.n22.msg.weixin.util.CommonUtil> <WIN-CBCCPK0SHE8> <Server-1> <[ACTIVE] ExecuteThread: '14' for queue: 'weblogic.kernel.Default (self-tuning)'> <<anonymous>> <> <> <1449797541041> <BEA-000000> <https请求异常:{}java.lang.ClassCastException: weblogic.net.http.SOAPHttpsURLConnection cannot be cast to javax.net.ssl.HttpsURLConnectionat com.nnn.msg.weixin.util.CommonUtil.httpsRequest(CommonUtil.java:54)at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)at java.lang.reflect.Method.invoke(Method.java:606)at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:221)at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:137)at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:111)at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:806)at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:729)at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:959)at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:893)at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970)at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:872)at javax.servlet.http.HttpServlet.service(HttpServlet.java:751)at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)at javax.servlet.http.HttpServlet.service(HttpServlet.java:844)at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:280)at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:254)at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:136)at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:346)at weblogic.servlet.internal.TailFilter.doFilter(TailFilter.java:25)at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:79)at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:85)at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:79)at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.wrapRun(WebAppServletContext.java:3436)at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3402)at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:120)at weblogic.servlet.provider.WlsSubjectHandle.run(WlsSubjectHandle.java:57)at weblogic.servlet.internal.WebAppServletContext.doSecuredExecute(WebAppServletContext.java:2285)at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2201)at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2179)at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1572)at weblogic.servlet.provider.ContainerSupportProviderImpl$WlsRequestExecutor.run(ContainerSupportProviderImpl.java:255)at weblogic.work.ExecuteThread.execute(ExecuteThread.java:311)at weblogic.work.ExecuteThread.run(ExecuteThread.java:263)>
服务器环境的原因导致了报错,查看相关资料。
①在WEBLOGIC没有对使用的SSL实现类进行配置的情况下,在程序中如果正常使用java.net.URL的不带 URLStreamHandler 参数的构造方法new 一个URL对象的话(URL url = new URL(requestUrl);),url.openConnection()默认是返回SOAPHttpsURLConnection类型对象,导致转换失败。
3、解决办法:
①看到网上的解决办法将URL url = new URL(requestUrl);改成URL url = new URL(null,requestUrl,new com.sun.net.ssl.internal.www.protocol.https.Handler());
尝试了下,在本地Tomact上都不通过,后来在服务器weblogic上测试还是失败。
②将URL url = new URL(requestUrl);改成URL url = new URL(null,requestUrl,new sun.net.www.protocol.https.Handler());本地tomcat测试没问题,服务器weblogic上测试还是失败。
③从Weblogic配置的层面上解决报错的问题。对于单机的Weblogic配置,可以在启动脚本中(比如startWebLogic.sh)在JAVA_OPTIONS增加 -DUseSunHttpHandler=true ,例如
<span style="font-size:18px;">set JAVA_OPTIONS=%JAVA_OPTIONS% %JAVA_PROPERTIES% -DUseSunHttpHandler=true -Dwlw.iterativeDev=%iterativeDevFlag% - Dwlw.testConsole=%testConsoleFlag% -Dwlw.logErrorsToConsole=% logErrorsToConsoleFlag%</span>
如果是配置了集群,则不必在启动脚本中增加参数,可以在weblogic控制台中针对特定server配置此参数
这个参数的目的就是告诉WebLogic使用Sun的HttpHandler而不要使用WebLogic自己的。这样配置后使用url.openConnection()就会返回HttpsURLConnection类型对象了。
- weblogic.net.http.SOAPHttpsURLConnection cannot be cast to javax.net.ssl.HttpsURLConnection
- 微信开发:weblogic.net.http.SOAPHttpsURLConnection cannot be cast to javax.net.ssl.HttpsURLConnection
- weblogic.net.http.SOAPHttpsURLConnection cannot be cast to javax.net.ssl.HttpsURLConnection
- weblogic.net.http.SOAPHttpsURLConnection cannot be cast to javax.net.ssl.HttpsURLConnection
- HttpURLConnectionImpl cannot be cast to javax.net.ssl.HttpsURLConnection
- sun.net.www.protocol.http.HttpURLConnection cannot be cast to javax.net.ssl.HttpsURLConnection
- 解决sun.net.www.protocol.http.HttpURLConnection cannot be cast to javax.net.ssl.HttpsURLConnection
- 关于异常:HttpURLConnectionImpl cannot be cast to javax.net.ssl.HttpsURLConnection的解决办法
- java.lang.ClassCastException: libcore.net.http.HttpURLConnectionImpl cannot be cast to javax.net.ssl
- java.lang.ClassCastException: sun.net.www.protocol.http.HttpURLConnection cannot be cast to javax.n
- cannot be cast to javax.servlet.Servlet
- weblogic.xml.jaxp.RegistrySAXParserFactory cannot be cast to javax.xml.parsers.SAXParserFactory
- jms异常 weblogic.jms.client.JMSConnectionFactory cannot be cast to javax.jms.ConnectionFactory
- net.sf.ezmorph.bean.MorphDynaBean cannot be cast to
- StrutsPrepareAndExecuteFilter cannot be cast to javax.servlet.Filter
- tomcat服务器cannot be cast to javax.servlet.Servlet问题
- StrutsPrepareAndExecuteFilter cannot be cast to javax.servlet.Filter
- Caused by:....SpringServletContainerInitializer cannot be cast to javax.servlet.ServletContainerInit
- 【C#】反射基本用法
- 使用www加载的坑
- Android之项目推荐使用的第三方库
- android4.4系统源码编译(三)_编译
- 磁盘槽位和盘符绑定方案
- weblogic.net.http.SOAPHttpsURLConnection cannot be cast to javax.net.ssl.HttpsURLConnection
- Android之日期/时间选择对话框
- 百宝云Json与数组命令教程
- JSON使用IContractResolver序列化实现属性名骆驼命名法
- 同时运行多个 tomcat 修改端口
- 欢迎使用CSDN-markdown编辑器
- Android自动填充短信验证码
- Java NIO原理图文分析及代码实现
- js中的document.write