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);
}
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;
}
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;
}
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('`', '\"'));
}
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('`', '\"'));
}
Aggregations