Projects tigase _server tigase-http-api Issues #170
Add support for wildcard/regexp in our `@Path` implementation (#170)
Wojciech Kapcia (Tigase) opened 6 days ago

Right now trying to use regexp in @Path annotation (e.g. @Path("/check{ restOfUrl: .* }")) is not supported and yields Exception [1].

Path specification (https://jakarta.ee/specifications/restful-ws/3.0/apidocs/jakarta/ws/rs/path) allows it:

String value Defines a URI template for the resource class or method, must not include matrix parameters.

Embedded template parameters are allowed and are of the form:

 param = "{" *WSP name *WSP [ ":" *WSP regex *WSP ] "}"
 name = (ALPHA / DIGIT / "_")*(ALPHA / DIGIT / "." / "_" / "-" ) ; \w[\w\.-]*
 regex = *( nonbrace / "{" *nonbrace "}" ) ; where nonbrace is any char other than "{" and "}"

See RFC 5234 for a description of the syntax used above and the expansions of WSP, ALPHA and DIGIT. In the above name is the template parameter name and the optional regex specifies the contents of the capturing group for the parameter. If regex is not supplied then a default value of [^/]+ which terminates at a path segment boundary, is used. Matching of request URIs to URI templates is performed against encoded path values and implementations will not escape literal characters in regex automatically, therefore any literals in regex should be escaped by the author according to the rules of RFC 3986 section 3.3. Caution is recommended in the use of regex, incorrect use can lead to a template parameter matching unexpected URI paths. See Pattern for further information on the syntax of regular expressions. Values of template parameters may be extracted using PathParam.

The literal part of the supplied value (those characters that are not part of a template parameter) is automatically percent encoded to conform to the path production of RFC 3986 section 3.3. Note that percent encoded values are allowed in the literal part of the value, an implementation will recognize such values and will not double encode the '%' character.


[1] Exception:

HTTP ERROR 500 javax.servlet.ServletException: /*==tigase.http.modules.rest.RestServlet@5db{jsp=null,order=-1,inst=true,async=true,src=EMBEDDED:null,STARTED}
URI:	/rest/update/check
STATUS:	500
MESSAGE:	javax.servlet.ServletException: /*==tigase.http.modules.rest.RestServlet@5db{jsp=null,order=-1,inst=true,async=true,src=EMBEDDED:null,STARTED}
SERVLET:	/*
CAUSED BY:	javax.servlet.ServletException: /*==tigase.http.modules.rest.RestServlet@5db{jsp=null,order=-1,inst=true,async=true,src=EMBEDDED:null,STARTED}
CAUSED BY:	java.lang.NullPointerException
Caused by:

javax.servlet.ServletException: /*==tigase.http.modules.rest.RestServlet@5db{jsp=null,order=-1,inst=true,async=true,src=EMBEDDED:null,STARTED}
	at org.eclipse.jetty.servlet.ServletHolder.initServlet(ServletHolder.java:650)
	at org.eclipse.jetty.servlet.ServletHolder.getServlet(ServletHolder.java:486)
	at org.eclipse.jetty.servlet.ServletHolder.prepare(ServletHolder.java:759)
	at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:549)
	at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:143)
	at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:571)
	at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:127)
	at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:235)
	at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1440)
	at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:188)
	at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:505)
	at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:186)
	at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1355)
	at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
	at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:234)
	at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:127)
	at org.eclipse.jetty.server.Server.handle(Server.java:516)
	at org.eclipse.jetty.server.HttpChannel.lambda$handle$1(HttpChannel.java:487)
	at org.eclipse.jetty.server.HttpChannel.dispatch(HttpChannel.java:732)
	at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:479)
	at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:277)
	at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:311)
	at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:105)
	at org.eclipse.jetty.io.ChannelEndPoint$1.run(ChannelEndPoint.java:104)
	at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:883)
	at org.eclipse.jetty.util.thread.QueuedThreadPool$Runner.run(QueuedThreadPool.java:1034)
	at java.base/java.lang.Thread.run(Thread.java:1583)
Caused by: java.lang.NullPointerException
	at java.base/java.lang.Class.isAssignableFrom(Native Method)
	at tigase.http.jaxrs.JaxRsRequestHandler.regexForClass(JaxRsRequestHandler.java:300)
	at tigase.http.jaxrs.JaxRsRequestHandler.prepareMatcher(JaxRsRequestHandler.java:264)
	at tigase.http.jaxrs.JaxRsRequestHandler.create(JaxRsRequestHandler.java:146)
	at tigase.http.jaxrs.JaxRsRequestHandler.create(JaxRsRequestHandler.java:117)
	at tigase.http.jaxrs.JaxRsServlet.init(JaxRsServlet.java:96)
	at tigase.http.modules.rest.RestServlet.init(RestServlet.java:47)
	at javax.servlet.GenericServlet.init(GenericServlet.java:244)
	at org.eclipse.jetty.servlet.ServletHolder.initServlet(ServletHolder.java:632)
	... 26 more

Powered by Jetty:// 9.4.57.v20241219 
  • Wojciech Kapcia (Tigase) added "Related" tigase-private/tigase-update-checker-handler#19 6 days ago
  • Wojciech Kapcia (Tigase) changed state to 'In Progress' 6 days ago
    Previous Value Current Value
    Open
    In Progress
  • Wojciech Kapcia (Tigase) commented 5 hours ago

    Added unit-tests with relevant cases Reworked tigase.http.jaxrs.JaxRsRequestHandler#prepareMatcher to properly handle parameters with regexps in @Path.

  • Wojciech Kapcia (Tigase) changed state to 'Closed' 5 hours ago
    Previous Value Current Value
    In Progress
    Closed
issue 1 of 1
Type
New Feature
Priority
Normal
Assignee
Version
none
Sprints
n/a
Customer
n/a
Iterations
Issue Votes (0)
Watchers (2)
Reference
tigase/_server/tigase-http-api#170
Please wait...
Page is in error, reload to recover