Search in sources :

Example 81 with BasicHttpRequest

use of org.apache.hc.core5.http.message.BasicHttpRequest in project httpcomponents-core by apache.

the class HttpRequestWrapperTest method testRequestBasics.

@Test
public void testRequestBasics() throws Exception {
    final HttpRequest request = new BasicHttpRequest(Method.GET, "/stuff");
    final HttpRequestWrapper httpRequestWrapper = new HttpRequestWrapper(request);
    Assertions.assertEquals(Method.GET.name(), httpRequestWrapper.getMethod());
    Assertions.assertEquals("/stuff", httpRequestWrapper.getPath());
    Assertions.assertNull(httpRequestWrapper.getAuthority());
    Assertions.assertEquals(new URI("/stuff"), httpRequestWrapper.getUri());
    httpRequestWrapper.setPath("/another-stuff");
    Assertions.assertEquals("/another-stuff", httpRequestWrapper.getPath());
}
Also used : HttpRequest(org.apache.hc.core5.http.HttpRequest) URI(java.net.URI) Test(org.junit.jupiter.api.Test)

Example 82 with BasicHttpRequest

use of org.apache.hc.core5.http.message.BasicHttpRequest in project httpcomponents-core by apache.

the class HttpRequestWrapperTest method testRequestWithUserInfo.

@Test
public void testRequestWithUserInfo() throws Exception {
    final HttpRequest request = new BasicHttpRequest(Method.GET, new URI("https://user:pwd@host:9443/stuff?param=value"));
    final HttpRequestWrapper httpRequestWrapper = new HttpRequestWrapper(request);
    Assertions.assertEquals(Method.GET.name(), httpRequestWrapper.getMethod());
    Assertions.assertEquals("/stuff?param=value", httpRequestWrapper.getPath());
    Assertions.assertEquals(new URIAuthority("user:pwd", "host", 9443), httpRequestWrapper.getAuthority());
    Assertions.assertEquals("https", httpRequestWrapper.getScheme());
    Assertions.assertEquals(new URI("https://host:9443/stuff?param=value"), httpRequestWrapper.getUri());
}
Also used : HttpRequest(org.apache.hc.core5.http.HttpRequest) URIAuthority(org.apache.hc.core5.net.URIAuthority) URI(java.net.URI) Test(org.junit.jupiter.api.Test)

Example 83 with BasicHttpRequest

use of org.apache.hc.core5.http.message.BasicHttpRequest in project httpcomponents-core by apache.

the class HttpRequestWrapperTest method testRequestWithAuthorityRelativePath.

@Test
public void testRequestWithAuthorityRelativePath() throws Exception {
    final HttpRequest request = new BasicHttpRequest(Method.GET, new HttpHost("http", "somehost", -1), "stuff");
    final HttpRequestWrapper httpRequestWrapper = new HttpRequestWrapper(request);
    Assertions.assertEquals(Method.GET.name(), httpRequestWrapper.getMethod());
    Assertions.assertEquals("stuff", httpRequestWrapper.getPath());
    Assertions.assertEquals("stuff", httpRequestWrapper.getRequestUri());
    Assertions.assertEquals(new URIAuthority("somehost"), httpRequestWrapper.getAuthority());
    Assertions.assertEquals(new URI("http://somehost/stuff"), httpRequestWrapper.getUri());
}
Also used : HttpRequest(org.apache.hc.core5.http.HttpRequest) URIAuthority(org.apache.hc.core5.net.URIAuthority) HttpHost(org.apache.hc.core5.http.HttpHost) URI(java.net.URI) Test(org.junit.jupiter.api.Test)

Example 84 with BasicHttpRequest

use of org.apache.hc.core5.http.message.BasicHttpRequest in project httpcomponents-core by apache.

the class HttpRequestWrapperTest method testRequestWithNoPath.

@Test
public void testRequestWithNoPath() throws Exception {
    final HttpRequest request = new BasicHttpRequest(Method.GET, new URI("http://host"));
    final HttpRequestWrapper httpRequestWrapper = new HttpRequestWrapper(request);
    Assertions.assertEquals(Method.GET.name(), httpRequestWrapper.getMethod());
    Assertions.assertEquals("/", httpRequestWrapper.getPath());
    Assertions.assertEquals(new URIAuthority("host"), httpRequestWrapper.getAuthority());
    Assertions.assertEquals("http", httpRequestWrapper.getScheme());
    Assertions.assertEquals(new URI("http://host/"), httpRequestWrapper.getUri());
}
Also used : HttpRequest(org.apache.hc.core5.http.HttpRequest) URIAuthority(org.apache.hc.core5.net.URIAuthority) URI(java.net.URI) Test(org.junit.jupiter.api.Test)

Example 85 with BasicHttpRequest

use of org.apache.hc.core5.http.message.BasicHttpRequest in project httpcomponents-core by apache.

the class HttpRequestWrapperTest method testDefaultRequestConstructors.

@Test
public void testDefaultRequestConstructors() {
    final HttpRequest request1 = new BasicHttpRequest("WHATEVER", "/");
    final HttpRequestWrapper httpRequestWrapper = new HttpRequestWrapper(request1);
    Assertions.assertEquals("WHATEVER", httpRequestWrapper.getMethod());
    Assertions.assertEquals("/", httpRequestWrapper.getPath());
    final HttpRequest request2 = new BasicHttpRequest(Method.GET, "/");
    final HttpRequestWrapper httpRequestWrapper2 = new HttpRequestWrapper(request2);
    Assertions.assertEquals(Method.GET.name(), httpRequestWrapper2.getMethod());
    Assertions.assertEquals("/", httpRequestWrapper2.getPath());
    Assertions.assertThrows(NullPointerException.class, () -> new BasicHttpRequest(Method.GET, (URI) null));
}
Also used : HttpRequest(org.apache.hc.core5.http.HttpRequest) URI(java.net.URI) Test(org.junit.jupiter.api.Test)

Aggregations

HttpRequest (org.apache.hc.core5.http.HttpRequest)75 BasicHttpRequest (org.apache.hc.core5.http.message.BasicHttpRequest)68 Test (org.junit.jupiter.api.Test)45 HttpResponse (org.apache.hc.core5.http.HttpResponse)41 BasicRequestProducer (org.apache.hc.core5.http.nio.support.BasicRequestProducer)37 Message (org.apache.hc.core5.http.Message)34 StringAsyncEntityConsumer (org.apache.hc.core5.http.nio.entity.StringAsyncEntityConsumer)33 InetSocketAddress (java.net.InetSocketAddress)30 HttpHost (org.apache.hc.core5.http.HttpHost)30 Test (org.junit.Test)30 URI (java.net.URI)23 HttpException (org.apache.hc.core5.http.HttpException)21 IOException (java.io.IOException)20 BasicHttpResponse (org.apache.hc.core5.http.message.BasicHttpResponse)19 URIAuthority (org.apache.hc.core5.net.URIAuthority)17 InterruptedIOException (java.io.InterruptedIOException)16 HttpContext (org.apache.hc.core5.http.protocol.HttpContext)15 Header (org.apache.hc.core5.http.Header)14 URISyntaxException (java.net.URISyntaxException)8 ContentType (org.apache.hc.core5.http.ContentType)8