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.trustedanalytics.h2oscoringengine.publisher.http.HttpCommunicationTest.java

private HttpEntity<String> createExpectedPostRequest(String body) {
    HttpHeaders headers = new HttpHeaders();
    headers.add("Accept", "application/json");
    headers.add("Content-type", "application/x-www-form-urlencoded");

    return new HttpEntity<>(body, headers);
}

From source file:org.openbaton.nse.beans.connectivitymanageragent.ConnectivityManagerRequestor.java

public QosAdd setQoS(QosAdd qosRequest) {

    logger.debug("SENDING REQUEST FOR " + mapper.toJson(qosRequest, QosAdd.class));
    String url = configuration.getBaseUrl() + "/qoses";
    HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.APPLICATION_JSON);
    HttpEntity<String> setEntity = new HttpEntity<>(mapper.toJson(qosRequest, QosAdd.class), headers);
    logger.debug("SENDING QOS " + mapper.toJson(qosRequest, QosAdd.class));
    ResponseEntity<String> insert = template.exchange(url, HttpMethod.POST, setEntity, String.class);

    logger.debug("Setting of QoS has produced http status:" + insert.getStatusCode() + " with body: "
            + insert.getBody());/* w  w  w  .  j a  v a 2  s .  c om*/

    if (!insert.getStatusCode().is2xxSuccessful()) {
        return null;
    } else {
        QosAdd result = mapper.fromJson(insert.getBody(), QosAdd.class);
        logger.debug(
                "RESULT IS " + insert.getStatusCode() + " with body " + mapper.toJson(result, QosAdd.class));
        return result;
    }
}

From source file:org.jrb.commons.web.ResponseUtils.java

public <R extends Response> ResponseEntity<R> finalize(final R response, final HttpStatus status) {
    return finalize(response, status, new HttpHeaders());
}

From source file:org.shaigor.rest.retro.service.security.IntegrationTest.java

/**
 * Access resource for given URI and user
 * @param uri resource URI to access/*from  ww w .ja v a 2s  . c  o m*/
 * @param pwd the password of the user
 * @throws IOException 
 */
protected void testResourceAccess(URIInfo testUri) throws IOException {
    HttpHeaders headers = new HttpHeaders();
    ResponseEntity<String> response = helper.getForResponse(testUri.getUri(), headers);

    assertEquals(HttpStatus.OK, response.getStatusCode());
    assertEquals("Rigth method should be called.", testUri.getResponse(), response.getBody());
}

From source file:org.openbaton.marketplace.api.exceptions.GlobalExceptionHandler.java

@ExceptionHandler({ InterruptedException.class, IOException.class })
@ResponseStatus(value = HttpStatus.NOT_FOUND)
protected ResponseEntity<Object> handleException(HttpServletRequest req, Exception e) {
    log.error("Exception with message " + e.getMessage() + " was thrown");
    HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.APPLICATION_JSON);
    Map body = new HashMap<>();
    body.put("error", "Upload Error");
    body.put("exception", e.getClass().toString());
    body.put("message", e.getMessage());
    body.put("path", req.getRequestURI());
    body.put("status", HttpStatus.I_AM_A_TEAPOT.value());
    body.put("timestamp", new Date().getTime());
    ResponseEntity responseEntity = new ResponseEntity(body, headers, HttpStatus.I_AM_A_TEAPOT);
    return responseEntity;
}

From source file:com.embedler.moon.graphql.boot.sample.test.GenericTodoSchemaParserTest.java

@Test
public void restViewerByIdTest() throws IOException {
    HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.APPLICATION_JSON_UTF8);

    GraphQLServerRequest qlQuery = new GraphQLServerRequest("{viewer{ id }}");

    HttpEntity<GraphQLServerRequest> httpEntity = new HttpEntity<>(qlQuery, headers);
    ResponseEntity<GraphQLServerResult> responseEntity = restTemplate.exchange(
            "http://localhost:" + port + "/graphql", HttpMethod.POST, httpEntity, GraphQLServerResult.class);

    GraphQLServerResult result = responseEntity.getBody();
    Assert.assertTrue(CollectionUtils.isEmpty(result.getErrors()));
    Assert.assertFalse(CollectionUtils.isEmpty(result.getData()));
    LOGGER.info(objectMapper.writeValueAsString(result.getData()));
}

From source file:de.escalon.hypermedia.sample.event.ReviewController.java

@Action("ReviewAction")
@RequestMapping(value = "/events/{eventId}", method = RequestMethod.POST)
public @ResponseBody ResponseEntity<Void> addReview(@PathVariable int eventId, @RequestBody Review review) {
    Assert.notNull(review);/*from  w w w . j  ava2s  . c  o  m*/
    Assert.notNull(review.getReviewRating());
    Assert.notNull(review.getReviewRating().getRatingValue());
    ResponseEntity<Void> responseEntity;
    try {
        eventBackend.addReview(eventId, review.getReviewBody(), review.getReviewRating());
        final HttpHeaders headers = new HttpHeaders();
        headers.setLocation(AffordanceBuilder
                .linkTo(AffordanceBuilder.methodOn(this.getClass()).getReviews(eventId)).toUri());
        responseEntity = new ResponseEntity<Void>(headers, HttpStatus.CREATED);
    } catch (NoSuchElementException ex) {
        responseEntity = new ResponseEntity<Void>(HttpStatus.NOT_FOUND);
    }
    return responseEntity;
}

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

@Override
public void getLeaveStatement(String emplid, String docId, StatementType type, ProxyResponse proxyResponse) {
    final HttpHeaders httpHeaders = new HttpHeaders();
    httpHeaders.set("HRID", emplid);
    this.restOperations.proxyRequest(proxyResponse, this.statementUrl, HttpMethod.GET, httpHeaders, docId,
            type.getKey());/*from w  w  w.j a v a 2 s  .  c om*/
}

From source file:za.ac.cput.project.universalhardwarestorev2.api.ItemApi.java

@RequestMapping(value = "/item/create", method = RequestMethod.POST)
public ResponseEntity<Void> createItem(@RequestBody Item item, UriComponentsBuilder ucBuilder) {
    System.out.println("Creating Item " + item.getName());

    //     USE THIS IF YOU WANT TO CHECK UNIQUE OBJECT
    //      if (ItemService.isItemExist(Item)) {
    //            System.out.println("A Item with name " + Item.getName() + " already exist");
    //            return new ResponseEntity<Void>(HttpStatus.CONFLICT);
    //        }//  w w  w  .java  2  s  .  com

    service.save(item);

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

From source file:com.example.notes.NotesController.java

@ResponseStatus(HttpStatus.CREATED)
@RequestMapping(method = RequestMethod.POST)
HttpHeaders create(@RequestBody NoteInput noteInput) {
    Note note = new Note();
    note.setTitle(noteInput.getTitle());
    note.setBody(noteInput.getBody());//from w w w.j  a v a2 s . c o  m
    note.setTags(getTags(noteInput.getTagUris()));

    this.noteRepository.save(note);

    HttpHeaders httpHeaders = new HttpHeaders();
    httpHeaders.setLocation(linkTo(NotesController.class).slash(note.getId()).toUri());

    return httpHeaders;
}