List of usage examples for com.google.common.net HttpHeaders CONTENT_DISPOSITION
String CONTENT_DISPOSITION
To view the source code for com.google.common.net HttpHeaders CONTENT_DISPOSITION.
Click Source Link
From source file:com.epam.ta.reportportal.ws.controller.impl.LaunchController.java
@Override @RequestMapping(value = "/{launchId}/report", method = RequestMethod.GET) @ResponseBody/* w ww. j a va2 s . c om*/ @ResponseStatus(OK) @ApiOperation(value = "Export specified launch", notes = "Only following formats are supported: pdf (by default), xml, xls, html.") public void getLaunchReport(@PathVariable String projectName, @PathVariable String launchId, @RequestParam(value = "view", required = false, defaultValue = "pdf") String view, Principal principal, HttpServletResponse response) throws IOException { JasperPrint jasperPrint = getJasperHandler.getLaunchDetails(launchId, principal.getName()); ReportFormat format = getJasperHandler.getReportFormat(view); response.setContentType(format.getContentType()); response.setHeader(HttpHeaders.CONTENT_DISPOSITION, String.format("attachment; filename=RP_%s_Report.%s", format.name(), format.getValue())); getJasperHandler.writeReport(format, response.getOutputStream(), jasperPrint); }
From source file:org.jclouds.openstack.swift.v1.blobstore.RegionScopedSwiftBlobStore.java
@Override public String copyBlob(String fromContainer, String fromName, String toContainer, String toName, CopyOptions options) {//from ww w . j a va 2 s . c o m ObjectApi objectApi = api.getObjectApi(regionId, toContainer); org.jclouds.openstack.swift.v1.options.CopyOptions swiftOptions = new org.jclouds.openstack.swift.v1.options.CopyOptions(); if (options.ifMatch() != null) { swiftOptions.ifMatch(options.ifMatch()); } if (options.ifNoneMatch() != null) { throw new UnsupportedOperationException("Swift does not support ifNoneMatch"); } if (options.ifModifiedSince() != null) { swiftOptions.ifModifiedSince(options.ifModifiedSince()); } if (options.ifUnmodifiedSince() != null) { swiftOptions.ifUnmodifiedSince(options.ifUnmodifiedSince()); } Map<String, String> systemMetadata = Maps.newHashMap(); ContentMetadata contentMetadata = options.contentMetadata(); Map<String, String> userMetadata = options.userMetadata(); if (contentMetadata != null || userMetadata != null) { if (contentMetadata != null) { String contentDisposition = contentMetadata.getContentDisposition(); if (contentDisposition != null) { systemMetadata.put(HttpHeaders.CONTENT_DISPOSITION, contentDisposition); } String contentEncoding = contentMetadata.getContentEncoding(); if (contentEncoding != null) { systemMetadata.put(HttpHeaders.CONTENT_ENCODING, contentEncoding); } String contentLanguage = contentMetadata.getContentLanguage(); if (contentLanguage != null) { systemMetadata.put(HttpHeaders.CONTENT_LANGUAGE, contentLanguage); } String contentType = contentMetadata.getContentType(); if (contentType != null) { systemMetadata.put(HttpHeaders.CONTENT_TYPE, contentType); } } if (userMetadata == null) { userMetadata = Maps.newHashMap(); } } else { SwiftObject metadata = api.getObjectApi(regionId, fromContainer).getWithoutBody(fromName); if (metadata == null) { throw new KeyNotFoundException(fromContainer, fromName, "Swift could not find the specified source key"); } contentMetadata = metadata.getPayload().getContentMetadata(); String contentDisposition = contentMetadata.getContentDisposition(); if (contentDisposition != null) { systemMetadata.put(HttpHeaders.CONTENT_DISPOSITION, contentDisposition); } String contentEncoding = contentMetadata.getContentEncoding(); if (contentEncoding != null) { systemMetadata.put(HttpHeaders.CONTENT_ENCODING, contentEncoding); } String contentLanguage = contentMetadata.getContentLanguage(); if (contentLanguage != null) { systemMetadata.put(HttpHeaders.CONTENT_LANGUAGE, contentLanguage); } String contentType = contentMetadata.getContentType(); if (contentType != null) { systemMetadata.put(HttpHeaders.CONTENT_TYPE, contentType); } userMetadata = metadata.getMetadata(); } objectApi.copy(toName, fromContainer, fromName, userMetadata, systemMetadata, swiftOptions); // TODO: Swift copy object *appends* user metadata, does not overwrite return objectApi.getWithoutBody(toName).getETag(); }
From source file:org.gaul.s3proxy.S3ProxyHandler.java
private void handleCopyBlob(HttpServletRequest request, HttpServletResponse response, BlobStore blobStore, String destContainerName, String destBlobName) throws IOException, S3Exception { String copySourceHeader = request.getHeader("x-amz-copy-source"); copySourceHeader = URLDecoder.decode(copySourceHeader, "UTF-8"); if (copySourceHeader.startsWith("/")) { // Some clients like boto do not include the leading slash copySourceHeader = copySourceHeader.substring(1); }/*from www . ja va2s.c om*/ String[] path = copySourceHeader.split("/", 2); if (path.length != 2) { throw new S3Exception(S3ErrorCode.INVALID_REQUEST); } String sourceContainerName = path[0]; String sourceBlobName = path[1]; boolean replaceMetadata = "REPLACE".equalsIgnoreCase(request.getHeader("x-amz-metadata-directive")); if (sourceContainerName.equals(destContainerName) && sourceBlobName.equals(destBlobName) && !replaceMetadata) { throw new S3Exception(S3ErrorCode.INVALID_REQUEST); } CopyOptions.Builder options = CopyOptions.builder(); if (replaceMetadata) { ContentMetadataBuilder contentMetadata = ContentMetadataBuilder.create(); ImmutableMap.Builder<String, String> userMetadata = ImmutableMap.builder(); for (String headerName : Collections.list(request.getHeaderNames())) { String headerValue = Strings.nullToEmpty(request.getHeader(headerName)); if (headerName.equalsIgnoreCase(HttpHeaders.CONTENT_DISPOSITION)) { contentMetadata.contentDisposition(headerValue); } else if (headerName.equalsIgnoreCase(HttpHeaders.CONTENT_ENCODING)) { contentMetadata.contentEncoding(headerValue); } else if (headerName.equalsIgnoreCase(HttpHeaders.CONTENT_LANGUAGE)) { contentMetadata.contentLanguage(headerValue); } else if (headerName.equalsIgnoreCase(HttpHeaders.CONTENT_TYPE)) { contentMetadata.contentType(headerValue); } else if (headerName.toLowerCase().startsWith(USER_METADATA_PREFIX)) { userMetadata.put(headerName.substring(USER_METADATA_PREFIX.length()), headerValue); } // TODO: Expires } options.contentMetadata(contentMetadata.build()); options.userMetadata(userMetadata.build()); } String eTag; try { eTag = blobStore.copyBlob(sourceContainerName, sourceBlobName, destContainerName, destBlobName, options.build()); } catch (KeyNotFoundException knfe) { throw new S3Exception(S3ErrorCode.NO_SUCH_KEY, knfe); } // TODO: jclouds should include this in CopyOptions String cannedAcl = request.getHeader("x-amz-acl"); if (cannedAcl != null && !cannedAcl.equalsIgnoreCase("private")) { handleSetBlobAcl(request, response, blobStore, destContainerName, destBlobName); } BlobMetadata blobMetadata = blobStore.blobMetadata(destContainerName, destBlobName); try (Writer writer = response.getWriter()) { XMLStreamWriter xml = xmlOutputFactory.createXMLStreamWriter(writer); xml.writeStartDocument(); xml.writeStartElement("CopyObjectResult"); xml.writeDefaultNamespace(AWS_XMLNS); writeSimpleElement(xml, "LastModified", blobStore.getContext().utils().date().iso8601DateFormat(blobMetadata.getLastModified())); writeSimpleElement(xml, "ETag", "\"" + eTag + "\""); xml.writeEndElement(); xml.flush(); } catch (XMLStreamException xse) { throw new IOException(xse); } }
From source file:org.gaul.s3proxy.S3ProxyHandler.java
private static void addMetadataToResponse(HttpServletResponse response, BlobMetadata metadata) { ContentMetadata contentMetadata = metadata.getContentMetadata(); response.addHeader(HttpHeaders.CONTENT_DISPOSITION, contentMetadata.getContentDisposition()); response.addHeader(HttpHeaders.CONTENT_ENCODING, contentMetadata.getContentEncoding()); response.addHeader(HttpHeaders.CONTENT_LANGUAGE, contentMetadata.getContentLanguage()); response.addHeader(HttpHeaders.CONTENT_LENGTH, contentMetadata.getContentLength().toString()); response.setContentType(contentMetadata.getContentType()); HashCode contentMd5 = contentMetadata.getContentMD5AsHashCode(); if (contentMd5 != null) { byte[] contentMd5Bytes = contentMd5.asBytes(); response.addHeader(HttpHeaders.CONTENT_MD5, BaseEncoding.base64().encode(contentMd5Bytes)); response.addHeader(HttpHeaders.ETAG, "\"" + BaseEncoding.base16().lowerCase().encode(contentMd5Bytes) + "\""); }// www .j a va 2 s .c o m Date expires = contentMetadata.getExpires(); if (expires != null) { response.addDateHeader(HttpHeaders.EXPIRES, expires.getTime()); } response.addDateHeader(HttpHeaders.LAST_MODIFIED, metadata.getLastModified().getTime()); for (Map.Entry<String, String> entry : metadata.getUserMetadata().entrySet()) { response.addHeader(USER_METADATA_PREFIX + entry.getKey(), entry.getValue()); } }
From source file:org.gaul.s3proxy.S3ProxyHandler.java
private static void addContentMetdataFromHttpRequest(BlobBuilder.PayloadBlobBuilder builder, HttpServletRequest request) {//from w ww . ja v a 2 s . c o m ImmutableMap.Builder<String, String> userMetadata = ImmutableMap.builder(); for (String headerName : Collections.list(request.getHeaderNames())) { if (headerName.toLowerCase().startsWith(USER_METADATA_PREFIX)) { userMetadata.put(headerName.substring(USER_METADATA_PREFIX.length()), Strings.nullToEmpty(request.getHeader(headerName))); } } builder.contentDisposition(request.getHeader(HttpHeaders.CONTENT_DISPOSITION)) .contentEncoding(request.getHeader(HttpHeaders.CONTENT_ENCODING)) .contentLanguage(request.getHeader(HttpHeaders.CONTENT_LANGUAGE)) .userMetadata(userMetadata.build()); String contentType = request.getContentType(); if (contentType != null) { builder.contentType(contentType); } long expires = request.getDateHeader(HttpHeaders.EXPIRES); if (expires != -1) { builder.expires(new Date(expires)); } }