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:bq.tutorial.netflix.hystrix.StatusPressureTest.java

/**
 * less test thread pool size, to avoid service rejected error and make shortcircuit error
 *///w ww  . ja  va  2s.  co  m
@Test(invocationCount = 2000, threadPoolSize = 5)
public void testStatusCircuited() {
    RestTemplate client = new RestTemplate();
    String result = client.getForObject("http://localhost:8080/netflix_hystrix/mvc/pressure", String.class);
    System.out.println(result);
}

From source file:org.awesomeagile.integrations.hackpad.HackpadClientTest.java

public HackpadClientTest() {
    restTemplate = new RestTemplate();
    client = new RestTemplateHackpadClient(restTemplate, "http://test");
}

From source file:com.provenance.cloudprovenance.connector.policy.PolicyEnforcementConnector.java

/** Method retrieves the policy response based on a response Id as a string */
@Override/*from   w w  w  . ja v a 2 s. co  m*/
public String policyResponse(String serviceId, String policyResponseId) {

    RestTemplate restTemplate = new RestTemplate();
    String restURIstructure = new String();

    restURIstructure = protocol + "://" + server_add + ":" + port_no + "/" + service + "/" + resource + "/"
            + serviceId + "/" + policyResponseId;

    logger.info("Invoking URI: " + restURIstructure);

    String policyResponse = restTemplate.getForObject(restURIstructure, String.class);

    return policyResponse;
}

From source file:org.trustedanalytics.metadata.security.authorization.PlatformAuthorization.java

@Override
public boolean checkAccess(HttpServletRequest request, UUID orgId) throws IOException, ServletException {

    LOG.debug(String.format("Check if user can access org: '%s'", orgId));

    String token;//  w ww.  ja  v a2s . com
    try {
        token = getToken(request);
    } catch (OauthTokenMissingException e) {
        LOG.debug(e.getMessage(), e);
        return false;
    }

    String url = userManagementBaseUrl + "/rest/orgs/permissions?orgs={org}";
    ResponseEntity<CcOrgPermission[]> access = RestOperationsHelpers.getForEntityWithToken(new RestTemplate(),
            token, url, CcOrgPermission[].class, ImmutableMap.of("org", orgId));
    return access.getBody().length > 0;
}

From source file:jp.go.aist.six.util.core.web.spring.Http.java

/**
 * Generic HTTP method execution.//from   w  w  w  .  ja va  2 s.c  o m
 *
 * @throws  HttpException
 *  when an exceptional condition occurred during the HTTP method execution.
 */
protected static <T> T _execute(final URL from_url, final HttpMethod method, final RequestCallback callback,
        final ResponseExtractor<T> extractor) {
    _LOG_.debug("HTTP: method = " + method + ", URL=" + from_url);

    URI from_uri = null;
    try {
        from_uri = from_url.toURI();
        //throws URISyntaxException
    } catch (URISyntaxException ex) {
        throw new HttpException(ex);
    }

    T response = null;
    try {
        RestTemplate rest = new RestTemplate();
        response = rest.execute(from_uri, method, callback, extractor);
    } catch (RestClientException ex) {
        _LOG_.error("HTTP error: " + ex);
        throw new HttpException(ex);
    }

    return response;
}

From source file:org.starfishrespect.myconsumption.server.business.sensors.flukso.FluksoRetriever.java

/**
 * Creates the retriever and tries to get the sensors parameters from
 * the Flukso API/*from   w w w .  j a va 2s .  co m*/
 *
 * @param sensor the wanted sensor
 * @throws RetrieveException if information cannot be retrieved from the
 *                           information API
 */

public FluksoRetriever(FluksoSensor sensor) throws RetrieveException {
    this.sensor = sensor;

    restTemplate = new RestTemplate();

    SSLCheckUtil.disableChecks();

    this.params = retrieveParams();

    // SSLCheckUtil.enableChecks();

}

From source file:com.tikinou.schedulesdirect.ClientUtils.java

private ClientUtils() {
    restTemplate = new RestTemplate();
    //        restTemplate.setErrorHandler(new ErrorHandler());
    prepareMessageConverters(restTemplate.getMessageConverters());
}

From source file:uy.edu.ort.fachada.FachadaOperaciones.java

/**
 * Operaciones sobre la Entidad Barco//from  ww  w.j av  a 2  s  . c o m
 */

public static void mostrarBarco(String codigo) {
    String url = ManejoPropiedades.obtenerInstancia().obtenerPropiedad("restService") + "restbarco/" + codigo
            + ".htm";

    RestTemplate restTemplate1 = new RestTemplate();
    restTemplate1.getMessageConverters().add(new StringHttpMessageConverter());
    restTemplate1.getMessageConverters().add(new MappingJacksonHttpMessageConverter());

    Barco barco = restTemplate1.getForObject(url, Barco.class);
    System.out.println(
            "\tId \t\tCodigo \t\tNombre \t\tBandera \t\tCapacidad(kgs) \t\tAo \t\tCantidadTripulantes");
    System.out.println("\t" + barco.getId() + "\t\t" + barco.getCodigo() + " \t\t" + barco.getNombre() + " \t\t"
            + barco.getBandera() + " \t\t" + barco.getCapacidadTransporte() + " \t\t"
            + String.valueOf(barco.getAnioFabricacion()) + " \t\t" + barco.getCantidadTripulantes());

}

From source file:com.skipjaq.awspricing.pricing.AwsPricing.java

private PricingInfo getAwsPricing(String awsTemplatesUrl, String offerCode) {
    RestTemplate restTemplate = new RestTemplate();
    MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter();
    converter.setSupportedMediaTypes(/*from   w w  w .  ja v a2s  .  c  om*/
            Arrays.asList(new MediaType[] { MediaType.APPLICATION_JSON, MediaType.APPLICATION_OCTET_STREAM }));
    restTemplate.setMessageConverters(Arrays.asList(converter, new FormHttpMessageConverter()));
    return restTemplate.getForObject(awsTemplatesUrl, PricingInfo.class, offerCode);
}

From source file:nl.surfnet.coin.janus.JanusRestClient.java

public JanusRestClient() {
    this.restTemplate = new RestTemplate();
    restTemplate.setMessageConverters(//www  .  j  a  va  2s .c  o m
            Arrays.<HttpMessageConverter<?>>asList(new MappingJacksonHttpMessageConverter()));
}