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.cemeterylistingswebtest.test.rest.CemeteryControllerTest.java

@Test(enabled = false)
public void testCreate() {
    System.out.println("Cemetery Testing");

    Location local = new Location.Builder().setCemeteryName("Palm Springs").setCountry("America")
            .setDistrict_state("Washington").setLocationOfCemetery("12.06.12:45.63.89")
            .setProvince_State("New Jersey").setTown("Marlboro").build();

    Cemetery newCemetery = new Cemetery.Builder().setContactName("Palm Springs").setContactNumber("0215698412")
            .setLocation(local).build();

    HttpEntity<Cemetery> requestEntity = new HttpEntity<>(newCemetery, 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/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);
    id = newCemetery.getId();//  w  ww  .  ja  v a2 s  .co  m
}

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

public String performPostRequest(Object xmlRequest)
        throws TransformerFactoryConfigurationError, TransformerException {
    HttpEntity<String> requestEntity = new HttpEntity<String>(XMLBeansHelper.nodeToString((Node) xmlRequest),
            headers);//from   w w  w  .j ava2s.co m
    ResponseEntity<String> exchange = restTemplate.exchange(baseUrl, HttpMethod.POST, requestEntity,
            String.class);
    return exchange.getBody();
}

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

public void addBlockComment(String shortName, Integer dayId, Integer scheduleId, Integer blockId,
        Comment comment) {//from  www . j a  v  a  2  s  .  co m
    HttpHeaders requestHeaders = new HttpHeaders();
    requestHeaders.setContentType(new MediaType("application", "json"));

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

    restTemplate.exchange(
            "public/" + shortName + "/days/" + dayId + "/schedules/" + scheduleId + "/blocks/" + blockId
                    + "/comments",
            HttpMethod.POST, requestEntity, String.class, shortName, dayId, scheduleId, blockId).getBody();
}

From source file:edu.fing.tagsi.db4o.business.CiudadesController.java

public Recorrido ObtenerRecorrido(Ciudad origen, Ciudad destino) {
    RestTemplate restTemplate = new RestTemplate();
    RequestRecorrido req = new RequestRecorrido(origen.getNombre(), destino.getNombre());
    HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.APPLICATION_JSON);
    HttpEntity<RequestRecorrido> entity = new HttpEntity<>(req, headers);
    RecorridoREST recorrido = restTemplate.postForObject(URL, entity, RecorridoREST.class);

    if (recorrido.getCiudades() != null) {
        NodoCamino[] ciudades = new NodoCamino[recorrido.getCiudades().length];
        for (int i = 0; i < ciudades.length; i++) {
            if (i == 0) {
                ciudades[i] = new NodoCamino(ObtenerCiudad(recorrido.getCiudades()[i].getName()), true, 0,
                        null);/*w  w  w . j  av a 2  s.  c om*/
            } else {
                Tramo tramo = recorrido.getRutas()[i - 1];
                ciudades[i] = new NodoCamino(ObtenerCiudad(recorrido.getCiudades()[i].getName()), false,
                        tramo.getDistancia(), tramo.getRutas());
            }
        }
        Recorrido resultado = new Recorrido(recorrido.getDistanciaTotal(), ciudades);
        return resultado;
    } else {
        return null;
    }

}

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

public static String runQuery(String sparqlQuery) {

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

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

    RestTemplate restTemplate = new RestTemplate();

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

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

    return result;
}

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

public StatusInfoDocument asyncExecute(String processId, String executeDocument) {
    HttpEntity<String> requestEntity = new HttpEntity<String>(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 post(String json, String url) {
    HttpEntity<String> requestEntity = new HttpEntity<>(json, headers);
    ResponseEntity<String> responseEntity = rest.exchange(url, HttpMethod.POST, requestEntity, String.class);
    this.setStatus(responseEntity.getStatusCode());
    return responseEntity.getBody();
}

From source file:org.zalando.riptide.AsyncRest.java

public AsyncDispatcher execute(final HttpMethod method, final URI url, final HttpHeaders headers,
        final Object body) {
    return execute(method, url, new HttpEntity<>(body, headers));
}

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

@Test(enabled = false)
public void testCreate() {
    Long subID = new Long(17);
    List<PersonOtherNames> names = null;

    PublishedDeceasedListing newListing = new PublishedDeceasedListing.Builder().setFirstName("Hendrika")
            .setSurname("Fourie").setMaidenName("Gerber").setGender("Female").setDateOfBirth("08/06/1969")
            .setDateOfDeath("14/02/2005").setGraveInscription("Hippiest person eva").setGraveNumber("2456")
            .setImageOfBurialSite("/images/001.jpg").setLastKnownContactName("Berry")
            .setLastKnownContactNumber("0725576482").setSubscriberSubmitID(subID).setNames(names).build();

    HttpEntity<PublishedDeceasedListing> requestEntity = new HttpEntity<>(newListing, getContentType());
    //        Make the HTTP POST request, marshaling the request to JSON, and the response to a String
    ResponseEntity<String> responseEntity = restTemplate.exchange(URL + "api/publishedListings/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);
    id = newListing.getPublishedListingID();
}

From source file:com.joseph.california.test.restapi.ClubRestControllerTest.java

@Test
public void tesClubUpdate() {
    // 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
    Club club = new Club.Builder("Hackers").build();
    HttpEntity<Club> requestEntity = new HttpEntity<>(club, getContentType());
    //        Make the HTTP POST request, marshaling the request to JSON, and the response to a String
    ResponseEntity<String> responseEntity = restTemplate.exchange(URL + "api/club/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);

}