當前位置: 首頁>>代碼示例>>Java>>正文


Java HttpOptions類代碼示例

本文整理匯總了Java中org.apache.http.client.methods.HttpOptions的典型用法代碼示例。如果您正苦於以下問題:Java HttpOptions類的具體用法?Java HttpOptions怎麽用?Java HttpOptions使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


HttpOptions類屬於org.apache.http.client.methods包,在下文中一共展示了HttpOptions類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: createApacheRequest

import org.apache.http.client.methods.HttpOptions; //導入依賴的package包/類
private HttpRequestBase createApacheRequest(SdkHttpFullRequest request, String uri) {
    switch (request.method()) {
        case HEAD:
            return new HttpHead(uri);
        case GET:
            return new HttpGet(uri);
        case DELETE:
            return new HttpDelete(uri);
        case OPTIONS:
            return new HttpOptions(uri);
        case PATCH:
            return wrapEntity(request, new HttpPatch(uri));
        case POST:
            return wrapEntity(request, new HttpPost(uri));
        case PUT:
            return wrapEntity(request, new HttpPut(uri));
        default:
            throw new RuntimeException("Unknown HTTP method name: " + request.method());
    }
}
 
開發者ID:aws,項目名稱:aws-sdk-java-v2,代碼行數:21,代碼來源:ApacheHttpRequestFactory.java

示例2: testOptionsCorrectOrigin

import org.apache.http.client.methods.HttpOptions; //導入依賴的package包/類
@Test
public void testOptionsCorrectOrigin() throws Exception {
    String url = "http://localhost:8080";
    CloseableHttpClient client = HttpClients.createDefault();
    HttpOptions httpOptions = new HttpOptions(url);
    httpOptions.setHeader("Origin", "http://localhost");
    httpOptions.setHeader("Access-Control-Request-Method", "POST");
    httpOptions.setHeader("Access-Control-Request-Headers", "X-Requested-With");

    try {
        CloseableHttpResponse response = client.execute(httpOptions);
        int statusCode = response.getStatusLine().getStatusCode();
        String body = IOUtils.toString(response.getEntity().getContent(), "utf8");
        Header[] headers = response.getAllHeaders();
        Header header = response.getFirstHeader("Access-Control-Allow-Origin");
        Assert.assertEquals(200, statusCode);
        if(statusCode == 200) {
            Assert.assertNotNull(header);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
開發者ID:networknt,項目名稱:light-4j,代碼行數:24,代碼來源:CorsHttpHandlerTest.java

示例3: createHttpRequest

import org.apache.http.client.methods.HttpOptions; //導入依賴的package包/類
private static HttpRequestBase createHttpRequest(String method, URI uri, HttpEntity entity) {
    switch(method.toUpperCase(Locale.ROOT)) {
        case HttpDeleteWithEntity.METHOD_NAME:
            return addRequestBody(new HttpDeleteWithEntity(uri), entity);
        case HttpGetWithEntity.METHOD_NAME:
            return addRequestBody(new HttpGetWithEntity(uri), entity);
        case HttpHead.METHOD_NAME:
            return addRequestBody(new HttpHead(uri), entity);
        case HttpOptions.METHOD_NAME:
            return addRequestBody(new HttpOptions(uri), entity);
        case HttpPatch.METHOD_NAME:
            return addRequestBody(new HttpPatch(uri), entity);
        case HttpPost.METHOD_NAME:
            HttpPost httpPost = new HttpPost(uri);
            addRequestBody(httpPost, entity);
            return httpPost;
        case HttpPut.METHOD_NAME:
            return addRequestBody(new HttpPut(uri), entity);
        case HttpTrace.METHOD_NAME:
            return addRequestBody(new HttpTrace(uri), entity);
        default:
            throw new UnsupportedOperationException("http method not supported: " + method);
    }
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:25,代碼來源:RestClient.java

示例4: randomHttpRequest

import org.apache.http.client.methods.HttpOptions; //導入依賴的package包/類
private static HttpUriRequest randomHttpRequest(URI uri) {
    int requestType = randomIntBetween(0, 7);
    switch(requestType) {
        case 0:
            return new HttpGetWithEntity(uri);
        case 1:
            return new HttpPost(uri);
        case 2:
            return new HttpPut(uri);
        case 3:
            return new HttpDeleteWithEntity(uri);
        case 4:
            return new HttpHead(uri);
        case 5:
            return new HttpTrace(uri);
        case 6:
            return new HttpOptions(uri);
        case 7:
            return new HttpPatch(uri);
        default:
            throw new UnsupportedOperationException();
    }
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:24,代碼來源:RequestLoggerTests.java

示例5: createHttpUriRequest

import org.apache.http.client.methods.HttpOptions; //導入依賴的package包/類
/**
 * Create a Commons HttpMethodBase object for the given HTTP method and URI specification.
 * @param httpMethod the HTTP method
 * @param uri the URI
 * @return the Commons HttpMethodBase object
 */
protected HttpUriRequest createHttpUriRequest(HttpMethod httpMethod, URI uri) {
	switch (httpMethod) {
		case GET:
			return new HttpGet(uri);
		case DELETE:
			return new HttpDelete(uri);
		case HEAD:
			return new HttpHead(uri);
		case OPTIONS:
			return new HttpOptions(uri);
		case POST:
			return new HttpPost(uri);
		case PUT:
			return new HttpPut(uri);
		case TRACE:
			return new HttpTrace(uri);
		case PATCH:
			return new HttpPatch(uri);
		default:
			throw new IllegalArgumentException("Invalid HTTP method: " + httpMethod);
	}
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:29,代碼來源:HttpComponentsClientHttpRequestFactory.java

示例6: testOptionsWrongOrigin

import org.apache.http.client.methods.HttpOptions; //導入依賴的package包/類
@Test
public void testOptionsWrongOrigin() throws Exception {
    String url = "http://localhost:8080";
    CloseableHttpClient client = HttpClients.createDefault();
    HttpOptions httpOptions = new HttpOptions(url);
    httpOptions.setHeader("Origin", "http://example.com");
    httpOptions.setHeader("Access-Control-Request-Method", "POST");
    httpOptions.setHeader("Access-Control-Request-Headers", "X-Requested-With");

    try {
        CloseableHttpResponse response = client.execute(httpOptions);
        int statusCode = response.getStatusLine().getStatusCode();
        String body = IOUtils.toString(response.getEntity().getContent(), "utf8");
        Header header = response.getFirstHeader("Access-Control-Allow-Origin");
        Assert.assertEquals(200, statusCode);
        if(statusCode == 200) {
            Assert.assertNull(header);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
開發者ID:networknt,項目名稱:light-4j,代碼行數:23,代碼來源:CorsHttpHandlerTest.java

示例7: createHttpUriRequest

import org.apache.http.client.methods.HttpOptions; //導入依賴的package包/類
/**
 * Create a Commons HttpMethodBase object for the given HTTP method and URI specification.
 * @param httpMethod the HTTP method
 * @param uri the URI
 * @return the Commons HttpMethodBase object
 */
protected HttpUriRequest createHttpUriRequest(HttpMethod httpMethod, URI uri) {
	switch (httpMethod) {
		case GET:
			return new HttpGet(uri);
		case HEAD:
			return new HttpHead(uri);
		case POST:
			return new HttpPost(uri);
		case PUT:
			return new HttpPut(uri);
		case PATCH:
			return new HttpPatch(uri);
		case DELETE:
			return new HttpDelete(uri);
		case OPTIONS:
			return new HttpOptions(uri);
		case TRACE:
			return new HttpTrace(uri);
		default:
			throw new IllegalArgumentException("Invalid HTTP method: " + httpMethod);
	}
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:29,代碼來源:HttpComponentsClientHttpRequestFactory.java

示例8: getRawMethodRequest

import org.apache.http.client.methods.HttpOptions; //導入依賴的package包/類
private HttpUriRequest getRawMethodRequest()
{
	AbstractURL url = request.getUrl();

	switch(request.getMattpMethod())
	{
		case GET:
			return new HttpGet(url.toString());
		case HEAD:
			return new HttpHead(url.toString());
		case POST:
			return new HttpPost(url.toString());
		case PUT:
			return new HttpPut(url.toString());
		case DELETE:
			return new HttpDelete(url.toString());
		case TRACE:
			return new HttpTrace(url.toString());
		case OPTIONS:
			return new HttpOptions(url.toString());
		case PATCH:
			return new HttpPatch(url.toString());
	}

	throw new ShouldNeverHappenError();
}
 
開發者ID:domisum,項目名稱:AuxiliumLib,代碼行數:27,代碼來源:MattpRequestEnvoy.java

示例9: getRequest

import org.apache.http.client.methods.HttpOptions; //導入依賴的package包/類
private HttpUriRequest getRequest(AbstractURL url)
{
	switch(this)
	{
		case GET:
			return new HttpGet(url.toString());
		case HEAD:
			return new HttpHead(url.toString());
		case POST:
			return new HttpPost(url.toString());
		case PUT:
			return new HttpPut(url.toString());
		case DELETE:
			return new HttpDelete(url.toString());
		case TRACE:
			return new HttpTrace(url.toString());
		case OPTIONS:
			return new HttpOptions(url.toString());
		case PATCH:
			return new HttpPatch(url.toString());
	}

	throw new ShouldNeverHappenError();
}
 
開發者ID:domisum,項目名稱:AuxiliumLib,代碼行數:25,代碼來源:HttpFetch.java

示例10: testDeny2Man

import org.apache.http.client.methods.HttpOptions; //導入依賴的package包/類
@Test
public void testDeny2Man() throws Exception {
   log.info("start testDeny2Man()");

   HttpGet method = new HttpGet(
         getBaseURL() + "/test/spring/loginSpring?USER=Fred&ROLE=adminXXX" + "&TENANT=" + TENANT);
   HttpResponse response = client.execute(method);
   method.abort();
   Thread.sleep(20);

   log.debug("now the test");
   HttpOptions g = new HttpOptions(URL_TS + "?role=" + URLEncoder.encode("adminXXXX", "UTF-8"));
   response = client.execute(g);
   Assert.assertEquals(HttpStatus.SC_FORBIDDEN, response.getStatusLine().getStatusCode());
   readResponseBody(response);
   g.abort();
}
 
開發者ID:Wolfgang-Winter,項目名稱:cibet,代碼行數:18,代碼來源:HttpSpringSecurity2IT.java

示例11: testDeny2Man2

import org.apache.http.client.methods.HttpOptions; //導入依賴的package包/類
@Test
public void testDeny2Man2() throws Exception {
   log.info("start testDeny2Man2()");
   HttpGet method = new HttpGet(
         getBaseURL() + "/test/spring/loginSpring?USER=Fred&secondUser=NULL&ROLE=admin" + "&TENANT=" + TENANT);
   HttpResponse response = client.execute(method);
   method.abort();

   Thread.sleep(20);
   log.debug("now the test");
   HttpOptions g = new HttpOptions(URL_TS + "?role=" + URLEncoder.encode("admin", "UTF-8") + "&secondUser="
         + URLEncoder.encode("NULL", "UTF-8"));
   response = client.execute(g);
   Assert.assertEquals(HttpStatus.SC_ACCEPTED, response.getStatusLine().getStatusCode());
   readResponseBody(response);
   g.abort();
}
 
開發者ID:Wolfgang-Winter,項目名稱:cibet,代碼行數:18,代碼來源:HttpSpringSecurity2IT.java

示例12: testDeny2Man3

import org.apache.http.client.methods.HttpOptions; //導入依賴的package包/類
@Test
public void testDeny2Man3() throws Exception {
   log.info("start testDeny2Man3()");
   HttpGet method = new HttpGet(getBaseURL()
         + "/test/spring/loginSpring?secondUser=hall&USER=Fred&secondRole=NULL&ROLE=admin" + "&TENANT=" + TENANT);
   HttpResponse response = client.execute(method);
   method.abort();
   Thread.sleep(20);

   log.debug("now the test");
   HttpOptions g = new HttpOptions(URL_TS + "?role=" + URLEncoder.encode("admin", "UTF-8") + "&secondUser="
         + URLEncoder.encode("hall", "UTF-8") + "&secondRole=" + URLEncoder.encode("NULL", "UTF-8"));
   response = client.execute(g);
   Assert.assertEquals(HttpStatus.SC_ACCEPTED, response.getStatusLine().getStatusCode());
   readResponseBody(response);
   String erString = response.getFirstHeader(Headers.CIBET_EVENTRESULT.name()).getValue();
   EventResult er = CibetUtil.decodeEventResult(erString);
   log.debug("#### EventResult: " + er);
   Assert.assertEquals(ExecutionStatus.POSTPONED, er.getExecutionStatus());
   Assert.assertEquals(ExecutionStatus.DENIED, er.getChildResults().get(0).getExecutionStatus());
   g.abort();
}
 
開發者ID:Wolfgang-Winter,項目名稱:cibet,代碼行數:23,代碼來源:HttpSpringSecurity2IT.java

示例13: testDeny2Man4

import org.apache.http.client.methods.HttpOptions; //導入依賴的package包/類
@Test
public void testDeny2Man4() throws Exception {
   log.info("start testDeny2Man4()");
   HttpGet method = new HttpGet(getBaseURL()
         + "/test/spring/loginSpring?secondUser=hil&secondRole=sssss&USER=Fred&ROLE=admin" + "&TENANT=" + TENANT);
   HttpResponse response = client.execute(method);
   method.abort();
   Thread.sleep(20);

   log.debug("now the test");
   HttpOptions g = new HttpOptions(URL_TS + "?role=" + URLEncoder.encode("admin", "UTF-8") + "&secondUser="
         + URLEncoder.encode("höl", "UTF-8") + "&secondRole=" + URLEncoder.encode("ssssssss", "UTF-8"));
   response = client.execute(g);
   Assert.assertEquals(HttpStatus.SC_ACCEPTED, response.getStatusLine().getStatusCode());
   readResponseBody(response);
   String erString = response.getFirstHeader(Headers.CIBET_EVENTRESULT.name()).getValue();
   EventResult er = CibetUtil.decodeEventResult(erString);
   Assert.assertEquals(ExecutionStatus.POSTPONED, er.getExecutionStatus());
   Assert.assertEquals(ExecutionStatus.DENIED, er.getChildResults().get(0).getExecutionStatus());

   g.abort();
}
 
開發者ID:Wolfgang-Winter,項目名稱:cibet,代碼行數:23,代碼來源:HttpSpringSecurity2IT.java

示例14: testGrant2Man

import org.apache.http.client.methods.HttpOptions; //導入依賴的package包/類
@Test
public void testGrant2Man() throws Exception {
   log.info("start testGrant2Man()");
   HttpGet method = new HttpGet(getBaseURL()
         + "/test/spring/loginSpring?USER=Fred&secondUser=hil&secondRole=second&ROLE=admin" + "&TENANT=" + TENANT);
   HttpResponse response = client.execute(method);
   method.abort();
   Thread.sleep(20);

   log.debug("now the test");
   HttpOptions g = new HttpOptions(URL_TS + "?role=" + URLEncoder.encode("admin", "UTF-8") + "&secondUser="
         + URLEncoder.encode("höl", "UTF-8") + "&secondRole=" + URLEncoder.encode("second", "UTF-8"));
   response = client.execute(g);
   Assert.assertEquals(HttpStatus.SC_ACCEPTED, response.getStatusLine().getStatusCode());
   readResponseBody(response);
   String erString = response.getFirstHeader(Headers.CIBET_EVENTRESULT.name()).getValue();
   EventResult er = CibetUtil.decodeEventResult(erString);
   Assert.assertEquals(ExecutionStatus.POSTPONED, er.getExecutionStatus());
   Assert.assertEquals(ExecutionStatus.EXECUTED, er.getChildResults().get(0).getExecutionStatus());

   g.abort();
}
 
開發者ID:Wolfgang-Winter,項目名稱:cibet,代碼行數:23,代碼來源:HttpSpringSecurity2IT.java

示例15: requireThatServerRespondsToAllMethods

import org.apache.http.client.methods.HttpOptions; //導入依賴的package包/類
@Test
public void requireThatServerRespondsToAllMethods() throws Exception {
    final TestDriver driver = TestDrivers.newInstance(newEchoHandler());
    final URI uri = driver.client().newUri("/status.html");
    driver.client().execute(new HttpGet(uri))
          .expectStatusCode(is(OK));
    driver.client().execute(new HttpPost(uri))
          .expectStatusCode(is(OK));
    driver.client().execute(new HttpHead(uri))
          .expectStatusCode(is(OK));
    driver.client().execute(new HttpPut(uri))
          .expectStatusCode(is(OK));
    driver.client().execute(new HttpDelete(uri))
          .expectStatusCode(is(OK));
    driver.client().execute(new HttpOptions(uri))
          .expectStatusCode(is(OK));
    driver.client().execute(new HttpTrace(uri))
          .expectStatusCode(is(OK));
    driver.client().execute(new HttpPatch(uri))
            .expectStatusCode(is(OK));
    assertThat(driver.close(), is(true));
}
 
開發者ID:vespa-engine,項目名稱:vespa,代碼行數:23,代碼來源:JDiscHttpServletTest.java


注:本文中的org.apache.http.client.methods.HttpOptions類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。