List of usage examples for javax.servlet.http HttpServletRequest getAttributeNames
public Enumeration<String> getAttributeNames();
Enumeration
containing the names of the attributes available to this request. From source file:org.ejbca.ui.web.pub.AutoEnrollServlet.java
/** * Recievies the request.// www. j a v a 2s .c o m */ public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { log.trace(">doPost"); try { AuthenticationToken internalAdmin = new AlwaysAllowLocalAuthenticationToken( new UsernamePrincipal("AutoEnrollServlet: " + request.getRemoteAddr())); //Admin internalAdmin = Admin.getInternalAdmin(); GlobalConfiguration globalConfiguration = (GlobalConfiguration) globalConfigurationSession .getCachedConfiguration(GlobalConfiguration.GLOBAL_CONFIGURATION_ID); // Make sure we allow use of this Servlet if (!globalConfiguration.getAutoEnrollUse()) { log.info("Unauthorized access attempt from " + request.getRemoteAddr()); response.getOutputStream().println("Not allowed."); return; } int caid = globalConfiguration.getAutoEnrollCA(); if (caid == GlobalConfiguration.AUTOENROLL_DEFAULT_CA) { log.info("Configure a proper CA to use with enroll."); response.getOutputStream().println("Configure a proper CA to use with enroll."); return; } boolean debugRequest = "true".equalsIgnoreCase(request.getParameter("debug")); String debugInfo = ""; RequestHelper.setDefaultCharacterEncoding(request); if (debugRequest) { debugInfo += "getAttributeNames:\n"; Enumeration<?> enumeration = request.getAttributeNames(); while (enumeration.hasMoreElements()) { String temp = enumeration.nextElement().toString(); debugInfo += temp + " = " + request.getAttribute(temp) + "\n"; } debugInfo += "\ngetParameterNames:\n"; enumeration = request.getParameterNames(); while (enumeration.hasMoreElements()) { String temp = enumeration.nextElement().toString(); debugInfo += temp + " = " + request.getParameter(temp) + "\n"; } debugInfo += "\ngetHeaderNames:\n"; enumeration = request.getHeaderNames(); while (enumeration.hasMoreElements()) { String temp = enumeration.nextElement().toString(); debugInfo += temp + " = " + request.getHeader(temp) + "\n"; } debugInfo += "Remote address: " + request.getRemoteAddr() + "\n"; log.info(debugInfo); } byte[] result = null; String requestData = MSCertTools.extractRequestFromRawData(request.getParameter("request")); if (requestData == null) { response.getOutputStream().println("No request supplied.."); return; } log.info("Got request: " + requestData); // The next line expects apache to forward the kerberos-authenticated user as X-Remote-User" String remoteUser = request.getHeader("X-Remote-User"); String usernameShort = StringTools.stripUsername(remoteUser.substring(0, remoteUser.indexOf("@"))) .replaceAll("/", ""); if (remoteUser == null || "".equals(remoteUser) || "(null)".equals(remoteUser)) { response.getOutputStream().println("X-Remote-User was not supplied.."); return; } MSPKCS10RequestMessage req = null; String certificateTemplate = null; String command = request.getParameter("command"); if (command != null && "status".equalsIgnoreCase(command)) { response.getOutputStream().println(returnStatus(internalAdmin, "Autoenrolled-" + usernameShort + "-" + request.getParameter("template"))); return; } else { // Default command "request" } req = new MSPKCS10RequestMessage(Base64.decode(requestData.getBytes())); certificateTemplate = req.getMSRequestInfoTemplateName(); int templateIndex = MSCertTools.getTemplateIndex(certificateTemplate); /* TODO: Lookup requesting entity in AD here to verify that only Machines request Machine Certificates etc.. Also check permissions like who is allowed to enroll for what if possible. */ // Create or edit a user "Autoenrolled-Username-Templatename" String username = "Autoenrolled-" + usernameShort + "-" + certificateTemplate; log.info("Got autoenroll request from " + remoteUser + " (" + username + ") for a " + certificateTemplate + "-certificate."); String fetchedSubjectDN = null; if (MSCertTools.isRequired(templateIndex, MSCertTools.GET_SUBJECTDN_FROM_AD, 0)) { fetchedSubjectDN = ActiveDirectoryTools.getUserDNFromActiveDirectory(globalConfiguration, usernameShort); } int certProfileId = MSCertTools.getOrCreateCertificateProfile(internalAdmin, templateIndex, certificateProfileSession); int endEntityProfileId; try { endEntityProfileId = MSCertTools.getOrCreateEndEndtityProfile(internalAdmin, templateIndex, certProfileId, caid, usernameShort, fetchedSubjectDN, raAdminSession, endEntityProfileSession); } catch (EndEntityProfileNotFoundException e) { String msg = "Could not retrieve required information from AD."; log.error(msg, e); response.getOutputStream().println(msg); return; } catch (IllegalArgumentException e) { String msg = "Could not retrieve required information from AD."; log.error(msg, e); response.getOutputStream().println(msg); return; } // Create user // The CA needs to use non-LDAP order and we need to have the SAN like "CN=Users, CN=Username, DC=com, DC=company".. why?? // TODO: fix this here.. or is this an general order issue? String subjectDN = fetchedSubjectDN; if (subjectDN == null) { if (MSCertTools.isRequired(templateIndex, DnComponents.COMMONNAME, 0)) { subjectDN = "CN=" + usernameShort; } } String subjectAN = ""; if (MSCertTools.isRequired(templateIndex, DnComponents.UPN, 0)) { subjectAN += (subjectAN.length() == 0 ? "" : ",") + "UPN=" + remoteUser; } if (MSCertTools.isRequired(templateIndex, DnComponents.GUID, 0)) { String reqGUID = req.getMSRequestInfoSubjectAltnames()[0]; subjectAN += (subjectAN.length() == 0 ? "" : ",") + "GUID=" + reqGUID; } if (MSCertTools.isRequired(templateIndex, DnComponents.DNSNAME, 0)) { String reqDNS = req.getMSRequestInfoSubjectAltnames()[1]; subjectAN += (subjectAN.length() == 0 ? "" : ",") + "DNSNAME=" + reqDNS; } log.info("sdn=" + subjectDN + ", san=" + subjectAN); debugInfo += "\nsdn=" + subjectDN + ", san=" + subjectAN + "\n"; EndEntityInformation userData = new EndEntityInformation(username, subjectDN, caid, subjectAN, null, EndEntityConstants.STATUS_NEW, new EndEntityType(EndEntityTypes.ENDUSER), endEntityProfileId, certProfileId, new Date(), new Date(), SecConst.TOKEN_SOFT_BROWSERGEN, 0, null); String password = PasswordGeneratorFactory .getInstance(PasswordGeneratorFactory.PASSWORDTYPE_LETTERSANDDIGITS).getNewPassword(8, 8); userData.setPassword(password); try { if (endEntityManagementSession.existsUser(username)) { endEntityManagementSession.changeUser(internalAdmin, userData, true); } else { endEntityManagementSession.addUser(internalAdmin, userData, true); } } catch (Exception e) { log.error("Could not add user " + username, e); } Certificate cert = null; debugInfo += "Request: " + requestData + "\n"; req.setUsername(username); req.setPassword(password); ResponseMessage resp; try { resp = signSession.createCertificate(internalAdmin, req, X509ResponseMessage.class, null); cert = CertTools.getCertfromByteArray(resp.getResponseMessage()); result = signSession.createPKCS7(internalAdmin, cert, true); debugInfo += "Resulting cert: " + new String(Base64.encode(result, true)) + "\n"; } catch (Exception e) { log.error("Noooo!!! ", e); response.getOutputStream().println("An error has occurred."); return; } if (debugRequest) { response.getOutputStream().println(StringEscapeUtils.escapeJavaScript(debugInfo)); } else { // Output the certificate ServletOutputStream os = response.getOutputStream(); os.print(RequestHelper.BEGIN_PKCS7_WITH_NL); os.print(new String(Base64.encode(result, true))); os.print(RequestHelper.END_PKCS7_WITH_NL); response.flushBuffer(); log.info("Sent cert to client"); } } catch (AuthorizationDeniedException e1) { response.sendError(HttpServletResponse.SC_UNAUTHORIZED, e1.getMessage()); } log.trace("<doPost"); }
From source file:org.springframework.web.servlet.MyDispatcherServlet.java
/** * Exposes the DispatcherServlet-specific request attributes and delegates to {@link #doDispatch} * for the actual dispatching.//from w w w . java 2s . com */ @Override protected void doService(HttpServletRequest request, HttpServletResponse response) throws Exception { if (logger.isDebugEnabled()) { String requestUri = urlPathHelper.getRequestUri(request); logger.debug("DispatcherServlet with name '" + getServletName() + "' processing " + request.getMethod() + " request for [" + requestUri + "]"); } // Keep a snapshot of the request attributes in case of an include, // to be able to restore the original attributes after the include. Map<String, Object> attributesSnapshot = null; if (WebUtils.isIncludeRequest(request)) { logger.debug("Taking snapshot of request attributes before include"); attributesSnapshot = new HashMap<String, Object>(); Enumeration<?> attrNames = request.getAttributeNames(); while (attrNames.hasMoreElements()) { String attrName = (String) attrNames.nextElement(); if (this.cleanupAfterInclude || attrName.startsWith("org.springframework.web.servlet")) { attributesSnapshot.put(attrName, request.getAttribute(attrName)); } } } //zenglp //manually refresh webApplicationContext so do not need to restart the server if (request.getParameter("debug") != null) { if (this.context instanceof ConfigurableWebApplicationContext) { //this will reload the xml ((ConfigurableWebApplicationContext) this.context).refresh(); } onRefresh(getWebApplicationContext()); } // Make framework objects available to handlers and view objects. request.setAttribute(WEB_APPLICATION_CONTEXT_ATTRIBUTE, getWebApplicationContext()); request.setAttribute(LOCALE_RESOLVER_ATTRIBUTE, this.localeResolver); request.setAttribute(THEME_RESOLVER_ATTRIBUTE, this.themeResolver); request.setAttribute(THEME_SOURCE_ATTRIBUTE, getThemeSource()); FlashMap inputFlashMap = this.flashMapManager.retrieveAndUpdate(request, response); if (inputFlashMap != null) { request.setAttribute(INPUT_FLASH_MAP_ATTRIBUTE, Collections.unmodifiableMap(inputFlashMap)); } request.setAttribute(OUTPUT_FLASH_MAP_ATTRIBUTE, new FlashMap()); request.setAttribute(FLASH_MAP_MANAGER_ATTRIBUTE, this.flashMapManager); try { doDispatch(request, response); } finally { // Restore the original attribute snapshot, in case of an include. if (attributesSnapshot != null) { restoreAttributesAfterInclude(request, attributesSnapshot); } } }
From source file:com.wabacus.system.ReportRequest.java
public ReportRequest(HttpServletRequest request, int _showtype) { this.locallanguage = request.getLocale().getLanguage(); if (this.locallanguage == null || this.locallanguage.trim().toLowerCase().equals("en")) { this.locallanguage = ""; } else {//from ww w . j a v a 2 s . c o m this.locallanguage = this.locallanguage.trim().toLowerCase(); } Enumeration enume = request.getAttributeNames(); while (enume.hasMoreElements()) { String name = (String) enume.nextElement(); Object value = request.getAttribute(name); if (value != null) { if (this.attributes.containsKey(name)) { log.warn("request attribute????" + name + "?"); } this.attributes.put(name, value); } } Enumeration enumer = request.getParameterNames(); while (enumer.hasMoreElements()) { String name = (String) enumer.nextElement(); if (name != null && !name.trim().equals("")) { if (this.attributes.containsKey(name)) { log.warn("request????" + name + "?"); } String[] values = request.getParameterValues(name); if (values == null) { this.attributes.put(name, null); } else if (values.length == 1) { this.attributes.put(name, values[0]); } else { this.attributes.put(name, values); } } } this.showtype = _showtype; this.request = request; request.setAttribute("WX_REPORTREQUEST", this); this.actiontype = Tools.getRequestValue(request, "ACTIONTYPE", Consts.SHOWREPORT_ACTION); }
From source file:org.springframework.web.servlet.LogDispatcherServlet.java
/** * Exposes the DispatcherServlet-specific request attributes and delegates to {@link #doDispatch} * for the actual dispatching./* w w w . java 2s. c o m*/ */ @Override protected void doService(HttpServletRequest request, HttpServletResponse response) throws Exception { if (logger.isDebugEnabled()) { String resumed = WebAsyncUtils.getAsyncManager(request).hasConcurrentResult() ? " resumed" : ""; logger.debug("DispatcherServlet with name '" + getServletName() + "'" + resumed + " processing " + request.getMethod() + " request for [" + getRequestUri(request) + "]"); } // Keep a snapshot of the request attributes in case of an include, // to be able to restore the original attributes after the include. Map<String, Object> attributesSnapshot = null; if (WebUtils.isIncludeRequest(request)) { attributesSnapshot = new HashMap<String, Object>(); Enumeration<?> attrNames = request.getAttributeNames(); while (attrNames.hasMoreElements()) { String attrName = (String) attrNames.nextElement(); if (this.cleanupAfterInclude || attrName.startsWith("org.springframework.web.servlet")) { attributesSnapshot.put(attrName, request.getAttribute(attrName)); } } } // Make framework objects available to handlers and view objects. request.setAttribute(WEB_APPLICATION_CONTEXT_ATTRIBUTE, getWebApplicationContext()); request.setAttribute(LOCALE_RESOLVER_ATTRIBUTE, this.localeResolver); request.setAttribute(THEME_RESOLVER_ATTRIBUTE, this.themeResolver); request.setAttribute(THEME_SOURCE_ATTRIBUTE, getThemeSource()); FlashMap inputFlashMap = this.flashMapManager.retrieveAndUpdate(request, response); if (inputFlashMap != null) { request.setAttribute(INPUT_FLASH_MAP_ATTRIBUTE, Collections.unmodifiableMap(inputFlashMap)); } request.setAttribute(OUTPUT_FLASH_MAP_ATTRIBUTE, new FlashMap()); request.setAttribute(FLASH_MAP_MANAGER_ATTRIBUTE, this.flashMapManager); try { doDispatch(request, response); } finally { if (!WebAsyncUtils.getAsyncManager(request).isConcurrentHandlingStarted()) { // Restore the original attribute snapshot, in case of an include. if (attributesSnapshot != null) { restoreAttributesAfterInclude(request, attributesSnapshot); } } } }
From source file:org.springframework.web.servlet.DispatcherServlet.java
/** * Exposes the DispatcherServlet-specific request attributes and delegates to {@link #doDispatch} * for the actual dispatching.//from ww w . j ava 2 s. c om */ @Override protected void doService(HttpServletRequest request, HttpServletResponse response) throws Exception { if (logger.isDebugEnabled()) { String resumed = WebAsyncUtils.getAsyncManager(request).hasConcurrentResult() ? " resumed" : ""; logger.debug("DispatcherServlet with name '" + getServletName() + "'" + resumed + " processing " + request.getMethod() + " request for [" + getRequestUri(request) + "]"); } // Keep a snapshot of the request attributes in case of an include, // to be able to restore the original attributes after the include. Map<String, Object> attributesSnapshot = null; if (WebUtils.isIncludeRequest(request)) { attributesSnapshot = new HashMap<>(); Enumeration<?> attrNames = request.getAttributeNames(); while (attrNames.hasMoreElements()) { String attrName = (String) attrNames.nextElement(); if (this.cleanupAfterInclude || attrName.startsWith(DEFAULT_STRATEGIES_PREFIX)) { attributesSnapshot.put(attrName, request.getAttribute(attrName)); } } } // Make framework objects available to handlers and view objects. request.setAttribute(WEB_APPLICATION_CONTEXT_ATTRIBUTE, getWebApplicationContext()); request.setAttribute(LOCALE_RESOLVER_ATTRIBUTE, this.localeResolver); request.setAttribute(THEME_RESOLVER_ATTRIBUTE, this.themeResolver); request.setAttribute(THEME_SOURCE_ATTRIBUTE, getThemeSource()); if (this.flashMapManager != null) { FlashMap inputFlashMap = this.flashMapManager.retrieveAndUpdate(request, response); if (inputFlashMap != null) { request.setAttribute(INPUT_FLASH_MAP_ATTRIBUTE, Collections.unmodifiableMap(inputFlashMap)); } request.setAttribute(OUTPUT_FLASH_MAP_ATTRIBUTE, new FlashMap()); request.setAttribute(FLASH_MAP_MANAGER_ATTRIBUTE, this.flashMapManager); } try { doDispatch(request, response); } finally { if (!WebAsyncUtils.getAsyncManager(request).isConcurrentHandlingStarted()) { // Restore the original attribute snapshot, in case of an include. if (attributesSnapshot != null) { restoreAttributesAfterInclude(request, attributesSnapshot); } } } }
From source file:org.mifos.framework.struts.action.MifosRequestProcessor.java
/** * This method is overridden because in case of exception we need to * populate the request with the old values so that when the user goes back * to the previous page it has all the values in the request.For this we * create an object which will store the values of previous request in case * the request is successful and if there is an exception it reads values * from that object and context and dups all in the request. *//*from w w w.ja v a 2s . co m*/ @Override protected ActionForward processActionPerform(HttpServletRequest request, HttpServletResponse response, Action action, ActionForm form, ActionMapping mapping) throws IOException, ServletException { ActivityContext activityContext = null; ActionForward forward = null; HttpSession session = request.getSession(); // gets the object where we will store values from request. PreviousRequestValues previousRequestValues = (PreviousRequestValues) session .getAttribute(Constants.PREVIOUS_REQUEST); if (null == previousRequestValues) { previousRequestValues = new PreviousRequestValues(); session.setAttribute(Constants.PREVIOUS_REQUEST, previousRequestValues); } // getting the activity context from the session activityContext = (ActivityContext) session.getAttribute("ActivityContext"); // check if the action desired is permissible or not. // if allowed invoke the execute method of the action class try { String currentFlowKey = request.getParameter(Constants.CURRENTFLOWKEY); if (currentFlowKey != null) { previousRequestValues.getPreviousRequestValueMap().put(Constants.CURRENTFLOWKEY, currentFlowKey); } forward = (action.execute(mapping, form, request, response)); String method = request.getParameter("method"); if (method.equals(ClientConstants.METHOD_RETRIEVE_PICTURE)) { forward = mapping.findForward("get_success"); } // set the last forward in the activity context if (activityContext != null) { activityContext.setLastForward(forward); } // read the request and add the values to the PreviousRequestValues // object. this will set every thing in the request apart from // context and value object. Enumeration requestAttributes = request.getAttributeNames(); while (requestAttributes.hasMoreElements()) { String nextName = (String) requestAttributes.nextElement(); if (nextName.startsWith(Constants.STORE_ATTRIBUTE) || nextName.equalsIgnoreCase(Constants.CURRENTFLOWKEY)) { logger.debug(nextName + "=" + request.getAttribute(nextName)); previousRequestValues.getPreviousRequestValueMap().put(nextName, request.getAttribute(nextName)); } } } catch (Exception e) { // processException logs an error (see MifosExceptionHandler) forward = (processException(request, response, e, form, mapping)); // set the last forward in the activity context if (activityContext != null) { activityContext.setLastForward(forward); } populateTheRequestFromPreviousValues(request, previousRequestValues); } finally { try { session.removeAttribute(SecurityConstants.SECURITY_PARAM); } catch (Exception e) { // FIXME: yikes, what is being swallowed here? } } if (null != forward) { logger.info("forward.path=" + forward.getPath()); } return forward; }
From source file:com.mystudy.source.spring.mvc.DispatcherServlet.java
/** * Exposes the DispatcherServlet-specific request attributes and delegates to {@link #doDispatch} * for the actual dispatching./*from ww w .jav a 2 s. c o m*/ */ @Override protected void doService(HttpServletRequest request, HttpServletResponse response) throws Exception { if (logger.isDebugEnabled()) { String requestUri = urlPathHelper.getRequestUri(request); String resumed = WebAsyncUtils.getAsyncManager(request).hasConcurrentResult() ? " resumed" : ""; logger.debug("DispatcherServlet with name '" + getServletName() + "'" + resumed + " processing " + request.getMethod() + " request for [" + requestUri + "]"); } // Keep a snapshot of the request attributes in case of an include, // to be able to restore the original attributes after the include. Map<String, Object> attributesSnapshot = null; if (WebUtils.isIncludeRequest(request)) { logger.debug("Taking snapshot of request attributes before include"); attributesSnapshot = new HashMap<String, Object>(); Enumeration<?> attrNames = request.getAttributeNames(); while (attrNames.hasMoreElements()) { String attrName = (String) attrNames.nextElement(); if (this.cleanupAfterInclude || attrName.startsWith("org.springframework.web.servlet")) { attributesSnapshot.put(attrName, request.getAttribute(attrName)); } } } // Make framework objects available to handlers and view objects. request.setAttribute(WEB_APPLICATION_CONTEXT_ATTRIBUTE, getWebApplicationContext()); request.setAttribute(LOCALE_RESOLVER_ATTRIBUTE, this.localeResolver); request.setAttribute(THEME_RESOLVER_ATTRIBUTE, this.themeResolver); request.setAttribute(THEME_SOURCE_ATTRIBUTE, getThemeSource()); FlashMap inputFlashMap = this.flashMapManager.retrieveAndUpdate(request, response); if (inputFlashMap != null) { request.setAttribute(INPUT_FLASH_MAP_ATTRIBUTE, Collections.unmodifiableMap(inputFlashMap)); } request.setAttribute(OUTPUT_FLASH_MAP_ATTRIBUTE, new FlashMap()); request.setAttribute(FLASH_MAP_MANAGER_ATTRIBUTE, this.flashMapManager); try { doDispatch(request, response); } finally { if (WebAsyncUtils.getAsyncManager(request).isConcurrentHandlingStarted()) { return; } // Restore the original attribute snapshot, in case of an include. if (attributesSnapshot != null) { restoreAttributesAfterInclude(request, attributesSnapshot); } } }
From source file:net.ymate.framework.webmvc.AbstractWebErrorProcessor.java
private String __doParseExceptionDetail(Throwable e) { IRequestContext _requestCtx = WebContext.getRequestContext(); HttpServletRequest _request = WebContext.getRequest(); WebContext _context = WebContext.getContext(); ///*from w ww . ja va 2 s . c o m*/ StringBuilder _errSB = new StringBuilder("An exception occurred at ") .append(DateTimeUtils.formatTime(System.currentTimeMillis(), DateTimeUtils.YYYY_MM_DD_HH_MM_SS_SSS)) .append(":\n"); _errSB.append("-------------------------------------------------\n"); _errSB.append("-- ThreadId: ").append(Thread.currentThread().getId()).append("\n"); _errSB.append("-- RequestMapping: ").append(_requestCtx.getRequestMapping()).append("\n"); _errSB.append("-- ResponseStatus: ").append(((GenericResponseWrapper) WebContext.getResponse()).getStatus()) .append("\n"); _errSB.append("-- Method: ").append(_requestCtx.getHttpMethod().name()).append("\n"); _errSB.append("-- RemoteAddrs: ").append(JSON.toJSONString(WebUtils.getRemoteAddrs(_request))).append("\n"); RequestMeta _meta = _context.getAttribute(RequestMeta.class.getName()); if (_meta != null) { _errSB.append("-- Controller: ").append(_meta.getTargetClass().getName()).append(":") .append(_meta.getMethod().getName()).append("\n"); } _errSB.append("-- ContextAttributes:").append("\n"); for (Map.Entry<String, Object> _entry : _context.getAttributes().entrySet()) { if (!StringUtils.startsWith(_entry.getKey(), "net.ymate.platform.webmvc")) { _errSB.append("\t ").append(_entry.getKey()).append(": ") .append(JSON.toJSONString(_entry.getValue())).append("\n"); } } _errSB.append("-- Parameters:").append("\n"); for (Map.Entry<String, Object> _entry : _context.getParameters().entrySet()) { _errSB.append("\t ").append(_entry.getKey()).append(": ").append(JSON.toJSONString(_entry.getValue())) .append("\n"); } _errSB.append("-- Attributes:").append("\n"); Enumeration _enum = _request.getAttributeNames(); while (_enum.hasMoreElements()) { String _attrName = (String) _enum.nextElement(); _errSB.append("\t ").append(_attrName).append(": ") .append(JSON.toJSONString(_request.getAttribute(_attrName))).append("\n"); } _errSB.append("-- Headers:").append("\n"); _enum = _request.getHeaderNames(); while (_enum.hasMoreElements()) { String _headName = (String) _enum.nextElement(); if ("cookie".equalsIgnoreCase(_headName)) { continue; } _errSB.append("\t ").append(_headName).append(": ") .append(JSON.toJSONString(_request.getHeader(_headName))).append("\n"); } _errSB.append("-- Cookies:").append("\n"); Cookie[] _cookies = _request.getCookies(); if (_cookies != null) { for (Cookie _cookie : _cookies) { _errSB.append("\t ").append(_cookie.getName()).append(": ") .append(JSON.toJSONString(_cookie.getValue())).append("\n"); } } _errSB.append("-- Session:").append("\n"); for (Map.Entry<String, Object> _entry : _context.getSession().entrySet()) { _errSB.append("\t ").append(_entry.getKey()).append(": ").append(JSON.toJSONString(_entry.getValue())) .append("\n"); } _errSB.append(__doExceptionToString(e)); _errSB.append("-------------------------------------------------\n"); // return _errSB.toString(); }
From source file:org.osaf.cosmo.dav.servlet.StandardRequestHandler.java
@SuppressWarnings("unchecked") private void dumpRequest(HttpServletRequest req) { if (!log.isTraceEnabled()) return;//www .ja v a 2 s . c o m StringBuffer sb = new StringBuffer("\n------------------------ Dump of request -------------------\n"); try { Enumeration names = req.getHeaderNames(); sb.append("Request headers:\n"); while (names.hasMoreElements()) { String key = (String) names.nextElement(); String val = req.getHeader(key); sb.append(" ").append(key).append(" = \"").append(val).append("\"\n"); } names = req.getParameterNames(); String title = "Request parameters"; sb.append(title).append(" - global info and uris:").append("\n"); sb.append("getMethod = ").append(req.getMethod()).append("\n"); sb.append("getRemoteAddr = ").append(req.getRemoteAddr()).append("\n"); sb.append("getRequestURI = ").append(req.getRequestURI()).append("\n"); sb.append("getRemoteUser = ").append(req.getRemoteUser()).append("\n"); sb.append("getRequestedSessionId = ").append(req.getRequestedSessionId()).append("\n"); sb.append("HttpUtils.getRequestURL(req) = ").append(req.getRequestURL()).append("\n"); sb.append("contextPath=").append(req.getContextPath()).append("\n"); sb.append("query=").append(req.getQueryString()).append("\n"); sb.append("contentlen=").append(req.getContentLength()).append("\n"); sb.append("request=").append(req).append("\n"); sb.append(title).append(":\n"); while (names.hasMoreElements()) { String key = (String) names.nextElement(); String val = req.getParameter(key); sb.append(" ").append(key).append(" = \"").append(val).append("\"").append("\n"); ; } sb.append("Request attributes:\n"); for (Enumeration<String> e = req.getAttributeNames(); e.hasMoreElements();) { String key = (String) e.nextElement(); Object val = req.getAttribute(key); sb.append(" ").append(key).append(" = \"").append(val).append("\"").append("\n"); ; } } catch (Throwable t) { t.printStackTrace(); } sb.append("------------------------ End dump of request -------------------"); log.trace(sb); }
From source file:com.founder.fix.fixflow.FlowCenter.java
/** * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse * response)/*from ww w .ja v a 2s.com*/ */ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String userId = StringUtil.getString(request.getSession().getAttribute(FlowCenterService.LOGIN_USER_ID)); if (StringUtil.isEmpty(userId)) { String context = request.getContextPath(); response.sendRedirect(context + "/"); return; } CurrentThread.init(); ServletOutputStream out = null; String action = StringUtil.getString(request.getParameter("action")); if (StringUtil.isEmpty(action)) { action = StringUtil.getString(request.getAttribute("action")); } if (StringUtil.isEmpty(action)) { action = "getMyTask"; } RequestDispatcher rd = null; try { Map<String, Object> filter = new HashMap<String, Object>(); if (ServletFileUpload.isMultipartContent(request)) { ServletFileUpload Uploader = new ServletFileUpload(new DiskFileItemFactory()); // Uploader.setSizeMax("); // Uploader.setHeaderEncoding("utf-8"); List<FileItem> fileItems = Uploader.parseRequest(request); for (FileItem item : fileItems) { filter.put(item.getFieldName(), item); if (item.getFieldName().equals("action")) action = item.getString(); } } else { Enumeration enu = request.getParameterNames(); while (enu.hasMoreElements()) { Object tmp = enu.nextElement(); Object obj = request.getParameter(StringUtil.getString(tmp)); // if (request.getAttribute("ISGET") != null) obj = new String(obj.toString().getBytes("ISO8859-1"), "utf-8"); filter.put(StringUtil.getString(tmp), obj); } } Enumeration attenums = request.getAttributeNames(); while (attenums.hasMoreElements()) { String paramName = (String) attenums.nextElement(); Object paramValue = request.getAttribute(paramName); // ?map filter.put(paramName, paramValue); } filter.put("userId", userId); request.setAttribute("nowAction", action); if (action.equals("getMyProcess")) { rd = request.getRequestDispatcher("/fixflow/center/startTask.jsp"); List<Map<String, String>> result = getFlowCenter().queryStartProcess(userId); Map<String, List<Map<String, String>>> newResult = new HashMap<String, List<Map<String, String>>>(); for (Map<String, String> tmp : result) { String category = tmp.get("category"); if (StringUtil.isEmpty(category)) category = ""; List<Map<String, String>> tlist = newResult.get(category); if (tlist == null) { tlist = new ArrayList<Map<String, String>>(); } tlist.add(tmp); newResult.put(category, tlist); } request.setAttribute("result", newResult); //??sqlserverbug???? request.setAttribute("userId", userId); // userId add Rex try { List<Map<String, String>> lastestProcess = getFlowCenter().queryLastestProcess(userId); request.setAttribute("lastest", lastestProcess); } catch (Exception ex) { ex.printStackTrace(); } } else if (action.equals("getMyTask")) { rd = request.getRequestDispatcher("/fixflow/center/todoTask.jsp"); filter.put("path", request.getSession().getServletContext().getRealPath("/")); Map<String, Object> pageResult = getFlowCenter().queryMyTaskNotEnd(filter); filter.putAll(pageResult); request.setAttribute("result", filter); request.setAttribute("pageInfo", filter.get("pageInfo")); } else if (action.equals("getProcessImage")) { response.getOutputStream(); } else if (action.equals("getAllProcess")) { rd = request.getRequestDispatcher("/fixflow/center/queryprocess.jsp"); Map<String, Object> pageResult = getFlowCenter().queryTaskInitiator(filter); filter.putAll(pageResult); request.setAttribute("result", filter); request.setAttribute("pageInfo", filter.get("pageInfo")); } else if (action.equals("getPlaceOnFile")) { rd = request.getRequestDispatcher("/fixflow/center/placeOnFile.jsp"); Map<String, Object> pageResult = getFlowCenter().queryPlaceOnFile(filter); filter.putAll(pageResult); request.setAttribute("result", filter); request.setAttribute("pageInfo", filter.get("pageInfo")); } else if (action.equals("getTaskDetailInfo")) { rd = request.getRequestDispatcher("/fixflow/center/flowGraphic.jsp"); Map<String, Object> pageResult = getFlowCenter().getTaskDetailInfo(filter); filter.putAll(pageResult); request.setAttribute("result", filter); } else if (action.equals("getTaskDetailInfoSVG")) { rd = request.getRequestDispatcher("/fixflow/center/flowGraphic.jsp"); Map<String, Object> pageResult = getFlowCenter().getTaskDetailInfoSVG(filter); filter.putAll(pageResult); request.setAttribute("result", filter); } else if (action.equals("getFlowGraph")) { InputStream is = getFlowCenter().getFlowGraph(filter); out = response.getOutputStream(); response.setContentType("application/octet-stream;charset=UTF-8"); byte[] buff = new byte[2048]; int size = 0; while (is != null && (size = is.read(buff)) != -1) { out.write(buff, 0, size); } } else if (action.equals("getUserInfo")) { rd = request.getRequestDispatcher("/fixflow/common/userInfo.jsp"); filter.put("path", request.getSession().getServletContext().getRealPath("/")); Map<String, Object> pageResult = getFlowCenter().getUserInfo(filter); filter.putAll(pageResult); request.setAttribute("result", filter); } else if (action.equals("getUserIcon")) { rd = request.getRequestDispatcher("/fixflow/common/userOperation.jsp"); filter.put("path", request.getSession().getServletContext().getRealPath("/")); Map<String, Object> pageResult = getFlowCenter().getUserInfo(filter); filter.putAll(pageResult); request.setAttribute("result", filter); } else if (action.equals("updateUserIcon")) { rd = request.getRequestDispatcher("/FlowCenter?action=getUserInfo"); filter.put("path", request.getSession().getServletContext().getRealPath("/")); getFlowCenter().saveUserIcon(filter); } else if (action.equals("selectUserList")) { // String isMulti = request.getParameter("isMulti"); rd = request.getRequestDispatcher("/fixflow/common/selectUserList.jsp?isMulti=" + isMulti); Map<String, Object> pageResult = getFlowCenter().getAllUsers(filter); filter.putAll(pageResult); request.setAttribute("result", filter); request.setAttribute("isMulti", isMulti); request.setAttribute("pageInfo", filter.get("pageInfo")); } else if (action.equals("selectNodeList")) { // rd = request.getRequestDispatcher("/fixflow/common/selectNodeList.jsp"); Map<String, Object> pageResult = getFlowCenter().getRollbackNode(filter); filter.putAll(pageResult); request.setAttribute("result", filter); } else if (action.equals("selectStepList")) { // rd = request.getRequestDispatcher("/fixflow/common/selectStepList.jsp"); Map<String, Object> pageResult = getFlowCenter().getRollbackTask(filter); filter.putAll(pageResult); request.setAttribute("result", filter); } else if (action.equals("viewDelegation")) { // rd = request.getRequestDispatcher("/fixflow/common/setDelegation.jsp"); Map<String, Object> pageResult = new HashMap<String, Object>(); pageResult = this.getFlowIdentityService().getUserDelegationInfo(userId); filter.putAll(pageResult); request.setAttribute("result", filter); } else if (action.equals("saveDelegation")) { // String agentInfoJson = StringUtil.getString(request.getParameter("insertAndUpdate")); if (StringUtil.isNotEmpty(agentInfoJson)) { Map<String, Object> delegationInfo = JSONUtil.parseJSON2Map(agentInfoJson); this.getFlowIdentityService().saveUserDelegationInfo(delegationInfo); } response.setContentType("text/html;charset=UTF-8"); response.getWriter().write("<script>alert('??');window.close();</script>"); } } catch (Exception e) { e.printStackTrace(); request.setAttribute("errorMsg", e.getMessage()); try { CurrentThread.rollBack(); } catch (SQLException e1) { e1.printStackTrace(); request.setAttribute("errorMsg", e.getMessage()); } } finally { if (out != null) { out.flush(); out.close(); } try { CurrentThread.clear(); } catch (SQLException e) { request.setAttribute("errorMsg", e.getMessage()); e.printStackTrace(); } } if (rd != null) { rd.forward(request, response); } }