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


Java Request类代码示例

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


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

示例1: createCommonResponse

import play.mvc.Http.Request; //导入依赖的package包/类
/**
 * This method will create common response for all controller method
 * 
 * @param response Object
 * @param key String
 * @param request play.mvc.Http.Request
 * @return Result
 */
public Result createCommonResponse(Object response, String key, play.mvc.Http.Request request) {

  if (response instanceof Response) {
    Response courseResponse = (Response) response;
    if (!ProjectUtil.isStringNullOREmpty(key)) {
      Object value = courseResponse.getResult().get(JsonKey.RESPONSE);
      courseResponse.getResult().remove(JsonKey.RESPONSE);
      courseResponse.getResult().put(key, value);
    }
    return Results.ok(
        Json.toJson(BaseController.createSuccessResponse(request, (Response) courseResponse)));
  } else {
    ProjectCommonException exception = (ProjectCommonException) response;
    return Results.status(exception.getResponseCode(),
        Json.toJson(BaseController.createResponseOnException(request, exception)));
  }
}
 
开发者ID:project-sunbird,项目名称:sunbird-lms-service,代码行数:26,代码来源:BaseController.java

示例2: createAction

import play.mvc.Http.Request; //导入依赖的package包/类
@Override
public Action<Void> createAction(Request request, Method actionMethod) {

    return new Action.Simple() {
        @Override
        public Promise<Result> call(Context ctx) throws Throwable {
            // Inject the required services into the context
            injectCommonServicesIncontext(ctx);
            final Language language = new Language(request.getQueryString("lang"));

            if (messagesPlugin.isLanguageValid(language.getCode())) {
                Logger.debug("change language to: " + language.getCode());
                ctx.changeLang(language.getCode());
                // Update the CAS language cookie which is relying on Spring
                // framework (not really solid yet works)
                Utilities.setSsoLanguage(ctx, language.getCode());
            }

            return delegate.call(ctx);

        }
    };

}
 
开发者ID:theAgileFactory,项目名称:maf-desktop-app,代码行数:25,代码来源:MafHttpRequestHandler.java

示例3: writeInterface

import play.mvc.Http.Request; //导入依赖的package包/类
@Override
public void writeInterface(JsonGenerator generator, PlayHttpRequestInterface playHttpInterface) throws IOException {
	Request request = playHttpInterface.getRequest();
	
	generator.writeStartObject();
	generator.writeStringField(URL, buildUrl(request));
	generator.writeStringField(METHOD, request.method());
	
	generator.writeFieldName(DATA);
	writeData(generator, request);

	generator.writeStringField(QUERY_STRING, extractQueryString(request));
	
	generator.writeFieldName(COOKIES);
	writeCookies(generator, request.cookies());
	
	generator.writeFieldName(HEADERS);
	writeHeaders(generator, request.headers());
	
	generator.writeFieldName(ENVIRONMENT);
	writeEnvironment(generator, request);
	
	generator.writeEndObject();
}
 
开发者ID:xolvo,项目名称:play-sentry,代码行数:25,代码来源:PlayHttpRequestInterfaceBinding.java

示例4: loadConfiguration

import play.mvc.Http.Request; //导入依赖的package包/类
private static ClientConf.Configuration loadConfiguration(Request request) {
    ClientConf.Configuration configuration = new ClientConf.Configuration();

    configuration.set(
        ClientConf.Setting.INDEX_URL,
        routes.Application.index().url());

    configuration.set(
        ClientConf.Setting.ASSETS_URL,
        controllers.routes.Assets.at("").url());

    configuration.set(
        ClientConf.Setting.RPC_SERVICE_HTTP_URL,
        controllers.rpc.routes.HTTPController.call().url());

    configuration.set(
        ClientConf.Setting.RPC_SERVICE_WS_URL,
        controllers.rpc.routes.WebSocketController.socket().webSocketURL(
            request));

    return configuration;
}
 
开发者ID:snogaraleal,项目名称:wbi,代码行数:23,代码来源:ServerConf.java

示例5: renderTemplate

import play.mvc.Http.Request; //导入依赖的package包/类
@Test
public void renderTemplate() throws InstantiationException, IllegalAccessException {
    Request requestMock = mock(Request.class);

    Context.current.set(new Context(1l, mock(RequestHeader.class), requestMock, //
            Collections.<String, String>emptyMap(), // sessionData
            Collections.<String, String>emptyMap(), // flashData
            Collections.<String, Object>emptyMap()));

    when(requestMock.username()).thenReturn("nom_de_test");

    Html html = views.html.index.render("Your new application is ready.");
    assertThat(contentType(html)).isEqualTo("text/html");
    assertThat(contentAsString(html)).contains("Your new application is ready.");
    assertThat(contentAsString(html)).contains("Bonjour nom_de_test!");
}
 
开发者ID:fmaturel,项目名称:PlayTraining,代码行数:17,代码来源:ApplicationTest.java

示例6: PlayServerWebSocket

import play.mvc.Http.Request; //导入依赖的package包/类
public PlayServerWebSocket(Request request, In<String> in, Out<String> out) {
    this.request = request;
    this.out = out;
    // TODO https://github.com/vibe-project/vibe-java-platform/issues/4
    // Supports text frame only for now
    in.onMessage(new Callback<String>() {
        @Override
        public void invoke(String message) throws Throwable {
            textActions.fire(message);
        }
    });
    in.onClose(new Callback0() {
        @Override
        public void invoke() throws Throwable {
            closeActions.fire();
        }
    });
}
 
开发者ID:vibe-project,项目名称:vibe-java-platform,代码行数:19,代码来源:PlayServerWebSocket.java

示例7: 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

示例8: beforeActionInvocation

import play.mvc.Http.Request; //导入依赖的package包/类
@Override
public void beforeActionInvocation(Method actionMethod) {
    super.beforeActionInvocation(actionMethod);
    // displayGae("beforeActionInvocation");
    // RenderArgs.current().put("profiler", profilerUtil);
    boolean shouldProfile = ProfilerEnhancer.shouldProfile();
    if (shouldProfile)
    {
        ProfilerEnhancer.addHeader(Request.current(), ProfilerEnhancer.REQUEST_ID_ATTRIBUTE, requestId);
        profilerUtil.setRequestId(requestId);

        RenderArgs.current().put("profiler", profilerUtil);
    }
    // Logger.info("beforeInvocation: " + actionMethod.getName() +
    // " requestId:" + ProfilerEnhancer.currentRequestId());
}
 
开发者ID:PerfectCarl,项目名称:play-profiler,代码行数:17,代码来源:ProfilerPlugin.java

示例9: routeRequest

import play.mvc.Http.Request; //导入依赖的package包/类
@Override
public void routeRequest(Request request) {
    boolean shouldProfile = ProfilerEnhancer.shouldProfile();
    if (shouldProfile)
    {
        profilerUtil = ProfilerEnhancer.addIncludes();
        requestId = String.valueOf(counter.incrementAndGet());
        ProfilerEnhancer.before(requestId);
        // Logger.info("routeRequest:" + request.path + " requestId:" +
        // ProfilerEnhancer.currentRequestId());
        startTime = System.currentTimeMillis();
        // displayGae("routeRequest");
        MiniProfiler.start();
    }
    super.routeRequest(request);
}
 
开发者ID:PerfectCarl,项目名称:play-profiler,代码行数:17,代码来源:ProfilerPlugin.java

示例10: bind

import play.mvc.Http.Request; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public Object bind(String name, Annotation[] annotations, String value, Class actualClass, Type genericType) {
    if (value == null || value.trim().length() == 0) {
        return null;
    }
    try {
        List<Upload> uploads = (List<Upload>) Request.current().args.get("__UPLOADS");
        for (Upload upload : uploads) {
            if (upload.getFieldName().equals(value) && upload.getSize() > 0) {
                return upload;
            }
        }
        if (Params.current().get(value + "_delete_") != null) {
            return null;
        }
        return Binder.MISSING;
    } catch (Exception e) {
        Logger.error("", e);
        throw new UnexpectedException(e);
    }
}
 
开发者ID:eBay,项目名称:restcommander,代码行数:22,代码来源:UploadBinder.java

示例11: bind

import play.mvc.Http.Request; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public File[] bind(String name, Annotation[] annotations, String value, Class actualClass, Type genericType) {
    if (value == null || value.trim().length() == 0) {
        return null;
    }
    List<Upload> uploads = (List<Upload>) Request.current().args.get("__UPLOADS");
    List<File> fileArray = new ArrayList<File>();
    for (Upload upload : uploads) {
        if (upload.getFieldName().equals(value)) {
            File file = upload.asFile();
            if (file.length() > 0) {
                fileArray.add(file);
            }
        }
    }
    return fileArray.toArray(new File[fileArray.size()]);
}
 
开发者ID:eBay,项目名称:restcommander,代码行数:18,代码来源:FileArrayBinder.java

示例12: bind

import play.mvc.Http.Request; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public File bind(String name, Annotation[] annotations, String value, Class actualClass, Type genericType) {
    if (value == null || value.trim().length() == 0) {
        return null;
    }
    List<Upload> uploads = (List<Upload>) Request.current().args.get("__UPLOADS");
    for (Upload upload : uploads) {
        if (upload.getFieldName().equals(value)) {
            File file = upload.asFile();
            if (file.length() > 0) {
                return file;
            }
            return null;
        }
    }
    return null;
}
 
开发者ID:eBay,项目名称:restcommander,代码行数:18,代码来源:FileBinder.java

示例13: bind

import play.mvc.Http.Request; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public Object bind(String name, Annotation[] annotations, String value, Class actualClass, Type genericType) {
    if (value == null || value.trim().length() == 0) {
        return null;
    }
    try {
        Model.BinaryField b = (Model.BinaryField) actualClass.newInstance();
        List<Upload> uploads = (List<Upload>) Request.current().args.get("__UPLOADS");
        for (Upload upload : uploads) {
            if (upload.getFieldName().equals(value) && upload.getSize() > 0) {
                b.set(upload.asStream(), upload.getContentType());
                return b;
            }
        }
        if (Params.current().get(value + "_delete_") != null) {
            return null;
        }
        return Binder.MISSING;
    } catch (Exception e) {
        throw new UnexpectedException(e);
    }
}
 
开发者ID:eBay,项目名称:restcommander,代码行数:23,代码来源:BinaryBinder.java

示例14: renderTemplate

import play.mvc.Http.Request; //导入依赖的package包/类
/**
 * Render a specific template.
 *
 * @param templateName The template name.
 * @param args The template data.
 */
protected static void renderTemplate(String templateName, Map<String,Object> args) {
    // Template datas
    Scope.RenderArgs templateBinding = Scope.RenderArgs.current();
    templateBinding.data.putAll(args);
    templateBinding.put("session", Scope.Session.current());
    templateBinding.put("request", Http.Request.current());
    templateBinding.put("flash", Scope.Flash.current());
    templateBinding.put("params", Scope.Params.current());
    templateBinding.put("errors", Validation.errors());
    try {
        Template template = TemplateLoader.load(template(templateName));
        throw new RenderTemplate(template, templateBinding.data);
    } catch (TemplateNotFoundException ex) {
        if (ex.isSourceAvailable()) {
            throw ex;
        }
        StackTraceElement element = PlayException.getInterestingStrackTraceElement(ex);
        if (element != null) {
            throw new TemplateNotFoundException(templateName, Play.classes.getApplicationClass(element.getClassName()), element.getLineNumber());
        } else {
            throw ex;
        }
    }
}
 
开发者ID:eBay,项目名称:restcommander,代码行数:31,代码来源:Controller.java

示例15: invokeControllerMethod

import play.mvc.Http.Request; //导入依赖的package包/类
public static Object invokeControllerMethod(Method method, Object[] forceArgs) throws Exception {
    if (Modifier.isStatic(method.getModifiers()) && !method.getDeclaringClass().getName().matches("^controllers\\..*\\$class$")) {
        return invoke(method, null, forceArgs == null ? getActionMethodArgs(method, null) : forceArgs);
    } else if (Modifier.isStatic(method.getModifiers())) {
        Object[] args = getActionMethodArgs(method, null);
        args[0] = Http.Request.current().controllerClass.getDeclaredField("MODULE$").get(null);
        return invoke(method, null, args);
    } else {
        Object instance = null;
        try {
            instance = method.getDeclaringClass().getDeclaredField("MODULE$").get(null);
        } catch (Exception e) {
            Annotation[] annotations = method.getDeclaredAnnotations();
            String annotation = Utils.getSimpleNames(annotations);
            if (!StringUtils.isEmpty(annotation)) {
                throw new UnexpectedException("Method public static void " + method.getName() + "() annotated with " + annotation + " in class " + method.getDeclaringClass().getName() + " is not static.");
            }
            // TODO: Find a better error report
            throw new ActionNotFoundException(Http.Request.current().action, e);
        }
        return invoke(method, instance, forceArgs == null ? getActionMethodArgs(method, instance) : forceArgs);
    }
}
 
开发者ID:eBay,项目名称:restcommander,代码行数:24,代码来源:ActionInvoker.java


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