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


Java Verb类代码示例

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


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

示例1: isCachable

import com.netflix.client.http.HttpRequest.Verb; //导入依赖的package包/类
public boolean isCachable(HttpRequest request) {

        boolean isCacheable = true;
        
        LOGGER.debug("Verb: {}", request.getVerb());
        if(request.getVerb() == Verb.GET){
            
            final Optional<String> cacheControl = 
                            Optional.ofNullable(request.getHeaders().get("Cache-Control"))
                                .map(list -> list.stream().findFirst().orElse(""));
            
            LOGGER.debug("Found Cache-Control header: {}", cacheControl.isPresent());
            if (cacheControl.isPresent()) {
                // Explicitly cannot cache if the response has an unacceptable
                // cache-control header
                if (UNACCEPTABLE_CACHE_CONTROL_VALUE.stream().anyMatch(a -> cacheControl.get().contains(a))) {
                    LOGGER.debug("Found UNACCEPTABLE_CACHE_CONTROL_VALUE in request");
                    
                    isCacheable = false;
                }
            }
        }
        
        LOGGER.debug("Request isCacheable: {}", isCacheable);
        return isCacheable;
    }
 
开发者ID:kenzanlabs,项目名称:bowtie,代码行数:27,代码来源:RestCachingPolicy.java

示例2: testNullEntityWithOldConstruct

import com.netflix.client.http.HttpRequest.Verb; //导入依赖的package包/类
/**
 * Tests old constructors kept for backwards compatibility with Spring Cloud Sleuth 1.x versions
 */
@Test
@Deprecated
public void testNullEntityWithOldConstruct() throws Exception {
	String uri = "http://example.com";
	LinkedMultiValueMap<String, String> headers = new LinkedMultiValueMap<>();
	headers.add("my-header", "my-value");
	LinkedMultiValueMap<String, String> params = new LinkedMultiValueMap<>();
	params.add("myparam", "myparamval");
	RestClientRibbonCommand command = 
			new RestClientRibbonCommand("cmd", null,Verb.GET ,uri, false, headers, params, null);

	HttpRequest request = command.createRequest();

	assertThat("uri is wrong", request.getUri().toString(), startsWith(uri));
	assertThat("my-header is wrong", request.getHttpHeaders().getFirstValue("my-header"), is(equalTo("my-value")));
	assertThat("myparam is missing", request.getQueryParams().get("myparam").iterator().next(), is(equalTo("myparamval")));
	
	command = 
			new RestClientRibbonCommand("cmd", null,
			new RibbonCommandContext("example", "GET", uri, false, headers, params, null),
			zuulProperties);

	request = command.createRequest();

	assertThat("uri is wrong", request.getUri().toString(), startsWith(uri));
	assertThat("my-header is wrong", request.getHttpHeaders().getFirstValue("my-header"), is(equalTo("my-value")));
	assertThat("myparam is missing", request.getQueryParams().get("myparam").iterator().next(), is(equalTo("myparamval")));
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-netflix,代码行数:32,代码来源:RestClientRibbonCommandTests.java

示例3: testPost

import com.netflix.client.http.HttpRequest.Verb; //导入依赖的package包/类
@Test
public void testPost() throws Exception {
	URI getUri = new URI(SERVICE_URI + "test/setObject");
	TestObject obj = new TestObject();
	obj.name = "fromClient";
	HttpRequest request = HttpRequest.newBuilder().verb(Verb.POST).uri(getUri).entity(obj).build();
	HttpResponse response = client.execute(request);
	assertEquals(200, response.getStatus());
	assertTrue(response.getEntity(TestObject.class).name.equals("fromClient"));
}
 
开发者ID:Netflix,项目名称:ribbon,代码行数:11,代码来源:GetPostTest.java

示例4: testChunkedEncoding

import com.netflix.client.http.HttpRequest.Verb; //导入依赖的package包/类
@Test
public void testChunkedEncoding() throws Exception {
    String obj = "chunked encoded content";
	URI postUri = new URI(SERVICE_URI + "test/postStream");
	InputStream input = new ByteArrayInputStream(obj.getBytes("UTF-8"));
	HttpRequest request = HttpRequest.newBuilder().verb(Verb.POST).uri(postUri).entity(input).build();
	HttpResponse response = client.execute(request);
	assertEquals(200, response.getStatus());
	assertTrue(response.getEntity(String.class).equals(obj));
}
 
开发者ID:Netflix,项目名称:ribbon,代码行数:11,代码来源:GetPostTest.java

示例5: postReadTimeout

import com.netflix.client.http.HttpRequest.Verb; //导入依赖的package包/类
@Test
public void postReadTimeout() throws Exception {
    URI localUrl = new URI("/noresponse");
    HttpRequest request = HttpRequest.newBuilder().uri(localUrl).verb(Verb.POST).build();
    try {
        client.executeWithLoadBalancer(request, DefaultClientConfigImpl.getEmptyConfig().set(CommonClientConfigKey.MaxAutoRetriesNextServer, 2));
        fail("Exception expected");
    } catch (ClientException e) { // NOPMD
    }
    ServerStats stats = lb.getLoadBalancerStats().getSingleServerStat(localServer); 
    assertEquals(1, stats.getSuccessiveConnectionFailureCount());
}
 
开发者ID:Netflix,项目名称:ribbon,代码行数:13,代码来源:RetryTest.java

示例6: testRetriesOnPost

import com.netflix.client.http.HttpRequest.Verb; //导入依赖的package包/类
@Test
public void testRetriesOnPost() throws Exception {
    URI localUrl = new URI("/noresponse");
    HttpRequest request = HttpRequest.newBuilder().uri(localUrl).verb(Verb.POST).setRetriable(true).build();
    try {
        client.executeWithLoadBalancer(request, DefaultClientConfigImpl.getEmptyConfig().set(CommonClientConfigKey.MaxAutoRetriesNextServer, 2));
        fail("Exception expected");
    } catch (ClientException e) { // NOPMD
    }
    ServerStats stats = lb.getLoadBalancerStats().getSingleServerStat(localServer); 
    assertEquals(3, stats.getSuccessiveConnectionFailureCount());
}
 
开发者ID:Netflix,项目名称:ribbon,代码行数:13,代码来源:RetryTest.java

示例7: testRetriesOnPostWithConnectException

import com.netflix.client.http.HttpRequest.Verb; //导入依赖的package包/类
@Test
public void testRetriesOnPostWithConnectException() throws Exception {
    URI localUrl = new URI("/status?code=503");
    lb.setServersList(Lists.newArrayList(localServer));
    HttpRequest request = HttpRequest.newBuilder().uri(localUrl).verb(Verb.POST).setRetriable(true).build();
    try {
        HttpResponse response = client.executeWithLoadBalancer(request, DefaultClientConfigImpl.getEmptyConfig().set(CommonClientConfigKey.MaxAutoRetriesNextServer, 2));
        fail("Exception expected");
    } catch (ClientException e) { // NOPMD
    }
    ServerStats stats = lb.getLoadBalancerStats().getSingleServerStat(localServer); 
    assertEquals(3, stats.getSuccessiveConnectionFailureCount());
}
 
开发者ID:Netflix,项目名称:ribbon,代码行数:14,代码来源:RetryTest.java


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