Search in sources :

Example 76 with Http2Request

use of com.webpieces.http2.api.dto.highlevel.Http2Request in project webpieces by deanhiller.

the class ErrorCommonTest method testGetNotMatchPostRoute.

@Test
public void testGetNotMatchPostRoute() {
    log.info("starting");
    String moduleFileContents = CommonRoutesModules.class.getName();
    RouterService server = createServer(isProdTest, moduleFileContents);
    server.start();
    Http2Request req = RequestCreation.createHttpRequest(HttpMethod.GET, "/postroute");
    MockStreamHandle mockStream = new MockStreamHandle();
    StreamRef ref = server.incomingRequest(req, mockStream);
    XFuture<StreamWriter> future = ref.getWriter();
    Assert.assertTrue(future.isDone() && !future.isCompletedExceptionally());
    Http2Response response = mockStream.getLastResponse();
    String contents = mockStream.getResponseBody();
    verifyNotFoundRendered(response, contents);
    // We did not send a keep alive so it should close
    Assert.assertTrue(mockStream.isWasClosed());
}
Also used : RouterService(org.webpieces.router.api.RouterService) Http2Response(com.webpieces.http2.api.dto.highlevel.Http2Response) StreamRef(com.webpieces.http2.api.streaming.StreamRef) Http2Request(com.webpieces.http2.api.dto.highlevel.Http2Request) StreamWriter(com.webpieces.http2.api.streaming.StreamWriter) Test(org.junit.Test)

Example 77 with Http2Request

use of com.webpieces.http2.api.dto.highlevel.Http2Request in project webpieces by deanhiller.

the class RequestCreation method createHttpRequest.

public static Http2Request createHttpRequest(HttpMethod method, String path) {
    Http2Request req = new Http2Request();
    req.addHeader(new Http2Header(Http2HeaderName.METHOD, method.getCode()));
    req.addHeader(new Http2Header(Http2HeaderName.PATH, path));
    req.addHeader(new Http2Header(Http2HeaderName.SCHEME, "http"));
    req.addHeader(new Http2Header(Http2HeaderName.AUTHORITY, "orderly.com"));
    return req;
}
Also used : Http2Request(com.webpieces.http2.api.dto.highlevel.Http2Request) Http2Header(com.webpieces.http2.api.dto.lowlevel.lib.Http2Header)

Example 78 with Http2Request

use of com.webpieces.http2.api.dto.highlevel.Http2Request in project webpieces by deanhiller.

the class TestProdRouter method testAsyncRouteAndMocking.

/**
 * This test won't work in DevRoute right now as we need to do the following
 * 1. create CompileOnDemand very early on
 * 2. do a Thread.current().setContextClassLoader(compileOnDemand.getLatestClassloader())
 *
 * and this all needs to be done BEFORE TestModule is created and more importantly before
 * the bind(SomeService.class) as SomeService will be loaded from one classloader and then
 * when DEVrouter creates the controller, the compileOnDemand classloader is used resulting
 * in a mismatch.
 */
@Test
public void testAsyncRouteAndMocking() {
    Http2Request req = RequestCreation.createHttpRequest(HttpMethod.GET, "/async");
    // setup returning a response
    XFuture<Integer> future1 = new XFuture<Integer>();
    overrides.mockService.addToReturn(future1);
    MockStreamHandle mockStream = new MockStreamHandle();
    StreamRef ref = server.incomingRequest(req, mockStream);
    XFuture<StreamWriter> future = ref.getWriter();
    Assert.assertFalse(future.isDone());
    // no response yet...
    Assert.assertNull(mockStream.getLastResponse());
    // release controlleer
    int id = 78888;
    future1.complete(id);
    Assert.assertTrue(future.isDone() && !future.isCompletedExceptionally());
    Http2Response resp = mockStream.getLastResponse();
    Assert.assertNull(resp.getSingleHeaderValue(Http2HeaderName.AUTHORITY));
    Assert.assertEquals("http://" + req.getAuthority() + "/meeting/" + id, resp.getSingleHeaderValue(Http2HeaderName.LOCATION));
    // We did not send a keep alive so it should close
    Assert.assertTrue(mockStream.isWasClosed());
}
Also used : Http2Response(com.webpieces.http2.api.dto.highlevel.Http2Response) StreamRef(com.webpieces.http2.api.streaming.StreamRef) Http2Request(com.webpieces.http2.api.dto.highlevel.Http2Request) XFuture(org.webpieces.util.futures.XFuture) StreamWriter(com.webpieces.http2.api.streaming.StreamWriter) MockStreamHandle(org.webpieces.router.api.error.MockStreamHandle) Test(org.junit.Test)

Example 79 with Http2Request

use of com.webpieces.http2.api.dto.highlevel.Http2Request in project webpieces by deanhiller.

the class DefaultCorsProcessor method send403Response.

private void send403Response(ResponseStreamHandle responseStream, Http2Request request) {
    Http2Response response = new Http2Response();
    response.addHeader(new Http2Header(Http2HeaderName.STATUS, "403"));
    response.addHeader(new Http2Header(Http2HeaderName.VARY, "Origin"));
    sendResponse(responseStream, response);
}
Also used : Http2Response(com.webpieces.http2.api.dto.highlevel.Http2Response) Http2Header(com.webpieces.http2.api.dto.lowlevel.lib.Http2Header)

Example 80 with Http2Request

use of com.webpieces.http2.api.dto.highlevel.Http2Request in project webpieces by deanhiller.

the class HttpsJsonClient method createCurl2.

private String createCurl2(int port, Http2Request req, Supplier<String> supplier) {
    String s = "";
    s += "\n\n************************************************************\n";
    s += "            CURL REQUEST\n";
    s += "***************************************************************\n";
    s += "curl -k --request " + req.getKnownMethod().getCode() + " ";
    for (Http2Header header : req.getHeaders()) {
        if (header.getName().startsWith(":")) {
            // base headers we can discard
            continue;
        }
        s += "-H \"" + header.getName() + ":" + header.getValue() + "\" ";
    }
    String host = req.getSingleHeaderValue(Http2HeaderName.AUTHORITY);
    String path = req.getSingleHeaderValue(Http2HeaderName.PATH);
    s += supplier.get();
    s += " \"https://" + host + ":" + port + path + "\"\n";
    s += "***************************************************************\n";
    return s;
}
Also used : Http2Header(com.webpieces.http2.api.dto.lowlevel.lib.Http2Header)

Aggregations

Http2Request (com.webpieces.http2.api.dto.highlevel.Http2Request)71 Test (org.junit.Test)39 Http2Response (com.webpieces.http2.api.dto.highlevel.Http2Response)36 StreamWriter (com.webpieces.http2.api.streaming.StreamWriter)36 Http2Header (com.webpieces.http2.api.dto.lowlevel.lib.Http2Header)33 StreamRef (com.webpieces.http2.api.streaming.StreamRef)32 DataWrapper (org.webpieces.data.api.DataWrapper)18 DataFrame (com.webpieces.http2.api.dto.lowlevel.DataFrame)14 MockResponseListener (org.webpieces.http2client.mock.MockResponseListener)14 XFuture (org.webpieces.util.futures.XFuture)13 RequestStreamHandle (com.webpieces.http2.api.streaming.RequestStreamHandle)11 GoAwayFrame (com.webpieces.http2.api.dto.lowlevel.GoAwayFrame)10 MockStreamWriter (org.webpieces.http2client.mock.MockStreamWriter)10 CancelReason (com.webpieces.http2.api.dto.lowlevel.CancelReason)9 Http2Msg (com.webpieces.http2.api.dto.lowlevel.lib.Http2Msg)9 PassedIn (org.webpieces.httpfrontend2.api.mock2.MockHttp2RequestListener.PassedIn)9 InetSocketAddress (java.net.InetSocketAddress)8 Http2Push (com.webpieces.http2.api.dto.highlevel.Http2Push)7 MockStreamWriter (org.webpieces.httpfrontend2.api.mock2.MockStreamWriter)7 Http2HeaderName (com.webpieces.http2.api.dto.lowlevel.lib.Http2HeaderName)6