最近看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相关推荐

  1. Java如何通过WSDL文件来调用这些web service

    下面我们来看Java如何通过WSDL文件来调用这些web service: 注意,以下的代码并没有经过真正的测试,只是说明这些情况,不同版本的Axis相差很大,大家最好以apache网站上的例子为准, ...

  2. CORBA 简单了解和JAVA与C++互操以及C++调用Java web service

    CORBA了解 CORBA(Common Object Request Broker Architecture, 公共对象请求代理体系结构)是由OMG(对象管理组织,Object Management ...

  3. C++ 调用 SOAP Web Service

    C++ 调用 SOAP Web Service 背景 首先,gSoap 肯定是个不错的选择,但是如果你的程序要调用多个 Web Services(即有多个 WSDL),gSoap 会比较麻烦.还有一个 ...

  4. 调用天气预报Web Service

    调用天气Web Service             i.创建项目                 项目名称:weatherclient             ii.创建本地的wsdl文件    ...

  5. abap 调用外部web service 使用小结

    abap调用外部 web service 时,大致分为以下三个步骤 1,se80,选择package,点击创建enterprise service/web service-proxy client 2 ...

  6. SAP调用外部web service

    前提:外部提供可用的web service,通常为链接 1. SE80,创建web service proxy    1)SE80,选择package,右击->create->Enterp ...

  7. WSDL文件生成WEB service server端C#程序

    一般一个已经实现功能的WEB Server会发布自己的WSDL文件,供客户端生成代理类. 但有时是先有的server与client交互的接口定义(WSDL)文件,然后由server和client端分别 ...

  8. 在ASP.NET Atlas中调用Web Service——创建Mashup调用远端Web Service(基础知识以及简单示例)...

    作者:Dflying Chen (http://dflying.cnblogs.com/) 注:Atlas中的Mashup极其复杂,其中涉及众多的对象与架构,为了写这篇文章,我花了不少时间学习研究.同 ...

  9. html调用天气预报wsdl服务,调用天气预报Web Service

    中国国家气象局天气预报接口总共提供了三个: http://www.weather.com.cn/data/sk/101010100.html http://www.weather.com.cn 天气预 ...

最新文章

  1. Tensorflow C++ 编译和调用图模型
  2. Codeforces 375D - Tree and Queries(dfs序+莫队)
  3. javascript 鼠标事件总结
  4. Reshape cannot infer the missing input size for an empty tensor unless all specified input sizes are
  5. oracle blob update,Oracle数据库中对BLOB数据的操作问题
  6. java线程wait和notify详解
  7. docker php安装gd扩展_PHP安装AMQP扩展
  8. oracle12c备份和恢复,oracle12C使用RMAN备份和恢复
  9. Android下DLAN中DMS模块的实现
  10. 拼多多开放平台订单信息查询接口【pdd.order.basic.list.get订单基础信息列表查询接口(根据成交时间)】代码对接教程
  11. 【报错记录】解决Shell脚本报ambiguous redirect
  12. 计算机装逼技巧,【干货来啦】电脑装逼技巧,让你一秒变大神!
  13. [NOI2010] 航空管制 (构反图+拓扑)
  14. python爬取推特的详细教程_使用Selenium Python进行网页抓取[Twitter+Instagram]
  15. UDF、UDAF、UDTF之间的区别
  16. linux系统中硬盘及分区如何命名,Linux硬盘命名和安装分区
  17. 2023—静待“雨中的海棠”发芽
  18. USB Type-c手机无线领夹麦克风(MIC)快充方案,直播神器
  19. 多语言跨境商城开发,源码无加密
  20. 说说$strobe,$monitor 和 $display 的差别

热门文章

  1. 计算机视觉:图像分类定位(单一目标检测)python实现
  2. Spring Boot 日志管理
  3. JavaScript实现跳跃游戏的动态编程自下而上的方法的算法(附完整源码)
  4. JavaScript实现广度优先搜索BFS算法(附完整源码)
  5. wxWidgets:wxHtmlHelpWindow类用法
  6. wxWidgets:wxCondition类用法
  7. boost::type_erasure::less_than_comparable相关的测试程序
  8. boost::mp11::mp_bind相关用法的测试程序
  9. boost::hana::empty用法的测试程序
  10. boost::filesystem::copy用法的测试程序