use of org.webpieces.httpparser.api.dto.HttpUri in project webpieces by deanhiller.
the class TestRequestParsing method testBasic.
@Test
public void testBasic() {
HttpRequestLine requestLine = new HttpRequestLine();
requestLine.setMethod(KnownHttpMethod.POST);
requestLine.setUri(new HttpUri("http://myhost.com"));
HttpRequest request = new HttpRequest();
request.setRequestLine(requestLine);
String result1 = request.toString();
String result2 = parser.marshalToString(request);
String msg = "POST http://myhost.com HTTP/1.1\r\n\r\n";
Assert.assertEquals(msg, result1);
Assert.assertEquals(msg, result2);
}
use of org.webpieces.httpparser.api.dto.HttpUri in project webpieces by deanhiller.
the class Requests method createRequest.
public static HttpRequest createRequest(KnownHttpMethod method, String url, Integer port) {
HttpUri httpUri = new HttpUri(url);
HttpRequestLine requestLine = new HttpRequestLine();
requestLine.setMethod(method);
requestLine.setUri(httpUri);
HttpRequest req = new HttpRequest();
req.setRequestLine(requestLine);
if (port == null)
req.addHeader(new Header(KnownHeaderName.HOST, "myhost.com"));
else
req.addHeader(new Header(KnownHeaderName.HOST, "myhost.com:" + port));
return req;
}
use of org.webpieces.httpparser.api.dto.HttpUri in project webpieces by deanhiller.
the class Requests method createPostRequestImpl.
private static HttpDummyRequest createPostRequestImpl(String url, String... argTuples) throws UnsupportedEncodingException {
if (argTuples.length % 2 != 0)
throw new IllegalArgumentException("argTuples.length must be of even size (key/value)");
HttpUri httpUri = new HttpUri(url);
HttpRequestLine requestLine = new HttpRequestLine();
requestLine.setMethod(KnownHttpMethod.POST);
requestLine.setUri(httpUri);
HttpRequest req = new HttpRequest();
req.setRequestLine(requestLine);
req.addHeader(new Header(KnownHeaderName.HOST, "myhost.com"));
String encodedParams = "";
for (int i = 0; i < argTuples.length; i += 2) {
String key = URLEncoder.encode(argTuples[i], StandardCharsets.UTF_8);
String value = URLEncoder.encode(argTuples[i + 1], StandardCharsets.UTF_8);
if (!"".equals(encodedParams))
encodedParams += "&";
encodedParams += key + "=" + value;
}
byte[] bytes = encodedParams.getBytes(StandardCharsets.UTF_8);
DataWrapper body = gen.wrapByteArray(bytes);
HttpData data = new HttpData(body, true);
req.addHeader(new Header(KnownHeaderName.CONTENT_LENGTH, "" + body.getReadableSize()));
req.addHeader(new Header(KnownHeaderName.CONTENT_TYPE, "application/x-www-form-urlencoded"));
return new HttpDummyRequest(req, data);
}
use of org.webpieces.httpparser.api.dto.HttpUri in project webpieces by deanhiller.
the class Requests method createGetRequest.
public static HttpRequest createGetRequest(String domain, String url) {
HttpUri httpUri = new HttpUri(url);
HttpRequestLine requestLine = new HttpRequestLine();
requestLine.setMethod(KnownHttpMethod.GET);
requestLine.setUri(httpUri);
HttpRequest req = new HttpRequest();
req.setRequestLine(requestLine);
req.addHeader(new Header(KnownHeaderName.HOST, domain));
return req;
}
Aggregations