Multipart Jersey Request Does Not Work with Mule 3.5.0

Posted on the 02 December 2016 by Abhishek Somani @somaniabhi
We can create file upload functionality in mule which is described in this blog post. But this solution does not work with mule version 3.5.0 and throws errors like this.

java.lang.StringIndexOutOfBoundsException: String index out of range: -1
at java.lang.String.substring(String.java:1915)
at org.mule.transport.http.multipart.MultiPartInputStream.parse(MultiPartInputStream.java:349)
at org.mule.transport.http.multipart.MultiPartInputStream.getParts(MultiPartInputStream.java:304)
at org.mule.transport.http.HttpMultipartMuleMessageFactory.extractPayloadFromHttpRequest(HttpMultipartMuleMessageFactory.java:35)
at org.mule.transport.http.HttpMuleMessageFactory.extractPayload(HttpMuleMessageFactory.java:75)
at org.mule.transport.AbstractMuleMessageFactory.doCreate(AbstractMuleMessageFactory.java:79)
at org.mule.transport.AbstractMuleMessageFactory.create(AbstractMuleMessageFactory.java:63)
at org.mule.transport.AbstractTransportMessageHandler.createMuleMessage(AbstractTransportMessageHandler.java:458)
at org.mule.transport.AbstractTransportMessageProcessTemplate.createMessageFromSource(AbstractTransportMessageProcessTemplate.java:147)
at org.mule.transport.http.HttpMessageProcessTemplate.createMessageFromSource(HttpMessageProcessTemplate.java:286)
at org.mule.transport.AbstractTransportMessageProcessTemplate.getMuleEvent(AbstractTransportMessageProcessTemplate.java:48)
at org.mule.execution.FlowProcessingPhase$1$1.process(FlowProcessingPhase.java:74)
at org.mule.execution.FlowProcessingPhase$1$1.process(FlowProcessingPhase.java:63)
at org.mule.execution.ExecuteCallbackInterceptor.execute(ExecuteCallbackInterceptor.java:16)
at org.mule.execution.HandleExceptionInterceptor.execute(HandleExceptionInterceptor.java:30)
at org.mule.execution.HandleExceptionInterceptor.execute(HandleExceptionInterceptor.java:14)
at org.mule.execution.BeginAndResolveTransactionInterceptor.execute(BeginAndResolveTransactionInterceptor.java:54)
at org.mule.execution.ResolvePreviousTransactionInterceptor.execute(ResolvePreviousTransactionInterceptor.java:44)
at org.mule.execution.SuspendXaTransactionInterceptor.execute(SuspendXaTransactionInterceptor.java:50)
at org.mule.execution.ValidateTransactionalStateInterceptor.execute(ValidateTransactionalStateInterceptor.java:40)
at org.mule.execution.IsolateCurrentTransactionInterceptor.execute(IsolateCurrentTransactionInterceptor.java:41)
at org.mule.execution.ExternalTransactionInterceptor.execute(ExternalTransactionInterceptor.java:48)
at org.mule.execution.RethrowExceptionInterceptor.execute(RethrowExceptionInterceptor.java:28)
at org.mule.execution.RethrowExceptionInterceptor.execute(RethrowExceptionInterceptor.java:13)
at org.mule.execution.TransactionalErrorHandlingExecutionTemplate.execute(TransactionalErrorHandlingExecutionTemplate.java:109)
at org.mule.execution.FlowProcessingPhase$1.run(FlowProcessingPhase.java:62)
at org.mule.transport.TrackingWorkManager$TrackeableWork.run(TrackingWorkManager.java:267)
at org.mule.work.WorkerContext.run(WorkerContext.java:286)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
This is a known issue in mule and it is rectified in further version of mule , but not in 3.5.0 . Now to resolve this , you need to remove mule-transport-http-3.5.0.jar file from mule_home/lib/mule folder and add mule-transport-http-3.3.1.jar and restart mule . It should work fine after that .