xfire1.2.6不能访问互联网环境下的问题及解决方案

前几天用xfire开发了个接口,本来在工程可以访问互联网的情况下没有任何问题的,但昨天部署到客户的内网环境就出问题了,异常如下:
javax.faces.FacesException: java.net.UnknownHostException: www.springframework.org

找不到主机www.springframework.org,因为不能访问互联网
找到问题出处,在xfire的配置文件/WEB-INF/xfire-servlet.xml,该文件内容如下:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
"http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<!-- 引入XFire预配置信息 -->
<import resource="classpath:org/codehaus/xfire/spring/xfire.xml" />
<!-- 定义访问的url -->
<bean
class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="urlMap">
<map>
<entry key="/WSPersonsInfoService.ws">
<ref bean="WSPersonsInfoService" />
</entry>
</map>
</property>
</bean>
<!-- 使用XFire导出器 -->
<bean id="baseWebService"
class="org.codehaus.xfire.spring.remoting.XFireExporter"
lazy-init="false" abstract="true">
<!-- 引用xfire.xml中定义的工厂 -->
<property name="serviceFactory" ref="xfire.serviceFactory" />
<!-- 引用xfire.xml中的xfire实例 -->
<property name="xfire" ref="xfire" />
</bean>
<bean id="WSPersonsInfoService" parent="baseWebService">
<!-- 业务服务bean -->
<property name="serviceBean" ref="WSPersonsInfoImp" />
<!-- 业务服务bean的窄接口类 -->
<property name="serviceClass"
value="com.ws.yxjsry.IWSPersonsInfo" />
</bean>
<bean id="WSPersonsInfoImp"
class="com.ws.yxjsry.WSPersonsInfoImp" />
</beans>



问题就出在
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
"http://www.springframework.org/dtd/spring-beans.dtd">
在不能访问互联网的条件下访问不了http://www.springframework.org/dtd/spring-beans.dtd


[b]解决方案尝试:[/b]
在网上找了半天,很多说把DOCTYPE改为访问本地文件,如:
<!DOCTYPE beans SYSTEM "spring-beans.dtd">
需要把spring-beans.dtd文件放在classpath目录下,例如tomcat的tomcat/bin/目录下。
修改后启动,发现仍然报找不到主机www.springframework.org,仔细查找后发现原因是在xfire-servlet.xml里面有一行<import resource="classpath:org/codehaus/xfire/spring/xfire.xml" />
在xfire.xml中存在
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
"http://www.springframework.org/dtd/spring-beans.dtd">
而且在xfire.xml中还有引用另一个xml文件
<import resource="customEditors.xml"/>
customEditors.xml中也存在
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
"http://www.springframework.org/dtd/spring-beans.dtd">

因为xfire.xml和customEditors.xml在xfire-all-1.2.6,jar里面,不想对JAR包作修改,于是,我就想到了把,xfire.xml和customEditors.xml的内容直接复制到xfire-servlet.xml里面,把引用<import resource="classpath:org/codehaus/xfire/spring/xfire.xml" />
去掉,问题就可以解决了,修改后的xfire-servlet.xml如下:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans SYSTEM "spring-beans.dtd">
<!-- 引入XFire预配置信息 -->
<bean id="xfire.customEditorConfigurer"
class="org.springframework.beans.factory.config.CustomEditorConfigurer">
<property name="customEditors">
<map>
<entry
key="org.codehaus.xfire.service.ServiceFactory">
<bean
class="org.codehaus.xfire.spring.editors.ServiceFactoryEditor">
<property name="transportManager"
ref="xfire.transportManager" />
</bean>
</entry>
</map>
</property>
</bean>
<bean id="xfire.serviceRegistry"
class="org.codehaus.xfire.service.DefaultServiceRegistry"
scope="singleton" />

<bean id="xfire.transportManager"
class="org.codehaus.xfire.transport.DefaultTransportManager"
scope="singleton" init-method="initialize" destroy-method="dispose">
</bean>

<bean id="xfire" class="org.codehaus.xfire.DefaultXFire"
scope="singleton">
<constructor-arg index="0">
<ref bean="xfire.serviceRegistry" />
</constructor-arg>
<constructor-arg index="1">
<ref bean="xfire.transportManager" />
</constructor-arg>
</bean>

<bean id="xfire.typeMappingRegistry"
class="org.codehaus.xfire.aegis.type.DefaultTypeMappingRegistry"
init-method="createDefaultMappings" scope="singleton">
</bean>

<bean id="xfire.aegisBindingProvider"
class="org.codehaus.xfire.aegis.AegisBindingProvider"
scope="singleton">
<constructor-arg index="0">
<ref bean="xfire.typeMappingRegistry" />
</constructor-arg>
</bean>

<bean id="xfire.serviceFactory"
class="org.codehaus.xfire.service.binding.ObjectServiceFactory"
scope="singleton">
<constructor-arg index="0">
<ref bean="xfire.transportManager" />
</constructor-arg>
<constructor-arg index="1">
<ref bean="xfire.aegisBindingProvider" />
</constructor-arg>
</bean>

<bean id="xfire.servletController"
class="org.codehaus.xfire.transport.http.XFireServletController"
scope="singleton">
<constructor-arg>
<ref bean="xfire" />
</constructor-arg>
</bean>

<bean id="xfire.messageServiceFactory"
class="org.codehaus.xfire.service.binding.ObjectServiceFactory">
<constructor-arg index="0" ref="xfire.transportManager" />
<constructor-arg index="1" ref="xfire.messageBindingProvider" />
<property name="style" value="message" />
</bean>

<bean id="xfire.messageBindingProvider"
class="org.codehaus.xfire.service.binding.MessageBindingProvider" />

<!-- 定义访问的url -->
<bean
class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="urlMap">
<map>
<entry key="/WSPersonsInfoService.ws">
<ref bean="WSPersonsInfoService" />
</entry>
</map>
</property>
</bean>
<!-- 使用XFire导出器 -->
<bean id="baseWebService"
class="org.codehaus.xfire.spring.remoting.XFireExporter"
lazy-init="false" abstract="true">
<!-- 引用xfire.xml中定义的工厂 -->
<property name="serviceFactory" ref="xfire.serviceFactory" />
<!-- 引用xfire.xml中的xfire实例 -->
<property name="xfire" ref="xfire" />
</bean>
<bean id="WSPersonsInfoService" parent="baseWebService">
<!-- 业务服务bean -->
<property name="serviceBean" ref="WSPersonsInfoImp" />
<!-- 业务服务bean的窄接口类 -->
<property name="serviceClass"
value="com.ws.yxjsry.IWSPersonsInfo" />
</bean>
<bean id="WSPersonsInfoImp"
class="com.ws.yxjsry.WSPersonsInfoImp" />

</beans>


后来觉得要在classpath中放spring-beans.dtd文件太麻烦,就想到用spring2.x的schema方式,这样就不需要spring-beans.dtd文件了。方法是把<!DOCTYPE beans SYSTEM "spring-beans.dtd">去掉,把<beans>修改成
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">


当然,工程中用到的spring包要换成用2.0以上的,否则回报错
org.xml.sax.SAXParseException: Document is invalid: no grammar found.

org.xml.sax.SAXParseException: Document root element "beans", must match DOCTYPE root "null".


[b]问题总结:[/b]
问题关键是xfire1.2.6的XML定义格式是按照spring1.x格式的,而且dtd都是在网络上校验,所以在不能访问互联网的环境中就会报错。首先,需要把xfire.xml和customEditors.xml复制到xfire-servlet.xml中。
然后,
如果工程用的是spring1.x,就把spring-beans.dtd文件放在classpath目录下,修改DOCTYPE为<!DOCTYPE beans SYSTEM "spring-beans.dtd">

如果工程用的是spring2.x,就把<!DOCTYPE beans SYSTEM "spring-beans.dtd">去掉,把<beans>修改成
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">


附件中有xfire的包和spring-beans.dtd文件
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值