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:org.dspace.app.webui.cris.controller.MyRPController.java

@Override
public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
    Context context = UIUtil.obtainContext(request);
    EPerson currUser = context.getCurrentUser();
    if (currUser == null) {
        throw new ServletException(
                "Wrong data or configuration: access to the my rp servlet without a valid user: there is no user logged in or the user's netid is null");
    }/*from w w  w.  j av  a  2s . co  m*/

    if (AuthorizeManager.isAdmin(context)) {
        response.sendRedirect(request.getContextPath() + "/dspace-admin/");
    } else {
        Integer id = currUser.getID();
        ResearcherPage rp = applicationService.getResearcherPageByEPersonId(id);
        if (rp != null && rp.getStatus() != null && rp.getStatus().booleanValue()) {
            response.sendRedirect(
                    request.getContextPath() + "/rp/" + ResearcherPageUtils.getPersistentIdentifier(rp));
        } else {
            // the researcher page is not active so redirect the user to the home page
            response.sendRedirect(request.getContextPath() + "/");
        }
    }
    // nothing to save so abort the context to release resources
    context.abort();
    return null;
}

From source file:com.sri.save.FloraHttpServlet.java

@Override
public void init() throws ServletException {
    Properties properties = new Properties();
    try {/*w w  w. j  a  va2  s .c o  m*/
        ServletContext context = getServletContext();
        properties.load(context.getResourceAsStream("/WEB-INF/config.properties"));
    } catch (IOException e) {
        throw new ServletException("Could not open config.properties!");
    }
    String xsb = properties.getProperty("xsb");
    String floradir = properties.getProperty("flora.dir");
    String content_dir = properties.getProperty("ontology.dir"); // base dir for imported files

    // Initialize the server
    try {
        florajson = new FloraJsonServer(new File(xsb), new File(floradir), new File(content_dir));
    } catch (FloraJsonServerException ex) {
        throw new ServletException(ex);
    }
}

From source file:edu.cornell.mannlib.vitro.webapp.controller.authenticate.ProgramLogin.java

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    try {//from  w w w .j a v a 2  s  .co  m
        new ProgramLoginCore(req, resp).process();
    } catch (LoginNotPermitted e) {
        // This should have been prevented by the test for loginDisabled()
        throw new ServletException(e);
    }
}

From source file:com.collective.celos.servlet.JSONWorkflowListServlet.java

protected void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException {
    try {/*from   w w w.j av a  2s  .c o  m*/
        Scheduler sch = getOrCreateCachedScheduler();
        WorkflowConfiguration cfg = sch.getWorkflowConfiguration();
        ObjectNode object = createJSONObject(cfg);
        writer.writeValue(res.getOutputStream(), object);
    } catch (Exception e) {
        throw new ServletException(e);
    }
}

From source file:MailAccessor.java

private void handleMessages(HttpServletRequest request, PrintWriter out) throws IOException, ServletException {

    HttpSession httpSession = request.getSession();
    String user = (String) httpSession.getAttribute("user");
    String password = (String) httpSession.getAttribute("pass");
    String popAddr = (String) httpSession.getAttribute("pop");

    Store popStore = null;/*from w  ww .j  a  v  a 2  s . c  o  m*/
    Folder folder = null;

    if (!check(popAddr))
        popAddr = MailAccessor.DEFAULT_SERVER;

    try {

        if ((!check(user)) || (!check(password)))
            throw new ServletException("A valid username and password is required to check email.");

        Properties properties = System.getProperties();

        Session session = Session.getDefaultInstance(properties);

        popStore = session.getStore("pop3");

        popStore.connect(popAddr, user, password);

        folder = popStore.getFolder("INBOX");

        if (!folder.exists())
            throw new ServletException("An 'INBOX' folder does not exist for the user.");

        folder.open(Folder.READ_ONLY);

        Message[] messages = folder.getMessages();
        int msgLen = messages.length;

        if (msgLen == 0)
            out.println("<h2>The INBOX folder does not yet contain any email messages.</h2>");

        for (int i = 0; i < msgLen; i++) {
            displayMessage(messages[i], out);
            out.println("<br /><br />");
        }

    } catch (Exception exc) {

        out.println("<h2>Sorry, an error occurred while accessing the email messages.</h2>");
        out.println(exc.toString());

    } finally {
        try {
            if (folder != null)
                folder.close(false);

            if (popStore != null)
                popStore.close();
        } catch (Exception e) {
        }
    }
}

From source file:org.fusesource.restygwt.server.complex.DTOInterfaceServlet.java

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    DTOImplementation impl = new DTOImplementation();
    impl.setName("interface");

    resp.setContentType("application/json");
    ObjectMapper om = new ObjectMapper();
    try {/*from  w  ww.j ava 2  s .  c  o  m*/
        om.writeValue(resp.getOutputStream(), impl);
    } catch (Exception e) {
        throw new ServletException(e);
    }
}

From source file:org.fusesource.restygwt.server.complex.DTOImplementationServlet.java

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    DTOImplementation impl = new DTOImplementation();
    impl.setName("implementation");

    resp.setContentType("application/json");
    ObjectMapper om = new ObjectMapper();
    try {/*  ww  w. ja  v a  2  s.co m*/
        om.writeValue(resp.getOutputStream(), impl);
    } catch (Exception e) {
        throw new ServletException(e);
    }
}

From source file:com.googlecode.psiprobe.ProbeServlet.java

public void init(ServletConfig config) throws ServletException {
    super.init(config);
    if (wrapper != null) {
        getContainerWrapperBean().setWrapper(wrapper);
    } else {/*www .j  a  v a  2 s .com*/
        throw new ServletException("Wrapper is null");
    }
}

From source file:azkaban.web.MultipartParser.java

@SuppressWarnings("unchecked")
public Map<String, Object> parseMultipart(HttpServletRequest request) throws IOException, ServletException {
    ServletFileUpload upload = new ServletFileUpload(_uploadItemFactory);
    List<FileItem> items = null;
    try {//  w  w w  .ja v a  2 s. co m
        items = upload.parseRequest(request);
    } catch (FileUploadException e) {
        throw new ServletException(e);
    }

    Map<String, Object> params = new HashMap<String, Object>();
    for (FileItem item : items) {
        if (item.isFormField())
            params.put(item.getFieldName(), item.getString());
        else
            params.put(item.getFieldName(), item);
    }
    return params;
}

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

@Override
public void init(ServletConfig config) throws ServletException {
    super.init(config);
    final WebApplicationContext applicationContext = WebApplicationContextUtils
            .getWebApplicationContext(config.getServletContext());
    final String serviceName = config.getInitParameter(SERVICE_PARAM);
    if (StringUtils.isEmpty(serviceName)) {
        throw new ServletException("Required initParam " + SERVICE_PARAM + " not set.");
    }/*from w w  w  .  j av  a 2s  .  c  o  m*/
    try {
        _service = applicationContext.getBean(serviceName, HttpService.class);
    } catch (NoSuchBeanDefinitionException e) {
        throw new ServletException("No service '" + serviceName + "' (defined under initParam '" + SERVICE_PARAM
                + "') could not be found.", e);
    }
    try {
        _service.init(config.getServletContext());
    } catch (Exception e) {
        throw new ServletException("Could not initiate the service: " + _service, e);
    }
}