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);
}
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();
}
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;
}
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);
}
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;
}
Aggregations