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

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

Introduction

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

Prototype

public RestTemplate() 

Source Link

Document

Create a new instance of the RestTemplate using default settings.

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);//  ww  w  .ja v a2  s  .c o  m

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

    return result;

}

From source file:gumga.framework.presentation.api.GumgaThirdPartProxy.java

public GumgaThirdPartProxy() {
    restTemplate = new RestTemplate();
}

From source file:com.bailen.radioOnline.recursos.Jamendo.java

public Cancion[] canciones(Vector<Integer> ids) {
    String url = "http://api.jamendo.com/v3.0/tracks/?client_id=567e43c5&format=jsonpretty&limit=10&imagesize=600&id=";
    for (Integer id : ids) {
        url += id + "+";
    }//from  w w w  . j  a v a  2s  .c o  m

    String canc = new RestTemplate().getForObject(url, String.class, url);
    StringTokenizer st = new StringTokenizer(canc, "[", true);
    st.nextToken();
    st.nextToken();
    canc = "[" + st.nextToken();
    try {

        ObjectMapper a = new ObjectMapper();
        Cancion[] listilla = a.readValue(canc, Cancion[].class);
        return listilla;

    } catch (Exception e) {
        return null;
    }

}

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());

    /**/*from   w w  w  .  ja  v  a 2 s . 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.ge.predix.test.utils.ACSTestUtil.java

public static boolean isServerListening(final URI url) {
    RestTemplate restTemplate = new RestTemplate();
    try {/*  w  w  w .j a v  a2  s .c o  m*/
        restTemplate.getForObject(url, String.class);
    } catch (RestClientException e) {
        if (e.getCause() instanceof ConnectException) {
            return false;
        }
    }
    return true;
}

From source file:cz.cvut.jirutjak.fastimport.droid.oauth2.AccessTokenUtils.java

public static RestTemplate createRestTemplate() {
    RestTemplate template = new RestTemplate();
    Gson gson = new GsonBuilder().setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES).create();
    template.getMessageConverters().add(new GsonHttpMessageConverter(gson));

    return template;
}

From source file:io.fabric8.che.starter.client.StackClient.java

public List<Stack> listStacks(String cheServerUrl) {
    String url = CheRestEndpoints.LIST_STACKS.generateUrl(cheServerUrl);
    RestTemplate template = new RestTemplate();
    ResponseEntity<List<Stack>> response = template.exchange(url, HttpMethod.GET, null,
            new ParameterizedTypeReference<List<Stack>>() {
            });// w w  w.j av a2s.  c  o m
    return response.getBody();
}

From source file:com.appranix.adapter.service.AdapterServiceImpl.java

@Override
public void adapterRead(int id) throws Exception {
    try {/*from  ww  w .  j  a  va  2s. c  om*/
        final String uri = "http://localhost:9090/adapter/rest/cm/simple/cis/" + id;

        RestTemplate restTemplate = new RestTemplate();
        ResponseEntity<String> result = restTemplate.getForEntity(uri, String.class);

        System.out.println(result);

    } catch (Exception e) {
        throw new Exception("Error in Read Operation");
    }
}

From source file:demo.geocoders.MapquestGeocoder.java

@Autowired
public MapquestGeocoder(@Value("${mapquest.key}") String key) {
    this(key, new RestTemplate());
}

From source file:com.recursivechaos.stoopbot.service.RoomRequestService.java

public List<Items> pollHistory() {
    RestTemplate restTemplate = new RestTemplate();
    log.info("Polling room: " + room);
    ResponseEntity<History> responseEntity = restTemplate.getForEntity(
            "http://" + url + ".hipchat.com/v2/room/" + room + "/history?auth_token=" + key, History.class);
    log.debug("Response received: {}", responseEntity);
    return responseEntity.getBody().getItems();
}