List of usage examples for org.springframework.http HttpHeaders HttpHeaders
public HttpHeaders()
From source file:org.springsource.sinspctr.rest.SInspctrController.java
@ResponseBody @RequestMapping(value = "/**/*.xml", method = RequestMethod.GET) public ResponseEntity<String> findConfig(HttpServletRequest request) { ResponseEntity<String> response; try {/*from ww w .j a v a 2s.co m*/ String servletPath = request.getServletPath(); if (servletPath.startsWith("/sinspctr/configs")) { servletPath = servletPath.substring("/sinspctr/configs".length(), servletPath.length()); } File siConfigFile = ResourceLocator.getClasspathRelativeFile(servletPath); HttpHeaders headers = new HttpHeaders(); headers.add("content-type", "application/xml"); response = new ResponseEntity<String>(FileCopyUtils.copyToString(new FileReader(siConfigFile)), headers, HttpStatus.OK); return response; } catch (Exception e) { return new ResponseEntity<String>(HttpStatus.NOT_FOUND); } }
From source file:com.kurento.kmf.jsonrpcconnector.client.JsonRpcClientHttp.java
public JsonRpcClientHttp(String url) { this(url, new HttpHeaders()); }
From source file:com.github.ljtfreitas.restify.http.spring.client.call.exec.ResponseEntityConverter.java
private HttpHeaders headersOf(Headers headers) { HttpHeaders httpHeaders = new HttpHeaders(); headers.all().forEach(h -> httpHeaders.add(h.name(), h.value())); return httpHeaders; }
From source file:com.marklogic.mgmt.admin.AdminManager.java
public void init(String licenseKey, String licensee) { final URI uri = adminConfig.buildUri("/admin/v1/init"); String json = null;/*from w w w.ja va2s .c o m*/ if (licenseKey != null && licensee != null) { json = format("{\"license-key\":\"%s\", \"licensee\":\"%s\"}", licenseKey, licensee); } else { json = "{}"; } final String payload = json; logger.info("Initializing MarkLogic at: " + uri); invokeActionRequiringRestart(new ActionRequiringRestart() { @Override public boolean execute() { HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_JSON); HttpEntity<String> entity = new HttpEntity<String>(payload, headers); try { ResponseEntity<String> response = restTemplate.exchange(uri, HttpMethod.POST, entity, String.class); logger.info("Initialization response: " + response); // According to http://docs.marklogic.com/REST/POST/admin/v1/init, a 202 is sent back in the event a // restart is needed. A 400 or 401 will be thrown as an error by RestTemplate. return HttpStatus.ACCEPTED.equals(response.getStatusCode()); } catch (HttpClientErrorException hcee) { String body = hcee.getResponseBodyAsString(); if (logger.isTraceEnabled()) { logger.trace("Response body: " + body); } if (body != null && body.contains("MANAGE-ALREADYINIT")) { logger.info("MarkLogic has already been initialized"); return false; } else { logger.error("Caught error, response body: " + body); throw hcee; } } } }); }
From source file:com.abixen.platform.core.controller.common.ImageLibraryController.java
@RequestMapping(value = "/{fileName}/", method = RequestMethod.GET) public ResponseEntity<byte[]> getImage(@PathVariable String fileName) throws IOException { log.debug("fileName: " + fileName); InputStream in = new FileInputStream(platformResourceConfigurationProperties.getImageLibraryDirectory() + "/layout-miniature/" + fileName); byte[] b = IOUtils.toByteArray(in); in.close();/*from w w w. j ava2 s . c o m*/ final HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.IMAGE_PNG); return new ResponseEntity<byte[]>(b, headers, HttpStatus.CREATED); }
From source file:org.nebula.service.exception.NebulaExceptionHandler.java
@ExceptionHandler({ Exception.class }) protected ResponseEntity<Object> exceptions(Exception ex, WebRequest request) { String bodyOfResponse = "Internal Server Error"; ResponseEntity<Object> response = handleExceptionInternal(null, bodyOfResponse, new HttpHeaders(), HttpStatus.INTERNAL_SERVER_ERROR, request); logger.error("Exception:" + response.toString(), ex); return response; }
From source file:cz.muni.fi.mushroomhunter.restclient.LocationDeleteSwingWorker.java
@Override protected Integer doInBackground() throws Exception { int selectedRow = restClient.getTblLocation().getSelectedRow(); RestTemplate restTemplate = new RestTemplate(); String plainCreds = RestClient.USER_NAME + ":" + RestClient.PASSWORD; byte[] plainCredsBytes = plainCreds.getBytes(); byte[] base64CredsBytes = Base64.encodeBase64(plainCredsBytes); String base64Creds = new String(base64CredsBytes); HttpHeaders headers = new HttpHeaders(); headers.add("Authorization", "Basic " + base64Creds); HttpEntity<String> request = new HttpEntity<>(headers); restTemplate.setRequestFactory(new HttpComponentsClientHttpRequestFactory() { @Override//from ww w . j a v a2 s. c o m protected HttpUriRequest createHttpUriRequest(HttpMethod httpMethod, URI uri) { if (HttpMethod.DELETE == httpMethod) { return new HttpEntityEnclosingDeleteRequest(uri); } return super.createHttpUriRequest(httpMethod, uri); } }); restTemplate.exchange( RestClient.SERVER_URL + "pa165/rest/location/" + RestClient.getLocationIDs().get(selectedRow), HttpMethod.DELETE, request, LocationDto.class); RestClient.getLocationIDs().remove(selectedRow); return selectedRow; }
From source file:io.github.restdocsext.jersey.operation.preprocess.BinaryPartPlaceholderOperationPreprocessorTest.java
@Test public void replace_binary_multipart_content_with_placeholder() { OperationRequestPart part1 = this.partFactory.create("field1", "file1.png", "BinaryContent".getBytes(), new HttpHeaders()); OperationRequestPart part2 = this.partFactory.create("field2", null, "TextContent".getBytes(), new HttpHeaders()); final OperationRequest request = this.requestFactory.create(URI.create("http://localhost"), HttpMethod.POST, null, new HttpHeaders(), new Parameters(), Arrays.asList(part1, part2)); this.preprocessor.field("field1", "<<placeholder>>"); final OperationRequest preprocessed = this.preprocessor.preprocess(request); final Collection<OperationRequestPart> parts = preprocessed.getParts(); assertThat(hasPart(parts, "field1", "<<placeholder>>"), is(true)); assertThat(hasPart(parts, "field2", "TextContent"), is(true)); }
From source file:au.id.hazelwood.sos.web.controller.framework.GlobalExceptionHandler.java
@ExceptionHandler(value = IllegalArgumentException.class) public ResponseEntity<Object> handleIllegalArgument(Exception ex, WebRequest request) { return handleExceptionInternal(ex, null, new HttpHeaders(), HttpStatus.BAD_REQUEST, request); }
From source file:com.github.dactiv.fear.service.web.SystemCommonController.java
/** * ? freemarker ?/*w ww. j a v a2 s . c o m*/ * * @param name ??? * * @return ? */ @RequestMapping("get-ftl-template") public ResponseEntity<byte[]> getFtlTemplate(@RequestParam String name, HttpServletRequest request) throws IOException { HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.TEXT_PLAIN); String path = request.getSession().getServletContext().getRealPath("") + ftlTemplatePath + name + ".ftl"; byte[] bytes = FileUtils.readFileToByteArray(new File(path)); return new ResponseEntity<>(bytes, headers, HttpStatus.OK); }