国师与太师区别:mule cxf 入门篇
来源:百度文库 编辑:中财网 时间:2024/04/29 19:47:44
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配置文件
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">
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);
/**
*
*/
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配置文件
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">
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);
e-mule.......
E-MULE下载问题!
e-Mule不能用??
关于e-mule
使用e-mule
e-mule怎样增加上传?
关于e-mule的用法
想知道e-mule 怎么用.
E-mule中的各种颜色是什么意思?
.CXF的文件用什么打开?介绍一下这是什么格式的文件!
E Mule的工作原理是什么?
关于电驴E-mule的问题!
e-Mule的服务器干什么用的
用E-mule下载能断点续传吗?
e mule 和 迅雷 有什么区别?
一个关于e-mule的问题
E-mule和BT怎么用呢?
e mule哪个版本比较好?
推荐几个e-mule下载网站
求<机器人制作入门篇>下载地址
股票入门
钢琴入门
炒股入门
pp2005入门