Example usage for org.springframework.http HttpEntity HttpEntity

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

Introduction

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

Prototype

public HttpEntity(@Nullable T body, @Nullable MultiValueMap<String, String> headers) 

Source Link

Document

Create a new HttpEntity with the given body and headers.

Usage

From source file:org.openlmis.fulfillment.service.request.RequestHelper.java

/**
 * Creates an {@link HttpEntity} with the given payload as a body and headers.
 */// w  ww  .  j a v  a  2  s .  c o m
public static <E> HttpEntity<E> createEntity(E payload, RequestHeaders headers) {
    return new HttpEntity<>(payload, headers.toHeaders());
}

From source file:org.n52.restfulwpsproxy.wps.ProcessesClient.java

public ProcessOfferingsDocument getProcessDescription(String processId) {
    HttpEntity<?> requestEntity = new HttpEntity<Object>(null, headers);
    return restTemplate.exchange(new RequestUrlBuilder(DESCRIBE_PROCESS).identifier(processId).build(),
            HttpMethod.GET, requestEntity, ProcessOfferingsDocument.class).getBody();
}

From source file:org.n52.restfulwpsproxy.wps.CapabilitiesClient.java

public CapabilitiesDocument get() {
    HttpEntity<?> requestEntity = new HttpEntity<Object>(null, headers);

    ResponseEntity<CapabilitiesDocument> capabilities = restTemplate.exchange(
            new RequestUrlBuilder(REQUEST_GET_CAPABILITIES).build(), HttpMethod.GET, requestEntity,
            CapabilitiesDocument.class);

    return capabilities.getBody();
}

From source file:com.recursivechaos.clearent.service.ClearentService.java

public Transaction postTransaction(Transaction transaction) {
    RestTemplate restTemplate = new RestTemplate();
    ResponseEntity<Response> responseEntity;
    HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.APPLICATION_JSON);
    headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
    headers.set("api-key", gatewayProperties.getKey());
    HttpEntity<String> request = new HttpEntity<>(transaction.toString(), headers);
    try {/*w w  w. j  av  a 2  s. com*/
        responseEntity = restTemplate.postForEntity(gatewayProperties.getUrl() + "/transactions", request,
                Response.class);
    } catch (HttpClientErrorException he) {
        logger.error("Gateway Request Failed: {}", he.getLocalizedMessage());
        logger.error(he.getResponseBodyAsString());
        throw new GatewayException(he.getLocalizedMessage());
    }
    assert responseEntity != null;
    return responseEntity.getBody().getPayload().getTransaction();
}

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

@Test(enabled = true)
public void testDemo() {
    String s = new String();
    HttpEntity<String> requestEntity = new HttpEntity<>(s, getContentType());
    System.out.println();/*from  ww  w  . j av  a 2 s . c o  m*/
    /*ResponseEntity<String> responseEntity = restTemplate.exchange(URL + "demo",
        HttpMethod.GET,
        requestEntity,
        String.class);
            
    System.out.println(" THE RESPONSE BODY " + responseEntity.getBody());
    */
}

From source file:org.trustedanalytics.servicebroker.gearpump.service.externals.helpers.CfCaller.java

public HttpEntity<String> createJsonRequest(String body, HttpHeaders headers) {
    return new HttpEntity<String>(body, headers == null ? createJsonHeaders() : headers);
}

From source file:com.bradley.musicapp.test.restapi.TrackRestControllerTest.java

@Test
public void testCreate() {
    Track track = new Track.Builder().trackName("yolo").trackLength("03:45").build();
    HttpEntity<Track> requestEntity = new HttpEntity<>(track, getContentType());
    //        Make the HTTP POST request, marshaling the request to JSON, and the response to a String
    ResponseEntity<Track> responseEntity = restTemplate.exchange(URL + "api/track/create", HttpMethod.POST,
            requestEntity, Track.class);
    System.out.println(" THE RESPONSE BODY " + responseEntity.getBody());
    System.out.println(" THE RESPONSE STATUS CODE " + responseEntity.getStatusCode());
    System.out.println(" THE RESPONSE IS HEADERS " + responseEntity.getHeaders());
    System.out.println("id = " + responseEntity.getBody().getId());
    id = responseEntity.getBody().getId();
    Assert.assertEquals(responseEntity.getStatusCode(), HttpStatus.OK);

}

From source file:org.n52.restfulwpsproxy.wps.ExecuteClient.java

public StatusInfoDocument asyncExecute(String processId, ExecuteDocument executeDocument)
        throws URISyntaxException {
    HttpEntity<ExecuteDocument> requestEntity = new HttpEntity<ExecuteDocument>(executeDocument, headers);
    return restTemplate.exchange(baseUrl, HttpMethod.POST, requestEntity, StatusInfoDocument.class).getBody();
}

From source file:org.openbaton.nfvo.vnfm_reg.impl.sender.RestVnfmSender.java

private String get(String path, String url) {
    HttpEntity<String> requestEntity = new HttpEntity<>("", headers);
    ResponseEntity<String> responseEntity = rest.exchange(url + path, HttpMethod.GET, requestEntity,
            String.class);
    this.setStatus(responseEntity.getStatusCode());
    return responseEntity.getBody();
}

From source file:com.mycompany.CPUTAuction.restapi.BidRestControllerTest.java

public void tesCreate() {

    Bid bid = new Bid.Builder(1001).amount(300).build();
    //repo.save(b);
    //id = b.getId();

    HttpEntity<Bid> requestEntity = new HttpEntity<>(bid, getContentType());
    //        Make the HTTP POST request, marshaling the request to JSON, and the response to a String
    ResponseEntity<String> responseEntity = restTemplate.exchange(URL + "api/bid/create", HttpMethod.POST,
            requestEntity, String.class);
    System.out.println(" THE RESPONSE BODY " + responseEntity.getBody());
    System.out.println(" THE RESPONSE STATUS CODE " + responseEntity.getStatusCode());
    System.out.println(" THE RESPONSE IS HEADERS " + responseEntity.getHeaders());
    Assert.assertEquals(responseEntity.getStatusCode(), HttpStatus.OK);

}