You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by "Alden, John" <JO...@LibertyMutual.com> on 2015/03/19 23:56:07 UTC

Http Component Post Parameters

Hi all, I'm having some trouble making a REST service call with POST parameters.  I saw a similar post but I didn't understand the solution and I need some more direction.

http://camel.465427.n5.nabble.com/Http-Component-Sending-Post-Parameters-td5740321.html#a5740409

The following is my route configuration.

from("timer://runOnce?repeatCount=1")
    .onException(Exception.class)
    .handled(true)
    .process(new GenericExceptionProcessor())
    .end()
    .setHeader(Exchange.HTTP_METHOD, simple("POST"))
    .setHeader(Exchange.CONTENT_TYPE, simple("application/x-www-form-urlencoded"))
    .to("https://dev-sdsservices-was8/IMSDSWebService/servlet/SDSClientRequestServlet"
        + "?proxyHost=VDDP03C-EDB4ED9&proxyPort=8888&httpClient.authenticationPreemptive=true"
        + "&authMethod=Basic&authUsername=********&authPassword=********")
        + "&serviceType=getNextIDFromDB&serviceID=1&dataElementID=814&dataSourceID=50"
    .to("file:{{sf.archive.dir}}?fileName=sds-response.xml")
    .end();

The request is made using the POST method -- verified with Fiddler.  However, the parameters are being sent as a query string on the URL.  I am successfully calling the service, however, an error is returned because the service requires POST parameters.

I would appreciate any help with POSTing the parameters ("&serviceType=getNextIDFromDB&serviceID=1&dataElementID=814&dataSourceID=50") to the service.


Re: Http Component Post Parameters

Posted by pilgrim08 <jo...@libertymutual.com>.
Thank you Willem.  I did try this solution but still it still doesn't work. 
In this case it sends the parameters in the request body but they aren't
POST parameters.  The web service I am calling is unable to access the
parameters.  When I make this call with a Straight
java.net.URLConnennection, it works fine but I would like to get this
working with Camel.  If there are other options for accomplishing this, I
would love to hear.     	 from("timer://runOnce?repeatCount=1")            
.onException(Exception.class)            .handled(true)           
.process(new GenericExceptionProcessor())            .end()           
.log("Requesting a claim ID from SDS.")           
.setHeader(Exchange.HTTP_METHOD, constant("POST"))           
.setHeader(Exchange.CONTENT_TYPE,
constant("application/x-www-form-urlencoded"))		   
*.setBody(constant("serviceType=getNextIDFromDB&serviceID=1&dataElementID=814&dataSourceID=50"))*           
.to("https://dev-sdsservices-was8/IMSDSWebService/servlet/SDSClientRequestServlet"            	
+
"?proxyHost=VDDP03C-EDB4ED9&proxyPort=8888&httpClient.authenticationPreemptive=true"            	
+ "&authMethod=Basic&authUsername=********&authPassword=********"            	
+ "&httpClient.soTimeout=5000")           
.to("file:{{sf.archive.dir}}?fileName=sds-response.xml")			.log("Completed
web service call to SDS for file ${file:name}.")            .end();Regards,
John



--
View this message in context: http://camel.465427.n5.nabble.com/Http-Component-Post-Parameters-tp5764464p5764478.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Http Component Post Parameters

Posted by Willem Jiang <wi...@gmail.com>.
I just did a quick test by using the ProduceTemplate just like this:

String out = template.requestBodyAndHeader("http://localhost:" + port1 + "/parameter", "request=PostParameter&others=blogs", Exchange.CONTENT_TYPE, "application/x-www-form-urlencoded", String.class);

The Post message can be sent out without any error.
        

--  
Willem Jiang

Red Hat, Inc.
Web: http://www.redhat.com
Blog: http://willemjiang.blogspot.com (English)
http://jnn.iteye.com (Chinese)
Twitter: willemjiang  
Weibo: 姜宁willem



On March 23, 2015 at 8:11:26 PM, pilgrim08 (john.alden@libertymutual.com) wrote:
> The web service I am calling is returning an xml response that contains
> nullPointerException. This is because the service is unable to obtain the
> POST parameters from the request and is getting a null pointer.
>  
> I was able to successfully call the service using a standard
> java.net.URLConnection but I would prefer to make the call using Camel.
>  
> Regards, John
>  
>  
>  
> --
> View this message in context: http://camel.465427.n5.nabble.com/Http-Component-Post-Parameters-tp5764464p5764641.html  
> Sent from the Camel - Users mailing list archive at Nabble.com.
>  


Re: Http Component Post Parameters

Posted by pilgrim08 <jo...@libertymutual.com>.
The web service I am calling is returning an xml response that contains
nullPointerException.  This is because the service is unable to obtain the
POST parameters from the request and is getting a null pointer.

I was able to successfully call the service using a standard
java.net.URLConnection but I would prefer to make the call using Camel.

Regards, John



--
View this message in context: http://camel.465427.n5.nabble.com/Http-Component-Post-Parameters-tp5764464p5764641.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Http Component Post Parameters

Posted by Willem Jiang <wi...@gmail.com>.
What’s kind of error did you get?

--  
Willem Jiang

Red Hat, Inc.
Web: http://www.redhat.com
Blog: http://willemjiang.blogspot.com (English)
http://jnn.iteye.com (Chinese)
Twitter: willemjiang  
Weibo: 姜宁willem



On March 20, 2015 at 8:40:48 PM, pilgrim08 (john.alden@libertymutual.com) wrote:
> Thank you Willem.
>  
> I had added the "application/x-www-form-urlencoded" content-type because I
> saw it in another thread. Maybe that wasn't a good idea.
>  
> I did try your solution of setting the parameters in the body but it still
> doesn't send them as POST parameters. In this case it sends the parameters
> in the request body. The web service I am calling is unable to access the
> parameters.
>  
> Are there other options/ideas I could try?
>  
> from("timer://runOnce?repeatCount=1")
> .onException(Exception.class)
> .handled(true)
> .process(new GenericExceptionProcessor())
> .end()
> .setHeader(Exchange.HTTP_METHOD, constant("POST"))
> .setHeader(Exchange.CONTENT_TYPE,
> constant("application/x-www-form-urlencoded"))
>  
> .setBody(constant("serviceType=getNextIDFromDB&serviceID=1&dataElementID=814&dataSourceID=50"))
>  
> .to("https://dev-sdsservices-was8/IMSDSWebService/servlet/SDSClientRequestServlet"  
> +
> "?proxyHost=VDDP03C-EDB4ED9&proxyPort=8888&httpClient.authenticationPreemptive=true"  
> + "&authMethod=Basic&authUsername=********&authPassword=********"
> + "&httpClient.soTimeout=5000")
> .to("file:{{sf.archive.dir}}?fileName=sds-response.xml")
> .end();
>  
> Regards, John
>  
>  
>  
> --
> View this message in context: http://camel.465427.n5.nabble.com/Http-Component-Post-Parameters-tp5764464p5764480.html  
> Sent from the Camel - Users mailing list archive at Nabble.com.
>  


Re: Http Component Post Parameters

Posted by pilgrim08 <jo...@libertymutual.com>.
Thank you Willem. 

I had added the "application/x-www-form-urlencoded" content-type because I
saw it in another thread.  Maybe that wasn't a good idea.

I did try your solution of setting the parameters in the body but it still
doesn't send them as POST parameters. In this case it sends the parameters
in the request body. The web service I am calling is unable to access the
parameters.  

Are there other options/ideas I could try? 

from("timer://runOnce?repeatCount=1")
 .onException(Exception.class)
 .handled(true)
 .process(new GenericExceptionProcessor())
 .end()
 .setHeader(Exchange.HTTP_METHOD, constant("POST"))
 .setHeader(Exchange.CONTENT_TYPE,
constant("application/x-www-form-urlencoded"))

.setBody(constant("serviceType=getNextIDFromDB&serviceID=1&dataElementID=814&dataSourceID=50"))

.to("https://dev-sdsservices-was8/IMSDSWebService/servlet/SDSClientRequestServlet"
     +
"?proxyHost=VDDP03C-EDB4ED9&proxyPort=8888&httpClient.authenticationPreemptive=true"  
     + "&authMethod=Basic&authUsername=********&authPassword=********" 
     + "&httpClient.soTimeout=5000")
 .to("file:{{sf.archive.dir}}?fileName=sds-response.xml")
 .end(); 

Regards, John 



--
View this message in context: http://camel.465427.n5.nabble.com/Http-Component-Post-Parameters-tp5764464p5764480.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Http Component Post Parameters

Posted by Willem Jiang <wi...@gmail.com>.
Hi,

When you use the content-type of "application/x-www-form-urlencoded”, you are supposed to send the parameters in message body instead of using URL options. You can find more information here[1]

Please put paramters into the message body by using setBody DSL 

setBody("serviceType=getNextIDFromDB&serviceID=1&dataElementID=814&dataSourceID=50”)

[1]http://stackoverflow.com/questions/14551194/how-are-parameters-sent-in-an-http-post-request

--  
Willem Jiang

Red Hat, Inc.
Web: http://www.redhat.com
Blog: http://willemjiang.blogspot.com (English)
http://jnn.iteye.com (Chinese)
Twitter: willemjiang  
Weibo: 姜宁willem



On March 20, 2015 at 6:56:38 AM, Alden, John (john.alden@libertymutual.com) wrote:
> Hi all, I'm having some trouble making a REST service call with POST parameters. I saw  
> a similar post but I didn't understand the solution and I need some more direction.
>  
> http://camel.465427.n5.nabble.com/Http-Component-Sending-Post-Parameters-td5740321.html#a5740409  
>  
> The following is my route configuration.
>  
> from("timer://runOnce?repeatCount=1")
> .onException(Exception.class)
> .handled(true)
> .process(new GenericExceptionProcessor())
> .end()
> .setHeader(Exchange.HTTP_METHOD, simple("POST"))
> .setHeader(Exchange.CONTENT_TYPE, simple("application/x-www-form-urlencoded"))  
> .to("https://dev-sdsservices-was8/IMSDSWebService/servlet/SDSClientRequestServlet"  
> + "?proxyHost=VDDP03C-EDB4ED9&proxyPort=8888&httpClient.authenticationPreemptive=true"  
> + "&authMethod=Basic&authUsername=********&authPassword=********")
> + "&serviceType=getNextIDFromDB&serviceID=1&dataElementID=814&dataSourceID=50"  
> .to("file:{{sf.archive.dir}}?fileName=sds-response.xml")
> .end();
>  
> The request is made using the POST method -- verified with Fiddler. However, the parameters  
> are being sent as a query string on the URL. I am successfully calling the service, however,  
> an error is returned because the service requires POST parameters.
>  
> I would appreciate any help with POSTing the parameters ("&serviceType=getNextIDFromDB&serviceID=1&dataElementID=814&dataSourceID=50")  
> to the service.
>  
>