Java Code Examples for org.springframework.web.util.DefaultUriTemplateHandler#setBaseUrl()

The following examples show how to use org.springframework.web.util.DefaultUriTemplateHandler#setBaseUrl() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SmartlingClientConfiguration.java    From mojito with Apache License 2.0 5 votes vote down vote up
public OAuth2RestTemplate smartlingRestTemplate() {
    OAuth2RestTemplate oAuth2RestTemplate = new OAuth2RestTemplate(smartling(), new DefaultOAuth2ClientContext());

    RestTemplateUtils restTemplateUtils = new RestTemplateUtils();
    restTemplateUtils.enableFeature(oAuth2RestTemplate, DeserializationFeature.UNWRAP_ROOT_VALUE);

    AccessTokenProviderChain accessTokenProviderChain = new AccessTokenProviderChain(Arrays.asList(
            new SmartlingAuthorizationCodeAccessTokenProvider())
    );
    oAuth2RestTemplate.setAccessTokenProvider(accessTokenProviderChain);

    DefaultUriTemplateHandler defaultUriTemplateHandler = new DefaultUriTemplateHandler();
    defaultUriTemplateHandler.setBaseUrl(baseUri);

    oAuth2RestTemplate.setUriTemplateHandler(defaultUriTemplateHandler);

    oAuth2RestTemplate.setErrorHandler(new DefaultResponseErrorHandler() {
        @Override
        public void handleError(ClientHttpResponse response) throws IOException {
            try {
                super.handleError(response);
            } catch (HttpClientErrorException e) {
                if (resttemplateLogger.isDebugEnabled()) {
                    resttemplateLogger.debug(e.getResponseBodyAsString());
                }
                throw e;
            }
        }
    });

    return oAuth2RestTemplate;
}
 
Example 2
Source File: EvolveConfiguration.java    From mojito with Apache License 2.0 5 votes vote down vote up
RestTemplate evolveRestTemplate() {
    RestTemplate restTemplate = new RestTemplate();
    DefaultUriTemplateHandler defaultUriTemplateHandler = new DefaultUriTemplateHandler();
    defaultUriTemplateHandler.setBaseUrl(evolveConfigurationProperties.getUrl());
    restTemplate.setUriTemplateHandler(defaultUriTemplateHandler);

    restTemplate.getInterceptors().add(new ClientHttpRequestInterceptor() {
        @Override
        public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution) throws IOException {
            request.getHeaders().add(HttpHeaders.AUTHORIZATION, evolveConfigurationProperties.getToken());
            return execution.execute(request, body);
        }
    });

    restTemplate.setErrorHandler(new DefaultResponseErrorHandler() {
        @Override
        public void handleError(ClientHttpResponse response) throws IOException {
            try {
                super.handleError(response);
            } catch (HttpServerErrorException | HttpClientErrorException e) {
                resttemplateLogger.debug(e.getResponseBodyAsString());
                throw e;
            }
        }
    });

    return restTemplate;
}