本文整理汇总了Java中org.apache.cxf.jaxrs.client.JAXRSClientFactoryBean类的典型用法代码示例。如果您正苦于以下问题:Java JAXRSClientFactoryBean类的具体用法?Java JAXRSClientFactoryBean怎么用?Java JAXRSClientFactoryBean使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
JAXRSClientFactoryBean类属于org.apache.cxf.jaxrs.client包,在下文中一共展示了JAXRSClientFactoryBean类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: get
import org.apache.cxf.jaxrs.client.JAXRSClientFactoryBean; //导入依赖的package包/类
public JAXRSClientFactoryBean get(String address) throws Exception {
JAXRSClientFactoryBean retVal = null;
synchronized (cache) {
retVal = cache.get(address);
if (retVal == null) {
retVal = ((CxfRsEndpoint)getEndpoint()).createJAXRSClientFactoryBean(address);
cache.put(address, retVal);
LOG.trace("Created client factory bean and add to cache for address '{}'", address);
} else {
LOG.trace("Retrieved client factory bean from cache for address '{}'", address);
}
}
return retVal;
}
示例2: setupJAXRSClientFactoryBean
import org.apache.cxf.jaxrs.client.JAXRSClientFactoryBean; //导入依赖的package包/类
protected void setupJAXRSClientFactoryBean(JAXRSClientFactoryBean cfb, String address) {
// address
if (address != null) {
cfb.setAddress(address);
}
if (modelRef != null) {
cfb.setModelRef(modelRef);
}
if (getResourceClasses() != null && !getResourceClasses().isEmpty()) {
cfb.setResourceClass(getResourceClasses().get(0));
cfb.getServiceFactory().setResourceClasses(getResourceClasses());
}
setupCommonFactoryProperties(cfb);
cfb.setThreadSafe(true);
getNullSafeCxfRsEndpointConfigurer().configure(cfb);
}
示例3: testCxfRsEndpointSetProvider
import org.apache.cxf.jaxrs.client.JAXRSClientFactoryBean; //导入依赖的package包/类
@Test
public void testCxfRsEndpointSetProvider() throws Exception {
String endpointUri = "cxfrs://http://localhost:" + CTX + ""
+ "?resourceClass=org.apache.camel.component.cxf.jaxrs.testbean.CustomerService";
CxfRsComponent component = new CxfRsComponent(context);
CxfRsEndpoint endpoint = (CxfRsEndpoint)component.createEndpoint(endpointUri);
JSONProvider<?> jsonProvider = new JSONProvider<Object>();
jsonProvider.setDropRootElement(true);
jsonProvider.setSupportUnwrapped(true);
endpoint.setProvider(jsonProvider);
JAXRSServerFactoryBean sfb = endpoint.createJAXRSServerFactoryBean();
assertEquals("Get a wrong proider size", 1, sfb.getProviders().size());
JAXRSClientFactoryBean cfb = endpoint.createJAXRSClientFactoryBean();
assertEquals("Get a wrong proider size", 1, cfb.getProviders().size());
}
示例4: build
import org.apache.cxf.jaxrs.client.JAXRSClientFactoryBean; //导入依赖的package包/类
/**
* Build a client proxy, for a specific proxy type.
*
* @param proxyType proxy type class
* @return client proxy stub
*/
protected <T> T build(Class<T> proxyType) {
String address = generateAddress();
T rootResource;
// Synchronized on the class to correlate with the scope of clientStaticResources
// We want to ensure that the shared bean isn't set concurrently in multiple callers
synchronized (AmbariClientBuilder.class) {
JAXRSClientFactoryBean bean = cleanFactory(clientStaticResources.getUnchecked(proxyType));
bean.setAddress(address);
if (username != null) {
bean.setUsername(username);
bean.setPassword(password);
}
if (enableLogging) {
bean.setFeatures(Arrays.<AbstractFeature> asList(new LoggingFeature()));
}
rootResource = bean.create(proxyType);
}
boolean isTlsEnabled = address.startsWith("https://");
ClientConfiguration config = WebClient.getConfig(rootResource);
HTTPConduit conduit = (HTTPConduit) config.getConduit();
if (isTlsEnabled) {
TLSClientParameters tlsParams = new TLSClientParameters();
if (!validateCerts) {
tlsParams.setTrustManagers(new TrustManager[] { new AcceptAllTrustManager() });
} else if (trustManagers != null) {
tlsParams.setTrustManagers(trustManagers);
}
tlsParams.setDisableCNCheck(!validateCn);
conduit.setTlsClientParameters(tlsParams);
}
HTTPClientPolicy policy = conduit.getClient();
policy.setConnectionTimeout(connectionTimeoutUnits.toMillis(connectionTimeout));
policy.setReceiveTimeout(receiveTimeoutUnits.toMillis(receiveTimeout));
return rootResource;
}
示例5: rawTest
import org.apache.cxf.jaxrs.client.JAXRSClientFactoryBean; //导入依赖的package包/类
@Test
@Ignore
public void rawTest(){
JAXRSClientFactoryBean bean=new JAXRSClientFactoryBean();
bean.setAddress("http://localhost:8080/cxf-plus/ws/rest/");
bean.setServiceClass(PeopleServiceXml.class);
// bean.setProvider(new FastJSONProvider(true, false));
bean.getInInterceptors().add(new LoggingInInterceptor());
bean.getOutInterceptors().add(new LoggingOutInterceptor());
PeopleServiceXml s=(PeopleServiceXml)bean.create();
List<People> r=s.getAll();
System.out.println("-------------------");
System.out.println("得到用户"+r.size());
// int id=s.create(new People("[email protected]","jiyi","lu"));
// System.out.println(id);
}
示例6: createSAMLClient
import org.apache.cxf.jaxrs.client.JAXRSClientFactoryBean; //导入依赖的package包/类
private static WebClient createSAMLClient(String address, boolean selfSigned) {
JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean();
bean.setAddress(address);
Map<String, Object> properties = new HashMap<String, Object>();
properties.put("ws-security.callback-handler", "org.apache.cxf.systest.jaxrs.security.saml.KeystorePasswordCallback");
properties.put("ws-security.saml-callback-handler", "org.teiid.saml.jaxrs.SamlCallbackHandler");
properties.put("ws-security.signature.username", "alice");
properties.put("ws-security.signature.properties", "org/apache/cxf/systest/jaxrs/security/alice.properties");
if (selfSigned) {
properties.put("ws-security.self-sign-saml-assertion", "true");
}
bean.setProperties(properties);
bean.getOutInterceptors().add(new SamlEnvelopedOutInterceptor(!selfSigned));
XmlSigOutInterceptor xmlSig = new XmlSigOutInterceptor();
if (selfSigned) {
xmlSig.setStyle(XmlSigOutInterceptor.DETACHED_SIG);
}
return bean.createWebClient();
}
示例7: SyncopeClient
import org.apache.cxf.jaxrs.client.JAXRSClientFactoryBean; //导入依赖的package包/类
public SyncopeClient(
final MediaType mediaType,
final JAXRSClientFactoryBean restClientFactory,
final RestClientExceptionMapper exceptionMapper,
final AuthenticationHandler handler,
final boolean useCompression) {
this.mediaType = mediaType;
this.restClientFactory = restClientFactory;
if (this.restClientFactory.getHeaders() == null) {
this.restClientFactory.setHeaders(new HashMap<>());
}
this.exceptionMapper = exceptionMapper;
init(handler);
this.useCompression = useCompression;
}
示例8: createClient
import org.apache.cxf.jaxrs.client.JAXRSClientFactoryBean; //导入依赖的package包/类
public IOpenDaylightStaticFlowPusherClient createClient(ProtocolSessionContext sessionContext) {
String uri = (String) sessionContext.getSessionParameters().get(ProtocolSessionContext.PROTOCOL_URI);
String switchId = (String) sessionContext.getSessionParameters().get(OpenDaylightProtocolSession.SWITCHID_CONTEXT_PARAM_NAME);
// TODO use switch id to instantiate the client
// create CXF client
ProxyClassLoader classLoader = new ProxyClassLoader();
classLoader.addLoader(IOpenDaylightStaticFlowPusherClient.class.getClassLoader());
classLoader.addLoader(JAXRSClientFactoryBean.class.getClassLoader());
JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean();
bean.setAddress(uri);
bean.setUsername(odlUserName);
bean.setPassword(odlPassword);
bean.setProvider(new CustomJSONProvider());
bean.setResourceClass(IOpenDaylightStaticFlowPusherClient.class);
bean.setClassLoader(classLoader);
IOpenDaylightStaticFlowPusherClient cxfClient = (IOpenDaylightStaticFlowPusherClient) bean.create();
// create mixed client using CXF and custom Java clients
IOpenDaylightStaticFlowPusherClient client = new OpenDaylightStaticFlowPusherClient(cxfClient, sessionContext);
return client;
}
示例9: createClient
import org.apache.cxf.jaxrs.client.JAXRSClientFactoryBean; //导入依赖的package包/类
public IFloodlightStaticFlowPusherClient createClient(ProtocolSessionContext sessionContext) {
String uri = (String) sessionContext.getSessionParameters().get(ProtocolSessionContext.PROTOCOL_URI);
String switchId = (String) sessionContext.getSessionParameters().get(FloodlightProtocolSession.SWITCHID_CONTEXT_PARAM_NAME);
// TODO use switch id to instantiate the client
// create CXF client
ProxyClassLoader classLoader = new ProxyClassLoader();
classLoader.addLoader(IFloodlightStaticFlowPusherClient.class.getClassLoader());
classLoader.addLoader(JAXRSClientFactoryBean.class.getClassLoader());
JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean();
bean.setAddress(uri);
bean.setProvider(new CustomJSONProvider());
bean.setResourceClass(IFloodlightStaticFlowPusherClient.class);
bean.setClassLoader(classLoader);
IFloodlightStaticFlowPusherClient cxfClient = (IFloodlightStaticFlowPusherClient) bean.create();
// create mixed client using CXF and custom Java clients
IFloodlightStaticFlowPusherClient client = new FloodlightStaticFlowPusherClient(cxfClient, sessionContext);
return client;
}
示例10: createRestClient
import org.apache.cxf.jaxrs.client.JAXRSClientFactoryBean; //导入依赖的package包/类
/**
* Creates a JAXRSClient with given clientInterface.
*
* @param uri
* the URI where the service is running
* @param clientInterface
* interface class the client should has.
* @param providers
* custom JAX-RS providers
* @param username
* Basic authentication username
* @param password
* Basic authentication password
* @return JAX-RX Client configured with given parameters.
*/
@SuppressWarnings("unchecked")
public static <T> T createRestClient(String uri, Class<T> clientInterface, List<? extends Object> providers, String username, String password) {
ProxyClassLoader classLoader = new ProxyClassLoader();
classLoader.addLoader(clientInterface.getClassLoader());
classLoader.addLoader(JAXRSClientFactoryBean.class.getClassLoader());
JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean();
bean.setAddress(uri);
if (providers != null && !providers.isEmpty())
bean.setProviders(providers);
bean.setResourceClass(clientInterface);
bean.setClassLoader(classLoader);
if (username != null && password != null) {
bean.setUsername(username);
bean.setPassword(password);
}
return (T) bean.create();
}
示例11: build
import org.apache.cxf.jaxrs.client.JAXRSClientFactoryBean; //导入依赖的package包/类
/**
* This method returns an instance of an implementation the specified {@code clazz} (which should be a REST service
* interface, e.g. TablemanagementRestService.class). <br/>
* The caller must take care that no parameter value is equal to {@code NULL}. <br/>
* The caller will be authenticated using basic authentication with the provided credentials. The method
* {@code setLocalServerPort} MUST be called in advance.
*
* @param <T> The return type.
* @param clazz This must be an interface type.
* @param userName The userName for basic authentication.
* @param tmpPassword The password for basic authentication.
* @param tmpUrl The URL through which the server is reached.
* @return A REST proxy of type {@code T}
*/
public <T extends RestService> T build(Class<T> clazz, String userName, String tmpPassword, String tmpUrl) {
JAXRSClientFactoryBean factoryBean = new JAXRSClientFactoryBean();
factoryBean.setAddress(tmpUrl);
factoryBean.setHeaders(new HashMap<String, String>());
// example for basic auth
String payload = userName + ":" + tmpPassword;
String authorizationHeader = "Basic " + Base64Utility.encode(payload.getBytes());
factoryBean.getHeaders().put("Authorization", Arrays.asList(authorizationHeader));
factoryBean.setProviders(Arrays.asList(this.jacksonJsonProvider));
factoryBean.setServiceClass(clazz);
return factoryBean.create(clazz);
}
示例12: getBean
import org.apache.cxf.jaxrs.client.JAXRSClientFactoryBean; //导入依赖的package包/类
static JAXRSClientFactoryBean getBean(String baseAddress, String configLocation, Map<String, String> headers) {
JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean();
if (configLocation != null) {
SpringBusFactory bf = new SpringBusFactory();
Bus bus = bf.createBus(configLocation);
bean.setBus(bus);
}
bean.setAddress(baseAddress);
if (headers != null && !headers.isEmpty()) {
bean.setHeaders(headers);
}
return bean;
}
示例13: testCxfBusInjection
import org.apache.cxf.jaxrs.client.JAXRSClientFactoryBean; //导入依赖的package包/类
@Test
public void testCxfBusInjection() {
CxfRsEndpoint serviceEndpoint = context.getEndpoint("cxfrs:bean:serviceEndpoint", CxfRsEndpoint.class);
CxfRsEndpoint routerEndpoint = context.getEndpoint("cxfrs:bean:routerEndpoint", CxfRsEndpoint.class);
JAXRSServerFactoryBean server = routerEndpoint.createJAXRSServerFactoryBean();
JAXRSClientFactoryBean client = serviceEndpoint.createJAXRSClientFactoryBean();
assertEquals("These cxfrs endpoints don't share the same bus", server.getBus().getId(), client.getBus().getId());
}
示例14: testProducerInOutInterceptors
import org.apache.cxf.jaxrs.client.JAXRSClientFactoryBean; //导入依赖的package包/类
@Test
public void testProducerInOutInterceptors() throws Exception {
CxfRsEndpoint e = context.getEndpoint(
"cxfrs://bean://rsClientHttpInterceptors", CxfRsEndpoint.class);
CxfRsProducer p = new CxfRsProducer(e);
CxfRsProducer.ClientFactoryBeanCache cache = p.getClientFactoryBeanCache();
JAXRSClientFactoryBean bean = cache.get("http://localhost:8080/CxfRsProducerClientFactoryBeanInterceptors/");
List<Interceptor<?>> ins = bean.getInInterceptors();
assertEquals(1, ins.size());
assertTrue(ins.get(0) instanceof LoggingInInterceptor);
List<Interceptor<?>> outs = bean.getOutInterceptors();
assertEquals(1, outs.size());
assertTrue(outs.get(0) instanceof LoggingOutInterceptor);
}
示例15: load
import org.apache.cxf.jaxrs.client.JAXRSClientFactoryBean; //导入依赖的package包/类
@Override
public JAXRSClientFactoryBean load(Class<?> proxyType) throws Exception {
JAXRSClientFactoryBean clientFactoryBean = new JAXRSClientFactoryBean();
clientFactoryBean.setResourceClass(proxyType);
clientFactoryBean.setProvider(new TextJacksonJsonProvider(new ApiObjectMapper()));
return clientFactoryBean;
}