当前位置: 首页>>代码示例>>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;未经允许,请勿转载。