List of usage examples for org.springframework.http HttpHeaders CONTENT_LENGTH
String CONTENT_LENGTH
To view the source code for org.springframework.http HttpHeaders CONTENT_LENGTH.
Click Source Link
From source file:nl.dtls.fairdatapoint.api.controller.utils.LoggerUtils.java
/** * Log the request./* www . jav a2s.co m*/ * * Log message pattern [Time\t IP\t requestMethod\t requestedURL] * @param logger Class logger * @param request Client request * @param response Server response */ public static void logRequest(Logger logger, HttpServletRequest request, HttpServletResponse response) { ThreadContext.put("requestMethod", request.getMethod()); ThreadContext.put("requestURI", request.getRequestURI()); ThreadContext.put("requestProtocol", request.getProtocol()); ThreadContext.put("responseStatus", String.valueOf(response.getStatus())); String contentLength = response.getHeader(HttpHeaders.CONTENT_LENGTH); ThreadContext.put("contentSize", contentLength); logger.log(Level.getLevel("API-REQUEST"), ""); }
From source file:de.codecentric.boot.admin.zuul.filters.post.SendResponseFilterTests.java
private SendResponseFilter createFilter(String content, String characterEncoding, MockHttpServletResponse response, boolean streamContent) throws Exception { HttpServletRequest request = new MockHttpServletRequest(); RequestContext context = new RequestContext(); context.setRequest(request);// w w w . ja v a2 s. co m context.setResponse(response); if (characterEncoding != null) { response.setCharacterEncoding(characterEncoding); } if (streamContent) { context.setResponseDataStream(new ByteArrayInputStream(content.getBytes(characterEncoding))); } else { context.setResponseBody(content); } context.addZuulResponseHeader(HttpHeaders.CONTENT_LENGTH, String.valueOf(content.length())); context.set("error.status_code", HttpStatus.NOT_FOUND.value()); RequestContext.testSetCurrentContext(context); SendResponseFilter filter = new SendResponseFilter(); return filter; }
From source file:com.github.zhanhb.ckfinder.download.PathPartial.java
private void setContentLengthLong(HttpServletResponse response, long length) { if (HAS_METHOD_CONTENT_LENGTH_LONG) { response.setContentLengthLong(length); } else if (length <= Integer.MAX_VALUE) { response.setContentLength((int) length); } else {//from w ww .j a va 2 s . co m response.setHeader(HttpHeaders.CONTENT_LENGTH, Long.toString(length)); } }
From source file:eu.europa.ec.grow.espd.controller.EspdController.java
private void downloadEspdFile(@PathVariable String agent, @ModelAttribute("espd") EspdDocument espd, HttpServletResponse response) throws IOException { try (CountingOutputStream out = new CountingOutputStream(response.getOutputStream())) { response.setContentType(APPLICATION_XML_VALUE); if ("eo".equals(agent)) { response.setHeader(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"espd-response.xml\""); exchangeMarshaller.generateEspdResponse(espd, out); } else {/*from ww w .j av a 2 s.co m*/ response.setHeader(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"espd-request.xml\""); exchangeMarshaller.generateEspdRequest(espd, out); } response.setHeader(HttpHeaders.CONTENT_LENGTH, String.valueOf(out.getByteCount())); out.flush(); } }
From source file:org.fao.geonet.api.records.MetadataApi.java
@ApiOperation(value = "Get a metadata record as ZIP", notes = "Metadata Exchange Format (MEF) is returned. MEF is a ZIP file containing " + "the metadata as XML and some others files depending on the version requested. " + "See http://geonetwork-opensource.org/manuals/trunk/eng/users/annexes/mef-format.html.", nickname = "getRecordAsZip") @RequestMapping(value = "/{metadataUuid}/formatters/zip", method = RequestMethod.GET, consumes = { MediaType.ALL_VALUE }, produces = { "application/zip", MEF_V1_ACCEPT_TYPE, MEF_V2_ACCEPT_TYPE }) @ApiResponses(value = { @ApiResponse(code = 200, message = "Return the record."), @ApiResponse(code = 403, message = ApiParams.API_RESPONSE_NOT_ALLOWED_CAN_VIEW) }) public @ResponseBody void getRecordAsZip( @ApiParam(value = API_PARAM_RECORD_UUID, required = true) @PathVariable String metadataUuid, @ApiParam(value = "MEF file format.", required = false) @RequestParam(required = false, defaultValue = "FULL") MEFLib.Format format, @ApiParam(value = "With related records (parent and service).", required = false) @RequestParam(required = false, defaultValue = "true") boolean withRelated, @ApiParam(value = "Resolve XLinks in the records.", required = false) @RequestParam(required = false, defaultValue = "true") boolean withXLinksResolved, @ApiParam(value = "Preserve XLink URLs in the records.", required = false) @RequestParam(required = false, defaultValue = "false") boolean withXLinkAttribute, @RequestParam(required = false, defaultValue = "true") boolean addSchemaLocation, @RequestHeader(value = HttpHeaders.ACCEPT, defaultValue = "application/x-gn-mef-2-zip") String acceptHeader, HttpServletResponse response, HttpServletRequest request) throws Exception { ApplicationContext appContext = ApplicationContextHolder.get(); GeonetworkDataDirectory dataDirectory = appContext.getBean(GeonetworkDataDirectory.class); AbstractMetadata metadata;/*from w ww . j a v a 2 s . c o m*/ try { metadata = ApiUtils.canViewRecord(metadataUuid, request); } catch (SecurityException e) { Log.debug(API.LOG_MODULE_NAME, e.getMessage(), e); throw new NotAllowedException(ApiParams.API_RESPONSE_NOT_ALLOWED_CAN_VIEW); } Path stylePath = dataDirectory.getWebappDir().resolve(Geonet.Path.SCHEMAS); Path file = null; ServiceContext context = ApiUtils.createServiceContext(request); MEFLib.Version version = MEFLib.Version.find(acceptHeader); if (version == MEFLib.Version.V1) { // This parameter is deprecated in v2. boolean skipUUID = false; file = MEFLib.doExport(context, metadataUuid, format.toString(), skipUUID, withXLinksResolved, withXLinkAttribute, addSchemaLocation); } else { Set<String> tmpUuid = new HashSet<String>(); tmpUuid.add(metadataUuid); // MEF version 2 support multiple metadata record by file. if (withRelated) { // Adding children in MEF file // Creating request for services search Element childRequest = new Element("request"); childRequest.addContent(new Element("parentUuid").setText(metadataUuid)); childRequest.addContent(new Element("to").setText("1000")); // Get children to export - It could be better to use GetRelated service TODO Set<String> childs = MetadataUtils.getUuidsToExport(metadataUuid, request, childRequest); if (childs.size() != 0) { tmpUuid.addAll(childs); } // Creating request for services search Element servicesRequest = new Element(Jeeves.Elem.REQUEST); servicesRequest .addContent(new Element(org.fao.geonet.constants.Params.OPERATES_ON).setText(metadataUuid)); servicesRequest.addContent(new Element(org.fao.geonet.constants.Params.TYPE).setText("service")); // Get linked services for export Set<String> services = MetadataUtils.getUuidsToExport(metadataUuid, request, servicesRequest); if (services.size() != 0) { tmpUuid.addAll(services); } } Log.info(Geonet.MEF, "Building MEF2 file with " + tmpUuid.size() + " records."); file = MEFLib.doMEF2Export(context, tmpUuid, format.toString(), false, stylePath, withXLinksResolved, withXLinkAttribute, false, addSchemaLocation); } response.setHeader(HttpHeaders.CONTENT_DISPOSITION, String.format("inline; filename=\"%s.zip\"", metadata.getUuid())); response.setHeader(HttpHeaders.CONTENT_LENGTH, String.valueOf(Files.size(file))); response.setContentType(acceptHeader); FileUtils.copyFile(file.toFile(), response.getOutputStream()); }
From source file:org.springframework.cloud.netflix.zuul.filters.route.SimpleHostRoutingFilterTests.java
@Test public void contentLengthServlet30WithInvalidLongHeaderTest() throws IOException { setupContext();/*from w w w . java2s .c o m*/ MockMultipartHttpServletRequest request = getMockedReqest(-1L); request.addHeader(HttpHeaders.CONTENT_LENGTH, "InvalidLong"); contentLengthTest(-1L, getServlet30Filter(), request); }
From source file:org.springframework.cloud.netflix.zuul.filters.route.SimpleHostRoutingFilterTests.java
public void contentLengthServlet30WithHeaderTest(Long contentLength) throws IOException { setupContext();/*from www . jav a 2 s .com*/ MockMultipartHttpServletRequest request = getMockedReqest(contentLength); request.addHeader(HttpHeaders.CONTENT_LENGTH, contentLength); contentLengthTest(contentLength, getServlet30Filter(), request); }
From source file:org.springframework.cloud.netflix.zuul.filters.route.SimpleHostRoutingFilterTests.java
public void contentLengthTest(Long expectedContentLength, SimpleHostRoutingFilter filter, MockMultipartHttpServletRequest request) throws IOException { byte[] data = "poprqwueproqiwuerpoqweiurpo".getBytes(); MockMultipartFile file = new MockMultipartFile("test.zip", "test.zip", "application/zip", data); String boundary = "q1w2e3r4t5y6u7i8o9"; request.setContentType("multipart/form-data; boundary=" + boundary); request.setContent(createFileContent(data, boundary, "application/zip", "test.zip")); request.addFile(file);//w w w. j a v a 2 s .com request.setMethod("POST"); request.setParameter("variant", "php"); request.setParameter("os", "mac"); request.setParameter("version", "3.4"); request.setRequestURI("/app/echo"); MockHttpServletResponse response = new MockHttpServletResponse(); RequestContext.getCurrentContext().setRequest(request); RequestContext.getCurrentContext().setResponse(new MockHttpServletResponse()); URL url = new URL("http://localhost:" + this.port); RequestContext.getCurrentContext().set("routeHost", url); filter.run(); String responseString = IOUtils.toString( new GZIPInputStream(((CloseableHttpResponse) RequestContext.getCurrentContext().get("zuulResponse")) .getEntity().getContent())); assertTrue(!responseString.isEmpty()); if (expectedContentLength < 0) { assertThat(responseString, containsString("\"" + HttpHeaders.TRANSFER_ENCODING.toLowerCase() + "\":\"chunked\"")); assertThat(responseString, not(containsString(HttpHeaders.CONTENT_LENGTH.toLowerCase()))); } else { assertThat(responseString, containsString( "\"" + HttpHeaders.CONTENT_LENGTH.toLowerCase() + "\":\"" + expectedContentLength + "\"")); } }
From source file:org.springframework.vault.authentication.AwsIamAuthentication.java
private static Map<String, String> createIamRequestHeaders(AwsIamAuthenticationOptions options) { Map<String, String> headers = new LinkedHashMap<>(); headers.put(HttpHeaders.CONTENT_LENGTH, "" + REQUEST_BODY.length()); headers.put(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_FORM_URLENCODED_VALUE); if (StringUtils.hasText(options.getServerName())) { headers.put("X-Vault-AWS-IAM-Server-ID", options.getServerName()); }// w w w. j a v a 2 s.c o m return headers; }