List of usage examples for javax.servlet ServletContext getAttribute
public Object getAttribute(String name);
null
if there is no attribute by that name. From source file:org.apache.hadoop.gateway.filter.rewrite.impl.UrlRewriteResponseTest.java
@Test public void testResolveGatewayParams() throws Exception { UrlRewriteProcessor rewriter = EasyMock.createNiceMock(UrlRewriteProcessor.class); ServletContext context = EasyMock.createNiceMock(ServletContext.class); EasyMock.expect(context.getAttribute(UrlRewriteServletContextListener.PROCESSOR_ATTRIBUTE_NAME)) .andReturn(rewriter).anyTimes(); FilterConfig config = EasyMock.createNiceMock(FilterConfig.class); EasyMock.expect(config.getServletContext()).andReturn(context).anyTimes(); HttpServletRequest request = EasyMock.createNiceMock(HttpServletRequest.class); EasyMock.expect(request.getScheme()).andReturn("mock-scheme").anyTimes(); EasyMock.expect(request.getLocalName()).andReturn("mock-host").anyTimes(); EasyMock.expect(request.getLocalPort()).andReturn(42).anyTimes(); EasyMock.expect(request.getContextPath()).andReturn("/mock-path").anyTimes(); HttpServletResponse response = EasyMock.createNiceMock(HttpServletResponse.class); EasyMock.replay(rewriter, context, config, request, response); UrlRewriteResponse rewriteResponse = new UrlRewriteResponse(config, request, response); List<String> url = rewriteResponse.resolve("gateway.url"); assertThat(url, hasItems(new String[] { "mock-scheme://mock-host:42/mock-path" })); List<String> scheme = rewriteResponse.resolve("gateway.scheme"); assertThat(scheme, hasItems(new String[] { "mock-scheme" })); List<String> host = rewriteResponse.resolve("gateway.host"); assertThat(host, hasItems(new String[] { "mock-host" })); List<String> port = rewriteResponse.resolve("gateway.port"); assertThat(port, hasItems(new String[] { "42" })); List<String> addr = rewriteResponse.resolve("gateway.addr"); assertThat(addr, hasItems(new String[] { "mock-host:42" })); List<String> address = rewriteResponse.resolve("gateway.addr"); assertThat(address, hasItems(new String[] { "mock-host:42" })); List<String> path = rewriteResponse.resolve("gateway.path"); assertThat(path, hasItems(new String[] { "/mock-path" })); }
From source file:org.bimserver.servlets.RootServlet.java
@Override public void init() throws ServletException { super.init(); ServletContext servletContext = getServletContext(); bimServer = (BimServer) servletContext.getAttribute("bimserver"); if (bimServer == null) { throw new ServletException("No bimserver context attribute"); }/*from www . java2s . c om*/ jsonApiServlet = new JsonApiServlet(bimServer, servletContext); syndicationServlet = new SyndicationServlet(bimServer, servletContext); uploadServlet = new UploadServlet(bimServer, servletContext); bulkUploadServlet = new BulkUploadServlet(bimServer, servletContext); downloadServlet = new DownloadServlet(bimServer, servletContext); soap11Servlet = new WebServiceServlet11(bimServer, servletContext); soap11Servlet.init(getServletConfig()); soap12Servlet = new WebServiceServlet12(bimServer, servletContext); soap12Servlet.init(getServletConfig()); oAuthAuthorizationServlet = new OAuthAuthorizationServlet(bimServer, servletContext); oAuthRegistrationServlet = new OAuthRegistrationServlet(bimServer, servletContext); }
From source file:org.jboss.arquillian.spring.integration.inject.container.WebApplicationContextProducer.java
/** * <p>Retrieves the application context for the given servlet.</p> * * @param rootContext the root web application context * @param servletName the servlet name/*from w w w . j a v a2s . c om*/ * * @return the retrieved application context */ private ApplicationContext getServletApplicationContext(WebApplicationContext rootContext, String servletName) { // retrieves the servlet context from web application context ServletContext servletContext = rootContext.getServletContext(); // retrieves the application context for the given servlet using it's name return (ApplicationContext) servletContext .getAttribute(MessageFormat.format(SpringInjectConstants.SERVLET_APPLICATION_CONTEXT, servletName)); }
From source file:org.flymine.web.ChartRenderer.java
/** * First, check for a cached image, otherwise defer to appropriate method. * * @param mapping The ActionMapping used to select this instance * @param form The optional ActionForm bean for this request (if any) * @param request The HTTP request we are processing * @param response The HTTP response we are creating * @return an ActionForward object defining where control goes next * @exception Exception if the application business logic throws * an exception/*from ww w. j av a 2 s . c o m*/ */ public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { HttpSession session = request.getSession(); ServletContext servletContext = session.getServletContext(); Map graphImageCache = (Map) servletContext.getAttribute(Constants.GRAPH_CACHE); String filename = (String) graphImageCache.get(request.getQueryString()); if (filename != null) { //ServletUtilities.sendTempFile(filename, response); return null; } Method method = getClass().getMethod(request.getParameter("method"), SIG); if (!"execute".equals(method.getName())) { // avoid infinite loop return (ActionForward) method.invoke(this, new Object[] { mapping, form, request, response }); } LOG.error("bad method parameter \"" + request.getParameter("method") + "\""); return null; }
From source file:org.iplantc.phyloviewer.viewer.server.ParseTreeService.java
@Override public void init() throws ServletException { ServletContext servletContext = this.getServletContext(); IImportTreeData treeImporter = (IImportTreeData) servletContext .getAttribute(Constants.IMPORT_TREE_DATA_KEY); ImportTreeLayout layoutImporter = (ImportTreeLayout) servletContext .getAttribute(Constants.IMPORT_TREE_LAYOUT_KEY); String path = servletContext.getInitParameter("treefile.path"); path = servletContext.getRealPath(path); parseTree = new ParseTree(treeImporter, layoutImporter); parseTree.setTreeBackupDir(path);//from ww w . j a v a 2 s.co m Logger.getLogger("org.iplantc.phyloviewer").log(Level.INFO, "Setting parseTree file backup path to " + parseTree.getTreeBackupDir().getAbsolutePath()); }
From source file:net.scran24.staff.server.services.UploadUserInfoService.java
@Override protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { resp.setContentType("text/html"); ServletOutputStream outputStream = resp.getOutputStream(); PrintWriter writer = new PrintWriter(outputStream); if (!ServletFileUpload.isMultipartContent(req)) { resp.sendError(HttpServletResponse.SC_BAD_REQUEST); } else {//w w w. ja v a 2s . co m DiskFileItemFactory factory = new DiskFileItemFactory(); ServletContext servletContext = this.getServletConfig().getServletContext(); File repository = (File) servletContext.getAttribute("javax.servlet.context.tempdir"); factory.setRepository(repository); ServletFileUpload upload = new ServletFileUpload(factory); try { List<FileItem> items = upload.parseRequest(req); InputStream file = null; String role = null; Set<String> permissions = new HashSet<String>(); String surveyId = req.getParameter("surveyId"); for (FileItem i : items) { if (i.getFieldName().equals("file")) file = i.getInputStream(); else if (i.getFieldName().equals("role")) role = i.getString(); else if (i.getFieldName().equals("permission")) permissions.add(i.getString()); } if (file == null) throw new ServletException("file field not specified"); if (role == null) throw new ServletException("role field not specified"); if (surveyId == null) throw new ServletException("surveyId field not specified"); List<UserRecord> userRecords = UserRecordCSV.fromCSV(file); try { Set<String> roles = new HashSet<String>(); roles.add(role); dataStore.saveUsers(surveyId, mapToSecureUserRecords(userRecords, roles, permissions)); writer.print("OK"); } catch (DataStoreException e) { writer.print("ERR:" + e.getMessage()); } catch (DuplicateKeyException e) { writer.print("ERR:" + e.getMessage()); } } catch (FileUploadException e) { writer.print("ERR:" + e.getMessage()); } catch (IOException e) { writer.print("ERR:" + e.getMessage()); } } writer.close(); }
From source file:org.apache.hadoop.security.authentication.util.TestZKSignerSecretProvider.java
private ServletContext getDummyServletContext() { ServletContext servletContext = mock(ServletContext.class); when(servletContext .getAttribute(ZKSignerSecretProvider.ZOOKEEPER_SIGNER_SECRET_PROVIDER_CURATOR_CLIENT_ATTRIBUTE)) .thenReturn(null);/* w ww . j a va 2 s . c o m*/ return servletContext; }
From source file:org.hyperic.hq.ui.security.UISessionInitializationStrategy.java
private void loadDashboard(ServletContext ctx, WebUser webUser, AuthzBoss authzBoss) { try {// w w w . ja v a 2 s . co m ConfigResponse defaultUserDashPrefs = (ConfigResponse) ctx.getAttribute(Constants.DEF_USER_DASH_PREFS); AuthzSubject me = authzBoss.findSubjectById(webUser.getSessionId(), webUser.getSubject().getId()); UserDashboardConfig userDashboard = dashboardManager.getUserDashboard(me, me); if (userDashboard == null) { userDashboard = dashboardManager.createUserDashboard(me, me, webUser.getName()); } ConfigResponse userDashobardConfig = userDashboard.getConfig(); if (mergeValues(userDashobardConfig, defaultUserDashPrefs, false)) { dashboardManager.configureDashboard(me, userDashboard, userDashobardConfig); } } catch (PermissionException e) { log.error(e); } catch (SessionNotFoundException e) { // User not logged in log.error(e); } catch (SessionTimeoutException e) { // User session has expired log.error(e); } }
From source file:com.liferay.arquillian.DeployerServlet.java
private InputStream getUploadedBundleInputStream(HttpServletRequest request) throws FileUploadException, IOException { DiskFileItemFactory factory = new DiskFileItemFactory(); ServletConfig servletConfig = this.getServletConfig(); ServletContext servletContext = servletConfig.getServletContext(); File repository = (File) servletContext.getAttribute("javax.servlet.context.tempdir"); factory.setRepository(repository);//from w w w . j a va 2s .co m ServletFileUpload upload = new ServletFileUpload(factory); List<FileItem> items = upload.parseRequest(request); FileItem fileItem = items.get(0); return fileItem.getInputStream(); }
From source file:com.telefonica.iot.perseo.UtilsTest.java
/** * Test of initEPService method, of class Utils. *//*from www .j a v a2 s.c om*/ @Test public void testInitEPService() { System.out.println("initEPService"); ServletContext sc = new ServletContextMock(); EPServiceProvider result = Utils.initEPService(sc); assertEquals(sc.getAttribute("epService"), result); //Do not create a new one if it already exists EPServiceProvider result2 = Utils.initEPService(sc); assertEquals(result, result2); }