10 September 2015

前言

为了配合公司的平台战略,最近一段时间都是在搞java应用容器(还在搞容器?很土是吧.)移植的问题,从高大上的weblogic到屌丝Jboss。本文主要是对遇到的一些奇怪问题的总结。 当然普适性的部署描述迁移不在此列。

1. http 头的大小写问题

JBOSS(tomcat)竟然把http header的key全部转成了小写字符,导致一些奇怪的问题。

从http的标准来看,http的头中key是大小写不敏感的,所以对于一些servlet的API都是能够处理这种大小写问题的,但是如果应用自己的代码把头的map全部导出来自己处理的话就要小心了。

2. java mail的兼容问题

on Jboss, Axis 1.4&java mail 1.4.5 does not work anymore with current code.

MimeBodyPart mimeBodyPart = new MimeBodyPart(new ByteArrayInputStream(
                    attachment));
DataHandler dataHandler= mimeBodyPart.getDataHandler();

AttachmentPart attachmentPart = new AttachmentPart(dataHandler);

update the code to below since Java mail 1.4.5 has some updates for the mime data handler. So we create the dataHanlder in the code:

MimeBodyPart mimeBodyPart = new MimeBodyPart(new ByteArrayInputStream(
                    attachment));

DataHandler dataHandler= new DataHandler(new MimePartDataSource(mimeBodyPart));

AttachmentPart attachmentPart = new AttachmentPart(dataHandler);

3. ClassNotFoundException cannot find a class in a package named “internal”

应用报错。

Caused by: java.lang.ClassNotFoundException: com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl from [Module "deployment.Messaging.ear:main" from Service Module Loader]
at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:213) ~[na:na]
at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:459) ~[na:na]
...

To fix the problem, add below configuration. This will indicate JBOSS to fetch package “com.sun.org.apache.xalan.internal” from JDK lib, instead of JBOSS lib or Application lib.

-Djboss.modules.system.pkgs=......,com.sun.org.apache.xalan.internal

4. Logback 问题

对于ear包中有很多war的情形如果要能使用logback的配置,需要在部署中写全sub deployment. 可以参考 链接

5. DataSource 配置问题

这个严格说来并不是代码的问题,是jboss配置的问题,原来的datasource的url在jboss下都是要重新配过,特别注意里面的超时重连配置,目的是当数据库重启后还能恢复连接。

                <validation>
                    <check-valid-connection-sql>select 1 from dual</check-valid-connection-sql>
                    <validate-on-match>false</validate-on-match>
                    <background-validation>true</background-validation>
                    <background-validation-millis>10000</background-validation-millis>
                </validation>
                <timeout>
                    <allocation-retry>2</allocation-retry>
                    <allocation-retry-wait-millis>500</allocation-retry-wait-millis>
                </timeout>

后记

对于容器依赖的东西,还是能去掉就去掉了,不然以后始终是麻烦事情。

容器用起来都是问题多多,需要提供平台支撑及部署管理等,所以自带容器的服务比如spring-boot的应用才是正道。



blog comments powered by Disqus