You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by jamalissimo <ro...@gmail.com> on 2013/07/04 08:16:59 UTC

File upload

Hello guys,

I have working file upload route(
http://camel.465427.n5.nabble.com/Send-file-via-POST-request-td5728674.html#a5729109
). Only problem is that I can send only file which is located at the same
server as Karaf. My workflow is like this:

Server with upload form -> Upload to server with Karaf -> Save it as
temporary file -> Take file from temp -> Send @POST request as
MultiPartEntity -> Save it to server with documents

I am using Karaf 2.3.1, Camel 2.11 and I noticed in
http://camel.apache.org/cxfrs.html that InputStream can be used for request
binding, but I did not find any example or hint how to do that.

Thanks for advice

-Roman





--
View this message in context: http://camel.465427.n5.nabble.com/File-upload-tp5735172.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: File upload

Posted by jamalissimo <ro...@gmail.com>.
I moved the question to CXF forums and I also added solution 

http://cxf.547215.n5.nabble.com/Multipart-file-upload-td5730547.html



--
View this message in context: http://camel.465427.n5.nabble.com/File-upload-tp5735172p5735840.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: File upload

Posted by Sergey Beryozkin <sb...@gmail.com>.
On 08/07/13 13:57, Sergey Beryozkin wrote:
> Hi,
>
> The method expects a form payload but the log shows the content type is
> 'application/x-www-form-urlencoded'...
sorry, I meant to say the method expects a multipart/form-data payload...

sergey
> Please consider asking on CXF users list when a route does not work due
> to a CXF specific exception...
>
> Thanks, Sergey
>
> On 08/07/13 13:30, jamalissimo wrote:
>> Hello Sergey,
>>
>> thanks for the tip. I am still experimenting and so far I can see from
>> the
>> log, that I am receiving the request, but I am not able create a
>> condition
>> for choice definition.
>>
>> This is the REST part:
>>
>>     @POST
>>     @Consumes(MediaType.MULTIPART_FORM_DATA)
>>     @Path("/upload")
>>     @Produces(MediaType.APPLICATION_JSON)
>>     public Response uploadTest (InputStream is) throws IOException {
>>         return null;
>>     }
>>
>> And here is beginning of the route:
>>
>> from("cxfrs:bean:myServer")
>>    .routeId("myMainRoute")
>>     .choice()
>>      .when(header(Exchange.HTTP_PATH).isEqualTo("/upload"))
>>       ......
>>
>> The karaf.log says, that it can not find any matching operation nor
>> method
>>
>> 2013-07-08 12:42:31,594 | DEBUG | upload | JAXRSUtils |
>> apache.cxf.jaxrs.utils.JAXRSUtils  516 | 139 -
>> org.apache.cxf.cxf-rt-frontend-jaxrs - 2.7.4 | No method match, method
>> name
>> : upload, request path : /upload, method @Path : /upload, HTTP Method :
>> POST, method HTTP Method : POST, ContentType :
>> application/x-www-form-urlencoded, method @Consumes :
>> multipart/form-data,,
>> Accept :
>> text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8,,
>> method @Produces : application/json
>>
>>
>> -Br, Roman
>>
>>
>>
>> --
>> View this message in context:
>> http://camel.465427.n5.nabble.com/File-upload-tp5735172p5735284.html
>> Sent from the Camel - Users mailing list archive at Nabble.com.
>>


Re: File upload

Posted by Sergey Beryozkin <sb...@gmail.com>.
Hi,

The method expects a form payload but the log shows the content type is 
'application/x-www-form-urlencoded'...
Please consider asking on CXF users list when a route does not work due 
to a CXF specific exception...

Thanks, Sergey

On 08/07/13 13:30, jamalissimo wrote:
> Hello Sergey,
>
> thanks for the tip. I am still experimenting and so far I can see from the
> log, that I am receiving the request, but I am not able create a condition
> for choice definition.
>
> This is the REST part:
>
> 	@POST
> 	@Consumes(MediaType.MULTIPART_FORM_DATA)
> 	@Path("/upload")
> 	@Produces(MediaType.APPLICATION_JSON)
> 	public Response uploadTest (InputStream is) throws IOException {
> 		return null;
> 	}
>
> And here is beginning of the route:
>
> from("cxfrs:bean:myServer")
>    .routeId("myMainRoute")
>     .choice()		
>      .when(header(Exchange.HTTP_PATH).isEqualTo("/upload"))
>       ......
>
> The karaf.log says, that it can not find any matching operation nor method
>
> 2013-07-08 12:42:31,594 | DEBUG | upload | JAXRSUtils |
> apache.cxf.jaxrs.utils.JAXRSUtils  516 | 139 -
> org.apache.cxf.cxf-rt-frontend-jaxrs - 2.7.4 | No method match, method name
> : upload, request path : /upload, method @Path : /upload, HTTP Method :
> POST, method HTTP Method : POST, ContentType :
> application/x-www-form-urlencoded, method @Consumes : multipart/form-data,,
> Accept : text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8,,
> method @Produces : application/json
>
>
> -Br, Roman
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/File-upload-tp5735172p5735284.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>

Re: File upload

Posted by jamalissimo <ro...@gmail.com>.
Hello Sergey,

thanks for the tip. I am still experimenting and so far I can see from the
log, that I am receiving the request, but I am not able create a condition
for choice definition. 

This is the REST part:

	@POST
	@Consumes(MediaType.MULTIPART_FORM_DATA)
	@Path("/upload")
	@Produces(MediaType.APPLICATION_JSON)
	public Response uploadTest (InputStream is) throws IOException {
		return null;
	} 

And here is beginning of the route:

from("cxfrs:bean:myServer")
  .routeId("myMainRoute")  
   .choice()		
    .when(header(Exchange.HTTP_PATH).isEqualTo("/upload"))
     ......

The karaf.log says, that it can not find any matching operation nor method

2013-07-08 12:42:31,594 | DEBUG | upload | JAXRSUtils |
apache.cxf.jaxrs.utils.JAXRSUtils  516 | 139 -
org.apache.cxf.cxf-rt-frontend-jaxrs - 2.7.4 | No method match, method name
: upload, request path : /upload, method @Path : /upload, HTTP Method :
POST, method HTTP Method : POST, ContentType :
application/x-www-form-urlencoded, method @Consumes : multipart/form-data,,
Accept : text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8,,
method @Produces : application/json


-Br, Roman



--
View this message in context: http://camel.465427.n5.nabble.com/File-upload-tp5735172p5735284.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: File upload

Posted by Sergey Beryozkin <sb...@gmail.com>.
Hi
On 04/07/13 08:16, jamalissimo wrote:
> Hello guys,
>
> I have working file upload route(
> http://camel.465427.n5.nabble.com/Send-file-via-POST-request-td5728674.html#a5729109
> ). Only problem is that I can send only file which is located at the same
> server as Karaf. My workflow is like this:
>
> Server with upload form -> Upload to server with Karaf -> Save it as
> temporary file -> Take file from temp -> Send @POST request as
> MultiPartEntity -> Save it to server with documents
>
> I am using Karaf 2.3.1, Camel 2.11 and I noticed in
> http://camel.apache.org/cxfrs.html that InputStream can be used for request
> binding, but I did not find any example or hint how to do that.
>
I believe you can use cxfrs simple binding to accept multipart payloads 
and then reuse the accepted payload, as InputStream in your case, with 
cxfrs producer - I haven't tried this option, so please experiment.
I'm sure there are other options there with Camel Jetty, etc.

Now, as far as cxfrs is concerned, one option is to use CXF JAX-RS 
endpoint directly and link to it from Camel Servlet via camel transport, 
so you'd have something like


@POST
public void upload (InputStream is) {
    WebClient.create(targetAddress).type("multipart/form-data").post(is);
}

Cheers, Sergey

> Thanks for advice
>
> -Roman
>
>
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/File-upload-tp5735172.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>