简体   繁体   English

ule子定制变压器

[英]Mule custom transformer with

I'm having some trouble finding out how to create a custom transformer that can input and output a file in Mule 3.2. 我在查找如何创建可以在Mule 3.2中输入和输出文件的自定义转换器时遇到了一些麻烦。 I have prototyped the code for the transformation and that works fine but I can't find any documentation on how to take in a file in a transformer. 我已经为转换编写了代码原型,并且可以正常工作,但是我找不到任何有关如何在转换器中获取文件的文档。

Here is what I have so far as I'm but even this throws an error: 这是我目前所拥有的,但是即使这样也会引发错误:

@ContainsTransformerMethods
  public class xmlToJson {

  @Transformer
  public File xmlIn(File file) {
    // logic to go here
    return file;
  }
}

Here is the exception that is thrown: 这是抛出的异常:

ERROR 2012-06-27 14:08:37,664 [main] org.mule.tooling.server.application.
ApplicationDeployer: null
java.lang.IllegalStateException: Cannot convert value of type [convert.xmlToJson]
to required type [org.mule.api.processor.MessageProcessor] for property 'messageProcessors[0]': no matching editors or conversion strategy found

I can't seem to find any documentation or tutorials that show how to structure a custom transformer to take in a file. 我似乎找不到任何文档或教程来显示如何构建自定义转换器以接收文件。

The annoteted transformer are usually intended for automatic transformation as explained here: 带注释的变压器通常用于自动转换,如下所示:

http://www.mulesoft.org/documentation/display/MULE3USER/Creating+Custom+Transformers http://www.mulesoft.org/documentation/display/MULE3USER/Creating+Custom+Transformers

What would probably fit better you use case is creating a custom transforme by extending the AbstractTransformer as explained here: 您可能更适合用例的方法是,通过扩展AbstractTransformer来创建自定义变换,如下所示:

http://www.mulesoft.org/documentation/display/MULE3USER/Creating+Custom+Transformer+Class http://www.mulesoft.org/documentation/display/MULE3USER/Creating+Custom+Transformer+Class

You can find a good tutorial about how to use either of this approaches at the following link 您可以在以下链接中找到有关如何使用这两种方法的很好的教程

http://www.mulesoft.org/documentation/display/MULE3EXAMPLES/Invoking+Component+Methods http://www.mulesoft.org/documentation/display/MULE3EXAMPLES/Invoking+Component+Methods

In order to create a custom transformer with a custom logic you need to create your custom class which extends AbstractMessageTransformer and then you should override the transformMessage() from this Abstract class. 为了创建具有自定义逻辑的自定义转换器,您需要创建自定义类,该自定义类扩展了AbstractMessageTransformer,然后应从此Abstract类中覆盖transformMessage()。 After that only you can provide your custom class in any of the transformer tags. 之后,只有您可以在任何转换器标签中提供自定义类。 The annotated transformers will be registered within Mule and they would get called automatically if Mule needs to transform from sourceType to returnType. 带注释的转换器将在Mule中注册,如果Mule需要从sourceType转换为returnType,它们将被自动调用。

@ContainsTransformerMethods
public class MyCustomTransformers
{
 @Transformer
  public URL stringToURL(String string) throws MalformedURLException
   {
     return new java.net.URL(string);
   }
}

Here the sourceType is String and returnType is URL. 这里的sourceType是String,returnType是URL。 So whenever Mule itself needs to convert from a String to a URL, this transformer will be used. 因此,每当Mule本身需要从String转换为URL时,都将使用此转换器。

Here is a nice link for creating custom transformers in Mule 这是一个在Mule中创建自定义转换器的好链接

http://javacodinggeeks.blogspot.in/2015/05/writing-custom-transformers-in-mule.html http://javacodinggeeks.blogspot.in/2015/05/writing-custom-transformers-in-mule.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM