/**
  * The RestTemplate works because it uses a custom request-factory that uses Ribbon to look-up the
  * service to use. This method simply exists to show this.
  */
 @PostConstruct
 public void demoOnly() {
   // Can't do this in the constructor because the RestTemplate injection
   // happens afterwards.
   logger.warning(
       "The RestTemplate request factory is " + restTemplate.getRequestFactory().getClass());
 }
Esempio n. 2
0
 protected ResourceOwnerPasswordAccessTokenProvider
     createResourceOwnerPasswordAccessTokenProvider() {
   ResourceOwnerPasswordAccessTokenProvider resourceOwnerPasswordAccessTokenProvider =
       new ResourceOwnerPasswordAccessTokenProvider();
   resourceOwnerPasswordAccessTokenProvider.setRequestFactory(
       restTemplate.getRequestFactory()); // copy the http proxy along
   return resourceOwnerPasswordAccessTokenProvider;
 }
  @Test
  public void loginTestForOauthClient() throws MalformedURLException {
    String token = "12345678";
    RestTemplate restTemplate = mock(RestTemplate.class);
    ClientHttpRequestFactory requestFactory = mock(ClientHttpRequestFactory.class);
    OAuth2AccessToken oauthToken = mock(OAuth2AccessToken.class);
    when(restTemplate.getRequestFactory()).thenReturn(requestFactory);
    when(restTemplate.execute(
            anyString(),
            any(HttpMethod.class),
            any(RequestCallback.class),
            any(ResponseExtractor.class),
            any(Map.class)))
        .thenReturn(oauthToken);
    when(oauthToken.getValue()).thenReturn(token);
    when(oauthToken.getTokenType()).thenReturn("bearer");

    // Run Test
    OauthClient oauthClient = new OauthClient(new URL("http://uaa.cloud.me"), restTemplate);
    OAuth2AccessToken ouathToken = oauthClient.getToken("*****@*****.**", "passwd");
    String loginToken = oauthToken.getValue();
    assertThat(loginToken, is(token));
  }
 private void configureCloudFoundryRequestFactory(RestTemplate restTemplate) {
   ClientHttpRequestFactory requestFactory = restTemplate.getRequestFactory();
   restTemplate.setRequestFactory(new CloudFoundryClientHttpRequestFactory(requestFactory));
 }