public static ServletContext getServletContext() { return (ServletContext) ContainerUtil.retrieveExternalContext().getApplication(); }
protected void viaLastaDiContext(HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws IOException, ServletException { final LaContainer container = SingletonLaContainerFactory.getContainer(); final ExternalContext externalContext = container.getExternalContext(); if (externalContext == null) { throw new IllegalStateException("The externalContext should not be null from the container: " + container); } final Object prevoiusRequest = externalContext.getRequest(); final Object previousResponse = externalContext.getResponse(); try { externalContext.setRequest(request); externalContext.setResponse(response); viaHotdeploy(request, response, chain); // #to_action } finally { externalContext.setRequest(prevoiusRequest); externalContext.setResponse(previousResponse); } }
protected Object getValue(final String name, final ExternalContext extCtx) { Object value = extCtx.getRequestParameterMap().get(name); if (value != null) { return value; } value = extCtx.getRequestHeaderMap().get(name); if (value != null) { return value; } return extCtx.getRequestMap().get(name); }
protected Object[] getValues(final String name, final ExternalContext extCtx) { Object[] values = (Object[]) extCtx.getRequestParameterValuesMap().get(name); if (values != null && values.length > 0) { return values; } values = (Object[]) extCtx.getRequestHeaderValuesMap().get(name); if (values != null && values.length > 0) { return values; } return null; } }
protected void xclearRequestMockContext() { final LaContainer container = SingletonLaContainerFactory.getContainer(); final ExternalContext externalContext = container.getExternalContext(); if (externalContext != null) { // just in case externalContext.setRequest(null); externalContext.setResponse(null); } xreleaseMockRequestInstance(); }
/** * @param request The request for external context of Lasta Di. (NotNull) * @throws IllegalStateException When the external context or existing request is not found. */ public static void overrideExternalRequest(HttpServletRequest request) { if (request == null) { throw new IllegalArgumentException("The argument 'request' should not be null."); } final ExternalContext context = retrieveExternalContext(); final Object existing = context.getRequest(); if (existing == null) { throw new IllegalStateException("Not found external request in Lasta Di container for your overriding by: " + request); } context.setRequest(request); }
/** * @return The optional request of servlet. (NotNull, EmptyAllowed: when out of scope for external context) */ public static OptionalThing<HttpServletRequest> getOptionalRequest() { final HttpServletRequest request; if (ContainerUtil.hasExternalContext()) { final ExternalContext externalContext = ContainerUtil.retrieveExternalContext(); // not null request = (HttpServletRequest) externalContext.getRequest(); // null allowed, request not found } else { request = null; // external context not found } return toRequestOptional(request); }
protected static void setupExternalContext() { if (container.getExternalContext() == null) { if (externalContext != null) { container.setExternalContext(externalContext); } } else if (container.getExternalContext().getApplication() == null && externalContext != null) { container.getExternalContext().setApplication(externalContext.getApplication()); } if (container.getExternalContextComponentDefRegister() == null && externalContextComponentDefRegister != null) { container.setExternalContextComponentDefRegister(externalContextComponentDefRegister); } }
@Override public Object getComponent() { return getContainer().getRoot().getExternalContext().getRequestMap(); } }
/** * @see org.lastaflute.di.core.ComponentDef#getComponent() */ public Object getComponent() { return getContainer().getRoot().getExternalContext().getApplicationMap(); } }
/** * @see org.lastaflute.di.core.ComponentDef#getComponent() */ public Object getComponent() { return getContainer().getRoot().getExternalContext().getRequestHeaderValuesMap(); } }
/** * @see org.lastaflute.di.core.ComponentDef#getComponent() */ public Object getComponent() { return getContainer().getRoot().getExternalContext().getRequestHeaderMap(); } }
public Object getComponent() { return getContainer().getRoot().getExternalContext().getInitParameterMap(); } }
/** * @see org.lastaflute.di.core.ComponentDef#getComponent() */ public Object getComponent() { return getContainer().getRoot().getExternalContext().getRequestParameterMap(); } }
protected void xregisterRequestMockContext(MockletServletConfig servletConfig) { // like S2ContainerFilter final LaContainer container = SingletonLaContainerFactory.getContainer(); final ExternalContext externalContext = container.getExternalContext(); final MockletHttpServletRequest request = createMockletHttpServletRequest(servletConfig.getServletContext()); final MockletHttpServletResponse response = createMockletHttpServletResponse(request); externalContext.setRequest(request); externalContext.setResponse(response); xkeepMockRequestInstance(request, response); // for web mock handling methods }
/** * @param request The request for external context of Lasta Di. (NotNull) * @throws IllegalStateException When the external context or existing request is not found. */ public static void overrideExternalRequest(HttpServletRequest request) { if (request == null) { throw new IllegalArgumentException("The argument 'request' should not be null."); } final ExternalContext context = retrieveExternalContext(); final Object existing = context.getRequest(); if (existing == null) { throw new IllegalStateException("Not found external request in Lasta Di container for your overriding by: " + request); } context.setRequest(request); }
/** * @see org.lastaflute.di.core.ComponentDef#getComponent() */ public Object getComponent() { return getContainer().getRoot().getExternalContext().getRequest(); } }
public Object deploy() { ComponentDef cd = getComponentDef(); ExternalContext extCtx = cd.getContainer().getRoot().getExternalContext(); if (extCtx == null) { RuntimeException re = new EmptyRuntimeException("externalContext"); logger.log(re); throw re; } Map<String, Object> requestMap = extCtx.getRequestMap(); String componentName = getComponentName(); Object component = null; component = requestMap.get(componentName); if (component != null) { return component; } component = getConstructorAssembler().assemble(); requestMap.put(componentName, component); getPropertyAssembler().assemble(component); getInitMethodAssembler().assemble(component); return component; }
public Object deploy() { ComponentDef cd = getComponentDef(); ExternalContext extCtx = cd.getContainer().getRoot().getExternalContext(); if (extCtx == null) { throw new EmptyRuntimeException("externalContext"); } Map<String, Object> applicationMap = extCtx.getApplicationMap(); String componentName = getComponentName(); Object component = applicationMap.get(componentName); if (component == null) { component = getConstructorAssembler().assemble(); getPropertyAssembler().assemble(component); getInitMethodAssembler().assemble(component); applicationMap.put(componentName, component); } return component; }
protected void viaLastaDiContext(HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws IOException, ServletException { final LaContainer container = SingletonLaContainerFactory.getContainer(); final ExternalContext externalContext = container.getExternalContext(); if (externalContext == null) { throw new IllegalStateException("The externalContext should not be null from the container: " + container); } final Object prevoiusRequest = externalContext.getRequest(); final Object previousResponse = externalContext.getResponse(); try { externalContext.setRequest(request); externalContext.setResponse(response); viaHotdeploy(request, response, chain); // #to_action } finally { externalContext.setRequest(prevoiusRequest); externalContext.setResponse(previousResponse); } }