@Override public void outject(final ActionRequest actionRequest, final Targets targets) { final ServletContext context = actionRequest.getHttpServletRequest().getServletContext(); targets.forEachTargetAndOut(this, (target, out) -> { final Object value = target.readValue(out); context.setAttribute(out.name(), value); }); }
@Override public void inject(final ActionRequest actionRequest, final Targets targets) { final HttpServletRequest servletRequest = actionRequest.getHttpServletRequest(); targets.forEachTargetAndIn(this, (target, in) -> { final Enumeration<String> headerNames = servletRequest.getHeaders(in.name()); if (headerNames != null) { final List<String> allValues = new ArrayList<>(); while (headerNames.hasMoreElements()) { allValues.add(headerNames.nextElement()); } final Object value; if (allValues.size() == 1) { value = allValues.get(0); } else { value = allValues; } target.writeValue(in, value, true); } }); }
@Override public void outject(final ActionRequest actionRequest, final Targets targets) { final HttpServletRequest servletRequest = actionRequest.getHttpServletRequest(); final HttpSession session = servletRequest.getSession(); targets.forEachTargetAndOut(this, (target, out) -> { final Object value = target.readValue(out); session.setAttribute(out.name(), value); }); } }
@Override public void outject(final ActionRequest actionRequest, final Targets targets) { final HttpServletResponse servletResponse = actionRequest.getHttpServletResponse(); targets.forEachTargetAndOut(this, (target, out) -> { final String value = (String) target.readValue(out); if (value != null) { servletResponse.setHeader(out.name(), value); } }); } }
@Override public void outject(final ActionRequest actionRequest, final Targets targets) { final HttpServletRequest servletRequest = actionRequest.getHttpServletRequest(); targets.forEachTargetAndOut(this, (target, out) -> { final Object value = target.readValue(out); servletRequest.setAttribute(out.name(), value); }); }
@Override public void inject(final Targets targets) { targets.forEachTargetAndIn(this, (target, in) -> { final Object value = madpc.getBean(in.name()); if (value != null) { target.writeValue(in, value, false); } }); }
@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); } }); }
@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()); }