使用Mule发布Web Service服务

来源:互联网 发布:肖像权网络侵权管辖 编辑:程序博客网 时间:2024/05/20 01:10

一、编写接口代码

view source
print?
1package cn.com.songjy.mule;
2 
3public interface IHelloWord {
4 
5    String hello(String name);
6     
7}

 

二、编写接口实现类代码

1package cn.com.songjy.mule;
2 
3public class HelloWord implements IHelloWord {
4 
5    public String hello(String name) {
6        return "你好:" + name + ",现在的时间是:" new java.util.Date();
7    }
8 
9}

三、编写mule配置文件【mule-config.xml】,路径是在classpath根目录下,即平常的src目录中

01<?xml version="1.0" encoding="UTF-8"?>
02 
03<!DOCTYPE mule-configuration PUBLIC "-//MuleSource //DTD mule-configuration XML V1.0//EN"
04                                "http://mule.mulesource.org/dtds/mule-configuration.dtd">
05<mule-configuration id="Ws-adapter" version="1.0">
06    <model name="helloTest">
07        <mule-descriptor name="helloService" implementation="cn.com.songjy.mule.HelloWord">
08            <inbound-router>
09                <endpoint address="axis:http://localhost:8281/services"></endpoint>
10            </inbound-router>
11            <properties>
12                <list name="serviceInterfaces">
13                    <entry value="cn.com.songjy.mule.IHelloWord" />
14                </list>
15            </properties>
16        </mule-descriptor>
17    </model>
18</mule-configuration>

四、编写发布Web Service接口代码

01package cn.com.songjy.mule;
02 
03import org.mule.config.ConfigurationException;
04import org.mule.config.builders.MuleXmlConfigurationBuilder;
05 
06public class PublicServer {
07 
08    /**
09     * create on 2013-5-27 下午2:01:15 by songjy
10     * @param args
11     */
12    public static void main(String[] args) {
13        try {
14            MuleXmlConfigurationBuilder xmlConfiguration = new MuleXmlConfigurationBuilder();
15            xmlConfiguration.configure("mule-config.xml");
16        catch (ConfigurationException e) {
17            e.printStackTrace();
18        }
19         
20    }
21 
22}

 

五、运行测试

在浏览器中输入http://localhost:8281/services/helloService?wsdl 即可看到效果。

示例代码:http://yunpan.cn/QeKkjgcum4dKp

Java使用XFire调用WebService接口:

http://www.cnblogs.com/simle/archive/2011/10/31/2230091.html

0 0
原创粉丝点击