public void inject(final ServletContext servletContext, final Targets targets) { targets.forEachTargetAndIn(madvocScope, (target, in) -> { final Class inType = in.type(); Object value = null; if (inType == ServletContext.class) { value = servletContext; } if (value != null) { target.writeValue(in, value, true); } }); }
@Override public void inject(final ActionRequest actionRequest, final Targets targets) { final HttpServletRequest servletRequest = actionRequest.getHttpServletRequest(); targets.forEachTargetAndIn(this, (target, in) -> { Object value = null; if (in.type() == Cookie.class) { // get single cookie final String cookieName = StringUtil.uncapitalize(in.name()); value = ServletUtil.getCookie(servletRequest, cookieName); } else if (in.type().isArray()) { if (in.type().getComponentType().equals(Cookie.class)) { if (StringUtil.isEmpty(in.name())) { // get all cookies value = servletRequest.getCookies(); } else { // get all cookies by name value = ServletUtil.getAllCookies(servletRequest, in.name()); } } } if (value != null) { target.writeValue(in, value, true); } }); }
@Override public void inject(final ActionRequest actionRequest, final Targets targets) { final String body = actionRequest.readRequestBody(); if (StringUtil.isEmpty(body)) { return; } targets.forEachTargetAndIn(this, (target, in) -> { if (in.type() == String.class) { target.writeValue(in, body, true); } else { final Object value = parseRequestBody(body, in.type()); target.writeValue(in, value, true); } }); }
public void inject(final ActionRequest actionRequest, final Targets targets) { final HttpServletRequest servletRequest = actionRequest.getHttpServletRequest(); final HttpServletResponse servletResponse = actionRequest.getHttpServletResponse(); targets.forEachTargetAndIn(madvocScope, (target, in) -> { final Class inType = in.type(); Object value = null; if (inType == HttpServletRequest.class) { value = servletRequest; } else if (inType == ServletRequest.class) { value = servletRequest; } else if (inType == HttpServletResponse.class) { value = servletResponse; } else if (inType == ServletResponse.class) { value = servletResponse; } else if (inType == HttpSession.class) { value = servletRequest.getSession(); } else if (inType == ServletContext.class) { value = servletRequest.getServletContext(); } else if (inType == AsyncContext.class) { value = servletRequest.getAsyncContext(); } else if (inType == ActionRequest.class) { value = actionRequest; } if (value != null) { target.writeValue(in, value, true); } }); }
@Test void testGenericAction() { ScopeDataInspector scopeDataInspector = new ScopeDataInspector(); PetiteContainer madpc = new PetiteContainer(); scopeDataInspector.scopeResolver = new ScopeResolver(); scopeDataInspector.scopeResolver.madpc = madpc; madpc.addBean("madvocEncoding", new MadvocEncoding()); ScopeData scopeData = scopeDataInspector.inspectClassScopes(GenAction.class); InjectionPoint[] in1 = scopeData.in(); InjectionPoint[] out1 = scopeData.out(); InjectionPoint in = in1[0]; InjectionPoint out = out1[0]; assertEquals("input", in.name()); assertEquals(String.class, in.type()); assertEquals("output", out.name()); assertEquals(Integer.class, out.type()); }
@Test void testInAnnotations() { ScopeDataInspector scopeDataInspector = new ScopeDataInspector(); PetiteContainer madpc = new PetiteContainer(); scopeDataInspector.scopeResolver = new ScopeResolver(); scopeDataInspector.scopeResolver.madpc = madpc; madpc.addBean("madvocEncoding", new MadvocEncoding()); ScopeData scopeData = scopeDataInspector.inspectClassScopes(Action.class); InjectionPoint[] in1 = scopeData.in(); InjectionPoint in = in1[0]; assertEquals("input", in.name()); assertEquals(String.class, in.type()); }