Package org.springframework.web.client

Examples of org.springframework.web.client.RestTemplate


  private YarnContainerClusterOperations operations;

  @Before
  public void setUp() {
    restTemplate = new RestTemplate();
    mockServer = MockRestServiceServer.createServer(restTemplate);
    operations = new YarnContainerClusterTemplate("/" + YarnContainerClusterEndpoint.ENDPOINT_ID, restTemplate);
  }
View Full Code Here


    private HttpComponentsClientHttpRequestFactory httpFactory = new HttpComponentsClientHttpRequestFactory(httpClient);
    private Gson gson = new Gson(); // note that this doesn't serialize nulls by default

    @Override
    public RegisteredClient load(ServerConfiguration serverConfig) throws Exception {
      RestTemplate restTemplate = new RestTemplate(httpFactory);


      RegisteredClient knownClient = registeredClientService.getByIssuer(serverConfig.getIssuer());
      if (knownClient == null) {

        // dynamically register this client
        JsonObject jsonRequest = ClientDetailsEntityJsonProcessor.serialize(template);
        String serializedClient = gson.toJson(jsonRequest);

        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.APPLICATION_JSON);
        headers.setAccept(Lists.newArrayList(MediaType.APPLICATION_JSON));

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

        String registered = restTemplate.postForObject(serverConfig.getRegistrationEndpointUri(), entity, String.class);
        // TODO: handle HTTP errors

        RegisteredClient client = ClientDetailsEntityJsonProcessor.parseRegistered(registered);

        // save this client for later
        registeredClientService.save(serverConfig.getIssuer(), client);

        return client;
      } else {

        if (knownClient.getClientId() == null) {
       
          // load this client's information from the server
          HttpHeaders headers = new HttpHeaders();
          headers.set("Authorization", String.format("%s %s", OAuth2AccessToken.BEARER_TYPE, knownClient.getRegistrationAccessToken()));
          headers.setAccept(Lists.newArrayList(MediaType.APPLICATION_JSON));
 
          HttpEntity<String> entity = new HttpEntity<String>(headers);
 
          String registered = restTemplate.exchange(knownClient.getRegistrationClientUri(), HttpMethod.GET, entity, String.class).getBody();
          // TODO: handle HTTP errors
 
          RegisteredClient client = ClientDetailsEntityJsonProcessor.parseRegistered(registered);
 
          return client;
View Full Code Here

        ((DefaultHttpClient) requestFactory.getHttpClient()).getCredentialsProvider().setCredentials(
                requestFactory.getLoginAuthScope(), new UsernamePasswordCredentials(uid, pwd));
    }

    private RestTemplate getAnonymousRestTemplate() {
        RestTemplate template = new RestTemplate(httpClientFactory);
        List<HttpMessageConverter<?>> converters = new ArrayList<HttpMessageConverter<?>>();
        converters.add(mappingJacksonHttpMessageConverter);
        template.setMessageConverters(converters);
        template.setErrorHandler(new SyncopeClientErrorHandler());
        return template;
    }
View Full Code Here

        }
        add(selfRegFrag);
    }

    private String[] authenticate(final String userId, final String password) {
        final RestTemplate restTemplate = SyncopeSession.get().getRestTemplate();

        // 1. Set provided credentials to check
        PreemptiveAuthHttpRequestFactory requestFactory =
                ((PreemptiveAuthHttpRequestFactory) restTemplate.getRequestFactory());

        ((DefaultHttpClient) requestFactory.getHttpClient()).getCredentialsProvider().setCredentials(
                requestFactory.getLoginAuthScope(), new UsernamePasswordCredentials(userId, password));

        // 2. Search authorizations for user specified by credentials
View Full Code Here

                ? false
                : result.booleanValue();
    }

    private String getSyncopeVersion() {
        final RestTemplate restTemplate = SyncopeSession.get().getRestTemplate();

        PreemptiveAuthHttpRequestFactory requestFactory = ((PreemptiveAuthHttpRequestFactory) restTemplate.
                getRequestFactory());

        String version = "";
        try {
            HttpGet get = new HttpGet(baseURL + "../version.jsp");
View Full Code Here

    Proxy proxy = new Proxy(java.net.Proxy.Type.HTTP,
      new InetSocketAddress("devproxy.rz.is24.loc", 3128));
    requestFactory.setProxy(proxy);

    RestTemplate template = new RestTemplate(requestFactory);
    //template = new RestTemplate();


    String response = template.getForObject("http://www.google.pl", String.class);
    System.out.println(response.length());
  }
View Full Code Here

        ((DefaultHttpClient) requestFactory.getHttpClient()).getCredentialsProvider().setCredentials(
                requestFactory.getLoginAuthScope(), new UsernamePasswordCredentials(uid, pwd));
    }

    private RestTemplate getAnonymousRestTemplate() {
        RestTemplate template = new RestTemplate(httpClientFactory);
        List<HttpMessageConverter<?>> converters = new ArrayList<HttpMessageConverter<?>>();
        converters.add(mappingJacksonHttpMessageConverter);
        template.setMessageConverters(converters);
        template.setErrorHandler(new SyncopeClientErrorHandler());
        return template;
    }
View Full Code Here

        String authorisation = "rest" + ":" + "rest";
        byte[] encodedAuthorisation = Base64.encode(authorisation.getBytes());
        connection.setRequestProperty("Authorization", "Basic " + new String(encodedAuthorisation));
        }
        };
        rt = new RestTemplate(s);
        List<HttpMessageConverter<?>> l = new ArrayList<>();
        l.add(new MappingJacksonHttpMessageConverter());
        rt.setMessageConverters(l);
    }
View Full Code Here

        String authorisation = "rest" + ":" + "rest";
        byte[] encodedAuthorisation = Base64.encode(authorisation.getBytes());
        connection.setRequestProperty("Authorization", "Basic " + new String(encodedAuthorisation));
        }
        };
        rt = new RestTemplate(s);
        List<HttpMessageConverter<?>> l = new ArrayList<>();
        l.add(new MappingJacksonHttpMessageConverter());
        rt.setMessageConverters(l);
    }
View Full Code Here

    @Autowired
    protected DataSource testDataSource;

    protected RestTemplate anonymousRestTemplate() {
        return new RestTemplate();
    }
View Full Code Here

TOP

Related Classes of org.springframework.web.client.RestTemplate

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.