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:com.opensearchserver.hadse.cluster.ClusterTest.java

@Test
public void t01_get() {
    HttpHeaders headers = new HttpHeaders();
    headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON));

    RestTemplate template = new RestTemplate();

    ResponseEntity<NodeItem[]> entity = template.exchange("http://localhost:8080/_cluster", HttpMethod.GET,
            null, NodeItem[].class);
    assertTrue(entity.getBody().length >= 1);
    assertEquals(HttpStatus.OK, entity.getStatusCode());
}

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

/** Method returns the output of the policy request as a string */
@Override//from w w  w.j a v a2  s .com
public String policyRequest(String serviceId, String policyrequestContent) {

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

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

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

    String policyIdResponse = restTemplate.postForObject(restURIstructure, policyrequestContent, String.class);

    return policyIdResponse;
}

From source file:com.companyname.plat.commons.client.HttpRestfulClient.java

public Object getObject(Map<String, String> params, Class clz) {
    RestTemplate restTemplate = new RestTemplate();

    try {//from   w w w  . jav  a2  s.c  om
        ResponseEntity<Object> entity = restTemplate.exchange(getEndPoint(), HttpMethod.GET,
                getHttpRequest(params), clz);

        setResponseStatus(entity.getStatusCode().toString());
        return entity.getBody();
    } catch (HttpClientErrorException ex) {
        if (HttpStatus.UNAUTHORIZED == ex.getStatusCode()) {
            System.out
                    .println("Unauthorized call to " + this.getEndPoint() + "\nWrong login and/or password (\""
                            + this.getUserName() + "\" / \"" + this.getPassword() + "\")");

            System.out.println("Cause: \n" + ex.getMessage());
        }
    }

    return null;
}

From source file:gr.cti.android.experimentation.client.WebServiceAndroidClient.java

public WebServiceAndroidClient(final String token) {
    this.token = token;
    restTemplate = new RestTemplate();
}

From source file:org.openwms.tms.routing.ModuleConfig.java

public @Bean RestTemplate simpleRestTemplate() {
    return new RestTemplate();
}

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

private AwsOffer getAwsOffer(String awsOffersUrl) {
    RestTemplate restTemplate = new RestTemplate();
    MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter();
    converter.setSupportedMediaTypes(//from   ww w. ja va 2s .  co  m
            Arrays.asList(new MediaType[] { MediaType.APPLICATION_JSON, MediaType.APPLICATION_OCTET_STREAM }));
    restTemplate.setMessageConverters(Arrays.asList(converter, new FormHttpMessageConverter()));
    try {
        return restTemplate.getForObject(awsOffersUrl, AwsOffer.class);
    } catch (RestClientException e) {
        e.printStackTrace();
        return null;
    }
}

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

public Usuario login(String email) {
    MultiValueMap<String, String> params = new LinkedMultiValueMap<>();
    params.add("email", email);
    String result = new RestTemplate().postForObject("http://ceatic.ujaen.es:8075/radioapi/v2/login", params,
            String.class);
    //return result;

    try {/* w w w. j av  a  2 s.c o  m*/

        ObjectMapper a = new ObjectMapper();
        Usuario listilla = a.readValue(result, Usuario.class);
        return listilla;

    } catch (Exception e) {
        return null;
    }

}

From source file:eu.cloudwave.wp5.common.rest.AbstractRestClient.java

public AbstractRestClient() {
    this.restTemplate = new RestTemplate();
}

From source file:com.epam.reportportal.auth.integration.github.GitHubClient.java

private GitHubClient(String accessToken) {
    this.restTemplate = new RestTemplate();
    this.restTemplate.getInterceptors().add((request, body, execution) -> {
        request.getHeaders().add("Authorization", "bearer " + accessToken);
        return execution.execute(request, body);
    });//from  w ww . jav  a2s  . c o m
}

From source file:fr.keemto.web.LoginWebIT.java

@Before
public void prepare() throws Exception {
    template = new RestTemplate();
}