所需jar包:

xfire-all-1.2.6.jar

xfire-jsr181-api-1.0-M1.jar

wsdl4j-1.6.2.jar

jdom-1.0.jar

 

clientB调用serverA的接口。

1.serverA -web.xml配置:

 

[html] view plaincopy
 
  1.   <!-- 配置文件加载 要添加xfire的配置文件。否则会找不到xfire.serviceFactory -->  
  2.   <context-param>  
  3.     <param-name>contextConfigLocation</param-name>  
  4.     <param-value>classpath:applicationContext.xml,classpath:org/codehaus/xfire/spring/xfire.xml</param-value>  
  5.   </context-param>  
  6. <!-- spring Listener  -->  
  7.   <listener>   
  8.     <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>  
  9.   </listener>  
  10.   
  11.  <!-- xfire 配置  -->     
  12. <servlet>       
  13.     <servlet-name>xfire</servlet-name>       
  14.     <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>    
  15. </servlet>     
  16. <servlet-mapping>    
  17.     <servlet-name>xfire</servlet-name>    
  18.     <url-pattern>*.ws</url-pattern>    
  19. </servlet-mapping>  
  20.   
  21.   
  22. xfire默认加载"servletName-servlet".xml(xfire-servlet.xml)  
  23.   
  24. 如果要自己指定xml可以:  
  25.   
  26.  <servlet>  
  27.         <servlet-name>xfire</servlet-name>  
  28.         <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>  
  29.         <init-param>  
  30.             <param-name>contextConfigLocation</param-name>  
  31.             <param-value>classpath:xfire-servlet.xml</param-value>  
  32.         </init-param>  
  33.     </servlet>  
  34. <servlet-mapping>  
  35.     <servlet-name>xfire</servlet-name>  
  36.     <url-pattern>*.ws</url-pattern>  
  37. </servlet-mapping>  


2.serverA的 xfire-servlet.xml

 

 

[html] view plaincopy
 
  1. <?xml version="1.0" encoding="UTF-8" ?>  
  2. <beans xmlns="http://www.springframework.org/schema/beans"  
  3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"  
  4. xmlns:aop="http://www.springframework.org/schema/aop"  
  5. xsi:schemaLocation="http://www.springframework.org/schema/beans  
  6.            http://www.springframework.org/schema/beans/spring-beans-3.0.xsd  
  7.            http://www.springframework.org/schema/aop   
  8.            http://www.springframework.org/schema/aop/spring-aop-3.0.xsd  
  9.            http://www.springframework.org/schema/context  
  10.            http://www.springframework.org/schema/context/spring-context-3.0.xsd">  
  11.       
  12.     <!-- webService基类 -->  
  13.     <bean id="webService" class="org.codehaus.xfire.spring.remoting.XFireExporter" abstract="true">  
  14.         <property name="serviceFactory">  
  15.             <ref bean="xfire.serviceFactory" />  
  16.         </property>  
  17.         <property name="xfire">  
  18.             <ref bean="xfire" />  
  19.         </property>  
  20.      </bean>  
  21.        
  22.      <!-- 实现类接口 -->  
  23.     <bean id="xFireTestExporter" parent="webService" class="org.codehaus.xfire.spring.remoting.XFireExporter">  
  24.          <property name="serviceBean">  
  25.              <ref bean="fairyhawkHessianServiceSupport"/>  
  26.          </property>  
  27.          <property name="serviceClass">  
  28.              <value>com.fairyhawk.service.hessian.FairyhawkHessianServiceSupport</value>  
  29.          </property>  
  30.    </bean>  
  31.      
  32.    <!-- 路径配置 -->  
  33.    <bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">  
  34.        <property name="urlMap">  
  35.              <map>  
  36.                   <entry key="/xFireTestExporter.ws">  
  37.                       <ref bean="xFireTestExporter"/>  
  38.                   </entry>  
  39.              </map>  
  40.                
  41.         </property>  
  42.    </bean>  
  43.      
  44. </beans>  


3.serverA 中的applicationContext.xml中要添加fairyhawkHessianServiceSupport的注册

 

 

[html] view plaincopy
 
  1. <bean id="fairyhawkHessianServiceSupport" class="com.fairyhawk.service.hessian.FairyhawkHessianServiceSupportImpl">     
  2.  </bean>  


4.ServaerA中提供
com.fairyhawk.service.hessian.FairyhawkHessianServiceSupport
和实现类
com.fairyhawk.service.hessian.FairyhawkHessianServiceSupportImpl

 

5.serverA给clientB提供接口FairyhawkHessianServiceSupport。可以复制到
clientB下。或者打成jar包。

6.clientB中测试类

 

[java] view plaincopy
 
  1. import org.codehaus.xfire.XFireFactory;  
  2. import org.codehaus.xfire.client.XFireProxyFactory;  
  3. import org.codehaus.xfire.service.Service;  
  4. import org.codehaus.xfire.service.binding.ObjectServiceFactory;  
  5.   
  6. public class TestxFire {  
  7.       
  8.     public static void main(String[] args) {  
  9.   
  10.   
  11.         try {  
  12.             XFireProxyFactory factoryInstance = new XFireProxyFactory(  
  13.                     XFireFactory.newInstance().getXFire());  
  14.               
  15.             Service srvcModel = new ObjectServiceFactory()  
  16.                     .create(FairyhawkHessianServiceSupport.class);  
  17.             FairyhawkHessianServiceSupport iWebService;  
  18.   
  19.             iWebService = (FairyhawkHessianServiceSupport) factoryInstance  
  20.                     .create(srvcModel, "http://127.0.0.1/opens_admin/xFireTestExporter.ws");  
  21.             // 具体调用  
  22.             System.out.println(iWebService.getUser(null).get("user"));  
  23.         } catch (MalformedURLException e) {  
  24.             e.printStackTrace();  
  25.         }  
  26.       
  27.     }  
  28. }  


另 有用nginx的x有时给屏蔽掉了。需要加上ws

 

 

[plain] view plaincopy
 
    1. location ~ \.(ws|jsp|jspx|do|action|ws)?$  {  
    2.                 proxy_next_upstream http_502 http_504 error timeout invalid_header;  
    3.         proxy_set_header Host $host;  
    4.                 proxy_set_header X-Forwarded-For $remote_addr;  
    5.                 proxy_pass http://tomcat_server1;  

 

发布于2012-05-07

posted on 2014-06-04 18:00  ymlove7  阅读(203)  评论(0)    收藏  举报