You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Ted <na...@pritchard.uk.net> on 2015/04/23 10:18:14 UTC

HTTP OPTIONS

Hi,

I have a simple REST DSL route that has both a GET and a PUT for a
particular resource:

        rest("/orders")
	    	.get("/{orderId}").outType(Order.class)
	    		.to("direct:getOrder")
        	.put("/{orderId}").type(Order.class)
        		.to("direct:updateOrder");


This application is run on a different port to the consuming application so
I have enabled CORS via a servlet filter (I also tried the enable CORS
option on the configuration of REST DSL).  The consuming application is
sending a pre-flight HTTP OPTIONS request.  I can see in the class
ServletRestServletResolveConsumerStrategy that the method
matchRestMethod(method, restrict) has special provision for the OPTIONS
method.  The problem for me seems to be that if the consuming application
sends a method similar to:

/orders/1 OPTIONS 

Then the ServletRestServletResolveConsumerStrategy class is not able to find
a unique match because both the GET and the PUT methods are matched and the
consumer sees a 404.

Is there something I'm missing?

Ted



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

Re: HTTP OPTIONS

Posted by Ted <na...@pritchard.uk.net>.
I should have mentioned that I am using the Servlet component and Camel
2.15.1.

As a quick hack I added the following code to the end of the method
ServletRestServletResolveConsumerStrategy.resolve(HttpServletRequest
request, Map<String, HttpConsumer> consumers) 

        
        if (answer == null && method.equals("OPTIONS") && candidates.size()
> 0) {
            // If method was OPTIONS then just return first consumer
            answer = candidates.get(0);
        }

Added just before the final return answer;



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

Re: HTTP OPTIONS

Posted by Henryk Konsek <he...@gmail.com>.
Hi,

I've fixed some OPTIONS/CORS related issues in Netty HTTP component. After
these [1] two [2] changes (scheduled for 2.16 and 2.15.2) you can finally
call Netty HTTP based REST DSL routes from AngularJS without running into
the OPTIONS problems.

If you wait for Camel 2.15.2 and use Netty HTTP as a REST provider, you can
enjoy your favorite JS framework calling your REST API without any issues.

Cheers.

[1] https://issues.apache.org/jira/browse/CAMEL-8685
[2] https://issues.apache.org/jira/browse/CAMEL-8645

czw., 23.04.2015 o 10:57 użytkownik Claus Ibsen <cl...@gmail.com>
napisał:

> Hi
>
> What http component do you use? servlet / jetty / or something else?
> And what version of Camel.
>
> There is a few tickets about rest-dsl and CORS issues still to get
> fixed / improved.
>
> On Thu, Apr 23, 2015 at 10:18 AM, Ted <na...@pritchard.uk.net> wrote:
> > Hi,
> >
> > I have a simple REST DSL route that has both a GET and a PUT for a
> > particular resource:
> >
> >         rest("/orders")
> >                 .get("/{orderId}").outType(Order.class)
> >                         .to("direct:getOrder")
> >                 .put("/{orderId}").type(Order.class)
> >                         .to("direct:updateOrder");
> >
> >
> > This application is run on a different port to the consuming application
> so
> > I have enabled CORS via a servlet filter (I also tried the enable CORS
> > option on the configuration of REST DSL).  The consuming application is
> > sending a pre-flight HTTP OPTIONS request.  I can see in the class
> > ServletRestServletResolveConsumerStrategy that the method
> > matchRestMethod(method, restrict) has special provision for the OPTIONS
> > method.  The problem for me seems to be that if the consuming application
> > sends a method similar to:
> >
> > /orders/1 OPTIONS
> >
> > Then the ServletRestServletResolveConsumerStrategy class is not able to
> find
> > a unique match because both the GET and the PUT methods are matched and
> the
> > consumer sees a 404.
> >
> > Is there something I'm missing?
> >
> > Ted
> >
> >
> >
> > --
> > View this message in context:
> http://camel.465427.n5.nabble.com/HTTP-OPTIONS-tp5766194.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://hawt.io/fabric8>: http://fabric8.io/
>

Re: HTTP OPTIONS

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

What http component do you use? servlet / jetty / or something else?
And what version of Camel.

There is a few tickets about rest-dsl and CORS issues still to get
fixed / improved.

On Thu, Apr 23, 2015 at 10:18 AM, Ted <na...@pritchard.uk.net> wrote:
> Hi,
>
> I have a simple REST DSL route that has both a GET and a PUT for a
> particular resource:
>
>         rest("/orders")
>                 .get("/{orderId}").outType(Order.class)
>                         .to("direct:getOrder")
>                 .put("/{orderId}").type(Order.class)
>                         .to("direct:updateOrder");
>
>
> This application is run on a different port to the consuming application so
> I have enabled CORS via a servlet filter (I also tried the enable CORS
> option on the configuration of REST DSL).  The consuming application is
> sending a pre-flight HTTP OPTIONS request.  I can see in the class
> ServletRestServletResolveConsumerStrategy that the method
> matchRestMethod(method, restrict) has special provision for the OPTIONS
> method.  The problem for me seems to be that if the consuming application
> sends a method similar to:
>
> /orders/1 OPTIONS
>
> Then the ServletRestServletResolveConsumerStrategy class is not able to find
> a unique match because both the GET and the PUT methods are matched and the
> consumer sees a 404.
>
> Is there something I'm missing?
>
> Ted
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/HTTP-OPTIONS-tp5766194.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/