camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From crmanoj <manojrathi...@gmail.com>
Subject Using camel-servlet with Multipart - unable to fetch the file
Date Thu, 09 May 2013 01:22:47 GMT
Hi,

I am trying to upload a file to the server from client using
multipart/form-data. The server endpoint is a camel-servlet endpoint. I am
able to get the httprequestbody from the call using (in.headers), to parse
the form data and uploaded file data i'm using commons-fileupload( streaming
api <http://commons.apache.org/proper/commons-fileupload/streaming.html>  )
library. Though the request is a multipart, I am unable to get the fileitems
from the function call. Here is the codesnippet used to get the item
(iter.hasNext() always returns false).

HttpServletRequest request = (HttpServletRequest)
headers.get(Exchange.HTTP_SERVLET_REQUEST);

// Check if the request is actually a multipart/form-data request.
LOG.info("IS Mulipart: " + ServletFileUpload.isMultipartContent(request));
if (!ServletFileUpload.isMultipartContent(request))
{
     return "No Data found";
}
// Create a new file upload handler
ServletFileUpload upload = new ServletFileUpload();
FileItemIterator iter = upload.getItemIterator(request);
LOG.info("iter has next: " + iter.hasNext());

My Camel route looks like below:

from("servlet:///addContent").streamCaching()
    .to("log:servlet").beanRef("sampleProcessor");

My camel Servlet component definition goes as below:

 <service ref="camelServlet">
        <interfaces>
        	<value>javax.servlet.Servlet</value>
            <value>org.apache.camel.component.http.CamelServlet</value>
        </interfaces>
        <service-properties>
            <entry key="alias" value="/camel/services" />
            <entry key="matchOnUriPrefix" value="true" />
            <entry key="servlet-name" value="CamelServlet"/>
        </service-properties>
    </service>

<osgi:reference id="servletref"
interface="org.apache.camel.component.http.CamelServlet">
    <osgi:listener bind-method="register" unbind-method="unregister">
	<ref bean="httpRegistry" />
    </osgi:listener>
</osgi:reference>

<bean id="httpRegistry"
class="org.apache.camel.component.servlet.DefaultHttpRegistry">
</bean>
<bean id="servlet"
class="org.apache.camel.component.servlet.ServletComponent">
	<property name="httpRegistry" ref="httpRegistry" />
</bean>

This project is run in fuse-esb-7.1.0.fuse-047 using camel version: 2.9.
JDK: 1.6.

Could anyone guide me to separate the form parameters and file data using
servlet endpoint?

Thanks in Advance!



--
View this message in context: http://camel.465427.n5.nabble.com/Using-camel-servlet-with-Multipart-unable-to-fetch-the-file-tp5732204.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Mime
View raw message