[mule-user] Problem in Http connector and Multipart/form-data

2 views
Skip to first unread message

Sadegh Y

unread,
Sep 17, 2011, 2:06:32 AM9/17/11
to us...@mule.codehaus.org
Hi,
I have a problem in mule http connector with multipart/form-data. When i send a request from my http clinet to Mule i get this exception:
{color:#333399}Exception stack is:
1. todo (java.lang.IllegalArgumentException)
org.mule.transport.http.HttpMuleMessageFactory:105 (null)
2. Failed to create MuleMessage (org.mule.api.lifecycle.CreateException)
org.mule.transport.AbstractTransportMessageHandler:450 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/api/lifecycle/CreateException.html)
--------------------------------------------------------------------------------
Root Exception stack trace:
java.lang.IllegalArgumentException: todo
at org.mule.transport.http.HttpMuleMessageFactory.extractPayloadFromHttpRequest(HttpMuleMessageFactory.java:105)
at org.mule.transport.http.HttpMuleMessageFactory.extractPayload(HttpMuleMessageFactory.java:72)
at org.mule.transport.AbstractMuleMessageFactory.create(AbstractMuleMessageFactory.java:47)
+ 3 more (set debug level logging or '-Dmule.verbose.exceptions=true' for everything)

{color:#000000}My mule config is :

{color:#003366}<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns="http://www.mulesoft.org/schema/mule/core"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:http="http://www.mulesoft.org/schema/mule/http"
xmlns:vm="http://www.mulesoft.org/schema/mule/vm"
xsi:schemaLocation="
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/3.2/mule.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/3.2/mule-http.xsd
http://www.mulesoft.org/schema/mule/vm http://www.mulesoft.org/schema/mule/vm/3.2/mule-vm.xsd">


<description>
This configuration uses an HTTP endpoint to receive requests.
</description>

<custom-transformer name="ExceptionToString" class="org.mule.example.hello.ExceptionToString"/>

<http:connector name="HttpConnector" clientSoTimeout="12000" keepSendSocketOpen="true" />
<http:endpoint name="HttpEndpoint" address="http://localhost:8888/services" method="POST" encoding="utf-8" mimeType="multipart/form-data"
connector-ref="HttpConnector">
</http:endpoint>


<flow name="core">
<inbound-endpoint ref="HttpEndpoint" exchange-pattern="request-response" mimeType="multipart/form-data"/>
<outbound-endpoint address="stdio://ERR" exchange-pattern="one-way"/>
<custom-exception-strategy class="net.bmc.exception.MuleExceptionHandler"/>
</flow>

<flow name="exception">

<vm:inbound-endpoint path="userErrorHandler" responseTransformer-refs="ExceptionToString"
exchange-pattern="request-response"/>
<outbound-endpoint address="stdio://ERR" exchange-pattern="one-way"/>

</flow>

<!-- Handle any unexpected errors. Errors could also be routed elsewhere,
e.g. into an error file, send via email to a list, stored in a database, etc. -->
<flow name="SystemErrorHandler">
<vm:inbound-endpoint path="systemErrorHandler" exchange-pattern="request-response"/>
<outbound-endpoint address="stdio://ERR" exchange-pattern="one-way"/>
</flow>
</mule>

{color:#000000}please help me to solve this problem{color}
{color:#000000}Thanx{color}

{color}{color}{color}{color:#003366}
{color}

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email


Sadegh Y

unread,
Sep 19, 2011, 12:55:51 AM9/19/11
to us...@mule.codehaus.org
> {quote:title=Sadegh Y wrote:}{quote}

> Hi,
> I have a problem in mule http connector with multipart/form-data. When i send a request from my http clinet to Mule i get this exception:
>
> {color:#333399}Exception stack is:
> 1. todo (java.lang.IllegalArgumentException)
> org.mule.transport.http.HttpMuleMessageFactory:105 (null)
> 2. Failed to create MuleMessage (org.mule.api.lifecycle.CreateException)
> org.mule.transport.AbstractTransportMessageHandler:450 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/api/lifecycle/CreateException.html)
> --------------------------------------------------------------------------------
> Root Exception stack trace:
> java.lang.IllegalArgumentException: todo
> at org.mule.transport.http.HttpMuleMessageFactory.extractPayloadFromHttpRequest(HttpMuleMessageFactory.java:105)
> at org.mule.transport.http.HttpMuleMessageFactory.extractPayload(HttpMuleMessageFactory.java:72)
> at org.mule.transport.AbstractMuleMessageFactory.create(AbstractMuleMessageFactory.java:47)
> + 3 more (set debug level logging or '-Dmule.verbose.exceptions=true' for everything)
>
> -----

> {color:#000000}My mule config is :
>
> <?xml version="1.0" encoding="UTF-8"?>
> <description>

> This configuration uses an HTTP endpoint to receive requests.
> </description>

>
> <custom-transformer name="ExceptionToString" class="org.mule.example.hello.ExceptionToString"/>
>
> <http:connector name="HttpConnector" clientSoTimeout="12000" keepSendSocketOpen="true" />
> <http:endpoint name="HttpEndpoint" address="http://localhost:8888/services" method="POST" encoding="utf-8" mimeType="multipart/form-data"
> connector-ref="HttpConnector">
> </http:endpoint>
>
>
> <flow name="core">

> <inbound-endpoint ref="HttpEndpoint" exchange-pattern="request-response" mimeType="multipart/form-data"/>
> <outbound-endpoint address="stdio://ERR" exchange-pattern="one-way"/>
> <custom-exception-strategy class="net.bmc.exception.MuleExceptionHandler"/>
> </flow>
>
> <flow name="exception">

>
> <vm:inbound-endpoint path="userErrorHandler" responseTransformer-refs="ExceptionToString"
> exchange-pattern="request-response"/>
> <outbound-endpoint address="stdio://ERR" exchange-pattern="one-way"/>
>
> </flow>

>
> <!-- Handle any unexpected errors. Errors could also be routed elsewhere,
> e.g. into an error file, send via email to a list, stored in a database, etc. -->
> <flow name="SystemErrorHandler">

> <vm:inbound-endpoint path="systemErrorHandler" exchange-pattern="request-response"/>
> <outbound-endpoint address="stdio://ERR" exchange-pattern="one-way"/>
> </flow>
> </mule>
> -----

>
> please help me to solve this problem{color}
> Thanx
>
> Edited by: Sadegh Y on Sep 16, 2011 11:06 PM
Mule forum isn't active enough a lot of question remain without answer :( .
After investigation in mule source i found this block of code in *HttpMuleMessageFactory* class:
if (httpRequest.getContentType().contains("multipart/form-data"))
{
MultiPartInputStream in = new MultiPartInputStream(httpRequest.getBody(), httpRequest.getContentType(), null);

//We need to store this so that the headers for the part can be read
parts = in.getParts();
for (Part part : parts)
{
if (part.getName().equals("payload"))
{
body = part.getInputStream();
break;
}
}
if (body == null)
{
throw new IllegalArgumentException("todo");
}
}

So after i commented the if block or one of my parameters name being "payload" it works perfect. somebody knows why there is this kind of hard code in mule source?

Dirk Olmes

unread,
Sep 19, 2011, 9:08:13 PM9/19/11
to us...@mule.codehaus.org
> {quote:title=Sadegh Y wrote:}{quote}
> After investigation in mule source i found this block of code in *HttpMuleMessageFactory* class:
{code}

> if (httpRequest.getContentType().contains("multipart/form-data"))
> {
> MultiPartInputStream in = new MultiPartInputStream(httpRequest.getBody(), httpRequest.getContentType(), null);
>
> //We need to store this so that the headers for the part can be read
> parts = in.getParts();
> for (Part part : parts)
> {
> if (part.getName().equals("payload"))
> {
> body = part.getInputStream();
> break;
> }
> }
> if (body == null)
> {
> throw new IllegalArgumentException("todo");
> }
> }
{code}

>
> So after i commented the if block or one of my parameters name being "payload" it works perfect. somebody knows why there is this kind of hard code in mule source?

This looks like a bug to me. Can you create a JIRA please and attach this config *and a way to create a failing HTTP request* (i.e. either a for or some httpclient snippet)?

Sadegh Y

unread,
Sep 19, 2011, 11:00:50 PM9/19/11
to us...@mule.codehaus.org
Another problem is in concurrent request. when i send 20 request concurrent it cannot get the attachments. I had to lock it for solve this problem. my code is :
<div class="jive-quote"> try {
lock.lock();

//We need to store this so that the headers for the part can be read
parts = in.getParts();

for (Part part : parts) {
// if (part.getName().equals("payload"))
// {
body = part.getInputStream();
break;
// }


}
if (body == null) {
throw new IllegalArgumentException("todo");
}

} finally {
lock.unlock();
}

is it a bug or I have forgotten to configure something in config file?

Reply all
Reply to author
Forward
0 new messages