Example usage for javax.servlet ServletException ServletException

List of usage examples for javax.servlet ServletException ServletException

Introduction

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

Prototype


public ServletException(Throwable rootCause) 

Source Link

Document

Constructs a new servlet exception when the servlet needs to throw an exception and include a message about the "root cause" exception that interfered with its normal operation.

Usage

From source file:com.m2a.struts.M2AActionServlet.java

/**
 * Initialize this servlet.  Most of the processing has been factored into
 * support methods so that you can override particular functionality at a
 * fairly granular level./*from   w w  w  .  jav a2  s  .co m*/
 *
 * @exception ServletException if we cannot configure ourselves correctly
 */
public void init() throws ServletException {
    super.init();

    try {
        String appName = getServletConfig().getInitParameter("appname");
        if (appName != null) {
            M2ATokens.APPNAME = appName;
        }
        // collection to hold country code dropdown
        Collection countryCodeDD = M2ADropDowns.getCountryCodeDD();

        // collection to hold currency code dropdown
        Collection ccyCodeDD = M2ADropDowns.getCcyCodeDD();

        // collection to hold nationality code dropdown
        Collection nationalityCodeDD = M2ADropDowns.getNationalityCodeDD();

        // collection to hold purpose code dropdown
        Collection purposeCodeDD = M2ADropDowns.getPurposeCodeDD();

        // collection to hold sourceofincome code dropdown
        Collection sourceOfIncomeCodeDD = M2ADropDowns.getSourceOfIncomeCodeDD();

        // collection to hold idType code dropdown
        Collection idTypeDD = M2ADropDowns.getIdTypeDD();

        //collection to hold country code dropdown
        Collection benCountryCodeDD = M2ADropDowns.getBenCountryCodeDD();

        //collection to hold currency code dropdown
        Collection benCcyCodeDD = M2ADropDowns.getBenCcyCodeDD();

        //collection to hold country with currency code dropdown
        Collection countryCcyCodeDD = M2ADropDowns.getCountryCcyCodeDD();

        //collection to holde registration security questions
        Collection regSecQuestionsDD = M2ADropDowns.getRegSecQuestionsDD();

        getServletContext().setAttribute(M2ATokens.COUNTRY_DD, countryCodeDD);
        getServletContext().setAttribute(M2ATokens.CURRENCY_DD, ccyCodeDD);
        getServletContext().setAttribute(M2ATokens.NATIONALITY_DD, nationalityCodeDD);
        getServletContext().setAttribute(M2ATokens.PURPOSE_DD, purposeCodeDD);
        getServletContext().setAttribute(M2ATokens.SORUCEOFINCOME_DD, sourceOfIncomeCodeDD);
        getServletContext().setAttribute(M2ATokens.IDTYPE_DD, idTypeDD);
        getServletContext().setAttribute(M2ATokens.BENCOUNTRY_DD, benCountryCodeDD);
        getServletContext().setAttribute(M2ATokens.BENCURRENCY_DD, benCcyCodeDD);
        getServletContext().setAttribute(M2ATokens.COUNTRYCURRENCY_DD, countryCcyCodeDD);
        //for kuwait
        getServletContext().setAttribute(M2ATokens.REGSECQUESTIONS_DD, regSecQuestionsDD);
    } catch (M2AResourceException re) {
        throw new ServletException(re.getMessage());
    }

}

From source file:net.digitalprimates.persistence.hibernate.utils.filters.HibernateSessionServletFilter.java

public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
        throws IOException, ServletException {
    Session session = null;//from  www  .j  a  v  a2 s . com
    try {
        log.debug("Starting a database transaction");
        session = HibernateUtil.getCurrentSession();
        HibernateUtil.beginTransaction();

        // Call the next filter (continue request processing)
        chain.doFilter(request, response);

        // Commit and cleanup
        log.debug("Committing the database transaction");
        HibernateUtil.commitTransaction();

    } catch (StaleObjectStateException staleEx) {
        log.error("This interceptor does not implement optimistic concurrency control!");
        log.error("Your application will not work until you add compensation actions!");

        // Rollback, close everything, possibly compensate for any permanent
        // changes
        // during the conversation, and finally restart business
        // conversation. Maybe
        // give the user of the application a chance to merge some of his
        // work with
        // fresh data... what you do here depends on your applications
        // design.
        throw staleEx;
    } catch (Throwable ex) {
        // Rollback only
        ex.printStackTrace();
        try {
            if (HibernateUtil.getTransaction().isActive()) {
                log.debug("Trying to rollback database transaction after exception");
                HibernateUtil.rollbackTransaction();
            }
        } catch (Throwable rbEx) {
            log.error("Could not rollback transaction after exception!", rbEx);
        }

        // Let others handle it... maybe another interceptor for exceptions?
        throw new ServletException(ex);
    } finally {
        //SessionStatistics statistics = session.getStatistics();
        HibernateUtil.closeSession();
    }
}

From source file:com.id.get.expand.spring.MarshallingView.java

@Override
protected void renderMergedOutputModel(Map<String, Object> model, HttpServletRequest request,
        HttpServletResponse response) throws Exception {

    Object toBeMarshalled = locateToBeMarshalled(model);
    if (toBeMarshalled == null) {
        throw new ServletException("Unable to locate object to be marshalled in model: " + model);
    }/*  w w  w.ja  v  a 2s.  c o  m*/
    ByteArrayOutputStream baos = new ByteArrayOutputStream(1024);
    this.marshaller.marshal(toBeMarshalled, new StreamResult(baos));

    setResponseContentType(request, response);
    response.setContentLength(baos.size());
    baos.writeTo(response.getOutputStream());
}

From source file:com.adobe.acs.commons.mcp.impl.GenericReportExcelServlet.java

@Override
protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response)
        throws ServletException, IOException {
    GenericReport report = request.getResource().adaptTo(GenericReport.class);
    if (report != null) {
        String title = report.getName();
        String fileName = JcrUtil.createValidName(title) + ".xlsx";

        Workbook workbook = createSpreadsheet(report);
        response.setContentType("application/vnd.ms-excel");
        response.setHeader("Expires", "0");
        response.setHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0");
        response.setHeader("Pragma", "public");
        response.setHeader("Content-Disposition", "attachment; filename=" + fileName);
        try (ServletOutputStream out = response.getOutputStream()) {
            workbook.write(out);/*  ww w  .j  av a 2 s.c o  m*/
            out.flush();
        } catch (Exception ex) {
            LOG.error("Error generating excel export for " + request.getResource().getPath(), ex);
            throw ex;
        }
    } else {
        LOG.error("Unable to process report stored at " + request.getResource().getPath());
        throw new ServletException("Unable to process report stored at " + request.getResource().getPath());
    }
}

From source file:Admin.products.ProductS.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods.// w  w  w . j a  v  a  2 s .  c o m
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.setContentType("text/html;charset=UTF-8");
    try (PrintWriter out = response.getWriter()) {

        String brand = request.getParameter("sel01n");
        String category_1 = request.getParameter("sel02n");
        String category_2 = request.getParameter("sel03n");
        String category_3 = request.getParameter("sel04n");
        String product_name = request.getParameter("txf01n");
        String description = request.getParameter("txa01n");
        String specifications = request.getParameter("spe00n");

        try {

            String Name = null;
            String Price = null;
            String QTY = null;

            FileItemFactory item = new DiskFileItemFactory();
            ServletFileUpload upload = new ServletFileUpload(item);

            List<FileItem> list = upload.parseRequest(request);

            for (FileItem fileItem : list) {

                if (fileItem.isFormField()) { //form field

                    //                        fileItem.getFieldName().equals("sel01n")) {
                    Name = fileItem.getString();

                    if (fileItem.getFieldName().equals("spe01n")) {
                        System.out.println("NAME-----:" + Name);
                    } else if (fileItem.getFieldName().equals("spe02n")) {
                        System.out.println("VALUE-----:" + Name);
                    }

                } else {

                    System.out.println("---------------" + fileItem.getName());

                    //                        String n = new File(fileItem.getName()).getName();
                    System.out.println(request.getServletContext().getRealPath("/04_admin/product/img/") + "\\"
                            + System.currentTimeMillis() + ".jpg");
                    fileItem.write(new File(request.getServletContext().getRealPath("/04_admin/product/img/")
                            + "\\" + System.currentTimeMillis() + ".jpg"));
                }
            }

        } catch (Exception e) {
            throw new ServletException(e);
        }
    }
}

From source file:jamm.webapp.InitServlet.java

/**
 * Loads the jamm.properties file and uses it to initalize the
 * Globals object./*from   www.  j a  v  a2 s . c om*/
 *
 * @see jamm.webapp.Globals
 *
 * @param config The configuration from the servlet container.
 *
 * @throws ServletException when their is an IOException loading
 *                          the properties file
 */
private void loadProperties(ServletConfig config) throws ServletException {
    String path;
    Properties properties;

    try {
        path = config.getServletContext().getRealPath("WEB-INF/" + "jamm.properties");
        properties = new Properties();
        properties.load(new FileInputStream(path));

        Globals.setLdapHost(getStringProperty(properties, "ldap.host", "localhost"));
        Globals.setLdapPort(getIntProperty(properties, "ldap.port", 389));
        Globals.setLdapSearchBase(getStringProperty(properties, "ldap.search_base", ""));
        LdapPassword
                .setRandomClass(getStringProperty(properties, "random_class", "java.security.SecureRandom"));

        // Strip out leading and trailing quotes (common problem)
        String rootDn = getStringProperty(properties, "ldap.root_dn", "");
        if (rootDn.startsWith("\"") && rootDn.endsWith("\"")) {
            rootDn = StringUtils.substring(rootDn, 1, -1);
        }
        Globals.setRootDn(rootDn);
        Globals.setRootLogin(getStringProperty(properties, "ldap.root_login", "root"));
        MailManagerOptions.setUsePasswordExOp(getBooleanProperty(properties, "password.exop", true));
        MailManagerOptions
                .setVmailHomedir(getStringProperty(properties, "vmail.homedir", "/home/vmail/domains"));
    } catch (IOException e) {
        throw new ServletException(e);
    }

}

From source file:org.terasoluna.gfw.web.exception.ExceptionLoggingFilterTest.java

@Test
public void testDoFilter_occur_servletexception() throws IOException, ServletException {

    ServletException occurException = new ServletException("servlet exception.");

    doThrow(occurException).when(mockFilterChain).doFilter(mockRequest, mockResponse);

    try {//from  ww w  .  j  ava 2  s .c o m
        testTarget.doFilter(mockRequest, mockResponse, mockFilterChain);
    } catch (ServletException e) {
        assertSame(occurException, e);
    }

    verify(mockExceptionLogger, times(1)).log(occurException);

}

From source file:com.bluedragon.platform.java.JavaFileIO.java

public JavaFileIO(ServletConfig config) throws ServletException {

    try {/*w ww  .  j  a  va 2s.  c o m*/
        fsManager = VFS.getManager();
        ((StandardFileSystemManager) fsManager).addProvider("s3",
                new com.intridea.io.vfs.provider.s3.S3FileProvider());
        ((StandardFileSystemManager) fsManager).addOperationProvider("s3",
                new com.intridea.io.vfs.provider.s3.acl.AclOperationsProvider());
    } catch (Exception e1) {
        cfEngine.log("Failed to register the s3:// name space: " + e1.getMessage());
    }

    // Set the working directory
    try {
        if (!setWorkingDirectory(config.getInitParameter("BLUEDRAGON_WORKING_DIRECTORY"))) {
            throw new Exception(
                    config.getInitParameter("BLUEDRAGON_WORKING_DIRECTORY") + " could not be created");
        }
    } catch (Exception E) {
        System.out.println(cfEngine.PRODUCT_NAME + ": Init Parameter BLUEDRAGON_WORKING_DIRECTORY Error: " + E);
        throw new ServletException(
                cfEngine.PRODUCT_NAME + ": Init Parameter BLUEDRAGON_WORKING_DIRECTORY Error: " + E);
    }

    // Setup the logging
    com.nary.Debug.SystemOff();
    File logFile = new File(getWorkingDirectory(), "bluedragon.log");
    rolloverLogFile(logFile);
    com.nary.Debug.setFilename(logFile.toString());

    setTempDirectory();
    setupRuntimeLogging();

    cfEngine.log(cfEngine.PRODUCT_NAME + " WorkingDirectory=[" + getWorkingDirectory() + "]");
    cfEngine.log(cfEngine.PRODUCT_NAME + " TempDirectory=[" + getTempDirectory() + "]");
}

From source file:com.knowbout.hibernate.OpenTransactionInViewFilter.java

/**
 * @see javax.servlet.Filter#doFilter(javax.servlet.ServletRequest, javax.servlet.ServletResponse, javax.servlet.FilterChain)
 *///from  w  ww .  ja  v a  2s  .c om
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
        throws IOException, ServletException {

    TransactionManager.beginTransaction();
    boolean commit = false;
    try {
        chain.doFilter(request, response);
        commit = !TransactionManager.isRollbackOnly();
    } catch (ServletException se) {
        String message = se.toString();
        if (se.getRootCause() != null) {
            message = se.getRootCause().toString();
        }
        if (printFullExceptions) {
            if (se.getRootCause() != null) {
                log.error(message, se.getRootCause());
            } else {
                log.error(message, se);
            }
        } else {
            log.error(message);
        }
        commit = false;
        throw se;
    } catch (Throwable t) {
        log.error("Error with transaction, rolling back instead.", t);
        commit = false;
    } finally {
        //dispose of the open transaction by commit or rollback
        //transactionHolder.remove(transaction);
        if (commit) {
            try {
                TransactionManager.commitTransaction();
            } catch (Throwable e) {
                log.error("Cannot commit transaction, rolling back instead.", e);
                TransactionManager.rollbackTransaction();
                throw new ServletException(e);
            }
        } else {
            try {
                TransactionManager.rollbackTransaction();
            } catch (Throwable e) {
                log.error("Cannot rollback transaction.", e);
                throw new ServletException(e);
            }
        }
    }
}