本文整理汇总了Java中org.apache.cxf.jaxrs.client.JAXRSClientFactoryBean.create方法的典型用法代码示例。如果您正苦于以下问题:Java JAXRSClientFactoryBean.create方法的具体用法?Java JAXRSClientFactoryBean.create怎么用?Java JAXRSClientFactoryBean.create使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.cxf.jaxrs.client.JAXRSClientFactoryBean
的用法示例。
在下文中一共展示了JAXRSClientFactoryBean.create方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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;
}
示例2: 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);
}
示例3: 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;
}
示例4: 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;
}
示例5: 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();
}
示例6: 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);
}
示例7: createProxy
import org.apache.cxf.jaxrs.client.JAXRSClientFactoryBean; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public <T> T createProxy(String url, Class<T> clz) {
JAXRSClientFactoryBean proxyFactoryBean = new JAXRSClientFactoryBean();
proxyFactoryBean.setAddress(url);
proxyFactoryBean.setServiceClass(clz);
proxyFactoryBean.setProvider(new FastJSONProvider(true, false));
proxyFactoryBean.getInInterceptors().add(new LoggingInInterceptor());
proxyFactoryBean.getOutInterceptors().add(new LoggingOutInterceptor());
T client = (T) proxyFactoryBean.create();
return client;
}
示例8: createClient
import org.apache.cxf.jaxrs.client.JAXRSClientFactoryBean; //导入方法依赖的package包/类
private IResourceModelReader createClient(String addressUri) {
// create CXF client
ProxyClassLoader classLoader = new ProxyClassLoader(IResourceModelReader.class.getClassLoader());
classLoader.addLoader(JAXRSClientFactoryBean.class.getClassLoader());
JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean();
bean.setAddress(addressUri);
bean.setResourceClass(IResourceModelReader.class);
bean.setClassLoader(classLoader);
return (IResourceModelReader) bean.create();
}
示例9: createClient
import org.apache.cxf.jaxrs.client.JAXRSClientFactoryBean; //导入方法依赖的package包/类
public IOpenDaylightFlowProgrammerNorthbound createClient(String addressUri, String username, String password) {
// create CXF client
ProxyClassLoader classLoader = new ProxyClassLoader(IOpenDaylightFlowProgrammerNorthbound.class.getClassLoader());
classLoader.addLoader(JAXRSClientFactoryBean.class.getClassLoader());
JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean();
bean.setAddress(addressUri);
bean.setUsername(username);
bean.setPassword(password);
bean.setResourceClass(IOpenDaylightFlowProgrammerNorthbound.class);
bean.setClassLoader(classLoader);
return (IOpenDaylightFlowProgrammerNorthbound) bean.create();
}
示例10: getClient
import org.apache.cxf.jaxrs.client.JAXRSClientFactoryBean; //导入方法依赖的package包/类
private static ISwitchNorthboundAPI getClient(String baseURL, String username, String password) {
JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean();
bean.setAddress(baseURL);
bean.setResourceClass(ISwitchNorthboundAPI.class);
bean.setUsername(username);
bean.setPassword(password);
return bean.create(ISwitchNorthboundAPI.class);
}
示例11: WebserviceMockControler
import org.apache.cxf.jaxrs.client.JAXRSClientFactoryBean; //导入方法依赖的package包/类
public WebserviceMockControler(String mockServiceRootAddress) {
JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean();
bean.setAddress(mockServiceRootAddress);
bean.setResourceClass(MockService.class);
mockServiceProxy = bean.create(MockService.class);
}
示例12: createClient
import org.apache.cxf.jaxrs.client.JAXRSClientFactoryBean; //导入方法依赖的package包/类
public IOpenDaylightvtnAPIClient createClient(ProtocolSessionContext sessionContext) {
String uri = (String) sessionContext.getSessionParameters().get(ProtocolSessionContext.PROTOCOL_URI);
// TODO use switch id to instantiate the client
// create CXF client
ProxyClassLoader classLoader = new ProxyClassLoader();
classLoader.addLoader(IOpenDaylightvtnAPIClient.class.getClassLoader());
classLoader.addLoader(JAXRSClientFactoryBean.class.getClassLoader());
Map user = new HashMap<String, String>();
user.put("username", odlUserName);
user.put("password", odlPassword);
JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean();
bean.setAddress(uri);
bean.setHeaders(user);
// bean.setUsername(odlUserName);
// bean.setPassword(odlPassword);
bean.setProvider(new CustomJSONProvider());
bean.setResourceClass(IOpenDaylightvtnAPIClient.class);
bean.setClassLoader(classLoader);
IOpenDaylightvtnAPIClient cxfClient = (IOpenDaylightvtnAPIClient) bean.create();
// create mixed client using CXF and custom Java clients
IOpenDaylightvtnAPIClient client = new OpenDaylightvtnAPIClient(cxfClient, sessionContext);
return client;
}
示例13: create
import org.apache.cxf.jaxrs.client.JAXRSClientFactoryBean; //导入方法依赖的package包/类
public static <T> T create(String baseAddress, Class<T> cls, List<?> providers, String configLocation, Map<String, String> headers) {
JAXRSClientFactoryBean bean = getBean(baseAddress, cls, configLocation, headers);
bean.setProviders(providers);
return bean.create(cls, new Object[0]);
}
示例14: invokeProxyClient
import org.apache.cxf.jaxrs.client.JAXRSClientFactoryBean; //导入方法依赖的package包/类
protected void invokeProxyClient(Exchange exchange) throws Exception {
Message inMessage = exchange.getIn();
Object[] varValues = inMessage.getHeader(CxfConstants.CAMEL_CXF_RS_VAR_VALUES, Object[].class);
String methodName = inMessage.getHeader(CxfConstants.OPERATION_NAME, String.class);
Client target = null;
JAXRSClientFactoryBean cfb = clientFactoryBeanCache.get(CxfEndpointUtils
.getEffectiveAddress(exchange, ((CxfRsEndpoint)getEndpoint()).getAddress()));
Bus bus = ((CxfRsEndpoint)getEndpoint()).getBus();
// We need to apply the bus setting from the CxfRsEndpoint which is not use the default bus
if (bus != null) {
cfb.setBus(bus);
}
if (varValues == null) {
target = cfb.create();
} else {
target = cfb.createWithValues(varValues);
}
setupClientHeaders(target, exchange);
// find out the method which we want to invoke
JAXRSServiceFactoryBean sfb = cfb.getServiceFactory();
sfb.getResourceClasses();
// check the null body first
Object[] parameters = null;
if (inMessage.getBody() != null) {
parameters = inMessage.getBody(Object[].class);
}
// get the method
Method method = findRightMethod(sfb.getResourceClasses(), methodName, getParameterTypes(parameters));
// Will send out the message to
// Need to deal with the sub resource class
Object response = method.invoke(target, parameters);
int statesCode = target.getResponse().getStatus();
if (throwException) {
if (response instanceof Response) {
Integer respCode = ((Response) response).getStatus();
if (respCode > 207) {
throw populateCxfRsProducerException(exchange, (Response) response, respCode);
}
}
}
CxfRsEndpoint cxfRsEndpoint = (CxfRsEndpoint) getEndpoint();
CxfRsBinding binding = cxfRsEndpoint.getBinding();
if (exchange.getPattern().isOutCapable()) {
LOG.trace("Response body = {}", response);
exchange.getOut().getHeaders().putAll(exchange.getIn().getHeaders());
exchange.getOut().setBody(binding.bindResponseToCamelBody(response, exchange));
exchange.getOut().getHeaders().putAll(binding.bindResponseHeadersToCamelHeaders(response, exchange));
exchange.getOut().setHeader(Exchange.HTTP_RESPONSE_CODE, statesCode);
} else {
// just close the input stream of the response object
if (response instanceof Response) {
((Response)response).close();
}
}
}