Example usage for javax.servlet ServletException initCause

List of usage examples for javax.servlet ServletException initCause

Introduction

In this page you can find the example usage for javax.servlet ServletException initCause.

Prototype

public synchronized Throwable initCause(Throwable cause) 

Source Link

Document

Initializes the cause of this throwable to the specified value.

Usage

From source file:ar.com.easytech.faces.filters.MultipartRequest.java

@SuppressWarnings("unchecked")
public MultipartRequest(HttpServletRequest request, String path) throws Exception {
    super(request);
    DiskFileItemFactory factory = new DiskFileItemFactory();

    if (path != null)
        factory.setRepository(new File(path));

    ServletFileUpload upload = new ServletFileUpload(factory);
    parameterMap.put("path", path);

    try {//from www .j av a  2  s .c  o m
        List<FileItem> items = (List<FileItem>) upload.parseRequest(request);

        for (FileItem item : items) {

            String str = item.getString();
            if (item.isFormField())
                parameterMap.put(item.getFieldName(), str);
            else {
                if (item.getName() != null) {
                    parameterMap.put("fileName", item.getName());
                }
                request.setAttribute(item.getFieldName(), item);
            }
        }

    } catch (FileUploadException ex) {
        ServletException servletEx = new ServletException();
        servletEx.initCause(ex);
        throw new Exception(ex.getLocalizedMessage());
    }
}

From source file:net.mymam.upload.UploadMultipartRequestWrapper.java

public UploadMultipartRequestWrapper(HttpServletRequest request, ServletFileUpload upload)
        throws ServletException {
    super(request);
    try {/* w  ww.  java2s.  c om*/
        List fileItems = upload.parseRequest(request);
        for (int i = 0; i < fileItems.size(); i++) {
            FileItem item = (FileItem) fileItems.get(i);
            if (item.isFormField()) {
                addParameter(item.getFieldName(), item.getString(), formParameters);
            } else {
                addParameter(item.getFieldName(), item, fileParameters);
            }
        }
    } catch (FileUploadException e) {
        // Request timed out
        ServletException servletException = new ServletException();
        servletException.initCause(e);
        throw servletException;
    }
}

From source file:com.corejsf.UploadFilter.java

public void init(FilterConfig config) throws ServletException {
    repositoryPath = ServerConfigurationService.getString("samigo.answerUploadRepositoryPath",
            "${sakai.home}/samigo/answerUploadRepositoryPath/");

    try {/*from   ww w .  j  av a 2s  .co m*/
        String paramValue = ServerConfigurationService.getString("samigo.sizeThreshold", "1024");
        if (paramValue != null)
            sizeThreshold = Integer.parseInt(paramValue);

        paramValue = ServerConfigurationService.getString("samigo.sizeMax", "40960");
        if (paramValue != null)
            sizeMax = Long.parseLong(paramValue);

        paramValue = ServerConfigurationService.getString("samigo.saveMediaToDb", "true");
        if (paramValue != null)
            saveMediaToDb = paramValue;

        //System.out.println("**** repositoryPath="+repositoryPath);
        //System.out.println("**** sabeMediaToDb="+saveMediaToDb);
        //System.out.println("**** sizeThreshold="+sizeThreshold);
        //System.out.println("**** sizeMax="+sizeMax);
    } catch (NumberFormatException ex) {
        ServletException servletEx = new ServletException();
        servletEx.initCause(ex);
        throw servletEx;
    }
    ServletContext context = config.getServletContext();
    context.setAttribute("FILEUPLOAD_REPOSITORY_PATH", repositoryPath);
    context.setAttribute("FILEUPLOAD_SIZE_THRESHOLD", Integer.valueOf(sizeThreshold));
    context.setAttribute("FILEUPLOAD_SIZE_MAX", Long.valueOf(sizeMax));
    context.setAttribute("FILEUPLOAD_SAVE_MEDIA_TO_DB", saveMediaToDb);
}

From source file:com.corejsf.UploadFilter.java

public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
        throws IOException, ServletException {

    //System.out.println("**** doFilter #1");
    if (!(request instanceof HttpServletRequest)) {
        chain.doFilter(request, response);
        return;//from   w ww.ja  va  2s .  com
    }

    //System.out.println("**** doFilter #2");
    HttpServletRequest httpRequest = (HttpServletRequest) request;
    boolean isMultipartContent = FileUpload.isMultipartContent(httpRequest);
    if (!isMultipartContent) {
        chain.doFilter(request, response);
        return;
    }

    //System.out.println("**** doFilter #3");
    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);
            //System.out.println("form filed="+item.getFieldName()+" : "+str);
            if (item.isFormField()) {
                String str = item.getString("UTF-8");
                map.put(item.getFieldName(), new String[] { str });
            } else {
                httpRequest.setAttribute(item.getFieldName(), item);
            }
        }

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

            // busywork follows ... should have been part of the wrapper
            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) {
        log.error(ex.getMessage());
        ServletException servletEx = new ServletException();
        servletEx.initCause(ex);
        throw servletEx;
    }
}

From source file:org.deegree.client.core.filter.InputFileWrapper.java

@SuppressWarnings("unchecked")
public InputFileWrapper(HttpServletRequest request) throws ServletException {
    super(request);
    try {// www .  ja  va 2 s .co  m
        ServletFileUpload upload = new ServletFileUpload();
        DiskFileItemFactory factory = new DiskFileItemFactory();
        upload.setFileItemFactory(factory);
        String encoding = request.getCharacterEncoding();
        List<FileItem> fileItems = upload.parseRequest(request);
        formParameters = new HashMap<String, String[]>();
        for (int i = 0; i < fileItems.size(); i++) {
            FileItem item = fileItems.get(i);
            if (item.isFormField()) {
                String[] values;
                String v;
                if (encoding != null) {
                    v = item.getString(encoding);
                } else {
                    v = item.getString();
                }
                if (formParameters.containsKey(item.getFieldName())) {
                    String[] strings = formParameters.get(item.getFieldName());
                    values = new String[strings.length + 1];
                    for (int j = 0; j < strings.length; j++) {
                        values[j] = strings[j];
                    }
                    values[strings.length] = v;
                } else {
                    values = new String[] { v };
                }
                formParameters.put(item.getFieldName(), values);
            } else if (item.getName() != null && item.getName().length() > 0 && item.getSize() > 0) {
                request.setAttribute(item.getFieldName(), item);
            }
        }
    } catch (FileUploadException fe) {
        ServletException servletEx = new ServletException();
        servletEx.initCause(fe);
        throw servletEx;
    } catch (UnsupportedEncodingException e) {
        ServletException servletEx = new ServletException();
        servletEx.initCause(e);
        throw servletEx;
    }
}

From source file:org.sakaiproject.tool.messageforums.FileUploadFilter.java

public void init(FilterConfig config) throws ServletException {
    repositoryPath = config//w  w w .j a  v a2  s  .c  om
            .getInitParameter("org.sakaiproject.tool.messageforums.FileUploadFilter.repositoryPath");

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

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

From source file:org.sakaiproject.tool.messageforums.FileUploadFilter.java

public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
        throws IOException, ServletException {
    if (!(request instanceof HttpServletRequest)) {
        chain.doFilter(request, response);
        return;/*from w ww . j  ava  2  s. co m*/
    }

    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;
    }
}

From source file:org.sakaiproject.tool.syllabus.FileUploadFilter.java

public void init(FilterConfig config) throws ServletException {
    repositoryPath = config.getInitParameter("org.sakaiproject.tool.syllabus.FileUploadFilter.repositoryPath");

    try {// ww  w . j  a  v  a2  s . c o  m
        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;
    }
}

From source file:org.sakaiproject.tool.syllabus.FileUploadFilter.java

public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
        throws IOException, ServletException {
    if (!(request instanceof HttpServletRequest)) {
        chain.doFilter(request, response);
        return;/*from   w ww .  ja  v a2  s.  c o m*/
    }

    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;
    }
}

From source file:uk.ac.lancs.e_science.fileUpload.UploadFilter.java

public void init(FilterConfig config) throws ServletException {
    try {// ww w  . java2 s .c  o m
        String paramValue = config.getInitParameter("uk.ac.lancs.e_science.fileUpload.UploadFilter.sizeMax");
        if (paramValue != null)
            sizeMax = Long.parseLong(paramValue) * 1024 * 1024;
    } catch (NumberFormatException ex) {
        ServletException servletEx = new ServletException();
        servletEx.initCause(ex);
        throw servletEx;
    }
}