Java Code Examples for org.osgl.http.H#Request
The following examples show how to use
org.osgl.http.H#Request .
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: RouterTest.java From actframework with Apache License 2.0 | 5 votes |
private void _regExtTests(String pattern) { router.addMapping(GET, "/int/" + pattern, controller); H.Request req = Mockito.mock(H.Request.class); when(ctx.req()).thenReturn(req); when(req.path()).thenReturn("/int/33"); RequestHandler handler = router.getInvoker(GET, "/int/33", ctx); same(controller, handler); verify(ctx).urlPathParam("n", "33"); }
Example 2
Source File: RequestBodyParser.java From actframework with Apache License 2.0 | 5 votes |
public static RequestBodyParser get(H.Request req) { H.Format contentType = req.contentType(); RequestBodyParser parser = parsers.get(contentType); if (null == parser) { parser = TextParser.INSTANCE; } return parser; }
Example 3
Source File: ActionContext.java From actframework with Apache License 2.0 | 5 votes |
public ActionContext applyContentType() { ActResponse resp = resp(); H.Format lastContentType = resp.lastContentType(); if (null != lastContentType && !lastContentType.isSameTypeWith(UNKNOWN)) { resp.commitContentType(); return this; } H.Request req = req(); H.Format fmt = req.accept(); if (fmt.isSameTypeWith(UNKNOWN)) { fmt = req.contentType(); } applyContentType(fmt); return this; }
Example 4
Source File: DefaultSessionCodec.java From actframework with Apache License 2.0 | 5 votes |
@Override public H.Session decodeSession(String encodedSession, H.Request request) { H.Session session = new H.Session(); boolean newSession = true; if (S.notBlank(encodedSession)) { resolveFromCookieContent(session, encodedSession, true); newSession = false; } session = processExpiration(session, $.ms(), newSession, sessionWillExpire, ttlInMillis, pingPath, request); return session; }
Example 5
Source File: RequestHandlerProxy.java From actframework with Apache License 2.0 | 5 votes |
private void onResult(Result result, ActionContext context) { context.dissolve(); boolean isRenderAny = false; try { context.applyResultHashToEtag(); if (result instanceof RenderAny) { RenderAny any = (RenderAny) result; isRenderAny = true; any.apply(context); } else { H.Request req = context.req(); ActResponse<?> resp = context.prepareRespForResultEvaluation(); if (result instanceof ErrorResult) { // see https://github.com/actframework/actframework/issues/1034 H.Format fmt = contentTypeForErrorResult(req); req.accept(fmt); resp.contentType(fmt); } result.apply(req, resp); } } catch (RuntimeException e) { context.cacheTemplate(null); throw e; } finally { if (isRenderAny) { RenderAny.clearThreadLocals(); } } }
Example 6
Source File: RouterTest.java From actframework with Apache License 2.0 | 5 votes |
@Test public void searchDynamicUrl3() { router.addMapping(GET, "/svc/{<[0-9]{4}>id}-{name}", controller); router.addMapping(GET, "/svc/{<[0-9]{4}>sid}-{sname}/obj", controller); router.addMapping(GET, "/Persons/Joe/Parents;generations={gen}", controller); router.addMapping(GET, "/place/{latitude};{longitude}", controller); H.Request req = Mockito.mock(H.Request.class); when(ctx.req()).thenReturn(req); when(req.path()).thenReturn("/svc/1234-abc"); when(ctx.urlPath()).thenReturn(UrlPath.of("/svc/1234-abc")); router.getInvoker(GET, "/svc/1234-abc", ctx).handle(ctx); verify(ctx).urlPathParam("id", "1234"); verify(ctx).urlPathParam("name", "abc"); when(req.path()).thenReturn("/svc/1234-abc/obj"); when(ctx.urlPath()).thenReturn(UrlPath.of("/svc/1234-abc/obj")); router.getInvoker(GET, "/svc/1234-abc/obj", ctx).handle(ctx); verify(ctx).urlPathParam("sid", "1234"); verify(ctx).urlPathParam("sname", "abc"); when(req.path()).thenReturn("/Persons/Joe/Parents;generations=147"); when(ctx.urlPath()).thenReturn(UrlPath.of("/Persons/Joe/Parents;generations=147")); router.getInvoker(GET, "/Persons/Joe/Parents;generations=147", ctx).handle(ctx); verify(ctx).urlPathParam("gen", "147"); when(req.path()).thenReturn("/place/39.87381;-86.1399"); when(ctx.urlPath()).thenReturn(UrlPath.of("/place/39.87381;-86.1399")); router.getInvoker(GET, "/place/39.87381;-86.1399", ctx).handle(ctx); verify(ctx).urlPathParam("latitude", "39.87381"); verify(ctx).urlPathParam("longitude", "-86.1399"); }
Example 7
Source File: AppConfig.java From actframework with Apache License 2.0 | 5 votes |
private Provider<String> cookieDomainProvider() { if (null == cookieDomainProvider) { try { cookieDomainProvider = get(COOKIE_DOMAIN_PROVIDER, new Provider<String>() { @Override public String get() { return host(); } }); } catch (ConfigurationException e) { Object obj = helper.getValFromAliases(raw, COOKIE_DOMAIN_PROVIDER.key(), "impl", null); String s = obj.toString(); if ("dynamic".equalsIgnoreCase(s) || "flexible".equalsIgnoreCase(s) || "contextual".equalsIgnoreCase(s)) { cookieDomainProvider = new Provider<String>() { @Override public String get() { H.Request req = ActionContext.current().req(); return req.domain(); } }; return cookieDomainProvider; } throw e; } } return cookieDomainProvider; }
Example 8
Source File: Gh1104.java From actframework with Apache License 2.0 | 5 votes |
@GetAction("all") public Map<String, Iterable<String>> allHeaders(H.Request<?> req) { Map<String, Iterable<String>> map = new HashMap<>(); for (String name : req.headerNames()) { map.put(name, req.headers(name)); } return map; }
Example 9
Source File: ResultEvent.java From actframework with Apache License 2.0 | 4 votes |
public H.Request request() { return req; }
Example 10
Source File: GH354.java From actframework with Apache License 2.0 | 4 votes |
@ProvidesImplicitTemplateVariable("reqUrl") public static String url(H.Request request) { return request.url(); }
Example 11
Source File: Gh1104.java From actframework with Apache License 2.0 | 4 votes |
@GetAction public Iterable<String> test(H.Request<?> req) { return req.headerNames(); }
Example 12
Source File: RenderAny.java From actframework with Apache License 2.0 | 4 votes |
@Override public void apply(H.Request req, H.Response resp) { throw E.unsupport("RenderAny does not support " + "apply to request and response. Please use apply(AppContext) instead"); }
Example 13
Source File: HttpCurrentStateStore.java From actframework with Apache License 2.0 | 4 votes |
@Override public H.Request request() { ActionContext ctx = ActionContext.current(); return null == ctx ? null : ctx.req(); }
Example 14
Source File: HelloController.java From actframework with Apache License 2.0 | 4 votes |
@GetAction("/req/path") public String reqPath(H.Request req) { return req.path(); }
Example 15
Source File: HelloController.java From actframework with Apache License 2.0 | 4 votes |
@GetAction("/req/query") public String reqQuery(H.Request req) { return req.query(); }
Example 16
Source File: ActionContext.java From actframework with Apache License 2.0 | 4 votes |
/** * Create an new {@code AppContext} and return the new instance */ public static ActionContext create(App app, H.Request request, ActResponse<?> resp) { return new ActionContext(app, request, resp); }
Example 17
Source File: ActProviders.java From actframework with Apache License 2.0 | 4 votes |
@Override public H.Request get() { return ActionContext.current().req(); }
Example 18
Source File: SessionMapper.java From actframework with Apache License 2.0 | 2 votes |
/** * Read the incoming HTTP request and extract serialized flash state. * * @param request * the incoming HTTP request * @return * flash state (a string) read from request or `null` if not * flash state found in the request using this mapper */ String readFlash(H.Request request);
Example 19
Source File: SessionCodec.java From actframework with Apache License 2.0 | 2 votes |
/** * Decode a session string into a session. * * @param encodedSession * the encoded session string * @param request * the incoming request - used to provide the current URL path */ H.Session decodeSession(String encodedSession, H.Request request);
Example 20
Source File: HttpClient.java From actframework with Apache License 2.0 | votes |
H.Response send(H.Request request);