打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
mule cxf 入门篇
 
 
1 创建服务接口
/**
*
*/
package com.cimstech.service;

import javax.jws.WebService;

/**
* @author wanghongyu
*
*/
@WebService
public interface MessageHandlerService {

public String messageHandler(String message);

}
2 实现服务接口
public class MessageHandlerImp implements MessageHandlerService {   

public MessageHandlerImp() {       

}

public String messageHandler(String message) {
System.out.println("haha");
return "success";
}
}
3 配置mule配置文件
<mule xmlns="http://www.mulesource.org/schema/mule/core/2.2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:spring="http://www.springframework.org/schema/beans"
xmlns:cxf="http://www.mulesource.org/schema/mule/cxf/2.2"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.mulesource.org/schema/mule/core/2.2
http://www.mulesource.org/schema/mule/core/2.2/mule.xsd
http://www.mulesource.org/schema/mule/cxf/2.2
http://www.mulesource.org/schema/mule/cxf/2.2/mule-cxf.xsd">

<model>
<service name="messageHandler">
<inbound>
<cxf:inbound-endpoint address="http://localhost:8080/61968WS" />
</inbound>

<component class="com.cimstech.imp.MessageHandlerImp"></component>
<!--
<component> <singleton-object
class="com.cimstech.imp.MessageHandlerImp" /> </component>
-->
</service>
</model>
</mule>
4 启动mule服务器
/**
*
*/
package com.cimstech.server;

import org.mule.MuleServer;
import org.mule.api.MuleContext;
import org.mule.api.MuleException;
import org.mule.api.config.ConfigurationException;
import org.mule.api.lifecycle.InitialisationException;
import org.mule.config.spring.SpringXmlConfigurationBuilder;
import org.mule.context.DefaultMuleContextFactory;

/**
* @author wanghongyu
*
*/
public class StartMule {

public boolean start(){   
MuleContext context;
try {
context = new DefaultMuleContextFactory()
.createMuleContext(new SpringXmlConfigurationBuilder(
"mule-config.xml"));
context.start();

} catch (InitialisationException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (ConfigurationException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (MuleException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return false;
}

/**
* @param args
*/
public static void main(String[] args) {
new StartMule().start();

}
}
5 启动客户端进行测试
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;

import org.apache.cxf.interceptor.LoggingInInterceptor;
import org.apache.cxf.interceptor.LoggingOutInterceptor;
import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;

import com.cimstech.service.MessageHandlerService;

/**
*
*/

/**
* @author wanghongyu
*
*/
public class CreateClient {

/**
* @param args
*/
public static void main(String[] args) {
try {
BufferedReader reader = new BufferedReader(new FileReader(
"F:\\eclipse_jee\\workspace\\61968WS\\WebContent\\WEB-INF\\examples\\create_CustomerAgreementConfig.xml"));
String xml = "";
String line = reader.readLine();
while (line != null) {
xml += line;
line = reader.readLine();
}
reader.close();           

//http://Dev1:8081/61968WS/services/MessageHandler

JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
factory.getInInterceptors().add(new LoggingInInterceptor());
factory.getOutInterceptors().add(new LoggingOutInterceptor());
factory.setServiceClass(MessageHandlerService.class);
factory
.setAddress("http://localhost:8080/61968WS/messageHandler");
Object x = factory.create();
System.out.println("class name : " + x.getClass());
MessageHandlerService client = (MessageHandlerService) factory.create();
String result = client.messageHandler(xml);           
System.out.println(result);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

}

}

mule 2.x的代码启动方式:
context = new DefaultMuleContextFactory()
.createMuleContext(new SpringXmlConfigurationBuilder(
"mule-config.xml"));
mule 3.0的启动方式:
MuleServer server = new MuleServer("mule-config.xml");
server.start(true, true);
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
Mule Spring Security | Mule Training | Mule ESB, Anypoint Registry, Anypoint Connectors, MMC, APIKit
WebService开发笔记 3 -- 增强访问 WebService 的安全性
xml、schema、xsd
Camel组件之CXF | salever的小站
CXF MyEclipse 开发webservice入门实例之HelloWorld
spring security 3.1配置过程从简单到复杂详细配置
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服