public void testDispatcherCallback() throws Exception { URL url = getClass().getResource("applicationContext.xml"); FileSystemXmlApplicationContext context = new FileSystemXmlApplicationContext(url.toString()); Dispatcher dispatcher = (Dispatcher) context.getBean("dispatcher"); TestDispatcherCallback callback = new TestDispatcherCallback(); MockHttpServletRequest request = setupRequest(); MockHttpServletResponse response = new MockHttpServletResponse(); dispatcher.callbacks.add(callback); dispatcher.handleRequest(request, response); assertEquals("Hello world!", response.getContentAsString()); assertEquals(TestDispatcherCallback.Status.FINISHED, callback.dispatcherStatus.get()); }
public void testErrorThrowingResponse() throws Exception { URL url = getClass().getResource("applicationContext-errorResponse.xml"); try (FileSystemXmlApplicationContext context = new FileSystemXmlApplicationContext(url.toString())) { Dispatcher dispatcher = (Dispatcher) context.getBean("dispatcher"); MockHttpServletRequest request = setupRequest(); MockHttpServletResponse response = new MockHttpServletResponse(); dispatcher.handleRequest(request, response); // the output is not there final String outputContent = response.getContentAsString(); assertThat(outputContent, not(containsString("Hello world!"))); // only the exception Document dom = XMLUnit.buildTestDocument(outputContent); assertEquals("ows:ExceptionReport", dom.getDocumentElement().getNodeName()); } } }
public void testDispatcherCallbackFailServiceDispatched() throws Exception { URL url = getClass().getResource("applicationContext.xml"); FileSystemXmlApplicationContext context = new FileSystemXmlApplicationContext(url.toString()); Dispatcher dispatcher = (Dispatcher) context.getBean("dispatcher"); final TestDispatcherCallback callback1 = new TestDispatcherCallback(); final TestDispatcherCallback callback2 = new TestDispatcherCallback(); TestDispatcherCallback callbackFail = new TestDispatcherCallback() { @Override public Service serviceDispatched(Request request, Service service) { dispatcherStatus.set(Status.SERVICE_DISPATCHED); throw new RuntimeException("TestDispatcherCallbackFailServiceDispatched"); } }; MockHttpServletRequest request = setupRequest(); MockHttpServletResponse response = new MockHttpServletResponse(); dispatcher.callbacks.add(callback1); dispatcher.callbacks.add(callbackFail); dispatcher.callbacks.add(callback2); dispatcher.handleRequest(request, response); assertTrue(response.getContentAsString().contains("ows:ExceptionReport")); assertEquals(TestDispatcherCallback.Status.FINISHED, callback1.dispatcherStatus.get()); assertEquals(TestDispatcherCallback.Status.FINISHED, callback2.dispatcherStatus.get()); }
public void testDispatcherCallbackFailOperationDispatched() throws Exception { URL url = getClass().getResource("applicationContext.xml"); FileSystemXmlApplicationContext context = new FileSystemXmlApplicationContext(url.toString()); Dispatcher dispatcher = (Dispatcher) context.getBean("dispatcher"); final TestDispatcherCallback callback1 = new TestDispatcherCallback(); final TestDispatcherCallback callback2 = new TestDispatcherCallback(); TestDispatcherCallback callbackFail = new TestDispatcherCallback() { @Override public Operation operationDispatched(Request request, Operation operation) { dispatcherStatus.set(Status.OPERATION_DISPATCHED); throw new RuntimeException("TestDispatcherCallbackFailOperationDispatched"); } }; MockHttpServletRequest request = setupRequest(); MockHttpServletResponse response = new MockHttpServletResponse(); dispatcher.callbacks.add(callback1); dispatcher.callbacks.add(callbackFail); dispatcher.callbacks.add(callback2); dispatcher.handleRequest(request, response); assertTrue(response.getContentAsString().contains("ows:ExceptionReport")); assertEquals(TestDispatcherCallback.Status.FINISHED, callback1.dispatcherStatus.get()); assertEquals(TestDispatcherCallback.Status.FINISHED, callback2.dispatcherStatus.get()); }
public void testDispatcherCallbackFailInit() throws Exception { URL url = getClass().getResource("applicationContext.xml"); FileSystemXmlApplicationContext context = new FileSystemXmlApplicationContext(url.toString()); Dispatcher dispatcher = (Dispatcher) context.getBean("dispatcher"); final TestDispatcherCallback callback1 = new TestDispatcherCallback(); final TestDispatcherCallback callback2 = new TestDispatcherCallback(); ; TestDispatcherCallback callbackFail = new TestDispatcherCallback() { @Override public Request init(Request request) { dispatcherStatus.set(Status.INIT); throw new RuntimeException("TestDispatcherCallbackFailInit"); } }; MockHttpServletRequest request = setupRequest(); MockHttpServletResponse response = new MockHttpServletResponse(); dispatcher.callbacks.add(callback1); dispatcher.callbacks.add(callbackFail); dispatcher.callbacks.add(callback2); dispatcher.handleRequest(request, response); assertTrue(response.getContentAsString().contains("ows:ExceptionReport")); assertEquals(TestDispatcherCallback.Status.FINISHED, callback1.dispatcherStatus.get()); assertEquals(TestDispatcherCallback.Status.FINISHED, callback2.dispatcherStatus.get()); }
public void testDispatcherCallbackFailOperationExecuted() throws Exception { URL url = getClass().getResource("applicationContext.xml"); FileSystemXmlApplicationContext context = new FileSystemXmlApplicationContext(url.toString()); Dispatcher dispatcher = (Dispatcher) context.getBean("dispatcher"); final TestDispatcherCallback callback1 = new TestDispatcherCallback(); final TestDispatcherCallback callback2 = new TestDispatcherCallback(); TestDispatcherCallback callbackFail = new TestDispatcherCallback() { @Override public Object operationExecuted( Request request, Operation operation, Object result) { dispatcherStatus.set(Status.OPERATION_EXECUTED); throw new RuntimeException("TestDispatcherCallbackFailOperationExecuted"); } }; MockHttpServletRequest request = setupRequest(); MockHttpServletResponse response = new MockHttpServletResponse(); dispatcher.callbacks.add(callback1); dispatcher.callbacks.add(callbackFail); dispatcher.callbacks.add(callback2); dispatcher.handleRequest(request, response); assertTrue(response.getContentAsString().contains("ows:ExceptionReport")); assertEquals(TestDispatcherCallback.Status.FINISHED, callback1.dispatcherStatus.get()); assertEquals(TestDispatcherCallback.Status.FINISHED, callback2.dispatcherStatus.get()); }
dispatcher.callbacks.add(callback2); dispatcher.handleRequest(request, response); assertEquals("Hello world!", response.getContentAsString()); assertTrue(firedCallback.get());
public void testDispatcherCallbackFailResponseDispatched() throws Exception { URL url = getClass().getResource("applicationContext.xml"); FileSystemXmlApplicationContext context = new FileSystemXmlApplicationContext(url.toString()); Dispatcher dispatcher = (Dispatcher) context.getBean("dispatcher"); final TestDispatcherCallback callback1 = new TestDispatcherCallback(); final TestDispatcherCallback callback2 = new TestDispatcherCallback(); TestDispatcherCallback callbackFail = new TestDispatcherCallback() { @Override public Response responseDispatched( Request request, Operation operation, Object result, Response response) { dispatcherStatus.set(Status.RESPONSE_DISPATCHED); throw new RuntimeException("TestDispatcherCallbackFailResponseDispatched"); } }; MockHttpServletRequest request = setupRequest(); MockHttpServletResponse response = new MockHttpServletResponse(); dispatcher.callbacks.add(callback1); dispatcher.callbacks.add(callbackFail); dispatcher.callbacks.add(callback2); dispatcher.handleRequest(request, response); assertTrue(response.getContentAsString().contains("ows:ExceptionReport")); assertEquals(TestDispatcherCallback.Status.FINISHED, callback1.dispatcherStatus.get()); assertEquals(TestDispatcherCallback.Status.FINISHED, callback2.dispatcherStatus.get()); }
request.setRequestURI("http://localhost/geoserver/hello"); dispatcher.handleRequest(request, response); assertEquals("Hello world!", response.getContentAsString()); dispatcher.handleRequest(request, response); assertEquals("Hello world!:V2", response.getContentAsString());
dispatcher.handleRequest(request, response); assertEquals("Hello world!", response.getContentAsString());
dispatcher.handleRequest(request, response); assertEquals("Hello world!", response.getContentAsString());
dispatcher.handleRequest(request, response); assertEquals("Hello world!", response.getContentAsString());
request.setQueryString("service=hello&request=hello&message=HelloWorld"); dispatcher.handleRequest(request, response); assertEquals(expectedCode, response.getStatusCode());
public void proxyOwsRequest(ConveyorTile tile) throws Exception { HttpServletRequest actualRequest = tile.servletReq; // get the param map and force service to be WMS if missing Map<String, String> parameterMap = new HashMap<String, String>(); Map<String, String[]> params = actualRequest.getParameterMap(); boolean hasService = false; for (Map.Entry<String, String[]> param : params.entrySet()) { String key = param.getKey(); String value = param.getValue()[0]; parameterMap.put(key, value); if ("service".equalsIgnoreCase(key) && (value == null || value.isEmpty() || !"WMS".equalsIgnoreCase(value))) { throw new GeoWebCacheException( "Failed to cascade request, service should be WMS but it was: '" + value + "'"); } } if (!hasService) { parameterMap.put("service", "WMS"); } // cascade Cookie[] cookies = actualRequest.getCookies(); FakeHttpServletRequest request = new FakeHttpServletRequest(parameterMap, cookies); owsDispatcher.handleRequest(request, tile.servletResp); }
/** * Dispatches a request to the GeoServer OWS {@link Dispatcher} * * @param params the KVP map of OWS parameters * @param cookies * @return an http response wrapper where to grab the raw dispatcher response from */ public Resource dispatchOwsRequest(final Map<String, String> params, Cookie[] cookies) throws Exception { // If the WORKSPACE parameter is set, remove it and use it to set the workspace of the // request String workspace = params.remove(WORKSPACE_PARAM); FakeHttpServletRequest req = new FakeHttpServletRequest(params, cookies, workspace); FakeHttpServletResponse resp = new FakeHttpServletResponse(); Request request = Dispatcher.REQUEST.get(); Dispatcher.REQUEST.remove(); try { owsDispatcher.handleRequest(req, resp); } finally { // reset the old request if (request != null) { Dispatcher.REQUEST.set(request); } else { Dispatcher.REQUEST.remove(); } } return new ByteArrayResource(resp.getBytes()); }
/** * Dispatches a request to the GeoServer OWS {@link Dispatcher} * * @param params * the KVP map of OWS parameters * @param cookies * @return an http response wrapper where to grab the raw dispatcher response from * @throws Exception */ public Resource dispatchOwsRequest(final Map<String, String> params, Cookie[] cookies) throws Exception { FakeHttpServletRequest req = new FakeHttpServletRequest(params, cookies); FakeHttpServletResponse resp = new FakeHttpServletResponse(); owsDispatcher.handleRequest(req, resp); return new ByteArrayResource(resp.getBytes()); }