You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by madhu_online1 <Na...@aoins.com> on 2014/06/22 04:54:03 UTC

Getting Bad Request response invoking REST web service

Hi,
I am trying to invoke an online REST web service through my Camel route and
get an http Bad Request response. I am not able to understand what is going
wrong.  

This is the code snippet for my route:-
MethodCallExpression encodingTransformer =  new
MethodCallExpression(URLEncoderTransformer.class, "transformBody");

	from(documentServiceEndpoint)				
			.unmarshal(format)
			.transform(encodingTransformer)
			.setHeader(Exchange.HTTP_URI,
simple("http://www.thomas-bayer.com/sqlrest/CUSTOMER/18/"))
			.toF("http://url")			
			.process(new Processor() {				
				@Override
				public void process(Exchange exchange) {
						Object fileNetResponse = exchange.getIn().getBody();
				
				} //End process
			})

It fails on the invocation of the REST web service itself. I am not sure
what is the best way to invoke the service. 

My Java snippet to invoke the same snippet works fine:-
		URL testUrl = new URL("http://www.thomas-bayer.com/sqlrest/CUSTOMER/18/");
		URLConnection conn = testUrl.openConnection(); 
		BufferedReader in = new BufferedReader(new
InputStreamReader(conn.getInputStream()));
		
		String inputLine = null;
		
		while ((inputLine = in.readLine())  != null) {
			System.out.println(inputLine);	
		}
		
		in.close();

Can someone please help me understand how I can do the same thing above in
Java in Camel? 







--
View this message in context: http://camel.465427.n5.nabble.com/Getting-Bad-Request-response-invoking-REST-web-service-tp5752659.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Getting Bad Request response invoking REST web service

Posted by Matt Sicker <bo...@gmail.com>.
I was going to suggest that perhaps you were sending too many headers that
was causing the server to blow up, but I guess it was the opposite! I've
actually had different problems before when the browser's Accept-Encoding
was sent to a web service invoked by CXF which didn't understand said
encoding itself. In summary, it's usually the headers!


On 22 June 2014 09:52, Claus Ibsen <cl...@gmail.com> wrote:

> Hi
>
> See the section _Calling using GET or POST_ at
> http://camel.apache.org/http
>
> On Sun, Jun 22, 2014 at 6:11 AM, madhu_online1 <Na...@aoins.com>
> wrote:
> > I was missing this:-
> > .setHeader(Exchange.HTTP_METHOD, constant("GET"))
> >
> >
> >
> > works now..surprising it wouldn't use a GET by default.
> >
> >
> >
> >
> >
> >
> > --
> > View this message in context:
> http://camel.465427.n5.nabble.com/Getting-Bad-Request-response-invoking-REST-web-service-tp5752659p5752661.html
> > Sent from the Camel - Users mailing list archive at Nabble.com.
>
>
>
> --
> Claus Ibsen
> -----------------
> Red Hat, Inc.
> Email: cibsen@redhat.com
> Twitter: davsclaus
> Blog: http://davsclaus.com
> Author of Camel in Action: http://www.manning.com/ibsen
> hawtio: http://hawt.io/
> fabric8: http://fabric8.io/
>



-- 
Matt Sicker <bo...@gmail.com>

Re: Getting Bad Request response invoking REST web service

Posted by Claus Ibsen <cl...@gmail.com>.
Hi

See the section _Calling using GET or POST_ at
http://camel.apache.org/http

On Sun, Jun 22, 2014 at 6:11 AM, madhu_online1 <Na...@aoins.com> wrote:
> I was missing this:-
> .setHeader(Exchange.HTTP_METHOD, constant("GET"))
>
>
>
> works now..surprising it wouldn't use a GET by default.
>
>
>
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Getting-Bad-Request-response-invoking-REST-web-service-tp5752659p5752661.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
Email: cibsen@redhat.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen
hawtio: http://hawt.io/
fabric8: http://fabric8.io/

Re: Getting Bad Request response invoking REST web service

Posted by madhu_online1 <Na...@aoins.com>.
I was missing this:-
.setHeader(Exchange.HTTP_METHOD, constant("GET"))



works now..surprising it wouldn't use a GET by default.






--
View this message in context: http://camel.465427.n5.nabble.com/Getting-Bad-Request-response-invoking-REST-web-service-tp5752659p5752661.html
Sent from the Camel - Users mailing list archive at Nabble.com.