Java 类play.mvc.Http.Header 实例源码

项目:play-profiler    文件:ProfilerPlugin.java   
private void displayGae(String name)
{
    Request request = Request.current();
    if (request != null)
    {
        Header header = request.headers.get("X-TraceUrl");
        if (header != null)
        {
            String value = header.value();
            if (StringUtils.isNotEmpty(value))
            {
                // Logger.info("profiler: " + name + " " + value);
            }
        }

    }
}
项目:play-profiler    文件:ProfilerEnhancer.java   
private static String getAppstatsIdFromResponse() {
    String result = "nada";
    Response request = Response.current();
    if (request != null)
    {
        Header header = request.headers.get("X-TraceUrl");
        if (header != null)
        {
            String value = header.value();
            result = value;
            if (StringUtils.isNotEmpty(value))
            {
                String[] parts = value.split("\\?")[1].split("&");
                for (String part : parts)
                {
                    String[] nameValue = part.split("=");
                    if ("time".equals(nameValue[0]))
                    {
                        result = nameValue[1];
                        Logger.info("profiler: appstats " + result);
                    }
                }

            }
        }
    }
    return result;
}
项目:play-profiler    文件:ProfilerEnhancer.java   
private static String getAppstatsIdFromRequest() {
    String result = "nada";
    Request request = Request.current();
    if (request != null)
    {
        Header header = request.headers.get("X-TraceUrl");
        if (header != null)
        {
            String value = header.value();
            result = value;
            if (StringUtils.isNotEmpty(value))
            {
                String[] parts = value.split("\\?")[1].split("&");
                for (String part : parts)
                {
                    String[] nameValue = part.split("=");
                    if ("time".equals(nameValue[0]))
                    {
                        result = nameValue[1];
                        Logger.info("profiler: appstats " + result);
                    }
                }

            }
        }
    }
    return result;
}
项目:play-profiler    文件:ProfilerEnhancer.java   
public static void addHeader(Request request, String name, String requestId) {
    if (request == null)
        return;
    Header h = new Header();
    h.name = name;
    h.values = new java.util.ArrayList<String>(1);
    h.values.add(requestId);
    request.headers.put(name, h);

}
项目:play-profiler    文件:ProfilerEnhancer.java   
static public String currentRequestId()
{
    if (Request.current() == null)
        return "";
    Header header = Request.current().headers.get(REQUEST_ID_ATTRIBUTE);
    if (header == null)
        return "";
    return header.value();
}
项目:restcommander    文件:WSAsync.java   
@Override
public List<Header> getHeaders() {
    Map<String, List<String>> hdrs = response.getHeaders();
    List<Header> result = new ArrayList<Header>();
    for (String key: hdrs.keySet()) {
        result.add(new Header(key, hdrs.get(key)));
    }
    return result;
}
项目:restcommander    文件:WSUrlFetch.java   
@Override
public List<Header> getHeaders() {
    List<Header> result = new ArrayList<Header>();
    for (String key: headersMap.keySet()) {
        result.add(new Header(key, headersMap.get(key)));
    }
    return result;
}
项目:restcommander    文件:CorePlugin.java   
/**
 * Intercept /@status and check that the Authorization header is valid. 
 * Then ask each plugin for a status dump and send it over the HTTP response.
 *
 * You can ask the /@status using the authorization header and putting your status secret key in it.
 * Prior to that you would be required to start play with  a -DstatusKey=yourkey
 */
@Override
public boolean rawInvocation(Request request, Response response) throws Exception {
    if (Play.mode == Mode.DEV && request.path.equals("/@kill")) {
        System.out.println("@KILLED");
        if (Play.standalonePlayServer) {
            System.exit(0);
        } else {
            Logger.error("Cannot execute @kill since Play is not running as standalone server");
        }
    }
    if (request.path.equals("/@status") || request.path.equals("/@status.json")) {
        if(!Play.started) {
            response.print("Application is not started");
            response.status = 503;
            return true;
        }
        response.contentType = request.path.contains(".json") ? "application/json" : "text/plain";
        Header authorization = request.headers.get("authorization");
        if (authorization != null && (Crypto.sign("@status").equals(authorization.value()) || System.getProperty("statusKey", Play.secretKey).equals(authorization.value()))) {
            response.print(computeApplicationStatus(request.path.contains(".json")));
            response.status = 200;
            return true;
        }
        response.status = 401;
        if (response.contentType.equals("application/json")) {
            response.print("{\"error\": \"Not authorized\"}");
        } else {
            response.print("Not authorized");
        }
        return true;
    }
    return super.rawInvocation(request, response);
}
项目:MyDMAM    文件:PartialContent.java   
@Override
public void apply(final Request request, final Response response) {
    try {
        response.status = 206;
        Header rangeHeader = request.headers.get("range");
        String rangeValue = rangeHeader.value().trim().substring("bytes=".length());
        long fileLength = this.file.length();
        long start, end;
        if (rangeValue.startsWith("-")) {
            end = fileLength - 1;
            start = fileLength - 1 - Long.parseLong(rangeValue.substring("-".length()));
        } else {
            String[] range = rangeValue.split("-");
            start = Long.parseLong(range[0]);
            end = range.length > 1 ? Long.parseLong(range[1]) : fileLength - 1;
        }
        if (end > fileLength - 1) {
            end = fileLength - 1;
        }
        if (start <= end) {
            long contentLength = end - start + 1;

            Loggers.Play.debug("Partial download, start: " + start + ", contentLength: " + contentLength);

            response.setHeader("Content-Length", contentLength + "");
            response.setHeader("Content-Range", "bytes " + start + "-" + end + "/" + fileLength);
            response.setHeader("Content-Type", mime);
            RandomAccessFile raf = new RandomAccessFile(this.file, "r");
            response.direct = new ChunkedFile(raf, start, contentLength, 8192);
        }
    } catch (Exception e) {
        throw new UnexpectedException(e);
    }
}
项目:restcommander    文件:WS.java   
public abstract List<Header> getHeaders();