1、使用org.codehaus.xfire.spring.XFireSpringServlet与ServiceBean
1.1 web.xml的配置
<web-app>
<display-name>Spring Image Database</display-name>
<description>Spring Image Database sample application</description>
<!--
These values are used by ContextLoaderListener, defined immediately below.
The files listed below are used to initialize the business logic portion of the application.
Each dispatcher servlet (defined further down) has their own configuration file,
which may or may not depend on items in these files.
-->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath:applicationContext-webservice.xml
</param-value>
</context-param>
<!-- Log4j configuration listener-->
<listener>
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>
<!-- Spring framework -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>XFireServlet</servlet-name>
<display-name>XFire Servlet</display-name>
<servlet-class>org.codehaus.xfire.spring.XFireSpringServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>XFireServlet</servlet-name>
<url-pattern>/services/*</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
1.2 applicationContext-webservice.xml的配置:
<beans>
<import resource="classpath:org/codehaus/xfire/spring/xfire.xml"/>
<bean name="echoService" class="org.codehaus.xfire.spring.ServiceBean">
<property name="serviceBean" ref="echo"/>
<property name="serviceClass" value="org.codehaus.xfire.test.Echo"/>
<property name="inHandlers">
<list>
<ref bean="addressingHandler"/>
</list>
</property>
</bean>
<bean id="echo" class="org.codehaus.xfire.test.EchoImpl"/>
<bean id="addressingHandler" class="org.codehaus.xfire.addressing.AddressingInHandler"/>
<bean name="bookService" class="org.codehaus.xfire.spring.ServiceBean">
<property name="serviceBean" ref="bookServiceBean"/>
<property name="serviceClass" value="org.codehaus.xfire.demo.BookService"/>
</bean>
<bean id="bookServiceBean" class="org.codehaus.xfire.demo.BookServiceImpl"/>
</beans>
1.3 这样将会发布两个service,BookService和EchoService。随后就可以使用client端进行测试了。
//测试BookService
public static void main(String args[])
{
String serviceURL = "http://127.0.0.1:9001/xfire/services/BookService";
Service serviceModel = new ObjectServiceFactory().create(BookService.class,null,"http://xfire.codehaus.org/BookService",null);
XFireProxyFactory serviceFactory = new XFireProxyFactory();
try
{
BookService service = (BookService) serviceFactory.create(serviceModel, serviceURL);
Client client = Client.getInstance(service);
client.addOutHandler(new OutHeaderHandler());
Book[] books = service.getBooks();
System.out.println("BOOKS:");
for (int i = 0; i < books.length; i++)
{
System.out.println(books[i].getTitle());
}
}
catch (MalformedURLException e)
{
e.printStackTrace();
}
}
1.4 忘了BookService及其实现了。
public interface BookService
{
public Book[] getBooks();
public Book findBook(String isbn);
public Map getBooksMap();
}
public class BookServiceImpl implements BookService
{
private Book onlyBook;
public BookServiceImpl()
{
onlyBook = new Book();
onlyBook.setAuthor("Dan Diephouse");
onlyBook.setTitle("Using XFire");
onlyBook.setIsbn("0123456789");
}
public Book[] getBooks()
{
return new Book[] { onlyBook };
}
public Book findBook(String isbn)
{
if (isbn.equals(onlyBook.getIsbn()))
return onlyBook;
return null;
}
public Map getBooksMap() {
Map result = new HashMap();
result.put(onlyBook.getIsbn(), onlyBook);
return result;
}
}
1.5 简单的测试就是通过IE,输入http://ip:port/context/services/BookService?wsdl或者http://ip:port/context/services/EchoService?wsdl,将会出现相应的wsdl文档。
如果只是输入http://ip:port/context/services/BookService,会出现Invalid SOAP request.这也说明配置正确。
2、直接集成Spring(通过Spring的org.springframework.web.servlet.DispatcherServlet)
2.1 web.xml配置
<web-app>
<!-- START SNIPPET: xfire -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath:org/codehaus/xfire/spring/xfire.xml</param-value>
</context-param>
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>/WEB-INF/log4j.properties</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<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>/*</url-pattern>
</servlet-mapping>
<!-- END SNIPPET: xfire -->
</web-app>
2.2 xfire-servlet.xml配置
<beans>
<!-- START SNIPPET: xfire -->
<bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="urlMap">
<map>
<entry key="/EchoService">
<ref bean="echo"/>
</entry>
</map>
</property>
</bean>
<bean id="echoBean" class="org.codehaus.xfire.spring.example.EchoImpl"/>
<!-- Declare a parent bean with all properties common to both services -->
<bean id="echo" class="org.codehaus.xfire.spring.remoting.XFireExporter">
<property name="serviceFactory">
<ref bean="xfire.serviceFactory"/>
</property>
<property name="xfire">
<ref bean="xfire"/>
</property>
<property name="serviceBean">
<ref bean="echoBean"/>
</property>
<property name="serviceClass">
<value>org.codehaus.xfire.spring.example.Echo</value>
</property>
</bean>
<!-- END SNIPPET: xfire -->
</beans>
2.3 余下的配置跟第一种方法一样。
3、另外xfire的官方文档上还有一种方法,是通过XBean与Spring结合来实现webservice的expose。还是觉得上面的两种方法比较好。既然已经与spring集成在一起了,何必再引入其他的呢?以后的维护是不是也要有问题呢?
在随后的文章里将会介绍xfire与Jibx结合的例子。
分享到:
相关推荐
spring xfire spring 集成xfire 比较好的一种方式
源代码 博文链接:https://callan.iteye.com/blog/135438
xFire与Spring集成xFire与Spring集成xFire与Spring集成xFire与Spring集成xFire与Spring集成
XFire与Spring组合发布webservices的几种方式实例,可以直接导入到环境运行
spring与xfire整合正确演示例子
spring和xfire配置,Spring和XFire可以通过多种方式结合,本文档是常用的一种简单而实用的方法。
NULL 博文链接:https://tangwenchao86.iteye.com/blog/728790
spring+xfire集成解决方案spring+xfire集成解决方案
spring xfire 集成, 笔者的开发环境描述如下: 1) jdk: 1.5版本; 2) Tomcat:5.5.20; 3) MyEclipse:5.1.1 GA。
webservice(xfire)+spring的二种实现方式,里面有详细的配置说明.
spring+xfire( 编写webservice完整配置+案例)
spring +xfire整合 1. xfire + spring 发布webservice 2. 利用 javascript 调用发布的webservice
xfire+spring+安全认证,包含服务端和客户端,xfire jar包可以从我的资源下面下或网上很多。
spring和xfire集成的时候修要的jar文件,spring需要的jar文件自己另行下载。.
XFire 是与Axis 2并列的新一代Web Service框架,通过提供简单的API支持Web Service各项标准协议,帮助你方便快速地开发Web Service应用。 相对于Axis来说,目前XFire相对受欢迎,加上其提供了和Spring集成的支持,在...
spring整合xfire myeclipse可直接用 分客户端(main方法)和服务器端(web项目)连个项目
NULL 博文链接:https://devil13th.iteye.com/blog/756419
自己写给同事培训的xfire整合spring的小项目 步骤清晰 简单易懂 适合刚刚接触xfire的同事们
XFire与Spring集成WebService客户端的两种开发方式.pdfXFire与Spring集成WebService客户端的两种开发方式.pdfXFire与Spring集成WebService客户端的两种开发方式.pdfXFire与Spring集成WebService客户端的两种开发方式...
spring-mvc与xfire的集成 对于这样的集成,看看里面的配置文件就行了 一个简单的接口,对应一个简单的实现。 然后在配置文件里指明就可以了。 DispatcherServlet本身会管理xfire的请求 配置文件中配置的key可以理解...