Java Code Examples for org.apache.cxf.jaxrs.client.JAXRSClientFactoryBean#setThreadSafe()

The following examples show how to use org.apache.cxf.jaxrs.client.JAXRSClientFactoryBean#setThreadSafe() . 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: ClientImpl.java    From cxf with Apache License 2.0 6 votes vote down vote up
private void initTargetClientIfNeeded(Map<String, Object> configProps) {
    URI uri = uriBuilder.build();
    if (targetClient == null) {
        JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean();
        bean.setAddress(uri.toString());
        bean.setProperties(configProps);
        Boolean threadSafe = getBooleanValue(configProps.get(THREAD_SAFE_CLIENT_PROP));
        if (threadSafe == null) {
            threadSafe = DEFAULT_THREAD_SAFETY_CLIENT_STATUS;
        }
        bean.setThreadSafe(threadSafe);
        if (threadSafe) {
            Integer cleanupPeriod = getIntValue(configProps.get(THREAD_SAFE_CLIENT_STATE_CLEANUP_PROP));
            if (cleanupPeriod == null) {
                cleanupPeriod = THREAD_SAFE_CLIENT_STATE_CLEANUP_PERIOD;
            }
            if (cleanupPeriod != null) {
                bean.setSecondsToKeepState(cleanupPeriod);
            }
        }
        targetClient = bean.createWebClient();
        ClientImpl.this.baseClients.add(targetClient);
    } else if (!targetClient.getCurrentURI().equals(uri)) {
        targetClient.to(uri.toString(), false);
    }
}
 
Example 2
Source File: SelfKeymasterClientContext.java    From syncope with Apache License 2.0 5 votes vote down vote up
@ConditionalOnExpression("#{'${keymaster.address}' matches '^http.+'}")
@Bean
@ConditionalOnMissingBean(name = "selfKeymasterRESTClientFactoryBean")
public JAXRSClientFactoryBean selfKeymasterRESTClientFactoryBean() {
    JAXRSClientFactoryBean restClientFactoryBean = new JAXRSClientFactoryBean();
    restClientFactoryBean.setAddress(address);
    restClientFactoryBean.setUsername(username);
    restClientFactoryBean.setPassword(password);
    restClientFactoryBean.setThreadSafe(true);
    restClientFactoryBean.setInheritHeaders(true);
    restClientFactoryBean.setFeatures(List.of(new LoggingFeature()));
    restClientFactoryBean.setProviders(
        List.of(new JacksonJsonProvider(), new SelfKeymasterClientExceptionMapper()));
    return restClientFactoryBean;
}
 
Example 3
Source File: AbstractJaxRsClientConfiguration.java    From cxf with Apache License 2.0 5 votes vote down vote up
protected Client createClient() {
    JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean();
    bean.setBus(bus);
    bean.setAddress(address);
    bean.setThreadSafe(threadSafe);
    setJaxrsResources(bean);

    for (String beanName : context.getBeanDefinitionNames()) {
        if (context.findAnnotationOnBean(beanName, Provider.class) != null) {
            bean.setProvider(context.getBean(beanName));
        } else if (context.findAnnotationOnBean(beanName, org.apache.cxf.annotations.Provider.class) != null) {
            addCxfProvider(bean, context.getBean(beanName));
        }
    }

    Map<String, String> extraHeaders = new HashMap<>();
    if (!StringUtils.isEmpty(accept)) {
        extraHeaders.put("Accept", accept);
    }
    if (!StringUtils.isEmpty(contentType)) {
        extraHeaders.put("Content-Type", contentType);
    }
    if (!extraHeaders.isEmpty()) {
        bean.setHeaders(extraHeaders);
    }
    return bean.create();
}