Example usage for org.springframework.http HttpEntity getBody

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

Introduction

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

Prototype

@Nullable
public T getBody() 

Source Link

Document

Returns the body of this entity.

Usage

From source file:cz.muni.fi.pa165.rentalofconstructionmachinery.restclient.MachineRestController.java

public static MachineDTO machineDetails(Long id) throws URISyntaxException {
    String url = MACHINE_URL + id;
    HttpEntity re = rt.exchange(new URI(url), HttpMethod.GET, new HttpEntity<>(httpHeaders), MachineDTO.class);
    return (MachineDTO) re.getBody();
}

From source file:cz.muni.fi.pa165.rentalofconstructionmachinery.restclient.MachineRestController.java

public static List<MachineDTO> listMachines() throws URISyntaxException {
    HttpEntity re = rt.exchange(new URI(MACHINE_URL), HttpMethod.GET, new HttpEntity<>(httpHeaders),
            MachineDTO[].class);
    return Arrays.asList((MachineDTO[]) re.getBody());
}

From source file:org.cloudfoundry.caldecott.client.TunnelHelper.java

public static String getTunnelProtocolVersion(CloudFoundryClient client, String uri) {
    String uriToUse = uri + "/info";
    HttpHeaders requestHeaders = new HttpHeaders();
    requestHeaders.set("Auth-Token", getTunnelAuth(client));
    HttpEntity<?> requestEntity = new HttpEntity(requestHeaders);
    HttpEntity<String> response = restTemplate.exchange(uriToUse, HttpMethod.GET, requestEntity, String.class);
    return response.getBody().trim();
}

From source file:org.cloudfoundry.caldecott.client.TunnelHelper.java

public static Map<String, String> getTunnelServiceInfo(CloudFoundryClient client, String serviceName) {
    String urlToUse = getTunnelUri(client) + "/services/" + serviceName;
    HttpHeaders requestHeaders = new HttpHeaders();
    requestHeaders.set("Auth-Token", getTunnelAuth(client));
    HttpEntity<?> requestEntity = new HttpEntity(requestHeaders);
    HttpEntity<String> response = restTemplate.exchange(urlToUse, HttpMethod.GET, requestEntity, String.class);
    String json = response.getBody().trim();
    Map<String, String> svcInfo = new HashMap<String, String>();
    try {/*  ww w  .j ava  2s .com*/
        svcInfo = convertJsonToMap(json);
    } catch (IOException e) {
        return new HashMap<String, String>();
    }
    if (svcInfo.containsKey("url")) {
        String svcUrl = svcInfo.get("url");
        try {
            URI uri = new URI(svcUrl);
            String[] userInfo;
            if (uri.getUserInfo().contains(":")) {
                userInfo = uri.getUserInfo().split(":");
            } else {
                userInfo = new String[2];
                userInfo[0] = uri.getUserInfo();
                userInfo[1] = "";
            }
            svcInfo.put("user", userInfo[0]);
            svcInfo.put("username", userInfo[0]);
            svcInfo.put("password", userInfo[1]);
            svcInfo.put("host", uri.getHost());
            svcInfo.put("hostname", uri.getHost());
            svcInfo.put("port", "" + uri.getPort());
            svcInfo.put("path", (uri.getPath().startsWith("/") ? uri.getPath().substring(1) : uri.getPath()));
            svcInfo.put("vhost", svcInfo.get("path"));
        } catch (URISyntaxException e) {
        }
    }
    return svcInfo;
}

From source file:net.slkdev.swagger.confluence.service.impl.XHtmlToConfluenceServiceImpl.java

private static Integer getPageIdFromResponse(final HttpEntity<String> responseEntity) {
    final String responseJson = responseEntity.getBody();
    final JSONParser jsonParser = new JSONParser(DEFAULT_PERMISSIVE_MODE);

    try {//from   ww  w  .j  a va2 s  . c o  m
        final JSONObject response = jsonParser.parse(responseJson, JSONObject.class);
        return Integer.valueOf((String) response.get(ID));
    } catch (ParseException e) {
        throw new ConfluenceAPIException("Error Parsing JSON Response from Confluence!", e);
    }
}

From source file:org.opencredo.couchdb.IsBodyEqual.java

@Override
public boolean matchesSafely(HttpEntity httpEntity) {
    return httpEntity.getBody().equals(object);
}

From source file:com.appleframework.monitor.action.TaskAction.java

@RequestMapping(value = "/projects/{projectName}/tasks/update", method = RequestMethod.POST)
public @ResponseBody WebResult updateTask(ModelMap map, @PathVariable String projectName,
        HttpEntity<Task> entity) {
    Task task = entity.getBody();
    logger.debug("update task {}", new Gson().toJson(task));
    projectService.saveTask(projectName, task);
    return new WebResult();
}

From source file:com.appleframework.monitor.action.DogAction.java

@RequestMapping(value = "/projects/{projectName}/dog", method = RequestMethod.POST)
public @ResponseBody WebResult update(@PathVariable String projectName, HttpEntity<MetricDog> entity) {
    MetricDog metricDog = entity.getBody();
    Project project = projectService.findProject(projectName);
    project.saveDog(metricDog);//from w  w w .  j  a va2 s .c  o  m
    projectService.saveProject(project);
    return new WebResult(project.getMetricDogs());
}

From source file:com.skymobi.monitor.action.TaskAction.java

@RequestMapping(value = "/projects/{projectName}/tasks/update", method = RequestMethod.POST)
public @ResponseBody WebResult updateTask(ModelMap map, @PathVariable String projectName,
        HttpEntity<Task> entity) {
    Task task = entity.getBody();
    logger.debug("update task {}", new Gson().toJson(task));
    projectService.saveTask(projectName, task);

    return new WebResult();
}

From source file:com.skymobi.monitor.action.DogAction.java

@RequestMapping(value = "/projects/{projectName}/dog", method = RequestMethod.POST)
public @ResponseBody WebResult update(@PathVariable String projectName, HttpEntity<MetricDog> entity) {
    MetricDog metricDog = entity.getBody();
    Project project = projectService.findProject(projectName);
    project.saveDog(metricDog);//ww w.j  av  a2s  .c  o m
    projectService.saveProject(project);

    return new WebResult(project.getMetricDogs());
}