当前位置: 首页>>代码示例>>Java>>正文


Java RestClient类代码示例

本文整理汇总了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);
	}
}
 
开发者ID:reshmik,项目名称:Zipkin,代码行数:17,代码来源:TraceRestClientRibbonCommandFactory.java

示例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);
}
 
开发者ID:kamkie,项目名称:micro-service-example,代码行数:20,代码来源:RibbonClientHttpRequestFactory.java

示例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();
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-netflix,代码行数:17,代码来源:SpringClientFactoryTests.java

示例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();
}
 
开发者ID:Netflix,项目名称:ribbon,代码行数:22,代码来源:NamedConnectionPoolTest.java

示例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);
	}
}
 
开发者ID:Netflix,项目名称:recipes-rss,代码行数:25,代码来源:AddRSSCommand.java

示例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);
	}
}
 
开发者ID:Netflix,项目名称:recipes-rss,代码行数:23,代码来源:GetRSSCommand.java

示例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);
	}
}
 
开发者ID:Netflix,项目名称:recipes-rss,代码行数:24,代码来源:DeleteRSSCommand.java

示例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;
}
 
开发者ID:reshmik,项目名称:Zipkin,代码行数:15,代码来源:TraceRestClientRibbonCommandFactory.java

示例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);
}
 
开发者ID:reshmik,项目名称:Zipkin,代码行数:14,代码来源:TraceRestClientRibbonCommandFactoryTest.java

示例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;
}
 
开发者ID:kenzanlabs,项目名称:bowtie,代码行数:29,代码来源:RestAdapter.java

示例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;
}
 
开发者ID:kenzanlabs,项目名称:bowtie,代码行数:10,代码来源:JerseyHystrixCommand.java

示例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);
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-netflix,代码行数:9,代码来源:RibbonHttpRequest.java

示例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;
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-netflix,代码行数:23,代码来源:RestClientRibbonConfiguration.java

示例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);
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-netflix,代码行数:16,代码来源:RibbonClientHttpRequestFactory.java

示例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));
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-netflix,代码行数:11,代码来源:RestClientRibbonCommandFactory.java


注:本文中的com.netflix.niws.client.http.RestClient类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。