當前位置: 首頁>>代碼示例>>Java>>正文


Java ClientHttpRequestInterceptor類代碼示例

本文整理匯總了Java中org.springframework.http.client.ClientHttpRequestInterceptor的典型用法代碼示例。如果您正苦於以下問題:Java ClientHttpRequestInterceptor類的具體用法?Java ClientHttpRequestInterceptor怎麽用?Java ClientHttpRequestInterceptor使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


ClientHttpRequestInterceptor類屬於org.springframework.http.client包,在下文中一共展示了ClientHttpRequestInterceptor類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: init

import org.springframework.http.client.ClientHttpRequestInterceptor; //導入依賴的package包/類
private void init(ApplicationContext ctx) {
	loadBalancedRestTemplate = new RestTemplate();
	SpringClientFactory springClientFactory = springClientFactory();
	springClientFactory.setApplicationContext(ctx);
	
	loadBalancerClient = new RibbonLoadBalancerClient(springClientFactory);
	
	//custom restTemplate
	LoadBalancerRequestFactory requestFactory = new LoadBalancerRequestFactory(loadBalancerClient, Collections.emptyList());
	LoadBalancerInterceptor interceptor = new LoadBalancerInterceptor(loadBalancerClient, requestFactory);
	
	List<ClientHttpRequestInterceptor> interceptors = loadBalancedRestTemplate.getInterceptors();
	ArrayList<ClientHttpRequestInterceptor> customedInterceptors = new ArrayList<>(interceptors.size() + 1);
	customedInterceptors.addAll(interceptors);
	customedInterceptors.add(interceptor);
	
	loadBalancedRestTemplate.setInterceptors(customedInterceptors);
}
 
開發者ID:QNJR-GROUP,項目名稱:EasyTransaction,代碼行數:19,代碼來源:RestRibbonEasyTransRpcConsumerImpl.java

示例2: createRestTemplate

import org.springframework.http.client.ClientHttpRequestInterceptor; //導入依賴的package包/類
private static RestTemplate createRestTemplate(String host, String username, String password, Set<ClientHttpRequestInterceptor> interceptors) throws GeneralSecurityException {
    CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
    credentialsProvider.setCredentials(new AuthScope(host, 25555),
        new UsernamePasswordCredentials(username, password));

    SSLContext sslContext = SSLContexts.custom()
        .loadTrustMaterial(null, new TrustSelfSignedStrategy())
        .useTLS()
        .build();

    SSLConnectionSocketFactory connectionFactory = new SSLConnectionSocketFactory(sslContext, new AllowAllHostnameVerifier());

    HttpClient httpClient = HttpClientBuilder.create()
        .disableRedirectHandling()
        .setDefaultCredentialsProvider(credentialsProvider)
        .setSSLSocketFactory(connectionFactory)
        .build();

    RestTemplate restTemplate = new RestTemplate(new HttpComponentsClientHttpRequestFactory(httpClient));
    restTemplate.getInterceptors().addAll(interceptors);

    return restTemplate;
}
 
開發者ID:strepsirrhini-army,項目名稱:chaos-lemur,代碼行數:24,代碼來源:StandardDirectorUtils.java

示例3: getTemplate

import org.springframework.http.client.ClientHttpRequestInterceptor; //導入依賴的package包/類
public static RestTemplate getTemplate(ClientHttpRequestInterceptor interceptor) {
    RestTemplate restTemplate = new RestTemplate();

    List<ClientHttpRequestInterceptor> ris = new ArrayList<>();
    ris.add(interceptor);
    restTemplate.setInterceptors(ris);
    SimpleClientHttpRequestFactory httpFactory = new SimpleClientHttpRequestFactory();
    httpFactory.setOutputStreaming(false);
    restTemplate.setRequestFactory(new BufferingClientHttpRequestFactory(httpFactory));
    restTemplate.getMessageConverters().add(0, new StringHttpMessageConverter(Charset.forName("UTF-8")));
    return restTemplate;
}
 
開發者ID:xm-online,項目名稱:xm-uaa,代碼行數:13,代碼來源:TemplateUtil.java

示例4: TracingRestTemplateTest

import org.springframework.http.client.ClientHttpRequestInterceptor; //導入依賴的package包/類
public TracingRestTemplateTest() {
    final RestTemplate restTemplate = new RestTemplate();
    restTemplate.setInterceptors(Collections.<ClientHttpRequestInterceptor>singletonList(
            new TracingRestTemplateInterceptor(mockTracer)));

    client = new Client<RestTemplate>() {
        @Override
        public <T> ResponseEntity<T> getForEntity(String url, Class<T> clazz) {
            return restTemplate.getForEntity(url, clazz);
        }

        @Override
        public RestTemplate template() {
            return restTemplate;
        }
    };

    mockServer = MockRestServiceServer.bindTo(client.template()).build();
}
 
開發者ID:opentracing-contrib,項目名稱:java-spring-web,代碼行數:20,代碼來源:TracingRestTemplateTest.java

示例5: setApiKey

import org.springframework.http.client.ClientHttpRequestInterceptor; //導入依賴的package包/類
/**
 * Sets the api key.
 *
 * @throws JsonParseException the json parse exception
 * @throws JsonMappingException the json mapping exception
 * @throws IOException Signals that an I/O exception has occurred.
 */
private void setApiKey() throws JsonParseException, JsonMappingException, IOException{
	ArrayList<ClientHttpRequestInterceptor> interceptors = new ArrayList<ClientHttpRequestInterceptor>();
	interceptors.add((HttpRequest request, byte[] body, ClientHttpRequestExecution execution) -> {
		if(body.length > 0) {
			body = addTokenInObject(body, new JsonNodeFormatter());
		}else{
			try {
				request = addTokenInURI(request);
			} catch (URISyntaxException e) {
				e.printStackTrace();
			}
		}
		return execution.execute(request, body);
	});
	this.restTemplate.setInterceptors(interceptors);
}
 
開發者ID:ac-silva,項目名稱:desafio-pagarme,代碼行數:24,代碼來源:Client.java

示例6: doGet

import org.springframework.http.client.ClientHttpRequestInterceptor; //導入依賴的package包/類
/**
 * 通過urlhttp的get的請求,適合無參的場景<br>
 * @param restPath
 * @return T
 * @Author fanyaowu
 * @data 2014年7月11日
 * @exception
 * @version
 *
 */
public static <T> T doGet(String restPath, Class<T> responseType, MediaType mediaType)
    throws RestInvocationException
{
    
    try
    {
        ClientHttpRequestInterceptor requestInterceptor = new AcceptHeaderHttpRequestInterceptor(mediaType);
        
        restTemplate.setInterceptors(Collections.singletonList(requestInterceptor));
        
        return restTemplate.getForObject(restPath, responseType);
        
    }
    catch (Exception e)
    {
        throw new RestInvocationException("Failed to request get url: " + restPath, e);
    }
}
 
開發者ID:marlonwang,項目名稱:raven,代碼行數:29,代碼來源:RestServiceUtils.java

示例7: testZg2Template

import org.springframework.http.client.ClientHttpRequestInterceptor; //導入依賴的package包/類
@Test
public void testZg2Template() {
    Zg2proRestTemplate z0 = new Zg2proRestTemplate();
    assertThat(z0.getErrorHandler()).isInstanceOf(RestTemplateErrorHandler.class);
    assertThat(z0.getInterceptors().size()).isGreaterThan(0);
    List<ClientHttpRequestInterceptor> lInterceptors = new ArrayList<>();
    lInterceptors.add(new LoggingRequestInterceptor());
    List<HttpMessageConverter<?>> covs = z0.getMessageConverters();
    z0 = new Zg2proRestTemplate(null, lInterceptors);
    assertThat(z0).isNotNull();
    Zg2proRestTemplate z = new Zg2proRestTemplate(covs, null);
    z.setInterceptors(lInterceptors);
    assertThat(z.getInterceptors().size()).isGreaterThan(0);
    z.setRequestFactory(LoggingRequestFactoryFactory.build());
    assertThat(z.getInterceptors().size()).isGreaterThan(0);
    assertThat(z.getErrorHandler()).isInstanceOf(RestTemplateErrorHandler.class);
    rt.getRestTemplate().setRequestFactory(z.getRequestFactory());
    ResponseEntity<String> resp;
    resp = rt.getForEntity(MockedControllers.TEST_URL_GET_BLANK_REPLY, String.class);
    assertNotNull(resp);
    ReturnedStructure rs = rt.getForObject(TEST_URL_GET_STRUCTURE, ReturnedStructure.class);
    assertThat(rs.getFieldOne()).isEqualTo(12);
}
 
開發者ID:zg2pro,項目名稱:spring-rest-basis,代碼行數:24,代碼來源:LogsTest.java

示例8: MMLWebFeatureServiceRequestTemplate

import org.springframework.http.client.ClientHttpRequestInterceptor; //導入依賴的package包/類
public MMLWebFeatureServiceRequestTemplate(MMLProperties mmlProperties, ClientHttpRequestFactory clientHttpRequestFactory) {
    this.mmlProperties = mmlProperties;
    this.restTemplate = new RestTemplate(clientHttpRequestFactory);

    final List<MediaType> xmlMediaTypes = Lists.newArrayList(
            MediaType.APPLICATION_XML, MediaType.TEXT_XML,
            new MediaType("application", "*+xml"),
            new MediaType("application", "vnd.ogc.se_xml"));

    final SourceHttpMessageConverter<Source> xmlConverter = new SourceHttpMessageConverter<>();
    xmlConverter.setSupportedMediaTypes(xmlMediaTypes);

    final List<HttpMessageConverter<?>> messageConverters = new ArrayList<>();
    messageConverters.add(xmlConverter);

    final List<ClientHttpRequestInterceptor> interceptors = new ArrayList<>();
    interceptors.add(new BasicAuthenticationClientInterceptor(
            mmlProperties.getWfsUsername(), mmlProperties.getWfsPassword()));

    this.restTemplate.setMessageConverters(messageConverters);
    this.restTemplate.setInterceptors(interceptors);
}
 
開發者ID:suomenriistakeskus,項目名稱:oma-riista-web,代碼行數:23,代碼來源:MMLWebFeatureServiceRequestTemplate.java

示例9: doCall

import org.springframework.http.client.ClientHttpRequestInterceptor; //導入依賴的package包/類
public void doCall() {
    RestTemplate restTemplate = new RestTemplate();
    ClientHttpRequestInterceptor ri = new LoggingRequestInterceptor();
    List<ClientHttpRequestInterceptor> ris = new ArrayList<ClientHttpRequestInterceptor>();
    ris.add(ri);
    restTemplate.setInterceptors(ris);
    
    MultiValueMap<String, String> map = new LinkedMultiValueMap<String, String>();
    map.add("grant_type", "client_credentials");

    HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);  
    headers.add("Authorization", "Basic " + credentialsBuilder.getCredentialsString());
    headers.add("Accept", "*/*");

    HttpEntity<MultiValueMap<String, String>> requestEntity = new HttpEntity<>(map, headers);
    List<HttpMessageConverter<?>> messageConverters = new ArrayList<HttpMessageConverter<?>>();
    messageConverters.add(new FormHttpMessageConverter());
    messageConverters.add(new MappingJackson2HttpMessageConverter());
    restTemplate.setMessageConverters(messageConverters);
    AuthResponse authToken = restTemplate.postForObject(config.getRestProperty("environment") + "/v2/auth/token", requestEntity, AuthResponse.class);
    tokenHolder.resetToken(authToken);
    
}
 
開發者ID:SabreDevStudio,項目名稱:SACS-Java,代碼行數:25,代碼來源:AuthenticationCall.java

示例10: init

import org.springframework.http.client.ClientHttpRequestInterceptor; //導入依賴的package包/類
/**
 * Init
 */
@PostConstruct
protected void init() {

    restTemplateForAuthenticationFlow = new CookieStoreRestTemplate();
    cookieStore = restTemplateForAuthenticationFlow.getCookieStore();

    logger.debug("Inject cookie store used in the rest template for authentication flow into the authRestTemplate so that they will match");
    authRestTemplate.restTemplate.setCookieStoreAndUpdateRequestFactory(cookieStore);

    List<ClientHttpRequestInterceptor> interceptors = Collections
            .<ClientHttpRequestInterceptor>singletonList(new ClientHttpRequestInterceptor() {
                @Override
                public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution) throws IOException {
                    if (latestCsrfToken != null) {
                        // At the beginning of auth flow, there's no token yet
                        injectCsrfTokenIntoHeader(request, latestCsrfToken);
                    }
                    return execution.execute(request, body);
                }
            });

    restTemplateForAuthenticationFlow.setRequestFactory(new InterceptingClientHttpRequestFactory(restTemplateForAuthenticationFlow.getRequestFactory(), interceptors));
}
 
開發者ID:box,項目名稱:mojito,代碼行數:27,代碼來源:FormLoginAuthenticationCsrfTokenInterceptor.java

示例11: getCustomerAccountServiceRestTemplate

import org.springframework.http.client.ClientHttpRequestInterceptor; //導入依賴的package包/類
@Bean(name = "customerAccountServiceRestTemplate")
public RestOperations getCustomerAccountServiceRestTemplate() {

    LOGGER.info("getCustomerAccountServiceRestTemplate()");

    AccessTokenRequest atr = new DefaultAccessTokenRequest();
    OAuth2RestTemplate restTemplate = new OAuth2RestTemplate(getResourceDetails(), new DefaultOAuth2ClientContext(atr));

    // Setting the interceptors to add YaaS specific http header properties
    List<ClientHttpRequestInterceptor> listOfInterceptors = new ArrayList<>();
    listOfInterceptors.add(new YaasRequestInterceptor());
    listOfInterceptors.add(new DebugClientHttpRequestInterceptor());

    restTemplate.setInterceptors(listOfInterceptors);

    // Setting the response error handler for the rest template
    restTemplate.setErrorHandler(new CustomerAccountResponseErrorHandler());

    return restTemplate;
}
 
開發者ID:fdlessard,項目名稱:YaasRestClientProject,代碼行數:21,代碼來源:SpringOAuth2ConfigurationProfile.java

示例12: clientHttpRequestFactory

import org.springframework.http.client.ClientHttpRequestInterceptor; //導入依賴的package包/類
@Bean
public ClientHttpRequestFactory clientHttpRequestFactory() {
	List<ClientHttpRequestInterceptor> interceptors = Arrays
			.asList(getSecurityInterceptor());
	SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory();
	Proxy proxy = this.properties.getRemote().getProxy();
	if (proxy.getHost() != null && proxy.getPort() != null) {
		requestFactory.setProxy(new java.net.Proxy(Type.HTTP,
				new InetSocketAddress(proxy.getHost(), proxy.getPort())));
	}
	return new InterceptingClientHttpRequestFactory(requestFactory, interceptors);
}
 
開發者ID:vikrammane23,項目名稱:https-github.com-g0t4-jenkins2-course-spring-boot,代碼行數:13,代碼來源:RemoteClientConfiguration.java

示例13: doInBackground

import org.springframework.http.client.ClientHttpRequestInterceptor; //導入依賴的package包/類
@Override
protected Void doInBackground(Class<RSP>... params) {
    RestTemplate restTemplate = new RestTemplate();
    List<ClientHttpRequestInterceptor> ris = new ArrayList<>();
    ris.add(new LoggingRequestInterceptor());
    ris.add(new AuthenticatingGetInterceptor());
    restTemplate.setInterceptors(ris);

    BaseDomainResponse<RSP> result = new BaseDomainResponse<>();
    try {
        result.setResult(restTemplate.getForObject(getRequestString(), params[0], new Object[]{}));
    } catch (HttpClientErrorException e) {
        result.setStatus(e.getStatusCode().value());
        context.setFaulty(true);
    }

    block.offer((BaseDomainResponse<RS>) result);
    return null;
}
 
開發者ID:SabreDevStudio,項目名稱:SACS-Android,代碼行數:20,代碼來源:GenericRestGetCall.java

示例14: doInBackground

import org.springframework.http.client.ClientHttpRequestInterceptor; //導入依賴的package包/類
@Override
protected AuthResponse doInBackground(Void... params) {
    RestTemplate restTemplate = new RestTemplate();
    ClientHttpRequestInterceptor ri = new LoggingRequestInterceptor();
    List<ClientHttpRequestInterceptor> ris = new ArrayList<>();
    ris.add(ri);
    restTemplate.setInterceptors(ris);

    MultiValueMap<String, String> map = new LinkedMultiValueMap<>();
    map.add("grant_type", "client_credentials");

    HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
    headers.add("Authorization", "Basic " + credentialsBuilder.getCredentialsString());
    headers.add("Accept", "*/*");

    HttpEntity<MultiValueMap<String, String>> requestEntity = new HttpEntity<>(map, headers);
    List<HttpMessageConverter<?>> messageConverters = new ArrayList<>();
    messageConverters.add(new FormHttpMessageConverter());
    messageConverters.add(new MappingJackson2HttpMessageConverter());
    restTemplate.setMessageConverters(messageConverters);
    AuthResponse authToken = restTemplate.postForObject(config.getRestProperty("environment") + "/v2/auth/token", requestEntity, AuthResponse.class);
    block.offer(authToken);
    return authToken;
}
 
開發者ID:SabreDevStudio,項目名稱:SACS-Android,代碼行數:26,代碼來源:AuthenticationCall.java

示例15: userInfoRestTemplate

import org.springframework.http.client.ClientHttpRequestInterceptor; //導入依賴的package包/類
@Bean(name = "userInfoRestTemplate")
public OAuth2RestTemplate userInfoRestTemplate() {
	if (this.details == null) {
		this.details = DEFAULT_RESOURCE_DETAILS;
	}
	OAuth2RestTemplate template = getTemplate();
	template.setInterceptors(Arrays.<ClientHttpRequestInterceptor>asList(
			new AcceptJsonRequestInterceptor()));
	AuthorizationCodeAccessTokenProvider accessTokenProvider = new AuthorizationCodeAccessTokenProvider();
	accessTokenProvider.setTokenRequestEnhancer(new AcceptJsonRequestEnhancer());
	template.setAccessTokenProvider(accessTokenProvider);
	AnnotationAwareOrderComparator.sort(this.customizers);
	for (UserInfoRestTemplateCustomizer customizer : this.customizers) {
		customizer.customize(template);
	}
	return template;
}
 
開發者ID:Nephilim84,項目名稱:contestparser,代碼行數:18,代碼來源:ResourceServerTokenServicesConfiguration.java


注:本文中的org.springframework.http.client.ClientHttpRequestInterceptor類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。