List of usage examples for javax.servlet ServletContext getRequestDispatcher
public RequestDispatcher getRequestDispatcher(String path);
From source file:com.ikon.servlet.admin.ReportServlet.java
/** * List reports parameters//from ww w. j a v a 2 s . c om */ private void paramList(String userId, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, DatabaseException, ParseException { log.debug("paramList({}, {}, {})", new Object[] { userId, request, response }); ServletContext sc = getServletContext(); int rpId = WebUtils.getInt(request, "rp_id"); List<FormElement> params = ReportUtils.getReportParameters(rpId); List<Map<String, String>> fMaps = new ArrayList<Map<String, String>>(); for (FormElement fe : params) { fMaps.add(FormUtils.toString(fe)); } sc.setAttribute("rp_id", rpId); sc.setAttribute("params", fMaps); sc.getRequestDispatcher("/admin/report_param_list.jsp").forward(request, response); log.debug("paramList: void"); }
From source file:com.zimbra.cs.service.ExternalUserProvServlet.java
@Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { String param = req.getParameter("p"); if (param == null) { throw new ServletException("request missing param"); }/*from w w w .j av a 2 s.co m*/ Map<Object, Object> tokenMap = validatePrelimToken(param); Map<String, String> reqHeaders = new HashMap<String, String>(); String ownerId = (String) tokenMap.get("aid"); String folderId = (String) tokenMap.get("fid"); String extUserEmail = (String) tokenMap.get("email"); Provisioning prov = Provisioning.getInstance(); Account grantee; try { Account owner = prov.getAccountById(ownerId); Domain domain = prov.getDomain(owner); grantee = prov.getAccountByName(mapExtEmailToAcctName(extUserEmail, domain)); if (grantee == null) { // external virtual account not created yet if (prov.isOctopus() && DebugConfig.skipVirtualAccountRegistrationPage) { // provision using 'null' password and display name // UI will ask the user to set these post provisioning provisionVirtualAccountAndRedirect(req, resp, null, null, ownerId, extUserEmail); } else { resp.addCookie(new Cookie("ZM_PRELIM_AUTH_TOKEN", param)); req.setAttribute("extuseremail", extUserEmail); if (WebClientServiceUtil.isServerInSplitMode()) { reqHeaders.put("extuseremail", extUserEmail); reqHeaders.put("ZM_PRELIM_AUTH_TOKEN", param); String htmlresp = WebClientServiceUtil .sendServiceRequestToOneRandomUiNode(EXT_USER_PROV_ON_UI_NODE, reqHeaders); resp.getWriter().print(htmlresp); } else { ServletContext context = getServletContext().getContext("/zimbra"); if (context != null) { RequestDispatcher dispatcher = context.getRequestDispatcher(PUBLIC_EXTUSERPROV_JSP); dispatcher.forward(req, resp); } else { logger.warn("Could not access servlet context url /zimbra"); throw ServiceException.TEMPORARILY_UNAVAILABLE(); } } } } else { // create a new mountpoint in the external user's mailbox if not already created String[] sharedItems = owner.getSharedItem(); int sharedFolderId = Integer.valueOf(folderId); String sharedFolderPath = null; MailItem.Type sharedFolderView = null; for (String sharedItem : sharedItems) { ShareInfoData sid = AclPushSerializer.deserialize(sharedItem); if (sid.getItemId() == sharedFolderId && extUserEmail.equalsIgnoreCase(sid.getGranteeId())) { sharedFolderPath = sid.getPath(); sharedFolderView = sid.getFolderDefaultViewCode(); break; } } if (sharedFolderPath == null) { throw new ServletException("share not found"); } String mountpointName = getMountpointName(owner, grantee, sharedFolderPath); ZMailbox.Options options = new ZMailbox.Options(); options.setNoSession(true); options.setAuthToken(AuthProvider.getAuthToken(grantee).toZAuthToken()); options.setUri(AccountUtil.getSoapUri(grantee)); ZMailbox zMailbox = new ZMailbox(options); ZMountpoint zMtpt = null; try { zMtpt = zMailbox.createMountpoint(String.valueOf(getMptParentFolderId(sharedFolderView, prov)), mountpointName, ZFolder.View.fromString(sharedFolderView.toString()), ZFolder.Color.DEFAULTCOLOR, null, ZMailbox.OwnerBy.BY_ID, ownerId, ZMailbox.SharedItemBy.BY_ID, folderId, false); } catch (ServiceException e) { logger.debug("Error in attempting to create mountpoint. Probably it already exists.", e); } if (zMtpt != null) { if (sharedFolderView == MailItem.Type.APPOINTMENT) { // make sure that the mountpoint is checked in the UI by default FolderActionSelector actionSelector = new FolderActionSelector(zMtpt.getId(), "check"); FolderActionRequest actionRequest = new FolderActionRequest(actionSelector); try { zMailbox.invokeJaxb(actionRequest); } catch (ServiceException e) { logger.warn("Error in invoking check action on calendar mountpoint", e); } } HashSet<MailItem.Type> types = new HashSet<MailItem.Type>(); types.add(sharedFolderView); enableAppFeatures(grantee, types); } // check if the external user is already logged-in String zAuthTokenCookie = null; javax.servlet.http.Cookie cookies[] = req.getCookies(); if (cookies != null) { for (Cookie cookie : cookies) { if (cookie.getName().equals("ZM_AUTH_TOKEN")) { zAuthTokenCookie = cookie.getValue(); break; } } } AuthToken zAuthToken = null; if (zAuthTokenCookie != null) { try { zAuthToken = AuthProvider.getAuthToken(zAuthTokenCookie); } catch (AuthTokenException ignored) { // auth token is not valid } } if (zAuthToken != null && !zAuthToken.isExpired() && zAuthToken.isRegistered() && grantee.getId().equals(zAuthToken.getAccountId())) { // external virtual account already logged-in resp.sendRedirect("/"); } else if (prov.isOctopus() && !grantee.isVirtualAccountInitialPasswordSet() && DebugConfig.skipVirtualAccountRegistrationPage) { // seems like the virtual user did not set his password during his last visit, after an account was // provisioned for him setCookieAndRedirect(req, resp, grantee); } else { req.setAttribute("virtualacctdomain", domain.getName()); if (WebClientServiceUtil.isServerInSplitMode()) { reqHeaders.put("virtualacctdomain", domain.getName()); String htmlresp = WebClientServiceUtil .sendServiceRequestToOneRandomUiNode(PUBLIC_LOGIN_ON_UI_NODE, reqHeaders); resp.getWriter().print(htmlresp); } else { RequestDispatcher dispatcher = getServletContext().getContext("/zimbra") .getRequestDispatcher(PUBLIC_LOGIN_JSP); dispatcher.forward(req, resp); } } } } catch (ServiceException e) { throw new ServletException(e); } }
From source file:com.ikon.servlet.admin.OmrServlet.java
/** * edit type record/*from w w w. jav a 2 s . c o m*/ */ private void edit(String userId, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, DatabaseException, ParseException, RepositoryException { log.debug("edit({}, {}, {})", new Object[] { userId, request, response }); ServletContext sc = getServletContext(); long omId = WebUtils.getLong(request, "om_id"); sc.setAttribute("action", WebUtils.getString(request, "action")); sc.setAttribute("om", OmrDAO.getInstance().findByPk(omId)); sc.setAttribute("properties", PropertyGroupUtils.getAllGroupsProperties()); sc.getRequestDispatcher("/admin/omr_edit.jsp").forward(request, response); log.debug("edit: void"); }
From source file:com.ikon.servlet.admin.MimeTypeServlet.java
/** * Delete mime type//from w w w .j a v a2 s .c o m */ private void delete(String userId, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, DatabaseException { log.debug("delete({}, {}, {})", new Object[] { userId, request, response }); ServletContext sc = getServletContext(); int mtId = WebUtils.getInt(request, "mt_id"); MimeType mt = MimeTypeDAO.findByPk(mtId); String extensions = ""; for (String ext : mt.getExtensions()) { extensions += ext + " "; } sc.setAttribute("action", WebUtils.getString(request, "action")); sc.setAttribute("extensions", extensions.trim()); sc.setAttribute("mt", mt); sc.getRequestDispatcher("/admin/mime_edit.jsp").forward(request, response); log.debug("delete: void"); }
From source file:com.ikon.servlet.admin.MimeTypeServlet.java
/** * Edit mime type//from w w w . j a va2 s . c om */ private void edit(String userId, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, DatabaseException { log.debug("edit({}, {}, {})", new Object[] { userId, request, response }); ServletContext sc = getServletContext(); int mtId = WebUtils.getInt(request, "mt_id"); MimeType mt = MimeTypeDAO.findByPk(mtId); String extensions = ""; for (String ext : mt.getExtensions()) { extensions += ext + " "; } sc.setAttribute("action", WebUtils.getString(request, "action")); sc.setAttribute("extensions", extensions.trim()); sc.setAttribute("mt", mt); sc.getRequestDispatcher("/admin/mime_edit.jsp").forward(request, response); log.debug("edit: void"); }
From source file:org.esigate.servlet.ServletExtension.java
@Override public boolean event(EventDefinition id, Event event) { FetchEvent fetchEvent = (FetchEvent) event; if (EventManager.EVENT_FETCH_PRE.equals(id)) { String uriString = fetchEvent.getHttpRequest().getRequestLine().getUri(); OutgoingRequest outgoingRequest = OutgoingRequestContext.adapt(fetchEvent.getHttpContext()) .getOutgoingRequest();//from ww w .jav a 2 s . c o m IncomingRequest incomingRequest = outgoingRequest.getOriginalRequest().getOriginalRequest(); String baseUrl = outgoingRequest.getBaseUrl().toString(); if (outgoingRequest.getOriginalRequest().isExternal()) { // Non local absolute uri return true; } else { String relUrl = uriString; if (UriUtils.isAbsolute(relUrl)) { relUrl = relUrl.substring(UriUtils.extractHost(relUrl).toURI().length()); } relUrl = relUrl.substring(UriUtils.getPath(baseUrl).length()); if (!relUrl.startsWith("/")) { relUrl = "/" + relUrl; } ContainerRequestContext requestContext = outgoingRequest.getContainerRequestContext(); CloseableHttpResponse result; if (!(requestContext instanceof HttpServletRequestContext)) { String message = ServletExtension.class.getName() + " can be used only inside a java servlet engine"; result = HttpErrorPage.generateHttpResponse(HttpStatus.SC_BAD_GATEWAY, message); } else { HttpServletRequestContext httpServletRequestContext = (HttpServletRequestContext) requestContext; try { if (fetchEvent.getHttpContext().isProxy()) { ResponseCapturingWrapper wrappedResponse = new ResponseCapturingWrapper( httpServletRequestContext.getResponse(), driver.getContentTypeHelper(), true, maxObjectSize, responseSender, incomingRequest); if (context == null) { httpServletRequestContext.getFilterChain() .doFilter(httpServletRequestContext.getRequest(), wrappedResponse); result = wrappedResponse.getCloseableHttpResponse(); } else { ServletContext crossContext = httpServletRequestContext.getServletContext() .getContext(context); if (crossContext == null) { String message = "Context " + context + " does not exist or cross context disabled"; result = HttpErrorPage.generateHttpResponse(HttpStatus.SC_BAD_GATEWAY, message); } else { crossContext.getRequestDispatcher(relUrl) .forward(httpServletRequestContext.getRequest(), wrappedResponse); result = wrappedResponse.getCloseableHttpResponse(); } } } else { ResponseCapturingWrapper wrappedResponse = new ResponseCapturingWrapper( httpServletRequestContext.getResponse(), driver.getContentTypeHelper(), false, maxObjectSize, responseSender, incomingRequest); if (context == null) { httpServletRequestContext.getRequest().getRequestDispatcher(relUrl) .forward(httpServletRequestContext.getRequest(), wrappedResponse); result = wrappedResponse.getCloseableHttpResponse(); } else { ServletContext crossContext = httpServletRequestContext.getServletContext() .getContext(context); if (crossContext == null) { String message = "Context " + context + " does not exist or cross context disabled"; result = HttpErrorPage.generateHttpResponse(HttpStatus.SC_BAD_GATEWAY, message); } else { crossContext.getRequestDispatcher(relUrl) .include(httpServletRequestContext.getRequest(), wrappedResponse); result = wrappedResponse.getCloseableHttpResponse(); } } } } catch (IOException | ServletException e) { result = HttpErrorPage.generateHttpResponse(e); } } fetchEvent.setHttpResponse(result); // Stop execution fetchEvent.setExit(true); } } return true; }
From source file:com.openkm.servlet.admin.StampServlet.java
/** * New image stamp//from w ww .java2 s .co m */ private void imageCreate(Session session, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, DatabaseException { log.debug("imageCreate({}, {}, {})", new Object[] { session, request, response }); ServletContext sc = getServletContext(); sc.setAttribute("action", WebUtils.getString(request, "action")); sc.setAttribute("persist", true); sc.setAttribute("users", AuthDAO.findAllUsers(true)); sc.setAttribute("stamp", new StampImage()); sc.getRequestDispatcher("/admin/stamp_image_edit.jsp").forward(request, response); log.debug("imageCreate: void"); }
From source file:org.pentaho.di.baserver.utils.web.HttpConnectionHelper.java
protected Response invokePlatformEndpoint(final String endpointPath, final String httpMethod, final Map<String, String> queryParameters) { Response response = new Response(); // get servlet context and request dispatcher ServletContext servletContext = null; RequestDispatcher requestDispatcher = null; try {//from w w w . ja va 2 s . c om Object context = getContext(); if (context instanceof ServletContext) { servletContext = (ServletContext) context; requestDispatcher = servletContext.getRequestDispatcher("/api" + endpointPath); } } catch (NoClassDefFoundError ex) { logger.error("Failed to get application servlet context", ex); return response; } if (requestDispatcher != null) { // create servlet request URL fullyQualifiedServerURL; try { fullyQualifiedServerURL = getUrl(); } catch (MalformedURLException e) { logger.error("FullyQualifiedServerURL is incorrect"); return response; } final InternalHttpServletRequest servletRequest = new InternalHttpServletRequest(httpMethod, fullyQualifiedServerURL, "/api", endpointPath); servletRequest.setAttribute("org.apache.catalina.core.DISPATCHER_TYPE", DispatcherType.FORWARD); //FORWARD = 2 try { insertParameters(httpMethod, queryParameters, servletRequest); } catch (UnsupportedEncodingException e) { logger.error("Can't encode parameters"); return response; } ServletRequestEvent servletRequestEvent = new ServletRequestEvent(servletContext, servletRequest); RequestContextListener requestContextListener = new RequestContextListener(); requestContextListener.requestInitialized(servletRequestEvent); // create servlet response ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); final InternalHttpServletResponse servletResponse = new InternalHttpServletResponse(outputStream); try { // used for calculating the response time long startTime = System.currentTimeMillis(); requestDispatcher.forward(servletRequest, servletResponse); // get response time long responseTime = System.currentTimeMillis() - startTime; response.setStatusCode(servletResponse.getStatus()); response.setResult(servletResponse.getContentAsString()); response.setResponseTime(responseTime); } catch (ServletException ex) { logger.error("Failed ", ex); return response; } catch (IOException ex) { logger.error("Failed ", ex); return response; } finally { requestContextListener.requestDestroyed(servletRequestEvent); } } return response; }
From source file:com.ikon.servlet.admin.LanguageServlet.java
/** * Create language/*from ww w .j a va2s . c o m*/ */ private void addTranslation(String userId, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, DatabaseException { log.debug("addTranslation({}, {}, {})", new Object[] { userId, request, response }); if (WebUtils.getBoolean(request, "persist")) { Language lang = LanguageDAO.findByPk(Language.DEFAULT); Translation trans = new Translation(); trans.getTranslationId().setModule(WebUtils.getString(request, "tr_module")); trans.getTranslationId().setKey(WebUtils.getString(request, "tr_key")); trans.getTranslationId().setLanguage(lang.getId()); trans.setText(WebUtils.getString(request, "tr_text")); lang.getTranslations().add(trans); LanguageDAO.update(lang); } List<String> modules = new ArrayList<String>(); modules.add(Translation.MODULE_FRONTEND); modules.add(Translation.MODULE_EXTENSION); modules.add(Translation.MODULE_ADMINISTRATION); ServletContext sc = getServletContext(); sc.setAttribute("action", WebUtils.getString(request, "action")); sc.setAttribute("persist", true); sc.setAttribute("tr_module", modules); sc.setAttribute("tr_key", ""); sc.setAttribute("tr_text", ""); sc.setAttribute("lang", LanguageDAO.findByPk(Language.DEFAULT)); sc.getRequestDispatcher("/admin/translation_add.jsp").forward(request, response); log.debug("addTranslation: void"); }
From source file:com.openkm.servlet.admin.StampServlet.java
/** * New text stamp//w w w . j av a 2s . c o m */ private void textCreate(Session session, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, DatabaseException { log.debug("textCreate({}, {}, {})", new Object[] { session, request, response }); if (WebUtils.getBoolean(request, "persist")) { StampText st = new StampText(); st.setName(WebUtils.getString(request, "st_name")); st.setDescription(WebUtils.getString(request, "st_description")); st.setText(WebUtils.getString(request, "st_text")); st.setLayer(WebUtils.getInt(request, "st_layer")); st.setOpacity(WebUtils.getFloat(request, "st_opacity")); st.setSize(WebUtils.getInt(request, "st_size")); st.setColor(WebUtils.getString(request, "st_color")); st.setAlign(WebUtils.getInt(request, "st_align")); st.setRotation(WebUtils.getInt(request, "st_rotation")); st.setExprX(WebUtils.getString(request, "st_expr_x")); st.setExprY(WebUtils.getString(request, "st_expr_y")); st.setActive(WebUtils.getBoolean(request, "st_active")); st.setUsers(new HashSet<String>(WebUtils.getStringList(request, "st_users"))); int id = StampTextDAO.create(st); // Activity log UserActivity.log(session.getUserID(), "ADMIN_STAMP_TEXT_CREATE", Integer.toString(id), st.toString()); } else { ServletContext sc = getServletContext(); sc.setAttribute("action", WebUtils.getString(request, "action")); sc.setAttribute("persist", true); sc.setAttribute("users", AuthDAO.findAllUsers(true)); sc.setAttribute("stamp", new StampText()); sc.getRequestDispatcher("/admin/stamp_text_edit.jsp").forward(request, response); } log.debug("textCreate: void"); }