Changeset 7216
- Timestamp:
- 10/21/18 17:40:59 (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
SRUAggregator/trunk/src/main/java/eu/clarin/sru/fcs/aggregator/app/ErrorHandler.java
r6153 r7216 6 6 import javax.servlet.http.HttpServletRequest; 7 7 import javax.servlet.http.HttpServletResponse; 8 import javax.servlet.http.HttpServletRequestWrapper; 9 //import org.apache.commons.lang3.StringEscapeUtils; 8 10 import org.eclipse.jetty.http.HttpMethod; 9 11 import org.eclipse.jetty.server.Request; … … 12 14 /** 13 15 * @author edima 16 * @author ljo 14 17 * 15 18 * The Aggregator is a single web page application, and most of the URLs are … … 31 34 public static final String PARAM_AGGREGATION_CONTEXT = "x-aggregation-context"; 32 35 33 public static final String redirectRoute = "/ index.html";36 public static final String redirectRoute = "/"; 34 37 35 38 … … 38 41 // On 404 page we need to show index.html and let JS router do the work, otherwise show error page 39 42 if (response.getStatus() == HttpServletResponse.SC_NOT_FOUND) { 40 forward(redirectRoute, baseRequest, re sponse);43 forward(redirectRoute, baseRequest, request, response); 41 44 } else if (request.getMethod().equals("POST") 42 45 && response.getStatus() == HttpServletResponse.SC_METHOD_NOT_ALLOWED) { … … 45 48 String[] queryValues = request.getParameterValues(PARAM_QUERY); 46 49 if (queryValues != null && queryValues.length > 0) { 47 baseRequest.getSession().setAttribute(PARAM_QUERY, queryValues[0]);50 request.getSession().setAttribute(PARAM_QUERY, queryValues[0]); 48 51 } 49 52 } … … 52 55 String[] modeValues = request.getParameterValues(PARAM_MODE); 53 56 if (modeValues != null && modeValues.length > 0) { 54 baseRequest.getSession().setAttribute(PARAM_MODE, modeValues[0]);57 request.getSession().setAttribute(PARAM_MODE, modeValues[0]); 55 58 } 56 59 } … … 59 62 String[] contextValues = request.getParameterValues(PARAM_AGGREGATION_CONTEXT); 60 63 if (contextValues != null && contextValues.length > 0) { 61 baseRequest.getSession().setAttribute(PARAM_AGGREGATION_CONTEXT, contextValues[0]); 64 request.getSession().setAttribute(PARAM_AGGREGATION_CONTEXT, contextValues[0]); 65 request.setAttribute(PARAM_AGGREGATION_CONTEXT, contextValues[0]); 66 request.setAttribute(PARAM_AGGREGATION_CONTEXT, contextValues[0]); 67 log.info("Error handler request.contextValues > 0: " + contextValues[0]); 62 68 } 69 63 70 } 64 71 65 baseRequest.setMethod(HttpMethod.GET, HttpMethod.GET.asString()); 72 HttpServletRequest getRequest = new HttpServletRequestWrapper(request) { 73 @Override 74 public String getMethod(){ 75 return HttpMethod.GET.asString(); 76 } 77 }; 78 79 //baseRequest.setMethod(HttpMethod.GET, HttpMethod.GET.asString()); 66 80 67 forward(redirectRoute, baseRequest, response);81 forward(redirectRoute, baseRequest, getRequest, response); 68 82 } else { 69 83 super.handle(target, baseRequest, request, response); … … 71 85 } 72 86 73 void forward(String target, Request request, HttpServletResponse response) throws IOException { 74 RequestDispatcher dispatcher = request.getRequestDispatcher(target); 87 void forward(final String target, final Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException { 88 StringBuilder params = new StringBuilder(); 89 if (request.getSession().getAttribute(PARAM_AGGREGATION_CONTEXT) != null) { 90 params.append("x-aggregation-context=" + request.getSession().getAttribute(PARAM_AGGREGATION_CONTEXT)); 91 } 92 RequestDispatcher dispatcher = request.getServletContext().getNamedDispatcher("static"); 93 request = new HttpServletRequestWrapper(request) { 94 @Override 95 public String getPathInfo(){ 96 return target; 97 } 98 }; 75 99 if (dispatcher != null) { 100 request.setAttribute(dispatcher.FORWARD_QUERY_STRING, params.toString()); 101 request.getSession().setAttribute(dispatcher.FORWARD_QUERY_STRING, params.toString()); 76 102 try { 103 log.info("dispatching attribute check:" + request.getSession().getAttribute(PARAM_AGGREGATION_CONTEXT) + " " + request.getSession()); 77 104 response.reset(); 78 105 dispatcher.forward(request, response); 79 106 } catch (ServletException e) { 80 super.handle(target, request, request, response); 107 log.info("dispatching failed, attribute check:" + request.getSession().getAttribute(PARAM_AGGREGATION_CONTEXT)); 108 super.handle(target, baseRequest, request, response); 81 109 } 82 110 } else { 83 111 log.error("Can not find internal redirect route '" + target + "' while handling error. Will show system error page"); 84 super.handle(target, request, request, response);112 super.handle(target, baseRequest, request, response); 85 113 } 86 114 }
Note: See TracChangeset
for help on using the changeset viewer.