Search in sources :

Example 1 with Fields

use of org.eclipse.jetty.util.Fields in project jetty.project by eclipse.

the class HttpClientURITest method testPathWithQuery.

@Test
public void testPathWithQuery() throws Exception {
    String name = "a";
    String value = "1";
    final String query = name + "=" + value;
    final String path = "/path";
    start(new AbstractHandler() {

        @Override
        public void handle(String target, org.eclipse.jetty.server.Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
            baseRequest.setHandled(true);
            Assert.assertEquals(path, request.getRequestURI());
            Assert.assertEquals(query, request.getQueryString());
        }
    });
    String pathQuery = path + "?" + query;
    Request request = client.newRequest("localhost", connector.getLocalPort()).scheme(scheme).timeout(5, TimeUnit.SECONDS).path(pathQuery);
    Assert.assertEquals(path, request.getPath());
    Assert.assertEquals(query, request.getQuery());
    Assert.assertTrue(request.getURI().toString().endsWith(pathQuery));
    Fields params = request.getParams();
    Assert.assertEquals(1, params.getSize());
    Assert.assertEquals(value, params.get(name).getValue());
    ContentResponse response = request.send();
    Assert.assertEquals(HttpStatus.OK_200, response.getStatus());
}
Also used : ContentResponse(org.eclipse.jetty.client.api.ContentResponse) Request(org.eclipse.jetty.client.api.Request) HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpServletResponse(javax.servlet.http.HttpServletResponse) IOException(java.io.IOException) AbstractHandler(org.eclipse.jetty.server.handler.AbstractHandler) HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletException(javax.servlet.ServletException) Fields(org.eclipse.jetty.util.Fields) Test(org.junit.Test)

Example 2 with Fields

use of org.eclipse.jetty.util.Fields in project jetty.project by eclipse.

the class HttpClientURITest method testPathWithParam.

@Test
public void testPathWithParam() throws Exception {
    String name = "a";
    String value = "1";
    final String query = name + "=" + value;
    final String path = "/path";
    String pathQuery = path + "?" + query;
    start(new AbstractHandler() {

        @Override
        public void handle(String target, org.eclipse.jetty.server.Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
            baseRequest.setHandled(true);
            Assert.assertEquals(path, request.getRequestURI());
            Assert.assertEquals(query, request.getQueryString());
        }
    });
    Request request = client.newRequest("localhost", connector.getLocalPort()).scheme(scheme).timeout(5, TimeUnit.SECONDS).path(path).param(name, value);
    Assert.assertEquals(path, request.getPath());
    Assert.assertEquals(query, request.getQuery());
    Assert.assertTrue(request.getURI().toString().endsWith(pathQuery));
    Fields params = request.getParams();
    Assert.assertEquals(1, params.getSize());
    Assert.assertEquals(value, params.get(name).getValue());
    ContentResponse response = request.send();
    Assert.assertEquals(HttpStatus.OK_200, response.getStatus());
}
Also used : ContentResponse(org.eclipse.jetty.client.api.ContentResponse) Request(org.eclipse.jetty.client.api.Request) HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpServletResponse(javax.servlet.http.HttpServletResponse) IOException(java.io.IOException) AbstractHandler(org.eclipse.jetty.server.handler.AbstractHandler) HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletException(javax.servlet.ServletException) Fields(org.eclipse.jetty.util.Fields) Test(org.junit.Test)

Example 3 with Fields

use of org.eclipse.jetty.util.Fields in project jetty.project by eclipse.

the class HttpClientURITest method testPathWithQueryAndParam.

@Test
public void testPathWithQueryAndParam() throws Exception {
    String name1 = "a";
    String value1 = "1";
    String name2 = "b";
    String value2 = "2";
    final String query = name1 + "=" + value1 + "&" + name2 + "=" + value2;
    final String path = "/path";
    String pathQuery = path + "?" + query;
    start(new AbstractHandler() {

        @Override
        public void handle(String target, org.eclipse.jetty.server.Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
            baseRequest.setHandled(true);
            Assert.assertEquals(path, request.getRequestURI());
            Assert.assertEquals(query, request.getQueryString());
        }
    });
    Request request = client.newRequest("localhost", connector.getLocalPort()).scheme(scheme).timeout(5, TimeUnit.SECONDS).path(path + "?" + name1 + "=" + value1).param(name2, value2);
    Assert.assertEquals(path, request.getPath());
    Assert.assertEquals(query, request.getQuery());
    Assert.assertTrue(request.getURI().toString().endsWith(pathQuery));
    Fields params = request.getParams();
    Assert.assertEquals(2, params.getSize());
    Assert.assertEquals(value1, params.get(name1).getValue());
    Assert.assertEquals(value2, params.get(name2).getValue());
    ContentResponse response = request.send();
    Assert.assertEquals(HttpStatus.OK_200, response.getStatus());
}
Also used : ContentResponse(org.eclipse.jetty.client.api.ContentResponse) Request(org.eclipse.jetty.client.api.Request) HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpServletResponse(javax.servlet.http.HttpServletResponse) IOException(java.io.IOException) AbstractHandler(org.eclipse.jetty.server.handler.AbstractHandler) HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletException(javax.servlet.ServletException) Fields(org.eclipse.jetty.util.Fields) Test(org.junit.Test)

Example 4 with Fields

use of org.eclipse.jetty.util.Fields in project jetty.project by eclipse.

the class HttpClientURITest method testPath.

@Test
public void testPath() throws Exception {
    final String path = "/path";
    start(new AbstractHandler() {

        @Override
        public void handle(String target, org.eclipse.jetty.server.Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
            baseRequest.setHandled(true);
            Assert.assertEquals(path, request.getRequestURI());
        }
    });
    Request request = client.newRequest("localhost", connector.getLocalPort()).scheme(scheme).timeout(5, TimeUnit.SECONDS).path(path);
    Assert.assertEquals(path, request.getPath());
    Assert.assertNull(request.getQuery());
    Fields params = request.getParams();
    Assert.assertEquals(0, params.getSize());
    Assert.assertTrue(request.getURI().toString().endsWith(path));
    ContentResponse response = request.send();
    Assert.assertEquals(HttpStatus.OK_200, response.getStatus());
}
Also used : ContentResponse(org.eclipse.jetty.client.api.ContentResponse) Request(org.eclipse.jetty.client.api.Request) HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpServletResponse(javax.servlet.http.HttpServletResponse) IOException(java.io.IOException) AbstractHandler(org.eclipse.jetty.server.handler.AbstractHandler) HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletException(javax.servlet.ServletException) Fields(org.eclipse.jetty.util.Fields) Test(org.junit.Test)

Example 5 with Fields

use of org.eclipse.jetty.util.Fields in project jetty.project by eclipse.

the class HttpClientURITest method testAsteriskFormTarget.

@Test
public void testAsteriskFormTarget() throws Exception {
    start(new AbstractHandler() {

        @Override
        public void handle(String target, org.eclipse.jetty.server.Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
            baseRequest.setHandled(true);
            Assert.assertEquals("*", target);
            Assert.assertEquals("*", request.getPathInfo());
        }
    });
    Request request = client.newRequest("localhost", connector.getLocalPort()).method(HttpMethod.OPTIONS).scheme(scheme).path("*").timeout(5, TimeUnit.SECONDS);
    Assert.assertEquals("*", request.getPath());
    Assert.assertNull(request.getQuery());
    Fields params = request.getParams();
    Assert.assertEquals(0, params.getSize());
    Assert.assertNull(request.getURI());
    ContentResponse response = request.send();
    Assert.assertEquals(HttpStatus.OK_200, response.getStatus());
}
Also used : ContentResponse(org.eclipse.jetty.client.api.ContentResponse) Request(org.eclipse.jetty.client.api.Request) HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpServletResponse(javax.servlet.http.HttpServletResponse) IOException(java.io.IOException) AbstractHandler(org.eclipse.jetty.server.handler.AbstractHandler) HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletException(javax.servlet.ServletException) Fields(org.eclipse.jetty.util.Fields) Test(org.junit.Test)

Aggregations

Fields (org.eclipse.jetty.util.Fields)11 IOException (java.io.IOException)10 ServletException (javax.servlet.ServletException)10 HttpServletRequest (javax.servlet.http.HttpServletRequest)10 HttpServletResponse (javax.servlet.http.HttpServletResponse)10 ContentResponse (org.eclipse.jetty.client.api.ContentResponse)10 AbstractHandler (org.eclipse.jetty.server.handler.AbstractHandler)10 Test (org.junit.Test)10 Request (org.eclipse.jetty.client.api.Request)9 AbstractHttpClientServerTest (org.eclipse.jetty.client.AbstractHttpClientServerTest)2 Request (org.eclipse.jetty.server.Request)2 Type (org.apache.camel.component.salesforce.SalesforceLoginConfig.Type)1 FormContentProvider (org.eclipse.jetty.client.util.FormContentProvider)1