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:guru.nidi.ramltester.UriTest.java

@RequestMapping(value = { "/raml/v1/{def}/{type}", "/v1/{def}/{type}", "/{def}/{type}",
        "/sub-raml/{a}/{b}/{c}/{d}" })
@ResponseBody/* ww w.j a v  a 2 s  .c  o m*/
public HttpEntity<String> test() {
    final HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.TEXT_HTML);
    return new HttpEntity<>(headers);
}

From source file:monkeys.web.BananasController.java

@RequestMapping(method = RequestMethod.DELETE, value = "/{id}")
public ResponseEntity<Void> deleteBanana(@PathVariable Long id) {
    bananaRepository.delete(id);/*from  w  w w .j  a va 2s  .  c  om*/
    HttpHeaders headers = new HttpHeaders();
    return new ResponseEntity<>(headers, HttpStatus.OK);
}

From source file:com.huoqiu.framework.rest.HttpComponentsClientHttpResponse.java

public HttpHeaders getHeaders() {
    if (this.headers == null) {
        this.headers = new HttpHeaders();
        for (Header header : this.httpResponse.getAllHeaders()) {
            headers.add(header.getName(), header.getValue());
        }//from  w  w  w  .java 2s  . co  m
    }
    return headers;
}

From source file:com.sra.biotech.submittool.persistence.client.SubmitExceptionHandler.java

@ExceptionHandler({ InvalidRequestException.class })
protected ResponseEntity<Object> handleInvalidRequest(RuntimeException e, WebRequest request) {
    InvalidRequestException ire = (InvalidRequestException) e;
    List<FieldErrorResource> fieldErrorResources = new ArrayList<>();

    List<FieldError> fieldErrors = ire.getErrors().getFieldErrors();
    for (FieldError fieldError : fieldErrors) {
        FieldErrorResource fieldErrorResource = new FieldErrorResource();
        fieldErrorResource.setResource(fieldError.getObjectName());
        fieldErrorResource.setField(fieldError.getField());
        fieldErrorResource.setCode(fieldError.getCode());
        fieldErrorResource.setMessage(fieldError.getDefaultMessage());
        fieldErrorResources.add(fieldErrorResource);
    }/* www .  ja  v  a 2s  . c o m*/

    ErrorResource error = new ErrorResource("InvalidRequest", ire.getMessage());
    error.setFieldErrors(fieldErrorResources);

    HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.APPLICATION_JSON);

    return handleExceptionInternal(e, error, headers, HttpStatus.UNPROCESSABLE_ENTITY, request);
}

From source file:edu.infsci2560.services.BlogsService.java

@RequestMapping(method = RequestMethod.POST, consumes = "application/json", produces = "application/json")
public ResponseEntity<Blog> create(@RequestBody Blog blog) {
    HttpHeaders headers = new HttpHeaders();
    return new ResponseEntity<>(repository.save(blog), headers, HttpStatus.OK);
}

From source file:net.eusashead.hateoas.conditional.interceptor.AsyncTestController.java

@RequestMapping(method = RequestMethod.HEAD)
public Callable<ResponseEntity<Void>> head() {
    return new Callable<ResponseEntity<Void>>() {

        @Override/*www  .  ja va  2  s.c  om*/
        public ResponseEntity<Void> call() throws Exception {
            HttpHeaders headers = new HttpHeaders();
            headers.setETag("\"123456\"");
            return new ResponseEntity<Void>(headers, HttpStatus.OK);
        }
    };

}

From source file:edu.infsci2560.services.FriendService.java

@RequestMapping(method = RequestMethod.POST, consumes = "application/json", produces = "application/json")
public ResponseEntity<Friend> create(@RequestBody Friend friends) {
    HttpHeaders headers = new HttpHeaders();
    return new ResponseEntity<>(repository.save(friends), headers, HttpStatus.OK);
}

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

@Test
public void testExcludes() throws Exception {
    HttpHeaders httpHeaders = new HttpHeaders();
    httpHeaders.setContentType(MediaType.APPLICATION_JSON);
    mockMvc.perform(get("/account/user/excludes/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("$.password").doesNotExist())
            .andExpect(jsonPath("$.dept").doesNotExist()).andExpect(jsonPath("$.roles").doesNotExist());

}

From source file:org.springsource.sinspctr.rest.SInspctrRootController.java

private ResponseEntity<String> getIndexHtml() {
    ResponseEntity<String> response;
    try {/*from  www  . ja v a2s.c  o m*/
        HttpHeaders headers = new HttpHeaders();
        headers.add("content-type", "text/html");
        response = new ResponseEntity<String>(
                FileCopyUtils.copyToString(
                        new FileReader(ResourceLocator.getClasspathRelativeFile("assets/index.html"))),
                headers, HttpStatus.OK);
        return response;
    } catch (Exception e) {
        return new ResponseEntity<String>(HttpStatus.NOT_FOUND);
    }
}

From source file:com.sentinel.web.controllers.RegistrationController.java

@RequestMapping(value = "/user", method = RequestMethod.POST)
@ResponseBody/*from  w  ww.j  av  a 2  s  .com*/
public ResponseEntity<Void> createUser(@RequestBody UserForm accountDto, UriComponentsBuilder ucBuilder) {

    LOG.debug("Registring new user");
    final User registered = createUserAccount(accountDto);
    if (registered == null) {
        return new ResponseEntity<Void>(HttpStatus.CONFLICT);
    }
    /* 
    if (userService.isUserExist(user)) {
    System.out.println("A User with name " + user.getUsername() + " already exist");
    }
    */
    userService.saveRegisteredUser(registered);
    HttpHeaders headers = new HttpHeaders();
    headers.setLocation(ucBuilder.path("/user/{id}").buildAndExpand(registered.getId()).toUri());//TODO
    return new ResponseEntity<Void>(headers, HttpStatus.CREATED);
}