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.manh.cp.fw.swagger.SwaggerConfigTest.java

@Test
public void simple_controller() {
    RestTemplate restTemplate = new RestTemplate();

    ResponseEntity<String> jsonResponseEntity = restTemplate
            .getForEntity("http://localhost:" + localPort + "/v2/api-docs", String.class);

    assertThat(jsonResponseEntity.getStatusCode(), equalTo(HttpStatus.OK));

    String json = jsonResponseEntity.getBody();

    assertThat(json, isJson());//from www.ja  va  2  s  .c  o  m
    assertThat(json, hasJsonPath("$.paths.*", hasSize(1)));

}

From source file:org.cloudfoundry.caldecott.client.HttpTunnelFactory.java

private RestTemplate createRestTemplate() {
    RestTemplate restTemplate = new RestTemplate();
    CommonsClientHttpRequestFactory requestFactory = new CommonsClientHttpRequestFactory();
    requestFactory.setConnectTimeout(TIMEOUT);
    requestFactory.setReadTimeout(TIMEOUT);
    if (httpProxyConfiguration != null) {
        requestFactory.getHttpClient().getHostConfiguration().setProxy(httpProxyConfiguration.getProxyHost(),
                httpProxyConfiguration.getProxyPort());
    }//from   w  w  w  .j a va 2  s  . com
    restTemplate.setRequestFactory(requestFactory);
    return restTemplate;
}

From source file:com.onyxscheduler.domain.HttpJobExecutionIT.java

@Before
public void setup() throws MalformedURLException {
    job = new HttpJob();
    job.setRestTemplate(new RestTemplate());
    job.setUrl(new URL("http://localhost:" + wireMockRule.port() + TEST_PATH));
    stubFor(any(urlMatching(".*")).willReturn(aResponse()));
}

From source file:com.navercorp.pinpoint.plugin.spring.web.RestTemplateIT.java

@Test
public void test1() throws Exception {
    RestTemplate restTemplate = new RestTemplate();
    String forObject = restTemplate.getForObject(webServer.getCallHttpUrl(), String.class);

    PluginTestVerifier verifier = PluginTestVerifierHolder.getInstance();
    verifier.printCache();/*w w w .  jav a  2  s .  c  o  m*/

    verifier.verifyTrace(event("REST_TEMPLATE", RestTemplate.class.getConstructor()));
    verifier.verifyTrace(event("REST_TEMPLATE", AbstractClientHttpRequest.class.getMethod("execute"),
            annotation("http.status.code", 200)));
}

From source file:com.tyro.oss.pact.spring4.pact.consumer.PactPublisher.java

private static void publishPactFile(String provider, String consumer, String version, String pactFile,
        String brokerBaseUrl) throws IOException {
    if (version.contains("-SNAPSHOT")) {
        version = version.replace("-SNAPSHOT", "");
    }// w  ww  . jav a 2  s  . c  o m

    String url = brokerBaseUrl + "/pacts/provider/" + provider + "/consumer/" + consumer + "/version/"
            + version;

    String pactJson = FileUtils.readFileToString(new File(pactFile));

    HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.APPLICATION_JSON);
    HttpEntity<String> httpEntity = new HttpEntity<>(pactJson, headers);

    try {
        RestTemplate restTemplate = new RestTemplate();
        restTemplate.put(url, httpEntity);
    } catch (ResourceAccessException e) {
        throw new NoPactBrokerException(String.format("Could not reach Pact broker: %s.", brokerBaseUrl), e);
    } catch (HttpClientErrorException e) {
        throw e;
    }
}

From source file:org.zaizi.sensefy.auth.service.AlfrescoLoginService.java

/**
 * <p>//  w  ww .j  a v  a  2s.co m
 * Initialize the REST template object used as HTTP Client
 * </p>
 */
private void initializeRestTemplate() {
    this.restTemplate = new RestTemplate();
}

From source file:org.cloudfoundry.identity.uaa.login.RemoteUaaControllerMockMvcTests.java

@Test
public void testLoginWithExplicitPrompts() throws Exception {
    RemoteUaaController controller = new RemoteUaaController(new MockEnvironment(), new RestTemplate());
    Prompt first = new Prompt("how", "text", "How did I get here?");
    Prompt second = new Prompt("where", "password", "Where does that highway go to?");
    controller.setPrompts(Arrays.asList(first, second));

    MockMvc mockMvc = getMockMvc(controller);

    mockMvc.perform(get("/login").accept(APPLICATION_JSON)).andExpect(status().isOk())
            .andExpect(view().name("login")).andExpect(model().attribute("prompts", hasKey("how")))
            .andExpect(model().attribute("prompts", hasKey("where")))
            .andExpect(model().attribute("prompts", not(hasKey("password"))));
}

From source file:eu.impress.impressplatform.IntegrationLayer.ResourcesMgmt.BedAvailabilityServiceBean.java

@Override
public String getBedAvailablityHAVEREST(String hospitalname) {

    //consume DHC rest service
    RestTemplate restTemplate = new RestTemplate();

    String s = restTemplate.getForObject(dhchost + "beds/available?hospital=" + hospitalname, String.class);
    log.info("URL query: " + dhchost + "beds/available?hospital=" + hospitalname);

    //return EDXL-HAVE
    return s;// w w  w. ja  v a2s  .  c  om
}

From source file:com.nestedbird.modules.soundcloudreader.SoundcloudReader.java

/**
 * This is the method that actually makes the http request
 *
 * @param url              request url/*  ww w .  j a  va 2  s. co m*/
 * @param deconstructClass class of request object
 * @param <T>              type of request object this is
 * @return request object
 */
private <T> T request(final String url, final Class<T> deconstructClass) {
    final RestTemplate restTemplate = new RestTemplate();
    T deconstructedResponse = null;

    try {
        deconstructedResponse = restTemplate.getForObject(url, deconstructClass);
    } catch (HttpClientErrorException err) {
        logger.info("[SoundcloudReader] [request] Failure To Retrieve SoundCloud Resource (" + url + ")", err);
    }

    return deconstructedResponse;
}

From source file:org.zalando.riptide.MapTest.java

public MapTest() {
    template = new RestTemplate();
    template.setMessageConverters(singletonList(
            new MappingJackson2HttpMessageConverter(new ObjectMapper().findAndRegisterModules())));
    template.setErrorHandler(new PassThroughResponseErrorHandler());
    this.server = MockRestServiceServer.createServer(template);
    this.unit = Rest.create(template);
}