加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

配置xfire.webservice

发布时间:2020-12-17 00:59:53 所属栏目:安全 来源:网络整理
导读:所需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配置: !-- 配置文件加载 要添加xfire的配置文件。否则会找不到xfire.serviceFactory -- context-param param-n

所需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配置:


  <!-- 配置文件加载 要添加xfire的配置文件。否则会找不到xfire.serviceFactory -->
  <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath:applicationContext.xml,classpath:org/codehaus/xfire/spring/xfire.xml</param-value>
  </context-param>
<!-- spring Listener  -->
  <listener> 
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>

 <!-- xfire 配置  -->	
<servlet>     
    <servlet-name>xfire</servlet-name>     
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>  
</servlet>   
<servlet-mapping>  
    <servlet-name>xfire</servlet-name>  
    <url-pattern>*.ws</url-pattern>  
</servlet-mapping>


xfire默认加载"servletName-servlet".xml(xfire-servlet.xml)

如果要自己指定xml可以:

 <servlet>
        <servlet-name>xfire</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>classpath:xfire-servlet.xml</param-value>
        </init-param>
    </servlet>
<servlet-mapping>
	<servlet-name>xfire</servlet-name>
	<url-pattern>*.ws</url-pattern>
</servlet-mapping>

2.serverA的 xfire-servlet.xml


<?xml version="1.0" encoding="UTF-8" ?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans
           http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
           http://www.springframework.org/schema/aop 
           http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
           http://www.springframework.org/schema/context
           http://www.springframework.org/schema/context/spring-context-3.0.xsd">
	
	<!-- webService基类 -->
   	<bean id="webService" class="org.codehaus.xfire.spring.remoting.XFireExporter" abstract="true">
        <property name="serviceFactory">
            <ref bean="xfire.serviceFactory" />
        </property>
        <property name="xfire">
            <ref bean="xfire" />
        </property>
     </bean>
     
     <!-- 实现类接口 -->
	<bean id="xFireTestExporter" parent="webService" class="org.codehaus.xfire.spring.remoting.XFireExporter">
	     <property name="serviceBean">
	         <ref bean="fairyhawkHessianServiceSupport"/>
	     </property>
	     <property name="serviceClass">
	         <value>com.fairyhawk.service.hessian.FairyhawkHessianServiceSupport</value>
	     </property>
   </bean>
   
   <!-- 路径配置 -->
   <bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
	   <property name="urlMap">
	         <map>
	              <entry key="/xFireTestExporter.ws">
	                  <ref bean="xFireTestExporter"/>
	              </entry>
	         </map>
	         
	    </property>
   </bean>
   
</beans>

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


<bean id="fairyhawkHessianServiceSupport" class="com.fairyhawk.service.hessian.FairyhawkHessianServiceSupportImpl">  	
 </bean>

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

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

6.clientB中测试类


import org.codehaus.xfire.XFireFactory;
import org.codehaus.xfire.client.XFireProxyFactory;
import org.codehaus.xfire.service.Service;
import org.codehaus.xfire.service.binding.ObjectServiceFactory;

public class TestxFire {
	
	public static void main(String[] args) {


		try {
			XFireProxyFactory factoryInstance = new XFireProxyFactory(
					XFireFactory.newInstance().getXFire());
			
			Service srvcModel = new ObjectServiceFactory()
					.create(FairyhawkHessianServiceSupport.class);
			FairyhawkHessianServiceSupport iWebService;

			iWebService = (FairyhawkHessianServiceSupport) factoryInstance
					.create(srvcModel,"http://127.0.0.1/opens_admin/xFireTestExporter.ws");
			// 具体调用
			System.out.println(iWebService.getUser(null).get("user"));
		} catch (MalformedURLException e) {
			e.printStackTrace();
		}
	
	}
}

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

location ~ .(ws|jsp|jspx|do|action|ws)?$  {
                proxy_next_upstream http_502 http_504 error timeout invalid_header;
		proxy_set_header Host $host;
                proxy_set_header X-Forwarded-For $remote_addr;
                proxy_pass http://tomcat_server1;

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读