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(String message, 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, including a description message.

Usage

From source file:io.fns.calculator.filter.CORSFilter.java

@Override
public void init(FilterConfig filterConfig) throws ServletException {
    super.init(filterConfig);
    try {//from  w w w  .  j  av a  2 s  .  co  m
        CORSConfiguration config = (CORSConfiguration) getInstanceField(this, "config");
        CORSRequestHandler handler = (CORSRequestHandler) getInstanceField(this, "handler");
        config = new CORSConfiguration(yamlProperties.getObject());
        handler = new CORSRequestHandler(config);
    } catch (CORSConfigurationException e) {
        throw new ServletException(e.getMessage(), e);
    } catch (Throwable t) {
        throw new ServletException(t.getMessage(), t);
    }
}

From source file:com.example.getstarted.basicactions.UpdateBookServlet.java

@Override
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    BookDao dao = (BookDao) this.getServletContext().getAttribute("dao");
    try {/*ww  w .j av a2 s . c o  m*/
        Book book = dao.readBook(Long.decode(req.getParameter("id")));
        req.setAttribute("book", book);
        req.setAttribute("action", "Edit");
        req.setAttribute("destination", "update");
        req.setAttribute("page", "form");
        req.getRequestDispatcher("/base.jsp").forward(req, resp);
    } catch (Exception e) {
        throw new ServletException("Error loading book for editing", e);
    }
}

From source file:org.osgpfoundation.osgp.webdemoapp.application.config.WebDemoInitializer.java

@Override
public void onStartup(final ServletContext servletContext) throws ServletException {
    try {// w  w w  . j  av  a 2s.co m
        TimeZone.setDefault(TimeZone.getTimeZone("UTC"));

        final Context initialContext = new InitialContext();

        final AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext();
        rootContext.register(ApplicationContext.class);

        final ServletRegistration.Dynamic dispatcher = servletContext.addServlet(DISPATCHER_SERVLET_NAME,
                new DispatcherServlet(rootContext));
        dispatcher.setLoadOnStartup(1);
        dispatcher.addMapping(DISPATCHER_SERVLET_MAPPING);

        servletContext.addListener(new ContextLoaderListener(rootContext));
    } catch (final NamingException e) {
        throw new ServletException("naming exception", e);
    }
}

From source file:com.example.appengine.analytics.AnalyticsServlet.java

@Override
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException {
    String trackingId = System.getenv("GA_TRACKING_ID");
    URIBuilder builder = new URIBuilder();
    builder.setScheme("http").setHost("www.google-analytics.com").setPath("/collect").addParameter("v", "1") // API Version.
            .addParameter("tid", trackingId) // Tracking ID / Property ID.
            // Anonymous Client Identifier. Ideally, this should be a UUID that
            // is associated with particular user, device, or browser instance.
            .addParameter("cid", "555").addParameter("t", "event") // Event hit type.
            .addParameter("ec", "example") // Event category.
            .addParameter("ea", "test action"); // Event action.
    URI uri = null;//w w  w  .  ja va  2  s.  c o  m
    try {
        uri = builder.build();
    } catch (URISyntaxException e) {
        throw new ServletException("Problem building URI", e);
    }
    URLFetchService fetcher = URLFetchServiceFactory.getURLFetchService();
    URL url = uri.toURL();
    fetcher.fetch(url);
    resp.getWriter().println("Event tracked.");
}

From source file:de.fhg.igd.vaadin.util.servlets.AutowiringApplicationServlet.java

/**
 * Get the {@link AutowireCapableBeanFactory} associated with the containing Spring {@link WebApplicationContext}.
 * This only works after the servlet has been initialized (via {@link #init init()}).
 *
 * @throws ServletException if the operation fails
 *//* w w w.  j a v  a2 s .  c  o m*/
protected final AutowireCapableBeanFactory getAutowireCapableBeanFactory() throws ServletException {
    try {
        return getWebApplicationContext().getAutowireCapableBeanFactory();
    } catch (final IllegalStateException e) {
        throw new ServletException(
                "containing context " + getWebApplicationContext() + " is not autowire-capable", e);
    }
}

From source file:cn.vlabs.duckling.vwb.ui.servlet.AbstractLoginServlet.java

private Config loadConfig(String realPath) throws ServletException {
    Config config = new Config();
    FileInputStream in = null;//  ww w .j  a  v a  2  s .  c o  m
    try {
        in = new FileInputStream(realPath);
        config.load(in);
    } catch (IOException e) {
        throw new ServletException("Load SSO configuration failed.", e);
    } finally {
        if (in != null) {
            try {
                in.close();
            } catch (IOException e) {
                // Do noting
            }
        }
    }
    return config;
}

From source file:be.fedict.eid.applet.service.PdfServlet.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");

    byte[] document;
    try {/*from   w  w w.  j a v a  2s  . c  o  m*/
        document = this.pdfGenerator.generatePdf(eIdData);
    } catch (DocumentException e) {
        throw new ServletException("PDF generator error: " + e.getMessage(), e);
    }

    response.setHeader("Expires", "0");
    response.setHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0");
    response.setHeader("Pragma", "public");

    response.setContentType("application/pdf");
    response.setContentLength(document.length);
    ServletOutputStream out = response.getOutputStream();
    out.write(document);
    out.flush();
}

From source file:be.fedict.eid.applet.service.VcardServlet.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");

    byte[] document;
    try {/*  w w  w .  j av  a 2  s .c  o m*/
        document = this.vcardGenerator.generateVcard(eIdData);
    } catch (IOException e) {
        throw new ServletException("vCard generator error: " + e.getMessage(), e);
    }

    response.setHeader("Expires", "0");
    response.setHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0");
    response.setHeader("Pragma", "public");

    response.setContentType(VcardLight.MIME_TYPE);
    response.setContentLength(document.length);
    ServletOutputStream out = response.getOutputStream();
    out.write(document);
    out.flush();
}

From source file:se.vgregion.mobile.qr.QrController.java

@RequestMapping("/qr")
public void image(@RequestParam("url") String url,
        @RequestParam(value = "width", defaultValue = "300") int width,
        @RequestParam(value = "height", defaultValue = "300") int height, HttpServletResponse response)
        throws ServletException {

    OutputStream out = null;// ww  w. ja v a 2  s .  c o m
    try {
        response.setContentType("image/png");
        out = response.getOutputStream();
        Writer writer = new QRCodeWriter();
        BitMatrix matrix = writer.encode(url, BarcodeFormat.QR_CODE, width, height);
        MatrixToImageWriter.writeToStream(matrix, "png", out);
        out.flush();
    } catch (WriterException e) {
        throw new ServletException("Failed writing QR", e);
    } catch (IOException e) {
        throw new ServletException("Failed writing QR", e);
    } finally {
        if (out != null) {
            try {
                out.close();
            } catch (IOException e) {
                // ignore
            }
        }
    }

}

From source file:com.example.analytics.AnalyticsServlet.java

@Override
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException {
    String trackingId = System.getenv("GA_TRACKING_ID");
    HttpClient client = HttpClientBuilder.create().build();
    URIBuilder builder = new URIBuilder();
    builder.setScheme("http").setHost("www.google-analytics.com").setPath("/collect").addParameter("v", "1") // API Version.
            .addParameter("tid", trackingId) // Tracking ID / Property ID.
            // Anonymous Client Identifier. Ideally, this should be a UUID that
            // is associated with particular user, device, or browser instance.
            .addParameter("cid", "555").addParameter("t", "event") // Event hit type.
            .addParameter("ec", "example") // Event category.
            .addParameter("ea", "test action"); // Event action.
    URI uri = null;/*  w  ww  . j  a va2 s .  c om*/
    try {
        uri = builder.build();
    } catch (URISyntaxException e) {
        throw new ServletException("Problem building URI", e);
    }
    HttpPost request = new HttpPost(uri);
    client.execute(request);
    resp.getWriter().println("Event tracked.");
}