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.bluelotussoftware.apache.commons.fileupload.example.CommonsFileUploadServlet.java

@Override
public void init(ServletConfig config) throws ServletException {
    super.init(config);
    log(getServletContext().getRealPath(DESTINATION_DIR_PATH));
    log(TMP_DIR_PATH);/*from ww  w  .  j a  v a2 s  .c  om*/
    tmpDir = new File(TMP_DIR_PATH);
    if (!tmpDir.isDirectory()) {
        throw new ServletException(TMP_DIR_PATH + " is not a directory");
    }

    String realPath = getServletContext().getRealPath(DESTINATION_DIR_PATH);
    destinationDir = new File(realPath);

    if (!destinationDir.isDirectory()) {
        String files = getServletContext().getRealPath("/") + "/files";
        destinationDir = new File(files);
        destinationDir.mkdir();
    }
}

From source file:cc.aileron.wsgi.WsgiHttpFilter.java

@Override
public void doFilter(final ServletRequest request, final ServletResponse response, final FilterChain chain)
        throws IOException, ServletException {
    try {/*from   ww w  .j a v a 2 s.co  m*/
        model.router.routing(context, (HttpServletRequest) request, (HttpServletResponse) response, chain);
    } catch (final FileUploadException e) {
        throw new ServletException(e);
    }
}

From source file:FlavorListServlet.java

public void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    PrintWriter out = response.getWriter();
    response.setContentType("text/html");

    // Get the bounds of the ranks to be listed
    // or use defaults

    int lowLimit = getLimit(request.getParameter("lowLimit"), 0);
    int highLimit = getLimit(request.getParameter("highLimit"), 100);

    Connection con = null;//w  ww  .  j av  a2  s .c o  m
    try {

        // Connect to the ice cream database

        Class.forName(JDBC_DRIVER);
        con = DriverManager.getConnection(URL);

        // Run a query to get the top flavors

        String sql = "SELECT  RANK, NAME" + "   FROM flavors" + "   WHERE RANK BETWEEN ? AND ?"
                + "   ORDER BY RANK";
        PreparedStatement pstmt = con.prepareStatement(sql);
        pstmt.setInt(1, lowLimit);
        pstmt.setInt(2, highLimit);
        ResultSet rs = pstmt.executeQuery();

        // Print as an ordered list

        out.println("<ol>");
        while (rs.next()) {
            int rank = rs.getInt(1);
            String name = rs.getString(2);
            out.println("   <li>" + name + "</li>");
        }
        out.println("</ol>");
    } catch (SQLException e) {
        throw new ServletException(e.getMessage());
    } catch (ClassNotFoundException e) {
        throw new ServletException(e.getMessage());
    }

    // Close the database

    finally {
        if (con != null) {
            try {
                con.close();
            } catch (SQLException ignore) {
            }
        }
    }
}

From source file:be.fedict.eid.applet.service.JSONServlet.java

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    LOG.debug("doGet");
    HttpSession httpSession = request.getSession();
    EIdData eIdData = (EIdData) httpSession.getAttribute("eid");
    if (null == eIdData) {
        throw new ServletException("no eID data available");
    }//from  w w  w  .j a  v a 2 s .  c  om
    PrintWriter writer = response.getWriter();
    try {
        outputJSON(eIdData, writer);
    } catch (CertificateEncodingException e) {
        throw new ServletException("Certificate encoding error: " + e.getMessage(), e);
    }
}

From source file:com.google.u2f.gaedemo.servlets.FinishSignServlet.java

public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException {

    SignSessionData sessionData = dataStore.getSignSessionData(req.getParameter("sessionId"));

    // Simple XSRF protection. We don't want users to be tricked into
    // submitting other people's enrollment data. Here we're just checking 
    // that it's the same user that also started the enrollment - you might
    // want to do something more sophisticated.
    String currentUser = userService.getCurrentUser().getUserId();
    String expectedUser = sessionData.getAccountName();
    if (!currentUser.equals(expectedUser)) {
        throw new ServletException("Cross-site request prohibited");
    }/*from w  ww .j a v  a2 s .c  o m*/

    SignResponse signResponse = new SignResponse(req.getParameter("clientData"),
            req.getParameter("signatureData"), Base64.encodeBase64URLSafeString(sessionData.getChallenge()),
            req.getParameter("sessionId"), sessionData.getAppId());

    SecurityKeyData securityKeyData;
    try {
        securityKeyData = u2fServer.processSignResponse(signResponse);
    } catch (U2FException e) {
        throw new ServletException("signature didn't verify", e);
    }

    resp.setContentType("application/json");
    resp.getWriter().println(new TokenStorageData(securityKeyData).toJson().toString());
}

From source file:waffle.spring.NegotiateSecurityFilterEntryPoint.java

@Override
public void commence(final HttpServletRequest request, final HttpServletResponse response,
        final AuthenticationException ex) throws IOException, ServletException {

    NegotiateSecurityFilterEntryPoint.LOGGER.debug("[waffle.spring.NegotiateEntryPoint] commence");

    if (this.provider == null) {
        throw new ServletException("Missing NegotiateEntryPoint.Provider");
    }//  w  w  w  .  j a  v a  2s  .  co  m

    response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
    response.setHeader("Connection", "keep-alive");
    this.provider.sendUnauthorized(response);
    response.flushBuffer();
}

From source file:edu.jhu.pha.vospace.DbPoolServlet.java

@Override
public void init() throws ServletException {
    ServletContext context = this.getServletContext();

    Configuration conf = (Configuration) context.getAttribute("configuration");

    try {//from   w w w. ja  v a2 s .  com
        Class.forName(conf.getString("db.driver"));
    } catch (ClassNotFoundException e) {
        logger.error(e);
        throw new ServletException(e);
    }

    GenericObjectPool pool = new GenericObjectPool(null);
    pool.setMinEvictableIdleTimeMillis(6 * 60 * 60 * 1000);
    pool.setTimeBetweenEvictionRunsMillis(30 * 60 * 1000);
    pool.setNumTestsPerEvictionRun(-1);

    DriverManagerConnectionFactory cf = new DriverManagerConnectionFactory(conf.getString("db.url"),
            conf.getString("db.login"), conf.getString("db.password"));

    PoolableConnectionFactory pcf = new PoolableConnectionFactory(cf, pool, null, "SELECT * FROM mysql.db",
            false, true);
    new PoolingDriver().registerPool("dbPool", pool);
}

From source file:gov.nih.nci.cabio.portal.portlet.ObjectDetailsJSONServlet.java

public void init() throws ServletException {
    try {//from  w  w w.  j  a  v a 2  s. c  o m
        this.objectConfig = (CannedObjectConfig) getServletContext().getAttribute("objectConfig");

        this.as = (CaBioApplicationService) ApplicationServiceProvider.getApplicationService();

        this.rs = new ReportService(as);
    } catch (Exception e) {
        throw new ServletException(e);
    }
}

From source file:com.googlecode.jsfFlex.phaseListener.NameValueServiceRequestDataRetrieverFlusher.java

@Override
void retrieveFlushData(FacesContext context, String componentId, String methodToInvoke)
        throws ServletException, IOException {

    Map<? extends Object, ? extends Object> objectMap = null;

    try {/*w ww  . ja  v a  2  s.c om*/
        objectMap = (Map<? extends Object, ? extends Object>) invokeResourceMethod(context, componentId,
                methodToInvoke, null, null);
    } catch (Exception methodInvocationException) {
        throw new ServletException(methodInvocationException);
    }

    HttpServletResponse response = HttpServletResponse.class.cast(context.getExternalContext().getResponse());
    response.setContentType(PLAIN_CONTENT_TYPE);

    if (objectMap != null) {
        StringBuilder responseContent = new StringBuilder();

        for (Iterator<? extends Object> iterate = objectMap.keySet().iterator(); iterate.hasNext();) {
            Object currKey = iterate.next();
            Object currValue = objectMap.get(currKey);
            String statementToWrite = currKey.toString() + EQUAL_CHAR + currValue.toString() + SEPARATOR_CHAR;
            responseContent.append(statementToWrite);
        }

        _log.info("Flushing content : " + responseContent.toString());

        Writer writer = response.getWriter();
        writer.write(responseContent.toString());
        writer.flush();
    }

}

From source file:gov.nih.nci.system.security.acegi.ui.globus.X509InitializationFilter.java

/**
 * This method checks the X509 certificate chain in globus context and then puts it in the session under property name of
 * javax.servlet.request.X509Certificate 
 * @param request DOCUMENT ME!//from   ww w .j  a  v a2s  .  c om
 * @param response DOCUMENT ME!
 * @param filterChain DOCUMENT ME!
 *
 * @throws IOException DOCUMENT ME!
 * @throws javax.servlet.ServletException DOCUMENT ME!
 */
public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain)
        throws IOException, ServletException {
    if (!(request instanceof HttpServletRequest)) {
        throw new ServletException("Can only process HttpServletRequest");
    }

    if (!(response instanceof HttpServletResponse)) {
        throw new ServletException("Can only process HttpServletResponse");
    }

    HttpServletRequest httpRequest = (HttpServletRequest) request;

    if (logger.isDebugEnabled()) {
        logger.debug("Checking HTTP Request for Globus Context ");
    }

    try {
        Object obj = httpRequest.getAttribute(GSIConstants.GSI_CONTEXT);
        if (obj != null) {
            GlobusGSSContextImpl ctx = (GlobusGSSContextImpl) obj;
            X509Certificate[] certChain = (X509Certificate[]) ctx.inquireByOid(GSSConstants.X509_CERT_CHAIN);
            if (certChain != null) {
                X509Certificate[] idCertChain = new X509Certificate[] {
                        BouncyCastleUtil.getIdentityCertificate(certChain) };
                request.setAttribute("javax.servlet.request.X509Certificate", idCertChain);
            }
        }
    } catch (Exception e) {
        logger.error("Error getting X509Certificate chain from the globus context:", e);
    }
    filterChain.doFilter(request, response);
}