request.setHttpResponse(httpResponse);
public void testErrorSavedOnRequestOnGenericException() throws Exception { MockHttpServletRequest request = new MockHttpServletRequest(); request.setContextPath("/geoserver"); request.setRequestURI("/geoserver/hello"); request.setMethod("get"); Dispatcher dispatcher = new Dispatcher(); Request req = new Request(); req.httpRequest = request; dispatcher.init(req); MockHttpServletResponse response = new MockHttpServletResponse(); req.setHttpResponse(response); RuntimeException genericError = new RuntimeException("foo"); dispatcher.exception(genericError, null, req); assertEquals("Exception did not get saved", genericError, req.error); }
protected void setUp() throws Exception { super.setUp(); HelloWorld helloWorld = new HelloWorld(); Service service = new Service( "hello", helloWorld, new Version("1.0.0"), Collections.singletonList("hello")); request = new MockHttpServletRequest() { public int getServerPort() { return 8080; } }; request.setScheme("http"); request.setServerName("localhost"); request.setContextPath("geoserver"); response = new MockHttpServletResponse(); handler = new DefaultServiceExceptionHandler(); requestInfo = new Request(); requestInfo.setHttpRequest(request); requestInfo.setHttpResponse(response); requestInfo.setService("hello"); requestInfo.setVersion("1.0.0"); }
public void testNoErrorOn304ErrorCodeException() throws Exception { MockHttpServletRequest request = new MockHttpServletRequest(); request.setContextPath("/geoserver"); request.setRequestURI("/geoserver/hello"); request.setMethod("get"); Dispatcher dispatcher = new Dispatcher(); Request req = new Request(); req.httpRequest = request; dispatcher.init(req); MockHttpServletResponse response = new MockHttpServletResponse(); req.setHttpResponse(response); RuntimeException error = new HttpErrorCodeException(304, "Not Modified"); dispatcher.exception(error, null, req); assertNull("Exception erroneously saved", req.error); }
public void testErrorSavedOnRequestOnNon304ErrorCodeException() throws Exception { MockHttpServletRequest request = new MockHttpServletRequest(); request.setContextPath("/geoserver"); request.setRequestURI("/geoserver/hello"); request.setMethod("get"); Dispatcher dispatcher = new Dispatcher(); Request req = new Request(); req.httpRequest = request; dispatcher.init(req); MockHttpServletResponse response = new MockHttpServletResponse(); req.setHttpResponse(response); RuntimeException genericError = new HttpErrorCodeException(500, "Internal Server Error"); dispatcher.exception(genericError, null, req); assertEquals("Exception did not get saved", genericError, req.error); }
@Override public Operation operationDispatched(Request request, Operation operation) { String version = request.getVersion(); String method = request.getRequest(); long timeout = getTimeoutMilliseconds(operation); if ("WFS".equalsIgnoreCase(request.getService()) && (version == null || V_20.compareTo(new Version(version)) <= 0) && method != null && (method.equalsIgnoreCase("GetFeature") || method.equalsIgnoreCase("GetFeatureWithLock") || method.equalsIgnoreCase("GetPropertyValue")) && timeout > 0 && operation.getParameters().length > 0 && operation.getParameters()[0] instanceof BaseRequestType) { if (LOGGER.isLoggable(Level.FINE)) { LOGGER.fine("Starting to track NSG timeout on this request"); } // start tracking time TimeoutVerifier timeoutVerifier = new TimeoutVerifier((BaseRequestType) operation.getParameters()[0], timeout); // need to wrap the http response and its output stream request.setHttpResponse( new TimeoutCancellingResponse(request.getHttpResponse(), timeoutVerifier)); // set in the thread local for later use TIMEOUT_VERIFIER.set(timeoutVerifier); } return operation; }
Request buildRequest(String gsCookieValue) { Request request = new Request(); MockHttpServletRequest httpRequest = new MockHttpServletRequest(); request.setHttpRequest(httpRequest); request.setHttpResponse(new MockHttpServletResponse()); if(gsCookieValue != null) { httpRequest.addCookie(new Cookie(UserFlowController.COOKIE_NAME, gsCookieValue)); } return request; } }
Request buildRequest(String ipAddress, String proxyIp) { Request request = new Request(); MockHttpServletRequest httpRequest = new MockHttpServletRequest(); request.setHttpRequest(httpRequest); request.setHttpResponse(new MockHttpServletResponse()); if (ipAddress != null && !ipAddress.equals("")) { httpRequest.setRemoteAddr(ipAddress); } else { httpRequest.setRemoteAddr("127.0.0.1"); } if (!proxyIp.equals("")) { httpRequest.setHeader("x-forwarded-for", proxyIp + ", " + ipAddress); } return request; }