Search in sources :

Example 1 with Header

use of play.mvc.Http.Header in project Japid by branaway.

the class JapidPlugin method dumpRequest.

private void dumpRequest(Request req) throws UnsupportedEncodingException, IOException {
    String querystring = req.querystring;
    if (querystring != null && querystring.length() > 0)
        querystring = "?" + querystring;
    else
        querystring = "";
    System.out.println("---->>" + req.method + " : " + req.url + querystring);
    String contentType = req.contentType;
    if (contentType == null || contentType.length() == 0) {
        contentType = "";
    }
    for (String k : req.headers.keySet()) {
        Header h = req.headers.get(k);
        System.out.println("... " + h.name + ":" + URLDecoder.decode(h.value(), "utf-8"));
    }
    // }
    if ("POST".equals(req.method) || "PUT".equals(req.method)) {
        if (contentType.contains("application/x-www-form-urlencoded")) {
            dumpReqBody(req, true);
        } else if (contentType.startsWith("text")) {
            dumpReqBody(req, false);
        } else if (contentType.contains("multipart/form-data")) {
        // cannot dump it, since it may contain binary
        } else if (contentType.contains("xml")) {
            dumpReqBody(req, false);
        } else if (contentType.contains("javascript")) {
            dumpReqBody(req, false);
        }
    }
}
Also used : Header(play.mvc.Http.Header)

Example 2 with Header

use of play.mvc.Http.Header in project Japid by branaway.

the class JapidPlugin method beforeActionInvocation.

/**
	 * just before an action is invoked. See {@code ActionInvoker}
	 */
@Override
public void beforeActionInvocation(Method actionMethod) {
    //		logDuration("beforeActionInvocation");
    final String actionName = actionMethod.getDeclaringClass().getName() + "." + actionMethod.getName();
    JapidController.threadData.get().put(ACTION_METHOD, actionName);
    String property = Play.configuration.getProperty("japid.dump.request");
    if (property != null && property.length() > 0) {
        if (!"false".equals(property) && !"no".equals(property)) {
            if ("yes".equals(property) || "true".equals(property)) {
                System.out.println("--- action ->: " + Request.current().action);
            } else if (Request.current().url.matches(property)) {
                System.out.println("--- action ->: " + Request.current().action);
            }
        }
    }
    String string = Flash.current().get(RenderResultCache.READ_THRU_FLASH);
    if (string != null) {
        RenderResultCache.setIgnoreCache(true);
    } else {
        // cache-control in lower case, lowercase for some reason
        Header header = Request.current().headers.get("cache-control");
        if (header != null) {
            List<String> list = header.values;
            if (list.contains(NO_CACHE)) {
                RenderResultCache.setIgnoreCache(true);
            }
        } else {
            header = Request.current().headers.get("pragma");
            if (header != null) {
                List<String> list = header.values;
                if (list.contains(NO_CACHE)) {
                    RenderResultCache.setIgnoreCache(true);
                }
            } else {
                // just in case
                RenderResultCache.setIgnoreCacheInCurrentAndNextReq(false);
            }
        }
    }
// // shortcut
// String path = Request.current().path;
// // System.out.println("request path:" + path);
// Matcher matcher = renderJapidWithPattern.matcher(path);
// if (matcher.matches()) {
// String template = matcher.group(1);
// JapidController.renderJapidWith(template);
// }
}
Also used : Header(play.mvc.Http.Header)

Example 3 with Header

use of play.mvc.Http.Header in project play-cookbook by spinscale.

the class CachingTest method testThatEtagCachingWorks.

@Test
public void testThatEtagCachingWorks() {
    Response response = GET("/etagCache/123");
    assertIsOk(response);
    assertContentEquals("Learn to use etags, dumbass!", response);
    Request request = newRequest();
    String etag = String.valueOf("123".hashCode());
    Header noneMatchHeader = new Header("if-none-match", etag);
    request.headers.put("if-none-match", noneMatchHeader);
    DateTime ago = new DateTime().minusHours(12);
    String agoStr = Utils.getHttpDateFormatter().format(ago.toDate());
    Header modifiedHeader = new Header("if-modified-since", agoStr);
    request.headers.put("if-modified-since", modifiedHeader);
    response = GET(request, "/etagCache/123");
    assertStatus(304, response);
}
Also used : Response(play.mvc.Http.Response) Header(play.mvc.Http.Header) Request(play.mvc.Http.Request) DateTime(org.joda.time.DateTime) FunctionalTest(play.test.FunctionalTest) Test(org.junit.Test)

Example 4 with Header

use of play.mvc.Http.Header in project play-cookbook by spinscale.

the class Application method checkAuth.

@Before(priority = 1, unless = { "createTicket", "quotes", "thing" })
public static void checkAuth() {
    Header ticket = request.headers.get("x-authorization");
    if (ticket == null) {
        error("Please provide a ticket");
    }
    String cacheTicket = Cache.get("ticket:" + ticket.value(), String.class);
    if (cacheTicket == null) {
        error("Please renew your ticket");
    }
    Cache.set("ticket:" + ticket.value(), cacheTicket, "5min");
}
Also used : Header(play.mvc.Http.Header) Before(play.mvc.Before)

Aggregations

Header (play.mvc.Http.Header)4 DateTime (org.joda.time.DateTime)1 Test (org.junit.Test)1 Before (play.mvc.Before)1 Request (play.mvc.Http.Request)1 Response (play.mvc.Http.Response)1 FunctionalTest (play.test.FunctionalTest)1