use of org.webpieces.httpparser.api.dto.HttpResponseStatus in project webpieces by deanhiller.
the class HttpParserImpl method validate.
private void validate(HttpResponse response) {
HttpResponseStatusLine statusLine = response.getStatusLine();
if (statusLine == null) {
throw new IllegalArgumentException("response.statusLine is not set(call response.setStatusLine");
}
HttpResponseStatus status = statusLine.getStatus();
if (status == null) {
throw new IllegalArgumentException("response.statusLine.status is not set(call response.getStatusLine().setStatus())");
} else if (status.getCode() == null) {
throw new IllegalArgumentException("response.statusLine.status.code is not set(call response.getStatusLine().getStatus().setCode())");
} else if (status.getReason() == null) {
throw new IllegalArgumentException("response.statusLine.status.reason is not set");
} else if (statusLine.getVersion() == null) {
throw new IllegalArgumentException("response.statusLine.version is not set");
}
}
use of org.webpieces.httpparser.api.dto.HttpResponseStatus in project webpieces by deanhiller.
the class TestResponseParsing method testBasic.
@Test
public void testBasic() {
HttpResponseStatus status = new HttpResponseStatus();
status.setKnownStatus(KnownStatusCode.HTTP_200_OK);
HttpResponseStatusLine statusLine = new HttpResponseStatusLine();
statusLine.setStatus(status);
HttpResponse response = new HttpResponse();
response.setStatusLine(statusLine);
String result1 = response.toString();
String result2 = parser.marshalToString(response);
String msg = "HTTP/1.1 200 OK\r\n\r\n";
Assert.assertEquals(msg, result1);
Assert.assertEquals(msg, result2);
}
use of org.webpieces.httpparser.api.dto.HttpResponseStatus in project webpieces by deanhiller.
the class TestResponseParsing method createOkResponse.
static HttpResponse createOkResponse() {
Header header1 = new Header();
header1.setName(KnownHeaderName.ACCEPT);
header1.setValue("CooolValue");
Header header2 = new Header();
//let's keep the case even though name is case-insensitive..
header2.setName("CustomerHEADER");
header2.setValue("betterValue");
HttpResponseStatus status = new HttpResponseStatus();
status.setKnownStatus(KnownStatusCode.HTTP_200_OK);
HttpResponseStatusLine statusLine = new HttpResponseStatusLine();
statusLine.setStatus(status);
HttpResponse resp = new HttpResponse();
resp.setStatusLine(statusLine);
resp.addHeader(header1);
resp.addHeader(header2);
return resp;
}
Aggregations