本文整理汇总了Java中org.springframework.http.client.InterceptingClientHttpRequestFactory类的典型用法代码示例。如果您正苦于以下问题:Java InterceptingClientHttpRequestFactory类的具体用法?Java InterceptingClientHttpRequestFactory怎么用?Java InterceptingClientHttpRequestFactory使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
InterceptingClientHttpRequestFactory类属于org.springframework.http.client包,在下文中一共展示了InterceptingClientHttpRequestFactory类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: init
import org.springframework.http.client.InterceptingClientHttpRequestFactory; //导入依赖的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));
}
示例2: clientHttpRequestFactory
import org.springframework.http.client.InterceptingClientHttpRequestFactory; //导入依赖的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
示例3: getRequestFactory
import org.springframework.http.client.InterceptingClientHttpRequestFactory; //导入依赖的package包/类
@Override
public ClientHttpRequestFactory getRequestFactory() {
ClientHttpRequestFactory delegate = super.getRequestFactory();
if (!CollectionUtils.isEmpty(getInterceptors())) {
return new InterceptingClientHttpRequestFactory(delegate, getInterceptors());
}
else {
return delegate;
}
}
示例4: addAuthentication
import org.springframework.http.client.InterceptingClientHttpRequestFactory; //导入依赖的package包/类
private void addAuthentication() {
if (StringUtils.isEmpty(username)) {
throw new RuntimeException("Username is mandatory for Basic Auth");
}
List<ClientHttpRequestInterceptor> interceptors = Collections
.singletonList(new BasicAuthInterceptor(username, password));
setRequestFactory(new InterceptingClientHttpRequestFactory(getRequestFactory(),
interceptors));
}
示例5: getRawRestTemplate
import org.springframework.http.client.InterceptingClientHttpRequestFactory; //导入依赖的package包/类
private RestTemplate getRawRestTemplate() {
RestTemplate restTemplate = new RestTemplate();
restTemplate.getMessageConverters().add(
new ByteArrayHttpMessageConverter());
restTemplate.setRequestFactory(
new InterceptingClientHttpRequestFactory(
restTemplate.getRequestFactory(),
Collections.singletonList(
new BasicAuthorizationInterceptor("1", "1"))));
return restTemplate;
}
示例6: interceptorsIntegration
import org.springframework.http.client.InterceptingClientHttpRequestFactory; //导入依赖的package包/类
@Override
protected void interceptorsIntegration(List<ClientHttpRequestInterceptor> lInterceptors, Object sslConfiguration) {
this.setInterceptors(lInterceptors);
SimpleClientHttpRequestFactory chrf = new SimpleClientHttpRequestFactory();
chrf.setOutputStreaming(false);
this.setRequestFactory(
new InterceptingClientHttpRequestFactory(
new BufferingClientHttpRequestFactory(chrf),
lInterceptors
)
);
}
示例7: testInterceptor
import org.springframework.http.client.InterceptingClientHttpRequestFactory; //导入依赖的package包/类
/**
* hard to check the logs provided by the interceptor when there's no error
* however this unit test garantees the interceptor does not alter the reply
* from the rest service.
*/
@Test
public void testInterceptor() {
List<ClientHttpRequestInterceptor> lInterceptors = new ArrayList<>();
//spring boot default log level is info
lInterceptors.add(new LoggingRequestInterceptor(StandardCharsets.ISO_8859_1, 100, Level.ERROR));
SimpleClientHttpRequestFactory chrf = new SimpleClientHttpRequestFactory();
chrf.setOutputStreaming(false);
rt.getRestTemplate().setRequestFactory(new InterceptingClientHttpRequestFactory(
new BufferingClientHttpRequestFactory(chrf),
lInterceptors
));
ResponseEntity<String> resp = rt.getForEntity(MockedControllers.TEST_URL_GET, String.class);
assertThat(resp.getBody()).isEqualTo(MockedControllers.TEST_RETURN_VALUE);
}
示例8: init
import org.springframework.http.client.InterceptingClientHttpRequestFactory; //导入依赖的package包/类
/**
* Initialize the internal restTemplate instance
*/
@PostConstruct
protected void init() {
logger.debug("Create the RestTemplate instance that will be wrapped");
makeRestTemplateWithCustomObjectMapper(restTemplate);
logger.debug("Set interceptor for authentication");
List<ClientHttpRequestInterceptor> interceptors = Collections
.<ClientHttpRequestInterceptor>singletonList(formLoginAuthenticationCsrfTokenInterceptor);
restTemplate.setRequestFactory(new InterceptingClientHttpRequestFactory(restTemplate.getRequestFactory(), interceptors));
}
示例9: addAuthentication
import org.springframework.http.client.InterceptingClientHttpRequestFactory; //导入依赖的package包/类
private void addAuthentication(RestTemplate restTemplate, String username,
String password) {
if (username == null) {
return;
}
List<ClientHttpRequestInterceptor> interceptors = Collections
.<ClientHttpRequestInterceptor>singletonList(
new BasicAuthorizationInterceptor(username, password));
restTemplate.setRequestFactory(new InterceptingClientHttpRequestFactory(
restTemplate.getRequestFactory(), interceptors));
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:12,代码来源:TestRestTemplate.java
示例10: addAuthentication
import org.springframework.http.client.InterceptingClientHttpRequestFactory; //导入依赖的package包/类
private void addAuthentication(String username, String password) {
if (username == null) {
return;
}
List<ClientHttpRequestInterceptor> interceptors = Collections
.<ClientHttpRequestInterceptor>singletonList(
new BasicAuthorizationInterceptor(username, password));
setRequestFactory(new InterceptingClientHttpRequestFactory(getRequestFactory(),
interceptors));
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:11,代码来源:TestRestTemplate.java
示例11: RestService
import org.springframework.http.client.InterceptingClientHttpRequestFactory; //导入依赖的package包/类
public RestService(String url, String username, String password) {
this.url = url;
template = new RestTemplate();
List<ClientHttpRequestInterceptor> interceptors = new ArrayList<>();
if (username != null) {
interceptors.add(new BasicAuthenticationInterceptor(username, password));
}
interceptors.add(new LoggingInterceptor());
template.setRequestFactory(
new InterceptingClientHttpRequestFactory(template.getRequestFactory(), interceptors));
prismContext = ProxyCreator.getProxy(PrismContext.class, () -> {
try {
PrismContextFactory factory = new MidPointPrismContextFactory() {
@Override
protected void registerExtensionSchemas(SchemaRegistryImpl schemaRegistry)
throws SchemaException, FileNotFoundException {
super.registerExtensionSchemas(schemaRegistry);
RestService.this.registerExtensionSchemas(schemaRegistry);
}
};
return factory.createPrismContext();
} catch (SchemaException | FileNotFoundException ex) {
throw new NinjaException("Couldn't load prism context", ex);
}
});
}
示例12: RamlRestTemplate
import org.springframework.http.client.InterceptingClientHttpRequestFactory; //导入依赖的package包/类
private RamlRestTemplate(RamlChecker ramlChecker, boolean notSending, ReportStore reportStore, ClientHttpRequestFactory requestFactory) {
this.ramlChecker = ramlChecker;
this.notSending = notSending;
this.reportStore = reportStore;
this.originalRequestFactory = requestFactory;
final RamlRequestInterceptor interceptor = new RamlRequestInterceptor(ramlChecker, notSending, reportStore);
setRequestFactory(new InterceptingClientHttpRequestFactory(
new BufferingClientHttpRequestFactory(requestFactory), Collections.<ClientHttpRequestInterceptor>singletonList(interceptor)));
}
示例13: authenticated
import org.springframework.http.client.InterceptingClientHttpRequestFactory; //导入依赖的package包/类
@Test
public void authenticated() {
assertThat(new TestRestTemplate("user", "password").getRestTemplate()
.getRequestFactory())
.isInstanceOf(InterceptingClientHttpRequestFactory.class);
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:7,代码来源:TestRestTemplateTests.java
示例14: authenticated
import org.springframework.http.client.InterceptingClientHttpRequestFactory; //导入依赖的package包/类
@Test
public void authenticated() {
assertTrue(new TestRestTemplate("user", "password")
.getRequestFactory() instanceof InterceptingClientHttpRequestFactory);
}