我是靠谱客的博主 害怕时光,最近开发中收集的这篇文章主要介绍Java中使用Aixs开发Webservice,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

  现在项目中大量应用了Webservice技术,与别的核心系统交互。之前没有用过Webservice,所以,了解下,做了个测试的例子。

  在Java中开发Webservice可以使用很多的框架,我们使用的Aixs。

     需要的包如下:

activation.jar

axis.jar

 

commons-discovery-0.2.jar

commons-logging-1.0.4.jar

jaxrpc.jar

mail.jar

saaj.jar

wsdl4j-1.5.1.jar

 

服务器端:建立接口和实现类:

接口类:

 

package server;

import java.rmi.Remote;

import com.cpic.b2bcore.externalinterface.wss.type.MusterCollectRequest;
import com.cpic.b2bcore.externalinterface.wss.type.MusterCollectResponse;

public interface ISayHello extends Remote {
	
	public MusterCollectResponse getPolicyInfo(MusterCollectRequest mrequest)throws java.rmi.RemoteException;

}

 

 实现类:

package server;

import java.rmi.RemoteException;

import com.cpic.b2bcore.externalinterface.wss.type.MusterCollectRequest;
import com.cpic.b2bcore.externalinterface.wss.type.MusterCollectResponse;

public class SayHello implements ISayHello {
	
	public MusterCollectResponse getPolicyInfo(MusterCollectRequest mrequest)
			throws RemoteException {
		// TODO Auto-generated method stub
		MusterCollectResponse mresponse = new MusterCollectResponse();
		mresponse.setPublicpolicies(null);
		return mresponse;
	}

}

 

 

 

可以看出,这里传入参数和返回参数都是自定义对象,属于较为复杂的 service。

 

需要 在web.xml 里面加入 AXIS 的配置参数。。

 

  <display-name>Apache-Axis</display-name>    
    <listener>
        <listener-class>org.apache.axis.transport.http.AxisHTTPSessionListener</listener-class>
    </listener>
    
  <servlet>
    <servlet-name>AxisServlet</servlet-name>
    <servlet-class>
        org.apache.axis.transport.http.AxisServlet
    </servlet-class>
  </servlet>

  <servlet>
    <servlet-name>AdminServlet</servlet-name>
    <servlet-class>
        org.apache.axis.transport.http.AdminServlet
    </servlet-class>
    <load-on-startup>100</load-on-startup>
  </servlet>

  <servlet>
    <servlet-name>SOAPMonitorService</servlet-name>
    <servlet-class>
        org.apache.axis.monitor.SOAPMonitorService
    </servlet-class>
    <init-param>
      <param-name>SOAPMonitorPort</param-name>
      <param-value>5001</param-value>
    </init-param>
    <load-on-startup>100</load-on-startup>
  </servlet>
  <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>SOAPMonitorService</servlet-name>
    <url-pattern>/SOAPMonitor</url-pattern>
  </servlet-mapping>

 <mime-mapping>
    <extension>wsdl</extension>
     <mime-type>text/xml</mime-type>
  </mime-mapping>

  <mime-mapping>
    <extension>xsd</extension>
    <mime-type>text/xml</mime-type>
  </mime-mapping>
	

 

 

编辑 wsdd 文件,用以生成 配置文件

 

<!-- Use this file to deploy some handlers/chains and services      -->
<!-- Two ways to do this:                                           -->
<!--   java org.apache.axis.client.AdminClient deploy.wsdd          -->
<!--      after the axis server is running                          -->
<!-- or                                                             -->
<!--   java org.apache.axis.utils.Admin client|server deploy.wsdd   -->
<!--      from the same directory that the Axis engine runs         -->

<deployment
    xmlns="http://xml.apache.org/axis/wsdd/"
    xmlns:java="http://xml.apache.org/axis/wsdd/providers/java">

  <!-- Services from YwxCommonService WSDL service -->

  <service name="PolicyInfoService" provider="java:RPC" style="wrapped" use="literal">
      <parameter name="className" value="server.SayHello"/>
      <parameter name="allowedMethods" value="getPolicyInfo"/>
      
      <parameter name="wsdlTargetNamespace" value="http://wss.cpic.com.cn/propertyinsurance/commonservice/ywx"/>
      <parameter name="schemaQualified" value="http://wss.cpic.com.cn/propertyinsurance/commonservice/ywx,http://wss.cpic.com.cn/propertyinsurance/commonservice/ywx/types"/>
      
      <parameter name="wsdlServiceElement" value="PolicyInfoService"/>
      <parameter name="wsdlServicePort" value="PolicyInfoService"/>
      <parameter name="wsdlPortType" value="PolicyInfoCommService"/>
      
      <parameter name="typeMappingVersion" value="1.2"/>
      
      <operation name="getPolicyInfo" qname="operNS:getPolicyInfo" 
      xmlns:operNS="http://wss.cpic.com.cn/propertyinsurance/commonservice/ywx" 
      returnQName="retNS:musterCollectResponse" xmlns:retNS="http://wss.cpic.com.cn/propertyinsurance/commonservice/ywx" 
      returnType="rtns:MusterCollectResponse" xmlns:rtns="http://wss.cpic.com.cn/propertyinsurance/commonservice/ywx/types" soapAction="" >
        <parameter qname="pns:musterCollectRequest" xmlns:pns="http://wss.cpic.com.cn/propertyinsurance/commonservice/ywx" type="tns:MusterCollectRequest" xmlns:tns="http://wss.cpic.com.cn/propertyinsurance/commonservice/ywx/types"/>
      </operation>
      <typeMapping
        xmlns:ns="http://wss.cpic.com.cn/propertyinsurance/commonservice/ywx/types"
        qname="ns:MusterCollectRequest"
        type="java:com.cpic.b2bcore.externalinterface.wss.type.MusterCollectRequest"
        serializer="org.apache.axis.encoding.ser.BeanSerializerFactory"
        deserializer="org.apache.axis.encoding.ser.BeanDeserializerFactory"
        encodingStyle=""
      />  
      <typeMapping
        xmlns:ns="http://wss.cpic.com.cn/propertyinsurance/commonservice/ywx/types"
        qname="ns:MusterCollectResponse"
        type="java:com.cpic.b2bcore.externalinterface.wss.type.MusterCollectResponse"
        serializer="org.apache.axis.encoding.ser.BeanSerializerFactory"
        deserializer="org.apache.axis.encoding.ser.BeanDeserializerFactory"
        encodingStyle=""
      />
  </service>
</deployment>

 

用于执行部署的批处理脚本:

 @echo off
set AXIS_HOME=D:workspacetestServicesWebRootWEB-INF
rem set AXIS_HOME

cd %AXIS_HOME%
rem echo current dir=%cd%

set JAVA_HOME=D:MyEclipse 6.5jre

rem set JAVA_HOME

set CLASSPATH=%JAVA_HOME%libtools.jar
set CLASSPATH=.;%CLASSPATH%
set CLASSPATH=%CLASSPATH%;%AXIS_HOME%WebRootWEB-INFlibactivation.jar
set CLASSPATH=%CLASSPATH%;%AXIS_HOME%WebRootWEB-INFlibaxis.jar
set CLASSPATH=%CLASSPATH%;%AXIS_HOME%WebRootWEB-INFlibaxis-ant.jar
set CLASSPATH=%CLASSPATH%;%AXIS_HOME%WebRootWEB-INFlibcommons-discovery-0.2.jar
set CLASSPATH=%CLASSPATH%;%AXIS_HOME%WebRootWEB-INFlibcommons-logging-1.0.4.jar
set CLASSPATH=%CLASSPATH%;%AXIS_HOME%WebRootWEB-INFlibjaxrpc.jar
set CLASSPATH=%CLASSPATH%;%AXIS_HOME%WebRootWEB-INFliblog4j-1.2.8.jar
set CLASSPATH=%CLASSPATH%;%AXIS_HOME%WebRootWEB-INFlibmail.jar
set CLASSPATH=%CLASSPATH%;%AXIS_HOME%WebRootWEB-INFlibsaaj.jar
set CLASSPATH=%CLASSPATH%;%AXIS_HOME%WebRootWEB-INFlibwsdl4j-1.5.1.jar
rem set CLASSPATH

set _RUNJAVA="%JAVA_HOME%binjava"
set _RUNJAVAW="%JAVA_HOME%binjavaw"
set _RUNJDB="%JAVA_HOME%binjdb"
set _RUNJAVAC="%JAVA_HOME%binjavac"
set OUTPUT_PATH=%AXIS_HOME%src

echo 开始执行wsddjava...

java -Djava.ext.dirs=lib org.apache.axis.client.AdminClient -l http://localhost:8080/testServices/services/PolicyInfoService deploy.wsdd

echo ...执行wsdd  java完成
pause

 

执行该批处理文件,顺利完成后,部署成功。

 

 

客户端的生成 见另外的 一篇 博客 。。 

最后

以上就是害怕时光为你收集整理的Java中使用Aixs开发Webservice的全部内容,希望文章能够帮你解决Java中使用Aixs开发Webservice所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(62)

评论列表共有 0 条评论

立即
投稿
返回
顶部