最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

java使用xfire搭建webservice服務(wù)的過(guò)程詳解

 更新時(shí)間:2020年07月15日 11:47:08   作者:經(jīng)典雞翅  
這篇文章主要介紹了java使用xfire搭建webservice服務(wù)的過(guò)程。使用xfire搭建webService的服務(wù),可以在瀏覽器訪問(wèn)。對(duì)此感興趣的可以了解一下

前言

以前用的都是 apache 的cxf來(lái)搞webservice,今天做項(xiàng)目發(fā)現(xiàn)這個(gè)項(xiàng)目用的是 xfire,于是搭一個(gè),寫個(gè)demo用一下,在此記錄一下過(guò)程。

搭建過(guò)程

本文使用的是maven形式的web工程。不知道如何搭建web工程的看上一篇博文。

引入xfire的依賴

<dependency>
  <groupId>org.codehaus.xfire</groupId>
  <artifactId>xfire-all</artifactId>
  <version>1.2.6</version>
</dependency>

配置web.xml

 <servlet>
  <servlet-name>XFireServlet</servlet-name>
  <servlet-class>org.codehaus.xfire.transport.http.XFireConfigurableServlet</servlet-class>
  <init-param>
   <param-name>config</param-name>
   <param-value>/xfire/services.xml</param-value>
  </init-param>
 </servlet>
 <servlet-mapping>
  <servlet-name>XFireServlet</servlet-name>
  <url-pattern>/services/*</url-pattern>
 </servlet-mapping>

編寫接口

public interface HelloService {
 public String helloService();
}

編寫實(shí)現(xiàn)類

public class HelloServiceImpl implements HelloService {
 public String helloService() {
  return "1111";
 }
}

配置xfire的services的配置文件

該配置文件通過(guò)查看源碼,默認(rèn)在META-INF下的xfire的services.xml。我將目錄放在了resource下,去掉了META-INF??赏ㄟ^(guò)上方的web.xml配置文件的地址。上方有例子。

<?xml version="1.0" encoding="UTF-8"?>
<beans>
 <service xmlns="http://xfire.codehaus.org/config/1.0">
  <name>webService</name>
  <namespace>http://jichi.com/</namespace>
  <serviceClass>com.HelloService</serviceClass>
  <implementationClass>com.HelloServiceImpl</implementationClass>
 </service>
</beans>

編寫一個(gè)訪問(wèn)webservice的方法

public static Object processWsMethod(String url,String methodName,Object ... params){
		Object result = null;
		try {
			if(!url.endsWith("?wsdl")){
				url += "?wsdl";
			}
			URL urls = new URL(url);
			Client client = new Client(urls);
			Object[] results = client.invoke(methodName,params);
			if(results!=null){
				if(results.length==1)
					result = results[0];
				else
					result = results;
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return result;
	}

編寫測(cè)試方法

 @Test
 public void testMyWebService(){
  String aa = (String) WebServiceUtil.processWsMethod("http://localhost:8080/services/webService", "helloService");
  System.out.println(aa);
 }

結(jié)果

控制臺(tái)打印111.搭建成功。

到此這篇關(guān)于使用xfire搭建webservice服務(wù)的過(guò)程詳解的文章就介紹到這了,更多相關(guān)使用xfire搭建webservice服務(wù)內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評(píng)論

南投市| 岢岚县| 定结县| 福州市| 石楼县| 句容市| 全南县| 闽清县| 肇东市| 满洲里市| 聊城市| 西昌市| 邵阳市| 团风县| 黑水县| 高青县| 中超| 洪雅县| 三明市| 湘西| 南江县| 慈溪市| 磴口县| 车险| 台湾省| 拉孜县| 抚松县| 璧山县| 鄂伦春自治旗| 黄龙县| 桦川县| 石门县| 平谷区| 长沙市| 宜君县| 黑山县| 灵璧县| 双牌县| 甘孜县| 华坪县| 墨玉县|