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.duracloud.duradmin.spaces.controller.SpaceController.java
private void setItemCount(final Space space, HttpServletRequest request) throws ContentStoreException { String key = formatItemCountCacheKey(space); final ServletContext appContext = request.getSession().getServletContext(); ItemCounter listener = (ItemCounter) appContext.getAttribute(key); space.setItemCount(new Long(-1)); if (listener != null) { if (listener.isCountComplete()) { space.setItemCount(listener.getCount()); } else {//from w w w. j a v a2s . c o m SpaceProperties properties = space.getProperties(); Long interCount = listener.getIntermediaryCount(); if (interCount == null) { interCount = 0l; } properties.setCount(String.valueOf(interCount) + "+"); space.setProperties(properties); } } else { final ItemCounter itemCounterListener = new ItemCounter(); appContext.setAttribute(key, itemCounterListener); final ContentStore contentStore = contentStoreManager.getContentStore(space.getStoreId()); final StoreCaller<Iterator<String>> caller = new StoreCaller<Iterator<String>>() { protected Iterator<String> doCall() throws ContentStoreException { return contentStore.getSpaceContents(space.getSpaceId()); } public String getLogMessage() { return "Error calling contentStore.getSpaceContents() for: " + space.getSpaceId(); } }; new Thread(new Runnable() { public void run() { ExtendedIteratorCounterThread runnable = new ExtendedIteratorCounterThread(caller.call(), itemCounterListener); runnable.run(); } }).start(); } }
From source file:com.ocpsoft.pretty.faces.el.resolver.CDIBeanNameResolver.java
/** * Tries to get the BeanManager from the servlet context attribute * <code>javax.enterprise.inject.spi.BeanManager</code>. This works with * Weld and the current OpenWebBeans snapshots. * /*from w ww . j a v a 2s .c o m*/ * @param servletContext The servlet context * @return The BeanManager instance or <code>null</code> */ private Object getBeanManagerFromServletContext(ServletContext servletContext) { // get BeanManager from servlet context Object obj = servletContext.getAttribute(BEAN_MANAGER_CLASS); // debug result if (log.isTraceEnabled()) { if (obj == null) { log.trace("BeanManager not found in servlet context."); } else { log.trace("Found BeanManager in the servlet context."); } } return obj; }
From source file:org.apache.struts.faces.application.ActionListenerImpl.java
/** * <p>Look up and return the <code>RequestProcessor</code> responsible for * the specified module, creating a new one if necessary. This method is * based on the corresponding code in <code>ActionServlet</code>, which * cannot be used directly because it is a protected method.</p> * * @param config The module configuration for which to * acquire and return a RequestProcessor * @param context The <code>ServletContext</code> instance * for this web application/* w w w . ja va2 s .co m*/ * * @exception IllegalStateException if we cannot instantiate a * RequestProcessor instance */ protected RequestProcessor getRequestProcessor(ModuleConfig config, ServletContext context) { String key = Globals.REQUEST_PROCESSOR_KEY + config.getPrefix(); RequestProcessor processor = (RequestProcessor) context.getAttribute(key); if (processor == null) { try { if (log.isDebugEnabled()) { log.debug("Instantiating RequestProcessor of class " + config.getControllerConfig().getProcessorClass()); } ActionServlet servlet = (ActionServlet) context.getAttribute(Globals.ACTION_SERVLET_KEY); processor = (RequestProcessor) RequestUtils .applicationInstance(config.getControllerConfig().getProcessorClass()); processor.init(servlet, config); context.setAttribute(key, processor); } catch (Exception e) { log.error("Cannot instantiate RequestProcessor of class " + config.getControllerConfig().getProcessorClass(), e); throw new IllegalStateException("Cannot initialize RequestProcessor of class " + config.getControllerConfig().getProcessorClass() + ": " + e); } } return (processor); }
From source file:eu.celarcloud.jcatascopia.api.subscriptions.SubscriptionsServer.java
/** * Returns a list of all the subscriptions * /* ww w. j av a2 s .co m*/ * @param req * @param response * @param context * @return a list of all the subscriptions */ @GET @Path("/") @Produces(MediaType.APPLICATION_JSON) public Response getAvailableSubscriptions(@Context HttpServletRequest req, @Context HttpServletResponse response, @Context ServletContext context) { IDBInterface dbInterface = (IDBInterface) context.getAttribute("dbInterface"); ArrayList<SubscriptionObj> sublist = dbInterface.getSubscriptions(); StringBuilder sb = new StringBuilder(); sb.append("{\"subs\":["); if (sublist != null) { boolean first = true; for (SubscriptionObj s : sublist) { if (!first) sb.append(","); sb.append(s.toJSON()); first = false; } } sb.append("]}"); if (context.getAttribute("debug_mode") != null && context.getAttribute("debug_mode").toString().equals("true")) { System.out.println("Listing available subscriptions"); System.out.println(sb.toString()); } return Response.status(Response.Status.OK).entity(sb.toString()).build(); }
From source file:com.github.nblair.web.ProfileConditionalDelegatingFilterProxyTest.java
/** * Set up a {@link ServletContext} to contain a {@link WebApplicationContext} with the provided {@link Environment}. * //from ww w. j a va2 s . co m * @param environment * @return a mock {@link ServletContext} ready for use in the delegate filter proxy */ protected ServletContext mockServletContextWithEnvironment(Environment environment) { ServletContext servletContext = mock(ServletContext.class); WebApplicationContext wac = mock(WebApplicationContext.class); when(wac.getEnvironment()).thenReturn(environment); when(servletContext.getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE)) .thenReturn(wac); return servletContext; }
From source file:eu.celarcloud.jcatascopia.api.subscriptions.SubscriptionsServer.java
/** * Creates a new subscription./*from w w w . ja v a 2s . co m*/ * * @param req * @param response * @param context * @param body A body containing all the required data for creating a new subscription * @return a message with the status of creating the new subscription */ @PUT @Path("/") @Produces(MediaType.APPLICATION_JSON) public Response addSubscription(@Context HttpServletRequest req, @Context HttpServletResponse response, @Context ServletContext context, String body) { String serverIP = (String) context.getAttribute("serverIP"); String serverPort = (String) context.getAttribute("serverPort"); IDBInterface dbInterface = (IDBInterface) context.getAttribute("dbInterface"); try { if (body.startsWith("subscription=")) body = URLDecoder.decode(body.split("=")[1], "UTF-8"); JSONObject json = new JSONObject(body); json.put("subID", UUID.randomUUID().toString().replace("-", "")); boolean resp = dbInterface.createSubscription(serverIP, serverPort, json.toString()); if (resp) { if (context.getAttribute("debug_mode") != null && context.getAttribute("debug_mode").toString().equals("true")) System.out.println("Added a new subscription with id " + json.getString("subID")); return Response.status(Response.Status.CREATED) .entity("{\"status\":\"added\",\"subID\":\"" + json.getString("subID") + "\"}").build(); } else { System.out.println("Failed to add new subscription"); //TODO fix this status code which gives the wrong impression return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity("{\"status\":\"failed\"}") .build(); } } catch (JSONException e) { e.printStackTrace(); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } return null; }
From source file:eu.celarcloud.jcatascopia.api.subscriptions.SubscriptionsServer.java
/** * Deletes the given subscription./*from ww w. j a va 2 s . c o m*/ * * @param req * @param response * @param context * @param subID The subscription's id to delete * @return a status message */ @DELETE @Path("/{subid}") @Produces(MediaType.APPLICATION_JSON) public Response deleteSubscription(@Context HttpServletRequest req, @Context HttpServletResponse response, @Context ServletContext context, @PathParam("subid") String subID) { String serverIP = (String) context.getAttribute("serverIP"); String serverPort = (String) context.getAttribute("serverPort"); IDBInterface dbInterface = (IDBInterface) context.getAttribute("dbInterface"); boolean resp = dbInterface.removeSubscription(serverIP, serverPort, "{\"subID\" : \"" + subID + "\"}"); if (resp) { if (context.getAttribute("debug_mode") != null && context.getAttribute("debug_mode").toString().equals("true")) System.out.println("Removed subscription with id " + subID); return Response.status(Response.Status.OK).entity("{\"status\":\"success\"}").build(); } else { System.out.println("Failed to delete subscription with id " + subID); return Response.status(Response.Status.NOT_FOUND).entity("{\"status\":\"failed\"}").build(); } }
From source file:org.apache.struts.upload.DiskMultipartRequestHandler.java
/** * Retrieves the temporary directory from either ActionServlet, a context * property, or a system property, in that order. */// w w w .ja v a 2 s . c o m protected void retrieveTempDir(ModuleConfig moduleConfig) { //attempt to retrieve the servlet container's temporary directory ActionServlet servlet = getServlet(); if (servlet != null) { //attempt to retrieve the servlet container's temporary directory ServletContext context = servlet.getServletContext(); try { tempDir = (String) context.getAttribute("javax.servlet.context.tempdir"); } catch (ClassCastException cce) { tempDir = ((File) context.getAttribute("javax.servlet.context.tempdir")).getAbsolutePath(); } } if (tempDir == null) { //attempt to retrieve the temporary directory from the controller tempDir = moduleConfig.getControllerConfig().getTempDir(); if (tempDir == null) { //default to system-wide tempdir tempDir = System.getProperty("java.io.tmpdir"); log.debug("DiskMultipartRequestHandler.handleRequest(): " + "defaulting to java.io.tmpdir directory \"" + tempDir); } } }
From source file:com.skilrock.lms.web.loginMgmt.RolesInterceptor.java
public boolean isSessionTimeOut(HttpSession session) { HttpSession sessionNew = null;/* ww w . j a va 2 s .c o m*/ ServletContext sc = ServletActionContext.getServletContext(); Map currentUserSessionMap = (Map) sc.getAttribute("LOGGED_IN_USERS"); UserInfoBean userBean = (UserInfoBean) session.getAttribute("USER_INFO"); if (userBean == null) { return true; } if (currentUserSessionMap != null && userBean != null) { sessionNew = (HttpSession) currentUserSessionMap.get(userBean.getUserName()); } // logger.debug("In Else If New is --"+sessionNew+" Session Current // --"+session); // logger.debug("The User in Map are"+currentUserSessionMap ); if (sessionNew == null) { return true; } return false; }
From source file:de.ingrid.iplug.web.BusClientContextListener.java
public void contextInitialized(ServletContextEvent servletcontextevent) { ServletContext servletContext = servletcontextevent.getServletContext(); String communicationFile = servletContext.getInitParameter("communication.xml"); BusClient busClient = null;/*from w w w .j a va2 s. c o m*/ try { busClient = connectIBus(communicationFile); BeanFactory beanFactory = (BeanFactory) servletContext.getAttribute("beanFactory"); beanFactory.addBean("busClient", busClient); } catch (Exception e1) { LOG.error("can not connect to ibus", e1); } }