Java 类org.springframework.http.client.InterceptingClientHttpRequestFactory 实例源码

项目:mojito    文件:FormLoginAuthenticationCsrfTokenInterceptor.java   
/**
 * 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));
}
项目:lams    文件:InterceptingHttpAccessor.java   
@Override
public ClientHttpRequestFactory getRequestFactory() {
    ClientHttpRequestFactory delegate = super.getRequestFactory();
    if (!CollectionUtils.isEmpty(getInterceptors())) {
        return new InterceptingClientHttpRequestFactory(delegate, getInterceptors());
    }
    else {
        return delegate;
    }
}
项目:swordfish-service    文件:RestTemplateConfig.java   
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));
}
项目:swordfish-service    文件:AuthenticatedRestTemplateImpl.java   
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));
}
项目:second-opinion-api    文件:MediaDownloadControllerIT.java   
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;
}
项目:spring-rest-basis    文件:Zg2proRestTemplate.java   
@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
            )
    );
}
项目:spring-rest-basis    文件:LogsTest.java   
/**
 * 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);
}
项目:spring4-understanding    文件:InterceptingHttpAccessor.java   
@Override
public ClientHttpRequestFactory getRequestFactory() {
    ClientHttpRequestFactory delegate = super.getRequestFactory();
    if (!CollectionUtils.isEmpty(getInterceptors())) {
        return new InterceptingClientHttpRequestFactory(delegate, getInterceptors());
    }
    else {
        return delegate;
    }
}
项目:mojito    文件:AuthenticatedRestTemplate.java   
/**
 * 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));
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:TestRestTemplate.java   
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));
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:TestRestTemplate.java   
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));
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:RemoteClientConfiguration.java   
@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);
}
项目:spring-boot-concourse    文件:TestRestTemplate.java   
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));
}
项目:spring-boot-concourse    文件:TestRestTemplate.java   
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));
}
项目:spring-boot-concourse    文件:RemoteClientConfiguration.java   
@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);
}
项目:contestparser    文件:TestRestTemplate.java   
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));
}
项目:contestparser    文件:RemoteClientConfiguration.java   
@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);
}
项目:ShoppingMall    文件:InterceptingHttpAccessor.java   
@Override
public ClientHttpRequestFactory getRequestFactory() {
    ClientHttpRequestFactory delegate = super.getRequestFactory();
    if (!CollectionUtils.isEmpty(getInterceptors())) {
        return new InterceptingClientHttpRequestFactory(delegate, getInterceptors());
    }
    else {
        return delegate;
    }
}
项目:midpoint    文件:RestService.java   
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);
        }
    });
}
项目:class-guard    文件:InterceptingHttpAccessor.java   
@Override
public ClientHttpRequestFactory getRequestFactory() {
    ClientHttpRequestFactory delegate = super.getRequestFactory();
    if (!CollectionUtils.isEmpty(getInterceptors())) {
        return new InterceptingClientHttpRequestFactory(delegate, getInterceptors());
    }
    else {
        return delegate;
    }
}
项目:raml-tester    文件:RamlRestTemplate.java   
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)));
}
项目:midpoint    文件:RestService.java   
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);
        }
    });
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:TestRestTemplateTests.java   
@Test
public void authenticated() {
    assertThat(new TestRestTemplate("user", "password").getRestTemplate()
            .getRequestFactory())
                    .isInstanceOf(InterceptingClientHttpRequestFactory.class);
}
项目:spring-boot-concourse    文件:TestRestTemplateTests.java   
@Test
public void authenticated() {
    assertThat(new TestRestTemplate("user", "password").getRestTemplate()
            .getRequestFactory())
                    .isInstanceOf(InterceptingClientHttpRequestFactory.class);
}
项目:contestparser    文件:TestRestTemplateTests.java   
@Test
public void authenticated() {
    assertTrue(new TestRestTemplate("user", "password")
            .getRequestFactory() instanceof InterceptingClientHttpRequestFactory);
}