Regular Expression matching any

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Regular Expression matching any

John Ament
I've run into an issue, and I'm not sure what I missed.  I created a JAX-RS service that i want to match anything that matches page/(.+)

So I added this to my class level:

@Path("page/(.+)")
@RequestScoped //CDI enabled

and method level:

@GET
@Produces("application/json")
public JSONObject getPage() throws JSONException {

When it deploys, jersey finds no matches.  No indication that the service was invoked.

Thanks!

John
Reply | Threaded
Open this post in threaded view
|

Re: Regular Expression matching any

Paul Sandoz
Administrator
Hi John,

Regular expressions are supported when declaring path parameters. So  
you will need to do something like this:

   @Path("page/{page: .+}") // JAX-RS reuses a subset of the URI  
template syntax.
   public class MyResource {
      @PathParam("page") String page;
   }

See:

   https://jsr311.dev.java.net/nonav/releases/1.1/javax/ws/rs/ 
Path.html#value%28%29

You can enable tracing and logging  in Jersey and you should see what  
the generated regular expressions are in trace headers of the response:

     <init-param>
         <param-name>com.sun.jersey.config.feature.Trace</param-name>
         <param-value>true</param-value>
     </init-param>
     <init-param>
         <param-
name>com.sun.jersey.spi.container.ContainerRequestFilters</param-name>
         <param-
value>com.sun.jersey.api.container.filter.LoggingFilter</param-value>
     </init-param>
     <init-param>
         <param-
name>com.sun.jersey.spi.container.ContainerResponseFilters</param-name>
         <param-
value>com.sun.jersey.api.container.filter.LoggingFilter</param-value>
     </init-param>

Paul.

On Jun 16, 2010, at 2:46 PM, John Ament wrote:

> I've run into an issue, and I'm not sure what I missed.  I created a  
> JAX-RS service that i want to match anything that matches page/(.+)
>
> So I added this to my class level:
>
> @Path("page/(.+)")
> @RequestScoped //CDI enabled
>
> and method level:
>
> @GET
> @Produces("application/json")
> public JSONObject getPage() throws JSONException {
>
> When it deploys, jersey finds no matches.  No indication that the  
> service was invoked.
>
> Thanks!
>
> John


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Regular Expression matching any

John Ament
Yep, I realized that right after I sent the email.  Silly me.  Thanks though!

John

On Wed, Jun 16, 2010 at 10:36 AM, Paul Sandoz <[hidden email]> wrote:
Hi John,

Regular expressions are supported when declaring path parameters. So you will need to do something like this:

 @Path("page/{page: .+}") // JAX-RS reuses a subset of the URI template syntax.
 public class MyResource {
    @PathParam("page") String page;
 }

See:

 https://jsr311.dev.java.net/nonav/releases/1.1/javax/ws/rs/Path.html#value%28%29

You can enable tracing and logging  in Jersey and you should see what the generated regular expressions are in trace headers of the response:

   <init-param>
       <param-name>com.sun.jersey.config.feature.Trace</param-name>
       <param-value>true</param-value>
   </init-param>
   <init-param>
       <param-name>com.sun.jersey.spi.container.ContainerRequestFilters</param-name>
       <param-value>com.sun.jersey.api.container.filter.LoggingFilter</param-value>
   </init-param>
   <init-param>
       <param-name>com.sun.jersey.spi.container.ContainerResponseFilters</param-name>
       <param-value>com.sun.jersey.api.container.filter.LoggingFilter</param-value>
   </init-param>

Paul.


On Jun 16, 2010, at 2:46 PM, John Ament wrote:

I've run into an issue, and I'm not sure what I missed.  I created a JAX-RS service that i want to match anything that matches page/(.+)

So I added this to my class level:

@Path("page/(.+)")
@RequestScoped //CDI enabled

and method level:

@GET
@Produces("application/json")
public JSONObject getPage() throws JSONException {

When it deploys, jersey finds no matches.  No indication that the service was invoked.

Thanks!

John


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]


Reply | Threaded
Open this post in threaded view
|

Re: Regular Expression matching any

Ayesha
In reply to this post by Paul Sandoz
Hello Paul,

I have a problem with the leading question mark that is added is http request. my url pattern is going to be like this:
http://localhost:8080/subscription/121231/?param1=value1¶m2=value2

my resource path is:
@Path("/subscription/")

my path is set as:

 @GET
 @Path("{id}/{sub}")
 @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
 @Consumes({MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN})
   
Can you pls tell me how can I handle the leading question mark in the url? as of now I have to send the request without question mark:
http://localhost:8080/subscription/121231/?param1=value1¶m2=value2

how can I support the one that I want? that is the following:
http://localhost:8080/subscription/121231/?param1=value1¶m2=value2

Thanks you.
Ayesha
Reply | Threaded
Open this post in threaded view
|

Re: Regular Expression matching any

Marek Potociar
In reply to this post by Paul Sandoz
Hello Ayesha,

it seems you are using query params in the place where you expect {sub}. Try updating your method path to @Path("{id}).
Then your URL with query parameters would look like:

http://localhost:8080/subscription/121231?param1=value1&param2=value2

HTH,
Marek

On 08/05/2011 08:19 PM, Ayesha wrote:

> Hello Paul,
>
> I have a problem with the leading question mark that is added is http
> request. my url pattern is going to be like this:
> http://localhost:8080/subscription/121231/?param1=value1&param2=value2
>
> my resource path is:
> @Path("/subscription/")
>
> my path is set as:
>
>  @GET
>  @Path("{id}/{sub}")
>  @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
>  @Consumes({MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN})
>    
> Can you pls tell me how can I handle the leading question mark in the url?
> as of now I have to send the request without question mark:
> http://localhost:8080/subscription/121231/?param1=value1&param2=value2
>
> how can I support the one that I want? that is the following:
> http://localhost:8080/subscription/121231/?param1=value1&param2=value2
>
> Thanks you.
> Ayesha
>
> --
> View this message in context: http://jersey.576304.n2.nabble.com/Regular-Expression-matching-any-tp5186256p6657525.html
> Sent from the Jersey mailing list archive at Nabble.com.
Reply | Threaded
Open this post in threaded view
|

Re: Regular Expression matching any

Ayesha
Hello Marek!
Thanks a lot. that solved my problem!!

Regards,
Ayesha