Example usage for org.springframework.http HttpHeaders HttpHeaders

List of usage examples for org.springframework.http HttpHeaders HttpHeaders

Introduction

In this page you can find the example usage for org.springframework.http HttpHeaders HttpHeaders.

Prototype

public HttpHeaders() 

Source Link

Document

Construct a new, empty instance of the HttpHeaders object.

Usage

From source file:org.busko.routemanager.web.admin.community.RouteSubmissionController.java

@RequestMapping(params = "view", value = "/{id}", method = RequestMethod.GET)
public ResponseEntity<byte[]> view(@PathVariable("id") Long id, Model uiModel) throws Exception {
    RouteSubmission routeSubmission = RouteSubmission.findRouteSubmission(id);

    HttpHeaders responseHeaders = new HttpHeaders();
    responseHeaders.set("Content-Disposition", "attachment;filename=" + routeSubmission.getUsername() + ".xml");
    responseHeaders.set("Content-Length", Integer.toString(routeSubmission.getFileContent().length));
    //        responseHeaders.set("Content-Type", "text/plain; charset=UTF-8");
    responseHeaders.set("Content-Type", "text/xml");
    return new ResponseEntity<byte[]>(routeSubmission.getFileContent(), responseHeaders, HttpStatus.OK);
}

From source file:org.makersoft.mvc.unit.FormatHandlerMethodReturnValueHandlerTests.java

@Test
public void testExcludeEntityAttributes() throws Exception {
    HttpHeaders httpHeaders = new HttpHeaders();
    httpHeaders.setContentType(MediaType.APPLICATION_JSON);
    mockMvc.perform(get("/account/user//exclude-entity-attributes/1").accept(MediaType.APPLICATION_JSON)
            .headers(httpHeaders)).andDo(print()).andExpect(status().isOk())
            .andExpect(content().contentType(MediaType.APPLICATION_JSON)).andExpect(content().encoding("UTF-8"))
            .andExpect(jsonPath("$.id").value(1)).andExpect(jsonPath("$.dept.users").doesNotExist())
            .andExpect(jsonPath("$.roles.users").doesNotExist());

}

From source file:org.greencheek.spring.rest.SSLCachingHttpComponentsClientHttpResponse.java

public HttpHeaders getHeaders() {
    if (this.headers == null) {
        this.headers = new HttpHeaders();
        for (Header header : this.httpResponse.getAllHeaders()) {
            this.headers.add(header.getName(), header.getValue());
        }//from   w  ww  .  j  a v a 2 s. c  om
    }
    return this.headers;
}

From source file:biz.c24.io.spring.http.C24HttpMessageConverterUnitTests.java

@Test
public void readsXmlCorrectly() throws IOException {

    when(inputMessage.getBody()).thenReturn(new ByteArrayInputStream(TestConstants.SAMPLE_XML.getBytes()));
    HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.APPLICATION_XML);
    when(inputMessage.getHeaders()).thenReturn(headers);

    CustomerLocal result = (CustomerLocal) converter.read(CustomerLocal.class, inputMessage);
    assertThat(result, is(notNullValue()));
    assertThat(result.getFirstname(), is("Firstname"));
}

From source file:edu.wisc.cypress.dao.levstmt.RestLeaveStatementDao.java

@Cacheable(cacheName = "leaveStatement", exceptionCacheName = "cypressUnknownExceptionCache")
@Override// w  w  w.ja va2s .  com
public Collection<SummarizedLeaveStatement> getLeaveStatements(String emplid) {
    final HttpHeaders httpHeaders = new HttpHeaders();
    httpHeaders.set("HRID", emplid);
    final XmlLeaveStatements leaveStatements = this.restOperations.getForObject(this.statementsUrl,
            XmlLeaveStatements.class, httpHeaders, emplid);
    return this.summarizeLeaveStatements(leaveStatements);
}

From source file:com.trafficfine.controller.TrafficFineController.java

/**
 * /*from ww w  . j  a v  a  2 s  .  co  m*/
 * @param infraction
 * @param ucBuilder
 * @return
 */
@RequestMapping(value = "/api/infracao/", method = RequestMethod.POST)
public ResponseEntity<Void> createInfraction(@RequestBody Infraction infraction,
        UriComponentsBuilder ucBuilder) {
    logger.info("Creating infraction: " + infraction.getPlaca());

    if (trafficFineService.isInfractionExist(infraction)) {
        logger.info("A infraction with license plate " + infraction.getPlaca() + " already exist");
        return new ResponseEntity<Void>(HttpStatus.CONFLICT);
    }
    trafficFineService.saveInfraction(infraction);

    HttpHeaders header = new HttpHeaders();
    header.setLocation(ucBuilder.path("/").buildAndExpand(infraction.getId()).toUri());
    return new ResponseEntity<Void>(header, HttpStatus.CREATED);
}

From source file:org.dineth.shooter.app.view.ImageController.java

@RequestMapping(value = "/get/{name}.{ext}")
public ResponseEntity<byte[]> getImage(@PathVariable("name") String name, @PathVariable("ext") String ext) {

    Resource resource = context.getResource("file:/home/dewmal/files/" + name + "." + ext);
    System.out.println(resource.getFilename());
    final HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.IMAGE_PNG);
    try {/*w w  w  .jav  a2 s .  co m*/
        return new ResponseEntity<>(IOUtils.toByteArray(resource.getInputStream()), headers,
                HttpStatus.CREATED);
    } catch (IOException ex) {
        Logger.getLogger(ImageController.class.getName()).log(Level.SEVERE, null, ex);
    }
    return null;
}

From source file:org.osiam.resources.exceptions.OsiamExceptionHandler.java

@ExceptionHandler(value = { Exception.class })
protected ResponseEntity<Object> handleConflict(Exception ex, WebRequest request) {
    LOGGER.log(Level.WARNING, "An exception occurred", ex);
    HttpStatus status = setStatus(ex);//from  ww w  .jav  a 2s .  c o m
    JsonErrorResult error = new JsonErrorResult(status.name(), constructMessage(ex.getMessage()));
    return handleExceptionInternal(ex, error, new HttpHeaders(), status, request);
}

From source file:cz.jirutka.spring.exhandler.handlers.AbstractRestExceptionHandler.java

protected HttpHeaders createHeaders(E ex, HttpServletRequest req) {
    return new HttpHeaders();
}

From source file:org.ala.spatial.web.services.LayerDistancesWSController.java

@RequestMapping(value = "/layers/analysis/inter_layer_association.csv", method = RequestMethod.GET)
public ResponseEntity<String> CSV(HttpServletRequest req) {
    String csv = makeCSV("displayname");
    HttpHeaders responseHeaders = new HttpHeaders();
    responseHeaders.setContentType(MediaType.parseMediaType("text/csv"));
    return new ResponseEntity<String>(csv, responseHeaders, HttpStatus.CREATED);
}