日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 前端技术 > javascript >内容正文

javascript

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

發布時間:2024/9/27 javascript 36 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Spring4.x整合Axis1.4发布WebService服务 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

Spring4.x整合Axis1.4發布WebService服務

文章目錄

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

一、服務端部署

1. 在web.xml文件中添加映射路徑和spring監聽

<!-- 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><!-- 接口調用的后續路徑設置 --><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監控如果不添加,服務發布正常,可以省略
2、文件中的掃描文件路徑根據項目具體位置而定

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默認是接口實現類的類名小寫,也可以小寫 自定義
2、 在web.xml配置文件中要配置spring監聽

<?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><!—北京接口服務 start--><service name="GblfyCommonServiceShell" provider="java:RPC"><parameter name="allowedMethods" value="*" /><parameter name="className"value="com.gblfy.controller.webservice.GblfyCommonServiceShell" /></service><!—北京接口服務 end--> </deployment>


只修改截圖部分即可!

4. 對外發布服務外殼類

  • 添加與server-config.wsdd配置文件,相對應對外發布服務外殼類
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 {/*** 北京業務接口* * @param xml* @return* @throws Exception*/public String webServiceForBJ(String tReqXml) throws Exception; }

6. 添加接口邏輯實現類

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 "接收到服務了!!!";} }

7. 瀏覽器測試

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

二、客戶端部署

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

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 = "客戶端調用webservice服務方成功了!!!";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 請求報文* @return resXml 響應報文* @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("轉發路徑標志==" + subUrl.substring(1, subUrl.length()));// 針對北京業務添加判斷,針對服務端有@Webservice 注解,有明確的參數因此,需要在客戶端設置此設置// if判斷 針對某個webservice服務 默認不走判斷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));// 這是要調用的方法resXml = (String) call.invoke(new Object[] { tReqXml.toString() });return resXml;}}


2.2 運行main方法測試

控制臺輸出

轉發路徑標志==WebServiceShell?wsdl %%%%%%%%%$$$$$接收到服務了!!!

三、多接口服務發布

3.1 server-config.wsdd 添加服務

3.2 添加對外暴露的外殼類

3.3 添加服務接口

3.4 添加服務接口邏輯處理類

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

3.6 發布服務

3.7 支持多個發布路徑

在web.xml文件中

  • 默認 /services/*
  • 新增加/gblfy/services/*

本文源碼下載:

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

總結

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

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。