解决方案自己摸索到了 还是谢谢上面各位的热心帮忙,下面说说我的解决方案
首先在我的pom.xml中加入几个解析包:
[code="java"]
soap
axis
1.1.0
<dependency>
<groupId>soap</groupId>
<artifactId>jaxrpc</artifactId>
<version>1.1.0</version>
</dependency>
<dependency>
<groupId>soap</groupId>
<artifactId>saaj</artifactId>
<version>1.1.0</version>
</dependency>
<dependency>
<groupId>soap</groupId>
<artifactId>wsdl4j</artifactId>
<version>1.6.1</version>
</dependency>
<dependency>
<groupId>commons-discovery</groupId>
<artifactId>commons-discovery</artifactId>
<version>0.4</version>
</dependency>[/code]
然后在我的 web.xml中增加如下配置:
[code="java"]
WebServices
org.apache.axis.transport.http.AxisServlet
SOAPMonitorService
org.apache.axis.monitor.SOAPMonitorService
SOAPMonitorPort
5001
100
AdminServlet
org.apache.axis.transport.http.AdminServlet
100
AxisServlet
org.apache.axis.transport.http.AxisServlet
<servlet-mapping>
<servlet-name>SOAPMonitorService</servlet-name>
<url-pattern>/SOAPMonitor</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>AxisServlet</servlet-name>
<url-pattern>/servlet/AxisServlet</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>AxisServlet</servlet-name>
<url-pattern>*.jws</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>AxisServlet</servlet-name>
<url-pattern>/services/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>WebServices</servlet-name>
<url-pattern>*.jws</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>WebServices</servlet-name>
<url-pattern>/WebServices/*</url-pattern>
</servlet-mapping>[/code]
在 web.xml 同等目录增加 server-config.wsdd 的wsdd解析文件
[code="java"]<?xml version="1.0" encoding="UTF-8"?>
xmlns:java="http://xml.apache.org/axis/wsdd/providers/java">
value="true" />
type="java:org.apache.axis.handlers.JWSHandler">
type="java:org.apache.axis.handlers.JWSHandler">
type="java:org.apache.axis.transport.local.LocalResponder" />
type="java:org.apache.axis.handlers.http.URLMapper" />
type="java:org.apache.axis.handlers.SimpleAuthenticationHandler" />
type="java:org.apache.axis.handlers.http.HTTPAuthHandler" />
type="java:org.apache.axis.handlers.http.HTTPAuthHandler" />
http://xml.apache.org/axis/wsdd/
<service name="BusiLink" provider="java:RPC">
<parameter name="allowedMethods" value="*" />
<requestFlow>
</requestFlow>
<parameter name="className"
value="com.***.sp.soap.service.impl.BusiLinkImpl" />
<parameter name="scope" value="Request" />
<namespace>webservice.***.com</namespace>
</service>
<transport name="http">
<requestFlow name="RequestFlow1">
<handler name="Handler1" type="URLMapper" />
<handler name="Handler2"
type="java:org.apache.axis.handlers.http.HTTPAuthHandler" />
</requestFlow>
<parameter name="qs:list"
value="org.apache.axis.transport.http.QSListHandler" />
<parameter name="qs:wsdl"
value="org.apache.axis.transport.http.QSWSDLHandler" />
<parameter name="qs:method"
value="org.apache.axis.transport.http.QSMethodHandler" />
</transport>
<transport name="local">
<responseFlow name="ResponseFlow1">
<handler name="Handler1" type="LocalResponder" />
</responseFlow>
</transport>
[/code]
由于我已经实现了业务实体pojo在struts2下的解析 所以这里直接以struts2中的action bean来实现webservice 的接口调用,相关代码如下:
[code="java"]import java.io.Serializable;
import java.rmi.RemoteException;
/**
- @author towne
- @version 创建时间:2009-6-12 下午03:14:06
- 类说明
/
public interface BusiLink extends Serializable {
/*
*方法名:QueryYijianList (String businessid)
*说 明:根据记录的业务编号 获取审批意见
*输 入:该记录的业务编号 businessid(String)从接口3获取
*返 回:String(XML)
- @throws RemoteException
*/
String QueryYijianList (String businessid) throws RemoteException;
}[/code]
[code="java"]import java.io.StringWriter;
import java.rmi.RemoteException;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import javax.xml.rpc.ServiceException;
import org.springframework.remoting.jaxrpc.ServletEndpointSupport;
import com.***.sp.soap.service.BusiLink;
import com.***.sp.web.struts2.BusiLinkAction;
import com.***.sp.web.struts2.DataRow;
import com.***.sp.web.struts2.SpBaseAction;
import com.***.sp.web.struts2.SpResult;
import com.***.sp.web.struts2.Table1;
import com.thoughtworks.xstream.XStream;
/**
- @author towne
- @version 创建时间:2009-6-12 下午03:19:14
-
类说明
*/
public class BusiLinkImpl extends ServletEndpointSupport implements BusiLink {
BusiLinkAction action;
protected void onInit() throws ServiceException{
action = (BusiLinkAction)getApplicationContext().getBean("spBusiLinkAction");
}
public String QueryYijianList(String businessid) throws RemoteException{
action.setBusinessid(businessid);
action.QueryYijianList();
return toXML(action.getResult());
}
public String toXML(SpResult sr){
XStream xstream = new XStream();
xstream.alias("result",SpResult.class);
xstream.alias("DataRow",DataRow.class);
xstream.useAttributeFor(DataRow.class, "id");
xstream.addImplicitCollection(DataRow.class, "bean");//去掉集合类型生成xml的父节点
xstream.addImplicitCollection(Table1.class, "list");
xstream.useAttributeFor(SpResult.class, "pageCount");
xstream.useAttributeFor(SpResult.class, "userId");
xstream.useAttributeFor(SpResult.class, "pageIndex");
xstream.useAttributeFor(SpResult.class, "typeId");
xstream.useAttributeFor(Table1.class, "name");
xstream.useAttributeFor(DataRow.class, "id");
StringWriter writer = new StringWriter();
xstream.toXML(sr,writer);
return writer.toString();
}
}[/code]
这样 开启jetty,测试:
[code="java"] public void test6656(){
try{
String wsdlUrl = "http://localhost:999/sp2/services/BusiLink?wsdl";
String nameSpaceUri = "http://localhost:999/sp2/services/BusiLink";
// 创建调用对象
Service service = new Service();
Call call = null;
call = (Call) service.createCall();
// 调用 getMessage
System.out.println(">>>getMessage");
call.setOperationName(new QName(nameSpaceUri, "QueryYijianList"));
call.setTargetEndpointAddress(new java.net.URL(wsdlUrl));
String ret = (String) call.invoke(new Object[] {"0906120093901990001"});
System.out.println("return value is " + ret);
} catch (Exception e) {
e.printStackTrace();
}
}[/code]
测试通过 产生需要的xml文件 从而使该系统即支持struts2的调用 也支持webservice的调用 同时支持xml,json,jsp 从而真正达到平台无关性
/**
ps:这分就加给自己吧 我也不客气了
*/