List of usage examples for javax.servlet ServletException ServletException
public ServletException(String message, Throwable rootCause)
From source file:com.vaadin.terminal.gwt.server.SpringApplicationOSGiServlet.java
@Override protected Application getNewApplication(HttpServletRequest request) throws ServletException { // Creates a new application instance try {//from www . j ava 2 s. c o m // Retrieve the Spring ApplicationContext registered as a service ApplicationContext springContext = getApplicationContext(); if (!springContext.containsBean(beanParam)) { throw new ClassNotFoundException("No application bean found under name " + beanParam); } final Application application = (Application) springContext.getBean(beanParam); return application; } catch (ClassNotFoundException e) { throw new ServletException("getNewApplication failed", e); } }
From source file:com.yahoo.yos.YahooFilter.java
/** * Set the 'oauth' init parameter for this filter to change from the default * oauth.properties resource for configuration. The file should define: * <p/>/* ww w . ja va2 s . c o m*/ * yos.consumerKey=... * yos.consumerSecret=... * oauth.requesttoken.url=https://api.login.yahoo.com/oauth/v2/get_request_token * oauth.requestauth.url=https://api.login.yahoo.com/oauth/v2/request_auth * oauth.accesstoken.url=https://api.login.yahoo.com/oauth/v2/get_token * oauth.callback.url=http://myapplication:8080/ * <p/> * To access production OAuth services from Yahoo. This filter relies on session * information stored by cookies to operate. * * @param filterConfig see upstream docs * @throws ServletException */ public void init(FilterConfig filterConfig) throws ServletException { String filename = filterConfig.getInitParameter("oauth"); if (filename == null) { filename = "oauth.properties"; } logger.debug("oauth properties file: {}", filename); oauthConfig = new Properties(); try { oauthConfig.load(getClass().getResourceAsStream("/" + filename)); } catch (IOException e) { throw new ServletException("Could not load oauth properties from resource: " + filename, e); } String redirectString = filterConfig.getInitParameter("redirect"); // defaults to redirect if null, zero-length redirect = redirectString == null || redirectString.trim().length() <= 0 || "true".equalsIgnoreCase(redirectString.trim()); logger.debug("redirect if access token not found: {}", redirect); String oauthConnectionClass = filterConfig.getInitParameter("oauthConnectionClass"); if (oauthConnectionClass == null) { oauthConnectionClass = "net.oauth.client.URLConnectionClient"; } logger.debug("oauth client connection class: {}", oauthConnectionClass); try { client = new OAuthClient((HttpClient) Class.forName(oauthConnectionClass).newInstance()); } catch (Exception cce) { throw new ServletException("unable to create OAuthClient from: " + oauthConnectionClass, cce); } provider = new OAuthServiceProvider( oauthConfig.getProperty("oauth.requesttoken.url", "https://api.login.yahoo.com/oauth/v2/get_request_token"), oauthConfig.getProperty("oauth.requestauth.url", "https://api.login.yahoo.com/oauth/v2/request_auth"), oauthConfig.getProperty("oauth.accesstoken.url", "https://api.login.yahoo.com/oauth/v2/get_token")); consumer = new OAuthConsumer(oauthConfig.getProperty("oauth.callback.url"), oauthConfig.getProperty("yos.consumerKey"), oauthConfig.getProperty("yos.consumerSecret"), provider); consumer.setProperty("oauth_signature_method", oauthConfig.getProperty("yos.oauth_signature_method", "HMAC-SHA1")); callbackUrl = oauthConfig.getProperty("oauth.callback.url", ""); }
From source file:com.sap.dirigible.runtime.content.ContentInitializerServlet.java
private void initRepository() throws ServletException { try {//from w w w. j a va 2s . co m final IRepository repository = RepositoryFacade.getInstance().getRepository(null); getServletContext().setAttribute(REPOSITORY_ATTRIBUTE, repository); } catch (Exception ex) { throw new ServletException(COULD_NOT_INITIALIZE_REPOSITORY, ex); } }
From source file:edu.cornell.mannlib.vitro.webapp.filters.StartupStatusDisplayFilter.java
private void displayStartupStatus(ServletRequest req, ServletResponse resp) throws IOException, ServletException { HttpServletResponse hresp = (HttpServletResponse) resp; HttpServletRequest hreq = (HttpServletRequest) req; try {//from w w w . jav a 2 s . co m Map<String, Object> bodyMap = new HashMap<String, Object>(); bodyMap.put("status", ss); bodyMap.put("showLink", !isFatal()); bodyMap.put("contextPath", getContextPath()); bodyMap.put("applicationName", getApplicationName()); String url = ""; String path = hreq.getRequestURI(); if (path != null) { url = path; } String query = hreq.getQueryString(); if (!StringUtils.isEmpty(query)) { url = url + "?" + query; } bodyMap.put("url", url); hresp.setContentType("text/html;charset=UTF-8"); hresp.setStatus(SC_INTERNAL_SERVER_ERROR); Template tpl = loadFreemarkerTemplate(); tpl.process(bodyMap, hresp.getWriter()); } catch (TemplateException e) { throw new ServletException("Problem with Freemarker Template", e); } }
From source file:org.apache.servicemix.http.HttpManagedServlet.java
protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { try {//from w w w . j a va 2 s. co m processor.process(request, response); } catch (IOException e) { throw e; } catch (ServletException e) { throw e; } catch (RuntimeException e) { throw e; } catch (Exception e) { throw new ServletException("Failed to process request: " + e, e); } }
From source file:ilarkesto.gwt.server.AUploadServlet.java
@Override public final void init(ServletConfig config) throws ServletException { super.init(config); try {/*w ww . j a v a 2 s . co m*/ webApplication = AWebApplication.get(); if (webApplication == null || webApplication.isStartupFailed()) throw new RuntimeException("Web application startup failed."); } catch (Throwable ex) { throw new ServletException(getClass().getSimpleName() + ".init(ServletConfig) failed.", ex); } }
From source file:fi.vm.kapa.identification.shibboleth.extauthn.ShibbolethExtAuthnHandlerError.java
@Override public void service(final HttpServletRequest httpRequest, final HttpServletResponse httpResponse) throws ServletException, IOException { try {/*from w w w .j a va2 s.c o m*/ final String key = httpRequest.getParameter("conversation"); if (StringUtils.isNotBlank(key)) { //Return to discovery page call from error page final String error = httpRequest.getParameter("e"); if (NO_CERT_FOUND.getCode().equals(error)) { httpRequest.setAttribute(ExternalAuthentication.AUTHENTICATION_ERROR_KEY, AuthnEventIds.NO_CREDENTIALS); } else if (CERT_REVOKED.getCode().equals(error) || CERT_TYPE_NOT_SUPPORTED.getCode().equals(error)) { httpRequest.setAttribute(ExternalAuthentication.AUTHENTICATION_ERROR_KEY, AuthnEventIds.INVALID_CREDENTIALS); } else { //Unknown error httpRequest.setAttribute(ExternalAuthentication.AUTHENTICATION_ERROR_KEY, AuthnEventIds.AUTHN_EXCEPTION); } ExternalAuthentication.finishExternalAuthentication(key, httpRequest, httpResponse); } } catch (final ExternalAuthenticationException e) { log.error("Error processing external authentication request"); throw new ServletException("Error processing external authentication request", e); } }
From source file:edu.emory.cci.aiw.cvrg.eureka.servlet.filter.HaveUserRecordFilter.java
@Override public void doFilter(ServletRequest inRequest, ServletResponse inResponse, FilterChain inFilterChain) throws IOException, ServletException { HttpServletRequest servletRequest = (HttpServletRequest) inRequest; HttpServletResponse servletResponse = (HttpServletResponse) inResponse; String remoteUser = servletRequest.getRemoteUser(); if (!StringUtils.isEmpty(remoteUser)) { try {//from w w w. j a v a 2 s.c om User user = this.servicesClient.getMe(); if (!user.isActive()) { HttpSession session = servletRequest.getSession(false); if (session != null) { session.invalidate(); } sendForbiddenError(servletResponse, servletRequest, true); } else { inRequest.setAttribute("user", user); inFilterChain.doFilter(inRequest, inResponse); } } catch (ClientException ex) { if (Status.FORBIDDEN.equals(ex.getResponseStatus())) { HttpSession session = servletRequest.getSession(false); if (session != null) { session.invalidate(); } sendForbiddenError(servletResponse, servletRequest, false); } else if (Status.UNAUTHORIZED.equals(ex.getResponseStatus())) { HttpSession session = servletRequest.getSession(false); if (session != null) { session.invalidate(); } servletResponse.sendRedirect(servletRequest.getContextPath() + "/logout?goHome=true"); } else { throw new ServletException("Error getting user " + servletRequest.getRemoteUser(), ex); } } } else { inFilterChain.doFilter(inRequest, inResponse); } }
From source file:de.mpg.escidoc.services.pidcache.web.MainServlet.java
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { logger.info("PID cache GET request"); try {/*from w ww.j a va 2 s.c o m*/ if (!authenticate(req, resp)) { logger.warn("Unauthorized request from " + req.getRemoteHost()); return; } PidCacheService pidCacheService = new PidCacheService(); if (GwdgPidService.GWDG_PIDSERVICE_VIEW.equals(req.getPathInfo()) || GwdgPidService.GWDG_PIDSERVICE_VIEW.concat("/").equals(req.getPathInfo())) { if (req.getParameter("pid") == null) { resp.sendError(HttpServletResponse.SC_NO_CONTENT, "PID parameter failed."); } resp.getWriter().append(pidCacheService.retrieve(req.getParameter("pid"))); } else if ("/cache/size".equals(req.getPathInfo())) { resp.getWriter().append("There are " + pidCacheService.getCacheSize() + " PID stored in cache"); } else if ("/queue/size".equals(req.getPathInfo())) { resp.getWriter().append("There are " + pidCacheService.getQueueSize() + " PID actually in queue"); } else { resp.sendError(HttpServletResponse.SC_NOT_FOUND, req.getPathInfo()); } } catch (Exception e) { throw new ServletException("Error processing request", e); } }