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:com.ge.predix.test.utils.PolicyHelper.java

public String setTestPolicy(final RestTemplate acs, final HttpHeaders headers, final String endpoint,
        final String policyFile) throws JsonParseException, JsonMappingException, IOException {

    PolicySet policySet = new ObjectMapper().readValue(new File(policyFile), PolicySet.class);
    String policyName = policySet.getName();
    acs.put(endpoint + ACS_POLICY_SET_API_PATH + policyName, new HttpEntity<>(policySet, headers));
    return policyName;
}

From source file:org.jasig.portlet.notice.service.ssp.SSPApiRequest.java

public HttpEntity<?> getRequestEntity() {
    return new HttpEntity<>(postData, headers);
}

From source file:de.zib.gndms.gndmc.gorfx.GORFXClient.java

@SuppressWarnings("unchecked")
public final ResponseEntity<Specifier<Facets>> createTaskFlow(final String type, final Order order,
        final String dn, final String wid, MultiValueMap<String, String> context) {

    GNDMSResponseHeader requestHeaders = new GNDMSResponseHeader();
    if (dn != null) {
        requestHeaders.setDN(dn);/*from   www  .  j  av  a2 s  .co  m*/
    }
    if (wid != null) {
        requestHeaders.setWId(wid);
    }

    requestHeaders.putAll(context);
    HttpEntity<Order> requestEntity = new HttpEntity<Order>(order, requestHeaders);

    RestOperations restTemplate = getRestTemplate();
    if (null == restTemplate) {
        throw new IllegalStateException("No RestTemplate set in GORFXClient.");
    }

    return (ResponseEntity<Specifier<Facets>>) (Object) restTemplate
            .exchange(getServiceURL() + "/gorfx/_" + type, HttpMethod.POST, requestEntity, Specifier.class);
}

From source file:eu.falcon.semantic.client.DenaClient.java

public static String getClassSubclasses(String classURI) {

    final String uri = "http://falconsemanticmanager.euprojects.net/api/v1/ontology/class/subclasses";
    //final String uri = "http://localhost:8090/api/v1/ontology/class/subclasses";

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

    RestTemplate restTemplate = new RestTemplate();

    HttpEntity<String> entity = new HttpEntity<>(classURI, headers);

    String result = restTemplate.postForObject(uri, entity, String.class);

    return result;
}

From source file:com.logaritex.hadoop.configuration.manager.SimpleHttpService.java

@Override
public <R> R delete(String url, Object request, Class<R> responseType, Object... uriVariables) {

    R response = restTemplate.exchange(baseUrl + url, HttpMethod.DELETE,
            new HttpEntity<Object>(request, httpHeaders), responseType, uriVariables).getBody();

    return response;
}

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  va 2s .  c o m*/

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

From source file:com.garyclayburg.UserRestSmokeTest.java

@Test
public void testHalJsonApache() throws Exception {
    RestTemplate rest = new RestTemplate(new HttpComponentsClientHttpRequestFactory());
    SimpleUser user1 = new SimpleUser();
    user1.setFirstname("Tommy");
    user1.setLastname("Deleteme");
    user1.setId("112" + (int) (Math.floor(Math.random() * 10000)));

    HttpHeaders requestHeaders = new HttpHeaders();
    requestHeaders.set("Content-Type", "application/hal+json");
    //        HttpEntity<?> requestEntity = new HttpEntity(requestHeaders);
    HttpEntity<?> requestEntity = new HttpEntity(user1, requestHeaders);

    ResponseEntity<SimpleUser> simpleUserResponseEntity = rest.exchange(
            "http://" + endpoint + "/audited-users/auditedsave", HttpMethod.POST, requestEntity,
            SimpleUser.class);

    //        ResponseEntity<SimpleUser> userResponseEntity =
    //            rest.postForEntity("http://" + endpoint + "/audited-users/auditedsave",user1,SimpleUser.class);
    log.info("got a response");
    MatcherAssertionErrors.assertThat(simpleUserResponseEntity.getStatusCode(),
            Matchers.equalTo(HttpStatus.OK));

}

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 ava2 s  .  com

    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:com.arvato.thoroughly.util.RestTemplateUtil.java

/**
 * @param url/*from   w  w w  . ja va2s .  c om*/
 * @param content
 *           It must be json format data
 * @return Results <br>
 *         code : http status <br>
 *         responseBody : http response body
 */
public JsonObject post(String url, String content) throws TmallAppException {
    LOGGER.trace("Post url:" + url);
    HttpEntity<String> request = new HttpEntity<String>(content, createHeaders());
    ResponseEntity<String> entity = null;
    try {
        entity = restTemplate.postForEntity(url, request, String.class);
    } catch (RestClientException e) {
        LOGGER.error(e.getMessage(), e);
        throw new TmallAppException(ResponseCode.CONNECTION_REFUSED.getCode(),
                "Connection refused:unknown URL content:" + url);
    }

    LOGGER.trace("Post data :" + content);
    LOGGER.trace("Response status:" + entity.getStatusCode().value());
    LOGGER.trace("Response body:" + entity.getBody());

    JsonObject responseObject = new JsonObject();
    if (entity.getStatusCode().value() == 200) {
        String responseBody = entity.getBody();
        JsonParser parser = new JsonParser();
        responseObject = parser.parse(responseBody).getAsJsonObject();
    } else {
        responseObject.addProperty("code", entity.getStatusCode().toString());
        responseObject.addProperty("msg", entity.getBody());
    }
    return responseObject;
}

From source file:com.cemeterylistingswebtest.test.rest.CemeteryControllerTest.java

@Test(enabled = false, dependsOnMethods = "testCreate")
public void testClubUpdate() {
    // LEFT AS AN EXERCISE FOR YOU
    // GET THE CLUB and THEN CHANGE AND MAKE A COPY
    //THEN SEND TO THE SERVER USING A PUT OR POST
    // THEN READ BACK TO SEE IF YOUR CHANGE HAS HAPPENED
    Long me = new Long(17);
    Cemetery oldCemetery = cs.find(me);/* ww  w.  j a v a2  s  .co m*/

    Cemetery updateCemetery = new Cemetery.Builder().Cemetery(oldCemetery).setContactNumber("0215554412")
            .build();

    repo.save(updateCemetery);
    id = updateCemetery.getId();

    HttpEntity<Cemetery> requestEntity = new HttpEntity<>(updateCemetery, getContentType());
    //        Make the HTTP POST request, marshaling the request to JSON, and the response to a String
    ResponseEntity<String> responseEntity = restTemplate.exchange(URL + "api/cemetery/update", HttpMethod.PUT,
            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);

}