Hi,
Sorry for a delay; you've mentioned at CXF users that this all actually
works except that you have to use some hard-coded values.
Can you explain what exactly is hard-coded, are you not able to get the
parameters passed to cxfrs uploadFile method ? I think with cxfrs server
one has to write a processor routine to get to the parameters, as in
this form the cxfrs is only used to match the HTTP request.
May be, if all you have to do is to effectively proxy the request, the
camel http component can be simpler to use; if you'd like to use cxfrs
then consider using CXF JAXRS endpoint directly (use Camel Servlet and
transport to link to it), have it processing GET and uploading to the
destination with the code like this one:
http://cxf.apache.org/docs/jax-rs-multiparts.html#JAX-RSMultiparts-Uploadingfiles
and then return from the route.
However it sounds like it may be not the easiest approach, so I'm not
100% sure
Cheers, Sergey
On 06/03/13 12:51, jamalissimo wrote:
Hello guys,
I am currently working on quite exciting assignment. Here is what I want to
do:
@GET REST response -> CXF to get parameters from exchange -> 3rd Party API
to get session_id -> BEAN to send data via POST method and in
multipart/mixed( it is for uploading files )
My first problem is that I don't know how to set the REST, for now it looks
like this:
@GET
@Path("/{myServerHost}/upload")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.MULTIPART_FORM_DATA)
public Response uploadFile(@PathParam("myHost") String knowledgetreeHost,
@QueryParam("myPort") String knowledgetreePort,
@QueryParam("user")
String user,
@QueryParam("password") String password,
@QueryParam("file") String file)
{
return null;
}
Then I have route and I am setting http method to post
.when(header(CxfConstants.OPERATION_NAME).isEqualTo("uploadFile"))
.recipientList("https://myserver.com/service/?method=login&username=myusername&password=123456")
.beanRef("myBean", "getSessionId")
// For now I needed data in GET(session_id),it is no problem, but in
the following method
// I need to send POST request
.setHeader(Exchange.HTTP_METHOD, constant("POST"))
.beanRef("myBean","uploadMyFile")
.endChoice()
Method uploadMyFile should send POST request. For now it looks like this:
public void uploadMyFile(Exchange exchange) throws IOException {
//SESSION_ID is set in previous steps of route
String sessionId =
exchange.getProperty("SESSION_ID").toString();
//FILENAME is taken from URL
/**
String filename = (String) msgList.get(4);
exchange.setProperty("FILENAME", filename);
*/
String filename =
"@"+exchange.getProperty("FILENAME").toString();
String pathToUploader =
"https://myserver.com/service/upload.php";
// Instantiate an HttpClient
HttpClient client = new HttpClient();
// Instantiate a POST HTTP method
PostMethod method = new PostMethod(pathToUploader);
method.setRequestHeader("Content-type",
exchange.getIn().getHeader("CONTENT_TYPE") + ";charset="+
exchange.getIn().getHeader("CONTENT_ENCODING"));
// Define name-value pairs to set into the QueryString
NameValuePair nvp1 = new NameValuePair("session_id", sessionId);
NameValuePair nvp2 = new NameValuePair("action", "A");
NameValuePair nvp3 = new NameValuePair("myfile", filename);
method.setQueryString(new NameValuePair[] { nvp1, nvp2, nvp3 });
try {
int statusCode = client.executeMethod(method);
System.out.println("Status Code = " + statusCode);
System.out.println("QueryString>>> " +
method.getQueryString());
System.out.println("Status Text>>>" +
HttpStatus.getStatusText(statusCode));
// Get data as a String
System.out.println(method.getResponseBodyAsString());
exchange.getIn().setHeader("HTTP_METHOD", "POST");
exchange.getIn().setBody(method.getResponseBodyAsString());
// release connection
method.releaseConnection();
} catch (IOException e) {
e.printStackTrace();
}
}
Basically I need to know how to set REST and how to set POST method for CXF
Thanks
-Br, Roman
--
View this message in context:
http://camel.465427.n5.nabble.com/Send-file-via-POST-request-tp5728674.html
Sent from the Camel - Users mailing list archive at Nabble.com.