ESB专题(三)实战mule 2

王朝other·作者佚名  2007-01-18
窄屏简体版  字體: |||超大  

前期配置 请 参考 ESB专题(二)实战mule 1

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=""/>去掉,就会发现页面是空白的,仅在后台打印出信息.

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有  導航