简体   繁体   中英

How can I send and acquire an object from a connector in Mule Studio?

I need to send and acquire a Java object to a custom connector that is expecting:

// inside MyConnector.java
@Processor
public Object doSomething(@Default(#[payload]) final Object data) {...}

I'm trying to send it an instance of the FakeData class. I can verify this works when I send the object using Mule's FunctionalTestCase class:

<!-- inside mule-config.xml -->
<flow name="Do_Something">
    <myconnector:do-Something document-ref="#[payload]"/>
</flow>


public class FlowBuilder extends FunctionalTestCase {

    public void run() {
        Object payload = new FakeData();
        Flow flow = lookupFlowConstruct("Do_Something");
        MuleEvent event = FunctionalTestCase.getTestEvent(payload);
        MuleEvent responseEvent= flow.process(event);
    }
}

I can't figure out how to send a FakeData object and receive another object in a regular Mule flow using Mule Studio.

Can someone help me out?

------- Update --------

I am invoking the flow using an HTTP front end. The flow looks like this:

[HTTP] -> [Java "My Transformer"] -> [Custom Connector]

I tried adding a transformer in front of the connector:

public class MyTransformer extends AbstractMessageTransformer {

    @Override
    public Object transformMessage(MuleMessage message, String outputEncoding)
            throws TransformerException {
        return new fakeData();
    }
}

Now I get this response:

Could not find a transformer to transform  
"SimpleDataType{type=org.mule.example.FakeData, mimeType='*/*'}" to 
"SimpleDataType{type=org.mule.api.transport.OutputHandler, mimeType='*/*'}". 
(org.mule.api.transformer.TransformerException) (org.mule.api.transformer.TransformerException). Message payload is of type: FakeData

In your flow, you can do something like:

<set-payload value="#[new org.mule.example.FakeData()]" />

EDIT: You've modified your question and added an HTTP inbound endpoint. The error you're getting is probably because you inbound HTTP endpoint is request-response and you haven't transformed org.mule.example.FakeData into something than be streamed over HTTP.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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