Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
Merge pull request #85 from eliasvasylenko/68-fix
Browse files Browse the repository at this point in the history
Simple response to feature request #68, enable primary rest endpoint.
  • Loading branch information
pkriens authored Mar 24, 2017
2 parents 673b5e2 + 0218e57 commit 9948c4f
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@ public Object convert(Type dest, Object o) throws Exception {
hasPayloadAsParameter = false;
}

if (path.equals("/") && cardinality > 0)
throw new IllegalArgumentException("Invalid " + verb
+ " method " + method.getName() + ". A method on the root path cannot have a non-zero cardinality.");

this.post = requestBody;

this.cardinality = cardinality;
Expand Down
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 9948c4f

Please sign in to comment.