當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。