- 浏览: 467079 次
- 性别:
- 来自: 北京
文章分类
- 全部博客 (371)
- Java (44)
- Flex (25)
- Design Pattern / UML (5)
- JVM (14)
- Software Engineer (4)
- Testing (30)
- Web Backend (60)
- Linux (7)
- Database (11)
- SOA (28)
- English (6)
- FX (5)
- SAP Support (25)
- SAP Development (5)
- SAP Impl & Oprn (8)
- Articles (15)
- Music (4)
- Recipe (14)
- Multi-thread (4)
- Lucene (2)
- CS basic / Algorithm (12)
- Tour (3)
- C C++ (21)
- Others (10)
- Code Repository C++ (1)
- Code Repository Java (1)
- Code Repository Algorithm (1)
- Code Repository SQL (1)
- Web Frontend (4)
最新评论
-
xiangxm:
Java 强引用、 软引用、 弱引用、虚引用 -
nml-lyb:
123
Mule 的第一个例子 -
nml-lyb:
http://www.baidu.com
Mule 的第一个例子 -
white___ant:
...
Java 强引用、 软引用、 弱引用、虚引用 -
joeyon:
...
Java NIO介绍
Using Transformers
Transformers convert message payloads as they are transported between services. Mule provides many standard transformers, which you configure using predefined elements and attributes in your Mule XML configuration file. You can also configure custom transformers using the <custom-transformer> element, in which you specify the fully qualified class name of the custom transformer class. For more information on creating and configuring a custom transformer, see Creating Custom Transformers .
Standard transformers are easier to use than custom transformers. You don't need to know the Java name of the transformer, and all properties are explicitly declared in a Mule configuration schema. Following is an example of declaring the standard Append String transformer, which appends string text to the original message payload:
<append-string-transformer name="myAppender"
message=" ... that's good to know!"
/>
If the original message payload was the string "foo", the transformer above would convert the string to "foo ... that's good to know!".
The Available Transformers section of this page describes all the standard transformers provided with Mule. Additionally, many transports and modules have their own transformers, such as the ObjectToJMSMessage transformer for the JMS transport.
Configuring Transformers
You can configure a transformer locally or globally . You configure a local transformer right on the endpoint where you want to apply it, whereas you configure a global transformer before the <model> element in your Mule configuration properties so you can then refer to the transformer in multiple places.
For example, the following code defines two global transformers, which are referenced from two different services:
<xm:xml-to-object-transformer name="XMLToExceptionBean" returnClass="org.mule.example.errorhandler.ExceptionBean" /> <custom-transformer name="ExceptionBeanToErrorMessage" class="org.mule.example.errorhandler.ExceptionBeanToErrorMessage" returnClass="org.mule.example.errorhandler.ErrorMessage" /> ... <model name="errorhandler-test" > <service name="Error Manager" > <inbound> <inbound-endpoint address="file://./test-data/in" transformer-refs="XMLToExceptionBean ExceptionBeanToErrorMessage" > <file:filename-wildcard-filter pattern="*.xml" /> </inbound-endpoint> </inbound> ... </service> ... <service name="Business Error Manager" > <inbound> <inbound-endpoint address="jms://exception.queue" transformer-refs="XMLToExceptionBean ExceptionBeanToErrorMessage" /> </inbound> ... </service> </model>
This example uses the transformer-refs attribute on the endpoint to specify the transformers to use. This is a fast way of specifying global transformers, but if you want to enter a local transformer or a mix of local and global transformers, you must use the <transformer> element instead. For example, if only one of the transformers were defined globally, you would refer to the global transformer and configure the local transformer as follows:
<service name="Error Manager" > <inbound> <inbound-endpoint address="file://./test-data/in" > <transformer ref="XMLToExceptionBean/> <custom-transformer name="ExceptionBeanToErrorMessage" class="org.mule.example.errorhandler.ExceptionBeanToErrorMessage" returnClass="org.mule.example.errorhandler.ErrorMessage" /> <file:filename-wildcard-filter pattern="*.xml" /> </inbound-endpoint> </inbound> ... </service>
Inbound, Outbound, and Response Configurations
The above examples illustrate configuring inbound transformers, which are applied to the message after it is received on the inbound endpoint and before it is passed to the service's component. You specify inbound transformers under the <inbound-endpoint> element.
You can also specify an outbound transformer in exactly the same way but on <outbound> element routers, in which case the message is transformed after it has been processed by the service's component but before it has been sent to the outbound endpoint specified by that router. For example:
<outbound> <filtering-router transformer-refs="ErrorMessageToException" > <file:outbound-endpoint path="test-data/exceptions" outputPattern="Exception-[UUID].xml" transformer-refs= "ErrorMessageToExceptionBean ExceptionBeanToXML" /> </filtering-router> ... </outbound>
Lastly, you can specify a response transformer, which converts response message payloads on their way from the service back to the caller. To configure a response transformer, you use the responseTransformers-refs attribute on the router, or you can use the <response-transformer> element. For example:
<inbound> <vm:inbound-endpoint path="my.inbound.endpoint" responseTransformer-refs="myAppender" /> </inbound> <some-component/>
In this example, the response message from "some-component" is transformed using the "myAppender" transformer before being returned to the caller. For more information on response messages and the messaging styles supported by Mule, see Mule Messaging Styles .
Chaining Transformers
You can chain transformers together so that the output from one transformer becomes the input for the next. To chain transformers, you create a space-separated list of transformers in the transformer-refs or responseTransformer-refs attributes or by creating multiple <transformer> elements as shown above.
For example, this chain ultimately converts from a ByteArray to InputStream:
transformer-refs="ByteArrayToString StringToObject ObjectToInputStream"
You could also configure this as follows:
<transformer ref="ByteArrayToString" /> <transformer ref="StringToObject" /> <transformer ref="ObjectToInputStream" />
Note that if you specify transformer chains, any default transformers or discoverable transformers are not applied. If you want to use those transformers, you must specify them explicitly with the other chained transformers.
Transformation Best Practices
Mule has an efficient transformation mechanism. Transformers are applied to inbound or outbound endpoints, and the data is transformed just before it is sent from a service or just before it is received by another service. Transformers can be concatenated, so it is simple to perform multiple transformations on data in transit.
There is no one standard approach for how and where transformations should occur. Some maintain that because transformation should always be applied on inbound/outbound data, transformations should be available as part of the enterprise service bus instead of inside the service components. This approach matches the concepts of Aspect Oriented Programming (AOP). Others conclude that it is far more efficient to encode the transformation logic into the service components themselves. In the second case, however, there is no distinction between code that is related to a business process and code that is generic enough to be reused, which contradicts the philosophy of an ESB.
While there is no industry best practice, MuleSoft recommends that developers examine their transformation logic to see if it will always be used (AOP) or if it is specific to a business process. In general, if it will always be used, you should use a transformer, and if it is specific to a single business process, it should be part of the service component.
Note the following cases where you should not configure a transformer:
- Default transformers: some transports have default transformers that are called by default, but only if you don't configure explicit transformations.
- Discoverable transformers: some transformers can be discovered and used automatically based on the type of message. You do not configure these transformers explicitly. These include custom transformers that have been defined as discoverable. For more information, see Creating Custom Transformers .
References: http://msdn2.microsoft.com/en-us/library/aa480061.aspx http://blogs.ittoolbox.com/eai/applications/archives/transformation-in-a-soa-12186
Available Transformers
Following are the transformers available with Mule. Some transformers are specific to a transport or module. For more information, see Available Transports and Using Mule Modules . For a complete reference to the elements and attributes for the standard Mule transformers, see Transformers Configuration Reference .
Basic
The basic transformers are in the org.mule.transformer.simple package. They do not require any special configuration. For details on these transformers, see Transformers Configuration Reference .
BeanBuilderTransformer | (As of Mule 2.2) Constructs simple bean
objects by defining the object and then setting a number of expressions
used to populate the bean properties. For example:
<bean-builder-transformer name="testTransformer3" beanClass="org.mule.test.fruit.Orange" > <bean-property name="brand" evaluator="mule" expression="message.payload" optional="true" /> <bean-property name="segments" evaluator="mule" expression="message.header(SEGMENTS)" /> </bean-builder-transformer> |
ByteArrayToHexString <-> HexStringToByteArray |
A pair of transformers that convert between byte arrays and hex strings. |
ByteArrayToMuleMessage <-> MuleMessageToByteArray |
A pair of transformers that convert between byte arrays and Mule messages. |
ByteArrayToObject <-> ObjectToByteArray |
A pair of transformers that convert between byte arrays and objects. If the byte array is not serialized, ByteArrayToObject returns a String created from the bytes as the returnType on the transformer. |
ByteArrayToSerializable <-> SerializableToByteArray |
A pair of transformers that serialize and deserialize objects. |
ExpressionTransformer | Evaluates one or more expressions on the current message and return the results as an Array. For details, see Using Expressions . |
MessagePropertiesTransformer | A configurable message transformer that allows users to add, overwrite, and delete properties on the current message. |
ObjectArrayToString <-> StringToObjectArray |
A pair of transformers that convert between object arrays and strings. Use the configuration elements <byte-array-to-string-transformer> and <string-to-byte-array-transformer> . |
ObjectToInputStream | Converts serializable objects to an input stream but treats java.lang.String differently by converting to bytes using the String.getBytes() method. |
ObjectToOutputHandler | Converts a byte array into a String. |
ObjectToString | Returns human-readable output for various kinds of objects. Useful for debugging. |
StringAppendTransformer | Appends a string to an existing string. |
StringToObjectArray | Converts a string to an object array. Use the configuration element <string-to-byte-array-transformer> . |
XML
The XML transformers are in the org.mule.module.xml.transformer package. They provide the ability to transform between different XML formats, use XSLT, and convert to POJOs from XML. For information, see XML Module .
Scripting
The Scripting transformer transforms objects using scripting, such as JavaScript or Groovy scripts. This transformer is in the org.mule.module.scripting.transformer package.
Encryption
The encryption transformers are in the org.mule.transformer.encryption package.
Encryption <-> Decryption | A pair of transformers that use a configured EncryptionStrategy implementation to encrypt and decrypt data. |
Compression
The compression transformers are in the org.mule.transformer.compression package. They do not require any special configuration.
GZipCompressTransformer <-> GZipUncompressTransformer | A pair of transformers that compress and uncompress data. |
Encoding
The encoding transformers are in the org.mule.transformer.codec package. They do not require any special configuration.
Base64Encoder <-> Base64Decoder | A pair of transformers that convert to and from Base 64 encoding. |
XMLEntityEncoder <-> XMLEntityDecoder | A pair of transformers that convert to and from XML entity encoding. |
The Email transport provides several transformers for converting from email to string, object to MIME, and more. For details, see Email Transport .
File
The File transport provides transformers for converting from a file to a byte array (byte[]) or a string. For details, see File Transport .
HTTP
The HTTP transport provides several transformers for converting an HTTP response to a Mule message or string, and for converting a message to an HTTP request or response. For details, see HTTP Transport . Additionally, the Servlet transport provides transformers that convert from HTTP requests to parameter maps, input streams, and byte arrays. For details, see Servlet Transport .
JDBC
The Mule Enterprise version of the JDBC transport provides transformers for moving CSV and XML data from files to databases and back. For details, see JDBC Transport .
JMS
The JMS Transport and Mule WMQ Transport (enterprise only) both provide transformers for converting between JMS messages and several different data types.
Strings and Byte Arrays
The Multicast Transport and TCP Transport both provide transformers that convert between byte arrays and strings.
XMPP
The XMPP transport provides transformers for converting between XMPP packets and strings. For details, see XMPP Transport .
http://www.mulesoft.org/display/MULE2USER/Using+Transformers
发表评论
-
Mule 例子:以axis做为inbound,传递复杂类型,MuleClient UMOMessage
2009-09-22 16:29 2998这个例子出自:http://raymondhekk.iteye ... -
Axis 客户端代码
2009-09-22 16:16 1858import org.apache.axis.client.C ... -
Mule, AquaLogic ESB 学习阶段性总结 (2009.9.21)
2009-09-21 14:53 1382下面这段文字为转载:http://dragonetzhou.i ... -
Mule 的 Loan Broker 例子的 PPT (经典的ESB的例子)
2009-09-21 14:26 1839http://wiki.springside.org.cn/d ... -
Aqualogic Service Bus 的第三个例子 (消息流进阶)
2009-09-18 17:34 1026P87 的那个例子 1、已经发布的Web Servic ... -
Aqualogic Service Bus 的第二个例子 (消息流基础)
2009-09-17 15:15 1224消息流节点类型: 启动节点、路由节点、分支节点、管道对节点 ... -
Aqualogic Service Bus 的第一个例子 (入门)
2009-09-17 11:17 1579本例子出自 《SOA权威指南》 第三章中的那个入门例子。 亲 ... -
XMPP协议简介
2009-09-07 14:15 1790XMPP协议简介 XMPP(Ext ... -
REST(Representational State Transfer) 介绍
2009-08-31 23:24 1347REST(Representational State Tra ... -
Staged Event Driven Architecture (SEDA) 介绍
2009-08-31 10:29 2463一、前言 二、当前流行的两种并发处理编程模型 ... -
Camel 入门
2009-08-27 18:25 899前段时间和一些朋友聊 ... -
OSGi 入门
2009-08-27 18:15 704还没开始入... -
Mule 的消息路由
2009-08-27 17:53 1248Mule的消息路由 作者 J ... -
Mule 的第二个例子
2009-08-27 15:17 2966这个例子 主要 演示了 web service 作为 inbo ... -
Geronimo入门
2009-08-25 16:23 955http://www.matrix.org.cn/resour ... -
Apache Mina 入门
2009-08-25 13:31 11892007 年 12 月 24 日 本文将通过一个简单的问 ... -
CXF -- JAXB
2009-08-21 10:38 5588JAXB : Java API for XML Bindin ... -
CXF -- JAX-WS
2009-08-21 10:01 1367JAX-WS Java API for XML Web Se ... -
CXF的第一个例子 -- 深入剖析
2009-08-20 20:43 1722Web Service 的 Client 和 Server 端 ... -
CXF的第一个例子 (附 wsdl详解)
2009-08-20 16:52 30571、在eclipse中 创建一个java project。 ...
相关推荐
文档详细介绍了Mule Studio的各个部件,包括端点(Endpoints)、组件(Components)、转换器(Transformers)、过滤器(Filters)、流程控制(Flow Controls)、路由器(Routers)和活动范围(Scopes)等核心组件。...
5. **Transformers**: 变换器用于将数据从一种格式转换为另一种格式,以适应不同的系统接口要求。例如,JSON到XML,或者CSV到Java对象。 6. **API Manager**: 虽然在社区版中可能不完全提供,但MuleSoft的API ...
在这个实验中,我们将探讨Mule的核心概念,包括数据流、连接器、 transformers以及如何构建一个简单的应用。 1. **Mule ESB介绍** Mule ESB是MuleSoft公司开发的一款强大且灵活的中间件,用于构建企业级的集成解决...
6. **数据转换与处理**:探讨如何使用Transformers进行数据格式转换,以及使用DataWeave进行复杂的数据操作。 7. **异常处理**:讲解Mule的错误处理机制,包括全局错误处理和特定Flow的错误处理。 8. **部署与测试**...
Mule ESB(Enterprise Service Bus,企业服务总线)是一款强大的开源集成平台,它帮助企业将不同的系统、应用程序和服务连接在一起,实现数据的高效流转。本教程将带您入门Mule ESB项目,通过实例学习其核心概念和...
在学习Mule ESB的过程中,重要的是理解其核心组件,例如Message Processors(消息处理器)、Connectors(连接器)和Transformers(转换器)。消息处理器负责控制流程的执行,如选择、过滤、分发消息;连接器用于与...
Common transports, routers, and transformers Security, routing, orchestration, and transactions About the Authors David Dossot is a software architect and has created numerous modules and transports ...
4. **Message Transformers**: 在Mule中,数据在传输过程中可能需要转换为不同的格式。示例可能包括XML到JSON,或者 vice versa 的转换。 5. **Flow Control**: Mule的流程控制元素(如Choice Router,Splitter,...
- **Transformers**:转换器用于在数据流中改变数据格式,确保数据在不同系统间能正确传递。 2. **Mule的部署模型** - **Standalone**:独立部署模式,适合小型项目或测试环境。 - **CloudHub**:MuleSoft提供的...
通常,这样的文档会解释Mule ESB的工作原理,包括Inbound Endpoints(输入端点)、Outbound Endpoints(输出端点)、Transformers(转换器)和Components(组件)等关键概念。此外,还可能介绍Mule的应用场景,如B2B...
- **转换器(Transformers)**: - 自定义转换器:根据特定需求定制数据转换逻辑。 - Object-to-XML 转换器:将 Java 对象转换为 XML 文档。 - XSLT 转换器:使用 XSLT 规则对 XML 数据进行转换。 - Xml/Json-to...
变换器(Transformers) 变换器用于转换消息的格式或内容。Mule 2.0的Transformer配置变得更加灵活,支持更多的转换选项,便于处理复杂的集成场景。 ##### 7. 桥接(Bridging) 桥接功能允许Mule在不同环境中...
手册中也包含了创建自定义转换器(transformers)和拦截器(interceptors)的指导。 8. 注解和绑定: 用户指南中还介绍了如何使用各种注解(annotations)来创建服务对象和转换器,以及如何通过注解来配置组件。...
#### 六、使用转换器(Using Transformers) 1. **转换器配置参考**:提供各种转换器的配置参考,帮助开发者正确使用转换器。 2. **原生 JSON 支持**:介绍 Mule 对 JSON 的原生支持。 3. **XML 格式化转换器**:...
3. **Transformers与Filters**:转换器用于在不同数据格式之间进行转换,而过滤器则用于根据特定条件筛选消息。通过示例,你可以学习如何创建自定义转换器和过滤器,以及如何在流程中应用它们。 4. **Error ...
例如,MuleStudio工具箱中的端点(Endpoints)、组件(Components)、转换器(Transformers)、过滤器(Filters)和流程控制(FlowControls)等关键概念。 端点(Endpoints)是MuleStudio中处理数据交换的起点或...
**转换器 (Transformers)** 转换器用于改变消息的内容或格式。它们可以帮助开发者处理不同数据源之间的兼容性问题。 **完整的 Mule 2.0 配置文件示例 (Complete Mule2.0 Configuration File)** 这一部分提供了一...
Mule的核心架构基于事件驱动模型,它由三个主要部分组成:消息代理、连接器和 transformers。消息代理负责接收和路由消息,连接器用于连接到各种外部系统,而transformers则处理数据转换。这种架构使得Mule能够灵活...