public void httpErrorCodeException() { throw new HttpErrorCodeException(HttpServletResponse.SC_NO_CONTENT); }
public void badRequestHttpErrorCodeException() { throw new HttpErrorCodeException(HttpServletResponse.SC_BAD_REQUEST); }
public void httpErrorCodeExceptionWithContentType() { throw new HttpErrorCodeException(HttpServletResponse.SC_OK, "{\"hello\":\"world\"}") .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(); } } }
@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"); }
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);
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);
/** * Returns the requested RepositoryItem * * @param request */ public RepositoryItem run(GetRepositoryItemType request) { try { RepositoryItem item = store.getRepositoryItem(request.getId()); if (item == null) { // by spec we have to return a 404 throw new HttpErrorCodeException( 404, "No repository item found for id " + request.getId()); } return item; } catch (IOException e) { throw new ServiceException("Failed to load the repository item", e); } } }
/** * Returns the requested RepositoryItem * * @param request * @return */ public RepositoryItem run(GetRepositoryItemType request) { try { RepositoryItem item = store.getRepositoryItem(request.getId()); if(item == null) { // by spec we have to return a 404 throw new HttpErrorCodeException(404, "No repository item found for id " + request.getId()); } return item; } catch (IOException e) { throw new ServiceException("Failed to load the repository item", e); } } }
throw new HttpErrorCodeException(Status.CLIENT_ERROR_LOCKED.getCode());
throw new HttpErrorCodeException(204); } else { FilterFactory ff = CommonFactoryFinder.getFilterFactory(null);
throw new HttpErrorCodeException(204); } else { FilterFactory ff = CommonFactoryFinder.getFilterFactory(null);