public void httpErrorCodeException() { throw new HttpErrorCodeException(HttpServletResponse.SC_NO_CONTENT); }
int errorCode = ece.getErrorCode(); if (errorCode < 199 || errorCode > 299) { logger.log(Level.FINE, "", t); boolean isError = ece.getErrorCode() >= 400; HttpServletResponse rsp = request.getHttpResponse(); if (ece.getContentType() != null) { rsp.setContentType(ece.getContentType()); if (ece.getMessage() != null) { rsp.sendError(ece.getErrorCode(), ece.getMessage()); } else { rsp.sendError(ece.getErrorCode()); rsp.setStatus(ece.getErrorCode()); if (ece.getMessage() != null) { rsp.getOutputStream().print(ece.getMessage());
public void httpErrorCodeExceptionWithContentType() { throw new HttpErrorCodeException(HttpServletResponse.SC_OK, "{\"hello\":\"world\"}") .setContentType("application/json"); } }
@Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { if (request instanceof HttpServletRequest) { HttpServletRequest requestHTTP = (HttpServletRequest) request; if (requestNeedsWrapper(requestHTTP)) { try { request = new RequestWrapper(requestHTTP); } catch (HttpErrorCodeException exception) { ((HttpServletResponse) response) .sendError(exception.getErrorCode(), exception.getMessage()); return; } } } chain.doFilter(request, response); }
numFeatures = -1; } catch (HttpErrorCodeException e) { if (e.getErrorCode() == 204) { throw e; } else {
public void testTimeout() { ControlFlowCallback callback = new ControlFlowCallback(); TestingConfigurator tc = new TestingConfigurator(); tc.timeout = 300; CountingController c1 = new CountingController(2, 200); CountingController c2 = new CountingController(1, 200); tc.controllers.add(c1); tc.controllers.add(c2); callback.configurator = tc; try { callback.operationDispatched(null, null); fail("A HTTP 503 should have been raised!"); } catch(HttpErrorCodeException e) { assertEquals(503, e.getErrorCode()); } assertEquals(1, c1.requestIncomingCalls); assertEquals(0, c1.requestCompleteCalls); assertEquals(1, c2.requestIncomingCalls); assertEquals(0, c1.requestCompleteCalls); callback.finished(null); }
public void badRequestHttpErrorCodeException() { throw new HttpErrorCodeException(HttpServletResponse.SC_BAD_REQUEST); }
@Override public Operation operationDispatched(Request request, Operation operation) { String sim = Optional.ofNullable(request.getRawKvp().get(KVP)) .map(String.class::cast) .orElse(null); if (sim == null) { return operation; } Map<String, Object> simOpts; if (sim.contains(";")) { try { simOpts = (Map<String, Object>) new FormatOptionsKvpParser().parse(sim.toString()); } catch (Exception e) { throw new RuntimeException( "Illegal syntax for simulate options: simulate=<key>:<val>[;<key>:<val>]*", e); } } else { simOpts = Collections.emptyMap(); } throw new HttpErrorCodeException(202, toJSON(operation, simOpts)) .setContentType("application/json"); }
public void wrappedHttpErrorCodeException() { try { throw new HttpErrorCodeException(HttpServletResponse.SC_NO_CONTENT); } catch (Exception e) { throw new ServiceException("Wrapping code error", e); } }
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); }
/** * When the read lock should be enacted, throws an exception to return the * expected HTTP status code */ public org.geoserver.ows.Request init(org.geoserver.ows.Request request) { // If the lock is not enabled or the lock is for write operations, does not enforce it if ( !this.enabled || this.lockType == LockType.WRITE) { return request; } throw new HttpErrorCodeException(Status.CLIENT_ERROR_LOCKED.getCode(), "Request rejected due to an underway backup/restore"); }
public void onBeginRequest() { // If the lock is not enabled, does not enforce it if ( !this.enabled) { return; } throw new HttpErrorCodeException(Status.CLIENT_ERROR_LOCKED.getCode(), "Request rejected due to an underway backup/restore"); }
private void setLayerName(String layerName) { List<LayerInfo> layers = NCNameResourceCodec.getLayers(catalog, layerName); if (!layers.isEmpty()) { typeName = layers.get(0).prefixedName(); } else { throw new HttpErrorCodeException( HttpStatus.NOT_FOUND.value(), "Could not find feature type " + layerName); } }
@Override public void write(Object value, OutputStream output, Operation operation) throws IOException, ServiceException { InputStream input = null; try { input = ((RepositoryItem) value).getContents(); if (null != input) { IOUtils.copy(input, output); } else { throw new HttpErrorCodeException(404, "Repository item had no content"); } } catch (IOException e) { throw new ServiceException("Failed to encode the repository item onto the output", e); } finally { IOUtils.closeQuietly(input); output.flush(); } }
@Override public void write(Object value, OutputStream output, Operation operation) throws IOException, ServiceException { InputStream input = null; try { input = ((RepositoryItem) value).getContents(); if (null != input) { IOUtils.copy(input, output); } else { throw new HttpErrorCodeException(404, "Repository item had no content"); } } catch (IOException e) { throw new ServiceException("Failed to encode the repository item onto the output", e); } finally { IOUtils.closeQuietly(input); output.flush(); } } }
long maxWait = maxTime - System.currentTimeMillis(); if(!flowController.requestIncoming(request, maxWait)) throw new HttpErrorCodeException(503, "Requested timeout out while waiting to be executed"); } else { flowController.requestIncoming(request, -1);
throw new HttpErrorCodeException( HttpStatus.NOT_FOUND.value(), "Unsupported path " + pathInfo); throw new HttpErrorCodeException( HttpStatus.NOT_FOUND.value(), "Unsupported path " + pathInfo);
private void setConditionalGetHeaders(RawMap map, ConveyorTile cachedTile, GetMapRequest request, String etag) { map.setResponseHeader("ETag", etag); final long tileTimeStamp = cachedTile.getTSCreated(); final String ifModSinceHeader = request.getHttpRequestHeader("If-Modified-Since"); // commons-httpclient's DateUtil can encode and decode timestamps formatted as per RFC-1123, // which is one of the three formats allowed for Last-Modified and If-Modified-Since headers // (e.g. 'Sun, 06 Nov 1994 08:49:37 GMT'). See // http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.3.1 final String lastModified = org.apache.commons.httpclient.util.DateUtil .formatDate(new Date(tileTimeStamp)); map.setResponseHeader("Last-Modified", lastModified); final Date ifModifiedSince; if (ifModSinceHeader != null && ifModSinceHeader.length() > 0) { try { ifModifiedSince = DateUtil.parseDate(ifModSinceHeader); // the HTTP header has second precision long ifModSinceSeconds = 1000 * (ifModifiedSince.getTime() / 1000); long tileTimeStampSeconds = 1000 * (tileTimeStamp / 1000); if (ifModSinceSeconds >= tileTimeStampSeconds) { throw new HttpErrorCodeException(HttpServletResponse.SC_NOT_MODIFIED); } } catch (DateParseException e) { if (LOGGER.isLoggable(Level.FINER)) { LOGGER.finer("Can't parse client's If-Modified-Since header: '" + ifModSinceHeader + "'"); } } } }
long tileTimeStampSeconds = 1000 * (tileTimeStamp / 1000); if (ifModSinceSeconds >= tileTimeStampSeconds) { throw new HttpErrorCodeException(HttpServletResponse.SC_NOT_MODIFIED);