@Override @Nullable public Object getAttribute(String name, int scope) { Assert.notNull(name, "Attribute name must not be null"); switch (scope) { case PAGE_SCOPE: return getAttribute(name); case REQUEST_SCOPE: return this.request.getAttribute(name); case SESSION_SCOPE: HttpSession session = this.request.getSession(false); return (session != null ? session.getAttribute(name) : null); case APPLICATION_SCOPE: return this.servletContext.getAttribute(name); default: throw new IllegalArgumentException("Invalid scope: " + scope); } }
@Override public void call(HttpServletRequest request, HttpServletResponse response) throws IOException { HttpSession session = request.getSession(); // Hack to expose the session to our test context session.getServletContext().setAttribute("session", session); session.setAttribute("lastAccessTime", session.getLastAccessedTime()); try { Thread.sleep(100); } catch (InterruptedException ex) { } session.setAttribute("somethingElse", 1); request.getSession(); response.getWriter().write("done"); } };
public String getInitParameter(String name) { String param = initParams.get(name); if (param == null) { param = sc.getInitParameter(name); if (param == null && useServletContextParameters) { param = sc.getServletContext().getInitParameter(name); } } return param; }
@Override public Object get(String name, ObjectFactory<?> objectFactory) { Object scopedObject = this.servletContext.getAttribute(name); if (scopedObject == null) { scopedObject = objectFactory.getObject(); this.servletContext.setAttribute(name, scopedObject); } return scopedObject; }
@Override public boolean isFile() { try { URL url = this.servletContext.getResource(this.path); if (url != null && ResourceUtils.isFileURL(url)) { return true; } else { return (this.servletContext.getRealPath(this.path) != null); } } catch (MalformedURLException ex) { return false; } }
/** * Close Spring's web application context for the given servlet context. * <p>If overriding {@link #loadParentContext(ServletContext)}, you may have * to override this method as well. * @param servletContext the ServletContext that the WebApplicationContext runs in */ public void closeWebApplicationContext(ServletContext servletContext) { servletContext.log("Closing Spring root WebApplicationContext"); try { if (this.context instanceof ConfigurableWebApplicationContext) { ((ConfigurableWebApplicationContext) this.context).close(); } } finally { ClassLoader ccl = Thread.currentThread().getContextClassLoader(); if (ccl == ContextLoader.class.getClassLoader()) { currentContext = null; } else if (ccl != null) { currentContextPerThread.remove(ccl); } servletContext.removeAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE); } }
@Override protected void doGet(final HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException { String idp = request.getParameter(Constants.PARAM_IDP); SyncopeClient anonymous = (SyncopeClient) request.getServletContext(). getAttribute(Constants.SYNCOPE_ANONYMOUS_CLIENT); try { SAML2RequestTO requestTO = anonymous.getService(SAML2SPService.class).createLoginRequest( StringUtils.substringBefore(request.getRequestURL().toString(), "/saml2sp"), idp); prepare(response, requestTO); } catch (Exception e) { LOG.error("While preparing authentication request to IdP", e); String errorURL = getServletContext().getInitParameter(Constants.CONTEXT_PARAM_LOGIN_ERROR_URL); if (errorURL == null) { request.setAttribute("exception", e); request.getRequestDispatcher("loginError.jsp").forward(request, response); e.printStackTrace(response.getWriter()); } else { response.sendRedirect(errorURL + "?errorMessage=" + URLEncoder.encode(e.getMessage(), StandardCharsets.UTF_8)); } } } }
response.setContentType("text/html;charset=UTF-8"); pageContext = _jspxFactory.getPageContext(this, request, response, null, true, 8192, true); out = pageContext.getOut(); _jspx_out = out; _jspx_resourceInjector = (org.glassfish.jsp.api.ResourceInjector) application.getAttribute("com.sun.appserv.jsp.resource.injector"); HMaster master = (HMaster)getServletContext().getAttribute(HMaster.MASTER); ZKWatcher watcher = master.getZooKeeper(); org.apache.jasper.runtime.JspRuntimeLibrary.include(request, response, "header.jsp" + "?" + org.apache.jasper.runtime.JspRuntimeLibrary.URLEncode("pageTitle", request.getCharacterEncoding())+ "=" + org.apache.jasper.runtime.JspRuntimeLibrary.URLEncode("Zookeeper Dump", request.getCharacterEncoding()), out, false); out.write("\n <div class=\"container-fluid content\">\n <div class=\"row inner_header\">\n <div class=\"page-header\">\n <h1>ZooKeeper Dump</h1>\n </div>\n </div>\n <div class=\"row\">\n <div class=\"span12\">\n <pre>"); out.print( StringEscapeUtils.escapeHtml4(ZKUtil.dump(watcher).trim()) ); out.clearBuffer(); if (_jspx_page_context != null) _jspx_page_context.handlePageException(t); else throw new ServletException(t);
throws ServletException, IOException { String op = request.getParameter(Constants.PARAM_OP); SyncopeClient anonymous = (SyncopeClient) request.getServletContext(). getAttribute(Constants.SYNCOPE_ANONYMOUS_CLIENT); try { String redirectURI = StringUtils.substringBefore(request.getRequestURL().toString(), "/login") + "/code-consumer"; OIDCLoginRequestTO requestTO = anonymous.getService(OIDCClientService.class). createLoginRequest(redirectURI, op); request.getSession().setAttribute(OIDCConstants.STATE, requestTO.getState()); request.getSession().setAttribute(OIDCConstants.OP, op); response.setHeader(HttpHeaders.CACHE_CONTROL, "no-cache, no-store"); response.setHeader("Pragma", "no-cache"); response.setStatus(HttpServletResponse.SC_SEE_OTHER); LOG.error("While preparing the Authentication Request", e); String errorURL = getServletContext().getInitParameter(Constants.CONTEXT_PARAM_LOGIN_ERROR_URL); if (errorURL == null) { request.setAttribute("exception", e); request.getRequestDispatcher("loginError.jsp").forward(request, response); e.printStackTrace(response.getWriter());
private void doAuthentication(HttpServletRequest req, HttpServletResponse resp) throws EntitlementCacheUpdateServletException { String username = req.getParameter(USERNAME_STRING); String password = req.getParameter(PSWD_STRING); String remoteIp = req.getServerName(); if (authenticate(username, password, remoteIp)) { RequestDispatcher requestDispatcher = req.getRequestDispatcher(UPDATE_CACHE); String subjectScope = EntitlementCacheUpdateServletDataHolder.getInstance().getServletConfig().getServletContext() .getInitParameter(SUBJECT_SCOPE); String subjectAttributeName = EntitlementCacheUpdateServletDataHolder.getInstance().getServletConfig().getServletContext() .getInitParameter("subjectAttributeName"); if (subjectScope.equals(EntitlementConstants.REQUEST_PARAM)) { requestDispatcher = req.getRequestDispatcher(UPDATE_CACHE + "?" + subjectAttributeName + "=" + username); } else if (subjectScope.equals(EntitlementConstants.REQUEST_ATTIBUTE)) { req.setAttribute(subjectAttributeName, username); } else if (subjectScope.equals(EntitlementConstants.SESSION)) { req.getSession().setAttribute(subjectAttributeName, username); } else { resp.setHeader("Authorization", Base64Utils.encode((username + ":" + password).getBytes(Charset.forName("UTF-8")))); } try { requestDispatcher.forward(req, resp); } catch (Exception e) { log.error("Error occurred while dispatching request to /updateCacheAuth.do", e); throw new EntitlementCacheUpdateServletException("Error occurred while dispatching request to /updateCacheAuth.do", e); } } else { showAuthPage(req, resp); } }
@Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { HRegionServer hrs = (HRegionServer)getServletContext().getAttribute(HRegionServer.REGIONSERVER); assert hrs != null : "No RS in context!"; resp.setContentType("text/html"); if (!hrs.isOnline()) { resp.getWriter().write("The RegionServer is initializing!"); resp.getWriter().close(); return; } RSStatusTmpl tmpl = new RSStatusTmpl(); if (req.getParameter("format") != null) tmpl.setFormat(req.getParameter("format")); if (req.getParameter("filter") != null) tmpl.setFilter(req.getParameter("filter")); if (req.getParameter("bcn") != null) tmpl.setBcn(req.getParameter("bcn")); if (req.getParameter("bcv") != null) tmpl.setBcv(req.getParameter("bcv")); tmpl.render(resp.getWriter(), hrs); } }
@Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { logger.debug("Export Get Action!"); try { Properties globalProps = (Properties) this.getServletContext().getAttribute("globalProps"); String zkServer = globalProps.getProperty("zkServer"); String[] zkServerLst = zkServer.split(","); String authRole = (String) request.getSession().getAttribute("authRole"); if (authRole == null) { authRole = ZooKeeperUtil.ROLE_USER; } String zkPath = request.getParameter("zkPath"); StringBuilder output = new StringBuilder(); output.append("#App Config Dashboard (ACD) dump created on :").append(new Date()).append("\n"); Set<LeafBean> leaves = ZooKeeperUtil.INSTANCE.exportTree(zkPath, ServletUtil.INSTANCE.getZookeeper(request, response, zkServerLst[0], globalProps), authRole); for (LeafBean leaf : leaves) { output.append(leaf.getPath()).append('=').append(leaf.getName()).append('=').append(ServletUtil.INSTANCE.externalizeNodeValue(leaf.getValue())).append('\n'); }// for all leaves response.setContentType("text/plain;charset=UTF-8"); try (PrintWriter out = response.getWriter()) { out.write(output.toString()); } } catch (InterruptedException | KeeperException ex) { logger.error(Arrays.toString(ex.getStackTrace())); ServletUtil.INSTANCE.renderError(request, response, ex.getMessage()); } } }
PrintWriter writer = null; final ServletContext context = getServletContext(); final Object parent = context.getAttribute(PARENT_ATTRIBUTE); writer = response.getWriter(); response.setContentType("application/json; charset=utf8"); response.setHeader(ACCESS_CONTROL_ALLOW_METHODS, "GET"); response.setHeader(ACCESS_CONTROL_ALLOW_ORIGIN, "*"); jg = jsonFactory.createJsonGenerator(writer); writer.close();
@Override public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException { // admin check - // allows when hadoop.security.instrumentation.requires.admin is set to false // when hadoop.security.instrumentation.requires.admin is set to true, checks if hadoop.security.authorization // is true and if the logged in user (via PAM or SPNEGO + kerberos) is in hive.users.in.admin.role list final ServletContext context = getServletContext(); if (!HttpServer.isInstrumentationAccessAllowed(context, request, response)) { LOG.warn("Unauthorized to perform GET action. remoteUser: {}", request.getRemoteUser()); return; } response.setContentType(HttpConstants.CONTENT_TYPE_JSON); response.setHeader(HttpConstants.ACCESS_CONTROL_ALLOW_METHODS, HttpConstants.METHOD_GET); response.setHeader(HttpConstants.ACCESS_CONTROL_ALLOW_ORIGIN, HttpConstants.WILDCARD); ServletContext ctx = getServletContext(); HiveConf hiveConf = (HiveConf) ctx.getAttribute("hiveconf"); HS2ActivePassiveHARegistry hs2Registry = HS2ActivePassiveHARegistryClient.getClient(hiveConf); HS2Instances instances = new HS2Instances(hs2Registry.getAll()); response.getWriter().write(instances.toJson()); response.setStatus(HttpServletResponse.SC_OK); response.flushBuffer(); } }
@Override protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException { String absoluteDiskPath = getServletContext().getRealPath(req.getPathInfo()); File requestedFile = new File(absoluteDiskPath); // async-profiler version 1.4 writes 'Started [cpu] profiling' to output file when profiler is running which // gets replaced by final output. If final output is not ready yet, the file size will be <100 bytes (in all modes). if (requestedFile.length() < 100) { LOG.info("{} is incomplete. Sending auto-refresh header..", requestedFile); resp.setHeader("Refresh", "2," + req.getRequestURI()); resp.getWriter().write("This page will auto-refresh every 2 second until output file is ready.."); } else { super.doGet(req, resp); } } }
final HttpServletResponse response) throws ServletException, IOException { SyncopeClientFactoryBean clientFactory = (SyncopeClientFactoryBean) request.getServletContext(). getAttribute(Constants.SYNCOPE_CLIENT_FACTORY); try { String accessToken = (String) request.getSession().getAttribute(Constants.SAML2SPJWT); if (StringUtils.isBlank(accessToken)) { throw new IllegalArgumentException("No access token found "); client.getService(SAML2SPService.class).validateLogoutResponse(receivedResponse); String successURL = getServletContext().getInitParameter(Constants.CONTEXT_PARAM_LOGOUT_SUCCESS_URL); if (successURL == null) { request.getRequestDispatcher("logoutSuccess.jsp").forward(request, response); } else { response.sendRedirect(successURL); request.getSession().removeAttribute(Constants.SAML2SPJWT); } catch (Exception e) { LOG.error("While processing authentication response from IdP", e); String errorURL = getServletContext().getInitParameter(Constants.CONTEXT_PARAM_LOGOUT_ERROR_URL); if (errorURL == null) { request.setAttribute("exception", e); request.getRequestDispatcher("logoutError.jsp").forward(request, response);
public void doTag() throws JspException, IOException { final JspContext jspContext = getJspContext(); final Class<?> resolvingClass = (Class<?>) jspContext .getAttribute(RequestDispatcherWrapper.RESOLVING_CLASS_ATTRIBUTE_NAME, PageContext.REQUEST_SCOPE); final String basePath = (String) jspContext.getAttribute(RequestDispatcherWrapper.BASE_PATH_ATTRIBUTE_NAME, PageContext.REQUEST_SCOPE); final ServletConfig servletConfig = (ServletConfig) getPageObject(PageContext.CONFIG); final ServletContext servletContext = servletConfig.getServletContext(); for (Class<?> clazz = resolvingClass; clazz != Object.class; clazz = clazz.getSuperclass()) { final String template = basePath + TemplateHelper.getAbsolutePath(clazz, page, '/'); if (servletContext.getResource(template) != null) { // Tomcat returns a RequestDispatcher even if the JSP file doesn't exist so check if the resource exists first. final RequestDispatcher dispatcher = servletContext.getRequestDispatcher(template); if (dispatcher != null) { try { final HttpServletRequest request = (HttpServletRequest) getPageObject(PageContext.REQUEST); final HttpServletResponse response = (HttpServletResponse) getPageObject(PageContext.RESPONSE); dispatcher.include(request, new Wrapper(response, new PrintWriter(jspContext.getOut()))); } catch (ServletException e) { throw new JspException(e); } return; } } } throw new JspException(LocalizationMessages.UNABLE_TO_FIND_PAGE_FOR_RESOLVING_CLASS(page, resolvingClass)); }
public void _jspService(final javax.servlet.http.HttpServletRequest request, final javax.servlet.http.HttpServletResponse response) throws java.io.IOException, javax.servlet.ServletException { final java.lang.String _jspx_method = request.getMethod(); if (!"GET".equals(_jspx_method) && !"POST".equals(_jspx_method) && !"HEAD".equals(_jspx_method) && !javax.servlet.DispatcherType.ERROR.equals(request.getDispatcherType())) { response.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED, "JSPs only permit GET POST or HEAD"); return; response.setContentType("text/html;charset=UTF-8"); pageContext = _jspxFactory.getPageContext(this, request, response, null, true, 8192, true); Configuration conf = (Configuration)ctx.getAttribute("hive.conf"); long startcode = conf.getLong("startcode", System.currentTimeMillis()); SessionManager sessionManager = (SessionManager)ctx.getAttribute("hive.sm"); String remoteUser = request.getRemoteUser(); if (out != null && out.getBufferSize() != 0) try { if (response.isCommitted()) { out.flush(); } else { else throw new ServletException(t);
/** {@inheritDoc} */ @Override public void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { log.debug("Servicing Request"); if (codecFactory == null) { ServletContext ctx = getServletContext(); log.debug("Context path: {}", ctx.getContextPath()); //attempt to lookup the webapp context webAppCtx = WebApplicationContextUtils.getRequiredWebApplicationContext(ctx); //now try to look it up as an attribute if (webAppCtx == null) { log.debug("Webapp context was null, trying lookup as attr."); webAppCtx = (WebApplicationContext) ctx.getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE); } //lookup the server and codec factory if (webAppCtx != null) { server = (IServer) webAppCtx.getBean("red5.server"); codecFactory = (RemotingCodecFactory) webAppCtx.getBean("remotingCodecFactory"); } else { log.debug("No web context"); } } log.debug("Remoting request {} {}", req.getContextPath(), req.getServletPath()); if (APPLICATION_AMF.equals(req.getContentType())) { serviceAMF(req, resp); } else { resp.getWriter().write("Red5 : Remoting Gateway"); } }
request.setAttribute(ACTUAL_REQUEST_URI, request.getRequestURI()); request.setAttribute(ACTUAL_QUERY_STRING, ServletUtils.encodeUrl(request.getQueryString())); int pos = request.getRequestURI().lastIndexOf("/"); pos = (pos >= 0) ? pos+=1 : request.getRequestURI().length(); File parentDir = new File(getServletContext().getRealPath(fileName)).getParentFile(); if (response.isCommitted() == false) { if (parentDir == null) { throw new ServletException("The template file "+templateFileName+" was not found."); getServletContext().getRequestDispatcher(templateFileUri).forward(request, response);