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:be.roots.taconic.pricingguide.service.HubSpotServiceImpl.java

public Contact getContactFor(String hsID) throws IOException {

    LOGGER.info("Start getting the recent contact information based on conversion-id: " + hsID);

    final RestTemplate restTemplate = new RestTemplate();

    RecentContacts recentContacts = null;
    do {/*from   ww  w . j a v a  2  s .c o m*/
        if (recentContacts == null) {
            // first call
            LOGGER.info("Initial call for recent contacts");
            recentContacts = restTemplate.getForObject(apiUrl + apiKey + "&count=100", RecentContacts.class);
        } else {
            // page through the next calls
            LOGGER.info("Secondary call for recent contacts with timeOffset=" + recentContacts.getTimeOffset()
                    + ", and vidOffset=" + recentContacts.getVidOffset());
            recentContacts = restTemplate.getForObject(apiUrl + apiKey + "&count=100&timeOffset="
                    + recentContacts.getTimeOffset() + "&vidOffset=" + recentContacts.getVidOffset(),
                    RecentContacts.class);
        }

        if (recentContacts != null && !CollectionUtils.isEmpty(recentContacts.getContacts())) {

            for (RecentContact contact : recentContacts.getContacts()) {

                if (!CollectionUtils.isEmpty(contact.getFormSubmissions())) {

                    for (FormSubmission form : contact.getFormSubmissions()) {

                        if (hsID.equals(form.getConversionId())) {
                            final Contact result = getContactDetailsFor(
                                    String.format(apiContactUrl + apiKey, contact.getVid()));
                            result.setHsId(hsID);
                            return result;

                        }

                    }

                }

            }
        }

    } while (recentContacts.isHasMore());

    LOGGER.info("No recent contact information found for: " + hsID);

    return null;

}

From source file:org.trustedanalytics.metricsprovider.config.Config.java

protected RestOperations restTemplate() {
    RestTemplate restTemplate = new RestTemplate();
    OAuth2Authentication authentication = getAuthentication();
    String token = tokenRetriever.getAuthToken(authentication);
    ClientHttpRequestInterceptor interceptor = new HeaderAddingHttpInterceptor("Authorization",
            "bearer " + token);
    restTemplate.setInterceptors(singletonList(interceptor));
    return restTemplate;
}

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

public List<Workspace> listWorkspaces(String cheServerURL) {
    String url = generateURL(cheServerURL, CheRestEndpoints.LIST_WORKSPACES);
    RestTemplate template = new RestTemplate();
    ResponseEntity<List<Workspace>> response = template.exchange(url, HttpMethod.GET, null,
            new ParameterizedTypeReference<List<Workspace>>() {
            });//from  ww w .ja va  2 s  .c o  m

    List<Workspace> workspaces = response.getBody();
    for (Workspace workspace : workspaces) {
        workspace.setName(workspace.getConfig().getName());
        workspace.setDescription(workspace.getConfig().getDescription());

        for (WorkspaceLink link : workspace.getLinks()) {
            if (WORKSPACE_LINK_IDE_URL.equals(link.getRel())) {
                workspace.setWorkspaceIdeUrl(link.getHref());
                break;
            }
        }
    }
    return workspaces;
}

From source file:com.jumpbyte.test.springrest.service.RESTControllerTestIT.java

private RestTemplate createJSONRestTemplate() {
    ArrayList<HttpMessageConverter<?>> messageConverters = new ArrayList<HttpMessageConverter<?>>();
    messageConverters.add(new MappingJacksonHttpMessageConverter());
    RestTemplate restTemplate = new RestTemplate();
    restTemplate.setMessageConverters(messageConverters);
    return restTemplate;
}

From source file:com.provenance.cloudprovenance.connector.traceability.TraceabilityStoreConnector.java

public String getTraceabilityRecord(String serviceId, String traceabilityEntryId) {

    if (this.getTraceabilityRecordId() != null) {
        return this.getTraceabilityRecordId();
    }//from w  w w .j  a v  a  2s .c om

    String restURI = "http://" + server_add + ":" + port_no + "/" + service + "/" + resource + "/" + serviceId
            + "/" + this.TRACEABILITY_TYPE + "/" + traceabilityEntryId;

    RestTemplate restTemplate = new RestTemplate();
    String traceabilityRecordResponse = restTemplate.getForObject(restURI, String.class);

    return traceabilityRecordResponse;
}

From source file:com.github.wnameless.spring.bulkapi.DefaultBulkApiService.java

@Override
public BulkResponse bulk(BulkRequest req, HttpServletRequest servReq) {
    validateBulkRequest(req, servReq);//  w  w w. java  2 s  .  com

    List<BulkResult> results = new ArrayList<BulkResult>();
    RestTemplate template = new RestTemplate();
    for (BulkOperation op : req.getOperations()) {
        BodyBuilder bodyBuilder = RequestEntity.method(//
                httpMethod(op.getMethod()), computeUri(servReq, op));

        ResponseEntity<String> rawRes = template.exchange(requestEntity(bodyBuilder, op), String.class);

        if (!op.isSilent())
            results.add(buldResult(rawRes));
    }

    return new BulkResponse(results);
}

From source file:org.aksw.gerbil.datasets.DatahubNIFConfig.java

public DatahubNIFConfig(WikipediaApiInterface wikiApi, String datasetName, String datasetUrl,
        boolean couldBeCached) {
    super(datasetName, couldBeCached, ExperimentType.Sa2W);
    this.wikiApi = wikiApi;
    this.datasetUrl = datasetUrl;
    rt = new RestTemplate();
}

From source file:eu.falcon.semantic.client.DenaClient.java

public static String getInstanceAttributes(String instanceURI) {

    final String uri = "http://falconsemanticmanager.euprojects.net/api/v1/ontology/instance/attributes";
    //final String uri = "http://localhost:8090/api/v1/ontology/instance/attributes";

    HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.APPLICATION_JSON);

    RestTemplate restTemplate = new RestTemplate();

    HttpEntity<String> entity = new HttpEntity<>(instanceURI, headers);

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

    return result;
}

From source file:com.concentricsky.android.khanacademy.data.remote.KAEntityCollectionFetcherTask.java

@Override
protected List<T> doInBackground(Void... arg0) {
    // call  API and fetch an entity tree (commonly the tree rooted at the root topic)

    RestTemplate restTemplate = new RestTemplate();
    if (consumer != null) {
        restTemplate.setRequestFactory(new SpringRequestFactory(consumer));
    }/*from   w  ww.j  a v  a  2 s .c om*/

    restTemplate.getMessageConverters().add(new StringHttpMessageConverter());
    ResponseEntity<String> result = restTemplate.getForEntity(url, String.class);
    String body = result.getBody();

    // String tag = "~~~~~~~~~~~~~~~~";
    // Log.setLevel(tag, Log.VERBOSE);
    // Log.d(tag, "result body is a " + body.getClass().getCanonicalName());
    // Log.d(tag, "result is " + body);

    ObjectMapper mapper = new ObjectMapper();

    List<T> list = null;
    try {
        list = mapper.readValue(body, type);
    } catch (JsonParseException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (JsonMappingException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    return list;
}