本文整理汇总了Java中com.netflix.client.ClientFactory.getNamedClient方法的典型用法代码示例。如果您正苦于以下问题:Java ClientFactory.getNamedClient方法的具体用法?Java ClientFactory.getNamedClient怎么用?Java ClientFactory.getNamedClient使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.netflix.client.ClientFactory
的用法示例。
在下文中一共展示了ClientFactory.getNamedClient方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: run
import com.netflix.client.ClientFactory; //导入方法依赖的package包/类
@Override
protected String run() {
try {
/*
* The named client param must match the prefix for the ribbon
* configuration specified in the edge.properties file
*/
RestClient client = (RestClient) ClientFactory.getNamedClient(RSSConstants.MIDDLETIER_REST_CLIENT);
HttpClientRequest request = HttpClientRequest
.newBuilder()
.setVerb(Verb.POST)
.setUri(new URI("/"
+ RSSConstants.MIDDLETIER_WEB_RESOURCE_ROOT_PATH
+ RSSConstants.RSS_ENTRY_POINT
+ "?url=" + url))
.build();
HttpClientResponse response = client.executeWithLoadBalancer(request);
return IOUtils.toString(response.getRawEntity(), Charsets.UTF_8);
} catch (Exception exc) {
throw new RuntimeException("Exception occurred when adding a RSS feed", exc);
}
}
示例2: testSunnyDayNoClientAuth
import com.netflix.client.ClientFactory; //导入方法依赖的package包/类
@Test
public void testSunnyDayNoClientAuth() throws Exception{
AbstractConfiguration cm = ConfigurationManager.getConfigInstance();
String name = "GetPostSecureTest" + ".testSunnyDayNoClientAuth";
String configPrefix = name + "." + "ribbon";
cm.setProperty(configPrefix + "." + CommonClientConfigKey.IsSecure, "true");
cm.setProperty(configPrefix + "." + CommonClientConfigKey.SecurePort, Integer.toString(PORT2));
cm.setProperty(configPrefix + "." + CommonClientConfigKey.IsHostnameValidationRequired, "false");
cm.setProperty(configPrefix + "." + CommonClientConfigKey.TrustStore, FILE_TS2.getAbsolutePath());
cm.setProperty(configPrefix + "." + CommonClientConfigKey.TrustStorePassword, PASSWORD);
RestClient rc = (RestClient) ClientFactory.getNamedClient(name);
testServer2.accept();
URI getUri = new URI(SERVICE_URI2 + "test/");
HttpRequest request = HttpRequest.newBuilder().uri(getUri).queryParams("name", "test").build();
HttpResponse response = rc.execute(request);
assertEquals(200, response.getStatus());
}
示例3: run
import com.netflix.client.ClientFactory; //导入方法依赖的package包/类
@Override
protected String run() {
try {
// The named client param must match the prefix for the ribbon
// configuration specified in the edge.properties file
RestClient client = (RestClient) ClientFactory.getNamedClient(RSSConstants.MIDDLETIER_REST_CLIENT);
HttpClientRequest request = HttpClientRequest
.newBuilder()
.setVerb(Verb.DELETE)
.setUri(new URI("/"
+ RSSConstants.MIDDLETIER_WEB_RESOURCE_ROOT_PATH
+ RSSConstants.RSS_ENTRY_POINT
+ "?url=" + url)
)
.build();
HttpClientResponse response = client.executeWithLoadBalancer(request);
return IOUtils.toString(response.getRawEntity(), Charsets.UTF_8);
} catch (Exception exc) {
throw new RuntimeException("Exception", exc);
}
}
示例4: testSecureClient2
import com.netflix.client.ClientFactory; //导入方法依赖的package包/类
@Test
public void testSecureClient2() throws Exception {
ConfigurationManager.getConfigInstance().setProperty("test3.ribbon." + CommonClientConfigKey.IsSecure, "true");
ConfigurationManager.getConfigInstance().setProperty("test3.ribbon." + CommonClientConfigKey.TrustStore, secureServer.getTrustStore().getAbsolutePath());
ConfigurationManager.getConfigInstance().setProperty("test3.ribbon." + CommonClientConfigKey.TrustStorePassword, SecureGetTest.PASSWORD);
RestClient client = (RestClient) ClientFactory.getNamedClient("test3");
BaseLoadBalancer lb = new BaseLoadBalancer();
Server[] servers = new Server[]{new Server("localhost", secureServer.getServerPort())};
lb.addServers(Arrays.asList(servers));
client.setLoadBalancer(lb);
HttpRequest request = HttpRequest.newBuilder().uri(new URI("/")).build();
HttpResponse response = client.executeWithLoadBalancer(request);
assertStatusIsOk(response.getStatus());
assertEquals(secureServer.getServerPath("/"), response.getRequestedURI().toString());
}
示例5: run
import com.netflix.client.ClientFactory; //导入方法依赖的package包/类
@Override
protected String run() {
try {
// The named client param must match the prefix for the ribbon
// configuration specified in the edge.properties file
RestClient client = (RestClient) ClientFactory.getNamedClient(RSSConstants.MIDDLETIER_REST_CLIENT);
HttpClientRequest request = HttpClientRequest
.newBuilder()
.setVerb(Verb.GET)
.setUri(new URI("/"
+ RSSConstants.MIDDLETIER_WEB_RESOURCE_ROOT_PATH
+ RSSConstants.RSS_ENTRY_POINT)
)
.build();
HttpClientResponse response = client.executeWithLoadBalancer(request);
return IOUtils.toString(response.getRawEntity(), Charsets.UTF_8);
} catch (Exception exc) {
throw new RuntimeException("Exception", exc);
}
}
示例6: testConnectionPoolCleaner
import com.netflix.client.ClientFactory; //导入方法依赖的package包/类
@Test
public void testConnectionPoolCleaner() throws Exception {
// LogManager.getRootLogger().setLevel((Level)Level.DEBUG);
ConfigurationManager.getConfigInstance().setProperty("ConnectionPoolCleanerTest.ribbon." + CommonClientConfigKey.ConnIdleEvictTimeMilliSeconds, "100");
ConfigurationManager.getConfigInstance().setProperty("ConnectionPoolCleanerTest.ribbon." + CommonClientConfigKey.ConnectionCleanerRepeatInterval, "500");
RestClient client = (RestClient) ClientFactory.getNamedClient("ConnectionPoolCleanerTest");
NFHttpClient httpclient = NFHttpClientFactory.getNamedNFHttpClient("ConnectionPoolCleanerTest");
assertNotNull(httpclient);
com.netflix.client.http.HttpResponse response = null;
try {
response = client.execute(HttpRequest.newBuilder().uri(server.getServerPath("/")).build());
} finally {
if (response != null) {
response.close();
}
}
MonitoredConnectionManager connectionPoolManager = (MonitoredConnectionManager) httpclient.getConnectionManager();
Thread.sleep(2000);
assertEquals(0, connectionPoolManager.getConnectionsInPool());
client.shutdown();
}
示例7: create
import com.netflix.client.ClientFactory; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public <T> T create(Class<T> clientClass) {
Preconditions.checkNotNull(this.namedClient, "NamedClient required");
Preconditions.checkNotNull(
this.restAdapterConfig.getMessageSerializer(),
"MessageSerializer required");
LOGGER.info("Using NamedClient {}", this.namedClient);
LOGGER.info("Using MessageSerializer {}",
this.restAdapterConfig.getMessageSerializer());
final RestClient restClient = (RestClient) ClientFactory
.getNamedClient(namedClient);
restClient.getJerseyClient().addFilter(new LoggerFilter());
if (this.restAdapterConfig.getEncoding() == Encoding.gzip) {
restClient.getJerseyClient().addFilter(
new GZIPContentEncodingFilter());
}
InvocationHandler invocationHandler = new JerseyInvocationHandler(
restClient, this.restAdapterConfig);
Object proxyInstance = Proxy.newProxyInstance(
ClassLoader.getSystemClassLoader(),
new Class<?>[] { clientClass }, invocationHandler);
return (T) proxyInstance;
}
示例8: doGet
import com.netflix.client.ClientFactory; //导入方法依赖的package包/类
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
* response)
*/
protected void doGet(HttpServletRequest servletRequest,
HttpServletResponse servletResponse) throws ServletException,
IOException {
try {
System.out.println(ConfigurationManager.getConfigInstance()
.getProperty("sample-client.ribbon.listOfServers"));
RestClient client = (RestClient) ClientFactory
.getNamedClient("sample-client");
HttpRequest request = HttpRequest.newBuilder().uri(new URI("/"))
.build();
for (int i = 0; i < 1; i++) {
HttpResponse response = client.executeWithLoadBalancer(request);
System.out.println("Status code for "
+ response.getRequestedURI() + " :"
+ response.getStatus());
}
@SuppressWarnings("rawtypes")
ZoneAwareLoadBalancer lb = (ZoneAwareLoadBalancer) client
.getLoadBalancer();
servletResponse.getOutputStream().println(lb.getLoadBalancerStats().toString());
} catch (Exception ex) {
ex.printStackTrace();
}
}
示例9: createClient
import com.netflix.client.ClientFactory; //导入方法依赖的package包/类
@VisibleForTesting
void createClient() {
if (ribbonEtc.containsKey("eureka")) {
ribbonEtc.setProperty(
clientName + ".ribbon.AppName", clientName);
ribbonEtc.setProperty(
clientName + ".ribbon.NIWSServerListClassName",
"com.netflix.niws.loadbalancer.DiscoveryEnabledNIWSServerList");
String[] host_port = addressList.get(0).split(":");
ribbonEtc.setProperty(
clientName + ".ribbon.DeploymentContextBasedVipAddresses",
host_port[0]);
ribbonEtc.setProperty(
clientName + ".ribbon.Port",
host_port[1]);
} else {
ribbonEtc.setProperty(clientName + ".ribbon.listOfServers", Joiner.on(",").join(addressList));
}
ribbonEtc.setProperty(
clientName + ".ribbon.EnablePrimeConnections",
"true");
String retryPropertyName = clientName + ".ribbon." + CommonClientConfigKey.OkToRetryOnAllOperations;
if (ribbonEtc.getProperty(retryPropertyName) == null) {
// default set this to enable retry on POST operation upon read timeout
ribbonEtc.setProperty(retryPropertyName, "true");
}
String maxRetryProperty = clientName + ".ribbon." + CommonClientConfigKey.MaxAutoRetriesNextServer;
if (ribbonEtc.getProperty(maxRetryProperty) == null) {
// by default retry two different servers upon exception
ribbonEtc.setProperty(maxRetryProperty, "2");
}
ConfigurationManager.loadProperties(ribbonEtc);
client = (RestClient) ClientFactory.getNamedClient(clientName);
}
示例10: testServerWeights
import com.netflix.client.ClientFactory; //导入方法依赖的package包/类
@Test
public void testServerWeights(){
try{
ConfigurationManager.loadPropertiesFromResources("sample-client.properties");
ConfigurationManager.getConfigInstance().setProperty(
"sample-client.ribbon.NFLoadBalancerClassName", "com.netflix.loadbalancer.DynamicServerListLoadBalancer");
ConfigurationManager.getConfigInstance().setProperty(
"sample-client.ribbon.NFLoadBalancerRuleClassName", "com.netflix.loadbalancer.WeightedResponseTimeRule");
// shorter weight adjusting interval
ConfigurationManager.getConfigInstance().setProperty(
"sample-client.ribbon." + WeightedResponseTimeRule.WEIGHT_TASK_TIMER_INTERVAL_CONFIG_KEY, "5000");
ConfigurationManager.getConfigInstance().setProperty(
"sample-client.ribbon.InitializeNFLoadBalancer", "true");
RestClient client = (RestClient) ClientFactory.getNamedClient("sample-client");
HttpRequest request = HttpRequest.newBuilder().uri(new URI("/")).build();
for (int i = 0; i < 20; i++) {
client.executeWithLoadBalancer(request);
}
System.out.println(((AbstractLoadBalancer) client.getLoadBalancer()).getLoadBalancerStats());
// wait for the weights to be adjusted
Thread.sleep(5000);
for (int i = 0; i < 50; i++) {
client.executeWithLoadBalancer(request);
}
System.out.println(((AbstractLoadBalancer) client.getLoadBalancer()).getLoadBalancerStats());
}
catch (Exception e){
e.printStackTrace();
}
}
示例11: init
import com.netflix.client.ClientFactory; //导入方法依赖的package包/类
@BeforeClass
public static void init() throws Exception {
PackagesResourceConfig resourceConfig = new PackagesResourceConfig("com.netflix.niws.http", "com.netflix.niws.client");
int port = (new Random()).nextInt(1000) + 4000;
SERVICE_URI = "http://localhost:" + port + "/";
try{
server = HttpServerFactory.create(SERVICE_URI, resourceConfig);
server.start();
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
client = (RestClient) ClientFactory.getNamedClient("GetPostTest");
}
示例12: testSunnyDay
import com.netflix.client.ClientFactory; //导入方法依赖的package包/类
@Test
public void testSunnyDay() throws Exception {
AbstractConfiguration cm = ConfigurationManager.getConfigInstance();
String name = "GetPostSecureTest" + ".testSunnyDay";
String configPrefix = name + "." + "ribbon";
cm.setProperty(configPrefix + "." + CommonClientConfigKey.IsSecure, "true");
cm.setProperty(configPrefix + "." + CommonClientConfigKey.SecurePort, Integer.toString(PORT1));
cm.setProperty(configPrefix + "." + CommonClientConfigKey.IsHostnameValidationRequired, "false");
cm.setProperty(configPrefix + "." + CommonClientConfigKey.IsClientAuthRequired, "true");
cm.setProperty(configPrefix + "." + CommonClientConfigKey.KeyStore, FILE_KS1.getAbsolutePath());
cm.setProperty(configPrefix + "." + CommonClientConfigKey.KeyStorePassword, PASSWORD);
cm.setProperty(configPrefix + "." + CommonClientConfigKey.TrustStore, FILE_TS1.getAbsolutePath());
cm.setProperty(configPrefix + "." + CommonClientConfigKey.TrustStorePassword, PASSWORD);
RestClient rc = (RestClient) ClientFactory.getNamedClient(name);
testServer1.accept();
URI getUri = new URI(SERVICE_URI1 + "test/");
HttpRequest request = HttpRequest.newBuilder().uri(getUri).queryParams("name", "test").build();
HttpResponse response = rc.execute(request);
assertEquals(200, response.getStatus());
}
示例13: testClientRejectsWrongServer
import com.netflix.client.ClientFactory; //导入方法依赖的package包/类
@Test
public void testClientRejectsWrongServer() throws Exception{
AbstractConfiguration cm = ConfigurationManager.getConfigInstance();
String name = "GetPostSecureTest" + ".testClientRejectsWrongServer";
String configPrefix = name + "." + "ribbon";
cm.setProperty(configPrefix + "." + CommonClientConfigKey.IsSecure, "true");
cm.setProperty(configPrefix + "." + CommonClientConfigKey.SecurePort, Integer.toString(PORT2));
cm.setProperty(configPrefix + "." + CommonClientConfigKey.IsHostnameValidationRequired, "false");
cm.setProperty(configPrefix + "." + CommonClientConfigKey.TrustStore, FILE_TS1.getAbsolutePath()); // <--
cm.setProperty(configPrefix + "." + CommonClientConfigKey.TrustStorePassword, PASSWORD);
RestClient rc = (RestClient) ClientFactory.getNamedClient(name);
testServer2.accept();
URI getUri = new URI(SERVICE_URI2 + "test/");
HttpRequest request = HttpRequest.newBuilder().uri(getUri).queryParams("name", "test").build();
try{
rc.execute(request);
fail("expecting ssl hostname validation error");
}catch(ClientHandlerException che){
assertTrue(che.getMessage().indexOf("peer not authenticated") > -1);
}
}
示例14: testExecuteWithoutLB
import com.netflix.client.ClientFactory; //导入方法依赖的package包/类
@Test
public void testExecuteWithoutLB() throws Exception {
RestClient client = (RestClient) ClientFactory.getNamedClient("google");
HttpRequest request = HttpRequest.newBuilder().uri(server.getServerURI()).build();
HttpResponse response = client.executeWithLoadBalancer(request);
assertStatusIsOk(response.getStatus());
response = client.execute(request);
assertStatusIsOk(response.getStatus());
}
示例15: testVipAsURI
import com.netflix.client.ClientFactory; //导入方法依赖的package包/类
@Test
public void testVipAsURI() throws Exception {
ConfigurationManager.getConfigInstance().setProperty("test1.ribbon.DeploymentContextBasedVipAddresses", server.getServerPath("/"));
ConfigurationManager.getConfigInstance().setProperty("test1.ribbon.InitializeNFLoadBalancer", "false");
RestClient client = (RestClient) ClientFactory.getNamedClient("test1");
assertNull(client.getLoadBalancer());
HttpRequest request = HttpRequest.newBuilder().uri(new URI("/")).build();
HttpResponse response = client.executeWithLoadBalancer(request);
assertStatusIsOk(response.getStatus());
assertEquals(server.getServerPath("/"), response.getRequestedURI().toString());
}