`
network-eagle
  • 浏览: 57988 次
  • 性别: Icon_minigender_1
  • 来自: 重庆
社区版块
存档分类
最新评论

mule2.1.2 初步认识 发布cxf 和axis服务

阅读更多
最近公司需要写这样一个功能。也就是需要一个esb消息总线。初步的功能是提供webservice的消息管理以后还会增加很多的功能。。以前本来在soa esb上面的东西就是个空白。在Google上找了一天最后由我自己觉得用mule2.1.2。让后就疯狂的找些好的帖子。希望能够很快的入门。但发现不是那么一回事。找到的很多都是1.X的版本。2.1.2 的少得很。经过近半周的研究。。终于自己写了一个小的test。贴上来给新入门的朋友希望有帮助。深入的研究以后还会继续。
配置文件:mule_config.xml
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns="http://www.mulesource.org/schema/mule/core/2.1"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xmlns:spring="http://www.springframework.org/schema/beans"
      xmlns:vm="http://www.mulesource.org/schema/mule/vm/2.1"
      xmlns:cxf="http://www.mulesource.org/schema/mule/cxf/2.1"
      xmlns:axis="http://www.mulesource.org/schema/mule/axis/2.1"
      xmlns:smtps="http://www.mulesource.org/schema/mule/smtps/2.1"
      xmlns:http="http://www.mulesource.org/schema/mule/http/2.1"
      xmlns:stdio="http://www.mulesource.org/schema/mule/stdio/2.1"
      xmlns:soap="http://www.mulesource.org/schema/mule/soap/2.1"
      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.1 http://www.mulesource.org/schema/mule/core/2.1/mule.xsd
               http://www.mulesource.org/schema/mule/stdio/2.1 http://www.mulesource.org/schema/mule/stdio/2.1/mule-stdio.xsd
               http://www.mulesource.org/schema/mule/vm/2.1 http://www.mulesource.org/schema/mule/vm/2.1/mule-vm.xsd
               http://www.mulesource.org/schema/mule/cxf/2.1 http://www.mulesource.org/schema/mule/cxf/2.1/mule-cxf.xsd
               http://www.mulesource.org/schema/mule/axis/2.1 http://www.mulesource.org/schema/mule/axis/2.1/mule-axis.xsd
               http://www.mulesource.org/schema/mule/smtps/2.1 http://www.mulesource.org/schema/mule/smtps/2.1/mule-smtps.xsd
               http://www.mulesource.org/schema/mule/soap/2.1 http://www.mulesource.org/schema/mule/soap/2.1/mule-soap.xsd
               http://www.mulesource.org/schema/mule/http/2.1 http://www.mulesource.org/schema/mule/http/2.1/mule-http.xsd
               ">
     <description>
        eagleMule demo which shows how to publish web services over CXF.
    </description>
    <model name="eagleMule">
    	 <service name="testMuleService">
            <inbound>
                <axis:inbound-endpoint address="http://localhost:8899/services/testMuleService">
            		<soap:http-to-soap-request-transformer />
            	</axis:inbound-endpoint>
            	<cxf:inbound-endpoint address="http://localhost:8898/services/testMuleService">
            		<soap:http-to-soap-request-transformer />
            	</cxf:inbound-endpoint>
            </inbound>
            <component class="com.eagle.mule.test.imp.MuleServiceImp">
            </component>
        </service>
    </model>
    </mule>

一个简单的 接口 为了先跑同就这样把。
MuleService.java
 @WebService
public interface MuleService {
public String testMule(@WebParam(name="str")String str);
}

MuleServiceImp.java
@WebService(serviceName="eagleMuleService",
		  endpointInterface="com.eagle.mule.test.MuleService")
public class MuleServiceImp implements MuleService {

	public String testMule(String str) {
		System.out.println("----service---");
		return "hello--"+str;
	}
}

启动服务:
public class EagleMuleMain {
	public static void main(String[] args) throws ConfigurationException, InitialisationException {
		try {
			String configFile = "com/eagle/mule/test/mule_config.xml";
			String[] configFileArr = new String[] { configFile };
			MuleContextFactory muleContextFactory = new DefaultMuleContextFactory();
			MuleContext context = muleContextFactory
					.createMuleContext(new SpringXmlConfigurationBuilder(
							configFileArr));
			context.start();
		} catch (MuleException t) {
			t.printStackTrace();
		}
	}
}

测试
package com.eagle.mule.test.clint;

import java.io.IOException;
import java.io.InputStream;

import org.apache.commons.io.IOUtils;
import org.mule.api.MuleException;
import org.mule.api.MuleMessage;
import org.mule.module.client.MuleClient;

public class Client {
	public static void main(String[] args){
		MuleClient client = null; 
		try {
			client = new MuleClient();
			String url = "axis:http://localhost:8899/services/testMuleService?wsdl&method=testMule";

			MuleMessage message = client.send(url, "eagle", null);
			Object obj = message.getPayload();
			System.out.println("--------------obj---------"+obj.getClass().getName());
			if(obj instanceof String){
				System.out.println("---------str--------------"+obj);
			}
		} catch (MuleException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			client.dispose();
		}

	}
}
注意 这里需要把mule 下lib中 endorsed  mule  opt 文件夹中的jar都加进去。如果不发布cxf的服务 可以不用添加endorsed文件夹中的jar。 
分享到:
评论
43 楼 sadlonewolf 2011-11-15  
LZ:我的xml文档怎么跑不通啊,一直报错unknown source和Cannot find the declaration of element 'mule',帮我看一下吧。
42 楼 deadcow 2009-07-01  
另外,写mule的test case。可以用上mule 的test package,里面有一个类似funtionalTest的class
41 楼 deadcow 2009-07-01  
好像没有体现ESB,你的src code 不应该加上任何类似WS的tag,怎样把WS expose出来,是通过MULE的inbound
40 楼 caiway 2009-07-01  
大家有把mule2集成到应用程序里去吗?照着官网把下面这段加入web.xml报错,应用在tomcat里面不能启动。
<context-param>
    <param-name>org.mule.config</param-name>
    <param-value>mule-config-main.xml,mule-components.xml</param-value>
</context-param>

<listener>
    <listener-class>org.mule.config.builders.MuleXmlBuilderContextListener</listener-class>
</listener>
39 楼 rrsy23 2009-06-18  
mule的例子可以看哈

你这个和mule的最简单的echo例子基本一样
38 楼 portrait 2009-05-30  
burke 写道
String url = "cxf:http://localhost:8898/services/testMuleService?method=testMule";
这个报错
Could not create client! No Server was found directly on the endpoint: http://localhost:8898/services/testMuleService

这是怎么回事啊
37 楼 qhhhn 2009-05-14  
刚好在学习ING...国内这一块的资料太少了...

36 楼 burke 2009-05-08  
String url = "cxf:http://localhost:8898/services/testMuleService?method=testMule";
这个报错
Could not create client! No Server was found directly on the endpoint: http://localhost:8898/services/testMuleService
35 楼 hf3862 2009-04-30  
我在运行您的例子时碰到这个错误:
Exception in thread "main" java.lang.IllegalStateException: Level number 10 is not recognized.
at org.slf4j.impl.JDK14LoggerAdapter.log(JDK14LoggerAdapter.java:529)
at org.apache.commons.logging.impl.SLF4JLocationAwareLog.debug(SLF4JLocationAwareLog.java:106)
at org.mule.util.IOUtils.getResourceAsUrl(IOUtils.java:154)
at org.mule.config.ConfigResource.<init>(ConfigResource.java:32)
at org.mule.config.builders.AbstractResourceConfigurationBuilder.loadConfigResources(AbstractResourceConfigurationBuilder.java:90)
at org.mule.config.builders.AbstractResourceConfigurationBuilder.<init>(AbstractResourceConfigurationBuilder.java:56)
at org.mule.config.spring.SpringXmlConfigurationBuilder.<init>(SpringXmlConfigurationBuilder.java:43)
at test.EagleMuleMain.main(EagleMuleMain.java:20)

也没有google到解决办法,请问是哪儿的问题?

xp/jdk1.5.0_18/eclipse3.4.2/mule2.1.2
34 楼 network-eagle 2009-04-22  
zhunzhunzhun-sky 写道
能把源码分享下吗?

我上面的结构就是原代码。没保留什么,还有 我是能跑通的。
33 楼 zhunzhunzhun-sky 2009-03-31  
能把源码分享下吗?
32 楼 network-eagle 2009-03-30  
不好意思 各位朋友。由于很久没上,让大家久等了。不过我的程序是调试通过的。如果大家有问题。请检查自己的配置。也请提供出错的信息!谢谢!
31 楼 zhunzhunzhun-sky 2009-03-30  
http://localhost:8899/services/testMuleService

这个服务没有


http://localhost:8898/services/testMuleService

这个服务无法创建客户端


这是怎么回事楼主?
30 楼 portrait 2009-03-18  
<soap:http-to-soap-request-transformer />  
这个标签撒意思?传soap消息 就要用这个标签吗?
29 楼 portrait 2009-03-04  
楼上的用mule调web service调通了吗?
28 楼 gp_len 2009-03-02  
我的问题已经解决,呵呵……

楼上的:
检查一下你的mule版本
mule-conifg.xml文件
还有那些所需的jar
27 楼 zsb77585210 2009-03-02  
[03-02 10:41:20] ERROR SpringXmlConfigurationBuilder [main]: Configuration with "org.mule.config.spring.SpringXmlConfigurationBuilder" failed.
org.mule.api.lifecycle.InitialisationException: Initialisation Failure: Configuration problem: Unable to locate NamespaceHandler for namespace [http://www.mulesource.org/schema/mule/core/2.1]
Offending resource: URL [file:/D:/EclipseItem/MuleAppTest/bin/mule-config.xml]
at org.mule.registry.AbstractRegistry.initialise(AbstractRegistry.java:76)
at org.mule.config.spring.SpringXmlConfigurationBuilder.createSpringRegistry(SpringXmlConfigurationBuilder.java:98)
at org.mule.config.spring.SpringXmlConfigurationBuilder.doConfigure(SpringXmlConfigurationBuilder.java:69)
at org.mule.config.builders.AbstractConfigurationBuilder.configure(AbstractConfigurationBuilder.java:39)
at org.mule.config.builders.AbstractResourceConfigurationBuilder.configure(AbstractResourceConfigurationBuilder.java:78)
at org.mule.context.DefaultMuleContextFactory.createMuleContext(DefaultMuleContextFactory.java:96)
at org.mule.context.DefaultMuleContextFactory.createMuleContext(DefaultMuleContextFactory.java:54)
at EagleMuleMain.main(EagleMuleMain.java:16)
Caused by: org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Unable to locate NamespaceHandler for namespace [http://www.mulesource.org/schema/mule/core/2.1]
Offending resource: URL [file:/D:/EclipseItem/MuleAppTest/bin/mule-config.xml]
at org.springframework.beans.factory.parsing.FailFastProblemReporter.error(FailFastProblemReporter.java:68)
at org.springframework.beans.factory.parsing.ReaderContext.error(ReaderContext.java:85)
at org.springframework.beans.factory.parsing.ReaderContext.error(ReaderContext.java:72)
at org.mule.config.spring.MuleHierarchicalBeanDefinitionParserDelegate.parseCustomElement(MuleHierarchicalBeanDefinitionParserDelegate.java:78)
at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1287)
at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.parseBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:141)
at org.mule.config.spring.MuleBeanDefinitionDocumentReader.parseBeanDefinitions(MuleBeanDefinitionDocumentReader.java:45)
at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.registerBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:92)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.registerBeanDefinitions(XmlBeanDefinitionReader.java:507)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:398)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:342)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:310)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:143)
at org.mule.config.spring.MuleApplicationContext.loadBeanDefinitions(MuleApplicationContext.java:104)
at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:123)
at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:422)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:352)
at org.mule.config.spring.SpringRegistry.doInitialise(SpringRegistry.java:87)
at org.mule.registry.AbstractRegistry.initialise(AbstractRegistry.java:68)
... 7 more
org.mule.api.config.ConfigurationException: Initialisation Failure: Configuration problem: Unable to locate NamespaceHandler for namespace [http://www.mulesource.org/schema/mule/core/2.1]
Offending resource: URL [file:/D:/EclipseItem/MuleAppTest/bin/mule-config.xml] (org.mule.api.lifecycle.InitialisationException)
at org.mule.config.builders.AbstractConfigurationBuilder.configure(AbstractConfigurationBuilder.java:46)
at org.mule.config.builders.AbstractResourceConfigurationBuilder.configure(AbstractResourceConfigurationBuilder.java:78)
at org.mule.context.DefaultMuleContextFactory.createMuleContext(DefaultMuleContextFactory.java:96)
at org.mule.context.DefaultMuleContextFactory.createMuleContext(DefaultMuleContextFactory.java:54)
at EagleMuleMain.main(EagleMuleMain.java:16)
Caused by: org.mule.api.lifecycle.InitialisationException: Initialisation Failure: Configuration problem: Unable to locate NamespaceHandler for namespace [http://www.mulesource.org/schema/mule/core/2.1]
Offending resource: URL [file:/D:/EclipseItem/MuleAppTest/bin/mule-config.xml]
at org.mule.registry.AbstractRegistry.initialise(AbstractRegistry.java:76)
at org.mule.config.spring.SpringXmlConfigurationBuilder.createSpringRegistry(SpringXmlConfigurationBuilder.java:98)
at org.mule.config.spring.SpringXmlConfigurationBuilder.doConfigure(SpringXmlConfigurationBuilder.java:69)
at org.mule.config.builders.AbstractConfigurationBuilder.configure(AbstractConfigurationBuilder.java:39)
... 4 more
Caused by: org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Unable to locate NamespaceHandler for namespace [http://www.mulesource.org/schema/mule/core/2.1]
Offending resource: URL [file:/D:/EclipseItem/MuleAppTest/bin/mule-config.xml]
at org.springframework.beans.factory.parsing.FailFastProblemReporter.error(FailFastProblemReporter.java:68)
at org.springframework.beans.factory.parsing.ReaderContext.error(ReaderContext.java:85)
at org.springframework.beans.factory.parsing.ReaderContext.error(ReaderContext.java:72)
at org.mule.config.spring.MuleHierarchicalBeanDefinitionParserDelegate.parseCustomElement(MuleHierarchicalBeanDefinitionParserDelegate.java:78)
at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1287)
at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.parseBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:141)
at org.mule.config.spring.MuleBeanDefinitionDocumentReader.parseBeanDefinitions(MuleBeanDefinitionDocumentReader.java:45)
at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.registerBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:92)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.registerBeanDefinitions(XmlBeanDefinitionReader.java:507)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:398)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:342)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:310)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:143)
at org.mule.config.spring.MuleApplicationContext.loadBeanDefinitions(MuleApplicationContext.java:104)
at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:123)
at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:422)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:352)
at org.mule.config.spring.SpringRegistry.doInitialise(SpringRegistry.java:87)
at org.mule.registry.AbstractRegistry.initialise(AbstractRegistry.java:68)
... 7 more
运行失败 请各位看看问题所在
26 楼 portrait 2009-02-24  
问题已经解决
25 楼 portrait 2009-02-24  
network-eagle 写道
最近公司需要写这样一个功能。也就是需要一个esb消息总线。初步的功能是提供webservice的消息管理以后还会增加很多的功能。。以前本来在soa esb上面的东西就是个空白。在Google上找了一天最后由我自己觉得用mule2.1.2。让后就疯狂的找些好的帖子。希望能够很快的入门。但发现不是那么一回事。找到的很多都是1.X的版本。2.1.2 的少得很。经过近半周的研究。。终于自己写了一个小的test。贴上来给新入门的朋友希望有帮助。深入的研究以后还会继续。
配置文件:mule_config.xml
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns="http://www.mulesource.org/schema/mule/core/2.1"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xmlns:spring="http://www.springframework.org/schema/beans"
      xmlns:vm="http://www.mulesource.org/schema/mule/vm/2.1"
      xmlns:cxf="http://www.mulesource.org/schema/mule/cxf/2.1"
      xmlns:axis="http://www.mulesource.org/schema/mule/axis/2.1"
      xmlns:smtps="http://www.mulesource.org/schema/mule/smtps/2.1"
      xmlns:http="http://www.mulesource.org/schema/mule/http/2.1"
      xmlns:stdio="http://www.mulesource.org/schema/mule/stdio/2.1"
      xmlns:soap="http://www.mulesource.org/schema/mule/soap/2.1"
      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.1 http://www.mulesource.org/schema/mule/core/2.1/mule.xsd
               http://www.mulesource.org/schema/mule/stdio/2.1 http://www.mulesource.org/schema/mule/stdio/2.1/mule-stdio.xsd
               http://www.mulesource.org/schema/mule/vm/2.1 http://www.mulesource.org/schema/mule/vm/2.1/mule-vm.xsd
               http://www.mulesource.org/schema/mule/cxf/2.1 http://www.mulesource.org/schema/mule/cxf/2.1/mule-cxf.xsd
               http://www.mulesource.org/schema/mule/axis/2.1 http://www.mulesource.org/schema/mule/axis/2.1/mule-axis.xsd
               http://www.mulesource.org/schema/mule/smtps/2.1 http://www.mulesource.org/schema/mule/smtps/2.1/mule-smtps.xsd
               http://www.mulesource.org/schema/mule/soap/2.1 http://www.mulesource.org/schema/mule/soap/2.1/mule-soap.xsd
               http://www.mulesource.org/schema/mule/http/2.1 http://www.mulesource.org/schema/mule/http/2.1/mule-http.xsd
               ">
     <description>
        eagleMule demo which shows how to publish web services over CXF.
    </description>
    <model name="eagleMule">
    	 <service name="testMuleService">
            <inbound>
                <axis:inbound-endpoint address="http://localhost:8899/services/testMuleService">
            		<soap:http-to-soap-request-transformer />
            	</axis:inbound-endpoint>
            	<cxf:inbound-endpoint address="http://localhost:8898/services/testMuleService">
            		<soap:http-to-soap-request-transformer />
            	</cxf:inbound-endpoint>
            </inbound>
            <component class="com.eagle.mule.test.imp.MuleServiceImp">
            </component>
        </service>
    </model>
    </mule>

一个简单的 接口 为了先跑同就这样把。
MuleService.java
 @WebService
public interface MuleService {
public String testMule(@WebParam(name="str")String str);
}

MuleServiceImp.java
@WebService(serviceName="eagleMuleService",
		  endpointInterface="com.eagle.mule.test.MuleService")
public class MuleServiceImp implements MuleService {

	public String testMule(String str) {
		System.out.println("----service---");
		return "hello--"+str;
	}
}

启动服务:
public class EagleMuleMain {
	public static void main(String[] args) throws ConfigurationException, InitialisationException {
		try {
			String configFile = "com/eagle/mule/test/mule_config.xml";
			String[] configFileArr = new String[] { configFile };
			MuleContextFactory muleContextFactory = new DefaultMuleContextFactory();
			MuleContext context = muleContextFactory
					.createMuleContext(new SpringXmlConfigurationBuilder(
							configFileArr));
			context.start();
		} catch (MuleException t) {
			t.printStackTrace();
		}
	}
}

测试
package com.eagle.mule.test.clint;

import java.io.IOException;
import java.io.InputStream;

import org.apache.commons.io.IOUtils;
import org.mule.api.MuleException;
import org.mule.api.MuleMessage;
import org.mule.module.client.MuleClient;

public class Client {
	public static void main(String[] args){
		MuleClient client = null; 
		try {
			client = new MuleClient();
			String url = "axis:http://localhost:8899/services/testMuleService?wsdl&method=testMule";

			MuleMessage message = client.send(url, "eagle", null);
			Object obj = message.getPayload();
			System.out.println("--------------obj---------"+obj.getClass().getName());
			if(obj instanceof String){
				System.out.println("---------str--------------"+obj);
			}
		} catch (MuleException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			client.dispose();
		}

	}
}
注意 这里需要把mule 下lib中 endorsed  mule  opt 文件夹中的jar都加进去。如果不发布cxf的服务 可以不用添加endorsed文件夹中的jar。 


@WebService 
(@WebParam(name="str")
@WebParam和name都报错 怎么回事?要加什么包吗?
24 楼 portrait 2009-02-24  
network-eagle 写道
希望对你有帮助就行。现在就是在基于消息这块还在继续研究中。也希望大家一起交流

lz,你是要研究jms这块吗?我已经搞出来了 你可以问我,你可以把你的msn,qq号码发到javaeye的信箱里,我加你一下,告诉你怎么弄

相关推荐

Global site tag (gtag.js) - Google Analytics