Search in sources :

Example 21 with FacesContext

use of javax.faces.context.FacesContext in project Payara by payara.

the class RestUtil method restRequest.

public static Map<String, Object> restRequest(String endpoint, Map<String, Object> attrs, String method, HandlerContext handlerCtx, boolean quiet, boolean throwException) {
    boolean useData = false;
    Object data = null;
    if (attrs == null) {
        try {
            data = (handlerCtx == null) ? null : handlerCtx.getInputValue("data");
        } catch (Exception e) {
        // 
        }
        if (data != null) {
            // We'll send the raw data
            useData = true;
        } else {
            // Initialize the attributes to an empty map
            attrs = new HashMap<String, Object>();
        }
    }
    method = method.toLowerCase(new Locale("UTF-8"));
    Logger logger = GuiUtil.getLogger();
    if (logger.isLoggable(Level.FINEST)) {
        Map maskedAttr = maskOffPassword(attrs);
        logger.log(Level.FINEST, GuiUtil.getCommonMessage("LOG_REST_REQUEST_INFO", new Object[] { endpoint, (useData && "post".equals(method)) ? data : attrs, method }));
    }
    // Execute the request...
    RestResponse restResponse = null;
    if ("post".equals(method)) {
        if (useData) {
            restResponse = post(endpoint, data, (String) handlerCtx.getInputValue("contentType"));
        } else {
            restResponse = post(endpoint, attrs);
        }
    } else if ("put".equals(method)) {
        if (useData) {
            restResponse = put(endpoint, data, (String) handlerCtx.getInputValue("contentType"));
        } else {
            restResponse = put(endpoint, attrs);
        }
    } else if ("get".equals(method)) {
        restResponse = get(endpoint, attrs);
    } else if ("delete".equals(method)) {
        restResponse = delete(endpoint, attrs);
    } else {
        throw new RuntimeException(GuiUtil.getCommonMessage("rest.invalid_method", new Object[] { method }));
    }
    // invalidate the session and force the the user to log back in.
    if (restResponse.getResponseCode() == 401) {
        FacesContext fc = FacesContext.getCurrentInstance();
        HttpSession session = (HttpSession) fc.getExternalContext().getSession(false);
        HttpServletRequest request = (HttpServletRequest) fc.getExternalContext().getRequest();
        HttpServletResponse response = (HttpServletResponse) fc.getExternalContext().getResponse();
        if (!"/login.jsf".equals(request.getServletPath())) {
            try {
                response.sendRedirect("/");
                fc.responseComplete();
                session.invalidate();
            } catch (Exception ex) {
                throw new RuntimeException(ex);
            }
        }
    }
    return parseResponse(restResponse, handlerCtx, endpoint, (useData && "post".equals(method)) ? data : attrs, quiet, throwException);
}
Also used : Locale(java.util.Locale) FacesContext(javax.faces.context.FacesContext) HttpSession(javax.servlet.http.HttpSession) HttpServletResponse(javax.servlet.http.HttpServletResponse) Logger(java.util.logging.Logger) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SAXException(org.xml.sax.SAXException) HttpServletRequest(javax.servlet.http.HttpServletRequest) HashMap(java.util.HashMap) Map(java.util.Map) MultivaluedHashMap(javax.ws.rs.core.MultivaluedHashMap) MultivaluedMap(javax.ws.rs.core.MultivaluedMap) TreeMap(java.util.TreeMap)

Example 22 with FacesContext

use of javax.faces.context.FacesContext in project Payara by payara.

the class CommonHandlers method redirect.

/**
 *	<p> This handler redirects to the given page.</p>
 *
 *	<p> Input value: "page" -- Type: <code>String</code></p>
 *
 *	@param	context	The {@link HandlerContext}.
 */
@Handler(id = "gf.redirect", input = { @HandlerInput(name = "page", type = String.class, required = true) })
public static void redirect(HandlerContext context) {
    String page = (String) context.getInputValue("page");
    FacesContext ctx = context.getFacesContext();
    page = handleBareAttribute(ctx, page);
    // }
    try {
        // FIXME: Should be: ctx.getExternalContext().redirect(page);  See FIXME above.
        ((HttpServletResponse) ctx.getExternalContext().getResponse()).sendRedirect(page);
    } catch (IOException ex) {
        throw new RuntimeException("Unable to redirect to page '" + page + "'!", ex);
    }
    ctx.responseComplete();
}
Also used : FacesContext(javax.faces.context.FacesContext) HttpServletResponse(javax.servlet.http.HttpServletResponse) IOException(java.io.IOException) Handler(com.sun.jsftemplating.annotation.Handler)

Example 23 with FacesContext

use of javax.faces.context.FacesContext in project Payara by payara.

the class RestUtil method getRestToken.

/**
 * <p> This method returns the value of the REST token if it is successfully set in session scope.</p>
 * @return
 */
public static String getRestToken() {
    String token = null;
    FacesContext ctx = FacesContext.getCurrentInstance();
    if (ctx != null) {
        token = (String) ctx.getExternalContext().getSessionMap().get(AdminConsoleAuthModule.REST_TOKEN);
    }
    return token;
}
Also used : FacesContext(javax.faces.context.FacesContext)

Example 24 with FacesContext

use of javax.faces.context.FacesContext in project Payara by payara.

the class PluginHandlers method getContentOfIntegrationPoints.

/**
 *	Finds the integration point of the specified type.  Returns the contents of this IP type as a list.
 *  The content can be a comma separated String.
 * This is useful for the case such as dropdown or list box to allow additional options in the component.
 */
@Handler(id = "getContentOfIntegrationPoints", input = { @HandlerInput(name = "type", type = String.class, required = true) }, output = { @HandlerOutput(name = "labels", type = List.class), @HandlerOutput(name = "values", type = List.class) })
public static void getContentOfIntegrationPoints(HandlerContext handlerCtx) throws java.io.IOException {
    // Get the input
    String type = (String) handlerCtx.getInputValue("type");
    // Get the IntegrationPoints
    FacesContext ctx = handlerCtx.getFacesContext();
    Set<IntegrationPoint> points = getSortedIntegrationPoints(getIntegrationPoints(ctx, type));
    List labels = new ArrayList();
    List values = new ArrayList();
    if (points != null) {
        for (IntegrationPoint it : points) {
            String content = it.getContent();
            if (GuiUtil.isEmpty(content)) {
                GuiUtil.getLogger().warning("No Content specified for Integration Point: " + type + " id : " + it.getId());
                continue;
            }
            List<String> labelsAndValues = GuiUtil.parseStringList(content, "|");
            values.add(labelsAndValues.get(0));
            labels.add(GuiUtil.getMessage(labelsAndValues.get(1), labelsAndValues.get(2)));
        }
    }
    handlerCtx.setOutputValue("labels", labels);
    handlerCtx.setOutputValue("values", values);
}
Also used : FacesContext(javax.faces.context.FacesContext) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) IntegrationPoint(org.glassfish.admingui.connector.IntegrationPoint) Handler(com.sun.jsftemplating.annotation.Handler) LayoutViewHandler(com.sun.jsftemplating.layout.LayoutViewHandler)

Example 25 with FacesContext

use of javax.faces.context.FacesContext in project acs-community-packaging by Alfresco.

the class UserProfileDialogCommand method execute.

/**
 * @see org.alfresco.web.app.servlet.command.Command#execute(org.alfresco.service.ServiceRegistry, java.util.Map)
 */
public Object execute(ServiceRegistry serviceRegistry, Map<String, Object> properties) {
    ServletContext sc = (ServletContext) properties.get(PROP_SERVLETCONTEXT);
    ServletRequest req = (ServletRequest) properties.get(PROP_REQUEST);
    ServletResponse res = (ServletResponse) properties.get(PROP_RESPONSE);
    FacesContext fc = FacesHelper.getFacesContext(req, res, sc, "/jsp/close.jsp");
    UsersDialog dialog = (UsersDialog) FacesHelper.getManagedBean(fc, UsersDialog.BEAN_NAME);
    // setup dialog context from url args in properties map
    String personId = (String) properties.get(PROP_PERSONID);
    ParameterCheck.mandatoryString(PROP_PERSONID, personId);
    dialog.setupUserAction(personId);
    NavigationHandler navigationHandler = fc.getApplication().getNavigationHandler();
    navigationHandler.handleNavigation(fc, null, "dialog:userProfile");
    String viewId = fc.getViewRoot().getViewId();
    try {
        sc.getRequestDispatcher(BaseServlet.FACES_SERVLET + viewId).forward(req, res);
    } catch (Exception e) {
        throw new AlfrescoRuntimeException("Unable to forward to viewId: " + viewId, e);
    }
    return null;
}
Also used : ServletRequest(javax.servlet.ServletRequest) ServletResponse(javax.servlet.ServletResponse) FacesContext(javax.faces.context.FacesContext) ServletContext(javax.servlet.ServletContext) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) NavigationHandler(javax.faces.application.NavigationHandler) UsersDialog(org.alfresco.web.bean.users.UsersDialog) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException)

Aggregations

FacesContext (javax.faces.context.FacesContext)361 NodeRef (org.alfresco.service.cmr.repository.NodeRef)61 Node (org.alfresco.web.bean.repository.Node)44 UserTransaction (javax.transaction.UserTransaction)43 ArrayList (java.util.ArrayList)33 HashMap (java.util.HashMap)28 IOException (java.io.IOException)27 InvalidNodeRefException (org.alfresco.service.cmr.repository.InvalidNodeRefException)27 ExternalContext (javax.faces.context.ExternalContext)26 SelectItem (javax.faces.model.SelectItem)26 QName (org.alfresco.service.namespace.QName)25 FacesMessage (javax.faces.application.FacesMessage)24 ChildAssociationRef (org.alfresco.service.cmr.repository.ChildAssociationRef)22 Map (java.util.Map)21 ResourceBundle (java.util.ResourceBundle)20 HttpServletResponse (javax.servlet.http.HttpServletResponse)19 MapNode (org.alfresco.web.bean.repository.MapNode)18 UIViewRoot (javax.faces.component.UIViewRoot)17 HttpServletRequest (javax.servlet.http.HttpServletRequest)16 Serializable (java.io.Serializable)15