本文整理汇总了Java中com.netflix.niws.client.http.RestClient类的典型用法代码示例。如果您正苦于以下问题:Java RestClient类的具体用法?Java RestClient怎么用?Java RestClient使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
RestClient类属于com.netflix.niws.client.http包,在下文中一共展示了RestClient类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: create
import com.netflix.niws.client.http.RestClient; //导入依赖的package包/类
@Override
@SuppressWarnings("deprecation")
public RestClientRibbonCommand create(RibbonCommandContext context) {
RestClient restClient = getClientFactory().getClient(context.getServiceId(),
RestClient.class);
try {
return new TraceRestClientRibbonCommand(context.getServiceId(), restClient,
getVerb(context.getVerb()), context.getUri(), context.getRetryable(),
context.getHeaders(), context.getParams(), context.getRequestEntity(),
this.tracer, this.spanInjector, this.httpTraceKeysInjector);
}
catch (URISyntaxException e) {
log.error("Exception occurred while trying to create the TraceRestClientRibbonCommand", e);
throw new RuntimeException(e);
}
}
示例2: createRequest
import com.netflix.niws.client.http.RestClient; //导入依赖的package包/类
@Override
@SuppressWarnings("deprecation")
public ClientHttpRequest createRequest(URI originalUri, HttpMethod httpMethod) throws IOException {
String serviceId = originalUri.getHost();
ServiceInstance instance = loadBalancer.choose(serviceId);
if (instance == null) {
throw new IllegalStateException("No instances available for " + serviceId);
}
URI uri = loadBalancer.reconstructURI(instance, originalUri);
IClientConfig clientConfig = clientFactory.getClientConfig(instance.getServiceId());
RestClient client = clientFactory.getClient(instance.getServiceId(), RestClient.class);
HttpRequest request = HttpRequest.newBuilder()
.uri(uri)
.verb(HttpRequest.Verb.valueOf(httpMethod.name()))
.build();
return new RibbonHttpRequest(request, client, clientConfig);
}
示例3: testCookiePolicy
import com.netflix.niws.client.http.RestClient; //导入依赖的package包/类
@SuppressWarnings("deprecation")
@Test
public void testCookiePolicy() {
SpringClientFactory factory = new SpringClientFactory();
AnnotationConfigApplicationContext parent = new AnnotationConfigApplicationContext();
addEnvironment(parent, "ribbon.restclient.enabled=true");
parent.register(RibbonAutoConfiguration.class, ArchaiusAutoConfiguration.class);
parent.refresh();
factory.setApplicationContext(parent);
RestClient client = factory.getClient("foo", RestClient.class);
ApacheHttpClient4 jerseyClient = (ApacheHttpClient4) client.getJerseyClient();
assertEquals(CookiePolicy.IGNORE_COOKIES, jerseyClient.getClientHandler()
.getHttpClient().getParams().getParameter(ClientPNames.COOKIE_POLICY));
parent.close();
factory.destroy();
}
示例4: testConnectionPoolCleaner
import com.netflix.niws.client.http.RestClient; //导入依赖的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();
}
示例5: run
import com.netflix.niws.client.http.RestClient; //导入依赖的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);
}
}
示例6: run
import com.netflix.niws.client.http.RestClient; //导入依赖的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);
}
}
示例7: run
import com.netflix.niws.client.http.RestClient; //导入依赖的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);
}
}
示例8: TraceRestClientRibbonCommand
import com.netflix.niws.client.http.RestClient; //导入依赖的package包/类
@SuppressWarnings("deprecation")
public TraceRestClientRibbonCommand(String commandKey, RestClient restClient,
HttpRequest.Verb verb, String uri, Boolean retryable,
MultiValueMap<String, String> headers,
MultiValueMap<String, String> params, InputStream requestEntity,
Tracer tracer, SpanInjector<HttpRequest.Builder> spanInjector,
HttpTraceKeysInjector httpTraceKeysInjector)
throws URISyntaxException {
super(commandKey, restClient, verb, uri, retryable, headers, params,
requestEntity);
this.tracer = tracer;
this.spanInjector = spanInjector;
this.httpTraceKeysInjector = httpTraceKeysInjector;
}
示例9: setup
import com.netflix.niws.client.http.RestClient; //导入依赖的package包/类
@Before
@SuppressWarnings({ "deprecation", "unchecked" })
public void setup() {
this.traceRestClientRibbonCommandFactory = new TraceRestClientRibbonCommandFactory(
this.springClientFactory, this.tracer, this.spanInjector,
httpTraceKeysInjector);
given(this.springClientFactory.getClient(anyString(), any(Class.class)))
.willReturn(new RestClient());
Span span = Span.builder().name("name").spanId(1L).traceId(2L).parent(3L)
.processId("processId").build();
given(this.tracer.getCurrentSpan()).willReturn(span);
given(this.tracer.isTracing()).willReturn(true);
}
示例10: create
import com.netflix.niws.client.http.RestClient; //导入依赖的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;
}
示例11: JerseyHystrixCommand
import com.netflix.niws.client.http.RestClient; //导入依赖的package包/类
public JerseyHystrixCommand(final MethodInfo methodInfo,
final RestClient client, final RestAdapterConfig config,
final Object[] args) {
super(methodInfo.getSetter());
this.methodInfo = methodInfo;
this.restClient = client;
this.restAdapterConfig = config;
this.args = args;
}
示例12: RibbonHttpRequest
import com.netflix.niws.client.http.RestClient; //导入依赖的package包/类
public RibbonHttpRequest(URI uri, HttpRequest.Verb verb, RestClient client,
IClientConfig config) {
this.uri = uri;
this.verb = verb;
this.client = client;
this.config = config;
this.builder = HttpRequest.newBuilder().uri(uri).verb(verb);
}
示例13: ribbonRestClient
import com.netflix.niws.client.http.RestClient; //导入依赖的package包/类
/**
* Create a Netflix {@link RestClient} integrated with Ribbon if none already exists
* in the application context. It is not required for Ribbon to work properly and is
* therefore created lazily if ever another component requires it.
*
* @param config the configuration to use by the underlying Ribbon instance
* @param loadBalancer the load balancer to use by the underlying Ribbon instance
* @param serverIntrospector server introspector to use by the underlying Ribbon instance
* @param retryHandler retry handler to use by the underlying Ribbon instance
* @return a {@link RestClient} instances backed by Ribbon
*/
@Bean
@Lazy
@ConditionalOnMissingBean(AbstractLoadBalancerAwareClient.class)
public RestClient ribbonRestClient(IClientConfig config, ILoadBalancer loadBalancer,
ServerIntrospector serverIntrospector, RetryHandler retryHandler) {
RestClient client = new RibbonClientConfiguration.OverrideRestClient(config, serverIntrospector);
client.setLoadBalancer(loadBalancer);
client.setRetryHandler(retryHandler);
Monitors.registerObject("Client_" + this.name, client);
return client;
}
示例14: createRequest
import com.netflix.niws.client.http.RestClient; //导入依赖的package包/类
@Override
@SuppressWarnings("deprecation")
public ClientHttpRequest createRequest(URI originalUri, HttpMethod httpMethod)
throws IOException {
String serviceId = originalUri.getHost();
if (serviceId == null) {
throw new IOException(
"Invalid hostname in the URI [" + originalUri.toASCIIString() + "]");
}
IClientConfig clientConfig = this.clientFactory.getClientConfig(serviceId);
RestClient client = this.clientFactory.getClient(serviceId, RestClient.class);
HttpRequest.Verb verb = HttpRequest.Verb.valueOf(httpMethod.name());
return new RibbonHttpRequest(originalUri, verb, client, clientConfig);
}
示例15: create
import com.netflix.niws.client.http.RestClient; //导入依赖的package包/类
@Override
@SuppressWarnings("deprecation")
public RestClientRibbonCommand create(RibbonCommandContext context) {
String serviceId = context.getServiceId();
FallbackProvider fallbackProvider = getFallbackProvider(serviceId);
RestClient restClient = this.clientFactory.getClient(serviceId,
RestClient.class);
return new RestClientRibbonCommand(context.getServiceId(), restClient, context,
this.zuulProperties, fallbackProvider, clientFactory.getClientConfig(serviceId));
}