当前位置: 首页>>代码示例>>Java>>正文


Java Request.current方法代码示例

本文整理汇总了Java中play.mvc.Http.Request.current方法的典型用法代码示例。如果您正苦于以下问题:Java Request.current方法的具体用法?Java Request.current怎么用?Java Request.current使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在play.mvc.Http.Request的用法示例。


在下文中一共展示了Request.current方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: displayGae

import play.mvc.Http.Request; //导入方法依赖的package包/类
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);
            }
        }

    }
}
 
开发者ID:PerfectCarl,项目名称:play-profiler,代码行数:18,代码来源:ProfilerPlugin.java

示例2: invocationFinally

import play.mvc.Http.Request; //导入方法依赖的package包/类
@Override
public void invocationFinally() {
	Long start = startTime.get();
	//start will be null IF StartupBean was just invoked!!!! 
	if(start != null) {
		Request current = Request.current();
		long total = System.currentTimeMillis() - start;
		startTime.set(null);
		if(log.isInfoEnabled() && isProduction || (!current.path.startsWith("/public")))
			log.info("---ended request="+current.method+":"+current.path+" total time="+total+" ms");
	}
	
	MDC.put("sessionid", "");
	MDC.put("user", "");
}
 
开发者ID:guci314,项目名称:playorm,代码行数:16,代码来源:AddLogContextPlugin.java

示例3: after

import play.mvc.Http.Request; //导入方法依赖的package包/类
public static void after(Profile profile, boolean shouldProfile, String requestId, long startTime) {
    // Logger.info("af: shouldProfile    " + shouldProfile);
    // Logger.info("af: requestId        " + requestId);
    // Logger.info("af: startTime        " + startTime);
    // Logger.info("af: profile          " + profile);

    if (shouldProfile)
    {
        Request request = Request.current();
        if (request == null)
        {
            Logger.info("request: null");
        } else
        {
            java.util.Map<String, Object> requestData = new java.util.HashMap<String, Object>();
            requestData.put("requestURL",
                    request.url + ((request.querystring != null) ? "?" + request.querystring : ""));
            requestData.put("timestamp", startTime);
            requestData.put("profile", profile);
            String appstatsId = getAppstatsId();
            if (StringUtils.isNotEmpty(appstatsId))
            {
                requestData.put("appstatsId", appstatsId);
            }
            cacheProfilerService.put(requestId, requestData);
        }
    }
}
 
开发者ID:PerfectCarl,项目名称:play-profiler,代码行数:29,代码来源:ProfilerEnhancer.java

示例4: getAppstatsIdFromRequest

import play.mvc.Http.Request; //导入方法依赖的package包/类
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;
}
 
开发者ID:PerfectCarl,项目名称:play-profiler,代码行数:29,代码来源:ProfilerEnhancer.java

示例5: currentRequestId

import play.mvc.Http.Request; //导入方法依赖的package包/类
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();
}
 
开发者ID:PerfectCarl,项目名称:play-profiler,代码行数:10,代码来源:ProfilerEnhancer.java

示例6: serve404

import play.mvc.Http.Request; //导入方法依赖的package包/类
public void serve404(GrizzlyRequest request, GrizzlyResponse response, NotFound e) {
    Logger.warn("404 -> %s %s (%s)", request.getMethod(), request.getRequestURI(), e.getMessage());
    response.setStatus(404);
    response.setContentType("text/html");
    Map<String, Object> binding = new HashMap<String, Object>();
    binding.put("result", e);
    binding.put("session", Scope.Session.current());
    binding.put("request", Http.Request.current());
    binding.put("flash", Scope.Flash.current());
    binding.put("params", Scope.Params.current());
    binding.put("play", new Play());
    try {
        binding.put("errors", Validation.errors());
    } catch (Exception ex) {
        //
    }
    String format = Request.current().format;
    response.setStatus(404);
    // Do we have an ajax request? If we have then we want to display some text even if it is html that is requested
    if ("XMLHttpRequest".equals(request.getHeader("X-Requested-With")) && (format == null || format.equals("html"))) {
        format = "txt";
    }
    if (format == null) {
        format = "txt";
    }
    response.setContentType(MimeTypes.getContentType("404." + format, "text/plain"));
    String errorHtml = TemplateLoader.load("errors/404." + format).render(binding);
    try {
        response.getOutputStream().write(errorHtml.getBytes("utf-8"));
    } catch (Exception fex) {
        Logger.error(fex, "(utf-8 ?)");
    }
}
 
开发者ID:eBay,项目名称:restcommander,代码行数:34,代码来源:PlayGrizzlyAdapter.java

示例7: template

import play.mvc.Http.Request; //导入方法依赖的package包/类
/**
 * Work out the default template to load for the invoked action.
 * E.g. "controllers.Pages.index" returns "views/Pages/index.html".
 */
protected static String template() {
    final Request theRequest = Request.current();
    final String format = theRequest.format;
    String templateName = theRequest.action.replace(".", "/") + "." + (format == null ? "html" : format);
    if (templateName.startsWith("@")) {
        templateName = templateName.substring(1);
        if (!templateName.contains(".")) {
            templateName = theRequest.controller + "." + templateName;
        }
        templateName = templateName.replace(".", "/") + "." + (format == null ? "html" : format);
    }
    return templateName;
}
 
开发者ID:eBay,项目名称:restcommander,代码行数:18,代码来源:Controller.java

示例8: await

import play.mvc.Http.Request; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
protected static <T> T await(Future<T> future) {

    if(future != null) {
        Request.current().args.put(ActionInvoker.F, future);
    } else if(Request.current().args.containsKey(ActionInvoker.F)) {
        // Since the continuation will restart in this code that isn't intstrumented by javaflow,
        // we need to reset the state manually.
        StackRecorder.get().isCapturing = false;
        StackRecorder.get().isRestoring = false;
        StackRecorder.get().value = null;
        future = (Future<T>)Request.current().args.get(ActionInvoker.F);

        // Now reset the Controller invocation context
        ControllerInstrumentation.stopActionCall();
        storeOrRestoreDataStateForContinuations( true );
    } else {
        throw new UnexpectedException("Lost promise for " + Http.Request.current() + "!");
    }
    
    if(future.isDone()) {
        try {
            return future.get();
        } catch(Exception e) {
            throw new UnexpectedException(e);
        }
    } else {
        Request.current().isNew = false;
        verifyContinuationsEnhancement();
        storeOrRestoreDataStateForContinuations( false );
        Continuation.suspend(future);
        return null;
    }
}
 
开发者ID:eBay,项目名称:restcommander,代码行数:35,代码来源:Controller.java

示例9: serve404

import play.mvc.Http.Request; //导入方法依赖的package包/类
public void serve404(HttpServletRequest servletRequest, HttpServletResponse servletResponse, NotFound e) {
    Logger.warn("404 -> %s %s (%s)", servletRequest.getMethod(), servletRequest.getRequestURI(), e.getMessage());
    servletResponse.setStatus(404);
    servletResponse.setContentType("text/html");
    Map<String, Object> binding = new HashMap<String, Object>();
    binding.put("result", e);
    binding.put("session", Scope.Session.current());
    binding.put("request", Http.Request.current());
    binding.put("flash", Scope.Flash.current());
    binding.put("params", Scope.Params.current());
    binding.put("play", new Play());
    try {
        binding.put("errors", Validation.errors());
    } catch (Exception ex) {
        //
    }
    String format = Request.current().format;
    servletResponse.setStatus(404);
    // Do we have an ajax request? If we have then we want to display some text even if it is html that is requested
    if ("XMLHttpRequest".equals(servletRequest.getHeader("X-Requested-With")) && (format == null || format.equals("html"))) {
        format = "txt";
    }
    if (format == null) {
        format = "txt";
    }
    servletResponse.setContentType(MimeTypes.getContentType("404." + format, "text/plain"));
    String errorHtml = TemplateLoader.load("errors/404." + format).render(binding);
    try {
        servletResponse.getOutputStream().write(errorHtml.getBytes(Response.current().encoding));
    } catch (Exception fex) {
        Logger.error(fex, "(encoding ?)");
    }
}
 
开发者ID:eBay,项目名称:restcommander,代码行数:34,代码来源:ServletWrapper.java

示例10: serve404

import play.mvc.Http.Request; //导入方法依赖的package包/类
public static void serve404(NotFound e, ChannelHandlerContext ctx, Request request, HttpRequest nettyRequest) {
    if (Logger.isTraceEnabled()) {
        Logger.trace("serve404: begin");
    }
    HttpResponse nettyResponse = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.NOT_FOUND);
    nettyResponse.setHeader(SERVER, signature);

    nettyResponse.setHeader(CONTENT_TYPE, "text/html");
    Map<String, Object> binding = getBindingForErrors(e, false);

    String format = Request.current().format;
    if (format == null) {
        format = "txt";
    }
    nettyResponse.setHeader(CONTENT_TYPE, (MimeTypes.getContentType("404." + format, "text/plain")));


    String errorHtml = TemplateLoader.load("errors/404." + format).render(binding);
    try {
        byte[] bytes = errorHtml.getBytes(Response.current().encoding);
        ChannelBuffer buf = ChannelBuffers.copiedBuffer(bytes);
        setContentLength(nettyResponse, bytes.length);
        nettyResponse.setContent(buf);
        ChannelFuture writeFuture = ctx.getChannel().write(nettyResponse);
        writeFuture.addListener(ChannelFutureListener.CLOSE);
    } catch (UnsupportedEncodingException fex) {
        Logger.error(fex, "(encoding ?)");
    }
    if (Logger.isTraceEnabled()) {
        Logger.trace("serve404: end");
    }
}
 
开发者ID:eBay,项目名称:restcommander,代码行数:33,代码来源:PlayHandler.java

示例11: before

import play.mvc.Http.Request; //导入方法依赖的package包/类
public static void before(String requestId) {
    if (Response.current() != null)
        Response.current().setHeader(RESPONSE_ID_HEADER, requestId);
    if (Request.current() != null)
        addHeader(Request.current(), REQUEST_ID_ATTRIBUTE, requestId);
}
 
开发者ID:PerfectCarl,项目名称:play-profiler,代码行数:7,代码来源:ProfilerEnhancer.java

示例12: shouldProfile

import play.mvc.Http.Request; //导入方法依赖的package包/类
public static boolean shouldProfile() {
    if (Request.current() == null)
        return true;
    return shouldProfile(Request.current().path);
}
 
开发者ID:PerfectCarl,项目名称:play-profiler,代码行数:6,代码来源:ProfilerEnhancer.java

示例13: OpenID

import play.mvc.Http.Request; //导入方法依赖的package包/类
private OpenID(String id) {
    this.id = id;
    this.returnAction = this.realmAction = Request.current().action;
}
 
开发者ID:eBay,项目名称:restcommander,代码行数:5,代码来源:OpenID.java

示例14: suspend

import play.mvc.Http.Request; //导入方法依赖的package包/类
/**
 * Suspend the current request for a specified amount of time (in milliseconds).
 *
 * <p><b>Important:</b> The method will not resume on the line after you call this. The method will
 * be called again as if there was a new HTTP request.
 *
 * @param millis Number of milliseconds to wait until trying again.
 */
@Deprecated
protected static void suspend(int millis) {
    Request.current().isNew = false;
    throw new Suspend(millis);
}
 
开发者ID:eBay,项目名称:restcommander,代码行数:14,代码来源:Controller.java

示例15: waitFor

import play.mvc.Http.Request; //导入方法依赖的package包/类
/**
 * Suspend this request and wait for the task completion
 *
 * <p><b>Important:</b> The method will not resume on the line after you call this. The method will
 * be called again as if there was a new HTTP request.
 *
 * @param tasks
 */
@Deprecated
protected static void waitFor(Future<?> task) {
    Request.current().isNew = false;
    throw new Suspend(task);
}
 
开发者ID:eBay,项目名称:restcommander,代码行数:14,代码来源:Controller.java


注:本文中的play.mvc.Http.Request.current方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。