无聊人士

搬家==》www.soapui.cn

  BlogJava :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理 ::
  32 随笔 :: 0 文章 :: 60 评论 :: 0 Trackbacks

受白衣同志的当,上了xfire的贼船,抛弃了axis,呜!

xfire 1.0终于final了,试用了一下,,感觉同1.0M6相比,使用变化不大。

看看user guide,照着examples下的例子,基本上hello xfire不成问题。

1、jar包

同以往一样,xfire user guide中的Dependency Guide.html还是说得不明不白,除了让人发晕,没有太大的实际意义。

SNAG-0000.jpg

注:
1)XmlSchema-1.0.jar、jakatra commons httpclient/codec只有在Dynamic Client中才需要用。
2)采用quick start、examples/book中用的service.xml配置方法时,xbean-spring与spring有兼容问题,我用1.2.7、2.0M2的spring时,总是报addPropertyValue(String,Object)之类的异常,换成1.2.6以后一切正常。用examples/spring例子中的配置方法时,没有出现这种情况。

2、quick start、examples/book

这种做法很简单,好象也不太合我的胃口,就没仔细折腾。
(1)在web.xml中配置一下

 1  <servlet>
 2    <servlet-name>XFireServlet</servlet-name>
 3    <display-name>XFire Servlet</display-name>
 4    <servlet-class>org.codehaus.xfire.transport.http.XFireConfigurableServlet</servlet-class>
 5  </servlet>
 6
 7  <servlet-mapping>
 8    <servlet-name>XFireServlet</servlet-name>
 9    <url-pattern>/servlet/XFireServlet/*</url-pattern>
10  </servlet-mapping>
11
12  <servlet-mapping>
13    <servlet-name>XFireServlet</servlet-name>
14    <url-pattern>/services/*</url-pattern>
15  </servlet-mapping>

(2)编码。这个不用说,呵呵
(3)在classpath中,建META-INF/xfire/services.xml配置文件,把刚才做好的webservices配置一下。

1<beans xmlns="http://xfire.codehaus.org/config/1.0">
2  <service>
3    <name>BookService</name>
4    <namespace>http://xfire.codehaus.org/BookService</namespace>
5    <serviceClass>org.codehaus.xfire.demo.BookService</serviceClass>
6  </service>
7</beans>

(4)然后就是deploy,访问http://ip:port/webapp name/BookService?WSDL之类的动作了。

3、examples/spring

xfire和spring勾搭得比较紧密啊,只需要简单配置一下,就可以把spring.xml中配置好的bean拿出来做web services了。
(1)折腾spring的东西(略)。
(2)在web.xml中配置一下(注意xfire那一段)

 1    <context-param>
 2        <param-name>contextConfigLocation</param-name>
 3        <param-value>/WEB-INF/applicationContext.xml classpath:org/codehaus/xfire/spring/xfire.xml</param-value>
 4    </context-param>
 5
 6    <listener>
 7        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
 8    </listener>
 9
10    <servlet>
11        <servlet-name>xfire</servlet-name>
12        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
13    </servlet>
14    <servlet-mapping>
15        <servlet-name>xfire</servlet-name>
16        <url-pattern>/*</url-pattern>
17    </servlet-mapping>

(3)在WEB-INF/xfire-servlet.xml中把spring bean同xfire webservices“关联”起来。这个xfire-servlet.xml实际上就是一个标准的spring.xml配置文件。

 1<?xml version="1.0" encoding="UTF-8"?>
 2<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
 3<beans>
 4    <bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
 5        <property name="urlMap">
 6            <map>
 7                <entry key="/EchoService" value-ref="echo"/>
 8            </map>
 9        </property>
10    </bean>
11    
12    <bean id="echo" class="org.codehaus.xfire.spring.remoting.XFireExporter">
13        <property name="serviceFactory" ref="xfire.serviceFactory"/>
14        <property name="xfire" ref="xfire"/>
15        <property name="serviceBean" ref="echoBean"/>
16        <property name="serviceClass" value="org.codehaus.xfire.spring.example.Echo"/>>
17    </bean>
18</beans>

注:第16行,xfire 1.0M6中用serviceInterface,现在改成serviceClass了。

(4)然后就完工,用http://ip:port/webapp name/xfire/EchoService?WSDL可以看到WSDL内容。

4、客户端

按我的恶习,这类事情,肯定是直接开vs.net或者C# developer来显摆一下了。不得不承认,.net里面调web services就是方便啊!
SNAG-0001.jpg
至于java做client么,以前一般是用axis来生成client class,xfire也提供类似的工具,不过对于xfire来说,最简单的办法就是用Dynamic Client,几行代码搞定。

1    Service serviceModel = new ObjectServiceFactory().create(Echo.class);
2    Echo service = (Echo) new XFireProxyFactory().create(serviceModel,
3        "http://localhost:8080/xfire-examples/EchoService");
4    String result = service.echo("ok");


 

posted on 2006-03-02 10:47 mmwy 阅读(11100) 评论(13)  编辑  收藏 所属分类: Others

评论

# re: xfire 1.0 终于final了 2006-03-02 14:36 江南白衣
axis也出axis2.0了,你还有回头是岸的机会呀。
  回复  更多评论
  

# re: xfire 1.0 终于final了 2006-04-21 14:13 hopeshared_lee
为啥我这样测试的结果是:
java.lang.VerifyError: (class: org/codehaus/xfire/aegis/type/basic/ObjectType, method: writeSchema signature: (Lorg/jdom/Element;)V) Incompatible argument to function
at org.codehaus.xfire.aegis.type.DefaultTypeMappingRegistry.createDefaultMappings(DefaultTypeMappingRegistry.java:294)
at org.codehaus.xfire.aegis.type.DefaultTypeMappingRegistry.<init>(DefaultTypeMappingRegistry.java:106)
at org.codehaus.xfire.aegis.type.DefaultTypeMappingRegistry.<init>(DefaultTypeMappingRegistry.java:95)
at org.codehaus.xfire.aegis.AegisBindingProvider.<init>(AegisBindingProvider.java:46)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:274)
at java.lang.Class.newInstance0(Class.java:308)
at java.lang.Class.newInstance(Class.java:261)
at org.codehaus.xfire.service.binding.ObjectServiceFactory.getBindingProvider(ObjectServiceFactory.java:144)
at org.codehaus.xfire.service.binding.ObjectServiceFactory.getInParameterName(ObjectServiceFactory.java:898)
at org.codehaus.xfire.service.binding.ObjectServiceFactory.addOperation(ObjectServiceFactory.java:683)
at org.codehaus.xfire.service.binding.ObjectServiceFactory.initializeOperations(ObjectServiceFactory.java:629)
at org.codehaus.xfire.service.binding.ObjectServiceFactory.create(ObjectServiceFactory.java:350)
at org.codehaus.xfire.service.binding.ObjectServiceFactory.create(ObjectServiceFactory.java:277)
at org.codehaus.xfire.service.binding.ObjectServiceFactory.create(ObjectServiceFactory.java:258)
at aa.CalculateHandler.getAddServiceResult(CalculateHandler.java:177)
at aa.CalculateHandler.start(CalculateHandler.java:33)
at aa.CalculateHandler.calculate(CalculateHandler.java:20)
at Test.main(Test.java:11)
Exception in thread "main"


?????????  回复  更多评论
  

# re: xfire 1.0 终于final了 2006-05-17 15:23 eureka
我在浏览器里看wsdl,返回下面的东东,谁能帮忙

500 Servlet Exception

javax.xml.stream.FactoryConfigurationError: Provider com.bea.xml.stream.MXParserFactory
not found
at javax.xml.stream.FactoryFinder.newInstance(FactoryFinder.java:72)
at javax.xml.stream.FactoryFinder.find(FactoryFinder.java:176)
at javax.xml.stream.FactoryFinder.find(FactoryFinder.java:92)
at javax.xml.stream.XMLInputFactory.newInstance(XMLInputFactory.java:136)
at org.codehaus.xfire.util.STAXUtils.<clinit>(STAXUtils.java:45)
at org.codehaus.xfire.util.jdom.StaxBuilder.<init>(StaxBuilder.java:150)
at org.codehaus.xfire.wsdl11.builder.AbstractWSDL.<clinit>(AbstractWSDL.java:50)
at org.codehaus.xfire.wsdl11.builder.DefaultWSDLBuilderFactory.createWSDLBuilder(DefaultWSDLBuilderFactory.java:25)
at org.codehaus.xfire.wsdl11.builder.WSDLBuilderAdapter.write(WSDLBuilderAdapter.java:40)
at org.codehaus.xfire.DefaultXFire.generateWSDL(DefaultXFire.java:116)
at org.codehaus.xfire.transport.http.XFireServletController.generateWSDL(XFireServletController.java:302)
at org.codehaus.xfire.transport.http.XFireServletController.doService(XFireServletController.java:141)
at org.codehaus.xfire.spring.remoting.XFireServletControllerAdapter.handleRequest(XFireServletControllerAdapter.java:63)
at org.codehaus.xfire.spring.remoting.XFireExporter.handleRequest(XFireExporter.java:44)
at org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:44)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:723)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:663)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:394)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:348)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:115)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:92)
at com.caucho.server.dispatch.ServletFilterChain.doFilter(ServletFilterChain.java:106)
at com.caucho.server.webapp.WebAppFilterChain.doFilter(WebAppFilterChain.java:178)
at com.caucho.server.dispatch.ServletInvocation.service(ServletInvocation.java:229)
at com.caucho.server.http.HttpRequest.handleRequest(HttpRequest.java:268)
at com.caucho.server.port.TcpConnection.run(TcpConnection.java:389)
at com.caucho.util.ThreadPool.runTasks(ThreadPool.java:492)
at com.caucho.util.ThreadPool.run(ThreadPool.java:425)
at java.lang.Thread.run(Thread.java:595)
  回复  更多评论
  

# re: xfire 1.0 终于final了 2006-07-19 17:09 david turing
hopeshared_lee, jdom版本不正确,download最新的jdom拉
基本上,我发现xfire除了快一些,真是一无是处
看看他的WS-Security的例子,也太烂了  回复  更多评论
  

# 请问怎么开发客户端阿 2006-10-31 23:50 敌对
sldfjs   回复  更多评论
  

# XFIRE CLENT 2006-10-31 23:54 敌对
是 不是服务器端开发完毕以后,输入命令java org.codehaus.xfire.gen.WsGen -wsdl
就可以生辰了CLIENT。郁闷好久了,还请你高手帮帮我这个XFIRE的晕虫  回复  更多评论
  

# re: xfire 1.0 终于final了 2006-11-01 16:36 mmwy
@敌对


我上面有介绍啊,如果是java来做client,可以象axis一样,从wsdl来生成client,也可以用Dynamic Client的办法来生成。

如果是vs.net、C# developer,可以用web references向导来生成client。

如果是delphi 7/2005/2006,有一个专门的wsdl importer可以生成client代码的。
  回复  更多评论
  

# re: xfire 1.0 终于final了 2006-11-22 11:34 ma
请问我测试这个例子为啥就遇到这个错误呢
2006-11-22 10:22:36,734 ERROR [org.codehaus.xfire.handler.DefaultFaultHandler] Fault occurred!
java.lang.IllegalArgumentException: prefix cannot be "null" when creating a QName
at javax.xml.namespace.QName.<init>(Unknown Source)
at com.bea.xml.stream.MXParser.getName(MXParser.java:1439)
at org.codehaus.xfire.soap.handler.ReadHeadersHandler.checkForFault(ReadHeadersHandler.java:107)
at org.codehaus.xfire.soap.handler.ReadHeadersHandler.invoke(ReadHeadersHandler.java:67)
at org.codehaus.xfire.handler.HandlerPipeline.invoke(HandlerPipeline.java:131)
at org.codehaus.xfire.transport.DefaultEndpoint.onReceive(DefaultEndpoint.java:64)


wsdl可以正确的看到  回复  更多评论
  

# re: xfire 1.0 终于final了 2006-11-22 11:39 ma
@ma
我用的是JBoss4.0.5  回复  更多评论
  

# re: xfire 1.0 终于final了 2007-05-14 11:33 咔咔
2007-05-14 11:21:59,203 ERROR [org.springframework.web.context.ContextLoader] - Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'xfire.customEditorConfigurer' defined in ServletContext resource [/WEB-INF/customEditors.xml]: Cannot create inner bean 'org.codehaus.xfire.spring.editors.ServiceFactoryEditor#1022de4' while setting bean property 'customEditors' with key [org.codehaus.xfire.service.ServiceFactory]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.codehaus.xfire.spring.editors.ServiceFactoryEditor#1022de4' defined in ServletContext resource [/WEB-INF/customEditors.xml]: Cannot resolve reference to bean 'xfire.transportManager' while setting bean property 'transportManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'xfire.transportManager' defined in ServletContext resource [/WEB-INF/xfire.xml]: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: javax/xml/stream/XMLStreamReader
Caused by:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.codehaus.xfire.spring.editors.ServiceFactoryEditor#1022de4' defined in ServletContext resource [/WEB-INF/customEditors.xml]: Cannot resolve reference to bean 'xfire.transportManager' while setting bean property 'transportManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'xfire.transportManager' defined in ServletContext resource [/WEB-INF/xfire.xml]: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: javax/xml/stream/XMLStreamReader
Caused by:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'xfire.transportManager' defined in ServletContext resource [/WEB-INF/xfire.xml]: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: javax/xml/stream/XMLStreamReader
Caused by:
java.lang.NoClassDefFoundError: javax/xml/stream/XMLStreamReader
at org.codehaus.xfire.soap.SoapTransportHelper.<clinit>(SoapTransportHelper.java:24)
at org.codehaus.xfire.transport.local.LocalTransport.<init>(LocalTransport.java:33)
……
我这是怎么回事呀  回复  更多评论
  

# re: xfire 1.0 终于final 2007-08-08 10:48 ooo
iopioopio  回复  更多评论
  

# re: xfire 1.0 终于final了 2008-08-08 12:22 njwyj
@eureka
下载jsr173.jar里面的jsr173_1.0_ri.jar包放到lib里就可以了
  回复  更多评论
  

# 关于MXParserFactory异常 2009-09-15 21:26 qianyuanyuan
对于:javax.xml.stream.FactoryConfigurationError: Provider com.bea.xml.stream.MXParserFactory
not found 错误,我今天刚刚也遇到了。我不是太清楚是怎么回事,但是加入了wstx-asl-3.0.1.jar时,问题就不出现了。大家可以试试。  回复  更多评论
  


只有注册用户登录后才能发表评论。


网站导航: