{"id":140,"date":"2010-10-20T21:17:05","date_gmt":"2010-10-21T04:17:05","guid":{"rendered":"http:\/\/www.corneliadavis.com\/blog\/?p=140"},"modified":"2010-10-20T21:17:05","modified_gmt":"2010-10-21T04:17:05","slug":"jax-rs-regular-expressions-in-path-annotations","status":"publish","type":"post","link":"https:\/\/corneliadavis.com\/blog\/2010\/10\/20\/jax-rs-regular-expressions-in-path-annotations\/","title":{"rendered":"Jax-RS : Regular Expressions in @Path Annotations"},"content":{"rendered":"<p>Sometimes I really wish I did something else for a living.  Okay, perhaps a bit over-dramatic but I&#8217;m feeling a bit tired this evening and wasting even 20 minutes on something totally useless (which, let&#8217;s face it, isn&#8217;t unusual in computing) has me ready to call it a night.  But since googling the error codes I was getting netted nothing (other than <a href=\"http:\/\/www.mail-archive.com\/users@cxf.apache.org\/msg04882.html\">this 2 year old thread<\/a>), perhaps I can be of service to the next person bitten by this.<\/p>\n<p>I&#8217;m writing a RESTful web service, using Jax-RS with a CXF runtime (v 2.2.10).  I&#8217;m defining a resource with a URI something like \/foo\/bar\/&#8230; &#8211; that is, the first part of my uri will have the literals &#8220;foo&#8221; and &#8220;bar&#8221; and then I want everything else on the URI to go into a parameter.  So I want \/foo\/bar\/a, \/foo\/bar\/a\/b and \/foo\/bar\/ab\/c to all resolve to the same resource\/method with a path parameter bound to &#8220;a&#8221;, &#8220;a\/b&#8221; and &#8220;a\/b\/c&#8221;, respectively.  So I create the follwoing @Path annotation:<\/p>\n<pre><code>@Path(\"foo\/bar\/{therest : .*}\")<\/code><\/pre>\n<p>My initial source for this tidbit was the Safari Books Online copy of <a href=\"http:\/\/my.safaribooksonline.com\/9780596809300\">Restful Java with Jax-RS<\/a>, page 47 which showed an example just like this.<\/p>\n<p>When I tried to launch my web service, however, I got an error that indicated something was wrong with the regular expression.<\/p>\n<pre><code>org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'Prototype': Error setting property values;\nnested exception is org.springframework.beans.PropertyBatchUpdateException; \nnested PropertyAccessExceptions (1) are:PropertyAccessException 1: org.springframework.beans.MethodInvocationException: Property 'serviceBeans' threw exception;\nnested exception is java.util.regex.PatternSyntaxException: Illegal repetition near index 27\/foo\/bar\/{therest : .*}(\/.*)?...<\/code><\/pre>\n<p>The answer was really simple, <em>get rid of the spaces around the &#8216;:&#8217;<\/em>.  Argh!  Since when do languages care that much about whitespace?!  And Argh again! How can a published book have this error?!  Or perhaps the bug is in CXF?  I&#8217;ll look into that when I have a chance.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Sometimes I really wish I did something else for a living. Okay, perhaps a bit over-dramatic but I&#8217;m feeling a bit tired this evening and wasting even 20 minutes on something totally useless (which, let&#8217;s face it, isn&#8217;t unusual in computing) has me ready to call it a night. But since googling the error codes [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"nf_dc_page":"","_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[4,8],"tags":[59,79,80],"class_list":["post-140","post","type-post","status-publish","format-standard","hentry","category-bug","category-cxf","tag-cxf","tag-regex","tag-rest"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/corneliadavis.com\/blog\/wp-json\/wp\/v2\/posts\/140","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/corneliadavis.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/corneliadavis.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/corneliadavis.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/corneliadavis.com\/blog\/wp-json\/wp\/v2\/comments?post=140"}],"version-history":[{"count":0,"href":"https:\/\/corneliadavis.com\/blog\/wp-json\/wp\/v2\/posts\/140\/revisions"}],"wp:attachment":[{"href":"https:\/\/corneliadavis.com\/blog\/wp-json\/wp\/v2\/media?parent=140"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/corneliadavis.com\/blog\/wp-json\/wp\/v2\/categories?post=140"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/corneliadavis.com\/blog\/wp-json\/wp\/v2\/tags?post=140"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}