Search in sources :

Example 11 with HttpMethod

use of org.jboss.netty.handler.codec.http.HttpMethod in project feeyo-hlsserver by variflight.

the class HttpServerRequestHandler method getHandler.

private IRequestHandler getHandler(HttpRequest request) {
    IRequestHandler handler = null;
    // 解析QueryString
    String uriString = request.getUri();
    // 获取Path
    String path = null;
    int pathEndPos = uriString.indexOf('?');
    if (pathEndPos < 0) {
        path = uriString;
    } else {
        path = uriString.substring(0, pathEndPos);
    }
    // 获取参数
    Map<String, String> parameters = new HashMap<String, String>();
    if (uriString.startsWith("?")) {
        uriString = uriString.substring(1, uriString.length());
    }
    String[] querys = uriString.split("&");
    for (String query : querys) {
        String[] pair = query.split("=");
        if (pair.length == 2) {
            try {
                parameters.put(URLDecoder.decode(pair[0], "UTF8"), URLDecoder.decode(pair[1], "UTF8"));
            } catch (UnsupportedEncodingException e) {
                parameters.put(pair[0], pair[1]);
            }
        }
    }
    HttpMethod method = request.getMethod();
    if (method == HttpMethod.GET) {
        handler = getHandlers.retrieve(path, parameters);
    } else if (method == HttpMethod.POST) {
        handler = postHandlers.retrieve(path, parameters);
    }
    return handler;
}
Also used : IRequestHandler(com.feeyo.net.http.handler.IRequestHandler) HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) UnsupportedEncodingException(java.io.UnsupportedEncodingException) HttpMethod(org.jboss.netty.handler.codec.http.HttpMethod)

Aggregations

HttpMethod (org.jboss.netty.handler.codec.http.HttpMethod)11 HttpRequest (org.jboss.netty.handler.codec.http.HttpRequest)4 Deferred (com.stumbleupon.async.Deferred)3 IOException (java.io.IOException)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 ChannelBuffer (org.jboss.netty.buffer.ChannelBuffer)3 HttpChunk (org.jboss.netty.handler.codec.http.HttpChunk)3 HttpResponse (org.jboss.netty.handler.codec.http.HttpResponse)3 ChannelFuture (org.jboss.netty.channel.ChannelFuture)2 DefaultHttpRequest (org.jboss.netty.handler.codec.http.DefaultHttpRequest)2 DefaultHttpResponse (org.jboss.netty.handler.codec.http.DefaultHttpResponse)2 AuditLogContent (co.cask.cdap.common.logging.AuditLogContent)1 AccessTokenTransformer (co.cask.cdap.security.auth.AccessTokenTransformer)1 TokenState (co.cask.cdap.security.auth.TokenState)1 IRequestHandler (com.feeyo.net.http.handler.IRequestHandler)1 JsonArray (com.google.gson.JsonArray)1 JsonObject (com.google.gson.JsonObject)1 DeferredGroupException (com.stumbleupon.async.DeferredGroupException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1