@Override public void beforeInvocation() { // // Prevent the regular JPA Plugin from starting a transaction. // JPA.entityManagerFactory = null; // // If we have no databases defined, and we have a directive to permit this state, allow it. // if (factoryMap.isEmpty() && Play.configuration.getProperty("mjpa.runWithNoDB", "").equals("true")) { log.debug("Empty factory map--using dummy factory"); JPA.entityManagerFactory = getDummyFactory(); return; } log.debug("Extracting DB key from request: " + Request.current()); // // Find the database key, so that we'll have one for the transaction. // String dbKey = keyExtractor.extractKey(Request.current()); log.debug("Found key: " + dbKey); try { if (dbKey != null) { // // Start the transaction // startTx(dbKey, false); } } catch (InvalidDatabaseException e) { throw new NotFound(e.getMessage()); } }
public void serveStatic( HttpServletResponse servletResponse, HttpServletRequest servletRequest, RenderStatic renderStatic) throws IOException { VirtualFile file = Play.getVirtualFile(renderStatic.file); if (file == null || file.isDirectory() || !file.exists()) { serve404( servletRequest, servletResponse, new NotFound("The file " + renderStatic.file + " does not exist")); } else { servletResponse.setContentType(MimeTypes.getContentType(file.getName())); boolean raw = false; for (PlayPlugin plugin : Play.plugins) { if (plugin.serveStatic(file, Request.current(), Response.current())) { raw = true; break; } } if (raw) { copyResponse(Request.current(), Response.current(), servletRequest, servletResponse); } else { if (Play.mode == Play.Mode.DEV) { servletResponse.setHeader("Cache-Control", "no-cache"); servletResponse.setHeader("Content-Length", String.valueOf(file.length())); if (!servletRequest.getMethod().equals("HEAD")) { copyStream(servletResponse, file.inputstream()); } else { copyStream(servletResponse, new ByteArrayInputStream(new byte[0])); } } else { long last = file.lastModified(); String etag = "\"" + last + "-" + file.hashCode() + "\""; if (!isModified(etag, last, servletRequest)) { servletResponse.setHeader("Etag", etag); servletResponse.setStatus(304); } else { servletResponse.setHeader( "Last-Modified", Utils.getHttpDateFormatter().format(new Date(last))); servletResponse.setHeader( "Cache-Control", "max-age=" + Play.configuration.getProperty("http.cacheControl", "3600")); servletResponse.setHeader("Etag", etag); copyStream(servletResponse, file.inputstream()); } } } } }
public static void serve404( NotFound e, ChannelHandlerContext ctx, Request request, HttpRequest nettyRequest) { 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 { ChannelBuffer buf = ChannelBuffers.copiedBuffer(errorHtml.getBytes("utf-8")); nettyResponse.setContent(buf); ChannelFuture writeFuture = ctx.getChannel().write(nettyResponse); writeFuture.addListener(ChannelFutureListener.CLOSE); } catch (UnsupportedEncodingException fex) { Logger.error(fex, "(utf-8 ?)"); } Logger.trace("serve404: end"); }
/** * @param template * @return */ public static String getTemapletClassName(String template) { // if (template == null || template.length() == 0) { template = template(); } if (template.endsWith(HTML)) { template = template.substring(0, template.length() - HTML.length()); } // String action = StackTraceUtils.getCaller(); // too tricky to use // stacktrace to track the caller action name // something like controllers.japid.SampleController.testFindAction if (template.startsWith("@")) { // a template in the current directory template = Request.current().controller + "/" + template.substring(1); } // map to default japid view if (template.startsWith("controllers.")) { template = template.substring(template.indexOf(DOT) + 1); } String templateClassName = template.startsWith(DirUtil.JAPIDVIEWS_ROOT) ? template : DirUtil.JAPIDVIEWS_ROOT + File.separator + template; templateClassName = templateClassName.replace('/', DOT).replace('\\', DOT); return templateClassName; }
// default visibility, because we want to use this only from Job.java static void addAfterRequestAction(Callable<? extends Object> c) { if (Request.current() == null) { throw new IllegalStateException( "After request actions can be added only from threads that serve requests!"); } afterInvocationActions.get().add(c); }
@Override protected void service( HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws ServletException, IOException { if (!routerInitializedWithContext) { loadRouter(httpServletRequest.getContextPath()); } if (Logger.isTraceEnabled()) { Logger.trace("ServletWrapper>service " + httpServletRequest.getRequestURI()); } Request request = null; try { Response response = new Response(); response.out = new ByteArrayOutputStream(); Response.current.set(response); request = parseRequest(httpServletRequest); if (Logger.isTraceEnabled()) { Logger.trace("ServletWrapper>service, request: " + request); } boolean raw = Play.pluginCollection.rawInvocation(request, response); if (raw) { copyResponse( Request.current(), Response.current(), httpServletRequest, httpServletResponse); } else { Invoker.invokeInThread( new ServletInvocation(request, response, httpServletRequest, httpServletResponse)); } } catch (NotFound e) { if (Logger.isTraceEnabled()) { Logger.trace("ServletWrapper>service, NotFound: " + e); } serve404(httpServletRequest, httpServletResponse, e); return; } catch (RenderStatic e) { if (Logger.isTraceEnabled()) { Logger.trace("ServletWrapper>service, RenderStatic: " + e); } serveStatic(httpServletResponse, httpServletRequest, e); return; } catch (Throwable e) { throw new ServletException(e); } finally { Request.current.remove(); Response.current.remove(); Scope.Session.current.remove(); Scope.Params.current.remove(); Scope.Flash.current.remove(); Scope.RenderArgs.current.remove(); Scope.RouteArgs.current.remove(); } }
/** * Retrieve the verified OpenID * * @return A UserInfo object */ public static UserInfo getVerifiedID() { try { String mode = Params.current().get("openid.mode"); // Check authentication if (mode != null && mode.equals("id_res")) { // id String id = Params.current().get("openid.claimed_id"); if (id == null) { id = Params.current().get("openid.identity"); } id = normalize(id); // server String server = Params.current().get("openid.op_endpoint"); if (server == null) { server = discoverServer(id); } String fields = Request.current() .querystring .replace("openid.mode=id_res", "openid.mode=check_authentication"); WS.HttpResponse response = WS.url(server).mimeType("application/x-www-form-urlencoded").body(fields).post(); if (response.getStatus() == 200 && response.getString().contains("is_valid:true")) { UserInfo userInfo = new UserInfo(); userInfo.id = id; Pattern patternAX = Pattern.compile("^openid[.].+[.]value[.]([^.]+)([.]\\d+)?$"); Pattern patternSREG = Pattern.compile("^openid[.]sreg[.]([^.]+)$"); for (String p : Params.current().allSimple().keySet()) { Matcher m = patternAX.matcher(p); if (m.matches()) { String alias = m.group(1); userInfo.extensions.put(alias, Params.current().get(p)); } m = patternSREG.matcher(p); if (m.matches()) { String alias = m.group(1); userInfo.extensions.put(alias, Params.current().get(p)); } } return userInfo; } else { return null; } } } catch (Exception e) { throw new RuntimeException(e); } return null; }
@Override public void beforeActionInvocation(Method actionMethod) { Scope.RenderArgs binding = Scope.RenderArgs.current(); Request request = Request.current(); binding.put("_menu_current", request.url); // binding.put("_menu_editing_url", Play.configuration.getProperty("menu.editing.url", // Router.reverse("_menu.Configurator.edit").url)); setRenderArgs_("_menu_context"); setRenderArgs_("_menu_label"); }
@Override public Object invokeMethod(String name, Object param) { try { if (controller == null) { controller = Request.current().controller; } String action = controller + "." + name; if (action.endsWith(".call")) { action = action.substring(0, action.length() - 5); } try { Map<String, Object> r = new HashMap<String, Object>(); Method actionMethod = (Method) ActionInvoker.getActionMethod(action)[1]; String[] names = (String[]) actionMethod.getDeclaringClass().getDeclaredField("$" + actionMethod.getName() + LocalVariablesNamesTracer.computeMethodHash(actionMethod.getParameterTypes())).get(null); if (param instanceof Object[]) { // too many parameters versus action, possibly a developer error. we must warn him. if (names.length < ((Object[]) param).length) { throw new NoRouteFoundException(action, null); } for (int i = 0; i < ((Object[]) param).length; i++) { if (((Object[]) param)[i] instanceof Router.ActionDefinition && ((Object[]) param)[i] != null) { Unbinder.unBind(r, ((Object[]) param)[i].toString(), i < names.length ? names[i] : ""); } else if (isSimpleParam(actionMethod.getParameterTypes()[i])) { if (((Object[]) param)[i] != null) { Unbinder.unBind(r, ((Object[]) param)[i].toString(), i < names.length ? names[i] : ""); } } else { Unbinder.unBind(r, ((Object[]) param)[i], i < names.length ? names[i] : ""); } } } Router.ActionDefinition def = Router.reverse(action, r); if (absolute) { def.absolute(); } if (template.template.name.endsWith(".html") || template.template.name.endsWith(".xml")) { def.url = def.url.replace("&", "&"); } return def; } catch (ActionNotFoundException e) { throw new NoRouteFoundException(action, null); } } catch (Exception e) { if (e instanceof PlayException) { throw (PlayException) e; } throw new UnexpectedException(e); } }
// // NOTE: This file was generated from: japidviews/_tags/SampleTag.html // Change to this file will be lost next time the template file is compiled. // @cn.bran.play.NoEnhance public class SampleTag extends cn.bran.japid.template.JapidTemplateBase { public static final String sourceTemplate = "japidviews/_tags/SampleTag.html"; { headers.put("Content-Type", "text/html; charset=utf-8"); } // - add implicit fields with Play final Request request = Request.current(); final Response response = Response.current(); final Session session = Session.current(); final RenderArgs renderArgs = RenderArgs.current(); final Params params = Params.current(); final Validation validation = Validation.current(); final cn.bran.play.FieldErrors errors = new cn.bran.play.FieldErrors(validation); final play.Play _play = new play.Play(); // - end of implicit fields with Play public SampleTag() { super(null); } public SampleTag(StringBuilder out) { super(out); } private String a; public cn.bran.japid.template.RenderResult render(String a) { this.a = a; long t = -1; super.layout(); return new cn.bran.japid.template.RenderResult(this.headers, getOut(), t); } @Override protected void doLayout() { // ------ ; // line 1 p("Hi "); // line 1 p(a); // line 2 p("!\n"); // line 2 } }
// // NOTE: This file was generated from: japidviews/more/MyController/myLayout.html // Change to this file will be lost next time the template file is compiled. // @cn.bran.play.NoEnhance public abstract class myLayout extends cn.bran.japid.template.JapidTemplateBase { public static final String sourceTemplate = "japidviews/more/MyController/myLayout.html"; { putHeader("Content-Type", "text/html; charset=utf-8"); } // - add implicit fields with Play final Request request = Request.current(); final Response response = Response.current(); final Session session = Session.current(); final RenderArgs renderArgs = RenderArgs.current(); final Params params = Params.current(); final Validation validation = Validation.current(); final cn.bran.play.FieldErrors errors = new cn.bran.play.FieldErrors(validation); final play.Play _play = new play.Play(); // - end of implicit fields with Play public myLayout() { super(null); } public myLayout(StringBuilder out) { super(out); } @Override public void layout() { p("<p>"); // line 1 title(); // line 1 p("</p>\n" + "<p>"); // line 1 side(); // line 2 p("</p>\n" + "<p>\n"); // line 2 doLayout(); // line 4 p("</p>"); // line 4 } protected void title() {}; protected void side() {}; protected abstract void doLayout(); }
/** * Parses the playframework action expressions. The string inside "()" is evaluated by OGNL in the * current context. * * @param arguments * @param attributeValue e.g. "Application.show(obj.id)" * @return parsed action path */ @SuppressWarnings("unchecked") static String toActionString(final Arguments arguments, String attributeValue) { Matcher matcher = PARAM_PATTERN.matcher(attributeValue); if (!matcher.matches()) { return Router.reverse(attributeValue).toString(); } String exp = matcher.group(1); if (StringUtils.isBlank(exp)) { return Router.reverse(attributeValue).toString(); } Object obj = PlayOgnlVariableExpressionEvaluator.INSTANCE.evaluate( arguments.getConfiguration(), arguments, exp, false); if (obj instanceof Map) { return Router.reverse(attributeValue, (Map<String, Object>) obj).toString(); } List<?> list = obj instanceof List ? (List<?>) obj : Arrays.asList(obj); Map<String, Object> paramMap = new HashMap<String, Object>(); String extracted = StringUtils.substringBefore(attributeValue, "("); if (!extracted.contains(".")) { extracted = Request.current().controller + "." + extracted; } Object[] actionMethods = ActionInvoker.getActionMethod(extracted); String[] paramNames = null; try { paramNames = Java.parameterNames((Method) actionMethods[1]); } catch (Exception e) { throw new RuntimeException(e); } if (paramNames.length < list.size()) { Logger.warn("param length unmatched. %s", Arrays.toString(paramNames)); throw new ActionNotFoundException(attributeValue, null); } for (int i = 0; i < list.size(); i++) { paramMap.put(paramNames[i], list.get(i)); } return Router.reverse(extracted, paramMap).toString(); }
@Override protected void service( HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws ServletException, IOException { if (!routerInitializedWithContext) { // Reload the rules, but this time with the context. Not really efficient through... // Servlet 2.4 does not allow you to get the context path from the servletcontext... loadRouter(httpServletRequest.getContextPath()); } Logger.trace("ServletWrapper>service " + httpServletRequest.getRequestURI()); Request request = null; try { Response response = new Response(); response.out = new ByteArrayOutputStream(); Response.current.set(response); request = parseRequest(httpServletRequest); Logger.trace("ServletWrapper>service, request: " + request); boolean raw = false; for (PlayPlugin plugin : Play.plugins) { if (plugin.rawInvocation(request, response)) { raw = true; break; } } if (raw) { copyResponse( Request.current(), Response.current(), httpServletRequest, httpServletResponse); } else { Invoker.invokeInThread( new ServletInvocation(request, response, httpServletRequest, httpServletResponse)); } } catch (NotFound e) { Logger.trace("ServletWrapper>service, NotFound: " + e); serve404(httpServletRequest, httpServletResponse, e); return; } catch (RenderStatic e) { Logger.trace("ServletWrapper>service, RenderStatic: " + e); serveStatic(httpServletResponse, httpServletRequest, e); return; } catch (Throwable e) { throw new ServletException(e); } }
public static String template() { // the super.template() class uses current request object to determine // the caller and method to find the matching template // this won't work if the current method is called from another action. // let's fall back to use the stack trace to deduce the template. // String caller2 = StackTraceUtils.getCaller2(); final StackTraceElement[] stes = new Throwable().getStackTrace(); // let's iterate back in the stacktrace to find the recent action calls. for (StackTraceElement st : stes) { String controller = st.getClassName(); String action = st.getMethodName(); ApplicationClass conAppClass = Play.classes.getApplicationClass(controller); if (conAppClass != null) { Class controllerClass = conAppClass.javaClass; if (JapidController2.class.isAssignableFrom(controllerClass)) { Method actionMethod = /* Java. */ findActionMethod(action, controllerClass); if (actionMethod != null) { String expr = controller + "." + action; // content negotiation String format = Request.current().format; if ("html".equals(format)) { return expr; } else { String expr_format = expr + "_" + format; if (expr_format.startsWith("controllers.")) { expr_format = "japidviews" + expr_format.substring(expr_format.indexOf('.')); } RendererClass rc = JapidPlayRenderer.japidClasses.get(expr_format); if (rc != null) return expr_format; else { // fall back return expr; } } } } } } throw new RuntimeException( "The calling stack does not contain a valid controller. Should not have happended..."); }
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 ?)"); } }
public void serveStatic( RenderStatic renderStatic, ChannelHandlerContext ctx, Request request, Response response, HttpRequest nettyRequest, MessageEvent e) { Logger.trace("serveStatic: begin"); HttpResponse nettyResponse = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.valueOf(response.status)); if (exposePlayServer) { nettyResponse.setHeader(SERVER, signature); } try { VirtualFile file = Play.getVirtualFile(renderStatic.file); if (file != null && file.exists() && file.isDirectory()) { file = file.child("index.html"); if (file != null) { renderStatic.file = file.relativePath(); } } if ((file == null || !file.exists())) { serve404( new NotFound("The file " + renderStatic.file + " does not exist"), ctx, request, nettyRequest); } else { boolean raw = false; for (PlayPlugin plugin : Play.plugins) { if (plugin.serveStatic(file, Request.current(), Response.current())) { raw = true; break; } } if (raw) { copyResponse(ctx, request, response, nettyRequest); } else { final File localFile = file.getRealFile(); final boolean keepAlive = isKeepAlive(nettyRequest); nettyResponse = addEtag(nettyRequest, nettyResponse, localFile); if (nettyResponse.getStatus().equals(HttpResponseStatus.NOT_MODIFIED)) { Channel ch = e.getChannel(); // Write the initial line and the header. ChannelFuture writeFuture = ch.write(nettyResponse); if (!keepAlive) { // Write the content. writeFuture.addListener(ChannelFutureListener.CLOSE); } } else { final RandomAccessFile raf = new RandomAccessFile(localFile, "r"); try { long fileLength = raf.length(); Logger.trace("keep alive " + keepAlive); Logger.trace( "content type " + (MimeTypes.getContentType(localFile.getName(), "text/plain"))); if (keepAlive && !nettyResponse.getStatus().equals(HttpResponseStatus.NOT_MODIFIED)) { // Add 'Content-Length' header only for a keep-alive connection. Logger.trace("file length " + fileLength); setContentLength(nettyResponse, fileLength); } nettyResponse.setHeader( CONTENT_TYPE, (MimeTypes.getContentType(localFile.getName(), "text/plain"))); Channel ch = e.getChannel(); // Write the initial line and the header. ChannelFuture writeFuture = ch.write(nettyResponse); // Write the content. if (!nettyRequest.getMethod().equals(HttpMethod.HEAD)) { writeFuture = ch.write(new ChunkedFile(raf, 0, fileLength, 8192)); } else { raf.close(); } if (!keepAlive) { // Close the connection when the whole content is written out. writeFuture.addListener(ChannelFutureListener.CLOSE); } } catch (Throwable exx) { try { raf.close(); } catch (Throwable ex) { /* Left empty */ } try { ctx.getChannel().close(); } catch (Throwable ex) { /* Left empty */ } } } } } } catch (Throwable ez) { Logger.error(ez, "serveStatic for request %s", request.method + " " + request.url); try { HttpResponse errorResponse = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.INTERNAL_SERVER_ERROR); ChannelBuffer buf = ChannelBuffers.copiedBuffer("Internal Error (check logs)".getBytes("utf-8")); errorResponse.setContent(buf); ChannelFuture future = ctx.getChannel().write(errorResponse); future.addListener(ChannelFutureListener.CLOSE); } catch (Exception ex) { Logger.error(ez, "serveStatic for request %s", request.method + " " + request.url); } } Logger.trace("serveStatic: end"); }
public Response retrieveAccessToken() { return retrieveAccessToken(Request.current().getBase() + Request.current().url); }
public void retrieveVerificationCode() { retrieveVerificationCode(Request.current().getBase() + Request.current().url); }
// // NOTE: This file was generated from: japidviews/_tags/picka.html // Change to this file will be lost next time the template file is compiled. // @cn.bran.play.NoEnhance public class picka extends cn.bran.japid.template.JapidTemplateBase { public static final String sourceTemplate = "japidviews/_tags/picka.html"; { putHeader("Content-Type", "text/html; charset=utf-8"); } // - add implicit fields with Play final Request request = Request.current(); final Response response = Response.current(); final Session session = Session.current(); final RenderArgs renderArgs = RenderArgs.current(); final Params params = Params.current(); final Validation validation = Validation.current(); final cn.bran.play.FieldErrors errors = new cn.bran.play.FieldErrors(validation); final play.Play _play = new play.Play(); // - end of implicit fields with Play public picka() { super(null); } public picka(StringBuilder out) { super(out); } /* based on https://github.com/branaway/Japid/issues/12 */ public static final String[] argNames = new String[] { /* args of the template*/ "a", "b", }; public static final String[] argTypes = new String[] { /* arg types of the template*/ "String", "String", }; public static final Object[] argDefaults = new Object[] { null, null, }; public static java.lang.reflect.Method renderMethod = getRenderMethod(japidviews._tags.picka.class); { setRenderMethod(renderMethod); setArgNames(argNames); setArgTypes(argTypes); setArgDefaults(argDefaults); } ////// end of named args stuff private String a; private String b; public cn.bran.japid.template.RenderResult render( DoBody body, cn.bran.japid.compiler.NamedArgRuntime... named) { Object[] args = buildArgs(named, body); return runRenderer(args); } private DoBody body; public static interface DoBody<A> { void render(A a); } public cn.bran.japid.template.RenderResult render(String a, String b, DoBody body) { this.body = body; this.a = a; this.b = b; long t = -1; super.layout(); return new cn.bran.japid.template.RenderResultPartial(getHeaders(), getOut(), t, actionRunners); } @Override protected void doLayout() { // ------ ; // line 1 p("<p>\n" + "some text \n" + "</p>\n" + "<p>\n"); // line 1 if (body != null) body.render(a + b); p("</p>\n" + "<p>\n" + "more text \n" + "</p>\n" + " "); // line 6 } }
public boolean verify() { try { // Normalize String claimedId = normalize(id); String server = null; String delegate = null; // Discover HttpResponse response = WS.url(claimedId).get(); // Try HTML (I know it's bad) String html = response.getString(); server = discoverServer(html); if (server == null) { // Try YADIS Document xrds = null; if (response.getContentType().contains("application/xrds+xml")) { xrds = getXml(html, response.getEncoding()); } else if (response.getHeader("X-XRDS-Location") != null) { xrds = WS.url(response.getHeader("X-XRDS-Location")).get().getXml(); } else { return false; } // Ok we have the XRDS file server = XPath.selectText( "//Type[text()='http://specs.openid.net/auth/2.0/server']/following-sibling::URI/text()", xrds); claimedId = XPath.selectText( "//Type[text()='http://specs.openid.net/auth/2.0/signon']/following-sibling::LocalID/text()", xrds); if (claimedId == null) { claimedId = "http://specs.openid.net/auth/2.0/identifier_select"; } else { server = XPath.selectText( "//Type[text()='http://specs.openid.net/auth/2.0/signon']/following-sibling::URI/text()", xrds); } if (server == null) { return false; } } else { // Delegate Matcher openid2Localid = Pattern.compile("<link[^>]+openid2[.]local_id[^>]+>", Pattern.CASE_INSENSITIVE) .matcher(html); Matcher openidDelegate = Pattern.compile("<link[^>]+openid[.]delegate[^>]+>", Pattern.CASE_INSENSITIVE) .matcher(html); if (openid2Localid.find()) { delegate = extractHref(openid2Localid.group()); } else if (openidDelegate.find()) { delegate = extractHref(openidDelegate.group()); } } // Redirect String url = server; if (!server.contains("?")) { url += "?"; } if (!url.endsWith("?") && !url.endsWith("&")) { url += "&"; } url += "openid.ns=" + URLEncoder.encode("http://specs.openid.net/auth/2.0", "UTF-8"); url += "&openid.mode=checkid_setup"; url += "&openid.claimed_id=" + URLEncoder.encode(claimedId, "utf8"); url += "&openid.identity=" + URLEncoder.encode(delegate == null ? claimedId : delegate, "utf8"); if (returnAction != null && (returnAction.startsWith("http://") || returnAction.startsWith("https://"))) { url += "&openid.return_to=" + URLEncoder.encode(returnAction, "utf8"); } else { url += "&openid.return_to=" + URLEncoder.encode( Request.current().getBase() + Router.reverse(returnAction), "utf8"); } if (realmAction != null && (realmAction.startsWith("http://") || realmAction.startsWith("https://"))) { url += "&openid.realm=" + URLEncoder.encode(realmAction, "utf8"); } else { url += "&openid.realm=" + URLEncoder.encode( Request.current().getBase() + Router.reverse(realmAction), "utf8"); } if (!sregOptional.isEmpty() || !sregRequired.isEmpty()) { url += "&openid.ns.sreg=" + URLEncoder.encode("http://openid.net/extensions/sreg/1.1", "UTF-8"); } String sregO = ""; for (String a : sregOptional) { sregO += URLEncoder.encode(a, "UTF-8") + ","; } if (!StringUtils.isEmpty(sregO)) { url += "&openid.sreg.optional=" + sregO.substring(0, sregO.length() - 1); } String sregR = ""; for (String a : sregRequired) { sregR += URLEncoder.encode(a, "UTF-8") + ","; } if (!StringUtils.isEmpty(sregR)) { url += "&openid.sreg.required=" + sregR.substring(0, sregR.length() - 1); } if (!axRequired.isEmpty() || !axOptional.isEmpty()) { url += "&openid.ns.ax=http%3A%2F%2Fopenid.net%2Fsrv%2Fax%2F1.0"; url += "&openid.ax.mode=fetch_request"; for (String a : axOptional.keySet()) { url += "&openid.ax.type." + a + "=" + URLEncoder.encode(axOptional.get(a), "UTF-8"); } for (String a : axRequired.keySet()) { url += "&openid.ax.type." + a + "=" + URLEncoder.encode(axRequired.get(a), "UTF-8"); } if (!axRequired.isEmpty()) { String r = ""; for (String a : axRequired.keySet()) { r += "," + a; } r = r.substring(1); url += "&openid.ax.required=" + r; } if (!axOptional.isEmpty()) { String r = ""; for (String a : axOptional.keySet()) { r += "," + a; } r = r.substring(1); url += "&openid.ax.if_available=" + r; } } if (Logger.isTraceEnabled()) { // Debug Logger.trace("Send request %s", url); } throw new Redirect(url); } catch (Redirect e) { throw e; } catch (PlayException e) { throw e; } catch (Exception e) { return false; } }
private OpenID(String id) { this.id = id; this.returnAction = this.realmAction = Request.current().action; }
public void serve500(Exception e, HttpServletRequest request, HttpServletResponse response) { try { Map<String, Object> binding = new HashMap<String, Object>(); if (!(e instanceof PlayException)) { e = new play.exceptions.UnexpectedException(e); } // Flush some cookies try { Map<String, Http.Cookie> cookies = Response.current().cookies; for (Http.Cookie cookie : cookies.values()) { if (cookie.sendOnError) { Cookie c = new Cookie(cookie.name, cookie.value); c.setSecure(cookie.secure); c.setPath(cookie.path); if (cookie.domain != null) { c.setDomain(cookie.domain); } response.addCookie(c); } } } catch (Exception exx) { // humm ? } binding.put("exception", 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) { // } response.setStatus(500); String format = "html"; if (Request.current() != null) { format = Request.current().format; } // 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("500." + format, "text/plain")); try { String errorHtml = TemplateLoader.load("errors/500." + format).render(binding); response.getOutputStream().write(errorHtml.getBytes(Response.current().encoding)); Logger.error(e, "Internal Server Error (500)"); } catch (Throwable ex) { Logger.error(e, "Internal Server Error (500)"); Logger.error(ex, "Error during the 500 response generation"); throw ex; } } catch (Throwable exxx) { if (exxx instanceof RuntimeException) { throw (RuntimeException) exxx; } throw new RuntimeException(exxx); } }
/** * can be used to generate a key based on the query * * @return */ public static String genCacheKey() { return "japidcache:" + Request.current().action + ":" + Request.current().querystring; }
// // NOTE: This file was generated from: japidviews/templates/EachCall.html // Change to this file will be lost next time the template file is compiled. // @cn.bran.play.NoEnhance public class EachCall extends cn.bran.play.JapidTemplateBase { public static final String sourceTemplate = "japidviews/templates/EachCall.html"; { putHeader("Content-Type", "text/html; charset=utf-8"); setContentType("text/html; charset=utf-8"); } // - add implicit fields with Play final Request request = Request.current(); final Response response = Response.current(); final Session session = Session.current(); final RenderArgs renderArgs = RenderArgs.current(); final Params params = Params.current(); final Validation validation = Validation.current(); final cn.bran.play.FieldErrors errors = new cn.bran.play.FieldErrors(validation); final play.Play _play = new play.Play(); // - end of implicit fields with Play public EachCall() { super(null); } public EachCall(StringBuilder out) { super(out); } /* based on https://github.com/branaway/Japid/issues/12 */ public static final String[] argNames = new String[] { /* args of the template*/ "posts", }; public static final String[] argTypes = new String[] { /* arg types of the template*/ "List<String>", }; public static final Object[] argDefaults = new Object[] { null, }; public static java.lang.reflect.Method renderMethod = getRenderMethod(japidviews.templates.EachCall.class); { setRenderMethod(renderMethod); setArgNames(argNames); setArgTypes(argTypes); setArgDefaults(argDefaults); setSourceTemplate(sourceTemplate); } ////// end of named args stuff private List<String> posts; // line 1 public cn.bran.japid.template.RenderResult render(List<String> posts) { this.posts = posts; long t = -1; try { super.layout(); } catch (RuntimeException e) { super.handleException(e); } // line 1 return new cn.bran.japid.template.RenderResultPartial( getHeaders(), getOut(), t, actionRunners, sourceTemplate); } @Override protected void doLayout() { beginDoLayout(sourceTemplate); // ------ ; // line 1 p( "\n" + "<p>\n" + "The \"each/Each\" command is a for loop on steroid, with lots of loop information. \n" + "</p>\n" + "\n" + "<p> \n" + "The instance variable is defined after the | line, the same way as any tag render-back\n" + "</p>\n" + "\n"); // line 1 final Each _Each0 = new Each(getOut()); _Each0.setOut(getOut()); _Each0.render( // line 11 posts, new Each.DoBody<String>() { // line 11 public void render( final String p, final int _size, final int _index, final boolean _isOdd, final String _parity, final boolean _isFirst, final boolean _isLast) { // line 11 // line 11 p(" <p>index: "); // line 11 p(_index); // line 12 p(", parity: "); // line 12 p(_parity); // line 12 p(", is odd? "); // line 12 p(_isOdd); // line 12 p(", is first? "); // line 12 p(_isFirst); // line 12 p(", is last? "); // line 12 p(_isLast); // line 12 p(", total size: "); // line 12 p(_size); // line 12 p(" </p>\n" + " call a tag: "); // line 12 final SampleTag _SampleTag1 = new SampleTag(getOut()); _SampleTag1.setActionRunners(getActionRunners()).setOut(getOut()); _SampleTag1.render(p); // line 13// line 13 } StringBuilder oriBuffer; @Override public void setBuffer(StringBuilder sb) { oriBuffer = getOut(); setOut(sb); } @Override public void resetBuffer() { setOut(oriBuffer); } }); // line 11 p("\n"); // line 14 final SampleTag _SampleTag2 = new SampleTag(getOut()); _SampleTag2.setActionRunners(getActionRunners()).setOut(getOut()); _SampleTag2.render("end"); // line 16// line 16 p( "\n" + "<p> now we have an enhanced for loop (the \"open for loop\") that also makes all the loop properties available</p>\n" + "\n"); // line 16 int k = 1; // line 20 final Each _Each3 = new Each(getOut()); _Each3.setOut(getOut()); _Each3.render( // line 21 posts, new Each.DoBody<String>() { // line 21 public void render( final String p, final int _size, final int _index, final boolean _isOdd, final String _parity, final boolean _isFirst, final boolean _isLast) { // line 21 // line 21 p(" <p>index: "); // line 21 p(_index); // line 22 p(", parity: "); // line 22 p(_parity); // line 22 p(", is odd? "); // line 22 p(_isOdd); // line 22 p(", is first? "); // line 22 p(_isFirst); // line 22 p(", is last? "); // line 22 p(_isLast); // line 22 p(", total size: "); // line 22 p(_size); // line 22 p(" </p>\n" + " call a tag: "); // line 22 final SampleTag _SampleTag4 = new SampleTag(getOut()); _SampleTag4.setActionRunners(getActionRunners()).setOut(getOut()); _SampleTag4.render(p); // line 23// line 23 } StringBuilder oriBuffer; @Override public void setBuffer(StringBuilder sb) { oriBuffer = getOut(); setOut(sb); } @Override public void resetBuffer() { setOut(oriBuffer); } }); // line 21 p("\n" + "\n"); // line 24 int[] ints = {1, 2, 3}; // line 27 final Each _Each5 = new Each(getOut()); _Each5.setOut(getOut()); _Each5.render( // line 28 ints, new Each.DoBody<Integer>() { // line 28 public void render( final Integer i, final int _size, final int _index, final boolean _isOdd, final String _parity, final boolean _isFirst, final boolean _isLast) { // line 28 // line 28 p(" --> "); // line 28 p(escape(i)); // line 29 p("\n"); // line 29 } StringBuilder oriBuffer; @Override public void setBuffer(StringBuilder sb) { oriBuffer = getOut(); setOut(sb); } @Override public void resetBuffer() { setOut(oriBuffer); } }); // line 28 ; // line 30 endDoLayout(sourceTemplate); } }
// // NOTE: This file was generated from: japidviews/Application/search.html // Change to this file will be lost next time the template file is compiled. // @cn.bran.play.NoEnhance public class search extends cn.bran.japid.template.JapidTemplateBase { public static final String sourceTemplate = "japidviews/Application/search.html"; { putHeader("Content-Type", "text/html; charset=utf-8"); } // - add implicit fields with Play final Request request = Request.current(); final Response response = Response.current(); final Session session = Session.current(); final RenderArgs renderArgs = RenderArgs.current(); final Params params = Params.current(); final Validation validation = Validation.current(); final cn.bran.play.FieldErrors errors = new cn.bran.play.FieldErrors(validation); final play.Play _play = new play.Play(); // - end of implicit fields with Play public search() { super(null); } public search(StringBuilder out) { super(out); } /* based on https://github.com/branaway/Japid/issues/12 */ public static final String[] argNames = new String[] { /* args of the template*/ "sp", }; public static final String[] argTypes = new String[] { /* arg types of the template*/ "SearchParams", }; public static final Object[] argDefaults = new Object[] { null, }; public static java.lang.reflect.Method renderMethod = getRenderMethod(japidviews.Application.search.class); { setRenderMethod(renderMethod); setArgNames(argNames); setArgTypes(argTypes); setArgDefaults(argDefaults); } ////// end of named args stuff private SearchParams sp; public cn.bran.japid.template.RenderResult render(SearchParams sp) { this.sp = sp; long t = -1; super.layout(); return new cn.bran.japid.template.RenderResultPartial(getHeaders(), getOut(), t, actionRunners); } @Override protected void doLayout() { // ------ ; // line 1 p("\n" + "\n" + "keys: "); // line 1 try { Object o = sp.keywords; if (o.toString().length() == 0) { p("没有 keywords"); } else { p(o); } } catch (NullPointerException npe) { p("没有 keywords"); } // line 3 p(", mode: "); // line 3 try { Object o = sp.mode; if (o.toString().length() == 0) { p("no mode"); } else { p(o); } } catch (NullPointerException npe) { p("no mode"); } // line 3 p("\n" + "\n" + "true/false: "); // line 3 p(true ? "class=\"someclass\"" : ""); // line 5 ; // line 5 } }
// // NOTE: This file was generated from: japidviews/templates/AllPost2.html // Change to this file will be lost next time the template file is compiled. // @cn.bran.play.NoEnhance public class AllPost2 extends Layout { public static final String sourceTemplate = "japidviews/templates/AllPost2.html"; { putHeader("Content-Type", "text/html; charset=utf-8"); setContentType("text/html; charset=utf-8"); } // - add implicit fields with Play final Request request = Request.current(); final Response response = Response.current(); final Session session = Session.current(); final RenderArgs renderArgs = RenderArgs.current(); final Params params = Params.current(); final Validation validation = Validation.current(); final cn.bran.play.FieldErrors errors = new cn.bran.play.FieldErrors(validation); final play.Play _play = new play.Play(); // - end of implicit fields with Play public AllPost2() { super(null); } public AllPost2(StringBuilder out) { super(out); } /* based on https://github.com/branaway/Japid/issues/12 */ public static final String[] argNames = new String[] { /* args of the template*/ "blogTitle", "allPost", }; public static final String[] argTypes = new String[] { /* arg types of the template*/ "String", "List<Post>", }; public static final Object[] argDefaults = new Object[] { null, null, }; public static java.lang.reflect.Method renderMethod = getRenderMethod(japidviews.templates.AllPost2.class); { setRenderMethod(renderMethod); setArgNames(argNames); setArgTypes(argTypes); setArgDefaults(argDefaults); setSourceTemplate(sourceTemplate); } ////// end of named args stuff private String blogTitle; // line 3 private List<Post> allPost; // line 3 public cn.bran.japid.template.RenderResult render(String blogTitle, List<Post> allPost) { this.blogTitle = blogTitle; this.allPost = allPost; long t = -1; try { super.layout(); } catch (RuntimeException e) { super.handleException(e); } // line 3 return new cn.bran.japid.template.RenderResultPartial( getHeaders(), getOut(), t, actionRunners, sourceTemplate); } @Override protected void doLayout() { beginDoLayout(sourceTemplate); // ------ ; // line 1 p("\n"); // line 3 p("\n" + "\n"); // line 5 if (allPost.size() > 0) { // line 8 p(" <p></p>\n" + " "); // line 8 for (Post p : allPost) { // line 10 p(" "); // line 10 final Display _Display1 = new Display(getOut()); _Display1.setActionRunners(getActionRunners()).setOut(getOut()); _Display1.render( // line 11 new Display.DoBody<String>() { // line 11 public void render(final String title) { // line 11 // line 11 p(" <p>The real title is: "); // line 11 p(title); // line 12 p(";</p>\n" + " "); // line 12 } StringBuilder oriBuffer; @Override public void setBuffer(StringBuilder sb) { oriBuffer = getOut(); setOut(sb); } @Override public void resetBuffer() { setOut(oriBuffer); } }, named("post", p), named("as", "home")); // line 11 p(" "); // line 13 } // line 14 } else { // line 15 p(" <p>There is no post at this moment</p>\n"); // line 15 } // line 17 p("\n"); // line 17 final Tag2 _Tag22 = new Tag2(getOut()); _Tag22.setActionRunners(getActionRunners()).setOut(getOut()); _Tag22.render(named("msg", blogTitle), named("age", 1000)); // line 19// line 19 p("\n" + "<p>end of it</p>"); // line 19 endDoLayout(sourceTemplate); } @Override protected void title() { p("Home"); ; } }
// TODO: add request and response as parameter public static void serve500(Exception e, ChannelHandlerContext ctx, HttpRequest nettyRequest) { Logger.trace("serve500: begin"); HttpResponse nettyResponse = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.INTERNAL_SERVER_ERROR); if (exposePlayServer) { nettyResponse.setHeader(SERVER, signature); } Request request = Request.current(); Response response = Response.current(); try { if (!(e instanceof PlayException)) { e = new play.exceptions.UnexpectedException(e); } // Flush some cookies try { Map<String, Http.Cookie> cookies = response.cookies; for (Http.Cookie cookie : cookies.values()) { CookieEncoder encoder = new CookieEncoder(true); Cookie c = new DefaultCookie(cookie.name, cookie.value); c.setSecure(cookie.secure); c.setPath(cookie.path); if (cookie.domain != null) { c.setDomain(cookie.domain); } if (cookie.maxAge != null) { c.setMaxAge(cookie.maxAge); } c.setHttpOnly(cookie.httpOnly); encoder.addCookie(c); nettyResponse.addHeader(SET_COOKIE, encoder.encode()); } } catch (Exception exx) { Logger.error(e, "Trying to flush cookies"); // humm ? } Map<String, Object> binding = getBindingForErrors(e, true); String format = request.format; if (format == null) { format = "txt"; } nettyResponse.setHeader( "Content-Type", (MimeTypes.getContentType("500." + format, "text/plain"))); try { String errorHtml = TemplateLoader.load("errors/500." + format).render(binding); ChannelBuffer buf = ChannelBuffers.copiedBuffer(errorHtml.getBytes("utf-8")); nettyResponse.setContent(buf); ChannelFuture writeFuture = ctx.getChannel().write(nettyResponse); writeFuture.addListener(ChannelFutureListener.CLOSE); Logger.error( e, "Internal Server Error (500) for request %s", request.method + " " + request.url); } catch (Throwable ex) { Logger.error( e, "Internal Server Error (500) for request %s", request.method + " " + request.url); Logger.error(ex, "Error during the 500 response generation"); try { ChannelBuffer buf = ChannelBuffers.copiedBuffer("Internal Error (check logs)".getBytes("utf-8")); nettyResponse.setContent(buf); ChannelFuture writeFuture = ctx.getChannel().write(nettyResponse); writeFuture.addListener(ChannelFutureListener.CLOSE); } catch (UnsupportedEncodingException fex) { Logger.error(fex, "(utf-8 ?)"); } } } catch (Throwable exxx) { try { ChannelBuffer buf = ChannelBuffers.copiedBuffer("Internal Error (check logs)".getBytes("utf-8")); nettyResponse.setContent(buf); ChannelFuture writeFuture = ctx.getChannel().write(nettyResponse); writeFuture.addListener(ChannelFutureListener.CLOSE); } catch (Exception fex) { Logger.error(fex, "(utf-8 ?)"); } if (exxx instanceof RuntimeException) { throw (RuntimeException) exxx; } throw new RuntimeException(exxx); } Logger.trace("serve500: end"); }
// // NOTE: This file was generated from: japidviews/_tags/paramWithDefaults.html // Change to this file will be lost next time the template file is compiled. // @cn.bran.play.NoEnhance public class paramWithDefaults extends cn.bran.play.JapidTemplateBase { public static final String sourceTemplate = "japidviews/_tags/paramWithDefaults.html"; { putHeader("Content-Type", "text/html; charset=utf-8"); setContentType("text/html; charset=utf-8"); } // - add implicit fields with Play final Request request = Request.current(); final Response response = Response.current(); final Session session = Session.current(); final RenderArgs renderArgs = RenderArgs.current(); final Params params = Params.current(); final Validation validation = Validation.current(); final cn.bran.play.FieldErrors errors = new cn.bran.play.FieldErrors(validation); final play.Play _play = new play.Play(); // - end of implicit fields with Play public paramWithDefaults() { super(null); } public paramWithDefaults(StringBuilder out) { super(out); } /* based on https://github.com/branaway/Japid/issues/12 */ public static final String[] argNames = new String[] { /* args of the template*/ "msg", "m2", "age", }; public static final String[] argTypes = new String[] { /* arg types of the template*/ "String", "String", "Integer", }; public static final Object[] argDefaults = new Object[] { "message 1 default value", new String("m2message"), 20, }; public static java.lang.reflect.Method renderMethod = getRenderMethod(japidviews._tags.paramWithDefaults.class); { setRenderMethod(renderMethod); setArgNames(argNames); setArgTypes(argTypes); setArgDefaults(argDefaults); setSourceTemplate(sourceTemplate); } ////// end of named args stuff private String msg; // line 1 private String m2; // line 1 private Integer age; // line 1 public cn.bran.japid.template.RenderResult render(String msg, String m2, Integer age) { this.msg = msg; this.m2 = m2; this.age = age; long t = -1; try { super.layout(); } catch (RuntimeException e) { super.handleException(e); } // line 1 return new cn.bran.japid.template.RenderResultPartial( getHeaders(), getOut(), t, actionRunners, sourceTemplate); } @Override protected void doLayout() { beginDoLayout(sourceTemplate); // ------ ; // line 1 p("\n" + "<span>"); // line 5 p(msg); // line 6 p("</span>\n" + "<span>"); // line 6 p(m2); // line 7 p("</span>\n" + "<span>"); // line 7 p(age); // line 8 p("</span>\n" + "\n"); // line 8 endDoLayout(sourceTemplate); } }
// // NOTE: This file was generated from: japidviews/Application/decorateName.html // Change to this file will be lost next time the template file is compiled. // @cn.bran.play.NoEnhance public class decorateName extends cn.bran.play.JapidTemplateBase { public static final String sourceTemplate = "japidviews/Application/decorateName.html"; { putHeader("Content-Type", "text/html; charset=utf-8"); } // - add implicit fields with Play final Request request = Request.current(); final Response response = Response.current(); final Session session = Session.current(); final RenderArgs renderArgs = RenderArgs.current(); final Params params = Params.current(); final Validation validation = Validation.current(); final cn.bran.play.FieldErrors errors = new cn.bran.play.FieldErrors(validation); final play.Play _play = new play.Play(); // - end of implicit fields with Play public decorateName() { super(null); } public decorateName(StringBuilder out) { super(out); } /* based on https://github.com/branaway/Japid/issues/12 */ public static final String[] argNames = new String[] { /* args of the template*/ "s", }; public static final String[] argTypes = new String[] { /* arg types of the template*/ "String", }; public static final Object[] argDefaults = new Object[] { null, }; public static java.lang.reflect.Method renderMethod = getRenderMethod(japidviews.Application.decorateName.class); { setRenderMethod(renderMethod); setArgNames(argNames); setArgTypes(argTypes); setArgDefaults(argDefaults); setSourceTemplate(sourceTemplate); } ////// end of named args stuff private String s; public cn.bran.japid.template.RenderResult render(String s) { this.s = s; long t = -1; try { super.layout(); } catch (RuntimeException e) { super.handleException(e); } return new cn.bran.japid.template.RenderResultPartial(getHeaders(), getOut(), t, actionRunners); } @Override protected void doLayout() { // ------ ; // line 1 p("\n" + "^^^_ "); // line 1 p(s); // line 3 p(" _^^^\n"); // line 3 } }
static Object invokeWithContinuation(Method method, Object instance, Object[] realArgs) throws Exception { // Callback case if (Http.Request.current().args.containsKey(A)) { // Action0 instance = Http.Request.current().args.get(A); Future f = (Future) Http.Request.current().args.get(F); Scope.RenderArgs renderArgs = (Scope.RenderArgs) Request.current().args.remove(ActionInvoker.CONTINUATIONS_STORE_RENDER_ARGS); Scope.RenderArgs.current.set(renderArgs); if (f == null) { method = instance.getClass().getDeclaredMethod("invoke"); method.setAccessible(true); return method.invoke(instance); } else { method = instance.getClass().getDeclaredMethod("invoke", Object.class); method.setAccessible(true); return method.invoke(instance, f.get()); } } // Continuations case Continuation continuation = (Continuation) Http.Request.current().args.get(C); if (continuation == null) { continuation = new Continuation(new StackRecorder((Runnable) null)); } StackRecorder pStackRecorder = new StackRecorder(continuation.stackRecorder); Object result = null; final StackRecorder old = pStackRecorder.registerThread(); try { pStackRecorder.isRestoring = !pStackRecorder.isEmpty(); // Execute code result = method.invoke(instance, realArgs); if (pStackRecorder.isCapturing) { if (pStackRecorder.isEmpty()) { throw new IllegalStateException( "stack corruption. Is " + method + " instrumented for javaflow?"); } Object trigger = pStackRecorder.value; Continuation nextContinuation = new Continuation(pStackRecorder); Http.Request.current().args.put(C, nextContinuation); if (trigger instanceof Long) { throw new Suspend((Long) trigger); } if (trigger instanceof Integer) { throw new Suspend(((Integer) trigger).longValue()); } if (trigger instanceof Future) { throw new Suspend((Future) trigger); } throw new UnexpectedException("Unexpected continuation trigger -> " + trigger); } else { Http.Request.current().args.remove(C); } } finally { pStackRecorder.deregisterThread(old); } return result; }