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:eu.falcon.semantic.client.DenaClient.java

public static String addInstances(String fileClassPath, String format) {

    RestTemplate restTemplate = new RestTemplate();
    LinkedMultiValueMap<String, Object> map = new LinkedMultiValueMap<>();
    //final String uri = "http://localhost:8090/api/v1/ontology/instances/publish";
    final String uri = "http://falconsemanticmanager.euprojects.net/api/v1/ontology/instances/publish";

    map.add("file", new ClassPathResource(fileClassPath));
    map.add("format", format);
    HttpHeaders headers = new HttpHeaders();

    headers.setContentType(MediaType.MULTIPART_FORM_DATA);

    HttpEntity<LinkedMultiValueMap<String, Object>> entity = new HttpEntity<LinkedMultiValueMap<String, Object>>(
            map, headers);// w  ww  .  ja  va  2s.  c  om

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

    return result;

}

From source file:rest.ApplianceRestController.java

@Test
public void testCreate() {
    Appliance app = new Appliance.Builder("samTv003").brand("samsung").descrip("HDTV").Build();
    HttpEntity<Appliance> requestEntity = new HttpEntity<>(app, getContentType());
    //        Make the HTTP POST request, marshaling the request to JSON, and the response to a String
    ResponseEntity<String> responseEntity = restTemplate.exchange(URL + "api/app/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);

}

From source file:com.nobu.dvdrentalweb.test.restapi.MovieRestControllerTest.java

@Test
public void createTest() {
    Movie movie = new Movie.Builder().moviename("Set it off").build();
    HttpEntity<Movie> requestEntity = new HttpEntity<>(movie, getContentType());
    ResponseEntity<String> responseEntity = restTemplate.exchange(URL + "api/movie/create", HttpMethod.POST,
            requestEntity, String.class);
}

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

@Test
public void tesCreate() {
    Name name = new Name();
    name.setFirstName("bradley");
    name.setLastName("bradley");

    Person p = new Person.Builder().name(name).build();

    System.out.println("rest Template = " + restTemplate);
    HttpEntity<Person> requestEntity = new HttpEntity<>(p, getContentType());
    //       Make the HTTP POST request, marshaling the request to JSON, and the response to a String

    ResponseEntity<String> responseEntity = restTemplate.exchange(URL + "api/person/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);

}

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

public void Registrar(Envio envio) {
    RestTemplate restTemplate = new RestTemplate();
    RequestTrackingAddPackage req = new RequestTrackingAddPackage(envio.getId().toString(),
            envio.getCliente().getId().toString(), envio.getDestino().getId().toString(), envio.getFechaEnvio(),
            false);/*from  w w  w. j a v a2s  . c  o  m*/
    HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.APPLICATION_JSON);
    HttpEntity<RequestTrackingAddPackage> entity = new HttpEntity<>(req, headers);
    restTemplate.postForObject(ConfigController.getInstance().getURLAddTracking(), entity, void.class);
}

From source file:cn.org.once.cstack.utils.RestUtils.java

@SuppressWarnings("rawtypes")
public static String sendPostCommand(String url, String volume) {

    RestTemplate restTemplate = new RestTemplate();
    HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.APPLICATION_JSON);
    headers.add("Accept", "text/plain");
    MultiValueMap<String, String> params = new LinkedMultiValueMap<String, String>();
    params.add("Binds", volume);
    @SuppressWarnings("unchecked")
    HttpEntity request = new HttpEntity(params, headers);
    ResponseEntity<String> response = restTemplate.postForEntity(url, request, String.class);
    return response.toString();
}

From source file:com.nobu.dvdrentalweb.test.restapi.AccountRestControllerTest.java

@Test
public void tesCreate() {
    Account account = new Account.Builder().accountName("Savings").accountType("Gold Card").build();
    HttpEntity<Account> requestEntity = new HttpEntity<>(account, getContentType());
    //        Make the HTTP POST request, marshaling the request to JSON, and the response to a String
    ResponseEntity<String> responseEntity = restTemplate.exchange(URL + "api/account/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);

}

From source file:ca.qhrtech.services.implementations.StrawPollServiceImpl.java

@Override
public long generatePollId(List<Game> games, BGLTable table) {
    StrawPoll poll = generateRequestBodyPoll(games, generatePollName(table));
    HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.APPLICATION_JSON);
    HttpEntity<StrawPoll> request = new HttpEntity<>(poll, headers);
    HttpComponentsClientHttpRequestFactory factory = new HttpComponentsClientHttpRequestFactory();
    RestTemplate template = new RestTemplate(factory);
    ResponseEntity<StrawPoll> generatedPoll;
    generatedPoll = template.postForEntity(STRAW_POLL_URL, request, StrawPoll.class);

    return generatedPoll.getBody().getId();
}

From source file:org.jnrain.mobile.accounts.kbs.KBSLogoutRequest.java

@Override
public SimpleReturnCode loadDataFromNetwork() throws Exception {
    MultiValueMap<String, String> params = new LinkedMultiValueMap<String, String>();
    // request body intentionally empty

    HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
    HttpEntity<MultiValueMap<String, String>> req = new HttpEntity<MultiValueMap<String, String>>(params,
            headers);// w w  w. j  a  v a2s.  c om

    return getRestTemplate().postForObject(
            /* "http://rhymin.jnrain.com/api/logout/", */
            "http://bbs.jnrain.com/rainstyle/apilogout.php", req, SimpleReturnCode.class);
}

From source file:org.jnrain.mobile.accounts.kbs.KBSCheckIDRequest.java

@Override
public KBSRegisterResult loadDataFromNetwork() throws Exception {
    MultiValueMap<String, String> params = new LinkedMultiValueMap<String, String>();
    params.set("id", _uid);

    HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
    HttpEntity<MultiValueMap<String, String>> req = new HttpEntity<MultiValueMap<String, String>>(params,
            headers);/*w w  w .j  a v a 2 s .  com*/

    return getRestTemplate().postForObject("http://bbs.jnrain.com/rainstyle/apicheckid.php", req,
            KBSRegisterResult.class);
}