Hi
Yes, I've seen this question on the Camel users list but I don't really
understand where @GET happens to be involved. Let me reply to the
original request as it appears it is more to do with the way parameters
are passed with camel cxfrs component
Cheers, Sergey
On 08/03/13 10:15, jamalissimo wrote:
Hello,
I have a CXF consumer which is able to send @POST http request and via this
upload a file. This is working but before I send the request I need to get
IP of server where to upload it to, credentials and name of the file. I was
trying to add @PathParam and @QueryParam but with theses annotations it did
not work. My question is if it is possible to retrieve @GET data from URL
and then send @POST multipart request and how to do that? For now it works
with hard-coded data and I really have no idea how to pass variables
mentioned above.
For now, my consumer looks like this:
@POST
@Path("/upload")
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@Produces(MediaType.APPLICATION_JSON)
public Response uploadFile(
@Multipart(value = "session_id") String sessionId,
@Multipart(value = "action") String action
){
return null;
}
and code sending the request looks like this:
String pathToUploader =
"https://myserver.com/service/upload.php";
String session_id = "0kk1sobmbuforgjamj10470a23";
String action = "A";
File myfile = new File("/path/to/my/file/document_folder1.txt");
HttpClient client = new DefaultHttpClient();
client.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION,
HttpVersion.HTTP_1_1);
HttpPost post = new HttpPost(pathToUploader);
MultipartEntity entity = new MultipartEntity(
HttpMultipartMode.BROWSER_COMPATIBLE );
// For File parameters
entity.addPart("myfile", new FileBody((( File ) myfile),
"application/octet-stream" ));
// For usual String parameters
entity.addPart("session_id", new StringBody(session_id,
"text/plain",
Charset.forName( "UTF-8" )));
entity.addPart("action", new StringBody(action,
"text/plain",
Charset.forName( "UTF-8" )));
post.setEntity( entity );
Thanks
-Roman
--
View this message in context:
http://cxf.547215.n5.nabble.com/MultipartBody-with-PathParam-and-QueryParam-tp5724291.html
Sent from the cxf-user mailing list archive at Nabble.com.
--
Sergey Beryozkin
Talend Community Coders
http://coders.talend.com/
Blog: http://sberyozkin.blogspot.com