Package org.springframework.web.client

Examples of org.springframework.web.client.RestTemplate$AcceptHeaderRequestCallback


    /**
     * 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
        MappingJackson2HttpMessageConverter json = new MappingJackson2HttpMessageConverter();
        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


    private ObjectMapper mapper;

    public ZencoderClient(String api_key) {
        this.api_key = api_key;
        this.api_url = API_URL;
        this.rt = new RestTemplate();
        this.mapper = createObjectMapper();
    }
View Full Code Here

       *   /*POST https://www.googleapis.com/urlshortener/v1/url
    Content-Type: application/json

    {"longUrl": "http://www.google.com/"}
       */
      RestTemplate template = new RestTemplate();
      List<HttpMessageConverter<?>> messageConverters = new ArrayList<HttpMessageConverter<?>>();
     messageConverters.add(new MappingJacksonHttpMessageConverter());
      template.setMessageConverters(messageConverters);
         //now we need to add the parameters
      String apiKey = this.searchConfigRetriever.getArbitrary("googleAPIKey");

       LinkShortenRequestGoogle postObject = new LinkShortenRequestGoogle(longUrl);
       LinkShortenReturnGoogle result = template.postForObject(url + apiKey, postObject, LinkShortenReturnGoogle.class);

       return result.getId();
    }
View Full Code Here

        } else {
          this.anonymous = true;
        }
      HttpComponentsClientHttpRequestFactory factory = new HttpComponentsClientHttpRequestFactory(httpclient);
     
          this.restTemplate = new RestTemplate(factory);
         
          this.allTags = new HashSet<String>();
          logger.info("client initialized");
      }
View Full Code Here

   * with {@link HttpComponentsClientHttpRequestFactory}.
   *
   * @param baseUri the base uri
   */
  public YarnContainerClusterTemplate(String baseUri) {
    this.restTemplate = new RestTemplate(new HttpComponentsClientHttpRequestFactory());
    this.baseUri = baseUri;
  }
View Full Code Here

  /**
   * @param args
   */
  public static void main(String[] args) throws Exception{
    RestTemplate template = new RestTemplate();
    Resource s2logo = new ClassPathResource(resourcePath);
    MultiValueMap<String, Object> multipartMap = new LinkedMultiValueMap<String, Object>();
    multipartMap.add("company", "SpringSource");
    multipartMap.add("company-logo", s2logo);
    logger.info("Created multipart request: " + multipartMap);
    HttpHeaders headers = new HttpHeaders();
    headers.setContentType(new MediaType("multipart", "form-data"));
    HttpEntity<Object> request = new HttpEntity<Object>(multipartMap, headers);
    logger.info("Posting request to: " + uri);
    ResponseEntity<?> httpResponse = template.exchange(uri, HttpMethod.POST, request, Object.class);
    if (!httpResponse.getStatusCode().equals(HttpStatus.OK)){
      logger.error("Problems with the request. Http status: " + httpResponse.getStatusCode());
    }
  }
View Full Code Here

* Time: 4:24 PM
*/
public class RestTemplateClient implements Client {
    @Override
    public Response execute(Request request, Request.Options options) throws IOException {
        RestTemplate restTemplate = new RestTemplate();
        HttpMethod method = HttpMethod.valueOf(request.method());

        HttpHeaders requestHeaders = new HttpHeaders();
        for (String header: request.headers().keySet()) {
            Collection<String> values = request.headers().get(header);
            if (values != null && !values.isEmpty())
                requestHeaders.put(header, new ArrayList<>(values));
        }

        HttpEntity<byte[]> httpEntity = new HttpEntity<>(request.body(), requestHeaders);

        ResponseEntity<byte[]> responseEntity = restTemplate.exchange(request.url(), method, httpEntity, byte[].class);

        Map<String, Collection<String>> headers = new HashMap<>();

        for (String header: responseEntity.getHeaders().keySet()) {
            headers.put(header, responseEntity.getHeaders().get(header));
View Full Code Here

        // create message converters list
        List<HttpMessageConverter<?>> httpMessageConverters = new ArrayList<HttpMessageConverter<?>>();
        httpMessageConverters.add(mappingJacksonHttpMessageConverter);

        // create rest template
        RestTemplate restTemplate = new RestTemplate();
        restTemplate.setMessageConverters(httpMessageConverters);

        // configure proxy
        if (Boolean.parseBoolean(System.getProperty("proxySet"))) {
            HttpHost httpHost = new HttpHost(System.getProperty("http.proxyHost"), Integer.parseInt(System.getProperty("http.proxyPort")));
            DefaultProxyRoutePlanner defaultProxyRoutePlanner = new DefaultProxyRoutePlanner(httpHost);
            HttpClient httpClient = HttpClients.custom().setRoutePlanner(defaultProxyRoutePlanner).build();
//            todo - need to support SOCKS protocol for this solution to work - jamesdbloom 12/01/2014
//            HttpClient httpClient = HttpClients.custom().setRoutePlanner(new SystemDefaultRoutePlanner(PROXY_SELECTOR.getDefault())).build();
            restTemplate.setRequestFactory(new HttpComponentsClientHttpRequestFactory(httpClient));
        }

        return restTemplate;
    }
View Full Code Here

    BasicCredentialsProvider credentialsProvider =  new BasicCredentialsProvider();
    credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(adminUser, adminPass));
    client.setCredentialsProvider(credentialsProvider);
    ClientHttpRequestFactory rf = new HttpComponentsClientHttpRequestFactory(client);

    RestTemplate template = new RestTemplate(rf);

    String fullUri = "http://" + hostUri + ":8091/pools/default/buckets/default";

    ResponseEntity<String> entity = null;
    try {
      entity = template.getForEntity(fullUri, String.class);
    } catch (HttpClientErrorException ex) {
      logger.info("Got execpetion while looking for bucket: " + ex.getMessage());
      if (ex.getMessage().equals("404 Object Not Found")) {
        logger.info("Creating default bucket with admin credentials.");
        createBucket();
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

TOP

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

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.