0

In Mule I need to manipulate via java an xlsx file sent via http post. How can I get the file posted via java? I thought it was reachable via Mule message but

eventContext.getMessage().getOutboundAttachmentNames()

and neither

eventContext.getMessage().getInboundAttachmentNames()

give results.

Any ideas?

to make http post test I use curl in this way:

curl --form upload=@filename --form press=OK http://localhost:8088/HttpController

The flow is simply something like this:

    <flow name="xlsx_to_xls_converterFlow1" doc:name="xlsx_to_xls_converterFlow1">
        <http:inbound-endpoint exchange-pattern="request-response"   doc:name="HTTP" address="http://localhost:8088/HttpController"/>
        <logger  level="INFO" doc:name="Logger"/>
        <component class="Convert_XLSXtoXLS" doc:name="Java"/>
</flow>

Thank you

UPDATED

To let the flagged solution work occurs to override extractPayloadFromHttpRequest of HttpMultipartMuleMessageFactory to choose the proper input file name. In fact with the current HttpMultipartMuleMessageFactory implementation the file is uploaded only if input file name = "payload"

2 Answers 2

3

You need to configure your HTTP connector to handle multipart requests to receive them in attachments. Add the following inside its XML configuration:

<service-overrides messageFactory="org.mule.transport.http.HttpMultipartMuleMessageFactory"/>

( if you think this is cumbersome, please upvote https://www.mulesoft.org/jira/browse/MULE-6862 )

Sign up to request clarification or add additional context in comments.

1 Comment

Actually it's not enough to change the messageFactory. I update the question putting the solution in there.
0

Putting a Java component behind an http:inbound-endpoint results in an InputStream as argument to the method in the component.

You have to work with the input stream or just put an echo in between:

<flow name="FileUpload" doc:name="FileUpload">
    <http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="9090" doc:name="HTTP"/>
    <echo-component doc:name="Echo"/>
    <component class="de.codecentric.basics.FileUploadComponent" doc:name="Java"/>
</flow>

The component has one method:

package de.codecentric.basics;

public class FileUploadComponent {

public String process(String message) {
System.out.println("message: " + message);
return "OK";
}

}

You still have to parse the multipart form data in this case.

Or try to use the REST component, see: http://www.javaroots.com/2013/05/createfileuploadmulejerseyrest.html

1 Comment

@David: The solution works, but the upload must be named "payload", e.g.: curl --form [email protected] localhost:9090 It would be better if HttpMultiPartMuleMessageFactory would parse all parts and put them in a Map with name as key. Additonal note: The service-overrides has to be in the connector, not in the endpoint.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.