3、http provider
首先把mule源码中的一个transform文件复制过来并编译到classes下面
HttpRequestToString.java :
package org.mule.samples.hello;
import org.mule.config.i18n.Message;
import org.mule.transformers.AbstractTransformer;
import org.mule.umo.transformer.TransformerException;
import java.io.UnsupportedEncodingException;
/**
* <code>NameStringToChatString</code> This is test class only for use with the Hello world
* test application.
*
* @author <a href="mailto_ross.mason@symphonysoft.com">Ross Mason</a>
* @version $Revision: 1.6 $
*/
public class HttpRequestToString extends AbstractTransformer
{
/**
*
*/
public HttpRequestToString()
{
super();
this.registerSourceType(String.class);
this.registerSourceType(byte[].class);
}
/* (non-Javadoc)
* @see org.mule.transformers.AbstractTransformer#doTransform(java.lang.Object)
*/
public Object doTransform(Object src, String encoding) throws TransformerException
{
String param = null;
if (src instanceof byte[]) {
if (encoding != null) {
try {
param = new String((byte[]) src, encoding);
} catch (UnsupportedEncodingException ex){
param = new String((byte[]) src);
}
} else {
param = new String((byte[]) src);
}
} else {
param = src.toString();
}
int equals = param.indexOf("=");
if(equals > -1)
{
return param.substring(equals + 1);
} else {
throw new TransformerException(Message.createStaticMessage("Failed to parse param string: " + param), this);
}
}
}
在conf下编写相应的配置文件 test-http-config.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mule-configuration PUBLIC "-//SymphonySoft //DTD mule-configuration XML V1.0//EN"
"http://www.symphonysoft.com/dtds/mule/mule-configuration.dtd">
<mule-configuration id="file" version="1.0">
<description>
本测试由刘玉军完整测试,如果有问题请访问http://blog.csdn.net/lyj_china
</description>
<mule-environment-properties synchronous="true" serverUrl=""/>
<transformers>
<transformer name="HttpRequestToString" className="org.mule.samples.hello.HttpRequestToString"/>
</transformers>
<model name="test http">
<mule-descriptor name="Service2" implementation="org.lyj.mule.Service">
<inbound-router>
<endpoint address="http://localhost:4567" transformers="HttpRequestToString">
<properties>
<property name="Content-Type" value="text/plain"/>
</properties>
</endpoint>
</inbound-router>
<!--
<outbound-router>
<router className="org.mule.routing.outbound.FilteringOutboundRouter">
<endpoint address="stream://System.out">
</endpoint>
</router>
</outbound-router>
-->
</mule-descriptor>
</model>
</mule-configuration>
在bin目录下创建testhttp.bat文件,内容如下
@echo off
REM There is no need to call this if you set the MULE_HOME in your environment properties
if "%MULE_HOME%" == "" SET MULE_HOME=..\..
REM Set your application specific classpath like this
SET CLASSPATH=%MULE_HOME%\testmule\conf;%MULE_HOME%\testmule\classes;
call %MULE_HOME%\bin\mule.bat -config ../conf/test-http-config.xml
SET MULE_MAIN=
SET CLASSPATH=
然后执行testhttp.bat,正常启动mule后,就可以看到效果了
通过 http://localhost:4567/name=success就可以看到页面上打印出success,mule后台打印出success;
如果把<mule-environment-properties synchronous="true" serverUrl=""/>去掉,就会发现页面是空白的,仅在后台打印出信息.
<!--EndFragment-->
分享到:
相关推荐
博文链接:https://hideto.iteye.com/blog/65607
博文链接:https://hideto.iteye.com/blog/65822
mule in aciton:mule 实战,主要是社区成熟,文档丰富。开源esb
企业服务总线ESB中用户数量大,文档丰富,社区成熟的一款开源ESB。
MULE用户指南3.3 官方原版
mule in action ,mule入门教程,系统学习资料,英文版
用户数最多 社区最活跃的开源框架 企业服务总线 虽然没有实现JBI但是却非常好用。
–ServiceMix架构–ServiceMix组件概览–ServiceMix实战–Demo–Mule的工作机理–Mule组件概览–Mule实战–Demo–削弱了部门间的协作–影响资源的整合Point-to-PointsolutionHub-and-...作为ASF的一员,它集成了包括...
Struts2 Hibernate Spring Html/CSS/ 浪曦JavaScript框架实战开发及应用 ExtJs 3.0 Oracle数据库,企业软件的基石 真实企业级CRM项目 另配套附送本项目其它高级部分,手把手教学视频在浪曦CRM教学中,比如...
source enterprise integration frameworks like Mule, Camel, ServiceMix, and Spring Integration. My work, over time, drove me to designing and developing processes and BPM , and I started using j BPM ...
为实现在CANoe中开发刷新功能,读取刷新文件相对较为复杂...实战使用过程中,遇到了ASCII的S19,Hex格式。二进制的bin文件。以及组合格式的VBF格式。 分享读取这2种文件的方法。有不同格式的文件,修改起来也大同小异;