This content has been marked as final.
Show 22 replies
-
15. Re: share my some fix for my portal impl
zjsun Mar 6, 2008 10:53 AM (in response to zjsun)to be continue...
-
16. Re: share my some fix for my portal impl
zjsun Mar 9, 2008 6:13 AM (in response to zjsun)"zjsun" wrote:
org.jboss.portletbridge.lifecycle.RestoreViewPhase:public void executePhase(FacesContext context) { // Check pre-created ViewRoot. UIViewRoot viewRoot = context.getViewRoot(); if (null != viewRoot) { if (_log.isDebugEnabled()) { _log.debug("Found created UIViewRoot in facesContext"); } viewRoot.setLocale(context.getExternalContext().getRequestLocale()); processBindings(context, viewRoot); } else { // Restore or Create new view. String viewId = calculateViewId(context); ViewHandler viewHandler = context.getApplication().getViewHandler(); if (isFacesRequest(context)) { // TODO - check for a null and throw exception. viewRoot = viewHandler.restoreView(context, viewId); if (null != viewRoot) { processBindings(context, viewRoot); } else { // Error restore view. Session Expired ? throw new ViewExpiredException("Error restore view " + viewId + ", session expired?"); } } else { viewRoot = viewHandler.createView(context, viewId); // TODO: zjsun fix here? context.renderResponse(); } context.setViewRoot(viewRoot); } }
private String calculateViewId(FacesContext context) { String viewId = null; // TODO:zjsun fix here 优先判æ–ÂPortletRequest先 Object externalRequest = context.getExternalContext().getRequest(); if (externalRequest instanceof PortletRequest) { viewId = PortletStateHolder.getInstance(context).getViewId(context); } else if (context.getExternalContext().getRequest() instanceof ServletRequest) { viewId = context.getExternalContext().getRequestPathInfo(); if (null == viewId) { viewId = context.getExternalContext().getRequestServletPath(); } } else { throw new FacesException(); } return viewId; }
problem:
1) according to the seam's restoreview phase impl, when create a view, should "context.renderResponse()";
2) should check "PortletRequest" first , because some container impl's PortletRequest is a ServletRequestWrapper -
17. Re: share my some fix for my portal impl
zjsun Mar 9, 2008 6:15 AM (in response to zjsun)"zjsun" wrote:
org.jboss.portletbridge.lifecycle.PortletLifecycle:public void render(FacesContext context) throws FacesException { // TODO - in the portletbridge mode, restore state, request scope // variables and Faces Messages. // Object request = context.getExternalContext().getRequest(); // if(request instanceof PortletRequest){ // executePhase.executePhase(context); // PortletViewState windowState = // PortletStateHolder.getInstance(context).getWindowState(context); // windowState.restoreMessages(context); // Map requestScopeBeans = windowState.getRequestScopeBeans(); // if(null != requestScopeBeans){ // context.getExternalContext().getRequestMap().putAll(requestScopeBeans); // } // } // TODO:zjsun fix here 判æ–Â是åÂ�¦å·²ç»Â�response complete if (!context.getResponseComplete()) { renderPhase.execute(context); } }
problem:
1) should check "response complete" before render phase executing. -
18. Re: share my some fix for my portal impl
zjsun Mar 9, 2008 8:54 AM (in response to zjsun)"zjsun" wrote:
org.jboss.portletbridge.context.ServletExternalContextImpl:@Override protected String createActionUrl(Map<String, String> parameters) { PortalActionURL actionUrl = new PortalActionURL(portalActionUrl); // TODO:zjsun fix here 对cmstar的url进行处ç�† if (CmstarURL.isCmstarUrl(actionUrl)) { CmstarURL cmstarUrl; try { cmstarUrl = new CmstarURL(actionUrl); for (Entry<String, String> parameterEntry : parameters .entrySet()) { cmstarUrl.addParameter(parameterEntry.getKey(), parameterEntry.getValue()); } return cmstarUrl.toString(); } catch (MalformedURLException e) { e.printStackTrace(); } } for (Entry<String, String> parameterEntry : parameters.entrySet()) { actionUrl.addParameter(parameterEntry.getKey(), parameterEntry .getValue()); } return actionUrl.toString(); }
// TODO:zjsun fix here é‡Â�写æÂ¤æ–¹æ³•,以便更新é‡Â�定åÂ�‘çš„viewId @Override public String encodeActionURL(String url) { try { PortalActionURL actionURL = new PortalActionURL(url); String viewId = actionURL.getParameter(VIEW_ID_PARAMETER); if (viewId == null && actionURL.isInContext(this.getHttpRequest() .getContextPath())) { viewId = FacesUtil.getViewIdFromPath(actionURL.getPath()); actionURL.addParameter(VIEW_ID_PARAMETER, viewId); url = actionURL.toString(); } } catch (MalformedURLException e) { e.printStackTrace(); } return super.encodeActionURL(url); }
problem:
1) my company's portal impl has the url base64-encoded, so i have to use my impl to add parameters
2) before a redirect(this will call encodeActionURL), a VIEW_ID_PARAMETER request parameter must set because the bridge relies on this -
19. Re: share my some fix for my portal impl
zjsun Mar 9, 2008 8:59 AM (in response to zjsun)"zjsun" wrote:
org.jboss.portletbridge.context.RenderPortletExternalContextImpl:protected Object getRequestParameter(String name) { // TODO: zjsun fix here 增åŠ 返回数组判æ–Â. Object retObj = getRequestParameterValues(name); if (retObj == null) { return null; } if (retObj.getClass().isArray()) { Object[] values = (Object[]) retObj; return values[0]; } else { return retObj; } }
@Override public void redirect(String url) throws IOException { if (null == url) { throw new NullPointerException("Path to redirect is null"); } PortalActionURL actionURL = new PortalActionURL(url); // TODO: zjsun fix here 对CMSTAR的actionUrl进行解ç �处ç�†å…ˆï¼Œ // CMSTAR Url:?.p=ASFWERISFSADF...... if (CmstarURL.isCmstarUrl(actionURL)) { CmstarURL cmstarUrl = new CmstarURL(actionURL); actionURL = cmstarUrl.toPortalActionURL(); // 强制设定actionURL.isInContext(getRequestContextPath() actionURL.setPath(getRequestContextPath() + ACTION_URL_DO_NOTHITG); } if ((!actionURL.isInContext(getRequestContextPath()) && null == actionURL .getParameter(VIEW_ID_PARAMETER)) || "true".equalsIgnoreCase(actionURL .getParameter(Bridge.DIRECT_LINK))) { // dispatch(url); // throw new IllegalStateException( // "Redirect to new url not at action phase"); } else { // HACK - if page is in the context, just treat it as navigation // case internalRedirect(actionURL); } }
@SuppressWarnings("unchecked") private Map<String, String[]> getSavedRequestParameters() { if (null == _requestParameters) { // Get parameters ( all or a View state only ) restored as requered // in the JSR 301 PLT 5.1 _requestParameters = (Map<String, String[]>) getRequestAttribute(PortletViewState.REQUEST_PARAMETERS_ATTRIBUTE); // TODO: zjsun fix here if (_requestParameters == null) { _requestParameters = Collections.EMPTY_MAP; } } return _requestParameters; }
// TODO: zjsun fix here @Override public Map getRequestParameterValuesMap() { return getSavedRequestParameters(); }
problem:
1) sometimes the getRequestParameterValues() method returns single value instead of string array, so i just have an array instance check
2)my portal impl's url process
3) add "_requestParameters " null check
4) override getRequestParameterValuesMap() method from AbstractExternalContext impl, using "getSavedRequestParameters()" directly. -
20. Re: share my some fix for my portal impl
zjsun Mar 9, 2008 9:04 AM (in response to zjsun)"zjsun" wrote:
org.jboss.portletbridge.context.PortletExternalContextImpl:public String getRemoteUser() { // TODO:zjsun fix here // return getPortletRequest().getRemoteUser(); String user = getPortletRequest().getRemoteUser(); if (user == null){ Principal userPrincipal = getUserPrincipal(); user = userPrincipal.getName(); } return user; }
public Object getSession(boolean create) { // TODO:zjsun fix here ä¼ é€’createå�‚æ•° return getPortletRequest().getPortletSession(create); }
protected void internalRedirect(PortalActionURL actionURL) { // Detect ViewId from URL and create new view for them. String viewId = actionURL.getParameter(VIEW_ID_PARAMETER); if (null != viewId) { try { viewId = URLDecoder.decode(viewId, "UTF8"); // Save new viewId to restore after redirect. getRequestMap().put(AbstractExternalContext.REDIRECT_VIEW_ID, viewId); // FacesContext facesContext = // FacesContext.getCurrentInstance(); // ViewHandler viewHandler = facesContext.getApplication() // .getViewHandler(); // facesContext.setViewRoot(viewHandler.createView(facesContext, // viewId)); // setHasNavigationRedirect(true); // TODO: zjsun fix here é‡�定å�‘时需è¦�å�Œæ—¶ä¿�留å�‚æ•° Map<String, String> actionParams = actionURL.getParameters(); if (actionParams != null) { Map<String, String[]> requestParameters = new HashMap<String, String[]>(); for (Iterator<Entry<String, String>> it = actionParams .entrySet().iterator(); it.hasNext();) { Entry<String, String> entry = it.next(); String key = entry.getKey(); if (key != null) { String value = entry.getValue(); requestParameters.put(key.trim(), new String[] { value }); } } if (requestParameters.size() > 0) { getRequestMap() .put( PortletViewState.REDIRECT_REQUEST_PARAMETERS_ATTRIBUTE, requestParameters); } } } catch (UnsupportedEncodingException e) { // Do nothing - UTF-8 encoding is a default. } } }
problems:
1) if RemoteUser from request is null, then using Principle's name
2) added the "create" arg to getPortletSession() call
3) hold the redirect url params in request's REDIRECT_REQUEST_PARAMETERS_ATTRIBUTE attribute -
21. Re: share my some fix for my portal impl
zjsun Mar 9, 2008 9:07 AM (in response to zjsun)"zjsun" wrote:
org.jboss.portletbridge.context.PortalActionURL://TODO:zjsun fix here 暴露这些属性,以便使用 public void setProtocol(String protocol) { this.protocol = protocol; } public void setHost(String host) { this.host = host; } public void setPort(int port) { this.port = port; } public void setAuthority(String authority) { this.authority = authority; } public void setPath(String path) { this.path = path; } public void setUserInfo(String userInfo) { this.userInfo = userInfo; } public void setParameters(Map<String, String> parameters) { this.parameters = parameters; } public void setQueryString(String queryString) { this.queryString = queryString; }
problem:
1) just make these properties writtable,for somewhere use -
22. Re: share my some fix for my portal impl
zjsun Mar 9, 2008 9:09 AM (in response to zjsun)"zjsun" wrote:
org.jboss.portletbridge.application.PortletStateHolder:public String getStateId(FacesContext context) { ExternalContext externalContext = context.getExternalContext(); Object request = externalContext.getRequest(); String stateId = null; // TODO: zjsun fix here 调整PortletRequest优先判æ–Â顺åºÂ� if (request instanceof PortletRequest) { PortletRequest portletRequest = (PortletRequest) request; PortletSession portletSession = portletRequest .getPortletSession(true); PortletConfig portletConfig = (PortletConfig) portletRequest .getAttribute(AbstractExternalContext.PORTLET_CONFIG_ATTRIBUTE); if (null == portletConfig) { throw new FacesException(); } String scopeId = portletConfig.getPortletName() + portletSession.getId(); String portletModeName = portletRequest.getPortletMode().toString(); if (request instanceof RenderRequest) { RenderRequest renderRequest = (RenderRequest) request; stateId = renderRequest.getParameter(STATE_ID_PARAMETER); if (null == stateId) { RenderResponse response = (RenderResponse) externalContext .getResponse(); stateId = scopeId + portletModeName + response.getNamespace(); } } else if (request instanceof ActionRequest) { ActionRequest actionRequest = (ActionRequest) request; if (stateId == null) { stateId = (String) actionRequest .getAttribute(STATE_ID_PARAMETER); } if (null == stateId) { UUID uuid = UUID.randomUUID(); stateId = scopeId + portletModeName + uuid.toString(); actionRequest.setAttribute(STATE_ID_PARAMETER, stateId); ActionResponse response = (ActionResponse) externalContext .getResponse(); response.setRenderParameter(STATE_ID_PARAMETER, stateId); } } else { throw new FacesException(); } WindowIDRetriver idRetriver = (WindowIDRetriver) portletSession .getAttribute(WINDOW_ID_RETRIVER); if (null == idRetriver) { idRetriver = new WindowIDRetriver(scopeId); portletSession.setAttribute(WINDOW_ID_RETRIVER, idRetriver); } } else if (request instanceof HttpServletRequest) { HttpServletRequest servletRequest = (HttpServletRequest) request; stateId = servletRequest.getParameter(STATE_ID_PARAMETER); // if (null == stateId) { // throw new FacesException("No portletbridge stateId parameter for // AJAX request"); // } } else { throw new FacesException(); } return stateId; }
problem:
1) put "PortletRequest" first in "if" clause.