Package org.springframework.web.client

Examples of org.springframework.web.client.RestTemplate


    /**
     * Create a JSON REST Template for requests
     * @return a RestTemplate configured to process JSON data
     */
    private RestTemplate getRestJsonTemplate(){
        RestTemplate restTemplate = new RestTemplate();
        List<HttpMessageConverter<?>> mc = restTemplate.getMessageConverters();
        // Add JSON message handler
        MappingJacksonHttpMessageConverter json = new MappingJacksonHttpMessageConverter();
        List<MediaType> supportedMediaTypes = new ArrayList<MediaType>();
        supportedMediaTypes.add(new MediaType("application","json", Charset.forName("UTF-8")));
        // Add default media type in case marketplace uses incorrect MIME type, otherwise
        // Spring refuses to process it, even if its valid JSON
        supportedMediaTypes.add(new MediaType("application","octet-stream", Charset.forName("UTF-8")));
        json.setSupportedMediaTypes(supportedMediaTypes);
        mc.add(json);
        restTemplate.setMessageConverters(mc);
        return restTemplate;
    }
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.getAuthScope(), 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

        ((DefaultHttpClient) requestFactory.getHttpClient()).getCredentialsProvider().setCredentials(
                requestFactory.getAuthScope(), 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

  @RequestMapping(value="/{time}", method = RequestMethod.GET)
  public @ResponseBody MyData getMyData(
      @PathVariable long time) {
   
    RestTemplate restTemplate = new RestTemplate();
   
    String remote = "http://localhost:8585/spring-server-side-rest-call/"
      + "MyRemoteData/" + System.currentTimeMillis();
   
    MyRemoteData mrd = restTemplate.getForObject(
      remote, MyRemoteData.class);
   
    return new MyData(System.currentTimeMillis(), mrd.getData());
   
  }
View Full Code Here

    @Autowired
    protected DataSource testDataSource;

    protected RestTemplate anonymousRestTemplate() {
        return new RestTemplate();
    }
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.getAuthScope(), new UsernamePasswordCredentials(userId, password));

        // 2. Search authorizations for user specified by credentials
        return restTemplate.getForObject(baseURL + "auth/entitlements.json", String[].class);
    }
View Full Code Here

    }

    private boolean isSelfRegistrationAllowed() {
        Boolean result = null;
        try {
            final RestTemplate restTemplate = SyncopeSession.get().getRestTemplate();
            result = restTemplate.getForObject(baseURL + "user/request/create/allowed", Boolean.class);
        } catch (HttpClientErrorException e) {
            LOG.error("While seeking if self registration is allowed", e);
        }

        return result == null
View Full Code Here

                ? false
                : result.booleanValue();
    }

    private String getCoreVersion() {
        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

        super(baseUrl, restTemplate);
    }

    @Override
    public Set<EntitlementTO> getAllEntitlements() {
        Set<String> entitlements = new HashSet<String>(Arrays.asList(new RestTemplate().getForObject(
                baseUrl + "auth/allentitlements.json", String[].class)));
        return CollectionWrapper.wrap(entitlements);
    }
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.