Return-Path: Delivered-To: apmail-cxf-users-archive@www.apache.org Received: (qmail 38565 invoked from network); 15 Oct 2009 09:13:41 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 15 Oct 2009 09:13:41 -0000 Received: (qmail 61109 invoked by uid 500); 15 Oct 2009 09:13:40 -0000 Delivered-To: apmail-cxf-users-archive@cxf.apache.org Received: (qmail 61023 invoked by uid 500); 15 Oct 2009 09:13:39 -0000 Mailing-List: contact users-help@cxf.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: users@cxf.apache.org Delivered-To: mailing list users@cxf.apache.org Received: (qmail 61013 invoked by uid 99); 15 Oct 2009 09:13:39 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 15 Oct 2009 09:13:39 +0000 X-ASF-Spam-Status: No, hits=-0.0 required=10.0 tests=SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: local policy) Received: from [193.52.21.73] (HELO puma.emsc-csem.org) (193.52.21.73) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 15 Oct 2009 09:13:29 +0000 Received: from iguane (iguane.emsc-csem.org [193.52.21.90]) by puma.emsc-csem.org (8.13.8+Sun/8.12.10) with ESMTP id n9F9D52k005068 for ; Thu, 15 Oct 2009 09:13:08 GMT From: "Linus Kamb" To: References: <25828961.post@talk.nabble.com> <25847003.post@talk.nabble.com> <25866419.post@talk.nabble.com> Subject: RE: Is it possible to register a default resource? Date: Thu, 15 Oct 2009 11:13:05 +0200 Message-ID: <424C5EE5C4924E57ACBA109D5F6A0B48@emsccsem.org> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable X-Mailer: Microsoft Office Outlook 11 In-Reply-To: <25866419.post@talk.nabble.com> Thread-Index: AcpLsCPGs3qCKqpWR4uJ9gGLxxJ2MABxRtSg X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.5579 X-Virus-Checked: Checked by ClamAV on apache.org This is great. I can have interface ServiceInterface { =20 @GET @Path("{path:.+}") Response defaultMethod(); @GET @Path("/a/correct/path") Response serviceMethod(); } And, it seems, everything but /a/correct/path will get shunted to defaultMethod(); It can be further controlled by @Produces, and you can add required PathParams. I don't know if this was the original poster's question, and I'm sure = I'm missing some detail or corner case, and maybe there is a "standard" way = to do this, but I find this incredibly useful. Thanks, Linus -----Message d'origine----- De=A0: devon.boyle [mailto:devon.boyle@rovicorp.com]=20 Envoy=E9=A0: Tuesday, October 13, 2009 4:51 AM =C0=A0: users@cxf.apache.org Objet=A0: Re: Is it possible to register a default resource? Hi Sergy, Thank you very much for your response. I did, eventually find a trick that worked. I changed my "default" = service to: interface ADefaultResource { @GET @Path("{path:.+}/{tail}") Response aKnownMethod(); } It turns out that my "subresource" problem goes away as long as the last matching chunk on the URI template is *not* a regex pattern. And the = above pattern ends up matching anything that is not otherwise matched to = another existing service. Obviously in this case, I am not actually using the = path variables in the service itself -- they are just a means to an end to = get the CXF dispatch service to find this method when appropriate. Perhaps it is not by design, but it turns out that the system does what = i had hoped: it matches the more specific services (even with variables) = when appropriate, and only falling back to the default method when no other resource can handle it. ------ Regarding the subresource error message: it is, in fact, a pipe = character, and not a slash. When I step into the code to see what is happening, I = can see that the path to be matched to a subresource is "|". This appears to only happen when the last element of the URI Template is a regex pattern that consumes the end of the URI prior to locating the subresource. Note that @GET/@POST don't seem to work when the patterns ends in regex -- = that is to say, using the @GET or @POST annotation does not stop the CXF = dispatch system from still trying to find a subresource matching "|". =20 I'm sure this is just an artifact of some bug related to the handling of = URI Templates which terminate in a regex variable. ------ Thank you very much for your time. Our team has been using CXF for = several months now, and we are very impressed! Please let me know if I can answer any more questions about the = behaviors I am describing. Thank you, -Devon Sergey Beryozkin wrote: >=20 > Hi >=20 > No problems at all and thanks for asking this question. > The problem is that both resources match requests starting from > /a/known/path/with or indeed with > /a/, etc. It is not possible in JAXRS to try to find an operation on = one > matching resource and then try to do the same for another matching > resource, etc; though a JIRA has been opened in CXF to extend the > selection algorithm. >=20 > So try restricting the URI space that a default resource can handle, = ex, > assuming that possible URIs are either >=20 > /a/known/path/with/{parameters} >=20 > or /a/known/path/with >=20 > then =20 >=20 > @path("/a/known/path/with/") > interface AKnownResource { > @path("{variables}") > Response aKnownMethod(); > } >=20 > @path("/a/known/path/with") > interface ADefaultResource { > @GET > Response defaultResource(); > } >=20 > should do it. >=20 > By the way, can you please give a bit more info about this message : >=20 > "No operation matching request path l is found on subresource" >=20 > is it '|' which is actually reported in this case ? or '/' ? >=20 > thanks, Sergey >=20 >=20 > devon.boyle wrote: >>=20 >> Hi. >>=20 >> I'm wondering if its possible to setup a default resource/service = class >> to handle requests that don't otherwise match existing resources in = the >> server?=20 >>=20 >> I'm new to CXF and JAX-RS, so I apologize if this is a painfully = obvious >> question. But somehow, I couldn't find any answers to it in the >> documentation or on the forums. Perhaps I don't know the right key = words >> yet... At any rate, I'd really appreciate any help anyone could = offer. >>=20 >> Here is a very simple example to explain what I'm trying to do: >>=20 >> interface AKnownResource { >> @path("/a/known/path/with/{variables}") >> Response aKnownMethod(); >> } >>=20 >> interface ADefaultResource { >> // Not sure what to put for @path() >> Response defaultResource(); >> } >>=20 >> With the idea that request for >> "http://mydomain/a/known/path/with/variables" would invoke >> aKnownMethod(), while any other URL would invoke defaultResource(). >>=20 >> I've tried using the regex variable syntax to register the default >> service, such as: >>=20 >> @Path("{path:(.)+}") >>=20 >> This successfully invokes the defaultResource() method, but then the >> server fails to find a subresource to complete the processing of the >> response.: >>=20 >> "No operation matching request path l is found on subresource" >>=20 >> I'm sure I am going about this all wrong. Would anyone mind pointing = me >> in the right direction? >>=20 >> Thank you, >> -Devon >>=20 >=20 >=20 --=20 View this message in context: http://www.nabble.com/Is-it-possible-to-register-a-default-resource--tp25= 828 961p25866419.html Sent from the cxf-user mailing list archive at Nabble.com.