I am trying to create a service.
The fact is that my index.xhtml should receive parameters (POST and GET) and cookies from an HTTP request.
I tried a combination with <f:metadata> and <f:event type="preRenderView"> as follows:
<f:metadata> <f:event type="preRenderView" listener="#{deConversation.start}"/> </f:metadata>
Code for deConversation.start:
public void start(ComponentSystemEvent event) { System.out.println("checkLogin"); HttpServletRequest request = SsoHelper.getRequest(); String requestSessId = SsoHelper.getRequestSessionId(request); String requestRedirect = SsoHelper.getRequestRedirect(request); System.out.println("sessId " + requestSessId); if (requestRedirect == null || requestRedirect.isEmpty()) { requestRedirect = "self"; } if (requestSessId != null) { trySessId(requestSessId, requestRedirect); } externalResourcesHandler.setExternalRedirect(requestRedirect); tryToBeginConversation(); if (!isAuthorized()) { SsoHelper.performNavigation("auth"); } }
SsoHelper simply provides the api as follows:
public static String getRequestSessionId(HttpServletRequest request) { Map<String, Object> cookieMap = FacesContext.getCurrentInstance().getExternalContext().getRequestCookieMap(); String requestDeSessionId = null; if (cookieMap.containsKey("de_session_id")) { requestDeSessionId = ((Cookie) cookieMap.get("de_session_id")).getValue(); } return requestDeSessionId; } public static String getRequestRedirect(HttpServletRequest request) { return getRequestParam(request, "redirect", "self"); } public static String getRequestExternalCss(HttpServletRequest request) { return getRequestParam(request, "externalcss", null); } public static String getRequestParam(HttpServletRequest request, String name, String defaultValue) { String[] paramValues = HttpServletRequestHelper.getParamValues(request, name); String paramValue = null; if (paramValues != null && paramValues.length != 0) { paramValue = paramValues[0]; } if(paramValue == null){ paramValue = defaultValue; } return paramValue; } public static HttpServletRequest getRequest() { return (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest(); } public static void performNavigation(String destination) { FacesContext context = FacesContext.getCurrentInstance(); ConfigurableNavigationHandler handler = (ConfigurableNavigationHandler) context.getApplication().getNavigationHandler(); handler.performNavigation(destination); }
The fact is, I could not get any POST or cookie parameters in the start () method. I can only get GET parameters.
Is it possible to read cookies and POST parameters using <f:event type="preRenderView"> ?
Jerome
source share