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(MultiValueMap<String, String> headers) 

Source Link

Document

Create a new HttpEntity with the given headers and no body.

Usage

From source file:org.socialsignin.exfmproxy.mvc.ExFmProxyController.java

protected String getJson(HttpServletRequest request, String url) {
    String json = "";
    String method = request.getMethod().toLowerCase();
    if (method.equals("get")) {
        if (request.getQueryString() != null) {
            json = restTemplate.getForObject(url + "?" + request.getQueryString(), String.class);
        } else {//from  ww w  .ja  v  a2s  .c  o  m
            json = restTemplate.getForObject(url, String.class);
        }
    } else if (method.equals("post")) {
        HttpHeaders requestHeaders = new HttpHeaders();

        requestHeaders.setAccept(Arrays.asList(MediaType.APPLICATION_JSON));

        HttpEntity<?> httpEntity = new HttpEntity<Object>(requestHeaders);
        json = restTemplate.postForEntity(url, httpEntity, String.class).getBody();

    }
    return json.trim();
}

From source file:org.terasoluna.gfw.functionaltest.app.logging.LoggingTest.java

@Test
public void test01_04_checkConsistencyXtrackMDCRequestToResponse() {
    // test Check consistency HTTP Request Header to Response Header
    HttpHeaders requestHeaders = new HttpHeaders();
    requestHeaders.set("X-Track", "12345678901234567890123456789012");
    ResponseEntity<byte[]> response = restTemplate.exchange(
            applicationContextUrl + "/logging/xTrackMDCPutFilter/1_4", HttpMethod.GET,
            new HttpEntity<byte[]>(requestHeaders), byte[].class);

    HttpHeaders headers = response.getHeaders();
    assertThat(headers.getFirst("X-Track"), is("12345678901234567890123456789012"));
}

From source file:aiai.ai.launchpad.snippet.SnippetController.java

@GetMapping("/snippet-delete/{id}")
public HttpEntity<String> delete(@ModelAttribute Result result, @PathVariable Long id,
        final RedirectAttributes redirectAttributes) {
    log.info("Start deleting snippet with id: {}", id);
    final Snippet snippet = snippetCache.findById(id);
    if (snippet != null) {
        //            redirectAttributes.addFlashAttribute("infoMessages",
        //                    Collections.singleton("Snippet "+id+" was deleted successfully"));
        snippetCache.delete(snippet.getId());
        binaryDataService.deleteByCodeAndDataType(snippet.getSnippetCode(), Enums.BinaryDataType.SNIPPET);
    }// w  ww  . j  a va2s  .co  m
    return new HttpEntity<>("true");
    //        return "redirect:/launchpad/snippets";
}

From source file:demo.RestServiceIntegrationTests.java

@Test
public void findByLocation() {
    TestRestTemplate template = new TestRestTemplate();
    ResponseEntity<Resource<ServiceLocation>> result = template.exchange(
            "http://localhost:" + this.port
                    + "/serviceLocations/search/findFirstByLocationNear?location={lat},{long}",
            HttpMethod.GET, new HttpEntity<Void>((Void) null),
            new ParameterizedTypeReference<Resource<ServiceLocation>>() {
            }, 39, -84);/*from  w  w w  . java2s . c o  m*/
    assertEquals(HttpStatus.OK, result.getStatusCode());
}

From source file:org.cloudfoundry.identity.uaa.scim.RemoteScimUserProvisioning.java

@Override
public ScimUser removeUser(String id, int version) throws ScimResourceNotFoundException {
    HttpHeaders headers = new HttpHeaders();
    headers.set("If-Match", String.format("%d", version));
    return restTemplate.exchange(baseUrl + "/User/{id}", HttpMethod.DELETE, new HttpEntity<Void>(headers),
            ScimUser.class, id).getBody();
}

From source file:org.cloudfoundry.identity.uaa.integration.ScimUserEndpointsIntegrationTests.java

@SuppressWarnings("rawtypes")
private ResponseEntity<Map> deleteUser(String id, int version) {
    HttpHeaders headers = new HttpHeaders();
    headers.add("If-Match", "\"" + version + "\"");
    return client.exchange(serverRunning.getUrl(userEndpoint + "/{id}"), HttpMethod.DELETE,
            new HttpEntity<Void>(headers), Map.class, id);
}

From source file:com.playhaven.android.req.PlayHavenRequest.java

protected HttpEntity<?> getEntity() {
    return new HttpEntity<Object>(getHeaders());
}

From source file:com.cloudera.nav.sdk.client.NavApiCient.java

private <R, T> T sendRequest(String url, HttpMethod method, Class<? extends T> resultClass, R requestPayload) {
    RestTemplate restTemplate = newRestTemplate();
    HttpHeaders headers = getAuthHeaders();
    HttpEntity<?> request = requestPayload == null ? new HttpEntity<String>(headers)
            : new HttpEntity<>(requestPayload, headers);
    ResponseEntity<? extends T> response = restTemplate.exchange(url, method, request, resultClass);
    return response.getBody();
}

From source file:cz.zcu.kiv.eeg.mobile.base.ws.asynctask.FetchPeople.java

/**
 * Method, where all people are read from server.
 * All heavy lifting is made here./* w w w. j a  v  a 2s . co m*/
 *
 * @param params omitted here
 * @return list of fetched people
 */
@Override
protected List<Person> doInBackground(Void... params) {
    SharedPreferences credentials = getCredentials();
    String username = credentials.getString("username", null);
    String password = credentials.getString("password", null);
    String url = credentials.getString("url", null) + Values.SERVICE_USER + Values.SERVICE_QUALIFIER_ALL;

    setState(RUNNING, R.string.working_ws_people);
    HttpAuthentication authHeader = new HttpBasicAuthentication(username, password);
    HttpHeaders requestHeaders = new HttpHeaders();
    requestHeaders.setAuthorization(authHeader);
    requestHeaders.setAccept(Collections.singletonList(MediaType.APPLICATION_XML));
    HttpEntity<Object> entity = new HttpEntity<Object>(requestHeaders);

    SSLSimpleClientHttpRequestFactory factory = new SSLSimpleClientHttpRequestFactory();
    // Create a new RestTemplate instance
    RestTemplate restTemplate = new RestTemplate(factory);
    restTemplate.getMessageConverters().add(new SimpleXmlHttpMessageConverter());

    try {
        // Make the network request
        Log.d(TAG, url);
        ResponseEntity<PersonList> response = restTemplate.exchange(url, HttpMethod.GET, entity,
                PersonList.class);
        PersonList body = response.getBody();

        if (body != null) {
            return body.getPeople();
        }

    } catch (Exception e) {
        Log.e(TAG, e.getLocalizedMessage(), e);
        setState(ERROR, e);
    } finally {
        setState(DONE);
    }
    return Collections.emptyList();
}