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.wcm.caconfig.editor.impl.ConfigNamesServlet.java

@Override
protected void doGet(@NotNull SlingHttpServletRequest request, @NotNull SlingHttpServletResponse response)
        throws ServletException, IOException {
    if (!editorConfig.isEnabled()) {
        response.sendError(HttpServletResponse.SC_FORBIDDEN);
        return;//from   w  ww.  j  av  a2  s . co m
    }

    Resource contextResource = request.getResource();
    try {
        JSONObject result = new JSONObject();
        result.putOpt("contextPath", getContextPath(contextResource));
        result.put("configNames", getConfigNames(contextResource));

        response.setContentType("application/json;charset=" + CharEncoding.UTF_8);
        response.getWriter().write(result.toString());
    } catch (JSONException ex) {
        throw new ServletException("Unable to generate JSON.", ex);
    }
}

From source file:com.github.woonsan.katharsis.servlet.AbstractKatharsisFilter.java

public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain)
        throws IOException, ServletException {

    if (req instanceof HttpServletRequest && res instanceof HttpServletResponse) {
        HttpServletRequest request = (HttpServletRequest) req;
        HttpServletResponse response = (HttpServletResponse) res;

        KatharsisInvokerContext invokerContext = createKatharsisInvokerContext(request, response);

        try {//from ww w.  jav a 2 s . c o m
            getKatharsisInvoker().invoke(invokerContext);
        } catch (KatharsisInvokerException e) {
            log.warn("Katharsis Invoker exception.", e);
            response.setStatus(e.getStatusCode());
        } catch (Exception e) {
            throw new ServletException("Katharsis invocation failed.", e);
        }
    } else {
        chain.doFilter(req, res);
    }
}

From source file:it.pronetics.madstore.server.test.servlet.DataServlet.java

public void init(ServletConfig config) throws ServletException {
    try {/*from  w  w w  .  j  a va2 s .c  om*/
        super.init(config);
        ctx = WebApplicationContextUtils.getWebApplicationContext(getServletContext());
        Map collectionRepositories = ctx.getBeansOfType(CollectionRepository.class);
        Map entryRepositories = ctx.getBeansOfType(EntryRepository.class);
        if (collectionRepositories.size() != 1 || entryRepositories.size() != 1) {
            throw new IllegalStateException();
        } else {
            collectionRepository = (CollectionRepository) collectionRepositories.values().toArray()[0];
            entryRepository = (EntryRepository) entryRepositories.values().toArray()[0];
        }
        InputStream collectionStream = Thread.currentThread().getContextClassLoader()
                .getResourceAsStream("entriesCollection.xml");
        InputStream entryStream1 = Thread.currentThread().getContextClassLoader()
                .getResourceAsStream("entry1.xml");
        InputStream entryStream2 = Thread.currentThread().getContextClassLoader()
                .getResourceAsStream("entry2.xml");
        InputStream entryStream3 = Thread.currentThread().getContextClassLoader()
                .getResourceAsStream("entry3.xml");

        byte[] bytes = new byte[collectionStream.available()];
        collectionStream.read(bytes);
        Element collection = DomHelper.getDomFromString(new String(bytes));

        bytes = new byte[entryStream1.available()];
        entryStream1.read(bytes);
        Element entry1 = DomHelper.getDomFromString(new String(bytes));

        bytes = new byte[entryStream2.available()];
        entryStream2.read(bytes);
        Element entry2 = DomHelper.getDomFromString(new String(bytes));

        bytes = new byte[entryStream3.available()];
        entryStream3.read(bytes);
        Element entry3 = DomHelper.getDomFromString(new String(bytes));

        collectionKey = collectionRepository.putIfAbsent(collection);
        entryRepository.put(collectionKey, entry1);
        entryRepository.put(collectionKey, entry2);
        entryRepository.put(collectionKey, entry3);
    } catch (Exception ex) {
        throw new ServletException(ex.getMessage(), ex);
    }
}

From source file:de.ingrid.interfaces.csw.server.CSWServlet.java

/**
 * @see javax.servlet.http.HttpServlet#doGet(javax.servlet.http.HttpServletRequest,
 *      javax.servlet.http.HttpServletResponse)
 *///from  w  w  w .  j a v  a 2  s .  c om
@Override
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException {
    try {
        if (request.getHeader("Keep-Alive") != null && request.getContentLength() == -1) {
            Log.debug("Ignore keep-alive request.");
        } else if (request.getContentType().toLowerCase().indexOf("application/soap+xml") != -1) {
            this.serverFacade.handleSoapRequest(request, response);
        } else {
            this.serverFacade.handlePostRequest(request, response);
        }
    } catch (Exception ex) {
        throw new ServletException("POST failed: " + ex.getMessage(), ex);
    }
}