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.community.chest.gitcloud.facade.backend.git.GitBackendServlet.java

@Override
public void init(ServletConfig config) throws ServletException {
    RepositoryResolver<HttpServletRequest> resolver = BackendRepositoryResolver.getInstance();
    if (resolver == null) {
        throw new ServletException("Repository resolver N/A");
    }//w ww  . jav  a2s  .  c o m

    UploadPackFactory<HttpServletRequest> uploadFactory = BackendUploadPackFactory.getInstance();
    if (uploadFactory == null) {
        throw new ServletException("Backend upload factory N/A");
    }

    ReceivePackFactory<HttpServletRequest> receiveFactory = BackendReceivePackFactory.getInstance();
    if (receiveFactory == null) {
        throw new ServletException("Backend receive factory N/A");
    }

    setRepositoryResolver(resolver);
    setReceivePackFactory(receiveFactory);
    setUploadPackFactory(uploadFactory);
    super.init(config);
}

From source file:de.betterform.agent.web.filter.XSLTFilter.java

public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
        throws IOException, ServletException {
    HttpServletRequest httpRequest = (HttpServletRequest) request;
    HttpServletResponse httpResponse = (HttpServletResponse) response;
    ServletContext servletContext = filterConfig.getServletContext();

    /* TODO: clean up, styleFile is  never used */
    String stylePath = null;//ww  w.  ja  va2s  .  c om
    try {
        stylePath = WebFactory.getRealPath(xsltPath, servletContext);
    } catch (XFormsConfigException e) {
        throw new ServletException(e);
    }
    File styleFile = new File(stylePath, xslFile);

    PrintWriter out = response.getWriter();
    CharResponseWrapper wrapper = new CharResponseWrapper((HttpServletResponse) response);
    try {
        URI uri = new File(WebFactory.getRealPath(xsltPath, servletContext)).toURI().resolve(new URI(xslFile));
        XSLTGenerator generator = WebFactory.setupTransformer(uri, servletContext);

        wrapper.setContentType("text/html");
        chain.doFilter(request, wrapper);

        StringReader sr = new StringReader(wrapper.toString());
        generator.setInput(sr);
        //            Source xmlSource = new StreamSource((Reader) sr);
        CharArrayWriter caw = new CharArrayWriter();
        generator.setOutput(caw);

        //            StreamResult result = new StreamResult(caw);
        //            transformer.transform(xmlSource, result);
        generator.generate();
        response.setContentLength(caw.toString().length());
        out.write(caw.toString());

    } catch (URISyntaxException e) {
        out.println(e.toString());
        out.write(wrapper.toString());
    } catch (XFormsException e) {
        out.println(e.toString());
        out.write(wrapper.toString());
    }
}

From source file:com.amalto.core.servlet.TransactionFilter.java

@Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain)
        throws IOException, ServletException {
    TransactionState state = getState(servletRequest);
    try {/*  w  ww  . j a  v a2  s.com*/
        state.preRequest();
        filterChain.doFilter(servletRequest, servletResponse);
    } catch (Throwable t) {
        state.cancelRequest();
        throw new ServletException(t);
    } finally {
        state.postRequest();
    }
}

From source file:be.fedict.eid.dss.portal.DownloadServlet.java

private String getRequiredInitParameter(ServletConfig config, String paramName) throws ServletException {
    String paramValue = config.getInitParameter(paramName);
    if (null == paramValue) {
        throw new ServletException("missing init-param: " + paramName);
    }/*ww  w . j  ava 2s.  co m*/
    return paramValue;
}

From source file:com.mirth.connect.server.servlets.MirthServlet.java

public boolean isUserAuthorized(HttpServletRequest request, Map<String, Object> parameterMap)
        throws ServletException {
    try {/*from   w w w .j  a v a2  s.  c o  m*/
        return authorizationController.isUserAuthorized(getCurrentUserId(request), request.getParameter("op"),
                parameterMap, getRequestIpAddress(request));
    } catch (ControllerException e) {
        throw new ServletException(e);
    }
}

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

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

    Collection<? extends Object> objectCollection = null;

    try {/*from   w ww . j  a  v a 2 s.co m*/
        objectCollection = (Collection<? 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(XML_CONTENT_TYPE);

    StringBuilder responseContent = new StringBuilder();
    responseContent.append(XML_HEAD);

    responseContent.append(XML_RESULT_ROOT_START_TAG);
    if (objectCollection != null) {
        for (Object currObj : objectCollection) {
            responseContent.append(XML_VALUE_START_TAG);
            responseContent.append(currObj.toString());
            responseContent.append(XML_VALUE_END_TAG);
        }
    }
    responseContent.append(XML_RESULT_ROOT_END_TAG);

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

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

}

From source file:com.haulmont.cuba.web.sys.CubaHttpFilter.java

@Override
public void init(FilterConfig filterConfig) throws ServletException {
    Configuration configuration = AppBeans.get(Configuration.NAME);
    if (configuration.getConfig(WebAuthConfig.class).getExternalAuthentication()) {
        try {//w w  w . j a va2  s. co  m
            authProvider = AppBeans.get(CubaAuthProvider.NAME);
            authProvider.init(filterConfig);
        } catch (Exception e) {
            throw new ServletException(e);
        }
        // Fill bypassUrls
        String urls = configuration.getConfig(WebConfig.class).getCubaHttpFilterBypassUrls();
        String[] strings = urls.split("[, ]");
        for (String string : strings) {
            if (StringUtils.isNotBlank(string)) {
                bypassUrls.add(string);
            }
        }
    }
}

From source file:com.Uploader.java

protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    if (!ServletFileUpload.isMultipartContent(request)) {
        throw new ServletException("Content type is not multipart/form-data");
    }// w ww  . ja v a  2s  .c  o  m

    response.setContentType("text/html");
    PrintWriter out = response.getWriter();
    out.write("<html><head></head><body>");
    try {
        List<FileItem> fileItemsList = uploader.parseRequest(request);
        Iterator<FileItem> fileItemsIterator = fileItemsList.iterator();
        while (fileItemsIterator.hasNext()) {
            FileItem fileItem = fileItemsIterator.next();
            System.out.println("FieldName=" + fileItem.getFieldName());
            System.out.println("FileName=" + fileItem.getName());
            System.out.println("ContentType=" + fileItem.getContentType());
            System.out.println("Size in bytes=" + fileItem.getSize());
            File file = new File(request.getServletContext().getAttribute("FILES_DIR") + File.separator
                    + fileItem.getName());
            System.out.println("Absolute Path at server=" + file.getAbsolutePath());
            fileItem.write(file);
            out.write("File " + fileItem.getName() + " uploaded successfully.");
            out.write("<br>");
            out.write("<a href=\"Uploader?fileName=" + fileItem.getName() + "\">Download " + fileItem.getName()
                    + "</a>");
        }
    } catch (FileUploadException e) {
        out.write("Exception in uploading file.");
        e.printStackTrace();
    } catch (Exception e) {
        out.write("Exception in uploading file.");
        e.printStackTrace();
    }
    out.write("</body></html>");
}

From source file:org.openmrs.web.controller.FieldGenController.java

@SuppressWarnings("unchecked")
public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    // find the field that was identified in the openmrs:fieldGen taglib
    Object uri = request.getAttribute("javax.servlet.include.servlet_path.fieldGen");
    if (uri == null) {
        uri = request.getAttribute("javax.servlet.include.servlet_path");
    }/*w  w w  .ja va  2s  .  c  o m*/
    String fieldGenPath = "";
    Map<String, Object> model = new HashMap<String, Object>();

    if (uri != null) {
        fieldGenPath = uri.toString();

        // Allowable extensions are '' (no extension) and '.field'
        if (fieldGenPath.endsWith("field")) {
            fieldGenPath = fieldGenPath.replace(".field", "");
        } else if (fieldGenPath.endsWith("jsp")) {
            throw new ServletException(
                    "Illegal extension used for fieldGen: '.jsp'. Allowable extensions are '' (no extension) and '.field'");
        }

        String type = (String) request.getAttribute("org.openmrs.fieldGen.type");
        String formFieldName = (String) request.getAttribute("org.openmrs.fieldGen.formFieldName");
        //String startVal = (String)request.getAttribute("org.openmrs.fieldGen.startVal");
        Map<String, Object> params = (Map<String, Object>) request
                .getAttribute("org.openmrs.fieldGen.parameters");
        Map<String, Object> moreParams = (Map<String, Object>) request
                .getAttribute("org.openmrs.fieldGen.parameterMap");

        model.put("type", type);
        model.put("formFieldName", formFieldName);
        model.put("obj", request.getAttribute("org.openmrs.fieldGen.object"));
        model.put("request", request.getAttribute("org.openmrs.fieldGen.request"));
        model.putAll(params);
        if (moreParams != null) {
            model.putAll(moreParams);
        }

        request.removeAttribute("org.openmrs.fieldGen.type");
        request.removeAttribute("org.openmrs.fieldGen.formFieldName");
        request.removeAttribute("org.openmrs.fieldGen.object");
        request.removeAttribute("org.openmrs.fieldGen.parameters");
        request.removeAttribute("org.openmrs.fieldGen.parameterMap");
    }

    return new ModelAndView(fieldGenPath, "model", model);

}

From source file:pt.sapo.pai.vip.VipServlet.java

@Override
public void init() throws ServletException {
    super.init();
    try {//from w w w .ja v a  2 s.c  om
        servers = ((String) new InitialContext().lookup("java:comp/env/servers")).split(",");
    } catch (NamingException ex) {
        throw new ServletException(ex);
    }
}