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:fr.mby.portal.coreimpl.app.BasicAppFactory.java
/** * @param request/*from w w w . ja va 2s . c o m*/ * @param appConfig * @return */ protected String generateNamespace(final HttpServletRequest request, final IAppConfig appConfig) { BuildInfo buildInfo = (BuildInfo) request.getAttribute(BasicAppFactory.REQUEST_BUILD_INFO); if (buildInfo == null) { buildInfo = new BuildInfo(); request.setAttribute(BasicAppFactory.REQUEST_BUILD_INFO, buildInfo); } final String sn = appConfig.getSymbolicName(); final String namespace = sn + "_" + buildInfo.nextNamespaceCount(sn); return namespace; }
From source file:com.arya.latihan.config.SecurityConfiguration.java
/** * Method untuk menyimpan CSRF TOKEN di cookie browser. * Token disimpan dengan nama XSRF-TOKEN karena AngularJS mengenal CSRF sebagai XSRF * @return Filter//w w w .jav a2s . com */ private Filter csrfHeaderFilter() { return new OncePerRequestFilter() { @Override protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException { CsrfToken csrfToken = (CsrfToken) request.getAttribute(CsrfToken.class.getName()); if (csrfToken != null) { String token = csrfToken.getToken(); Cookie cookie = WebUtils.getCookie(request, "XSRF-TOKEN");// angular js menamai CSRF dengan XSRF if (cookie == null || token != null && !token.equals(cookie.getValue())) { cookie = new Cookie("XSRF-TOKEN", token); cookie.setPath("/"); response.addCookie(cookie); } } filterChain.doFilter(request, response); } }; }
From source file:com.esri.gpt.control.publication.ValidateMetadataController.java
/** * Extracts the file item placed in the HTTP servlet request * by the MultipartFilter.// w w w . j a va2s . com * @return the uploaded file item (null if none) */ private FileItem extractFileItem() { FileItem item = null; HttpServletRequest httpReq = getContextBroker().extractHttpServletRequest(); if (httpReq != null) { Object oFile = httpReq.getAttribute("validate:validateXml"); if ((oFile != null) && (oFile instanceof FileItem)) { item = (FileItem) oFile; } } return item; }
From source file:de.hybris.platform.acceleratorstorefrontcommons.controllers.cms.AbstractCMSComponentController.java
@RequestMapping public String handleGet(final HttpServletRequest request, final HttpServletResponse response, final Model model) { T component = (T) request.getAttribute(COMPONENT); if (component != null) { // Add the component to the model model.addAttribute(COMPONENT, component); // Allow subclasses to handle the component return handleComponent(request, response, model, component); }/* w w w . j a va2 s . c om*/ String componentUid = (String) request.getAttribute(COMPONENT_UID); if (StringUtils.isEmpty(componentUid)) { componentUid = request.getParameter(COMPONENT_UID); } checkIfComponentNotEmpty(componentUid); try { component = getCmsComponentService().getAbstractCMSComponent(componentUid); if (component == null) { LOGGER.error("Component with UID [" + componentUid.replaceAll(SANITIZE_REGEX, "") + "] is null"); throw new AbstractPageController.HttpNotFoundException(); } else { // Add the component to the model model.addAttribute(COMPONENT, component); // Allow subclasses to handle the component return handleComponent(request, response, model, component); } } catch (final CMSItemNotFoundException e) { LOGGER.error("Could not find component with UID [" + componentUid.replaceAll(SANITIZE_REGEX, "") + "]"); throw new AbstractPageController.HttpNotFoundException(e); } }
From source file:org.guanxi.idp.service.GenericAuthHandler.java
/** * Copies required request parameters to prefixed request attributes to pass to the * authenticator page.//from w w w . j ava2 s . c om * @param request Standard HttpServletRequest */ protected void addRequiredParamsAsPrefixedAttributes(HttpServletRequest request) { if (request.getAttribute("binding") != null) { if (request.getAttribute("binding").equals("HTTP-POST")) { request.setAttribute(FORM_METHOD_ATTRIBUTE, "post"); } else if (request.getAttribute("binding").equals("HTTP-Redirect")) { request.setAttribute(FORM_METHOD_ATTRIBUTE, "get"); } } else { request.setAttribute(FORM_METHOD_ATTRIBUTE, "post"); } request.setAttribute(FORM_ACTION_ATTRIBUTE, authFormAction); if (requiredRequestParams != null) { for (String param : requiredRequestParams) { if (request.getParameter(param) != null) { request.setAttribute(REQUIRED_PARAM_PREFIX + param, request.getParameter(param)); } if (request.getAttribute(param) != null) { request.setAttribute(REQUIRED_PARAM_PREFIX + param, request.getAttribute(param)); } } } }
From source file:net.shopxx.plugin.weiboLogin.WeiboLoginPlugin.java
@Override public String getNickname(HttpServletRequest request) { Map<String, Object> parameterMap = new HashMap<String, Object>(); parameterMap.put("access_token", request.getAttribute("accessToken")); parameterMap.put("uid", request.getAttribute("uid")); String content = WebUtils.get("https://api.weibo.com/2/users/show.json", parameterMap); JsonNode jsonNode = JsonUtils.toTree(content); return jsonNode.has("screen_name") ? jsonNode.get("screen_name").textValue() : null; }
From source file:com.javaetmoi.core.mvc.tag.Html5InputTag.java
protected Object getBean(String beanName, Map<String, Object> model) { Object bean;//from w w w .j ava2 s . c o m if (model != null) { bean = model.get(beanName); } else { ConfigurablePropertyAccessor bw = PropertyAccessorFactory.forDirectFieldAccess(getRequestContext()); HttpServletRequest request = (HttpServletRequest) bw.getPropertyValue("request"); bean = request.getAttribute(beanName); } return bean; }
From source file:org.bpmscript.web.TemplateController.java
/** * Gets the sitemesh HTMLPage and passes that information to the right view * along with the following parameters:/*from w w w.j a v a 2 s . co m*/ * * <ul> * <li>base - the context path</li> * <li>locale - the locale for the page</li> * <li>req - the http request</li> * <li>res - the http response</li> * </ul> */ protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { HTMLPage htmlPage = (HTMLPage) request.getAttribute(RequestConstants.PAGE); Map<String, Object> context = new HashMap<String, Object>(templateModel); context.put("base", request.getContextPath()); context.put("locale", request.getLocale()); // For backwards compatability with apps that used the old VelocityDecoratorServlet // that extended VelocityServlet instead of VelocityViewServlet context.put("req", request); context.put("res", response); if (htmlPage == null) { context.put("title", "Title?"); context.put("body", "<p>Body?</p>"); context.put("head", "<!-- head -->"); } else { context.put("title", OutputConverter.convert(htmlPage.getTitle())); { StringWriter buffer = new StringWriter(); htmlPage.writeBody(OutputConverter.getWriter(buffer)); context.put("body", buffer.toString()); } { StringWriter buffer = new StringWriter(); htmlPage.writeHead(OutputConverter.getWriter(buffer)); context.put("head", buffer.toString()); } context.put("page", htmlPage); Factory factory = Factory.getInstance(new Config(new ServletConfig() { public ServletContext getServletContext() { return TemplateController.this.getServletContext(); } public String getInitParameter(String name) { return null; } public String getServletName() { return null; } public Enumeration<?> getInitParameterNames() { return null; } })); Decorator decorator = factory.getDecoratorMapper().getDecorator(request, htmlPage); context.put("decorator", decorator); } return new ModelAndView(getViewName(), context); }
From source file:coral.reef.web.ReefController.java
@RequestMapping(value = "/assets/**") public void icon(HttpServletRequest httpRequest, HttpServletResponse httpResponse) throws IOException { String path = ((String) httpRequest.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE)); Resource res = appContext.getResource("classpath:" + path); File f = res.getFile();//from ww w. j a v a2 s. co m FileSystemResource fr = new FileSystemResource(f); String type = servletContext.getMimeType(f.getAbsolutePath()); httpResponse.setContentType(type); IOUtils.copy(fr.getInputStream(), httpResponse.getOutputStream()); }
From source file:com.redhat.rhn.frontend.action.audit.scap.XccdfSearchAction.java
private Date getPickerDate(HttpServletRequest request, String paramName) { if (getOptionScanDateSearch(request)) { DatePicker dPick = (DatePicker) request.getAttribute(paramName); if (dPick != null) { return dPick.getDate(); }/*from w w w .j ava 2s .co m*/ } return null; }