Search in sources :

Example 6 with BridgeException

use of javax.portlet.faces.BridgeException in project liferay-faces-bridge-impl by liferay.

the class BridgePhaseRenderImpl method execute.

@Override
public void execute() throws BridgeException {
    logger.debug(Logger.SEPARATOR);
    logger.debug("execute(RenderRequest, RenderResponse) portletName=[{0}] portletMode=[{1}]", portletName, renderRequest.getPortletMode());
    Object renderPartAttribute = renderRequest.getAttribute(RenderRequest.RENDER_PART);
    if ((renderPartAttribute != null) && renderPartAttribute.equals(RenderRequest.RENDER_HEADERS)) {
        doFacesHeaders(renderRequest, renderResponse);
    } else {
        try {
            execute(null);
        } catch (BridgeException e) {
            throw e;
        } catch (Throwable t) {
            throw new BridgeException(t);
        } finally {
            cleanup(renderRequest);
        }
        logger.debug(Logger.SEPARATOR);
    }
}
Also used : BridgeException(javax.portlet.faces.BridgeException)

Example 7 with BridgeException

use of javax.portlet.faces.BridgeException in project liferay-faces-bridge-impl by liferay.

the class BridgeURLFactoryImpl method getBridgePartialActionURL.

@Override
public BridgeURL getBridgePartialActionURL(FacesContext facesContext, String uri) throws BridgeException {
    ExternalContext externalContext = facesContext.getExternalContext();
    ContextInfo contextInfo = new ContextInfo(facesContext.getViewRoot(), externalContext, facesContext.getResponseWriter());
    ClientWindowInfo clientWindowInfo = new ClientWindowInfo(externalContext);
    try {
        return new BridgeURLPartialActionImpl(uri, contextInfo.contextPath, contextInfo.namespace, contextInfo.encoding, contextInfo.facesURLEncoder, contextInfo.currentFacesViewId, clientWindowInfo.isRenderModeEnabled(facesContext), clientWindowInfo.getId(), clientWindowInfo.getUrlParameters(facesContext), contextInfo.portletConfig, contextInfo.bridgeConfig);
    } catch (URISyntaxException | UnsupportedEncodingException e) {
        throw new BridgeException(e);
    }
}
Also used : BridgeException(javax.portlet.faces.BridgeException) ExternalContext(javax.faces.context.ExternalContext) UnsupportedEncodingException(java.io.UnsupportedEncodingException) URISyntaxException(java.net.URISyntaxException)

Example 8 with BridgeException

use of javax.portlet.faces.BridgeException in project liferay-faces-bridge-impl by liferay.

the class FormRendererPrimeFacesImpl method encodeBegin.

@Override
public void encodeBegin(FacesContext facesContext, UIComponent uiComponent) throws IOException {
    // "javax.faces.encodedURL" hidden field.
    if ((majorVersion == 3) && (minorVersion < 3) && isMultiPartForm(uiComponent)) {
        boolean hasPrimeFacesAjaxFileUploadChild = false;
        UIComponent childComponent = getChildWithRendererType(uiComponent, RenderKitBridgeImpl.PRIMEFACES_FILE_UPLOAD_RENDERER_TYPE);
        if (childComponent != null) {
            if (!isSimpleMode(uiComponent)) {
                hasPrimeFacesAjaxFileUploadChild = true;
                facesContext.getAttributes().put(AJAX_FILE_UPLOAD, Boolean.TRUE);
            }
        }
        // Continue encoding with the wrapped FormRenderer. When it comes time to call
        // ExternalContext.encodeActionURL(String), the bridge will check for the
        // PrimeFacesFileUpload.AJAX_FILE_UPLOAD attribute. If found, then it will return a PartialActionURL
        // suitable for Ajax requests.
        super.encodeBegin(facesContext, uiComponent);
        if (hasPrimeFacesAjaxFileUploadChild) {
            facesContext.getAttributes().remove(AJAX_FILE_UPLOAD);
        }
    } else // the ACTION_PHASE of the portlet lifecycle.
    if (hasNonAjaxActionListener(uiComponent)) {
        ViewHandler viewHandler = facesContext.getApplication().getViewHandler();
        String viewId = facesContext.getViewRoot().getViewId();
        String facesActionURL = viewHandler.getActionURL(facesContext, viewId);
        ExternalContext externalContext = facesContext.getExternalContext();
        PortletContext portletContext = (PortletContext) externalContext.getContext();
        BridgeURLFactory bridgeURLFactory = (BridgeURLFactory) BridgeFactoryFinder.getFactory(portletContext, BridgeURLFactory.class);
        try {
            BridgeURL partialActionURL = bridgeURLFactory.getBridgePartialActionURL(facesContext, facesActionURL);
            partialActionURL.removeParameter(Bridge.FACES_AJAX_PARAMETER);
            partialActionURL.setParameter(BridgeExt.FACES_EXPORT_COMPONENT_PARAMETER, "true");
            String nonAjaxPartialActionURL = partialActionURL.toString();
            ResponseWriter responseWriter = facesContext.getResponseWriter();
            ResponseWriter primeFacesResponseWriter = new ResponseWriterPrimeFacesBodyImpl(responseWriter, nonAjaxPartialActionURL);
            facesContext.setResponseWriter(primeFacesResponseWriter);
            super.encodeBegin(facesContext, uiComponent);
            facesContext.setResponseWriter(responseWriter);
        } catch (BridgeException e) {
            logger.error(e);
        }
    } else // Otherwise, delegate encoding to the wrapped renderer.
    {
        super.encodeBegin(facesContext, uiComponent);
    }
}
Also used : BridgeException(javax.portlet.faces.BridgeException) BridgeURLFactory(javax.portlet.faces.BridgeURLFactory) ResponseWriter(javax.faces.context.ResponseWriter) ViewHandler(javax.faces.application.ViewHandler) ExternalContext(javax.faces.context.ExternalContext) UIComponent(javax.faces.component.UIComponent) PortletContext(javax.portlet.PortletContext) BridgeURL(javax.portlet.faces.BridgeURL)

Example 9 with BridgeException

use of javax.portlet.faces.BridgeException in project liferay-faces-bridge-ext by liferay.

the class LiferayURLGeneratorBaseImpl method parse.

private void parse() {
    parameterMap = new HashMap<String, String>();
    wsrpParameters = new ArrayList<LiferayURLParameter>();
    String queryString = baseURL;
    int queryPos = baseURL.indexOf("?");
    if (queryPos > 0) {
        prefix = baseURL.substring(0, queryPos + 1);
        queryString = baseURL.substring(queryPos + 1);
    }
    String[] nameValuePairs = queryString.split("[&]");
    if (nameValuePairs != null) {
        for (String nameValuePair : nameValuePairs) {
            int equalsPos = nameValuePair.indexOf("=");
            if (equalsPos > 0) {
                try {
                    String name = nameValuePair.substring(0, equalsPos);
                    name = URLDecoder.decode(name, encoding);
                    String value = nameValuePair.substring(equalsPos + 1);
                    value = URLDecoder.decode(value, encoding);
                    if (nameValuePair.startsWith("wsrp")) {
                        LiferayURLParameter liferayUrlParameter = new LiferayURLParameter(name, value);
                        wsrpParameters.add(liferayUrlParameter);
                    } else {
                        parameterMap.put(name, value);
                    }
                } catch (UnsupportedEncodingException e) {
                    throw new BridgeException(e);
                }
            }
        }
    }
    int pos = baseURL.indexOf("#");
    if (pos > 0) {
        portletURLAnchor = baseURL.substring(pos);
    }
}
Also used : BridgeException(javax.portlet.faces.BridgeException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 10 with BridgeException

use of javax.portlet.faces.BridgeException in project liferay-faces-bridge-impl by liferay.

the class BridgePhaseResourceImpl method execute.

@Override
public void execute() throws BridgeDefaultViewNotSpecifiedException, BridgeException {
    logger.debug(Logger.SEPARATOR);
    logger.debug("execute(ResourceRequest, ResourceResponse) portletName=[{0}]", portletName);
    try {
        init(resourceRequest, resourceResponse, Bridge.PortletPhase.RESOURCE_PHASE);
        // resource, then
        if (isJSF2ResourceRequest(facesContext)) {
            logger.debug("Detected JSF2 resource request");
            // Ask the Faces resource handler to copy the contents of the resource to the response.
            handleJSF2ResourceRequest(facesContext);
        } else if ((resourceRequest.getResourceID() != null) && !resourceRequest.getResourceID().equals("wsrp")) {
            logger.debug("Detected non-Faces resource");
            String resourceId = resourceRequest.getResourceID();
            String autoResourceDispatch = portletConfig.getInitParameter("javax.portlet.automaticResourceDispatching");
            if ((autoResourceDispatch != null) && autoResourceDispatch.equalsIgnoreCase("true")) {
                ExternalContext externalContext = facesContext.getExternalContext();
                ResourceValidator resourceValidator = ResourceValidatorFactory.getResourceValidatorInstance(externalContext);
                // resource.
                if (resourceValidator.containsBannedPath(resourceId)) {
                    // Simulate Liferay Portal's behavior for containers like Pluto
                    logger.warn("Invalid request for resource with banned path: resourceId=[{0}]", resourceId);
                    externalContext.setResponseStatus(HttpServletResponse.SC_OK);
                } else // serve the resource.
                if (resourceValidator.isBannedSequence(resourceId)) {
                    logger.warn("Invalid request for resource with banned sequence: resourceId=[{0}]", resourceId);
                    externalContext.setResponseStatus(HttpServletResponse.SC_NOT_FOUND);
                } else // Otherwise, if the resourceId targets a Facelet document, then do not serve the resource.
                if (resourceValidator.isFaceletDocument(facesContext, resourceId)) {
                    logger.warn("Invalid request for Facelet document: resourceId=[{0}]", resourceId);
                    externalContext.setResponseStatus(HttpServletResponse.SC_NOT_FOUND);
                } else // Otherwise,
                {
                    // Sanitize the resource path by removing special characters that indicate URL fragments, URL
                    // query-strings, etc.
                    String resourcePath = resourceId;
                    for (String urlSeparatorChar : URL_SEPARATOR_CHARS) {
                        int pos = resourcePath.indexOf(urlSeparatorChar);
                        if (pos > 0) {
                            resourcePath = resourcePath.substring(0, pos);
                        }
                    }
                    // has been enforced.
                    if (resourcePath.trim().length() == 0) {
                        final Product LIFERAY_PORTAL = ProductFactory.getProductInstance(externalContext, Product.Name.LIFERAY_PORTAL);
                        if (LIFERAY_PORTAL.isDetected()) {
                            logger.warn("Invalid request for resourceId=[] possibly due to Liferay Portal enforcing the portlet.resource.id.banned.paths.regexp property.");
                        } else {
                            logger.warn("Invalid request for resourceId=[].");
                            externalContext.setResponseStatus(HttpServletResponse.SC_NOT_FOUND);
                        }
                    } else // Otherwise,
                    {
                        // portlet, then do not serve the resource.
                        if (resourceValidator.isSelfReferencing(facesContext, resourcePath)) {
                            logger.warn("Invalid request for resource that is self-referencing: resourceId=[{0}]", resourceId);
                            externalContext.setResponseStatus(HttpServletResponse.SC_NOT_FOUND);
                        } else // Otherwise,
                        {
                            // If the resourceId maps to the FacesServlet, then do not serve the resource.
                            boolean mappedToFacesServlet = false;
                            ConfiguredServletMapping explicitFacesServletExtensionMapping = getExplicitFacesServletExtensionMapping(resourcePath);
                            if (explicitFacesServletExtensionMapping != null) {
                                logger.warn("Invalid request for resource that is EXPLICITLY extension-mapped to the FacesServlet: resourceId=[{0}] resourcePath=[{1}] servlet-mapping extension=[{2}]", resourceId, resourcePath, explicitFacesServletExtensionMapping.getExtension());
                                mappedToFacesServlet = true;
                                externalContext.setResponseStatus(HttpServletResponse.SC_NOT_FOUND);
                            } else {
                                ConfiguredServletMapping facesServletPathMapping = getFacesServletPathMapping(resourceId);
                                if (facesServletPathMapping != null) {
                                    logger.warn("Invalid request for resource that is path-mapped to the FacesServlet: resourceId=[{0}] resourcePath=[{1}] servlet-mapping url-pattern=[{2}]", resourceId, resourcePath, facesServletPathMapping.getUrlPattern());
                                    mappedToFacesServlet = true;
                                    externalContext.setResponseStatus(HttpServletResponse.SC_NOT_FOUND);
                                }
                            }
                            // Otherwise, attempt to serve the resource.
                            if (!mappedToFacesServlet) {
                                PortletRequestDispatcher portletRequestDispatcher = portletContext.getRequestDispatcher(resourceId);
                                if (portletRequestDispatcher != null) {
                                    portletRequestDispatcher.forward(resourceRequest, resourceResponse);
                                } else {
                                    logger.warn("Request for non-Faces resource=[{0}] but request dispatcher was null.", resourceId);
                                    externalContext.setResponseStatus(HttpServletResponse.SC_NOT_FOUND);
                                }
                            }
                        }
                    }
                }
            } else {
                logger.warn("Request for non-Faces resource=[{0}] but automatic dispatching is disabled.", resourceId);
            }
        } else // Otherwise, must be an Ajax (partial-submit) request. Though technically a postback type of request,
        // Ajax requests also utilize the portlet RESOURCE_PHASE. Therefore treat it like a postback, and
        // execute the entire Faces lifecycle: RESTORE_VIEW, APPLY_REQUEST_VALUES, PROCESS_VALIDATIONS,
        // UPDATE_MODEL, INVOKE_APPLICATION.
        {
            ExternalContext externalContext = facesContext.getExternalContext();
            if (logger.isDebugEnabled()) {
                String facesAjaxParameter = externalContext.getRequestParameterMap().get(Bridge.FACES_AJAX_PARAMETER);
                if (BooleanHelper.isTrueToken(facesAjaxParameter)) {
                    logger.debug("Detected Ajax ResourceRequest");
                } else {
                    logger.debug("Detected Non-Ajax ResourceRequest");
                }
            }
            String viewId = getFacesViewId(externalContext);
            logger.debug("Running Faces lifecycle for viewId=[{0}]", viewId);
            // Attach the JSF 2.2 client window to the JSF lifecycle so that Faces Flows can be utilized.
            attachClientWindowToLifecycle(facesContext, facesLifecycle);
            // Execute the JSF lifecycle.
            facesLifecycle.execute(facesContext);
            // Also execute the RENDER_RESPONSE phase of the Faces lifecycle, which will ultimately return a
            // DOM-update back to the jsf.js Javascript code that issued the XmlHttpRequest in the first place.
            facesLifecycle.render(facesContext);
            // "javax.portlet.faces.BRIDGE_REQUEST_SCOPE_AJAX_ENABLED" configuration parameter, then
            if (bridgeRequestScope != null) {
                // PROPOSED-FOR-BRIDGE3-API: https://issues.apache.org/jira/browse/PORTLETBRIDGE-202
                bridgeRequestScope.setPortletMode(resourceRequest.getPortletMode());
                // TCK: nonFacesResourceTest
                // TCK: resourceAttrRetainedAfterRedisplayPPRTest -- Preserve the non-excluded request
                // attributes in the BridgeRequestScope so that they can be restored in subsequent render requests.
                bridgeRequestScope.saveState(facesContext);
                maintainBridgeRequestScope(resourceRequest, resourceResponse, BridgeRequestScope.Transport.PORTLET_SESSION_ATTRIBUTE);
            }
            // Spec 6.6 (Namespacing)
            indicateNamespacingToConsumers(facesContext.getViewRoot(), resourceResponse);
        }
    } catch (Throwable t) {
        throw new BridgeException(t);
    } finally {
        cleanup(resourceRequest);
    }
    logger.debug(Logger.SEPARATOR);
}
Also used : PortletRequestDispatcher(javax.portlet.PortletRequestDispatcher) BridgeException(javax.portlet.faces.BridgeException) ResourceValidator(com.liferay.faces.util.application.ResourceValidator) ExternalContext(javax.faces.context.ExternalContext) Product(com.liferay.faces.util.product.Product) ConfiguredServletMapping(com.liferay.faces.util.config.ConfiguredServletMapping)

Aggregations

BridgeException (javax.portlet.faces.BridgeException)14 ExternalContext (javax.faces.context.ExternalContext)8 UnsupportedEncodingException (java.io.UnsupportedEncodingException)5 URISyntaxException (java.net.URISyntaxException)4 ViewHandler (javax.faces.application.ViewHandler)2 PortletMode (javax.portlet.PortletMode)2 BridgeInvalidViewPathException (javax.portlet.faces.BridgeInvalidViewPathException)2 BridgeNavigationHandler (com.liferay.faces.bridge.application.internal.BridgeNavigationHandler)1 CapturingWriter (com.liferay.faces.bridge.context.internal.CapturingWriter)1 WriterOperation (com.liferay.faces.bridge.context.internal.WriterOperation)1 EventPayloadWrapper (com.liferay.faces.bridge.event.EventPayloadWrapper)1 IPCPhaseListener (com.liferay.faces.bridge.event.internal.IPCPhaseListener)1 BridgeRequestScope (com.liferay.faces.bridge.scope.internal.BridgeRequestScope)1 ResourceValidator (com.liferay.faces.util.application.ResourceValidator)1 ConfiguredServletMapping (com.liferay.faces.util.config.ConfiguredServletMapping)1 Product (com.liferay.faces.util.product.Product)1 Serializable (java.io.Serializable)1 Writer (java.io.Writer)1 FacesException (javax.faces.FacesException)1 NavigationHandler (javax.faces.application.NavigationHandler)1