Search in sources :

Example 6 with HttpResponseStatus

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");
    }
}
Also used : HttpResponseStatus(org.webpieces.httpparser.api.dto.HttpResponseStatus) HttpResponseStatusLine(org.webpieces.httpparser.api.dto.HttpResponseStatusLine)

Example 7 with HttpResponseStatus

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);
}
Also used : HttpResponseStatus(org.webpieces.httpparser.api.dto.HttpResponseStatus) HttpResponse(org.webpieces.httpparser.api.dto.HttpResponse) HttpResponseStatusLine(org.webpieces.httpparser.api.dto.HttpResponseStatusLine) Test(org.junit.Test)

Example 8 with HttpResponseStatus

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;
}
Also used : Header(org.webpieces.httpparser.api.common.Header) HttpResponseStatus(org.webpieces.httpparser.api.dto.HttpResponseStatus) HttpResponse(org.webpieces.httpparser.api.dto.HttpResponse) HttpResponseStatusLine(org.webpieces.httpparser.api.dto.HttpResponseStatusLine)

Aggregations

HttpResponseStatus (org.webpieces.httpparser.api.dto.HttpResponseStatus)8 HttpResponseStatusLine (org.webpieces.httpparser.api.dto.HttpResponseStatusLine)8 HttpResponse (org.webpieces.httpparser.api.dto.HttpResponse)7 Header (org.webpieces.httpparser.api.common.Header)5 Http2Header (com.webpieces.http2parser.api.dto.lib.Http2Header)3 Test (org.junit.Test)1 HttpVersion (org.webpieces.httpparser.api.dto.HttpVersion)1