Ejemplo n.º 1
0
  public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
      throws IOException, ServletException {
    if (!(request instanceof HttpServletRequest)) {
      chain.doFilter(request, response);
      return;
    }

    HttpServletRequest httpRequest = (HttpServletRequest) request;

    boolean isMultipartContent = FileUpload.isMultipartContent(httpRequest);
    if (!isMultipartContent) {
      chain.doFilter(request, response);
      return;
    }

    DiskFileUpload upload = new DiskFileUpload();
    if (repositoryPath != null) upload.setRepositoryPath(repositoryPath);

    try {
      List list = upload.parseRequest(httpRequest);
      final Map map = new HashMap();
      for (int i = 0; i < list.size(); i++) {
        FileItem item = (FileItem) list.get(i);
        String str = item.getString();
        if (item.isFormField()) map.put(item.getFieldName(), new String[] {str});
        else httpRequest.setAttribute(item.getFieldName(), item);
      }

      chain.doFilter(
          new HttpServletRequestWrapper(httpRequest) {
            public Map getParameterMap() {
              return map;
            }

            public String[] getParameterValues(String name) {
              Map map = getParameterMap();
              return (String[]) map.get(name);
            }

            public String getParameter(String name) {
              String[] params = getParameterValues(name);
              if (params == null) return null;
              return params[0];
            }

            public Enumeration getParameterNames() {
              Map map = getParameterMap();
              return Collections.enumeration(map.keySet());
            }
          },
          response);
    } catch (FileUploadException ex) {
      ServletException servletEx = new ServletException();
      servletEx.initCause(ex);
      throw servletEx;
    }
  }
Ejemplo n.º 2
0
  /**
   * executed when a post request happens
   *
   * @param request the request object
   * @param response the response object
   * @throws ServletException if a read error occurs
   * @throws IOException if a read error occurs
   */
  public void doPost(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {

    if (log.isDebugEnabled()) {
      log.debug("Entered doPost");
    }

    if (request.getHeader("SOAPAction") != null) {
      passControl(request, response);
      return;
    }

    response.setContentType("text/xml");
    try {
      if (log.isDebugEnabled()) {
        log.debug("Passing control to XmlRpcServer.execute");
      }

      server.execute(
          request.getInputStream(),
          response.getWriter(),
          request.getRemoteAddr(),
          request.getLocalName(),
          request.getProtocol());

      /*
       * jesusr - 2007.09.14
       * this is still the case
       *
       * mbowman - 2005.10.06
       * Like we were raised in a barn, we are going to leave here without
       * flushing ;)
       * -- The current thinking is that Tocmat handles the outputStream
       * -- flushing and closing for us. This make sense since after this
       * -- method runs, the response still needs to go back up through
       * -- the filters and out. If things start breaking in the future,
       * -- this is a  good place to start looking.
       */
    }
    // As bad as this is, we have no choice, Marquee-xmlrpc throws
    // Throwable, so we have to catch it.
    catch (Throwable t) {
      // By the time we get here, it can't be a FaultException, so just
      // wrap it in a ServletException and toss.
      ServletException e = new ServletException("Throwable from XmlRpc", t);
      e.initCause(t);
      throw e;
    }
  }
Ejemplo n.º 3
0
  public void init(FilterConfig config) throws ServletException {
    repositoryPath =
        config.getInitParameter("org.sakaiproject.tool.syllabus.FileUploadFilter.repositoryPath");

    try {
      String paramValue =
          config.getInitParameter("org.sakaiproject.tool.syllabus.FileUploadFilter.sizeThreshold");

      if (paramValue != null) sizeThreshold = Integer.parseInt(paramValue);
      paramValue =
          config.getInitParameter("org.sakaiproject.tool.syllabus.FileUploadFilter.sizeMax");
      if (paramValue != null) sizeMax = Long.parseLong(paramValue);
    } catch (NumberFormatException ex) {
      ServletException servletEx = new ServletException();
      servletEx.initCause(ex);
      throw servletEx;
    }
  }