Search in sources :

Example 86 with HttpFullRequest

use of org.webpieces.httpclient11.api.HttpFullRequest in project webpieces by deanhiller.

the class TestBeans method testDeveloperMistypesBeanNameVsFormNames.

/*
	 * Have the controller method be postUser(UserDbo user, String password) BUT then in the html have
	 * entity.name, entity.age, entity.password INSTEAD of user.name, etc. such that there
	 * is a mismatch and verify there is a clean error for that
	 * 
	 * GET /adduser HTTP/1.1
	 * Host: localhost:59786
	 * User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:47.0) Gecko/20100101 Firefox/47.0
	 * Accept: text/html,application/xhtml+xml,application/xml;q=0.9,XX/XX;q=0.8
	 * Accept-Language: en-US,en;q=0.5
	 * Accept-Encoding: gzip, deflate
	 * Referer: http://localhost:59786/adduser
	 * Cookie: webSession=1-gzvc03bKRP2YYvWySwgENREwFSg=:__ST=3a2fda5dad7547d3b15b1f61bd3d12f5; webFlash=1:_message=Invalid+values+below&user.address.zipCode=Text+instead+of+number&__secureToken=3a2fda5dad7547d3b15b1f61bd3d12f5&user.firstName=Dean+Hiller; webErrors=1:user.address.zipCode=Could+not+convert+value
	 * Connection: keep-alive
	 */
@Test
public void testDeveloperMistypesBeanNameVsFormNames() {
    HttpFullRequest req = Requests.createPostRequest("/postuser", "entity.firstName", "D&D", "entity.lastName", "Hiller", "entity.fullName", "Dean Hiller", "password", "hi");
    XFuture<HttpFullResponse> respFuture = http11Socket.send(req);
    ResponseWrapper response = ResponseExtract.waitResponseAndWrap(respFuture);
    response.assertStatusCode(KnownStatusCode.HTTP_500_INTERNAL_SVR_ERROR);
}
Also used : HttpFullResponse(org.webpieces.httpclient11.api.HttpFullResponse) HttpFullRequest(org.webpieces.httpclient11.api.HttpFullRequest) ResponseWrapper(org.webpieces.webserver.test.ResponseWrapper) AbstractWebpiecesTest(org.webpieces.webserver.test.AbstractWebpiecesTest) PrivateWebserverForTest(org.webpieces.webserver.PrivateWebserverForTest) Test(org.junit.Test)

Example 87 with HttpFullRequest

use of org.webpieces.httpclient11.api.HttpFullRequest in project webpieces by deanhiller.

the class TestHttps method simulateLogin.

private Header simulateLogin() {
    HttpFullRequest req1 = Requests.createRequest(KnownHttpMethod.POST, "/postLogin");
    XFuture<HttpFullResponse> respFuture = https11Socket.send(req1);
    ResponseWrapper response1 = ResponseExtract.waitResponseAndWrap(respFuture);
    Header header = response1.getResponse().getHeaderLookupStruct().getHeader(KnownHeaderName.SET_COOKIE);
    String value = header.getValue();
    value = value.replace("; path=/; HttpOnly", "");
    Header cookie = new Header(KnownHeaderName.COOKIE, value);
    return cookie;
}
Also used : HttpFullResponse(org.webpieces.httpclient11.api.HttpFullResponse) HttpFullRequest(org.webpieces.httpclient11.api.HttpFullRequest) Header(org.webpieces.httpparser.api.common.Header) ResponseWrapper(org.webpieces.webserver.test.ResponseWrapper)

Example 88 with HttpFullRequest

use of org.webpieces.httpclient11.api.HttpFullRequest in project webpieces by deanhiller.

the class Translations2 method translate.

public static HttpFullRequest translate(FullRequest request) {
    // String scheme = request.getHeaders().getScheme();
    Http2Request headers = request.getHeaders();
    String authority = headers.getAuthority();
    String path = headers.getPath();
    String methodString = headers.getMethodString();
    if (methodString == null)
        throw new IllegalArgumentException("http2 :method header is required");
    else if (authority == null) {
        throw new IllegalArgumentException("http1 required host header so http2 message must have :authority header set");
    }
    HttpRequestLine reqLine = new HttpRequestLine();
    reqLine.setUri(new HttpUri(path));
    reqLine.setMethod(new HttpRequestMethod(methodString));
    reqLine.setVersion(new HttpVersion());
    HttpRequest httpReq = new HttpRequest();
    httpReq.setRequestLine(reqLine);
    DataWrapper data = request.getPayload();
    // translate all other headers here as well...
    for (Http2Header header : headers.getHeaders()) {
        if (// All standard headers go elsewhere except HOST which we do below
        !header.getName().startsWith(":"))
            httpReq.addHeader(new Header(header.getName(), header.getValue()));
    }
    httpReq.addHeader(new Header(KnownHeaderName.HOST, authority));
    HttpFullRequest req = new HttpFullRequest(httpReq, data);
    return req;
}
Also used : HttpRequest(org.webpieces.httpparser.api.dto.HttpRequest) DataWrapper(org.webpieces.data.api.DataWrapper) HttpRequestMethod(org.webpieces.httpparser.api.dto.HttpRequestMethod) HttpFullRequest(org.webpieces.httpclient11.api.HttpFullRequest) Http2Request(com.webpieces.http2.api.dto.highlevel.Http2Request) HttpRequestLine(org.webpieces.httpparser.api.dto.HttpRequestLine) Header(org.webpieces.httpparser.api.common.Header) Http2Header(com.webpieces.http2.api.dto.lowlevel.lib.Http2Header) Http2Header(com.webpieces.http2.api.dto.lowlevel.lib.Http2Header) HttpUri(org.webpieces.httpparser.api.dto.HttpUri) HttpVersion(org.webpieces.httpparser.api.dto.HttpVersion)

Example 89 with HttpFullRequest

use of org.webpieces.httpclient11.api.HttpFullRequest in project webpieces by deanhiller.

the class TestFlashAndSelect method testNullWillFlashProperly.

@Test
public void testNullWillFlashProperly() {
    HttpFullRequest req1 = Requests.createPostRequest("/user/post", "entity.id", user.getId() + "", // invalid first name
    "entity.firstName", // invalid first name
    "NextName", "entity.email", "dean@zz.com", "entity.lastName", "", "entity.password", "", "entity.levelOfEducation", "");
    XFuture<HttpFullResponse> respFuture1 = http11Socket.send(req1);
    ResponseWrapper response1 = ResponseExtract.waitResponseAndWrap(respFuture1);
    response1.assertStatusCode(KnownStatusCode.HTTP_303_SEEOTHER);
    String urlPath = "/user/edit/" + user.getId();
    Assert.assertEquals("http://myhost.com" + urlPath, response1.getRedirectUrl());
    HttpFullRequest req = Requests.createRequest(KnownHttpMethod.GET, urlPath);
    Header cookieHeader = response1.createCookieRequestHeader();
    req.addHeader(cookieHeader);
    XFuture<HttpFullResponse> respFuture = http11Socket.send(req);
    ResponseWrapper response = ResponseExtract.waitResponseAndWrap(respFuture);
    response.assertStatusCode(KnownStatusCode.HTTP_200_OK);
    // assert the nulls came through
    response.assertContains("<input type=`text` name=`entity.lastName` value=`` class=`input-xlarge`>".replace('`', '\"'));
    response.assertContains("<option value=`` selected=`selected`>Unselected</option>".replace('`', '\"'));
    response.assertContains("<option value=`k` >Kindergarten</script>".replace('`', '\"'));
}
Also used : HttpFullResponse(org.webpieces.httpclient11.api.HttpFullResponse) HttpFullRequest(org.webpieces.httpclient11.api.HttpFullRequest) Header(org.webpieces.httpparser.api.common.Header) ResponseWrapper(org.webpieces.webserver.test.ResponseWrapper) AbstractWebpiecesTest(org.webpieces.webserver.test.AbstractWebpiecesTest) PrivateWebserverForTest(org.webpieces.webserver.PrivateWebserverForTest) Test(org.junit.Test)

Example 90 with HttpFullRequest

use of org.webpieces.httpclient11.api.HttpFullRequest in project webpieces by deanhiller.

the class TestFlashAndSelect method testMultiSelect.

@Test
public void testMultiSelect() {
    HttpFullRequest req1 = Requests.createPostRequest("/multiselect", "entity.id", user.getId() + "", // invalid first name
    "entity.firstName", // invalid first name
    "NextName", "entity.email", "dean@zz.com", "entity.lastName", "", "entity.password", "", "entity.levelOfEducation", "", "selectedRoles", "j", "selectedRoles", "d");
    XFuture<HttpFullResponse> respFuture1 = http11Socket.send(req1);
    ResponseWrapper response1 = ResponseExtract.waitResponseAndWrap(respFuture1);
    response1.assertStatusCode(KnownStatusCode.HTTP_303_SEEOTHER);
    String urlPath = "/multiselect/" + user.getId();
    Assert.assertEquals("http://myhost.com" + urlPath, response1.getRedirectUrl());
    HttpFullRequest req = Requests.createRequest(KnownHttpMethod.GET, urlPath);
    Header cookieHeader = response1.createCookieRequestHeader();
    req.addHeader(cookieHeader);
    XFuture<HttpFullResponse> respFuture = http11Socket.send(req);
    ResponseWrapper response = ResponseExtract.waitResponseAndWrap(respFuture);
    response.assertStatusCode(KnownStatusCode.HTTP_200_OK);
    response.assertContains("<option value=`b` >Badass</script>".replace('`', '\"'));
    response.assertContains("<option value=`j` selected=`selected`>Jerk</script>".replace('`', '\"'));
    response.assertContains("<option value=`d` selected=`selected`>Delinquint</script>".replace('`', '\"'));
}
Also used : HttpFullResponse(org.webpieces.httpclient11.api.HttpFullResponse) HttpFullRequest(org.webpieces.httpclient11.api.HttpFullRequest) Header(org.webpieces.httpparser.api.common.Header) ResponseWrapper(org.webpieces.webserver.test.ResponseWrapper) AbstractWebpiecesTest(org.webpieces.webserver.test.AbstractWebpiecesTest) PrivateWebserverForTest(org.webpieces.webserver.PrivateWebserverForTest) Test(org.junit.Test)

Aggregations

HttpFullRequest (org.webpieces.httpclient11.api.HttpFullRequest)222 HttpFullResponse (org.webpieces.httpclient11.api.HttpFullResponse)205 ResponseWrapper (org.webpieces.webserver.test.ResponseWrapper)204 Test (org.junit.Test)194 AbstractWebpiecesTest (org.webpieces.webserver.test.AbstractWebpiecesTest)193 PrivateWebserverForTest (org.webpieces.webserver.PrivateWebserverForTest)180 Header (org.webpieces.httpparser.api.common.Header)50 XFuture (org.webpieces.util.futures.XFuture)13 HttpRequest (org.webpieces.httpparser.api.dto.HttpRequest)12 Http2Header (com.webpieces.http2.api.dto.lowlevel.lib.Http2Header)9 HttpRequestLine (org.webpieces.httpparser.api.dto.HttpRequestLine)9 HttpUri (org.webpieces.httpparser.api.dto.HttpUri)9 WebserverForTest (org.webpieces.plugins.fortesting.WebserverForTest)8 DataWrapper (org.webpieces.data.api.DataWrapper)6 UserDto (org.webpieces.webserver.basic.app.biz.UserDto)4 URL (java.net.URL)3 UserTestDbo (org.webpieces.plugins.hibernate.app.dbo.UserTestDbo)3 URI (java.net.URI)2 ByteBuffer (java.nio.ByteBuffer)2 NotFoundException (org.webpieces.http.exception.NotFoundException)2