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

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

mule 基于wsdl调用cxf web service

發布時間:2024/9/27 编程问答 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 mule 基于wsdl调用cxf web service 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

最近看mule的一個文檔mule esb 3 concepts,介紹了mule esb的一些基本概念。看完后,對soa,esb,服務等都有了更深的認識。今天試驗通過mule進行cxf web service的調用,試了一下午終于成功。

1,首先要有一個已經發布的cxf web service,可以通過mule studio以圖形化的方式簡單生成config.xml,再寫好相應的component class,就是發布用到的接口和pojo類。

interface

_____________________________

@WebService

public interface IHello {

@WebMethod

public String sayHello(@WebParam (name="name")String name);

}

?

class

_____________________

package test.server;

import javax.jws.WebMethod;

import javax.jws.WebParam;

import javax.jws.WebService;

?

package test.server;

public class Hello implements IHello {

public String sayHello(String name) {

// TODO Auto-generated method stub

System.err.println("name: "+name);

return "Hello, "+name;

}

}

2,用基于wsdl文件的方式調用。

在cxf的bin目錄,用wsdl2java生成client,就是下面繼承自javax.xml.ws.Service的java類。

wsdl2java命令:wsdl2java -d test -client http://localhost:8081?wsdl

?

生成的client類

————————————————————

package test.server;

?

import java.net.MalformedURLException;

import java.net.URL;

import javax.xml.namespace.QName;

import javax.xml.ws.WebEndpoint;

import javax.xml.ws.WebServiceClient;

import javax.xml.ws.WebServiceFeature;

import javax.xml.ws.Service;

?

/**

?* This class was generated by Apache CXF 2.5.0

?* 2011-12-18T15:35:33.461+08:00

?* Generated source version: 2.5.0

?*?

?*/

@WebServiceClient(name = "IHelloService",?

? ? ? ? ? ? ? ? ? wsdlLocation = "http://localhost:8081?wsdl",

? ? ? ? ? ? ? ? ? targetNamespace = "http://server.test/")?

public class IHelloService extends Service {

?

? ? public final static URL WSDL_LOCATION;

?

? ? public final static QName SERVICE = new QName("http://server.test/", "IHelloService");

? ? public final static QName IHelloPort = new QName("http://server.test/", "IHelloPort");

? ? static {

? ? ? ? URL url = null;

? ? ? ? try {

? ? ? ? ? ? url = new URL("http://localhost:8081?wsdl");

? ? ? ? } catch (MalformedURLException e) {

? ? ? ? ? ? java.util.logging.Logger.getLogger(IHelloService.class.getName())

? ? ? ? ? ? ? ? .log(java.util.logging.Level.INFO,?

? ? ? ? ? ? ? ? ? ? ?"Can not initialize the default wsdl from {0}", "http://localhost:8081?wsdl");

? ? ? ? }

? ? ? ? WSDL_LOCATION = url;

? ? }

?

? ? @WebEndpoint(name = "IHelloPort")

? ? public IHello getIHelloPort() {

? ? ? ? return super.getPort(IHelloPort, IHello.class);

? ? }

?

}

3,eclipse+mule ide環境中,創建mule project,將上面的client類copy到project,再新建一個config.xml。然后右鍵選擇運行。

config.xml如下:

?

<?xml version="1.0" encoding="UTF-8"?>

?

<mule xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:http="http://www.mulesoft.org/schema/mule/http"

xmlns:cxf="http://www.mulesoft.org/schema/mule/cxf" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xsi:schemaLocation="

http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd?

http://www.mulesoft.org/schema/mule/cxf http://www.mulesoft.org/schema/mule/cxf/current/mule-cxf.xsd?

http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd ">

<flow name="client">

<http:inbound-endpoint exchange-pattern="request-response"//發出http request并等待response

host="localhost" port="8888">//從localhost:8888接收http request。

?

<response>

<object-to-string-transformer />//將響應返回給http transport,在瀏覽器回顯。

</response>

</http:inbound-endpoint>

?

<http:outbound-endpoint exchange-pattern="request-response"//調用webservice并等待返回結果

host="localhost" port="8081">

<cxf:jaxws-client port="IHelloPort" clientClass="test.server.IHelloService"

operation="sayHello" wsdlLocation="http://localhost:8081?wsdl" />

</http:outbound-endpoint>

</flow>

</mule>

?4,運行config.xml.在地址欄輸入http://localhost:8888/abc, browser會顯示hello,/abc.

hello,/abc 是通過調用web service而得到的返回結果。

總結

以上是生活随笔為你收集整理的mule 基于wsdl调用cxf web service的全部內容,希望文章能夠幫你解決所遇到的問題。

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