Package javax.portlet.faces

Examples of javax.portlet.faces.BridgeException


    }
    if (null == response) {
      throw new NullPointerException("Response parameter is null");
    }
    if (!isInitialized()) {
      throw new BridgeException("JSF Portlet bridge is not initialized");
    }

    if (log.isLoggable(Level.FINE)) {
      log.fine("Start bridge render request processing for portlet "
          + getPortletName());
    }
    BufferedRenderResponseWrapper wrappedResponse = new BufferedRenderResponseWrapper(
        response);

    initRequest(request, wrappedResponse, Bridge.PortletPhase.RenderPhase);
    String namespace = wrappedResponse.getNamespace();
    StateId stateId = getStateHolder().getStateId(getPortletName(),
        request, namespace);

    PortletWindowState windowState = getStateHolder().getWindowState(
        stateId);
    if (null == windowState) {
      windowState = new PortletWindowState() {

        @Override
        public BridgeConfig getBridgeConfig() {
          return AjaxPortletBridge.this;
        }

      };
      getStateHolder().addWindowState(stateId, windowState);
    }
    PortletBridgeContext bridgeContext = createBridgeContext(request,
        windowState);
    bridgeContext.setStateId(stateId);

    FacesContext facesContext = getFacesContext(request, wrappedResponse);


    try {
      windowState.restoreRequest(facesContext, true);
      // If we're using RichFaces, setup proper parameters for this render
      // request
      if (RICHFACES_ENABLED) {
        setupAjaxParams(facesContext, stateId.toString(), namespace);
      }
      // set portletbridge title if its set.
      ResourceBundle bundle = portletConfig.getResourceBundle(request
          .getLocale());
      if (bundle != null) {
        String title = null;
        try {
          title = bundle.getString("javax.portlet.title");
          wrappedResponse.setTitle(title);
        } catch (Exception e) {
          // Ignore MissingResourceException
        }
      }

      try {

        renderResponse(facesContext, windowState);
        // TODO - detect redirect case. Reset response, clear request
        // variables as far as Seam state.
        // Perform new render phase with a new ViewId.
        String redirectViewId = bridgeContext.getRedirectViewId();
        if (null != redirectViewId) {
          windowState.reset();
          windowState.setViewId(redirectViewId);

          Map<String, String[]> redirectParams = bridgeContext
              .getRedirectRequestParameters();

          // release old FacesContext.
          facesContext.release();
          // Reset attributes to initial state
          Set<String> initialAttributes = bridgeContext
              .getInitialRequestAttributeNames();
          List<String> currentAttributes = Collections.list(request
              .getAttributeNames());
          currentAttributes.removeAll(initialAttributes);
          for (Object newAttribute : currentAttributes) {
            request.removeAttribute((String) newAttribute);
          }
          if (redirectParams != null) {
            windowState.setRequestParameters(redirectParams);
          }

          // Create new FacesContext
          facesContext = getFacesContext(request, wrappedResponse);
          ViewHandler viewHandler = facesContext.getApplication()
              .getViewHandler();
          UIViewRoot viewRoot = viewHandler.createView(facesContext,
              redirectViewId);
          facesContext.setViewRoot(viewRoot);
          renderResponse(facesContext, windowState);
        }
        windowState.setViewId(facesContext.getViewRoot().getViewId());
      } catch (Exception e) {
        wrappedResponse.reset();
        log.log(Level.SEVERE, "Error processing execute lifecycle", e);
        exceptionHandler.processRenderException(facesContext,
            windowState, e);
      }
      // Set important Portal parameters to window state.
      String viewId = facesContext.getViewRoot().getViewId();
      //
      String actionURL = facesContext.getApplication().getViewHandler()
          .getActionURL(facesContext, viewId);
      actionURL = facesContext.getExternalContext().encodeActionURL(
          actionURL);
      windowState.setPortalActionURL(new PortalActionURL(actionURL));

      PortletURL portletURL = wrappedResponse.createRenderURL();
      portletURL.setParameter(PortletStateHolder.STATE_ID_PARAMETER,
          stateId.toString());
      String renderUrl = portletURL.toString();
      windowState.setPortalRenderURL(new PortalActionURL(renderUrl));
      windowState.setNamespace(namespace);
      windowState.setPortletLocale(request.getLocale());
      // TODO - encode request attributes, portlet mode and windowId, as
      // required by JSR-301 5.3.3
      String portletModeName = request.getPortletMode().toString();
      PortalActionURL historyViewId = new PortalActionURL(viewId);
      historyViewId.setParameter(PortletStateHolder.STATE_ID_PARAMETER,
          stateId.toString());
      historyViewId.setParameter(Bridge.PORTLET_MODE_PARAMETER,
          portletModeName);
      facesContext.getExternalContext().getSessionMap().put(
          VIEWID_HISTORY_PREFIX + portletModeName,
          historyViewId.toString());
      // writer.println("</div>");
      windowState.saveSeamConversationId(facesContext);
      // PortletSession portletSession = request.getPortletSession(true);
      PortletSession portletSession = (PortletSession) facesContext
          .getExternalContext().getSession(true);
      WindowIDRetriver idRetriver = (WindowIDRetriver) portletSession
          .getAttribute(PortletStateHolder.WINDOW_ID_RETRIVER);

      if (null != idRetriver) {
        windowState.setWindowId(idRetriver.getWindowID());
      }
      PortletBridgePrincipal security = new PortletBridgePrincipal(request,userRoles);
      // TODO - get user roles, defined in the portletbridge.xml ( ???
      // parse it ??? ), and store all values for a
      // "isUserInRole(roleName)" calls
      portletSession.setAttribute(
          AbstractExternalContext.PORTAL_USER_PRINCIPAL,
          security, PortletSession.APPLICATION_SCOPE);
      if (log.isLoggable(Level.FINE)) {
        log.fine("Finish rendering portletbridge for namespace "
            + namespace);
      }
      // Disable portletbridge caching.
      // TODO - detect ajax components on page, static views can be
      // cached.
      wrappedResponse.setProperty(RenderResponse.EXPIRATION_CACHE, "0");

      if (RICHFACES_ENABLED) {
        richFacesHelper
            .getCurrentInstance();
        Object headEvents = request.getAttribute(AjaxContext.HEAD_EVENTS_PARAMETER);

        if (headEvents != null) {
          Node[] nodes = (Node[]) headEvents;

          Properties xhtmlProperties = OutputPropertiesFactory
              .getDefaultMethodProperties(Method.XHTML);
          Serializer serializer = SerializerFactory
              .getSerializer(xhtmlProperties);

          if (wrappedResponse.isUseWriter()) {
            serializer.setWriter(response.getWriter());
          } else {
            serializer.setOutputStream(response
                .getPortletOutputStream());
          }

          ContentHandler contentHandler = serializer
              .asContentHandler();
          TreeWalker treeWalker = new TreeWalker(contentHandler);

          contentHandler.startDocument();

          for (Node node : nodes) {
            treeWalker.traverseFragment(node);
          }

          contentHandler.endDocument();
        }
      }

      wrappedResponse.writeBufferedData();
    } catch (Exception e) {
      throw new BridgeException(e);
    } finally {
      facesContext.release();
    }
  }
View Full Code Here


    try {
      PortalActionURL viewIdUrl = new PortalActionURL(viewId);
      viewIdUrl.addParameter(Bridge.PORTLET_MODE_PARAMETER, mode);
      return viewIdUrl.toString();
    } catch (MalformedURLException e) {
      throw new BridgeException("Malformed ViewId",e);
    }
  }
View Full Code Here

         mode = new PortletMode(stateId.substring(0, modeEnd));
         uuid = stateId.substring(modeEnd + 1);
      }
      else
      {
         throw new BridgeException("Invalid StateId format");
      }
   }
View Full Code Here

      return windowMessageMap;
    } catch (Exception ehe) {
      log.error(
              "Unable to process exception with Seam exception handler",
              ehe);
      throw new BridgeException(ehe);
    } finally {
      // Finally, clean up the contexts
      try {
//        ExternalContext externalContext = facesContext
//                .getExternalContext();
View Full Code Here

        writeAjaxContent(facesContext, wrappedResponse);
      } else {
        writeContent(facesContext, wrappedResponse);
      }
    } catch (Exception e) {
      throw new BridgeException(e);
    }
  }
View Full Code Here

          // TODO - cache ?
          request.setAttribute(RICHFACES_RESOURCE, resource);
          lifecycle.send(resourceContext, resource);
          request.removeAttribute(RICHFACES_RESOURCE);
        } catch (IOException e) {
          throw new BridgeException(e);
        } finally {
          resourceContext.release();
        }
        return true;

      } catch (ResourceNotFoundException e) {
        return false;
      }
    } else { // Handle File Upload
        if(isMultipartContent(request)) {
        String uid = request
                .getParameter(FileUploadConstants.UPLOAD_FILES_ID);
        MultipartRequest multipartRequest;
        // RichFaces 3.3.1 & 3.3.3 uses different signatures in
        // constructor, so use reflection to create instance.
        try {
          try {
            Constructor<MultipartRequest> constructor = MultipartRequest.class
                    .getConstructor(HttpServletRequest.class,
                            boolean.class, int.class, String.class);
            multipartRequest = constructor.newInstance(
                    new ResourceRequestWrapper(request),
                    uploadToTempDir, uploadLimit, uid);
          } catch (NoSuchMethodException e) {
            // 3.3.1, add temp dir parameter.
            Constructor<MultipartRequest> constructor = MultipartRequest.class
                    .getConstructor(HttpServletRequest.class,
                            boolean.class, String.class, int.class,
                            String.class);
            multipartRequest = constructor.newInstance(
                    new ResourceRequestWrapper(request),
                    uploadToTempDir, null, uploadLimit, uid);
          }
        } catch (Exception e) {
          throw new BridgeException(
                  "Cannot create MultipartRequest instance", e);
        }
        request.setAttribute(
                FileUploadConstants.FILE_UPLOAD_REQUEST_ATTRIBUTE_NAME,
                multipartRequest);
View Full Code Here

        if(log.isLoggable(Level.FINE)){
          log.fine("New strategy instance "+className+ " has been created");
        }
      }
    } catch (ClassNotFoundException e) {
      throw new BridgeException("Bridge Strategy class "+className+" not found");
    } catch (NoSuchMethodException e) {
      throw new BridgeException("Bridge Strategy "+className+" has never BridgeStrategy(BridgeConfig) nor BridgeStrategy(BridgeConfig,BridgeStrategy) constructor");
    } catch (IllegalArgumentException e) {
      throw new BridgeException("Illegal argument for Bridge Strategy "+className+" constructor",e);
    } catch (InstantiationException e) {
      throw new BridgeException("Can't instantiate Bridge Strategy class "+className,e);
    } catch (IllegalAccessException e) {
      throw new BridgeException("Illegal access to Bridge Strategy constructor",e);
    } catch (InvocationTargetException e) {
      Throwable targetException = e.getTargetException();
      if (targetException instanceof NoClassDefFoundError) {
        log.info("Bridge Strategy was not activated due to "
                + targetException.getMessage());
      } else {
        throw new BridgeException("Can't instantiate Bridge Strategy class "+className,targetException);
      }
    } catch( NoClassDefFoundError e){
      log.info("Bridge Strategy was not activated due to "
              + e.getMessage());     
    }
View Full Code Here

              .getExternalContext().getRequest();
      bridgeContext.resetRequestAttributes(request);
      windowState.restoreBeans(context);
      renderErrorPage(context, windowState, e, redirectViewId);
    } else {
      throw new BridgeException("Error processing render lifecycle", e);
    }
  }
View Full Code Here

                      .getInitParameter(
                              HANDLE_VIEW_EXPIRED_ON_CLIENT));
      if (handleViewExpiredOnClient && isViewExpired(e)) {
        sendAjaxViewExpired(facesContext, e);
      } else {
        throw new BridgeException("Error processing resource lifecycle",
                e);
      }
    }
  }
View Full Code Here

                        + message
                        + "\" />"
                        + "</head></html>");
        output.flush();
      } catch (IOException e1) {
        throw new BridgeException("Error render Ajax-expired content",
                e);
      }
    }
View Full Code Here

TOP

Related Classes of javax.portlet.faces.BridgeException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.