日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) >

Spring4.x整合Axis1.4发布WebService服务

發(fā)布時(shí)間:2024/9/27 47 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Spring4.x整合Axis1.4发布WebService服务 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

Spring4.x整合Axis1.4發(fā)布WebService服務(wù)

文章目錄

  • 一、服務(wù)端部署
    • 1. 在web.xml文件中添加映射路徑和spring監(jiān)聽(tīng)
    • 2. 添加spring-axis.xml配置文件
    • 3. 添加server-config.wsdd配置文件
    • 4. 對(duì)外發(fā)布服務(wù)外殼類
    • 5. 添加接口類
    • 6. 添加接口邏輯實(shí)現(xiàn)類
    • 7. 瀏覽器測(cè)試
  • 二、客戶端部署
    • 2.1 axis1.4 工具類封裝(企業(yè)版本)
    • 2.2 運(yùn)行main方法測(cè)試
  • 三、多接口服務(wù)發(fā)布
    • 3.1 server-config.wsdd 添加服務(wù)
    • 3.2 添加對(duì)外暴露的外殼類
    • 3.3 添加服務(wù)接口
    • 3.4 添加服務(wù)接口邏輯處理類
    • 3.5 在spring-axis.xml 添加本地bean
    • 3.6 發(fā)布服務(wù)
    • 3.7 支持多個(gè)發(fā)布路徑
    • 本文源碼下載:

一、服務(wù)端部署

1. 在web.xml文件中添加映射路徑和spring監(jiān)聽(tīng)

<!-- webservices接口 axis 需要引入的 Servlet Start --><servlet><servlet-name>AxisServlet</servlet-name><servlet-class>org.apache.axis.transport.http.AxisServlet</servlet-class></servlet><servlet-mapping><servlet-name>AxisServlet</servlet-name><!-- 接口調(diào)用的后續(xù)路徑設(shè)置 --><url-pattern>/services/*</url-pattern></servlet-mapping><!-- webservices接口 axis 需要引入的 Servlet End --> <!-- 新增spring容器配置 Start --><listener><listener-class>org.springframework.web.context.ContextLoaderListener</listener-class></listener><context-param><param-name>contextConfigLocation</param-name><param-value>/WEB-INF/config/spring-*.xml</param-value></context-param><!-- 新增spring容器配置 End -->

注:
1、spring監(jiān)控如果不添加,服務(wù)發(fā)布正常,可以省略
2、文件中的掃描文件路徑根據(jù)項(xiàng)目具體位置而定

2. 添加spring-axis.xml配置文件

  • 文件名自定義即可,作用是本地bean
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-3.0.xsdhttp://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context-3.0.xsd"><bean id="nFisCommonWebServiceImpl" class="com.gblfy.service.impl.GblfyCommonWebServiceImpl" /> </beans>

注:
1、 id默認(rèn)是接口實(shí)現(xiàn)類的類名小寫(xiě),也可以小寫(xiě) 自定義
2、 在web.xml配置文件中要配置spring監(jiān)聽(tīng)

<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:context="http://www.springframework.org/schema/context"xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-3.0.xsdhttp://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context-3.0.xsd"><bean id="webServiceImpl"class="com.gblfy.axis.service.impl.WebServiceImpl" /> </beans>

3. 添加server-config.wsdd配置文件

<?xml version="1.0" encoding="UTF-8"?> <deployment xmlns="http://xml.apache.org/axis/wsdd/"xmlns:java="http://xml.apache.org/axis/wsdd/providers/java"><globalConfiguration><parameter name="adminPassword" value="admin" /><parameter name="sendXsiTypes" value="true" /><parameter name="sendMultiRefs" value="true" /><parameter name="sendXMLDeclaration" value="true" /><parameter name="axis.sendMinimizedElements" value="true" /><requestFlow><handler type="java:org.apache.axis.handlers.JWSHandler"><parameter name="scope" value="session" /></handler><handler type="java:org.apache.axis.handlers.JWSHandler"><parameter name="scope" value="request" /><parameter name="extension" value=".jwr" /></handler></requestFlow></globalConfiguration><handler name="Authenticate"type="java:org.apache.axis.handlers.SimpleAuthenticationHandler" /><handler name="LocalResponder"type="java:org.apache.axis.transport.local.LocalResponder" /><handler name="URLMapper"type="java:org.apache.axis.handlers.http.URLMapper" /><service name="AdminService" provider="java:MSG"><parameter name="allowedMethods" value="AdminService" /><parameter name="enableRemoteAdmin" value="false" /><parameter name="className"value="org.apache.axis.utils.Admin" /><namespace>http://xml.apache.org/axis/wsdd/</namespace></service><service name="Version" provider="java:RPC"><parameter name="allowedMethods" value="getVersion" /><parameter name="className" value="org.apache.axis.Version" /></service><transport name="http"><requestFlow><handler type="URLMapper" /><handlertype="java:org.apache.axis.handlers.http.HTTPAuthHandler" /></requestFlow></transport><transport name="local"><responseFlow><handler type="LocalResponder" /></responseFlow></transport><!—北京接口服務(wù) start--><service name="GblfyCommonServiceShell" provider="java:RPC"><parameter name="allowedMethods" value="*" /><parameter name="className"value="com.gblfy.controller.webservice.GblfyCommonServiceShell" /></service><!—北京接口服務(wù) end--> </deployment>


只修改截圖部分即可!

4. 對(duì)外發(fā)布服務(wù)外殼類

  • 添加與server-config.wsdd配置文件,相對(duì)應(yīng)對(duì)外發(fā)布服務(wù)外殼類
package com.gblfy.axis.controller;import javax.xml.rpc.ServiceException;import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationContext; import org.springframework.remoting.jaxrpc.ServletEndpointSupport;import com.gblfy.axis.service.IWebService;public class WebServiceShell extends ServletEndpointSupport {@Autowiredprivate ApplicationContext applicationContext;@Autowiredprivate IWebService iWebService;// 注入bean@Overrideprotected void onInit() throws ServiceException {// 初始化Spirng 配置applicationContext = super.getApplicationContext();iWebService = (IWebService) applicationContext.getBean("webServiceImpl");}public String webServiceForBJ(String tReqXml) throws Exception {return iWebService.webServiceForBJ(tReqXml);} }

5. 添加接口類

package com.gblfy.axis.service;public interface IWebService {/*** 北京業(yè)務(wù)接口* * @param xml* @return* @throws Exception*/public String webServiceForBJ(String tReqXml) throws Exception; }

6. 添加接口邏輯實(shí)現(xiàn)類

package com.gblfy.axis.service.impl;import com.gblfy.axis.service.IWebService;public class WebServiceImpl implements IWebService {@Overridepublic String webServiceForBJ(String tReqXml) throws Exception {return "接收到服務(wù)了!!!";} }

7. 瀏覽器測(cè)試

效果圖截圖:
http://localhost:8081/spring-axis/services/WebServiceShell?wsdl

二、客戶端部署

2.1 axis1.4 工具類封裝(企業(yè)版本)

package com.gblfy.axis.utils;import java.net.MalformedURLException;import javax.xml.namespace.QName; import javax.xml.rpc.ParameterMode; import javax.xml.rpc.ServiceException;import org.apache.axis.client.Call; import org.apache.axis.client.Service; import org.apache.ibatis.javassist.tools.rmi.RemoteException;/*** webService客戶端*/ public class WebServiceClientUtil {public static void main(String[] args) throws MalformedURLException, RemoteException, ServiceException, Exception {String url = "http://localhost:8081/spring-axis/services/WebServiceShell?wsdl";String namespace = "http://localhost:8081/spring-axis/services/WebServiceShell?wsdl";String method = "webServiceForBJ";String tReqXml = "客戶端調(diào)用webservice服務(wù)方成功了!!!";WebServiceClientUtil a = new WebServiceClientUtil();String dataResponse = a.RequestToResponse(url, namespace, method, tReqXml);System.out.println("%%%%%%%%%$$$$$" + dataResponse);}/*** * @param url WebService地址* @param namespace 命名空間* @param method 方法* @param tReqXml 請(qǐng)求報(bào)文* @return resXml 響應(yīng)報(bào)文* @throws ServiceException* @throws MalformedURLException* @throws RemoteException* @throws Exception*/public String RequestToResponse(String url, String namespace, String method, String tReqXml)throws ServiceException, MalformedURLException, RemoteException, Exception {Service service = new Service();Call call;String resXml = null;call = (Call) service.createCall();call.setTargetEndpointAddress(new java.net.URL(url));String subUrl = url.substring(url.lastIndexOf("/"));System.out.println("轉(zhuǎn)發(fā)路徑標(biāo)志==" + subUrl.substring(1, subUrl.length()));// 針對(duì)北京業(yè)務(wù)添加判斷,針對(duì)服務(wù)端有@Webservice 注解,有明確的參數(shù)因此,需要在客戶端設(shè)置此設(shè)置// if判斷 針對(duì)某個(gè)webservice服務(wù) 默認(rèn)不走判斷if ("BJServiceForClaim".equals(subUrl.substring(1, subUrl.length()))) {call.addParameter("xmlStr", org.apache.axis.Constants.XSD_STRING, ParameterMode.IN);call.setReturnType(org.apache.axis.Constants.XSD_STRING);}call.setOperationName(new QName(namespace, method));// 這是要調(diào)用的方法resXml = (String) call.invoke(new Object[] { tReqXml.toString() });return resXml;}}


2.2 運(yùn)行main方法測(cè)試

控制臺(tái)輸出

轉(zhuǎn)發(fā)路徑標(biāo)志==WebServiceShell?wsdl %%%%%%%%%$$$$$接收到服務(wù)了!!!

三、多接口服務(wù)發(fā)布

3.1 server-config.wsdd 添加服務(wù)

3.2 添加對(duì)外暴露的外殼類

3.3 添加服務(wù)接口

3.4 添加服務(wù)接口邏輯處理類

3.5 在spring-axis.xml 添加本地bean

3.6 發(fā)布服務(wù)

3.7 支持多個(gè)發(fā)布路徑

在web.xml文件中

  • 默認(rèn) /services/*
  • 新增加/gblfy/services/*

本文源碼下載:

鏈接https://pan.baidu.com/s/1fVe3Fq_n4Ru9CHG_XCXVOg
提取碼0iv1

總結(jié)

以上是生活随笔為你收集整理的Spring4.x整合Axis1.4发布WebService服务的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。