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:io.github.restdocsext.jersey.operation.preprocess.BinaryPartPlaceholderOperationPreprocessorTest.java

@Test
public void replace_binary_multipart_content_with_default_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");
    final OperationRequest preprocessed = this.preprocessor.preprocess(request);
    final Collection<OperationRequestPart> parts = preprocessed.getParts();
    assertThat(hasPart(parts, "field1", "<<binary data>>"), is(true));
    assertThat(hasPart(parts, "field2", "TextContent"), is(true));
}

From source file:org.openschedule.api.impl.EventTemplate.java

public void addEventComment(String shortName, Comment comment) {
    Log.v(TAG, "addEventComment : enter");

    HttpHeaders requestHeaders = new HttpHeaders();
    requestHeaders.setContentType(new MediaType("application", "json"));

    HttpEntity<Comment> requestEntity = new HttpEntity<Comment>(comment, requestHeaders);

    restTemplate.exchange("public/" + shortName + "/comments", HttpMethod.POST, requestEntity, String.class,
            shortName).getBody();/* w w w . j a  v a2  s  . c  o  m*/

    Log.v(TAG, "addEventComment : exit");
}

From source file:za.co.dwarfsun.jcmanager.test.restapi.JcUserRestControllerTest.java

private HttpHeaders getContentType() {
    HttpHeaders requestHeaders = new HttpHeaders();
    requestHeaders.setContentType(MediaType.TEXT_PLAIN);
    return requestHeaders;
}

From source file:com._8x8.presentation.restController.UserRestController.java

@RequestMapping(value = "/user/", method = RequestMethod.POST)
public ResponseEntity<Void> createUser(@RequestBody User user, UriComponentsBuilder ucBuilder) {

    System.out.println("Creating Username: " + user.getUsername());

    if (_userService.isUserExist(user)) {
        System.out.println("A User with name " + user.getUsername() + " already exist");
        return new ResponseEntity<Void>(HttpStatus.CONFLICT);
    }// w  ww  .  j a va 2s  .c  om

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

From source file:sample.RestTests.java

@Test
public void authenticateWithXAuthTokenWorks() {
    String auth = getAuth("user", "password");
    HttpHeaders headers = getHttpHeaders();
    headers.set(AUTHORIZATION, BASIC + auth);
    ResponseEntity<User> entity = getForUser(this.baseUrl + "/", headers, User.class);

    String token = entity.getHeaders().getFirst(X_AUTH_TOKEN);

    HttpHeaders authTokenHeader = new HttpHeaders();
    authTokenHeader.setAccept(Arrays.asList(MediaType.APPLICATION_JSON));
    authTokenHeader.set(X_AUTH_TOKEN, token);
    ResponseEntity<User> authTokenResponse = getForUser(this.baseUrl + "/", authTokenHeader, User.class);
    assertThat(authTokenResponse.getStatusCode()).isEqualTo(HttpStatus.OK);
    assertThat(authTokenResponse.getBody().getUsername()).isEqualTo("user");
}

From source file:com.github.hateoas.forms.spring.sample.test.ReviewController.java

@Action("ReviewAction")
@RequestMapping(value = "/events/{eventId}", method = RequestMethod.POST, params = { "review", "rating" })
public @ResponseBody ResponseEntity<Void> addReview(@PathVariable int eventId, @RequestParam String review,
        @RequestParam int rating) {
    final HttpHeaders headers = new HttpHeaders();
    headers.setLocation(AffordanceBuilder
            .linkTo(AffordanceBuilder.methodOn(this.getClass()).getReviews(eventId, null)).toUri());
    return new ResponseEntity(headers, HttpStatus.CREATED);
}

From source file:com.sra.biotech.submittool.persistence.service.SubmissionServiceImpl.java

@Override
public List<Submission> findAllSubmission() {
    HttpHeaders headers = new HttpHeaders();
    headers.add("Accept", MediaType.APPLICATION_JSON_VALUE);
    HttpEntity<String> request = new HttpEntity<String>(headers);
    ResponseEntity<String> response = restTemplate.exchange(getSubmissionUrlTemplate(), HttpMethod.GET, request,
            String.class);

    String responseBody = response.getBody();
    try {/*from  w w w . j av  a2  s  . co m*/
        if (RestUtil.isError(response.getStatusCode())) {
            ErrorResource error = objectMapper.readValue(responseBody, ErrorResource.class);
            throw new RestClientException("[" + error.getCode() + "] " + error.getMessage());
        } else {
            SubmissionResources resources = objectMapper.readValue(responseBody, SubmissionResources.class);
            //  SubmissionResources resources = restTemplate.getForObject(getSubmissionUrlTemplate(), SubmissionResources.class);
            if (resources == null || CollectionUtils.isEmpty(resources.getContent())) {
                return Collections.emptyList();
            }

            Link listSelfLink = resources.getLink(Link.REL_SELF);
            Collection<SubmissionResource> content = resources.getContent();

            if (!content.isEmpty()) {
                SubmissionResource firstSubmissionResource = content.iterator().next();
                Link linkToFirstResource = firstSubmissionResource.getLink(Link.REL_SELF);
                System.out.println("href = " + linkToFirstResource.getHref());
                System.out.println("rel = " + linkToFirstResource.getRel());
            }

            return resources.unwrap();
            // return resources;
        }
    } catch (IOException e) {
        throw new RuntimeException(e);
    }

}

From source file:edu.wisc.cypress.dao.benstmt.RestBenefitStatementDao.java

@Override
public void getBenefitStatement(String emplid, int year, String docId, String mode,
        ProxyResponse proxyResponse) {//from  w  ww  .  j a  v  a 2 s.c  om
    final HttpHeaders httpHeaders = new HttpHeaders();
    httpHeaders.set("HRID", emplid);

    final String yearStr = Integer.toString(year);
    final String yearCode;
    if (yearStr.length() > 2) {
        yearCode = yearStr.substring(2);
    } else if (yearStr.length() < 2) {
        yearCode = StringUtils.leftPad(yearStr, 2, '0');
    } else {
        yearCode = yearStr;
    }
    this.restOperations.proxyRequest(proxyResponse, this.statementUrl, HttpMethod.GET, httpHeaders, yearCode,
            docId, mode);
}

From source file:org.cloudfoundry.caldecott.client.HttpTunnel.java

private void openTunnel() {
    String initMsg = "{\"host\":\"" + host + "\",\"port\":" + port + "}";
    if (logger.isDebugEnabled()) {
        logger.debug("Initializing tunnel: " + initMsg);
    }//from w w  w.j  a  v  a 2 s  .  co  m
    HttpHeaders requestHeaders = new HttpHeaders();
    requestHeaders.set("Auth-Token", auth);
    requestHeaders.set("Content-Length", initMsg.length() + "");
    HttpEntity<String> requestEntity = new HttpEntity<String>(initMsg, requestHeaders);
    String jsonResponse;
    try {
        jsonResponse = restOperations.postForObject(url + "/tunnels", requestEntity, String.class);
    } catch (RuntimeException e) {
        logger.error("Fatal error while opening tunnel: " + e.getMessage());
        close();
        throw e;
    }
    try {
        this.tunnelInfo = TunnelHelper.convertJsonToMap(jsonResponse);
    } catch (IOException ignore) {
        this.tunnelInfo = new HashMap<String, String>();
    }
}