|
From: Porter W. <por...@gm...> - 2008-11-12 15:19:34
|
I came across what I think is a small bug with parameter parsing with
RESTeasy while getting my feet wet.
Here's the code:
package rest;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
@Path("/hello")
public class Hello {
@GET
@Produces("text/plain")
public String sayHelloPlain() {
return new String("Hello there.");
}
@GET
@Produces("text/html")
public String querySayHelloHTML(@QueryParam("name") String name) {
if (name == null || name.trim().length() == 0) return
sayHelloHTML();
return new
String("<html><head><title>Hello</title></head><body><p>Hello " + name +
".</p></body></html>");
}
@GET
@Path("/name/{name}")
@Produces("text/html")
public String pathSayHelloHTML(@PathParam("name") String name) {
if (name == null || name.trim().length() == 0) return
sayHelloHTML();
return new
String("<html><head><title>Hello</title></head><body><p>Hello " + name +
".</p></body></html>");
}
public String sayHelloHTML() {
return new
String("<html><head><title>Hello</title></head><body><p>Hello
there.</p></body></html>");
}
}
Pretty basic stuff - mounts on the /hello branch of URLs for the web-app.
Requesting:
http://localhost:8080/RestZen/rest/hello
produces the expected:
Hello there.
Requesting:
http://localhost:8080/RestZen/rest/hello?name=Porter
Produces:
Hello Porter.
Requesting:
http://localhost:8080/RestZen/rest/hello?name=+
Produces:
Hello there.
Requesting:
http://localhost:8080/RestZen/rest/hello/name/
Returns a 405 method not allowed. Which I'm guessing is correct since no
parameter was supplied... Although that does seem strange - as it's a
GET... Maybe a different response code might be more appropriate. The log
states: "INFO org.jboss.resteasy.core.SynchronousDispatcher - No resource
method found for GET, return 405 with Allow header".
Requesting:
http://localhost:8080/RestZen/rest/hello/name/+
Produces:
java.lang.StringIndexOutOfBoundsException: String index out of range: -1
java.lang.String.substring(String.java:1938)
org.jboss.resteasy.specimpl.UriInfoImpl.<init>(UriInfoImpl.java:95)
org.jboss.resteasy.plugins.server.servlet.ServletUtil.extractUriInfo(ServletUtil.java:62)
org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:72)
org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:66)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
Whereas requesting:
http://localhost:8080/RestZen/rest/hello/name/%20
Produces:
Hello there.
I'm thinking the stack trace on the + encoding for spaces in URLs might be
problematic.
The full strack trace from the log:
SEVERE: Servlet.service() for servlet Resteasy threw exception
java.lang.StringIndexOutOfBoundsException: String index out of range: -1
at java.lang.String.substring(String.java:1938)
at org.jboss.resteasy.specimpl.UriInfoImpl.<init>(UriInfoImpl.java:95)
at
org.jboss.resteasy.plugins.server.servlet.ServletUtil.extractUriInfo(ServletUtil.java:62)
at
org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:72)
at
org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:66)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:263)
at
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:584)
at
org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Thread.java:619)
Other than that - I am liking the implementation of RESTeasy for JAX-RS.
Found it easier to get going with than the Jersey implementation (didn't
really like the obfuscation with Glassfish, Grizzly, etc). While Restlet is
cool - I don't really want all the other stuff they're bringing to the
table. I just want the annotations.
- Porter
|