Example usage for org.springframework.web.client RestTemplate getForObject

List of usage examples for org.springframework.web.client RestTemplate getForObject

Introduction

In this page you can find the example usage for org.springframework.web.client RestTemplate getForObject.

Prototype

@Override
    @Nullable
    public <T> T getForObject(URI url, Class<T> responseType) throws RestClientException 

Source Link

Usage

From source file:com.softtek.medicine.java.util.TestRestClient.java

private static List<Incident> getAllIncidents() {
    List<Incident> incList = new ArrayList<Incident>();
    RestTemplate restTemplate = new RestTemplate();
    List<LinkedHashMap> emps = restTemplate.getForObject(SERVER_URI + "/dr/incidents/request", List.class);
    System.out.println(emps.size());

    /**//from   w  w w .  ja  v  a 2 s  . c  om
     * Trecho comentado para no fazer uppdate de todos incidentes durante
     * os testes
     */
    //      for (LinkedHashMap map : emps) {
    //         System.out.println("incidentNumber=" + map.get("incidentNumber"));
    //         Incident in = new Incident();
    //         in.setIncidentNumber(map.get("incidentNumber").toString());
    //         incList.add(in);
    //      }
    Incident in = new Incident();
    in.setIncidentNumber(emps.get(0).get("incidentNumber").toString());
    incList.add(in);

    return incList;
}

From source file:com.ge.predix.test.utils.ACSTestUtil.java

public static boolean isServerListening(final URI url) {
    RestTemplate restTemplate = new RestTemplate();
    try {//from www.j  a va  2  s  .com
        restTemplate.getForObject(url, String.class);
    } catch (RestClientException e) {
        if (e.getCause() instanceof ConnectException) {
            return false;
        }
    }
    return true;
}

From source file:org.jtalks.tests.jcommune.mail.pochta.PochtaClient.java

/**
 * Gets list of messages metadata// w w  w  . jav  a 2 s . c o m
 *
 * @return the list of messages metadata
 * @throws CouldNotGetMessagesException
 */
public static String getMessages() throws CouldNotGetMessagesException {
    RestTemplate client = new RestTemplate();
    try {
        return client.getForObject(new URI(mailtrapMessagesUri()), String.class);
    } catch (Exception e) {
        throw new CouldNotGetMessagesException(e);
    }
}

From source file:org.jtalks.tests.jcommune.mail.pochta.PochtaClient.java

/**
 * Get message by identifier//w w w. j  ava  2s  . c  om
 *
 * @param id the UUID type identifier
 * @return the message
 * @throws CouldNotGetMessageException
 */
public static String getMessage(String id) {
    RestTemplate client = new RestTemplate();
    try {
        return client.getForObject(new URI(API_INBOXES_URL), String.class);
    } catch (Exception e) {
        throw new CouldNotGetMessageException(e);
    }
}

From source file:org.jtalks.tests.jcommune.mail.mailtrap.MailtrapClient.java

/**
 * Gets list of messages metadata/*from  ww w . j a  v  a 2 s. co m*/
 *
 * @return the list of messages metadata
 * @throws CouldNotGetMessagesException
 */
public static String getMessages() throws CouldNotGetMessagesException {
    RestTemplate client = new RestTemplate();
    try {
        String data = client.getForObject(
                new URI(API_INBOXES_URL + JTALKS_AUTOTESTS_MESSAGES + API_TOKEN_PARAM), String.class);
        return data;
    } catch (Exception e) {
        throw new CouldNotGetMessagesException(e);
    }
}

From source file:org.jtalks.tests.jcommune.mail.mailtrap.MailtrapClient.java

/**
 * Get message by identifier// w  w  w . java  2s.  c  o  m
 *
 * @param id the UUID type identifier
 * @return the message
 * @throws CouldNotGetMessageException
 */
public static String getMessage(String id) {
    RestTemplate client = new RestTemplate();
    try {
        String data = client.getForObject(
                new URI(API_INBOXES_URL + JTALKS_AUTOTESTS_MESSAGES + id + API_TOKEN_PARAM), String.class);
        return data;
    } catch (Exception e) {
        throw new CouldNotGetMessageException(e);
    }
}

From source file:com.softtek.medicine.java.util.MedicineRestClientUtil.java

public static List<Incident> getAllIncidents() throws ParseException {
    List<Incident> incList = new ArrayList<Incident>();
    RestTemplate restTemplate = new RestTemplate();
    List<LinkedHashMap> emps = restTemplate.getForObject(SERVER_URI + "/dr/incidents/request", List.class);
    System.out.println(emps.size());

    /**// w w  w .  ja  v a2s .  c  o  m
     * Trecho comentado para no fazer uppdate de todos incidentes durante
     * os testes
     */
    for (LinkedHashMap map : emps) {
        //System.out.println("incidentNumber=" + map.get("incidentNumber"));
        Incident in = new Incident();
        in.setIncidentNumber(map.get("incidentNumber").toString());
        in.setPriority(Integer.parseInt(map.get("priority").toString()));
        in.setImpact(Integer.parseInt(map.get("impact").toString()));
        in.setUrgency(Integer.parseInt(map.get("urgency").toString()));
        in.setServiceType(Integer.parseInt(map.get("serviceType").toString()));
        in.setContactCompany(map.get("contactCompany").toString());
        in.setCategorizationTier1(map.get("categorizationTier1").toString());
        in.setCategorizationTier2(map.get("categorizationTier2").toString());
        in.setPhoneNumber(map.get("phoneNumber").toString());
        in.setFirstName(map.get("firstName").toString());
        in.setLastName(map.get("lastName").toString());
        in.setDescription(map.get("description").toString());
        //            in.setProductCategorizationTier1(map.get("productCategorizationTier1").toString());
        //            in.setProductCategorizationTier2(map.get("productCategorizationTier2").toString());
        //            in.setProductCategorizationTier3(map.get("productCategorizationTier3").toString());
        in.setEntryId(map.get("entryId").toString());
        in.setSubmitter(map.get("submitter").toString());
        //            in.setSubmitDate((Date) formatter.parse(map.get("submitDate").toString()));
        in.setTemplate(map.get("template").toString());
        in.setLastModifiedBy(map.get("lastModifiedBy").toString());
        //            in.setLastModifiedDate((Date) formatter.parse(map.get("lastModifiedDate").toString()));
        in.setStatus(Integer.parseInt(map.get("status").toString()));
        in.setCreatedBy(map.get("createdBy").toString());
        in.setCustomer(map.get("customer").toString());
        in.setCompany(map.get("company").toString());
        in.setFullName(map.get("fullName").toString());
        incList.add(in);
    }

    //        Incident in = new Incident();
    //        in.setIncidentNumber(emps.get(0).get("incidentNumber").toString());
    //        incList.add(in);
    return incList;
}

From source file:com.hatta.consumer.App.java

private static User getCustomer(int id, AuthTokenInfo tokenInfo) {
    Assert.notNull(tokenInfo, "Authenticate first please......");
    RestTemplate restTemplate = new RestTemplate();
    HttpEntity<String> request = new HttpEntity<String>(getHeaders());
    User cust = restTemplate.getForObject(
            REST_SERVICE_URI + "/api/user/" + id + QPM_ACCESS_TOKEN + tokenInfo.getAccess_token(), User.class);
    if (cust != null) {
        System.out.println("Retrieve a customer:");
        System.out.println("Customer : id=" + cust.getId() + ", Name=" + cust.getName() + ", Address="
                + cust.getPassword() + ", Email=" + cust.getEmail());
        return cust;
    } else {//from w  ww  .  j ava  2s.c  o m
        System.out.println("No customer exist----------");
        return null;
    }
}

From source file:org.eclipse.cft.server.core.internal.client.CloudFoundryClientFactory.java

public static String getSsoUrl(String apiurl, boolean trustSelfSignedCerts) throws Exception {
    RestUtil restUtil = new RestUtil();
    HttpProxyConfiguration httpProxyConfiguration = getProxy(new URL(apiurl));
    RestTemplate restTemplate = restUtil.createRestTemplate(httpProxyConfiguration, trustSelfSignedCerts);
    String infoV2Json = restTemplate.getForObject(getUrl(apiurl, "/v2/info"), String.class);
    Map<String, Object> infoV2Map = JsonUtil.convertJsonToMap(infoV2Json);
    String authorizationEndpoint = CloudUtil.parse(String.class, infoV2Map.get("authorization_endpoint"));
    String passcodeJson = getJson(restTemplate, getUrl(authorizationEndpoint, "/login"));
    Map<String, Object> passcodeMap = JsonUtil.convertJsonToMap(passcodeJson);
    Object prompts = passcodeMap.get("prompts");
    if (prompts instanceof Map) {
        @SuppressWarnings("rawtypes")
        Object text = ((Map) prompts).get("passcode");
        if (text instanceof List) {
            @SuppressWarnings("rawtypes")
            List list = (List) text;
            if (list.size() >= 2 && list.get(1) != null) {
                String message = list.get(1).toString();
                String[] elements = message.split(" ");
                for (int i = 0; i < elements.length; i++) {
                    String element = elements[i];
                    if (element != null && element.startsWith("http")) {

                        // Strip trailing parentheses
                        String url = element;
                        while (url.endsWith(")")) {
                            url = url.substring(0, url.length() - 1);
                        }/*  w  w w.  j a  v  a2 s .c  o m*/

                        return url;
                    }
                }
            }
        }
    }
    return null;
}

From source file:org.springframework.cloud.dataflow.server.service.impl.validation.DefaultAppValidationServiceTests.java

private static boolean dockerCheck() {
    boolean result = true;
    try {//  w  w  w .  ja  va 2s .co m
        CloseableHttpClient httpClient = HttpClients.custom().setSSLHostnameVerifier(new NoopHostnameVerifier())
                .build();
        HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory();
        requestFactory.setHttpClient(httpClient);
        requestFactory.setConnectTimeout(10000);
        requestFactory.setReadTimeout(10000);

        RestTemplate restTemplate = new RestTemplate(requestFactory);
        System.out.println("Testing access to " + DockerValidatorProperties.DOCKER_REGISTRY_URL
                + "springcloudstream/log-sink-rabbit/tags");
        restTemplate.getForObject(
                DockerValidatorProperties.DOCKER_REGISTRY_URL + "/springcloudstream/log-sink-rabbit/tags",
                String.class);
    } catch (Exception ex) {
        System.out.println("dockerCheck() failed. " + ex.getMessage());
        result = false;
    }
    return result;
}