Skip to content

Commit

Permalink
Simple response to feature request osgi#68, enable primary rest endpo…
Browse files Browse the repository at this point in the history
…int.

If a method is named for the verb with no path given, provide from the
root of the endpoint.

Signed-off-by: Elias N Vasylenko <[email protected]>
  • Loading branch information
Sophos-Elias-Vasylenko committed Mar 24, 2017
1 parent 673b5e2 commit b22569a
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ static String decode(String path, boolean toLower) {
//
// Skip last _ so we can escape keywords
//
if (sb.charAt(sb.length() - 1) == '-')
if (sb.length() > 0 && sb.charAt(sb.length() - 1) == '-')
sb.setLength(sb.length() - 1);
return sb.toString();
}
Expand Down Expand Up @@ -229,10 +229,8 @@ public boolean execute(HttpServletRequest rq, HttpServletResponse rsp)
try {
String path = rq.getPathInfo();
if (path == null)
throw new IllegalArgumentException(
"The rest servlet requires that the name of the resource follows the servlet path ('rest'), like /rest/aQute.service.library.Program[/...]*[?...]");

if (path.startsWith("/"))
path = "";
else if (path.startsWith("/"))
path = path.substring(1);

if (path.equals("openapi.json")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,6 @@ void setCloseable(Closeable c) {
}

public void service(HttpServletRequest rq, HttpServletResponse rsp) throws IOException, ServletException {
String pathInfo = rq.getPathInfo();
if (pathInfo == null) {
rsp.getWriter().println(
"The rest servlet requires that the name of the resource follows the servlet path ('rest'), like /rest/aQute.service.library.Program[/...]*[?...]");
rsp.setStatus(HttpServletResponse.SC_BAD_REQUEST);
return;
}

if (corsEnabled) {
addCorsHeaders(rsp);
}
Expand Down

0 comments on commit b22569a

Please sign in to comment.