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.liusoft.dlog4j.action.ActionBase.java
/** * ??,validateSiteOwner??//from w w w .j ava2 s . c o m * @param req * @return */ protected static UserBean getLoginUserAfterValidateSiteOwner(HttpServletRequest req) { return (UserBean) req.getAttribute(KEY_USER); }
From source file:com.liusoft.dlog4j.action.ActionBase.java
/** * ??validateSiteOwner??//w ww .ja v a 2 s . c om * @param req * @return */ protected static SiteBean getSiteBean(HttpServletRequest req) { SiteBean site = (SiteBean) req.getAttribute(KEY_SITE); if (site == null) { try { int site_id = Integer.parseInt(req.getParameter(Globals.PARAM_SID)); site = SiteDAO.getSiteByID(site_id); if (site != null) req.setAttribute(KEY_SITE, site); } catch (Exception e) { } } return site; }
From source file:gov.nih.nci.caarray.web.fileupload.MonitoredMultiPartRequest.java
/** * Retrieves the identifier for the current upload request. * @param request the current HTTP request * @return an identifier used to refer to this upload when checking for progress *///from w ww . java 2 s . com public static String getUploadKey(HttpServletRequest request) { String uploadId = request.getParameter(UPLOAD_ID_ATTRIBUTE); if (uploadId == null) { uploadId = StringUtils.defaultString((String) request.getAttribute(UPLOAD_ID_ATTRIBUTE)); } return ProgressMonitor.SESSION_PROGRESS_MONITOR + uploadId; }
From source file:filter.MultipartRequestFilter.java
private static void addAttributeValue(HttpServletRequest request, String name, final Object value) { System.out.println("Add attribute value: name=" + name + ", value = " + value); if (value == null) { return;/* ww w. java 2 s . c om*/ } final Object attrValue = request.getAttribute(name); System.out.println("oldValue = " + attrValue); if (attrValue == null) { request.setAttribute(name, value); } else if (attrValue instanceof List) { ((List) attrValue).add(value); } else { request.setAttribute(name, new ArrayList() { { add(attrValue); add(value); } }); } }
From source file:com.att.ajsc.csilogging.util.UtilLib.java
public static String getServiceName(HttpServletRequest request) { String serviceName = "N/A"; if (request.getAttribute(CommonNames.REST_NAME_HEADER) != null) { serviceName = request.getAttribute(CommonNames.REST_NAME_HEADER).toString(); } else {/*from w w w. j ava 2 s. c o m*/ String service = null; String pathinfo[] = request.getRequestURI().split("\\/"); for (int i = 1; i < pathinfo.length; i++) { if (service == null) { service = pathinfo[i]; } else { service = service + "." + pathinfo[i]; } } serviceName = service; } return serviceName; }
From source file:de.betterform.agent.web.WebUtil.java
/** * * @return String for use as root of URLs */// w ww. j a va 2 s . c o m public static String getContextRoot(HttpServletRequest request) { if (request.getAttribute(WebProcessor.ALTERNATIVE_ROOT) != null) { return (String) request.getAttribute(WebProcessor.ALTERNATIVE_ROOT); } else { return request.getContextPath(); } }
From source file:com.ebay.cloud.cms.service.resources.impl.QueryResource.java
@SuppressWarnings("unchecked") public static QueryContext createContext(CMSServer server, UriInfo uriInfo, String reponame, String branch, CMSQueryMode mode, PaginationMode pageMode, String consistPolicy, HttpServletRequest request) { String sourceIp = (String) request.getAttribute(CMSResourceUtils.X_CMS_CLIENT_IP); if (sourceIp == null) { sourceIp = request.getRemoteAddr(); }/* w ww . j av a 2 s . co m*/ MultivaluedMap<String, String> mmap = uriInfo.getQueryParameters(); QueryContext context = new QueryContext(reponame, branch); context.setSubject(mmap.getFirst(CMSResourceUtils.REQ_PARAM_COMPONENT)); context.setUserId(mmap.getFirst(CMSResourceUtils.REQ_PARAM_UID)); context.setShowDisplayMeta(Boolean.valueOf(mmap.getFirst(CMSResourceUtils.REQ_SHOW_META))); if (StringUtils.isEmpty(context.getUserId())) { context.setUserId(sourceIp); } context.setSourceIP(sourceIp); context.setCountOnly(mode == CMSQueryMode.COUNT); context.setPaginationMode(pageMode); String dal = mmap.getFirst(CMSResourceUtils.REQ_PARAM_DAL_IMPLEMENTATION); context.setRegistration(server.getDalImplementation(dal)); context.setConsistentPolicy(CMSResourceUtils.parsePolicy(server, consistPolicy)); Map<String, List<SearchCriteria>> addiotionalCriteria = (Map<String, List<SearchCriteria>>) request .getAttribute(CMSResourceUtils.REQ_READ_FILTER); context.setAdditionalCriteria(addiotionalCriteria); return context; }
From source file:de.itsvs.cwtrpc.core.CwtRpcUtils.java
public static String readContent(HttpServletRequest request) throws ServletException, IOException, SecurityException { String payload;/*from w ww.jav a 2 s . com*/ /* * Content can only be read once from servlet request. In order to * access it multiple times the content must be stored in request after * it has been read. */ payload = (String) request.getAttribute(GWT_RPC_REQUEST_CONTENT_ATTR_NAME); if (payload == null) { if (!containsStrongName(request)) { throw new SecurityException("Request does not contain required strong name header"); } payload = RPCServletUtils.readContentAsGwtRpc(request); request.setAttribute(GWT_RPC_REQUEST_CONTENT_ATTR_NAME, payload); } return payload; }
From source file:edu.utah.further.i2b2.hook.further.web.ServletUtil.java
/** * @param request/*w w w. j av a 2 s. c o m*/ */ public static void printRequestAttributes(final HttpServletRequest request) { log.debug("Request attributes:"); final Enumeration<?> attributeNames = request.getAttributeNames(); while (attributeNames.hasMoreElements()) { final String name = (String) attributeNames.nextElement(); log.debug(name + " = " + request.getAttribute(name)); } }
From source file:org.apache.ofbiz.passport.event.LinkedInEvents.java
private static String checkLoginLinkedInUser(HttpServletRequest request, Document userInfo, String accessToken) {/* ww w . ja v a2s . com*/ Delegator delegator = (Delegator) request.getAttribute("delegator"); LocalDispatcher dispatcher = (LocalDispatcher) request.getAttribute("dispatcher"); String productStoreId = ProductStoreWorker.getProductStoreId(request); String linkedInUserId = LinkedInAuthenticator.getLinkedInUserId(userInfo); GenericValue linkedInUser = null; try { linkedInUser = delegator.findOne("LinkedInUser", UtilMisc.toMap("linkedInUserId", linkedInUserId), false); } catch (GenericEntityException e) { request.setAttribute("_ERROR_MESSAGE_", e.getMessage()); return "error"; } if (linkedInUser != null) { boolean dataChanged = false; if (!accessToken.equals(linkedInUser.getString("accessToken"))) { linkedInUser.set("accessToken", accessToken); dataChanged = true; } if (!envPrefix.equals(linkedInUser.getString("envPrefix"))) { linkedInUser.set("envPrefix", envPrefix); dataChanged = true; } if (!productStoreId.equals(linkedInUser.getString("productStoreId"))) { linkedInUser.set("productStoreId", productStoreId); dataChanged = true; } if (dataChanged) { try { linkedInUser.store(); } catch (GenericEntityException e) { Debug.logError(e.getMessage(), module); } } } else { linkedInUser = delegator.makeValue("LinkedInUser", UtilMisc.toMap("accessToken", accessToken, "productStoreId", productStoreId, "envPrefix", envPrefix, "linkedInUserId", linkedInUserId)); try { linkedInUser.create(); } catch (GenericEntityException e) { Debug.logError(e.getMessage(), module); } } try { GenericValue userLogin = EntityUtil.getFirst(delegator.findByAnd("UserLogin", UtilMisc.toMap("externalAuthId", linkedInUserId), null, false)); LinkedInAuthenticator authn = new LinkedInAuthenticator(); authn.initialize(dispatcher); if (UtilValidate.isEmpty(userLogin)) { String userLoginId = authn.createUser(userInfo); userLogin = delegator.findOne("UserLogin", UtilMisc.toMap("userLoginId", userLoginId), false); } String autoPassword = RandomStringUtils.randomAlphanumeric( EntityUtilProperties.getPropertyAsInteger("security", "password.length.min", 5).intValue()); boolean useEncryption = "true".equals(UtilProperties.getPropertyValue("security", "password.encrypt")); userLogin.set("currentPassword", useEncryption ? HashCrypt.digestHash(LoginServices.getHashType(), null, autoPassword) : autoPassword); userLogin.store(); request.setAttribute("USERNAME", userLogin.getString("userLoginId")); request.setAttribute("PASSWORD", autoPassword); } catch (GenericEntityException e) { Debug.logError(e.getMessage(), module); request.setAttribute("_ERROR_MESSAGE_", e.toString()); return "error"; } catch (AuthenticatorException e) { Debug.logError(e.getMessage(), module); request.setAttribute("_ERROR_MESSAGE_", e.toString()); return "error"; } return "success"; }