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

Java Response类代码示例

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

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



Response类属于com.ecwid.consul.v1包,在下文中一共展示了Response类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: lookupRouterMessage

import com.ecwid.consul.v1.Response; //导入依赖的package包/类
public ConsulRouterResp lookupRouterMessage(String serviceName, long lastConsulIndex) {
    QueryParams queryParams = new QueryParams(ConsulConstants.CONSUL_BLOCK_TIME_SECONDS, lastConsulIndex);
    Response<GetValue> orgResponse = client.getKVValue(serviceName, queryParams);
    GetValue getValue = orgResponse.getValue();
    if (getValue != null && StringUtils.isNoneBlank(getValue.getValue())) {
        String router = new String(Base64.decodeBase64(getValue.getValue()));
        ConsulRouterResp response = ConsulRouterResp.newResponse()//
                                                    .withValue(router)//
                                                    .withConsulIndex(orgResponse.getConsulIndex())//
                                                    .withConsulLastContact(orgResponse.getConsulLastContact())//
                                                    .withConsulKnowLeader(orgResponse.isConsulKnownLeader())//
                                                    .build();
        return response;
    }
    return null;
}
 
开发者ID:venus-boot,项目名称:saluki,代码行数:17,代码来源:ConsulClient.java


示例2: testEmptyResolution

import com.ecwid.consul.v1.Response; //导入依赖的package包/类
@Test
public void testEmptyResolution() throws Exception {
    final Response<List<CatalogService>> response = composeResponse(new ArrayList<>());

    new Expectations() {{
        catalogClient.getCatalogService(SERVICE_NAME, QueryParams.DEFAULT);
        result = response;
        times = 1;
    }};

    final List<NameResolverEvent<?>> events = runTest(resolver, 1);
    assertEquals(1, events.size());

    final NameResolverEvent e  = events.get(0);
    assertEquals(NameResolverEventType.ON_ADDRESSES, e.type);
    assertTrue(((List) e.payload).isEmpty());
}
 
开发者ID:indeedeng-alpha,项目名称:indeed-grpc-java,代码行数:18,代码来源:ConsulNameResolverTest.java


示例3: beforeClass

import com.ecwid.consul.v1.Response; //导入依赖的package包/类
@BeforeClass
public static void beforeClass() {

	assumeTrue(CanConnect.to(new InetSocketAddress(CONSUL_HOST, CONSUL_PORT)));

	ConsulClient client = new ConsulClient();

	Response<List<CatalogService>> response = client.getCatalogService("vault",
			QueryParams.DEFAULT);

	if (response.getValue().isEmpty()) {

		NewService service = new NewService();
		service.setAddress("localhost");
		service.setPort(8200);
		service.setId("vault");
		service.setName("vault");

		client.agentServiceRegister(service);
	}
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-vault,代码行数:22,代码来源:DiscoveryBootstrapConfigurationTests.java


示例4: getKVValue

import com.ecwid.consul.v1.Response; //导入依赖的package包/类
@Override
public Response<GetValue> getKVValue(String key, String token, QueryParams queryParams) {
	UrlParameters tokenParams = token != null ? new SingleUrlParameters("token", token) : null;
	RawResponse rawResponse = rawClient.makeGetRequest("/v1/kv/" + key, tokenParams, queryParams);

	if (rawResponse.getStatusCode() == 200) {
		List<GetValue> value = GsonFactory.getGson().fromJson(rawResponse.getContent(), new TypeToken<List<GetValue>>(){}.getType());

		if (value.size() == 0) {
			return new Response<GetValue>(null, rawResponse);
		} else if (value.size() == 1) {
			return new Response<GetValue>(value.get(0), rawResponse);
		} else {
			throw new ConsulException("Strange response (list size=" + value.size() + ")");
		}
	} else if (rawResponse.getStatusCode() == 404) {
		return new Response<GetValue>(null, rawResponse);
	} else {
		throw new OperationException(rawResponse);
	}
}
 
开发者ID:flyaruu,项目名称:tasman,代码行数:22,代码来源:KeyValueConsulClient.java


示例5: getSessionInfo

import com.ecwid.consul.v1.Response; //导入依赖的package包/类
@Override
public Response<Session> getSessionInfo(String session, QueryParams queryParams) {
	RawResponse rawResponse = rawClient.makeGetRequest("/v1/session/info/" + session, queryParams);

	if (rawResponse.getStatusCode() == 200) {
		List<Session> value = GsonFactory.getGson().fromJson(rawResponse.getContent(), new TypeToken<List<Session>>() {
		}.getType());

		if (value.isEmpty()) {
			return new Response<Session>(null, rawResponse);
		} else if (value.size() == 1) {
			return new Response<Session>(value.get(0), rawResponse);
		} else {
			throw new ConsulException("Strange response (list size=" + value.size() + ")");
		}
	} else {
		throw new OperationException(rawResponse);
	}
}
 
开发者ID:flyaruu,项目名称:tasman,代码行数:20,代码来源:SessionConsulClient.java


示例6: loadConsulSettings

import com.ecwid.consul.v1.Response; //导入依赖的package包/类
private Map<String, String> loadConsulSettings(String serviceId) {
	Response<List<GetBinaryValue>> result = keyValueClient.getKVBinaryValues(serviceId);
	List<GetBinaryValue> list = result.getValue();
	Map<String, String> dict = new HashMap<>();
	if(list!=null) {
		for (GetBinaryValue element : list) {
			String value = new String(element.getValue());
			String key = element.getKey();
			String[] keyparts = key.split("/");
			if(value!=null) {
				dict.put(keyparts[1], value);
			}
		}
	}
	return dict;
}
 
开发者ID:flyaruu,项目名称:tasman,代码行数:17,代码来源:ConsulBridgeOSGi.java


示例7: getServiceInstances

import com.ecwid.consul.v1.Response; //导入依赖的package包/类
@Override
protected List<ServerInstance> getServiceInstances(String serviceName) {
    List<ServiceInstance> instances = new ArrayList<>();

    Response<List<HealthService>> healthServices = consulClient.getHealthServices(serviceName, true, QueryParams.DEFAULT);
    for (HealthService healthService : healthServices.getValue()) {
        if (isPassingChecks(healthService)) {
            String host = findHost(healthService);
            instances.add(new DefaultServiceInstance(serviceName, host,
                    healthService.getService().getPort(), false, getMetadata(healthService)));
        }
    }
    return convertToServerInstanceList(instances);
}
 
开发者ID:darren-fu,项目名称:RestyPass,代码行数:15,代码来源:CloudConsulServerContext.java


示例8: lookupHealthService

import com.ecwid.consul.v1.Response; //导入依赖的package包/类
public ConsulServiceResp lookupHealthService(String serviceName, long lastConsulIndex) {
    QueryParams queryParams = new QueryParams(ConsulConstants.CONSUL_BLOCK_TIME_SECONDS, lastConsulIndex);
    Response<List<HealthService>> orgResponse = client.getHealthServices(serviceName, true, queryParams);
    if (orgResponse != null && orgResponse.getValue() != null && !orgResponse.getValue().isEmpty()) {
        List<HealthService> HealthServices = orgResponse.getValue();
        List<ConsulService> ConsulServcies = Lists.newArrayList();
        for (HealthService orgService : HealthServices) {
            Service org = orgService.getService();
            ConsulService newService = ConsulService.newSalukiService()//
                                                    .withAddress(org.getAddress())//
                                                    .withName(org.getService())//
                                                    .withId(org.getId())//
                                                    .withPort(org.getPort().toString())//
                                                    .withTags(org.getTags())//
                                                    .build();
            ConsulServcies.add(newService);
        }
        if (!ConsulServcies.isEmpty()) {
            ConsulServiceResp response = ConsulServiceResp.newResponse()//
                                                          .withValue(ConsulServcies)//
                                                          .withConsulIndex(orgResponse.getConsulIndex())//
                                                          .withConsulLastContact(orgResponse.getConsulLastContact())//
                                                          .withConsulKnowLeader(orgResponse.isConsulKnownLeader())//
                                                          .build();
            return response;
        }
    }
    return null;
}
 
开发者ID:venus-boot,项目名称:saluki,代码行数:30,代码来源:ConsulClient.java


示例9: testFixedResolution

import com.ecwid.consul.v1.Response; //导入依赖的package包/类
@Test
public void testFixedResolution() throws Exception {
    final CatalogService service = new CatalogService();
    service.setAddress("localhost");
    service.setServicePort(8080);

    final List<CatalogService> services = new ArrayList<>();
    services.add(service);

    final Response<List<CatalogService>> response = composeResponse(services);

    new Expectations() {{
        catalogClient.getCatalogService(SERVICE_NAME, QueryParams.DEFAULT);
        result = response;
        times = 1;
    }};

    final List<NameResolverEvent<?>> events = runTest(resolver, 1);
    assertEquals(1, events.size());

    final NameResolverEvent e  = events.get(0);
    assertEquals(NameResolverEventType.ON_ADDRESSES, e.type);

    final List<EquivalentAddressGroup> addressGroups = (List<EquivalentAddressGroup>) e.payload;
    assertEquals(1, addressGroups.size());

    final List<SocketAddress> addresses = addressGroups.get(0).getAddresses();
    assertEquals(1, addresses.size());

    final InetSocketAddress inetAddress = (InetSocketAddress) addresses.get(0);
    assertEquals("localhost", inetAddress.getHostName());
    assertEquals(8080, inetAddress.getPort());
}
 
开发者ID:indeedeng-alpha,项目名称:indeed-grpc-java,代码行数:34,代码来源:ConsulNameResolverTest.java


示例10: getProviderUrls

import com.ecwid.consul.v1.Response; //导入依赖的package包/类
public List<URL> getProviderUrls(String serviceName) {
    List<URL> urls = new ArrayList<>();
    Response<List<HealthService>> healthServices = consulClient.getHealthServices(serviceName, true, null);
    for (HealthService healthService : healthServices.getValue()) {
        urls.add(URL.valueOf(healthService.getService().getAddress()));
    }
    return urls;
}
 
开发者ID:linux-china,项目名称:dubbo3,代码行数:9,代码来源:NotifyListenerConsulWrapper.java


示例11: testGetRateException

import com.ecwid.consul.v1.Response; //导入依赖的package包/类
@Test
public void testGetRateException() throws IOException {
    GetValue getValue = new GetValue();
    getValue.setValue("");
    when(consulClient.getKVValue(any())).thenReturn(new Response<>(getValue, 1L, true, 1L));
    when(objectMapper.readValue(anyString(), eq(Rate.class))).thenThrow(new IOException());
    ConsulRateLimiter consulRateLimiter = new ConsulRateLimiter(rateLimiterErrorHandler, consulClient, objectMapper);

    Rate rate = consulRateLimiter.getRate("");
    assertThat(rate).isNull();
}
 
开发者ID:marcosbarbero,项目名称:spring-cloud-zuul-ratelimit,代码行数:12,代码来源:ConsulRateLimiterTest.java


示例12: testRateLimitExceedCapacity

import com.ecwid.consul.v1.Response; //导入依赖的package包/类
@Test
@Override
@SuppressWarnings("unchecked")
public void testRateLimitExceedCapacity() throws Exception {
    Response<GetValue> response = mock(Response.class);
    GetValue getValue = mock(GetValue.class);
    when(this.consulClient.getKVValue(anyString())).thenReturn(response);
    when(response.getValue()).thenReturn(getValue);
    when(getValue.getDecodedValue()).thenReturn(this.objectMapper.writeValueAsString(this.rate(-1)));
    super.testRateLimitExceedCapacity();
}
 
开发者ID:marcosbarbero,项目名称:spring-cloud-zuul-ratelimit,代码行数:12,代码来源:ConsulRateLimitPreFilterTest.java


示例13: testRateLimit

import com.ecwid.consul.v1.Response; //导入依赖的package包/类
@Test
@Override
@SuppressWarnings("unchecked")
public void testRateLimit() throws Exception {
    Response<GetValue> response = mock(Response.class);
    GetValue getValue = mock(GetValue.class);
    when(this.consulClient.getKVValue(anyString())).thenReturn(response);
    when(response.getValue()).thenReturn(getValue);
    when(getValue.getDecodedValue()).thenReturn(this.objectMapper.writeValueAsString(this.rate(1)));

    this.request.setRequestURI("/serviceA");
    this.request.setRemoteAddr("10.0.0.100");

    assertTrue(this.filter.shouldFilter());

    for (int i = 0; i < 2; i++) {
        this.filter.run();
    }

    String key = "null_serviceA_serviceA_10.0.0.100_anonymous";
    String remaining = this.response.getHeader(RateLimitPreFilter.REMAINING_HEADER + key);
    assertEquals("0", remaining);

    TimeUnit.SECONDS.sleep(2);

    when(getValue.getDecodedValue()).thenReturn(this.objectMapper.writeValueAsString(this.rate(2)));
    this.filter.run();
    remaining = this.response.getHeader(RateLimitPreFilter.REMAINING_HEADER + key);
    assertEquals("1", remaining);
}
 
开发者ID:marcosbarbero,项目名称:spring-cloud-zuul-ratelimit,代码行数:31,代码来源:ConsulRateLimitPreFilterTest.java


示例14: convertToMap

import com.ecwid.consul.v1.Response; //导入依赖的package包/类
private ImmutableMap<String, Object> convertToMap(Response<List<GetValue>> kv) {
    if (kv == null || kv.getValue() == null) {
        return ImmutableMap.of();
    }
    ImmutableMap.Builder<String, Object> builder = ImmutableMap.builder();
    for(GetValue gv : kv.getValue()) {
        builder.put(keyFunc(gv), valFunc(gv));
    }
    return builder.build();
}
 
开发者ID:boundary,项目名称:archaius-consul,代码行数:11,代码来源:ConsulWatchedConfigurationSource.java


示例15: testAdded

import com.ecwid.consul.v1.Response; //导入依赖的package包/类
@Test
@Repeat(iterations = 5)
public void testAdded() throws Exception {

    final Response<List<GetValue>> initialResponse = randomListGetValueResponse();
    final GetValue added = randomGetVal();
    final List<GetValue> updatedList = Lists.newArrayList(initialResponse.getValue());
    updatedList.add(added);
    final Response<List<GetValue>> initialResponsePlus = randomResponse(updatedList);
    //noinspection unchecked
    when(client.getKVValues(eq(rootPath), any(QueryParams.class))).thenReturn(initialResponse, initialResponsePlus);

    UpdateListener listener = new UpdateListener();
    configSource.addUpdateListener(listener);

    configSource.runOnce();

    assertThat(configSource.getLatestIndex(), is(initialResponse.getConsulIndex()));

    configSource.runOnce();

    assertThat(configSource.getLatestIndex(), is(initialResponsePlus.getConsulIndex()));
    assertThat(listener.events.get(), is(2));
    assertThat(configSource.getCurrentData().values(), hasItem(decodeVal(added.getValue())));

    WatchedUpdateResult result = listener.results.get(1);
    assertThat(result.getAdded().values(), hasItem(decodeVal(added.getValue())));
    assertThat(result.getDeleted().isEmpty(), is(true));
    assertThat(result.getChanged().isEmpty(), is(true));
    assertThat(result.isIncremental(), is(true));


}
 
开发者ID:boundary,项目名称:archaius-consul,代码行数:34,代码来源:ConsulWatchedConfigurationSourceTest.java


示例16: getAclList

import com.ecwid.consul.v1.Response; //导入依赖的package包/类
@Override
public Response<List<Acl>> getAclList(String token) {
	UrlParameters tokenParams = token != null ? new SingleUrlParameters("token", token) : null;
	RawResponse rawResponse = rawClient.makeGetRequest("/v1/acl/list", tokenParams);

	if (rawResponse.getStatusCode() == 200) {
		List<Acl> value = GsonFactory.getGson().fromJson(rawResponse.getContent(), new TypeToken<List<Acl>>() {
		}.getType());
		return new Response<List<Acl>>(value, rawResponse);
	} else {
		throw new OperationException(rawResponse);
	}
}
 
开发者ID:flyaruu,项目名称:tasman,代码行数:14,代码来源:AclConsulClient.java


示例17: catalogRegister

import com.ecwid.consul.v1.Response; //导入依赖的package包/类
@Override
public Response<Void> catalogRegister(CatalogRegistration catalogRegistration) {
	String json = GsonFactory.getGson().toJson(catalogRegistration);

	RawResponse rawResponse = rawClient.makePutRequest("/v1/catalog/register", json);
	if (rawResponse.getStatusCode() == 200) {
		return new Response<Void>(null, rawResponse);
	} else {
		throw new OperationException(rawResponse);
	}
}
 
开发者ID:flyaruu,项目名称:tasman,代码行数:12,代码来源:CatalogConsulClient.java


示例18: getAgentServices

import com.ecwid.consul.v1.Response; //导入依赖的package包/类
@Override
public Response<Map<String, Service>> getAgentServices() {
	RawResponse rawResponse = rawClient.makeGetRequest("/v1/agent/services");

	if (rawResponse.getStatusCode() == 200) {
		Map<String, Service> agentServices = GsonFactory.getGson().fromJson(rawResponse.getContent(), new TypeToken<Map<String, Service>>() {
		}.getType());
		return new Response<Map<String, Service>>(agentServices, rawResponse);
	} else {
		throw new OperationException(rawResponse);
	}
}
 
开发者ID:flyaruu,项目名称:tasman,代码行数:13,代码来源:AgentConsulClient.java


示例19: sessionCreate

import com.ecwid.consul.v1.Response; //导入依赖的package包/类
@Override
public Response<String> sessionCreate(NewSession newSession, QueryParams queryParams) {
	String json = GsonFactory.getGson().toJson(newSession);
	RawResponse rawResponse = rawClient.makePutRequest("/v1/session/create", json, queryParams);

	if (rawResponse.getStatusCode() == 200) {
		Map<String, String> value = GsonFactory.getGson().fromJson(rawResponse.getContent(), new TypeToken<Map<String, String>>() {
		}.getType());
		return new Response<String>(value.get("ID"), rawResponse);
	} else {
		throw new OperationException(rawResponse);
	}
}
 
开发者ID:flyaruu,项目名称:tasman,代码行数:14,代码来源:SessionConsulClient.java


示例20: getHealthChecksState

import com.ecwid.consul.v1.Response; //导入依赖的package包/类
@Override
public Response<List<Check>> getHealthChecksState(Check.CheckStatus checkStatus, QueryParams queryParams) {
	String status = checkStatus == null ? "ANY" : checkStatus.name().toLowerCase();
	RawResponse rawResponse = rawClient.makeGetRequest("/v1/health/state/" + status, queryParams);

	if (rawResponse.getStatusCode() == 200) {
		List<Check> value = GsonFactory.getGson().fromJson(rawResponse.getContent(), new TypeToken<List<Check>>() {
		}.getType());
		return new Response<List<Check>>(value, rawResponse);
	} else {
		throw new OperationException(rawResponse);
	}
}
 
开发者ID:flyaruu,项目名称:tasman,代码行数:14,代码来源:HealthConsulClient.java



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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