Java Code Examples for io.netty.handler.codec.http.HttpResponseStatus#reasonPhrase()

The following examples show how to use io.netty.handler.codec.http.HttpResponseStatus#reasonPhrase() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Http.java    From zbus-server with MIT License 6 votes vote down vote up
private static void writeHttpLine(Message msg, OutputStream out) throws IOException{
	if(msg.getStatus() != null){
		String statusText = msg.getStatusText();
		if(statusText == null) {
			HttpResponseStatus s = HttpResponseStatus.valueOf(msg.getStatus());
			if(s != null){
				statusText = s.reasonPhrase();
			} else {
				statusText = "Unknown Status";
			}
		}
		out.write(PREFIX);
		out.write(String.format("%d", msg.getStatus()).getBytes());
		out.write(BLANK);
		out.write(statusText.getBytes());  
	} else {
		String method = msg.getMethod(); 
		if(method == null) method = "GET"; 
		out.write(method.getBytes());
		out.write(BLANK); 
		String requestString = msg.getUrl();
		if(requestString == null) requestString = "/";
		out.write(requestString.getBytes());
		out.write(SUFFIX); 
	}
}
 
Example 2
Source File: StatusMessageException.java    From reactor-guice with Apache License 2.0 4 votes vote down vote up
public StatusMessageException(HttpResponseStatus status) {
    super(status.reasonPhrase());
    this.errorCode = status.code();
}
 
Example 3
Source File: HttpException.java    From arcusplatform with Apache License 2.0 4 votes vote down vote up
public HttpException(HttpResponseStatus status) {
	this(status, "Http Error " + status.code() + ": " + status.reasonPhrase(), null);
}
 
Example 4
Source File: HttpException.java    From arcusplatform with Apache License 2.0 4 votes vote down vote up
public HttpException(HttpResponseStatus status, Throwable cause) {
	this(status, "Http Error " + status.code() + ": " + status.reasonPhrase(), cause);
}
 
Example 5
Source File: SearchHandler.java    From couchbase-jvm-core with Apache License 2.0 4 votes vote down vote up
@Override
protected CouchbaseResponse decodeResponse(ChannelHandlerContext ctx, HttpObject msg) throws Exception {
    SearchRequest request = currentRequest();
    CouchbaseResponse response = null;

    if (msg instanceof HttpResponse) {
        responseHeader = (HttpResponse) msg;

        if (responseContent != null) {
            responseContent.clear();
        } else {
            responseContent = ctx.alloc().buffer();
        }
    }


    if (msg instanceof HttpContent) {
        responseContent.writeBytes(((HttpContent) msg).content());
    }

    if (currentRequest() instanceof KeepAliveRequest) {
        if (msg instanceof LastHttpContent) {
            response = new KeepAliveResponse(ResponseStatusConverter.fromHttp(responseHeader.getStatus().code()), currentRequest());
            responseContent.clear();
            responseContent.discardReadBytes();
            finishedDecoding();
        }
    } else if (currentRequest() instanceof PingRequest) {
        if (msg instanceof LastHttpContent) {
            response = new PingResponse(ResponseStatusConverter.fromHttp(responseHeader.getStatus().code()), currentRequest());
            responseContent.clear();
            responseContent.discardReadBytes();
            finishedDecoding();
        }
    } else if (msg instanceof LastHttpContent) {
        HttpResponseStatus httpStatus = responseHeader.getStatus();
        ResponseStatus status = ResponseStatusConverter.fromHttp(httpStatus.code());
        String body = responseContent.readableBytes() > 0
                ? responseContent.toString(CHARSET) : httpStatus.reasonPhrase();

        if (request instanceof UpsertSearchIndexRequest) {
            response = new UpsertSearchIndexResponse(body, status);
        } else if (request instanceof GetSearchIndexRequest) {
            response = new GetSearchIndexResponse(body, status);
        } else if (request instanceof RemoveSearchIndexRequest) {
            response = new RemoveSearchIndexResponse(body, status);
        } else if (request instanceof SearchQueryRequest) {
            completeRequestSpan(currentRequest());
            response = new SearchQueryResponse(body, status, httpStatus.code());
        }

        finishedDecoding();
    }
    return response;
}