Java Code Examples for play.mvc.Http#Cookie
The following examples show how to use
play.mvc.Http#Cookie .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ValidationPlugin.java From restcommander with Apache License 2.0 | 6 votes |
static Validation restore() { try { Validation validation = new Validation(); Http.Cookie cookie = Http.Request.current().cookies.get(Scope.COOKIE_PREFIX + "_ERRORS"); if (cookie != null) { String errorsData = URLDecoder.decode(cookie.value, "utf-8"); Matcher matcher = errorsParser.matcher(errorsData); while (matcher.find()) { String[] g2 = matcher.group(2).split("\u0001"); String message = g2[0]; String[] args = new String[g2.length - 1]; System.arraycopy(g2, 1, args, 0, args.length); validation.errors.add(new Error(matcher.group(1), message, args)); } } return validation; } catch (Exception e) { return new Validation(); } }
Example 2
Source File: ServletWrapper.java From restcommander with Apache License 2.0 | 6 votes |
protected static Map<String, Http.Cookie> getCookies(HttpServletRequest httpServletRequest) { Map<String, Http.Cookie> cookies = new HashMap<String, Http.Cookie>(16); javax.servlet.http.Cookie[] cookiesViaServlet = httpServletRequest.getCookies(); if (cookiesViaServlet != null) { for (javax.servlet.http.Cookie cookie : cookiesViaServlet) { Http.Cookie playCookie = new Http.Cookie(); playCookie.name = cookie.getName(); playCookie.path = cookie.getPath(); playCookie.domain = cookie.getDomain(); playCookie.secure = cookie.getSecure(); playCookie.value = cookie.getValue(); playCookie.maxAge = cookie.getMaxAge(); cookies.put(playCookie.name, playCookie); } } return cookies; }
Example 3
Source File: FunctionalTest.java From restcommander with Apache License 2.0 | 5 votes |
public static void makeRequest(final Request request, final Response response) { final Future invocationResult = TestEngine.functionalTestsExecutor.submit(new Invoker.Invocation() { @Override public void execute() throws Exception { renderArgs.clear(); ActionInvoker.invoke(request, response); if(RenderArgs.current().data != null) { renderArgs.putAll(RenderArgs.current().data); } } @Override public InvocationContext getInvocationContext() { ActionInvoker.resolve(request, response); return new InvocationContext(Http.invocationType, request.invokedMethod.getAnnotations(), request.invokedMethod.getDeclaringClass().getAnnotations()); } }); try { invocationResult.get(30, TimeUnit.SECONDS); if (savedCookies == null) { savedCookies = new HashMap<String, Http.Cookie>(); } for(Map.Entry<String,Http.Cookie> e : response.cookies.entrySet()) { // If Max-Age is unset, browsers discard on exit; if // 0, they discard immediately. if(e.getValue().maxAge == null || e.getValue().maxAge > 0) { savedCookies.put(e.getKey(), e.getValue()); } } response.out.flush(); } catch (Exception ex) { throw new RuntimeException(ex); } }
Example 4
Source File: TracingFilterTest.java From skywalking with Apache License 2.0 | 4 votes |
@Override public Http.Cookie cookie(String s) { return null; }
Example 5
Source File: PlayGrizzlyAdapter.java From restcommander with Apache License 2.0 | 4 votes |
public static Request parseRequest(GrizzlyRequest grizzlyRequest) throws Exception { Request request = new Http.Request(); Request.current.set(request); URI uri = new URI(grizzlyRequest.getRequestURI()); request.method = grizzlyRequest.getMethod().intern(); request.path = uri.getPath(); request.querystring = grizzlyRequest.getQueryString() == null ? "" : grizzlyRequest.getQueryString(); Router.routeOnlyStatic(request); if (grizzlyRequest.getHeader("Content-Type") != null) { request.contentType = grizzlyRequest.getHeader("Content-Type").split(";")[0].trim().toLowerCase().intern(); } else { request.contentType = "text/html".intern(); } if (grizzlyRequest.getHeader("X-HTTP-Method-Override") != null) { request.method = grizzlyRequest.getHeader("X-HTTP-Method-Override").intern(); } request.body = grizzlyRequest.getInputStream(); request.secure = grizzlyRequest.isSecure(); request.url = uri.toString() + (grizzlyRequest.getQueryString() == null ? "" : "?" + grizzlyRequest.getQueryString()); request.host = grizzlyRequest.getHeader("host"); if (request.host.contains(":")) { request.port = Integer.parseInt(request.host.split(":")[1]); request.domain = request.host.split(":")[0]; } else { request.port = 80; request.domain = request.host; } request.remoteAddress = grizzlyRequest.getRemoteAddr(); if (Play.configuration.containsKey("XForwardedSupport") && grizzlyRequest.getHeader("X-Forwarded-For") != null) { if (!Arrays.asList(Play.configuration.getProperty("XForwardedSupport", "127.0.0.1").split(",")).contains(request.remoteAddress)) { throw new RuntimeException("This proxy request is not authorized"); } else { request.secure = ("https".equals(Play.configuration.get("XForwardedProto")) || "https".equals(grizzlyRequest.getHeader("X-Forwarded-Proto")) || "on".equals(grizzlyRequest.getHeader("X-Forwarded-Ssl"))); if (Play.configuration.containsKey("XForwardedHost")) { request.host = (String) Play.configuration.get("XForwardedHost"); } else if (grizzlyRequest.getHeader("X-Forwarded-Host") != null) { request.host = grizzlyRequest.getHeader("X-Forwarded-Host"); } if (grizzlyRequest.getHeader("X-Forwarded-For") != null) { request.remoteAddress = grizzlyRequest.getHeader("X-Forwarded-For"); } } } Enumeration headersNames = grizzlyRequest.getHeaderNames(); while (headersNames.hasMoreElements()) { Http.Header hd = new Http.Header(); hd.name = (String) headersNames.nextElement(); hd.values = new ArrayList<String>(); Enumeration enumValues = grizzlyRequest.getHeaders(hd.name); while (enumValues.hasMoreElements()) { String value = (String) enumValues.nextElement(); hd.values.add(value); } request.headers.put(hd.name.toLowerCase(), hd); } request.resolveFormat(); Cookie[] cookies = grizzlyRequest.getCookies(); if (cookies != null) { for (Cookie cookie : cookies) { Http.Cookie playCookie = new Http.Cookie(); playCookie.name = cookie.getName(); playCookie.path = cookie.getPath(); playCookie.domain = cookie.getDomain(); playCookie.secure = cookie.getSecure(); playCookie.value = cookie.getValue(); playCookie.maxAge = cookie.getMaxAge(); request.cookies.put(playCookie.name, playCookie); } } request._init(); return request; }