List of usage examples for javax.servlet.http HttpServletRequest getAttribute
public Object getAttribute(String name);
Object
, or null
if no attribute of the given name exists. From source file:com.nominanuda.web.http.ServletHelper.java
public @Nullable Object getHandlerOutput(HttpServletRequest servletRequest) throws IOException { return servletRequest.getAttribute("__handlerOutput__"); }
From source file:com.pkrete.locationservice.admin.controller.rest.v1.LanguagesRestController.java
@RequestMapping(method = RequestMethod.GET, produces = "application/json; charset=utf-8") @ResponseBody//ww w.j a va2s . c o m public List index(HttpServletRequest request) { // Get Owner object related to the user Owner owner = (Owner) request.getAttribute("owner"); // Get list of laguages related to the Owner List languages = this.languagesService.getLanguages(owner); // Return the languages return this.mapConverter.convert(languages); }
From source file:com.indusborn.ui.settings.SettingsController.java
@RequestMapping(value = "/sett/upd/details/{userId}", method = RequestMethod.GET) public ModelAndView settUpdDetails(@PathVariable Long userId, HttpServletRequest request, Model model) { ModelAndView resultView = new ModelAndView("sett.upd.details"); UserVO userVO = (UserVO) request.getAttribute("userVO"); UpdDetailsForm updDetailsForm = new UpdDetailsForm(); Message message;// w w w . j ava 2 s . c o m if (userId != userVO.getId()) { message = new Message(MessageType.ERROR, MessageValues.UPD_DETAILS_NOT_PERMITTED); model.addAttribute("message", message); return resultView; } updDetailsForm.setFname(userVO.getFname()); updDetailsForm.setLname(userVO.getLname()); updDetailsForm.setAddress(userVO.getAddress()); updDetailsForm.setPhone(userVO.getPhone()); updDetailsForm.setZip(userVO.getZip()); model.addAttribute("updDetailsForm", updDetailsForm); return resultView; }
From source file:com.pkrete.locationservice.admin.controller.rest.v1.MyOwnerRestController.java
@RequestMapping(value = "", method = RequestMethod.GET, produces = "application/json; charset=utf-8") @ResponseBody// w w w.j a v a 2 s . c o m public Map getSettings(HttpServletRequest request, HttpServletResponse response) throws ResourceNotFoundException { // Get Owner object related to the user Owner ownerAttr = (Owner) request.getAttribute("owner"); // Get owner matching the given id Owner owner = this.ownersService.getFullOwner(ownerAttr.getId()); // Check for null value if (owner == null) { // Throw exception throw new ResourceNotFoundException(getMessage("rest.resource.not.exist")); } // Return the owner return this.settingsMapConverter.convert(owner); }
From source file:com.tremolosecurity.proxy.auth.persistentCookie.PersistentCookieResult.java
@Override public void createResultCookie(Cookie cookie, HttpServletRequest request, HttpServletResponse response) throws ServletException { UrlHolder holder = (UrlHolder) request.getAttribute(ProxyConstants.AUTOIDM_CFG); ConfigManager mgr = holder.getConfig(); HashSet<String> mechs = new HashSet<String>(); for (String mechName : mgr.getAuthMechs().keySet()) { MechanismType mech = mgr.getAuthMechs().get(mechName); if (mech.getClassName() .equalsIgnoreCase("com.tremolosecurity.proxy.auth.persistentCookie.PersistentCookie")) { mechs.add(mechName);// w ww . j a va 2 s. c o m } } AuthController authCtl = (AuthController) request.getSession().getAttribute(ProxyConstants.AUTH_CTL); String chainName = authCtl.getAuthInfo().getAuthChain(); AuthChainType chain = mgr.getAuthChains().get(chainName); int millisToLive = 0; String keyAlias = ""; boolean useSSLSession = false; for (AuthMechType amt : chain.getAuthMech()) { if (mechs.contains(amt.getName())) { for (ParamType pt : amt.getParams().getParam()) { if (pt.getName().equalsIgnoreCase("millisToLive")) { millisToLive = Integer.parseInt(pt.getValue()); } if (pt.getName().equalsIgnoreCase("useSSLSessionID") && pt.getValue().equalsIgnoreCase("true")) { useSSLSession = true; } else if (pt.getName().equalsIgnoreCase("keyAlias")) { keyAlias = pt.getValue(); } } } } DateTime now = new DateTime(); DateTime expires = now.plusMillis(millisToLive); com.tremolosecurity.lastmile.LastMile lastmile = null; try { lastmile = new com.tremolosecurity.lastmile.LastMile("/", now, expires, 0, "NONE"); } catch (URISyntaxException e) { //not possible } lastmile.getAttributes().add(new Attribute("DN", authCtl.getAuthInfo().getUserDN())); lastmile.getAttributes().add(new Attribute("CLIENT_IP", request.getRemoteAddr())); if (useSSLSession) { Object sessionID = request.getAttribute("javax.servlet.request.ssl_session_id"); if (sessionID instanceof byte[]) { sessionID = new String(Base64.encodeBase64((byte[]) sessionID)); } lastmile.getAttributes().add(new Attribute("SSL_SESSION_ID", (String) sessionID)); } try { cookie.setValue(new StringBuilder().append('"') .append(lastmile.generateLastMileToken(mgr.getSecretKey(keyAlias))).append('"').toString()); } catch (Exception e) { throw new ServletException("Could not encrypt persistent cookie", e); } cookie.setMaxAge(millisToLive / 1000); }
From source file:edu.cornell.mannlib.vitro.webapp.i18n.I18n.java
/** Only clear the cache one time per request. */ private void clearCacheOnRequest(HttpServletRequest req) { if (req.getAttribute(ATTRIBUTE_CACHE_CLEARED) != null) { log.debug("Cache was already cleared on this request."); } else {//from www.j ava 2 s.co m ResourceBundle.clearCache(); log.debug("Cache cleared."); req.setAttribute(ATTRIBUTE_CACHE_CLEARED, Boolean.TRUE); } }
From source file:com.hypersocket.session.json.SessionUtils.java
public Session getActiveSession(HttpServletRequest request) { Session session = null;//from w ww . java2 s. c o m if (request.getAttribute(AUTHENTICATED_SESSION) != null) { session = (Session) request.getAttribute(AUTHENTICATED_SESSION); if (sessionService.isLoggedOn(session, true)) { return session; } } if (request.getSession().getAttribute(AUTHENTICATED_SESSION) != null) { session = (Session) request.getSession().getAttribute(AUTHENTICATED_SESSION); if (sessionService.isLoggedOn(session, true)) { return session; } } for (Cookie c : request.getCookies()) { if (c.getName().equals(HYPERSOCKET_API_SESSION)) { session = sessionService.getSession(c.getValue()); if (session != null && sessionService.isLoggedOn(session, true)) { return session; } } } if (request.getParameterMap().containsKey(HYPERSOCKET_API_KEY)) { session = sessionService.getSession(request.getParameter(HYPERSOCKET_API_KEY)); } else if (request.getHeader(HYPERSOCKET_API_SESSION) != null) { session = sessionService.getSession((String) request.getHeader(HYPERSOCKET_API_SESSION)); } if (session != null && sessionService.isLoggedOn(session, true)) { return session; } return null; }
From source file:cc.kune.core.server.rack.filters.rest.CORSServiceFilter.java
@Override protected void customDoFilter(final HttpServletRequest request, final HttpServletResponse response, final FilterChain chain) throws IOException, ServletException { final boolean cors = (Boolean) request.getAttribute("cors.isCorsRequest"); // This part is similar to RESTServiceFilter final String methodName = RackHelper.getMethodName(request, pattern); final ParametersAdapter parameters = new ParametersAdapter(request); LOG.debug((cors ? "" : "NO ") + "CORS METHOD: '" + methodName + "' on: " + serviceClass.getSimpleName()); response.setCharacterEncoding("utf-8"); // See: http://software.dzhuvinov.com/cors-filter-tips.html response.setContentType("text/plain"); final RESTResult result = transactionalFilter.doService(serviceClass, methodName, parameters, getInstance(serviceClass));/* w w w . ja v a2s .com*/ if (result != null) { final Exception exception = result.getException(); if (exception != null) { if (exception instanceof InvocationTargetException && ((InvocationTargetException) exception) .getTargetException() instanceof ContentNotFoundException) { printMessage(response, HttpServletResponse.SC_NOT_FOUND, result.getException().getMessage()); } else { printMessage(response, HttpServletResponse.SC_BAD_REQUEST, result.getException().getMessage()); } } else { final String output = result.getOutput(); if (output != null) { final PrintWriter writer = response.getWriter(); writer.print(output); writer.flush(); } else { // Is not for us!!! } } } }
From source file:edu.umd.cs.submitServer.servlets.UploadProjectStarterFiles.java
/** * The doPost method of the servlet. <br> * /*from w w w.j av a 2 s. c om*/ * This method is called when a form has its tag value method equals to * post. * * @param request * the request send by the client to the server * @param response * the response send by the server to the client * @throws ServletException * if an error occurred * @throws IOException * if an error occurred */ @Override public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { MultipartRequest multipartRequest = (MultipartRequest) request.getAttribute(MULTIPART_REQUEST); Project project = (Project) request.getAttribute(PROJECT); Connection conn = null; FileItem fileItem = null; try { conn = getConnection(); fileItem = multipartRequest.getFileItem(); long sizeInBytes = fileItem.getSize(); if (sizeInBytes == 0) { throw new ServletException("Trying upload file of size 0"); } // copy the fileItem into a byte array InputStream is = fileItem.getInputStream(); ByteArrayOutputStream bytes = new ByteArrayOutputStream((int) sizeInBytes); IO.copyStream(is, bytes); byte[] bytesForUpload = bytes.toByteArray(); // set the byte array as the archive project.setArchiveForUpload(bytesForUpload); FormatDescription desc = FormatIdentification.identify(bytesForUpload); if (desc == null || !desc.getMimeType().equals("application/zip")) { response.sendError(HttpServletResponse.SC_BAD_REQUEST, "You MUST submit starter files that are either zipped or jarred"); return; } Integer archivePK = project.getArchivePK(); if (archivePK == null || archivePK.equals(0)) { // If there is no archive, then upload and create a new one project.uploadCachedArchive(conn); project.update(conn); } else { // Otherwise, update the archive we already have project.updateCachedArchive(bytesForUpload, conn); } String redirectUrl = request.getContextPath() + "/view/instructor/projectUtilities.jsp?projectPK=" + project.getProjectPK(); response.sendRedirect(redirectUrl); } catch (SQLException e) { throw new ServletException(e); } finally { releaseConnection(conn); } }