Commit 57c727a8 by Tuomas Riihimäki

More logging for rest errors

1 parent 72df7970
......@@ -66,6 +66,10 @@ public class HostnameFilter implements Filter {
// Nothing...
}
private enum AuthType {
UNKNOWN, ANON, REST, USER
}
/**
* @see Filter#doFilter(ServletRequest, ServletResponse, FilterChain)
*/
......@@ -74,7 +78,7 @@ public class HostnameFilter implements Filter {
FilterChain chain) throws IOException, ServletException {
// logger.info("HostnameFilter called!");
HttpServletRequest httpRequest = null;
AuthType authtype = AuthType.UNKNOWN;
if (request != null && request instanceof HttpServletRequest) {
httpRequest = ((HttpServletRequest) request);
parseHostname(httpRequest);
......@@ -82,6 +86,7 @@ public class HostnameFilter implements Filter {
if (httpRequest.getUserPrincipal() == null) {
// Check if we are logging in with rest
if (RestApplicationEntrypoint.REST_PATH.equals(httpRequest.getServletPath())) {
authtype = AuthType.REST;
if (!restAuth(httpRequest, response)) {
response.getWriter().write("REST authentication failed!");
if (response instanceof HttpServletResponse) {
......@@ -92,6 +97,7 @@ public class HostnameFilter implements Filter {
}
} else {
try {
authtype = AuthType.ANON;
httpRequest.login(User.ANONYMOUS_LOGINNAME, null);
} catch (Throwable t) {
logger.warn("Error logging in as anonymous... ignoring.. ", t);
......@@ -100,6 +106,7 @@ public class HostnameFilter implements Filter {
}
else if (!httpRequest.getUserPrincipal().getName().equals(User.ANONYMOUS_LOGINNAME))
{
authtype = AuthType.USER;
sessionmgmt.updateSessionUser(httpRequest.getSession().getId(), httpRequest.getUserPrincipal().getName());
}
......@@ -107,6 +114,12 @@ public class HostnameFilter implements Filter {
// pass the request along the filter chain
try {
chain.doFilter(request, response);
} catch (Throwable t) {
if (AuthType.REST == authtype) {
logger.warn("Caught Exception for REST query. url {}, method: {}, content type {}, and length {}", httpRequest.getRequestURL(), httpRequest.getMethod(), httpRequest.getContentType(), httpRequest.getContentLength());
logger.warn("Caught exception at rest:", t);
}
throw t;
} finally {
BortalLocalContextHolder.cleanupThread();
}
......
......@@ -14,6 +14,8 @@ import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.ResponseBuilder;
import javax.ws.rs.core.Response.Status;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -92,6 +94,15 @@ public class MapAdminView {
return Response.ok().build();
}
@GET
@Path("/place/")
public Response getPlaceError() {
ResponseBuilder ret = Response.ok();
ret = ret.status(Status.METHOD_NOT_ALLOWED);
ret.entity("Method not allowed!\nGET is not supported for /place/. See api for correct use!");
return ret.build();
}
@POST
@Path("/place/")
public Response createPlace(PlaceInputPojo create) {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!