List of usage examples for javax.servlet ServletException ServletException
public ServletException(Throwable rootCause)
From source file:de.mpg.escidoc.services.fledgeddata.webservice.oaiServlet.java
/** * init is called one time when the Servlet is loaded. This is the * place where one-time initialization is done. Specifically, we * load the properties file for this application. * * @param config servlet configuration information * @exception ServletException there was a problem with initialization *//*w w w . j a v a 2 s . co m*/ public void init(ServletConfig config) throws ServletException { super.init(config); try { LOGGER.info("[FDS] Initialize oai servlet."); this.properties = OAIUtil.loadProperties(); } catch (FileNotFoundException e) { e.printStackTrace(); throw new ServletException(e.getMessage()); } catch (Throwable e) { e.printStackTrace(); throw new ServletException(e.getMessage()); } }
From source file:com.sun.socialsite.web.rest.servlets.GroupImageServlet.java
protected Result getResult(String itemName) throws IOException, ServletException { Group group;/*from ww w . j a v a 2 s . com*/ try { GroupManager mgr = Factory.getSocialSite().getGroupManager(); group = mgr.getGroupByHandle(itemName); } catch (SocialSiteException e) { throw new ServletException(e); } if (group == null) { throw new ServletException("no item found for display"); } return new Result(group.getUpdated(), group.getImageType(), (byte[]) (group.getImage())); }
From source file:com.doculibre.constellio.filters.LocalRequestFilter.java
@Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { Set<String> acceptedAndDynamicHosts = new HashSet<String>(); acceptedAndDynamicHosts.addAll(Arrays.asList(ACCEPTED_HOSTS)); // Solution adapted from http://www.exampledepot.com/egs/java.net/Local.html String hostName = InetAddress.getLocalHost().getHostName(); InetAddress addrs[] = InetAddress.getAllByName(hostName); for (InetAddress addr : addrs) { String hostAddress = addr.getHostAddress(); acceptedAndDynamicHosts.add(hostAddress); }//from w w w . j a v a 2 s. c o m boolean valid; if (isIgnoredRequest(request) || isFileRequest(request)) { valid = true; } else { valid = false; String remoteHost = request.getRemoteHost(); for (String acceptedHost : acceptedAndDynamicHosts) { if (remoteHost.equals(acceptedHost)) { valid = true; } } } if (valid) { // Pass control on to the next filter chain.doFilter(request, response); } else { HttpServletRequest httpRequest = (HttpServletRequest) request; throw new ServletException("Cannot send request to a servlet from outside the Web application : " + httpRequest.getRequestURL()); } }
From source file:net.nicoulaj.benchmark.mockwebapp.MockWebAppServlet.java
/** * Initialize the servlet./* w w w . j a v a 2s . com*/ * <p/> * Loads the {@link #mockWebAppConfig} by looking up the {@link #MOCK_WEB_APP_CONF_PROPERTY} as a system property or init parameter, * and sets up a listener on the file changes. * * @param config the {@link ServletConfig}, optionally with a {@link #MOCK_WEB_APP_CONF_PROPERTY} parameter. * @throws ServletException if the {@link #MOCK_WEB_APP_CONF_PROPERTY} was neither defined as a system property nor an init parameter. */ @Override public void init(ServletConfig config) throws ServletException { super.init(config); // Locate the config file parameter. String configFilePath = System.getProperty(MOCK_WEB_APP_CONF_PROPERTY); if (configFilePath == null) configFilePath = config.getInitParameter(MOCK_WEB_APP_CONF_PROPERTY); if (configFilePath == null) throw new ServletException("No mock web app config file defined. Please define one using the '" + MOCK_WEB_APP_CONF_PROPERTY + "' system property or servlet init parameter."); // Setup the config file changes listener. try { fileMonitor = new DefaultFileMonitor(new ConfigFileListener()); fileMonitor.addFile(VFS.getManager().resolveFile(new File("."), configFilePath)); fileMonitor.start(); } catch (Exception e) { getServletContext().log( "Failed setting up config file changes listener, config file changes will not be taken into account", e); } // Load the config from the file. final File configFile = new File(configFilePath); try { mockWebAppConfig = MockWebAppConfig.Parser.parseConfig(configFile); getServletContext().log("Loaded config file " + configFilePath); } catch (Exception e) { getServletContext().log("Failed loading config, please replace it with a valid one", e); } }
From source file:edu.lternet.pasta.datapackagemanager.dataserver.DataServerServlet.java
/** * Process a data download HEAD request using information that was generated * by the Data Package Manager service.// w w w. j ava2 s.c om */ protected void doHead(HttpServletRequest request, HttpServletResponse response) throws ServletException { String dataToken = request.getParameter("dataToken"); String size = request.getParameter("size"); String objectName = request.getParameter("objectName"); if (dataToken == null || dataToken.isEmpty() || size == null || size.isEmpty() || objectName == null || objectName.isEmpty()) { response.setStatus(HttpServletResponse.SC_BAD_REQUEST); } else { /* * Find out which directory the temporary data files are being * placed in by the Data Package Manager */ PropertiesConfiguration options = ConfigurationListener.getOptions(); String tmpDir = options.getString("datapackagemanager.tmpDir"); if (tmpDir == null || tmpDir.equals("")) { throw new ServletException("datapackagemanager.tmpDir property value was not specified."); } try { // reads input file from an absolute path String filePath = String.format("%s/%s", tmpDir, dataToken); File downloadFile = new File(filePath); if (!downloadFile.exists()) { String message = String.format("File not found: %s", filePath); throw new FileNotFoundException(message); } ServletContext context = getServletContext(); // gets MIME type of the file String mimeType = context.getMimeType(filePath); if (mimeType == null) { // set to binary type if MIME mapping not found mimeType = "application/octet-stream"; } // modifies response response.setContentType(mimeType); long length = Long.parseLong(size); if (length <= Integer.MAX_VALUE) { response.setContentLength((int) length); } else { response.addHeader("Content-Length", Long.toString(length)); } // forces download String headerKey = "Content-Disposition"; String headerValue = String.format("attachment; filename=\"%s\"", objectName); response.setHeader(headerKey, headerValue); } catch (FileNotFoundException e) { logger.error(e.getMessage()); e.printStackTrace(); response.setStatus(HttpServletResponse.SC_NOT_FOUND); } } }
From source file:de.berlios.jedi.presentation.admin.PrepareAdminSessionFilter.java
/** * Checks if the session has the needed attributes for the admin actions.<br> * If the session hasn't those attributes, it forwards to the * PrepareAdminSessionAction, using the name of the intercepted Action as * the value of the NEXT_FORWARD_NAME key.<br> * If the session already has those attributes, the next element in the * chain is invoked.// ww w . j a v a 2s. c o m * * @throws IOException * If an IOException occurs when filtering. * @throws ServletException * If a ServletException occurs when filtering. * * @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 PrepareAdminSessionFilter" + "isn't a HttpServletRequest"); throw new ServletException( "Unexpected error: request in PrepareAdminSessionFilter" + "isn't a HttpServletRequest"); } HttpServletRequest httpRequest = (HttpServletRequest) request; JispPackagesList jispPackagesList = (JispPackagesList) httpRequest.getSession() .getAttribute(AdminKeys.JISP_PACKAGES_LIST_KEY); JispIdManager jispIdManager = (JispIdManager) httpRequest.getSession() .getAttribute(AdminKeys.JISP_ID_MANAGER_KEY); try { if (jispPackagesList == null || jispIdManager == null) { httpRequest.setAttribute(Keys.NEXT_FORWARD_NAME, httpRequest.getServletPath()); httpRequest.getSession().getServletContext().getRequestDispatcher("/Admin/PrepareAdminSession.do") .forward(request, response); return; } chain.doFilter(request, response); } catch (IOException e) { LogFactory.getLog(LoginFilter.class).error("IOException in PrepareAdminSessionFilter", e); throw e; } catch (ServletException e) { LogFactory.getLog(LoginFilter.class).error("ServletException in PrepareAdminSessionFilter", e); throw e; } }
From source file:com.adeptj.modules.jaxrs.resteasy.internal.ResteasyProviderFactoryAdapter.java
ResteasyProviderFactoryAdapter(String[] blacklistedProviders) throws ServletException { this.blacklistedProviders = blacklistedProviders; this.providers = new CopyOnWriteArraySet<>(); // 27.03.2019 - Using reflection as the field is made private in 4.0.0.RC1, it was protected earlier. try {//from www . j a v a 2s. com FieldUtils.writeField(this, FIELD_PROVIDER_INSTANCES, this.providers, true); } catch (IllegalAccessException iae) { throw new ServletException(iae); } }
From source file:com.knowbout.hibernate.OpenSessionInViewFilter.java
/** * /*from ww w . j a v a2 s. c o m*/ * @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 { HibernateUtil.openSession(); try { chain.doFilter(request, response); } catch (ServletException se) { String message = se.toString(); if (se.getRootCause() != null) { message = se.getRootCause().toString(); } if (printFullExceptions) { if (se.getRootCause() != null) { log.error(message, se.getRootCause()); } else { log.error(message, se); } } else { log.error(message); } throw se; } catch (Throwable t) { if (printFullExceptions) { log.error(t.getMessage(), t); } else { log.error(t.toString()); } throw new ServletException(t); } finally { HibernateUtil.closeSession(); } }
From source file:info.magnolia.services.httputils.filters.InternalProxyFilter.java
@Override public void doFilter(HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws IOException, ServletException { String[] requestedUrl = request.getRequestURI().split("/", 4); if (!requestedUrl[1].equals(FILTER_CONTEXT)) throw new ServletException( "Requested url does not have the right context, please check the configuration of the filter."); if (StringUtils.isBlank(requestedUrl[2])) throw new ServletException("Service name is missing."); if (StringUtils.isBlank(requestedUrl[3])) throw new ServletException("No resources specified in the url"); // calculate internal url String service = requestedUrl[2]; String resource = requestedUrl[3]; WebTarget target = null;/*from w ww. j a v a2 s . c o m*/ //this.client.target("http://192.168.99.100:3004/").path(resource); // add query string String queryString = request.getQueryString(); if (StringUtils.isNotBlank(queryString)) target = target.path(queryString); // set content type String contentType = request.getContentType(); Invocation.Builder requestBuilder; if (StringUtils.isNotBlank(contentType)) requestBuilder = target.request(contentType); else requestBuilder = target.request(); // copy the original request body to the internal one StringBuilder internalBodyReq = new StringBuilder(); BufferedReader reader = request.getReader(); try { String line; while ((line = reader.readLine()) != null) { internalBodyReq.append(line); } } finally { reader.close(); } Response internalResp = null; // actually do the call based on the method String method = request.getMethod(); switch (method) { case "GET": internalResp = requestBuilder.get(); break; case "POST": internalResp = requestBuilder.post(Entity.entity(internalBodyReq, contentType)); break; case "PUT": internalResp = requestBuilder.put(Entity.entity(internalBodyReq, contentType)); break; case "DELETE": internalResp = requestBuilder.delete(); break; default: log.error("HTTP method not supported: " + method); break; } response.setStatus(internalResp.getStatus()); response.setContentType(internalResp.getMediaType().toString()); response.getOutputStream().print(internalResp.readEntity(String.class)); }
From source file:com.sdl.odata.controller.AbstractODataController.java
@RequestMapping(method = { GET, POST, PATCH, PUT, DELETE }) protected void service(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws ServletException, IOException { if (LOG.isTraceEnabled()) { LOG.trace("Start processing request from: {}", servletRequest.getRemoteAddr()); }//from w w w . j av a 2 s.c o m ODataResponse oDataResponse; try { ODataRequest oDataRequest = buildODataRequest(servletRequest); doWireLogging(oDataRequest); oDataResponse = oDataService.handleRequest(oDataRequest); } catch (ODataException e) { throw new ServletException(e); } fillServletResponse(oDataResponse, servletResponse); if (LOG.isTraceEnabled()) { LOG.trace("Finished processing request from: {}", servletRequest.getRemoteAddr()); } }