Axis2优劣:
现在用axis2开发一个webservice工程,虽说是webservice的一个新框架,但我并没有发现他有多么的好用,反而遇到了很多麻烦的问题:
1、axis2不支持事务。
对数据库增删改查一般都需要事务处理的,但是在对外发布的接口中是不能配置事务的。
解决方法:或者写一个代理类或者直接在dao中进行事务管理。
2、axis2不支持方法重载。
在对外发布的接口中不能使用方法重载,
[WARN] We don't support method overloading. Ignoring [updateClassifyTask]
[WARN] We don't support method overloading. Ignoring [updateClassifyTask]
[WARN] We don't support method overloading. Ignoring [updateClassifyTask]
如果你写了多个重名的方法,在该service中只会注册一个。
解决方法:无。要么更改成不同的方法名要么在传参上想办法
3、AXIS2 1.4.1 does not support java.util.Date type
Time portion of java.util.Date is missing from SOAP response in Axis2 1.5
瞧瞧axis2 的这些个bug,使用起来太不方便了。
虽然Apache的官方网站的bug页上有解决方案,但是我把DateServuce。aar文件考下来后仍然报相同的错误:
[ERROR] date string can not be less than 19 charactors
Caused by: java.lang.NumberFormatException: date string can not be less than 19 charactors
也不知道是怎么个意思,是把日期转换一下吗?好郁闷- - !
Axis2 1.5只能返回日期部分,时间部分丢失了!
解决方法:把Date类型都改成String类型的,这样是最安全的,但可能跟要求不符,应该不能算是一个好的解决方案吧。
4、axis2不能传递list类型的数据集合。
解决方法:将list转换成数组类型。这个还不算麻烦吧。
package com.etrip.axis2; import java.io.Serializable; /** * * @Title: TODO * @Description: 实现TODO * @Copyright:Copyright (c) 2011 * @Company: * @Date:2012-12-29 * @author * @version 1.0 */ public class User implements Serializable { private static final long serialVersionUID = 1L; private int id; private String name; private String address; private String email; public int getId() { return id; } public void setId(int id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getAddress() { return address; } public void setAddress(String address) { this.address = address; } public String getEmail() { return email; } public void setEmail(String email) { this.email = email; } }
package com.etrip.axis2; import java.util.ArrayList; import java.util.List; import org.springframework.stereotype.Service; /** * * @Title: TODO * @Description: 实现TODO * @Copyright:Copyright (c) 2011 * @Company * @Date:2012-12-24 * @author * @version 1.0 */ @Service public class UserService { /** * 传递数组 * @return */ public String[][] getTwoArray() { return new String[][] { { "中国", "北京" }, { "日本", "东京" }}; } /** * 传递非字符串 * @param b * @param len * @return */ public String upload4Byte(byte[] b, int len) { return String.valueOf(b)+len; } /** * 传递字符串 * @param userName * @return */ public String hello(String userName){ return "Hello ,"+userName; } /** * 传输对象 * @return */ public User getUer() { User user = new User(); user.setAddress("JingsanRoad"); user.setEmail("[email protected]"); user.setName("spark"); user.setId(2); return user; } }
spring-app-context.xml
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:flex="http://www.springframework.org/schema/flex" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/flex http://www.springframework.org/schema/flex/spring-flex-1.5.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd"> <context:component-scan base-package="*" /> <context:annotation-config/> <bean id="applicationContext" class="org.apache.axis2.extensions.spring.receivers.ApplicationContextHolder" /> </beans>
WebContent/WEB-INF/services/axis/META-INF/services.xml
<?xml version="1.0" encoding="UTF-8"?> <service name="userService"> <parameter name="ServiceObjectSupplier"> org.apache.axis2.extensions.spring.receivers.SpringAppContextAwareObjectSupplier </parameter> <parameter name="load-on-startup">true</parameter> <parameter name="SpringBeanName">userService</parameter> <messageReceivers> <messageReceiver mep="http://www.w3.org/2004/08/wsdl/in-only" class="org.apache.axis2.rpc.receivers.RPCInOnlyMessageReceiver" /> <messageReceiver mep="http://www.w3.org/2004/08/wsdl/in-out" class="org.apache.axis2.rpc.receivers.RPCMessageReceiver" /> </messageReceivers> </service>
web.xml
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5"> <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:spring/spring-*.xml </param-value> </context-param> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <listener> <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class> </listener> <display-name>Axis2SpringWS</display-name> <servlet> <servlet-name>AxisServlet</servlet-name> <servlet-class>org.apache.axis2.transport.http.AxisServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>AxisServlet</servlet-name> <url-pattern>/services/*</url-pattern> </servlet-mapping> <welcome-file-list> <welcome-file>index.html</welcome-file> <welcome-file>index.htm</welcome-file> <welcome-file>index.jsp</welcome-file> <welcome-file>default.html</welcome-file> <welcome-file>default.htm</welcome-file> <welcome-file>default.jsp</welcome-file> </welcome-file-list> <servlet> <display-name>Axis Admin Servlet</display-name> <servlet-name>AdminServlet</servlet-name> <servlet-class>org.apache.axis.transport.http.AdminServlet</servlet-class> <load-on-startup>100</load-on-startup> </servlet> <servlet-mapping> <servlet-name>AdminServlet</servlet-name> <url-pattern>/servlet/AdminServlet</url-pattern> </servlet-mapping> </web-app>
weblogic.xml
<?xml version="1.0" encoding="UTF-8"?> <wls:weblogic-web-app xmlns:wls="http://xmlns.oracle.com/weblogic/weblogic-web-app" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd http://xmlns.oracle.com/weblogic/weblogic-web-app http://xmlns.oracle.com/weblogic/weblogic-web-app/1.3/weblogic-web-app.xsd"> <wls:weblogic-version>10.3.6</wls:weblogic-version> <wls:context-root>Axis2SpringWS</wls:context-root> <wls:container-descriptor> <wls:prefer-web-inf-classes>true</wls:prefer-web-inf-classes> </wls:container-descriptor> </wls:weblogic-web-app>
详细参考:
http://axis.apache.org/axis2/java/core/docs/spring.html
http://axis.apache.org/axis2/java/core/docs/pojoguide.html
http://axis.apache.org/axis2/java/core/docs/jaxws-guide.html