Example usage for javax.servlet.http HttpServletRequest getAttributeNames

List of usage examples for javax.servlet.http HttpServletRequest getAttributeNames

Introduction

In this page you can find the example usage for javax.servlet.http HttpServletRequest getAttributeNames.

Prototype

public Enumeration<String> getAttributeNames();

Source Link

Document

Returns an Enumeration containing the names of the attributes available to this request.

Usage

From source file:org.unitedinternet.cosmo.dav.servlet.StandardRequestHandler.java

private void dumpRequest(HttpServletRequest req) {
    if (!LOG.isTraceEnabled()) {
        return;/*w  ww .j  a  v  a  2 s  . c o  m*/
    }

    StringBuffer sb = new StringBuffer("\n------------------------ Dump of request -------------------\n");
    try {
        Enumeration<String> names = req.getHeaderNames();

        sb.append("Request headers:\n");
        while (names.hasMoreElements()) {
            String key = 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 (Exception e) {
        LOG.error("Error on dumpRequest class StandardRequestHandler " + e);
    }
    sb.append("------------------------ End dump of request -------------------");
    //Fix Log Forging - java fortify
    //Writing unvalidated user input to log files can allow an attacker to forge log entries or
    //inject malicious content into the logs.

    LOG.trace(sb.toString());
}

From source file:com.founder.fix.fixflow.FlowManager.java

@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    CurrentThread.init();//from w  w  w. ja v  a 2s .  c  o  m
    String userId = StringUtil.getString(request.getSession().getAttribute(FlowCenterService.LOGIN_USER_ID));
    if (StringUtil.isEmpty(userId)) {
        String context = request.getContextPath();
        response.sendRedirect(context + "/");
        return;
    }
    ServletOutputStream out = null;
    String action = StringUtil.getString(request.getParameter("action"));
    if (StringUtil.isEmpty(action)) {
        action = StringUtil.getString(request.getAttribute("action"));
    }
    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();
                if (item.getFieldName().equals("deploymentId")) {
                    filter.put("deploymentId", 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 ("processDefinitionList".equals(action)) {
            rd = request.getRequestDispatcher("/fixflow/manager/processDefinitionList.jsp");
            Map<String, Object> result = getProcessDefinitionService().getProcessDefitionList(filter);
            filter.putAll(result);
            request.setAttribute("result", filter);
            request.setAttribute("pageInfo", filter.get("pageInfo"));
        } else if (action.equals("processManageList")) {
            rd = request.getRequestDispatcher("/fixflow/manager/processInstanceList.jsp");
            Map<String, Object> result = getFlowManager().getProcessInstances(filter);
            filter.putAll(result);
            request.setAttribute("result", filter);
            request.setAttribute("pageInfo", filter.get("pageInfo"));
        } else if (action.equals("suspendProcessInstance")) {
            rd = request.getRequestDispatcher("/FlowManager?action=processManageList");
            getFlowManager().suspendProcessInstance(filter);
        } else if (action.equals("continueProcessInstance")) {
            rd = request.getRequestDispatcher("/FlowManager?action=processManageList");
            getFlowManager().continueProcessInstance(filter);

        } else if (action.equals("terminatProcessInstance")) {
            rd = request.getRequestDispatcher("/FlowManager?action=processManageList");
            getFlowManager().terminatProcessInstance(filter);
        } else if (action.equals("deleteProcessInstance")) {
            rd = request.getRequestDispatcher("/FlowManager?action=processManageList");
            getFlowManager().deleteProcessInstance(filter);
        } else if (action.equals("toProcessVariable")) {
            rd = request.getRequestDispatcher("/fixflow/manager/processVariableList.jsp");
            Map<String, Object> result = getFlowManager().getProcessVariables(filter);
            filter.putAll(result);
            request.setAttribute("result", filter);
        } else if (action.equals("saveProcessVariables")) {
            String tmp = (String) filter.get("insertAndUpdate");
            if (StringUtil.isNotEmpty(tmp)) {
                Map<String, Object> tMap = JSONUtil.parseJSON2Map(tmp);
                filter.put("insertAndUpdate", tMap);
            }
            getFlowManager().saveProcessVariables(filter);
            rd = request.getRequestDispatcher("/FlowManager?action=toProcessVariable");
        } else if (action.equals("processTokenList")) {
            Map<String, Object> result = getFlowManager().getProcessTokens(filter);
            filter.putAll(result);
            request.setAttribute("result", filter);
            rd = request.getRequestDispatcher("/fixflow/manager/processTokenList.jsp");
        } else if (action.equals("taskInstanceList")) {
            rd = request.getRequestDispatcher("/fixflow/manager/taskInstanceList.jsp");
            filter.put("path", request.getSession().getServletContext().getRealPath("/"));
            Map<String, Object> pageResult = getTaskManager().getTaskList(filter);
            filter.putAll(pageResult);
            request.setAttribute("result", filter);
            request.setAttribute("pageInfo", filter.get("pageInfo"));
        } else if (action.equals("doTaskSuspend")) {
            rd = request.getRequestDispatcher("/FlowManager?action=taskInstanceList");
            getTaskManager().suspendTask(filter);
        } else if (action.equals("doTaskResume")) {
            rd = request.getRequestDispatcher("/FlowManager?action=taskInstanceList");
            getTaskManager().resumeTask(filter);
        } else if (action.equals("doTaskTransfer")) {
            rd = request.getRequestDispatcher("/FlowManager?action=taskInstanceList");
            getTaskManager().transferTask(filter);
        } else if (action.equals("doTaskRollBackNode")) {
            rd = request.getRequestDispatcher("/FlowManager?action=taskInstanceList");
            getTaskManager().rollBackNode(filter);
        } else if (action.equals("doTaskRollBackTask")) {
            rd = request.getRequestDispatcher("/FlowManager?action=taskInstanceList");
            getTaskManager().rollBackStep(filter);
        } else if (action.equals("flowLibrary")) {
            rd = request.getRequestDispatcher("/fixflow-explorer/flowLibrary.jsp");
        }
        //???deploymentId
        if ("deploy".equals(action)) {
            rd = request.getRequestDispatcher("/FlowManager?action=processDefinitionList");
            response.setContentType("text/html;charset=utf-8");
            getProcessDefinitionService().deployByZip(filter);
        } else if ("deleteDeploy".equals(action)) {
            rd = request.getRequestDispatcher("/FlowManager?action=processDefinitionList");
            getProcessDefinitionService().deleteDeploy(filter);
        } else if ("download".equals(action)) {
            String processDefinitionId = StringUtil.getString(filter.get("processDefinitionId"));
            response.reset();
            request.setCharacterEncoding("gbk");
            response.setContentType("applcation/octet-stream");
            response.setHeader("Content-disposition", "attachment; filename=" + processDefinitionId + ".zip");
            response.setHeader("Cache-Control",
                    "must-revalidate, post-check=0, pre-check=0,private, max-age=0");
            response.setHeader("Content-Type", "application/octet-stream");
            response.setHeader("Content-Type", "application/force-download");
            response.setHeader("Pragma", "public");
            response.setHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0");

            ZipOutputStream outZip = new ZipOutputStream(response.getOutputStream());
            List<Map<String, Object>> fileList = getProcessDefinitionService().getResources(filter);
            for (Map<String, Object> file : fileList) {
                ZipEntry entry = new ZipEntry(file.get("FILENAME").toString());
                entry.setSize(((byte[]) file.get("BYTES")).length);
                outZip.putNextEntry(entry);
                outZip.write((byte[]) file.get("BYTES"));
                outZip.closeEntry();
            }
            outZip.close();
            outZip.flush();
            outZip.close();
        } else if ("getUserList".equals(action)) {
            rd = request.getRequestDispatcher("/fixflow/manager/userList.jsp");
            request.setAttribute("nowAction", "UserGroup");
            Map<String, Object> result = getUserGroupService().getAllUsers(filter);
            filter.putAll(result);
            request.setAttribute("result", filter);

            List<Map<String, Object>> groupList = getUserGroupService().getAllGroupDefinition(filter);
            request.setAttribute("groupList", groupList);
            request.setAttribute("pageInfo", filter.get("pageInfo"));
        } else if ("getGroupList".equals(action)) {
            rd = request.getRequestDispatcher("/fixflow/manager/groupList.jsp");
            request.setAttribute("nowAction", "UserGroup");
            Map<String, Object> result = getUserGroupService().getAllGroup(filter);
            filter.putAll(result);
            request.setAttribute("result", filter);
            List<Map<String, Object>> groupList = getUserGroupService().getAllGroupDefinition(filter);
            request.setAttribute("groupList", groupList);
            request.setAttribute("pageInfo", filter.get("pageInfo"));
        } else if ("getUserInfo".equals(action)) {
            rd = request.getRequestDispatcher("/fixflow/manager/userInfo.jsp");
            Map<String, Object> pageResult = getUserGroupService().getUserInfo(filter);
            filter.putAll(pageResult);
            request.setAttribute("result", filter);
        } else if ("getGroupInfo".equals(action)) {
            rd = request.getRequestDispatcher("/fixflow/manager/groupInfo.jsp");
            Map<String, Object> pageResult = getUserGroupService().getGroupInfo(filter);
            filter.putAll(pageResult);
            request.setAttribute("result", filter);
        } else if ("getJobList".equals(action)) {
            rd = request.getRequestDispatcher("/fixflow/manager/jobList.jsp");
            request.setAttribute("nowAction", "jobManager");
            Map<String, Object> result = getJobService().getJobList(filter);
            filter.putAll(result);
            request.setAttribute("result", filter);
        } else if ("viewJobInfo".equals(action)) {
            rd = request.getRequestDispatcher("/fixflow/manager/jobInfo.jsp");
            request.setAttribute("nowAction", "jobManager");
            Map<String, Object> result = getJobService().getJobTrigger(filter);
            filter.putAll(result);
            request.setAttribute("result", filter);
        } else if ("suspendJob".equals(action)) {
            rd = request.getRequestDispatcher("/fixflow/manager/jobList.jsp");
            request.setAttribute("nowAction", "jobManager");
            getJobService().suspendJob(filter);
            Map<String, Object> result = getJobService().getJobList(filter);
            filter.putAll(result);
            request.setAttribute("result", filter);
        } else if ("continueJob".equals(action)) {
            rd = request.getRequestDispatcher("/fixflow/manager/jobList.jsp");
            getJobService().continueJob(filter);
            request.setAttribute("nowAction", "jobManager");
            Map<String, Object> result = getJobService().getJobList(filter);
            filter.putAll(result);
            request.setAttribute("result", filter);
        } else if ("suspendTrigger".equals(action)) {
            rd = request.getRequestDispatcher("/fixflow/manager/jobInfo.jsp");
            getJobService().suspendTrigger(filter);
            request.setAttribute("nowAction", "jobManager");
            Map<String, Object> result = getJobService().getJobTrigger(filter);
            filter.putAll(result);
            request.setAttribute("result", filter);
        } else if ("continueTrigger".equals(action)) {
            rd = request.getRequestDispatcher("/fixflow/manager/jobInfo.jsp");
            getJobService().continueTrigger(filter);
            request.setAttribute("nowAction", "jobManager");
            Map<String, Object> result = getJobService().getJobTrigger(filter);
            filter.putAll(result);
            request.setAttribute("result", filter);
        } else if ("setHis".equals(action)) {
            rd = request.getRequestDispatcher("/FlowManager?action=processManageList");
            getFlowManager().setHistory(filter);
        } else if ("updateCache".equals(action)) {
            ProcessEngineManagement.getDefaultProcessEngine().cleanCache(true, true);
            response.getWriter().write("update success!");
        }
    } 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) {
            e.printStackTrace();
            request.setAttribute("errorMsg", e.getMessage());
        }
    }
    if (rd != null)
        rd.forward(request, response);
}

From source file:ar.edu.unicen.exa.aop.aopetstore.waf.view.taglibs.smart.ClientStateTag.java

public int doEndTag() throws JspTagException {
    HttpServletRequest request = ((HttpServletRequest) pageContext.getRequest());
    StringBuffer buffer = new StringBuffer();
    buffer.append("<form method=\"POST\" action=\"" + targetURL + "\">");
    // insert any parameters that may have been added via sub tags
    if (parameters != null) {
        Iterator<String> it = parameters.keySet().iterator();
        // put the request attributes stored in the session in the request
        while (it.hasNext()) {
            String key = it.next();
            String value = parameters.get(key);
            buffer.append(" <input type=\"hidden\" name=\"" + key + "\" value=\"" + value + "\" />");
        }// w  w  w. ja v a2  s .  co  m
    }
    String fullURL = request.getRequestURI();
    // find the url that sent us this page
    String targetURL = null;
    int lastPathSeparator = fullURL.lastIndexOf("/") + 1;
    if (lastPathSeparator != -1) {
        targetURL = fullURL.substring(lastPathSeparator, fullURL.length());
    }
    buffer.append(" <input type=\"hidden\" name=\"referring_URL\"" + "value=\"" + targetURL + "\">");
    String referringScreen = (String) request.getSession().getAttribute(WebKeys.PREVIOUS_SCREEN);
    buffer.append(" <input type=\"hidden\" name=\"referring_screen\"" + "value=\"" + referringScreen + "\">");
    buffer.append(" <input type=\"hidden\" name=\"cacheId\"" + "value=\"" + cacheId + "\">");
    // check the request for previous parameters
    Map<?, ?> params = (Map<?, ?>) request.getParameterMap();
    if (!params.isEmpty() && encodeRequestParameters) {
        Iterator<?> it = params.keySet().iterator();
        // copy in the request parameters stored
        while (it.hasNext()) {
            String key = (String) it.next();
            if (!key.startsWith(cacheId)) {
                String[] values = (String[]) params.get(key);
                String valueString = values[0];
                buffer.append(" <input type=\"hidden\" name=\"" + key + "\" value=\"" + valueString + "\" />");
            }
        }
    }
    /**
      *  Now serialize the request attributes into the page (only sealizable objects are going
      *  to be processed).
      */
    if (encodeRequestAttributes) {
        // put the request attributes into tattributres
        Enumeration<?> myEnumeration = request.getAttributeNames();
        while (myEnumeration.hasMoreElements()) {
            String key = (String) myEnumeration.nextElement();
            // check if we have already serialized the items
            // also don't serialize javax items because
            if (!key.startsWith(cacheId) && !key.startsWith("javax.servlet")) {
                Object value = request.getAttribute(key);
                if (serializableClass == null) {
                    try {
                        getClass();
                        serializableClass = Class.forName("java.io.Serializable");
                    } catch (java.lang.ClassNotFoundException cnf) {
                        System.err.println("ClientStateTag caught: " + cnf);
                    }
                }
                // check if seralizable
                if (serializableClass.isAssignableFrom(value.getClass())) {
                    try {
                        ByteArrayOutputStream bos = new ByteArrayOutputStream();
                        ObjectOutput out = new ObjectOutputStream(bos);
                        out.writeObject(value);
                        out.close();
                        buffer.append(" <input type=\"hidden\" name=\"" + cacheId + "_attribute_" + key
                                + "\" value=\""
                                + new String(Base64.encodeBase64(bos.toByteArray()), "ISO-8859-1") + "\" />");
                    } catch (java.io.IOException iox) {
                        System.err.println("ClientStateTag caught: " + iox);
                    }
                } else {
                    System.out.println(key + " not to Serializeable");
                }
            }

        }
    } // end get attributes
      // now put the link in
    if (imageURL != null) {
        buffer.append(" <input alt=\"" + altText + "\" type=\"image\" " + "src=\"" + imageURL + "\"/>");
    } else {
        buffer.append(" <input alt=\"" + altText + "\"  type=\"submit\" " + "value=\"" + buttonText + "\"/>");
    }
    buffer.append("</form>");
    // write the output to the output stream
    try {
        JspWriter out = pageContext.getOut();
        out.print(buffer.toString());
    } catch (IOException ioe) {
        System.err.println("ClientStateTag: Problems with writing...");
    }
    // reset everything
    parameters = null;
    altText = "";
    buttonText = null;
    imageURL = null;
    cacheId = null;
    targetURL = null;
    encodeRequestAttributes = true;
    encodeRequestParameters = true;
    serializableClass = null;
    return EVAL_PAGE;
}

From source file:com.sun.j2ee.blueprints.taglibs.smart.ClientStateTag.java

public int doEndTag() throws JspTagException {
    if (imageURL == null && buttonText == null) {
        throw new JspTagException(
                "ClientStateTag error: either an " + "imageURL or buttonText attribute must be specified.");
    }//from  w  w w .j a va  2 s  .  c  o  m
    HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();
    StringBuffer buffer = new StringBuffer();
    buffer.append("<form method=\"POST\" action=\"" + targetURL + "\">");
    // insert any parameters that may have been added via sub tags
    if (parameters != null) {
        Iterator it = parameters.keySet().iterator();
        // put the request attributes stored in the session in the request
        while (it.hasNext()) {
            String key = (String) it.next();
            String value = (String) parameters.get(key);
            buffer.append(" <input type=\"hidden\" name=\"" + key + "\" value=\"" + value + "\" />");
        }
    }
    String fullURL = request.getRequestURI();
    // find the url that sent us this page
    String targetURL = null;
    int lastPathSeparator = fullURL.lastIndexOf("/") + 1;
    if (lastPathSeparator != -1) {
        targetURL = fullURL.substring(lastPathSeparator, fullURL.length());
    }
    buffer.append(" <input type=\"hidden\" name=\"referring_URL\"" + "value=\"" + targetURL + "\">");
    String referringScreen = (String) request.getSession().getAttribute(WebKeys.PREVIOUS_SCREEN);
    buffer.append(" <input type=\"hidden\" name=\"referring_screen\"" + "value=\"" + referringScreen + "\">");
    buffer.append(" <input type=\"hidden\" name=\"cacheId\"" + "value=\"" + cacheId + "\">");
    // check the request for previous parameters
    Map params = (Map) request.getParameterMap();
    if (!params.isEmpty() && encodeRequestParameters) {
        Iterator it = params.entrySet().iterator();
        // copy in the request parameters stored
        while (it.hasNext()) {
            Entry entry = (Entry) it.next();
            String key = (String) entry.getKey();
            if (!key.startsWith(cacheId)) {
                String[] values = (String[]) entry.getValue();
                String valueString = values[0];
                buffer.append(" <input type=\"hidden\" name=\"" + key + "\" value=\"" + valueString + "\" />");
            }
        }
    }
    /**
      *  Now serialize the request attributes into the page (only sealizable objects are going
      *  to be processed).
      */
    if (encodeRequestAttributes) {
        // put the request attributes into tattributres
        Enumeration enumeration = request.getAttributeNames();
        while (enumeration.hasMoreElements()) {
            String key = (String) enumeration.nextElement();
            // check if we have already serialized the items
            // also don't serialize javax items because
            if (!key.startsWith(cacheId) && !key.startsWith("javax.servlet")) {
                Object value = request.getAttribute(key);
                if (serializableClass == null) {
                    try {
                        serializableClass = Class.forName("java.io.Serializable");
                    } catch (java.lang.ClassNotFoundException cnf) {
                        logger.error("ClientStateTag caught: ", cnf);
                    }
                }
                // check if seralizable
                if (serializableClass.isAssignableFrom(value.getClass())) {
                    try {
                        ByteArrayOutputStream bos = new ByteArrayOutputStream();
                        ObjectOutput out = new ObjectOutputStream(bos);
                        out.writeObject(value);
                        out.close();
                        buffer.append(" <input type=\"hidden\" name=\"" + cacheId + "_attribute_" + key
                                + "\" value=\"" + new String(Base64.encode(bos.toByteArray()), "ISO-8859-1")
                                + "\" />");
                    } catch (java.io.IOException iox) {
                        logger.error("ClientStateTag caught: ", iox);
                    }
                } else {
                    logger.info(key + " not to Serializeable");
                }
            }
        }
    } // end get attributes
      // now put the link in
    if (imageURL != null) {
        buffer.append(" <input alt=\"" + altText + "\" type=\"image\" " + "src=\"" + imageURL + "\"/>");
    } else {
        buffer.append(" <input alt=\"" + altText + "\"  type=\"submit\" " + "value=\"" + buttonText + "\"/>");
    }
    buffer.append("</form>");
    // write the output to the output stream
    try {
        JspWriter out = pageContext.getOut();
        out.print(buffer.toString());
    } catch (IOException ioe) {
        logger.error("ClientStateTag: Problems with writing...", ioe);
    }
    // reset everything
    parameters = null;
    altText = "";
    buttonText = null;
    imageURL = null;
    cacheId = null;
    targetURL = null;
    encodeRequestAttributes = true;
    encodeRequestParameters = true;
    serializableClass = null;
    return EVAL_PAGE;
}

From source file:org.webdavaccess.servlet.WebdavServlet.java

/**
 * Handles the special WebDAV methods.//from  w  w w  .j av a2  s . c o  m
 */
protected void service(HttpServletRequest req, HttpServletResponse resp)
        throws ServletException, IOException, AuthenticationException {

    String method = req.getMethod();

    if (fdebug == 1) {
        log.debug("WebdavServlet REQUEST:  -----------------");
        log.debug("Method = " + method);
        log.debug("Time: " + System.currentTimeMillis());
        log.debug("Path: " + getRelativePath(req));
        Enumeration e = req.getHeaderNames();
        while (e.hasMoreElements()) {
            String s = (String) e.nextElement();
            log.debug("Header: " + s + " " + req.getHeader(s));
        }
        e = req.getAttributeNames();
        while (e.hasMoreElements()) {
            String s = (String) e.nextElement();
            log.debug("Attribute: " + s + " " + req.getAttribute(s));
        }
        e = req.getParameterNames();
        while (e.hasMoreElements()) {
            String s = (String) e.nextElement();
            log.debug("Parameter: " + s + " " + req.getParameter(s));
        }
    }

    try {
        fStore.begin(req, fParameter, getServletContext().getRealPath("/"));
        if (fAuthorize != null)
            fAuthorize.authorize(req);
        resp.setStatus(WebdavStatus.SC_OK);

        try {
            if (method.equals(METHOD_PROPFIND)) {
                doPropfind(req, resp);
            } else if (method.equals(METHOD_PROPPATCH)) {
                doProppatch(req, resp);
            } else if (method.equals(METHOD_MKCOL)) {
                doMkcol(req, resp);
            } else if (method.equals(METHOD_COPY)) {
                doCopy(req, resp);
            } else if (method.equals(METHOD_MOVE)) {
                doMove(req, resp);
            } else if (method.equals(METHOD_PUT)) {
                doPut(req, resp);
            } else if (method.equals(METHOD_GET)) {
                doGet(req, resp, true);
            } else if (method.equals(METHOD_OPTIONS)) {
                doOptions(req, resp);
            } else if (method.equals(METHOD_HEAD)) {
                doHead(req, resp);
            } else if (method.equals(METHOD_DELETE)) {
                doDelete(req, resp);
            } else {
                super.service(req, resp);
            }

            fStore.commit();

        } catch (IOException e) {
            log.error("WebdavServer internal error: ", e);
            resp.sendError(WebdavStatus.SC_INTERNAL_SERVER_ERROR);
            fStore.rollback();
            throw new ServletException(e);
        }

    } catch (UnauthenticatedException e) {
        log.error("WebdavServer not authenticated: ", e);
        resp.sendError(WebdavStatus.SC_FORBIDDEN);
    } catch (WebdavException e) {
        log.error("WebdavServer internal error: ", e);
        throw new ServletException(e);
    }
}

From source file:it.classhidra.core.controller.bsController.java

private static String prepareEnvironmentState(HttpServletRequest request, String id_action) {
    String log = "ClassHidra: Application Environment Memory Damp for [" + id_action + "] (only serialization)";
    String log_detail = "\n";
    int total = 0;
    int only_session = 0;
    int only_app = 0;
    try {//from   www .j a v a  2  s  .  c  om
        log_detail += "     ServletContext: \n";
        Enumeration en = request.getSession().getServletContext().getAttributeNames();
        while (en.hasMoreElements()) {
            String key = (String) en.nextElement();
            int dim = calc(request.getSession().getServletContext().getAttribute(key));
            log_detail += "          [" + key + "]=" + dim + "\n";
            only_app += dim;
        }
        total += only_app;

        log_detail += "     ClassHidra Local Container: \n";
        en = local_container.keys();
        while (en.hasMoreElements()) {
            String key = (String) en.nextElement();
            int dim = calc(local_container.get(key));
            log_detail += "          [" + key + "]=" + dim + "\n";
            only_app += dim;
        }
        total += only_app;

        log_detail += "     Session: \n";
        en = request.getSession().getAttributeNames();
        while (en.hasMoreElements()) {
            String key = (String) en.nextElement();
            int dim = calc(request.getSession().getAttribute(key));
            log_detail += "          [" + key + "]=" + dim + "\n";
            only_session += dim;
        }
        total += only_session;

        log_detail += "     Request Attributes: \n";
        en = request.getAttributeNames();
        while (en.hasMoreElements()) {
            String key = (String) en.nextElement();
            int dim = calc(request.getAttribute(key));
            log_detail += "          [" + key + "]=" + dim + "\n";
            total += dim;
        }

        log_detail += "     Request Parameters: \n";
        en = request.getParameterNames();
        while (en.hasMoreElements()) {
            String key = (String) en.nextElement();
            int dim = calc(request.getParameter(key));
            log_detail += "          [" + key + "]=" + dim + "\n";
            total += dim;
        }
        try {
            log_detail += "     Heap (very approximately): \n";
            log_detail += "          [HeapSize]=" + Runtime.getRuntime().totalMemory() + "\n";
            log_detail += "          [HeapMaxSize]=" + Runtime.getRuntime().maxMemory() + "\n";
            log_detail += "          [HeapFreeSize]=" + Runtime.getRuntime().maxMemory() + "\n";
        } catch (Exception ex) {
        } catch (Throwable th) {
        }
        return (log + "all=" + total + "; servletContext=" + only_app + "; session=" + only_session + ";"
                + log_detail);
    } catch (Exception e) {
        return "EXCEPTION: " + e.toString();
    } catch (Throwable e) {
        return "THROWABLE: " + e.toString();
    }
}

From source file:org.sakaiproject.util.Web.java

public static String snoop(PrintWriter out, boolean html, ServletConfig config, HttpServletRequest req) {
    // if no out, send to system out
    ByteArrayOutputStream ostream = null;
    if (out == null) {
        ostream = new ByteArrayOutputStream();
        out = new PrintWriter(ostream);
        html = false;/*from w  w w  . j  a v a  2  s .co m*/
    }

    String h1 = "";
    String h1x = "";
    String pre = "";
    String prex = "";
    String b = "";
    String bx = "";
    String p = "";
    if (html) {
        h1 = "<h1>";
        h1x = "</h1>";
        pre = "<pre>";
        prex = "</pre>";
        b = "<b>";
        bx = "</b>";
        p = "<p>";
    }

    Enumeration<?> e = null;

    out.println(h1 + "Snoop for request" + h1x);
    out.println(req.toString());

    if (config != null) {
        e = config.getInitParameterNames();
        if (e != null) {
            boolean first = true;
            while (e.hasMoreElements()) {
                if (first) {
                    out.println(h1 + "Init Parameters" + h1x);
                    out.println(pre);
                    first = false;
                }
                String param = (String) e.nextElement();
                out.println(" " + param + ": " + config.getInitParameter(param));
            }
            out.println(prex);
        }
    }

    out.println(h1 + "Request information:" + h1x);
    out.println(pre);

    print(out, "Request method", req.getMethod());
    String requestUri = req.getRequestURI();
    print(out, "Request URI", requestUri);
    displayStringChars(out, requestUri);
    print(out, "Request protocol", req.getProtocol());
    String servletPath = req.getServletPath();
    print(out, "Servlet path", servletPath);
    displayStringChars(out, servletPath);
    String contextPath = req.getContextPath();
    print(out, "Context path", contextPath);
    displayStringChars(out, contextPath);
    String pathInfo = req.getPathInfo();
    print(out, "Path info", pathInfo);
    displayStringChars(out, pathInfo);
    print(out, "Path translated", req.getPathTranslated());
    print(out, "Query string", req.getQueryString());
    print(out, "Content length", req.getContentLength());
    print(out, "Content type", req.getContentType());
    print(out, "Server name", req.getServerName());
    print(out, "Server port", req.getServerPort());
    print(out, "Remote user", req.getRemoteUser());
    print(out, "Remote address", req.getRemoteAddr());
    // print(out, "Remote host", req.getRemoteHost());
    print(out, "Authorization scheme", req.getAuthType());

    out.println(prex);

    e = req.getHeaderNames();
    if (e.hasMoreElements()) {
        out.println(h1 + "Request headers:" + h1x);
        out.println(pre);
        while (e.hasMoreElements()) {
            String name = (String) e.nextElement();
            out.println(" " + name + ": " + req.getHeader(name));
        }
        out.println(prex);
    }

    e = req.getParameterNames();
    if (e.hasMoreElements()) {
        out.println(h1 + "Servlet parameters (Single Value style):" + h1x);
        out.println(pre);
        while (e.hasMoreElements()) {
            String name = (String) e.nextElement();
            out.println(" " + name + " = " + req.getParameter(name));
        }
        out.println(prex);
    }

    e = req.getParameterNames();
    if (e.hasMoreElements()) {
        out.println(h1 + "Servlet parameters (Multiple Value style):" + h1x);
        out.println(pre);
        while (e.hasMoreElements()) {
            String name = (String) e.nextElement();
            String vals[] = (String[]) req.getParameterValues(name);
            if (vals != null) {
                out.print(b + " " + name + " = " + bx);
                out.println(vals[0]);
                for (int i = 1; i < vals.length; i++)
                    out.println("           " + vals[i]);
            }
            out.println(p);
        }
        out.println(prex);
    }

    e = req.getAttributeNames();
    if (e.hasMoreElements()) {
        out.println(h1 + "Request attributes:" + h1x);
        out.println(pre);
        while (e.hasMoreElements()) {
            String name = (String) e.nextElement();
            out.println(" " + name + ": " + req.getAttribute(name));
        }
        out.println(prex);
    }

    if (ostream != null) {
        out.flush();
        return ostream.toString();
    }

    return "";
}

From source file:org.apache.catalina.servlets.DefaultServlet.java

/**
 * Show HTTP header information.//  www . ja va2  s .c o  m
 *
 * @param req Description of the Parameter
 */
protected void showRequestInfo(HttpServletRequest req) {

    System.out.println();
    System.out.println("SlideDAV Request Info");
    System.out.println();

    // Show generic info
    System.out.println("Encoding : " + req.getCharacterEncoding());
    System.out.println("Length : " + req.getContentLength());
    System.out.println("Type : " + req.getContentType());

    System.out.println();
    System.out.println("Parameters");

    Enumeration parameters = req.getParameterNames();

    while (parameters.hasMoreElements()) {
        String paramName = (String) parameters.nextElement();
        String[] values = req.getParameterValues(paramName);
        System.out.print(paramName + " : ");
        for (int i = 0; i < values.length; i++) {
            System.out.print(values[i] + ", ");
        }
        System.out.println();
    }

    System.out.println();

    System.out.println("Protocol : " + req.getProtocol());
    System.out.println("Address : " + req.getRemoteAddr());
    System.out.println("Host : " + req.getRemoteHost());
    System.out.println("Scheme : " + req.getScheme());
    System.out.println("Server Name : " + req.getServerName());
    System.out.println("Server Port : " + req.getServerPort());

    System.out.println();
    System.out.println("Attributes");

    Enumeration attributes = req.getAttributeNames();

    while (attributes.hasMoreElements()) {
        String attributeName = (String) attributes.nextElement();
        System.out.print(attributeName + " : ");
        System.out.println(req.getAttribute(attributeName).toString());
    }

    System.out.println();

    // Show HTTP info
    System.out.println();
    System.out.println("HTTP Header Info");
    System.out.println();

    System.out.println("Authentication Type : " + req.getAuthType());
    System.out.println("HTTP Method : " + req.getMethod());
    System.out.println("Path Info : " + req.getPathInfo());
    System.out.println("Path translated : " + req.getPathTranslated());
    System.out.println("Query string : " + req.getQueryString());
    System.out.println("Remote user : " + req.getRemoteUser());
    System.out.println("Requested session id : " + req.getRequestedSessionId());
    System.out.println("Request URI : " + req.getRequestURI());
    System.out.println("Context path : " + req.getContextPath());
    System.out.println("Servlet path : " + req.getServletPath());
    System.out.println("User principal : " + req.getUserPrincipal());

    System.out.println();
    System.out.println("Headers : ");

    Enumeration headers = req.getHeaderNames();

    while (headers.hasMoreElements()) {
        String headerName = (String) headers.nextElement();
        System.out.print(headerName + " : ");
        System.out.println(req.getHeader(headerName));
    }

    System.out.println();
    System.out.println();

}

From source file:org.sakaiproject.portal.charon.SkinnableCharonPortal.java

private void showSnoop(PortalRenderContext rcontext, boolean b, ServletConfig servletConfig,
        HttpServletRequest req) {
    Enumeration e = null;/*from  w  w w  .  ja  v a 2 s  .c  o m*/

    rcontext.put("snoopRequest", req.toString());

    if (servletConfig != null) {
        Map<String, Object> m = new HashMap<String, Object>();
        e = servletConfig.getInitParameterNames();

        if (e != null) {
            while (e.hasMoreElements()) {
                String param = (String) e.nextElement();
                m.put(param, servletConfig.getInitParameter(param));
            }
        }
        rcontext.put("snoopServletConfigParams", m);
    }
    rcontext.put("snoopRequest", req);

    e = req.getHeaderNames();
    if (e.hasMoreElements()) {
        Map<String, Object> m = new HashMap<String, Object>();
        while (e.hasMoreElements()) {
            String name = (String) e.nextElement();
            m.put(name, req.getHeader(name));
        }
        rcontext.put("snoopRequestHeaders", m);
    }

    e = req.getParameterNames();
    if (e.hasMoreElements()) {
        Map<String, Object> m = new HashMap<String, Object>();
        while (e.hasMoreElements()) {
            String name = (String) e.nextElement();
            m.put(name, req.getParameter(name));
        }
        rcontext.put("snoopRequestParamsSingle", m);
    }

    e = req.getParameterNames();
    if (e.hasMoreElements()) {
        Map<String, Object> m = new HashMap<String, Object>();
        while (e.hasMoreElements()) {
            String name = (String) e.nextElement();
            String[] vals = (String[]) req.getParameterValues(name);
            StringBuilder sb = new StringBuilder();
            if (vals != null) {
                sb.append(vals[0]);
                for (int i = 1; i < vals.length; i++)
                    sb.append("           ").append(vals[i]);
            }
            m.put(name, sb.toString());
        }
        rcontext.put("snoopRequestParamsMulti", m);
    }

    e = req.getAttributeNames();
    if (e.hasMoreElements()) {
        Map<String, Object> m = new HashMap<String, Object>();
        while (e.hasMoreElements()) {
            String name = (String) e.nextElement();
            m.put(name, req.getAttribute(name));

        }
        rcontext.put("snoopRequestAttr", m);
    }
}