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:net.ontopia.topicmaps.nav2.servlets.DataIntegrationServlet.java

@Override
public void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    response.setContentType("text/plain; charset=utf-8");

    // get topic map id
    String topicMapId = topicMapId = getInitParameter("topicMapId");
    if (topicMapId == null)
        throw new ServletException("Topic map identifier is not specified.");

    // parse path
    String path = request.getPathInfo();
    if (path == null)
        throw new ServletException("Path is missing.");
    path = path.substring(1);//from w w w  .  j a  v a2  s  .co m

    String[] args = StringUtils.split(path, "/");
    String name = args[0];
    String action = args[1];

    // get topics query
    String topicsQuery = getInitParameter("topicsQuery");
    if (topicsQuery == null)
        throw new ServletException("Parameter 'topicsQuery' is not specified.");

    // get characteristcs query
    String characteristicsQuery = getInitParameter("characteristicsQuery");
    if (characteristicsQuery == null)
        throw new ServletException("Parameter 'characteristicsQuery' is not specified.");

    TopicMapStoreIF targetStore = TopicMaps.createStore(topicMapId, false);
    try {
        final TopicMapIF target = targetStore.getTopicMap();

        // transform input document to topic map
        final TopicMapIF source = transformRequest(name, request.getInputStream(),
                targetStore.getBaseAddress());

        // find topics to synchronize
        QueryProcessorIF qp = QueryUtils.getQueryProcessor(source);

        List candidates = new ArrayList();
        QueryResultIF qr = qp.execute(topicsQuery);
        try {
            while (qr.next()) {
                // synchronize topic
                candidates.add(qr.getValue(0));
            }
        } finally {
            qr.close();
        }

        if ("updated".equals(action) || "created".equals(action)) {

            DeciderIF tfilter = new DeciderIF() {
                @Override
                public boolean ok(Object o) {
                    return true;
                }
            };

            Iterator iter = candidates.iterator();
            while (iter.hasNext()) {
                TopicIF src = (TopicIF) iter.next();

                DeciderIF sfilter;
                if (characteristicsQuery == null) {
                    // let everything through
                    sfilter = tfilter;

                } else {
                    // let the characteristics query decide what gets synchronized
                    Collection characteristics = new HashSet();
                    QueryResultIF cqr = qp.execute(characteristicsQuery,
                            Collections.singletonMap("topic", src));
                    try {
                        while (cqr.next()) {
                            // synchronize topic
                            characteristics.add(cqr.getValue(0));
                        }
                    } finally {
                        cqr.close();
                    }
                    sfilter = new ContainmentDecider(characteristics);
                }
                // synchronize topic
                TopicMapSynchronizer.update(target, src, tfilter, sfilter);
            }
        } else if ("deleted".equals(action)) {

            Iterator iter = candidates.iterator();
            while (iter.hasNext()) {
                TopicIF src = (TopicIF) iter.next();
                Collection affectedTopics = IdentityUtils.findSameTopic(target, src);
                Iterator aiter = affectedTopics.iterator();
                while (aiter.hasNext()) {
                    TopicIF affectedTopic = (TopicIF) aiter.next();
                    affectedTopic.remove();
                }
            }
        } else {
            throw new ServletException("Unsupported action: " + action);
        }

        targetStore.commit();
    } catch (Exception e) {
        targetStore.abort();
        throw new ServletException(e);
    } finally {
        targetStore.close();
    }
}

From source file:edu.emory.cci.aiw.cvrg.eureka.servlet.ProxyServlet.java

@Override
public void init() throws ServletException {

    targetUri = getConfigParam(P_TARGET_URI);
    if (targetUri == null)
        throw new ServletException(P_TARGET_URI + " is required.");
    //test it's valid
    try {//from   w  w w .  j  a v a2 s .  c om
        targetUriObj = new URI(targetUri);
    } catch (Exception e) {
        throw new ServletException("Trying to process targetUri init parameter: " + e, e);
    }

}

From source file:com.controlj.green.istat.web.TreeServlet.java

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

    resp.setHeader("Expires", "Wed, 01 Jan 2003 12:00:00 GMT");
    resp.setHeader("Cache-Control", "no-cache");
    ServletOutputStream out = resp.getOutputStream();
    try {/*from   w  ww .  j  a  va  2  s.  c  o m*/
        writeLevel(out, req.getParameter(LOCATION_PARAM), req);
    } catch (Exception e) {
        Logging.LOGGER.println("Error getting tree info");
        e.printStackTrace(Logging.LOGGER);
        throw new ServletException(e);
    }
    out.flush();
    /*
    out.println("[");
    out.println("{ display:'Main Conf Room', id:'mainconf'},");
    out.println("{ display:'Board Room', id:'boardroom'},");
    out.println("{ display:'Room 235', id:'room235'}");
    out.println("]");
    */
}

From source file:com.vaadin.addon.jpacontainer.demo.servlet.SpringApplicationServlet.java

@Override
public void init(ServletConfig servletConfig) throws ServletException {
    super.init(servletConfig);
    /*//from w w  w.ja  v  a 2 s.  com
     * Look up the name of the Vaadin application prototype bean.
     */
    applicationBean = servletConfig.getInitParameter("applicationBean");
    if (applicationBean == null) {
        if (logger.isErrorEnabled()) {
            logger.error("ApplicationBean not specified in servlet parameters");
        }
        throw new ServletException("ApplicationBean not specified in servlet parameters");
    }

    if (logger.isInfoEnabled()) {
        logger.info("Found Vaadin ApplicationBean [" + applicationBean + "]");
    }
    /*
     * Fetch the Spring web application context
     */
    applicationContext = WebApplicationContextUtils.getWebApplicationContext(servletConfig.getServletContext());

    if (!applicationContext.isPrototype(applicationBean)) {
        if (logger.isWarnEnabled()) {
            logger.warn("ApplicationBean not configured as a prototype");
        }
    }

    applicationClass = (Class<? extends Application>) applicationContext.getType(applicationBean);
    if (logger.isDebugEnabled()) {
        logger.debug("Vaadin application class is [" + applicationClass + "]");
    }
}

From source file:net.sourceforge.vulcan.web.SignedRequestAuthorizationFilter.java

@Override
protected void initFilterBean() throws ServletException {
    if (StringUtils.isBlank(sharedSecret)) {
        secretKey = null;/*from   w  w w .  j  av a2s .co m*/
        return;
    }

    try {
        secretKey = new SecretKeySpec(sharedSecret.getBytes(), algorithm);

        // Initialize a mac instance to fail fast on NoSuchAlgorithmException or InvalidKeyException.
        // This way any configuration errors will prevent the application from starting instead of causing
        // problems later.
        final Mac mac = Mac.getInstance(algorithm);

        mac.init(secretKey);
    } catch (NoSuchAlgorithmException e) {
        throw new ServletException(e);
    } catch (InvalidKeyException e) {
        throw new ServletException(e);
    }
}

From source file:org.echocat.nodoodle.server.ServiceServlet.java

@Override
public void service(ServletRequest request, ServletResponse response) throws ServletException, IOException {
    final HttpService service = _service;
    if (service == null) {
        throw new ServletException("Was the init() method not called?");
    }//from  www.  ja v a  2 s.  c o  m
    service.handle((HttpServletRequest) request, (HttpServletResponse) response);
}

From source file:de.hybris.platform.b2bdocumentsfilter.B2BDocumentsSecureMediaFilter.java

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

    if ((!(request instanceof HttpServletRequest)) || (!(response instanceof HttpServletResponse))) {
        throw new ServletException("SecureMediaFilter just supports HTTP requests");
    }//from   w w w.j  av  a2  s  . c  o m
    final HttpServletRequest httpRequest = (HttpServletRequest) request;
    final HttpServletResponse httpResponse = (HttpServletResponse) response;

    final String resourcePath = getResourcePath(httpRequest);
    try {
        setSecureURLRendererForThread(httpResponse);

        if (StringUtils.contains(resourcePath, this.secureMediaToken)) {
            final String mediaPKStr = httpRequest.getParameter(MEDIA_PK);

            final MediaModel mediaModel = (MediaModel) this.modelService.get(PK.parse(mediaPKStr));

            if (mediaModel == null) {
                httpResponse.sendError(404);
                return;
            } else if (!(isAccessGranted(mediaModel))) {
                httpResponse.sendError(403);
                return;
            }
            final int mediaSize = (mediaModel.getSize() == null) ? 0 : mediaModel.getSize().intValue();
            sendData(httpResponse, this.mediaService.getStreamFromMedia(mediaModel), mediaSize);
        }

    } finally {

        chain.doFilter(request, response);
        clearSecureURLRendererForThread();
    }
}

From source file:de.berlios.jedi.presentation.editor.NewJispPackageFilter.java

/**
 * Sets a new Jisp Package, the list of existent Jisp Packages and a
 * JispIdManager in request session.<br>
 * Jisp Packages from list are registered in JispIdManager.<br>
 * If there is already a Jisp Package being created, nothing is done.
 * /*from w  ww  .  ja  v  a 2 s  .co  m*/
 * @throws ServletException
 *             If a ServletException occurs when doing the filter.
 * @throws IOException
 *             If a IOException occurs when doing the filter.
 * 
 * @see javax.servlet.Filter#doFilter(javax.servlet.ServletRequest,
 *      javax.servlet.ServletResponse, javax.servlet.FilterChain)
 */
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
        throws IOException, ServletException {

    if (!(request instanceof HttpServletRequest)) {
        LogFactory.getLog(LoginFilter.class)
                .error("Unexpected error: request in NewJispPackageFilter" + "isn't a HttpServletRequest");
        throw new ServletException(
                "Unexpected error: request in NewJispPackageFilter" + "isn't a HttpServletRequest");
    }

    HttpServletRequest httpRequest = (HttpServletRequest) request;
    JispPackage jispPackage = (JispPackage) ((HttpServletRequest) request).getSession()
            .getAttribute(EditorKeys.JISP_PACKAGE);

    try {
        if (jispPackage == null) {
            httpRequest.setAttribute(Keys.NEXT_FORWARD_NAME, httpRequest.getServletPath());
            httpRequest.getSession().getServletContext().getRequestDispatcher("/NewJispPackage.do")
                    .forward(request, response);
            return;
        }

        chain.doFilter(request, response);
    } catch (IOException e) {
        LogFactory.getLog(LoginFilter.class).error("IOException in NewJispPackageFilter", e);
        throw e;
    } catch (ServletException e) {
        LogFactory.getLog(LoginFilter.class).error("ServletException in NewJispPackageFilter", e);
        throw e;
    }
}

From source file:org.apache.cxf.fediz.service.idp.MetadataServlet.java

@Override
public void init(ServletConfig config) throws ServletException {
    super.init(config);
    realm = config.getInitParameter(PARAM_REALM);
    if (realm == null || realm.length() == 0) {
        throw new ServletException("Servlet parameter '" + PARAM_REALM + "' not defined");
    }/*from   ww w . j  a  v a2 s .co m*/
}

From source file:org.jamwiki.authentication.JAMWikiPostAuthenticationFilter.java

/**
 *
 *///from   w  w w .  j a  v  a2  s . c  om
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
        throws IOException, ServletException {
    if (!(request instanceof HttpServletRequest)) {
        throw new ServletException("HttpServletRequest required");
    }
    Authentication auth = SecurityContextHolder.getContext().getAuthentication();
    if (auth instanceof AnonymousAuthenticationToken) {
        // anonymous user
        this.handleAnonymousUser(auth);
    } else if (auth != null && auth.isAuthenticated()) {
        // registered user
        this.handleRegisteredUser(auth);
    }
    chain.doFilter(request, response);
}