Java Code Examples for javax.servlet.http.HttpServletResponse#SC_PARTIAL_CONTENT
The following examples show how to use
javax.servlet.http.HttpServletResponse#SC_PARTIAL_CONTENT .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ServletResponseController.java From vespa with Apache License 2.0 | 6 votes |
/** * Async version of {@link org.eclipse.jetty.server.Response#sendError(int, String)}. */ private void sendErrorAsync(int statusCode, String reasonPhrase) { servletResponse.setHeader(HttpHeaders.Names.EXPIRES, null); servletResponse.setHeader(HttpHeaders.Names.LAST_MODIFIED, null); servletResponse.setHeader(HttpHeaders.Names.CACHE_CONTROL, null); servletResponse.setHeader(HttpHeaders.Names.CONTENT_TYPE, null); servletResponse.setHeader(HttpHeaders.Names.CONTENT_LENGTH, null); setStatus(servletResponse, statusCode, Optional.of(reasonPhrase)); // If we are allowed to have a body if (statusCode != HttpServletResponse.SC_NO_CONTENT && statusCode != HttpServletResponse.SC_NOT_MODIFIED && statusCode != HttpServletResponse.SC_PARTIAL_CONTENT && statusCode >= HttpServletResponse.SC_OK) { servletResponse.setHeader(HttpHeaders.Names.CACHE_CONTROL, "must-revalidate,no-cache,no-store"); servletResponse.setContentType(MimeTypes.Type.TEXT_HTML_8859_1.toString()); byte[] errorContent = errorResponseContentCreator .createErrorContent(servletRequest.getRequestURI(), statusCode, Optional.ofNullable(reasonPhrase)); servletResponse.setContentLength(errorContent.length); servletOutputStreamWriter.sendErrorContentAndCloseAsync(ByteBuffer.wrap(errorContent)); } else { servletResponse.setContentLength(0); servletOutputStreamWriter.close(); } }
Example 2
Source File: GetSpaceByNameCommand.java From orion.server with Eclipse Public License 1.0 | 4 votes |
public ServerStatus _doIt() { try { // check the org first URI targetURI = URIUtil.toURI(target.getUrl()); URI orgsURI = targetURI.resolve("/v2/organizations"); //$NON-NLS-1$ GetMethod getOrgsMethod = new GetMethod(orgsURI.toString()); ServerStatus confStatus = HttpUtil.configureHttpMethod(getOrgsMethod, target.getCloud()); if (!confStatus.isOK()) return confStatus; ServerStatus getOrgsStatus = HttpUtil.executeMethod(getOrgsMethod); if (!getOrgsStatus.isOK() && getOrgsStatus.getHttpCode() != HttpServletResponse.SC_PARTIAL_CONTENT) return getOrgsStatus; JSONObject result = getOrgsStatus.getJsonData(); JSONArray orgs = result.getJSONArray("resources"); //$NON-NLS-1$ if (orgs.length() == 0) return new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_NOT_FOUND, "Organization not found", null); Org organization = getOrganization(orgs, orgName); if (organization == null) return new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_NOT_FOUND, "Organization not found", null); // now get the space String spaceUrl = organization.getCFJSON().getJSONObject("entity").getString("spaces_url"); //$NON-NLS-1$//$NON-NLS-2$ URI spaceURI = targetURI.resolve(spaceUrl); GetMethod getSpaceMethod = new GetMethod(spaceURI.toString()); confStatus = HttpUtil.configureHttpMethod(getSpaceMethod, target.getCloud()); if (!confStatus.isOK()) return confStatus; ServerStatus getSpaceStatus = HttpUtil.executeMethod(getSpaceMethod); if (!getSpaceStatus.isOK()) return getSpaceStatus; result = getSpaceStatus.getJsonData(); JSONArray spaces = result.getJSONArray("resources"); //$NON-NLS-1$ if (spaces.length() == 0) return new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_NOT_FOUND, "Space not found", null); Space space = getSpace(spaces, spaceName); if (space == null) return new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_NOT_FOUND, "Space not found", null); return new ServerStatus(Status.OK_STATUS, HttpServletResponse.SC_OK, space.toJSON()); } catch (Exception e) { String msg = NLS.bind("An error occured when performing operation {0}", commandName); //$NON-NLS-1$ logger.error(msg, e); return new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, msg, e); } }
Example 3
Source File: S3ProxyHandler.java From s3proxy with Apache License 2.0 | 4 votes |
private void handleGetBlob(HttpServletRequest request, HttpServletResponse response, BlobStore blobStore, String containerName, String blobName) throws IOException, S3Exception { int status = HttpServletResponse.SC_OK; GetOptions options = new GetOptions(); String ifMatch = request.getHeader(HttpHeaders.IF_MATCH); if (ifMatch != null) { options.ifETagMatches(ifMatch); } String ifNoneMatch = request.getHeader(HttpHeaders.IF_NONE_MATCH); if (ifNoneMatch != null) { options.ifETagDoesntMatch(ifNoneMatch); } long ifModifiedSince = request.getDateHeader( HttpHeaders.IF_MODIFIED_SINCE); if (ifModifiedSince != -1) { options.ifModifiedSince(new Date(ifModifiedSince)); } long ifUnmodifiedSince = request.getDateHeader( HttpHeaders.IF_UNMODIFIED_SINCE); if (ifUnmodifiedSince != -1) { options.ifUnmodifiedSince(new Date(ifUnmodifiedSince)); } String range = request.getHeader(HttpHeaders.RANGE); if (range != null && range.startsWith("bytes=") && // ignore multiple ranges range.indexOf(',') == -1) { range = range.substring("bytes=".length()); String[] ranges = range.split("-", 2); if (ranges[0].isEmpty()) { options.tail(Long.parseLong(ranges[1])); } else if (ranges[1].isEmpty()) { options.startAt(Long.parseLong(ranges[0])); } else { options.range(Long.parseLong(ranges[0]), Long.parseLong(ranges[1])); } status = HttpServletResponse.SC_PARTIAL_CONTENT; } Blob blob = blobStore.getBlob(containerName, blobName, options); if (blob == null) { throw new S3Exception(S3ErrorCode.NO_SUCH_KEY); } response.setStatus(status); String corsOrigin = request.getHeader(HttpHeaders.ORIGIN); if (!Strings.isNullOrEmpty(corsOrigin) && corsRules.isOriginAllowed(corsOrigin)) { response.addHeader(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN, corsOrigin); response.addHeader(HttpHeaders.ACCESS_CONTROL_ALLOW_METHODS, "GET"); } addMetadataToResponse(request, response, blob.getMetadata()); // TODO: handles only a single range due to jclouds limitations Collection<String> contentRanges = blob.getAllHeaders().get(HttpHeaders.CONTENT_RANGE); if (!contentRanges.isEmpty()) { response.addHeader(HttpHeaders.CONTENT_RANGE, contentRanges.iterator().next()); response.addHeader(HttpHeaders.ACCEPT_RANGES, "bytes"); } try (InputStream is = blob.getPayload().openStream(); OutputStream os = response.getOutputStream()) { ByteStreams.copy(is, os); os.flush(); } }
Example 4
Source File: ICalWorker.java From scipio-erp with Apache License 2.0 | 2 votes |
/** Create an HTTP Partial Content response. The calendar converter will use this * response when a calendar is only partially updated. * * @param statusMessage A message describing which calendar components were * not updated * @return Create an HTTP Partial Content response. */ public static ResponseProperties createPartialContentResponse(String statusMessage) { return new ResponseProperties(HttpServletResponse.SC_PARTIAL_CONTENT, statusMessage); }