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:IdeaBroker.InserirIdeiaServlet.java

/**
  * Handles the HTTP <code>GET</code> method.
  *//from w ww  .j  av a2s .com
  * @param request servlet request
  * @param response servlet response
  * @throws ServletException if a servlet-specific error occurs
  * @throws IOException if an I/O error occurs
  */
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    throw new ServletException(
            "Metodo Get usado com  " + getClass().getName() + " sendo o metodo Post o requirido.");
}

From source file:de.betterform.agent.web.servlet.XFormsPostServlet.java

/**
 * read from the inputStream and parse that as DOM. The result is passed into a request attribute for
 * processing by the XFormsFilter.//from   www. j  a  v  a 2s  . c  o  m
 *
 * @param request  servlet request
 * @param response servlet response
 * @throws javax.servlet.ServletException
 * @throws java.io.IOException
 */
protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    LOGGER.debug("hit XFormsPostServlet");

    request.setCharacterEncoding("UTF-8");
    WebUtil.nonCachingResponse(response);

    Document doc;
    try {
        //parse it
        doc = DOMUtil.parseInputStream(request.getInputStream(), true, false);
    } catch (ParserConfigurationException e) {
        throw new ServletException(e);
    } catch (SAXException e) {
        throw new ServletException(e);
    }

    //do the Filter twist
    request.setAttribute(WebFactory.XFORMS_NODE, doc);
    request.setAttribute(XFormsPostServlet.INIT_BY_POST, doc);
    response.getOutputStream().close();
}

From source file:com.tremolosecurity.proxy.filters.RetreiveIdToken.java

@Override
public void doFilter(HttpFilterRequest request, HttpFilterResponse response, HttpFilterChain chain)
        throws Exception {
    HashMap<String, OpenIDConnectIdP> idps = (HashMap<String, OpenIDConnectIdP>) GlobalEntries
            .getGlobalEntries().get(OpenIDConnectIdP.UNISON_OPENIDCONNECT_IDPS);

    OpenIDConnectIdP idp = idps.get(this.idpName);
    if (idp == null) {
        throw new ServletException("Could not find idp '" + this.idpName + "'");
    }/*  ww  w. jav  a2 s  . co m*/
    Gson gson = new Gson();
    String json = this.inflate(request.getParameter("refresh_token").getValues().get(0));
    Token token = gson.fromJson(json, Token.class);

    byte[] iv = org.bouncycastle.util.encoders.Base64.decode(token.getIv());

    IvParameterSpec spec = new IvParameterSpec(iv);
    Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
    cipher.init(Cipher.DECRYPT_MODE, GlobalEntries.getGlobalEntries().getConfigManager()
            .getSecretKey(idp.getTrusts().get(this.trustName).getCodeLastmileKeyName()), spec);

    byte[] encBytes = org.bouncycastle.util.encoders.Base64.decode(token.getEncryptedRequest());
    String refreshToken = new String(cipher.doFinal(encBytes));

    OIDCSession session = idp.getSessionByRefreshToken(refreshToken);

    if (session == null) {
        response.setStatus(401);
    } else {
        response.getWriter().print(session.getIdToken());
    }

}

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

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    try {/* w ww  . j  a v  a 2s  .  c o m*/
        User user = (User) req.getAttribute("user");
        user.setLastLogin(new Date());
        this.servicesClient.updateUser(user, user.getId());
        resp.sendRedirect(req.getContextPath() + "/index.jsp");
    } catch (ClientException e) {
        Status responseStatus = e.getResponseStatus();
        if (responseStatus == Status.FORBIDDEN) {
            HttpSession session = req.getSession(false);
            if (session != null) {
                session.invalidate();
            }
            resp.sendError(HttpStatus.SC_FORBIDDEN);
        } else {
            throw new ServletException(e);
        }
    }
}

From source file:filter.ConexaoHibernateFilter.java

@Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain chain)
        throws ServletException, IOException {
    try {// www .j  a va2  s .  c o m

        this.sf.getCurrentSession().beginTransaction();
        chain.doFilter(servletRequest, servletResponse);
        this.sf.getCurrentSession().getTransaction().commit();
        this.sf.getCurrentSession().close();
    } catch (Throwable ex) {
        try {
            if (this.sf.getCurrentSession().getTransaction().isActive()) {
                this.sf.getCurrentSession().getTransaction().rollback();
            }
        } catch (Throwable t) {
            t.printStackTrace();
        }
        throw new ServletException(ex);
    }
    HttpServletRequest request = (HttpServletRequest) servletRequest;
    HttpSession session = request.getSession();

    // recupera o usuario adm logado da sesso
    Object login = session.getAttribute("UsuarioAtual");
    RequestDispatcher dispatcher = null;

    if (!(request.getRequestURI().equals(paginaLogin) || request.getRequestURI().equals(paginaPrimeiroAcesso)
            || request.getRequestURI().equals(paginaRecuperarSenha))) {
        if (login == null) {
            // ento envia para a pagina de acesso invalido
            dispatcher = servletRequest.getRequestDispatcher("loginEntrar.xhtml");
            dispatcher.forward(servletRequest, servletResponse);
        }

    }

}

From source file:edu.indiana.d2i.datacatalog.dashboard.api.USStates.java

public void doGet(HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException {
    // TODO: Cache the states.
    response.setContentType("application/json");

    try {//from w w  w  .  j a v  a  2  s .c  o m
        String statesPath = getServletContext().getRealPath("/WEB-INF/resources/states.xml");
        response.getWriter().write(getStates(statesPath).toString());
    } catch (IOException e) {
        log.error("Error while reading states file.", e);
        throw e;
    } catch (ParserConfigurationException e) {
        log.error("Error while reading states file.", e);
        throw new ServletException(e);
    } catch (SAXException e) {
        log.error("Error while reading states file.", e);
        throw new ServletException(e);
    }
}

From source file:de.betterform.agent.web.servlet.XFormsRequestServlet.java

/**
 * This ia jus a little demo servlet to show operation with XFormsFilter. It parses the XForms
 * document form the file system and writes it out to the ServletStream. Additionally it sets the request property
 * XFORMS_FILTER to allow the Filter to work efficiently.
 *
 * @param request  servlet request/*from  ww w .j  av  a 2 s . co  m*/
 * @param response servlet response
 * @throws javax.servlet.ServletException
 * @throws java.io.IOException
 */
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    LOGGER.debug("hit XFormsRequestServlet");

    request.setCharacterEncoding("UTF-8");
    WebUtil.nonCachingResponse(response);

    Document doc;

    //locate it
    //        String formURI = request.getParameter(WebFactory.FORM_PARAM_NAME);
    String formURI = WebUtil.getFormUrlAsString(request);
    if (formURI.startsWith("http://")) {
        InputStream inputStream = new URL(formURI).openStream();
        try {
            doc = DOMUtil.parseInputStream(inputStream, true, false);
        } catch (ParserConfigurationException e) {
            throw new ServletException(e);
        } catch (SAXException e) {
            throw new ServletException(e);
        }
    } else {
        String realPath = null;
        try {
            realPath = WebFactory.getRealPath(formURI, getServletContext());
        } catch (XFormsConfigException e) {
            throw new ServletException(e);
        }
        File xfDoc = new File(realPath);
        try {
            doc = DOMUtil.parseXmlFile(xfDoc, true, false);
        } catch (ParserConfigurationException e) {
            throw new ServletException(e);
        } catch (SAXException e) {
            throw new ServletException(e);
        }
    }

    //parse it

    request.setAttribute(WebFactory.XFORMS_NODE, doc);
    //        try {
    //            DOMUtil.prettyPrintDOM(doc,response.getOutputStream());
    //        } catch (TransformerException e) {
    //            throw new ServletException(e);
    //        }

    //do the Filter twist
    response.getOutputStream().close();
}

From source file:org.echocat.jemoni.jmx.support.SpringUtils.java

public static void assertSpringAvailable() throws ServletException {
    if (!isSpringAvailable()) {
        throw new ServletException(
                "There is no spring available. Could not find a valid implementation in classpath.");
    }/* w  ww .  j  a v a  2s . c  om*/
}

From source file:org.ambraproject.user.action.AdminUserAlertsAction.java

/**
 * Save the alerts./* w  w  w  . j av a 2 s .  c o m*/
 *
 * @return webwork status
 * @throws Exception Exception
 */
public String saveAlerts() throws Exception {
    final String authId = getUserAuthId();
    if (authId == null) {
        throw new ServletException("Unable to resolve ambra user");
    }
    userService.setAlerts(authId, Arrays.asList(monthlyAlerts), Arrays.asList(weeklyAlerts));
    return SUCCESS;
}

From source file:com.meltmedia.cadmium.servlets.ErrorPageFilterSelectionTest.java

/**
 * Creates a filter chain that throws a ServletException with the specified cause.
 * @param cause the cause of the exception that will be thrown.
 * @return a filter chain that simulates an exception.
 *//*from   w w w  .  j a v a 2s . co m*/
public static FilterChain throwExceptionFilterChain(final Throwable cause) {
    return new FilterChain() {
        @Override
        public void doFilter(ServletRequest req, ServletResponse res) throws IOException, ServletException {
            throw new ServletException(cause);
        }
    };
}