转到正文

宁静海

发现,理解,提升

存档

标签: Java

起因:

公司因为设置了外网的proxy,eclipse必须设置Proxy来访问一些plug-in的update site或者marketplace,但总是不稳定,常常刚开始能访问,但是突然又不能,也不是被端口禁用或者别的原因,因为报错的那些站点浏览器都能正常访问。 今天花了整整半天时间来想要彻底解决这个问题。

结果:

这是一个长达4年的Bug,从未被修复。但有work around的方法能解决。

Reference:

https://bugs.eclipse.org/bugs/show_bug.cgi?id=364992#c5

https://bugs.eclipse.org/bugs/show_bug.cgi?id=281472

解决方法:

ht

-Djavax.net.ssl.trustStore 
-Dhttps.protocols=SSLv3 
-Djsse.enableSNIExtension=false //This is for JDK 7 SNI support, but need to be disabled.
-Djavax.net.debug=ssl
-Dweblogic.security.SSL.protocolVersion=SSL3
-Dweblogic.security.SSL.ignoreHostnameVerification=true

 

Reference

http://stackoverflow.com/questions/5507878/ssl-connection-reset

http://stackoverflow.com/questions/10188568/sslexception-during-handshake-while-resuming-cached-session

http://stackoverflow.com/questions/7615645/ssl-handshake-alert-unrecognized-name-error-since-upgrade-to-java-1-7-0

 

一句话概括,JDK升级到1.7后对于SSL的支持各种坑。

 

static static <K, V extends Comparable<? super V>> SortedSet<Map.Entry<K, V>> entriesSortedByValues(Map<K, V> map) {
    SortedSet<Map.Entry<K, V>> sortedEntries = new TreeSet<Map.Entry<K, V>>(new Comparator<Map.Entry<K, V>>() {
        @Override
        public int compare(Map.Entry<K, V> e1, Map.Entry<K, V> e2) {
            return e1.getValue().compareTo(e2.getValue());
        }
    });
    sortedEntries.addAll(map.entrySet());
    return sortedEntries;
}

Spring是常用的开发框架,曾经以为只有2种主要的IOC容器初始化方式

1、显式的实例化ApplicationContext

2、通过web.xml配置

 

以下内容参考自Spring-Reference PDF

显式实例化:

ApplicationContext ctx = new ClassPathXmlApplicationContext("conf/appContext.xml");
//MessengerService.class用来确定2个XML文件的路径
ApplicationContext ctx = new ClassPathXmlApplicationContext(new String[] {"services.xml", "daos.xml"}, MessengerService.class);
ApplicationContext ctx = new FileSystemXmlApplicationContext("conf/appContext.xml");
ApplicationContext ctx = new FileSystemXmlApplicationContext("classpath:conf/appContext.xml");

 

web.xml配置

原理基本就是Servlet,摘自Reference PDF

To support the scoping of beans at the request, session, and global session levels
(web-scoped beans), some minor initial configuration is required before you define your beans. (This
initial setup is not required for the standard scopes, singleton and prototype.)
How you accomplish this initial setup depends on your particular Servlet environment..

对于Servlet2.4以上容器且使用了第三方的工具来控制跳转,比如Struts,则必须添加listener

<listener>
    <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
</listener>

 

这个添加是为了scope考量,摘自PDF

If you access scoped beans within Spring Web MVC, in effect, within a request that is processed by the
Spring DispatcherServlet, or DispatcherPortlet, then no special setup is necessary:
DispatcherServlet and DispatcherPortlet already expose all relevant state.

可以看到如果使用MVC,或者纯粹的DispatcherServlet应用等,可无须配置该listener。
If you use a Servlet 2.4+ web container, with requests processed outside of Spring’s DispatcherServlet
(for example, when using JSF or Struts), you need to add the following
javax.servlet.ServletRequestListener to the declarations in your web applications

如果request的处理过程在Dis