• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java RestClient类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中com.netflix.niws.client.http.RestClient的典型用法代码示例。如果您正苦于以下问题:Java RestClient类的具体用法?Java RestClient怎么用?Java RestClient使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



RestClient类属于com.netflix.niws.client.http包,在下文中一共展示了RestClient类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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


示例16: RestClientRibbonCommand

import com.netflix.niws.client.http.RestClient; //导入依赖的package包/类
@Deprecated
public RestClientRibbonCommand(String commandKey, RestClient restClient,
		HttpRequest.Verb verb, String uri, Boolean retryable,
		MultiValueMap<String, String> headers, MultiValueMap<String, String> params,
		InputStream requestEntity) {
	this(commandKey, restClient, new RibbonCommandContext(commandKey, verb.verb(),
			uri, retryable, headers, params, requestEntity), new ZuulProperties());
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-netflix,代码行数:9,代码来源:RestClientRibbonCommand.java


示例17: create

import com.netflix.niws.client.http.RestClient; //导入依赖的package包/类
@Override
@SuppressWarnings("deprecation")
public RestClientRibbonCommand create(RibbonCommandContext context) {
	String uri = context.getUri();
	if (uri.startsWith("/throwexception/")) {
		String code = uri.replace("/throwexception/", "");
		RestClient restClient = clientFactory
				.getClient(context.getServiceId(), RestClient.class);
		return new MyCommand(Integer.parseInt(code), context.getServiceId(),
				restClient, context);
	}
	return super.create(context);
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-netflix,代码行数:14,代码来源:RestClientRibbonCommandIntegrationTests.java


示例18: doGet

import com.netflix.niws.client.http.RestClient; //导入依赖的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();
	}
}
 
开发者ID:WASdev,项目名称:sample.netflixoss.wlp,代码行数:31,代码来源:Ribbon.java


示例19: survive

import com.netflix.niws.client.http.RestClient; //导入依赖的package包/类
@Test
public void survive() throws IOException, ClientException, URISyntaxException, InterruptedException {

    String clientName = "RibbonClientTest-loadBalancingDefaultPolicyRoundRobin";
    String serverListKey = clientName + ".ribbon.listOfServers";
    int nbHitsPerServer = 60;
    MockWebServer server1 = new MockWebServer();
    MockWebServer server2 = new MockWebServer();

    for (int i = 0; i < nbHitsPerServer; i++) {
        server1.enqueue(new MockResponse().setResponseCode(200).setBody("server1 success <" + i + ">!"));
        server2.enqueue(new MockResponse().setResponseCode(200).setBody("server2 success <" + i + ">!"));
    }

    server1.play();
    server2.play();

    getConfigInstance().setProperty(serverListKey, hostAndPort(server1.getUrl("")) + "," + hostAndPort(server2.getUrl("")));

    RestClient client = (RestClient) ClientFactory.getNamedClient(clientName);
    HttpRequest request;
    for (int i = 0; i < nbHitsPerServer * 2; i++) {
        request = HttpRequest.newBuilder().uri(new URI("/")).build();
        HttpResponse response = client.executeWithLoadBalancer(request);
        response.close();
    }
}
 
开发者ID:Netflix,项目名称:ribbon,代码行数:28,代码来源:ManyShortLivedRequestsSurvivorTest.java


示例20: ElasticSearchSink

import com.netflix.niws.client.http.RestClient; //导入依赖的package包/类
public ElasticSearchSink(
    @JsonProperty("clientName") String clientName,
    @JsonProperty("queue4Sink") MessageQueue4Sink queue4Sink,
    @JsonProperty("batchSize") int batchSize,
    @JsonProperty("batchTimeout") int batchTimeout,
    @JsonProperty("addressList") List<String> addressList,
    @JsonProperty("indexInfo") @JacksonInject IndexInfoBuilder indexInfo,
    @JsonProperty("jobQueueSize") int jobQueueSize,
    @JsonProperty("corePoolSize") int corePoolSize,
    @JsonProperty("maxPoolSize") int maxPoolSize,
    @JsonProperty("jobTimeout") long jobTimeout,
    @JsonProperty("sleepOverClientException") int sleepOverClientException,
    @JsonProperty("ribbon.etc") Properties ribbonEtc,
    @JsonProperty("reEnqueueOnException") boolean reEnqueueOnException,
    @JacksonInject ObjectMapper jsonMapper,
    @JacksonInject RestClient client) {
    super(jobQueueSize, corePoolSize, maxPoolSize, jobTimeout, clientName);

    this.indexInfo =
        indexInfo == null ? new DefaultIndexInfoBuilder(null, null, null, null, null, jsonMapper) : indexInfo;

    initialize(
        clientName,
        queue4Sink == null ? new MemoryQueue4Sink(10000) : queue4Sink,
        batchSize,
        batchTimeout,
        true);

    this.jsonMapper = jsonMapper;
    this.addressList = addressList;
    this.ribbonEtc = ribbonEtc == null ? new Properties() : ribbonEtc;
    this.clientName = clientName;
    this.client = client;
    this.timer = Servo.getTimer(clientName + "_latency");
    this.sleepOverClientException = sleepOverClientException;
    this.reEnqueueOnException = reEnqueueOnException;
}
 
开发者ID:Netflix,项目名称:suro,代码行数:38,代码来源:ElasticSearchSink.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java UserFilter类代码示例发布时间:2022-05-23
下一篇:
Java ListableJobLocator类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap