List of usage examples for javax.servlet ServletException ServletException
public ServletException(Throwable rootCause)
From source file:EmailJndiServlet.java
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, java.io.IOException { response.setContentType("text/html"); java.io.PrintWriter out = response.getWriter(); out.println("<html><head><title>Email message sender</title></head><body>"); String to = request.getParameter("to"); String from = request.getParameter("from"); String subject = request.getParameter("subject"); String emailContent = request.getParameter("emailContent"); try {//from w w w . j ava2s .com sendMessage(to, from, subject, emailContent); } catch (Exception exc) { throw new ServletException(exc.getMessage()); } out.println("<h2>The message was sent successfully</h2></body></html>"); out.println("</body></html>"); out.close(); }
From source file:org.geowebcache.proxy.ProxyDispatcher.java
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { String methStr = request.getMethod(); if (!methStr.equalsIgnoreCase("POST")) { throw new ServletException("Illegal method " + methStr + " for this proxy."); }// w ww. ja va 2 s.c o m String urlStr = request.getParameter("url"); if (urlStr == null || urlStr.length() == 0 || !urlStr.startsWith("http://")) { throw new ServletException("Expected url parameter."); } synchronized (this) { long time = System.currentTimeMillis(); if (time - lastRequest < 1000) { throw new ServletException("Only one request per second please."); } else { lastRequest = time; } } log.info("Proxying request for " + request.getRemoteAddr() + " to " + " " + urlStr); String charEnc = request.getCharacterEncoding(); if (charEnc == null) { charEnc = "UTF-8"; } String decodedUrl = URLDecoder.decode(urlStr, charEnc); URL url = new URL(decodedUrl); HttpURLConnection wmsBackendCon = (HttpURLConnection) url.openConnection(); if (wmsBackendCon.getContentEncoding() != null) { response.setCharacterEncoding(wmsBackendCon.getContentEncoding()); } response.setContentType(wmsBackendCon.getContentType()); int read = 0; byte[] data = new byte[1024]; while (read > -1) { read = wmsBackendCon.getInputStream().read(data); if (read > -1) { response.getOutputStream().write(data, 0, read); } } return null; }
From source file:com.google.gwt.site.webapp.server.resources.HashServlet.java
@Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { int count;// www.j a v a 2 s.co m try { count = Integer.parseInt(req.getParameter("count")); } catch (NumberFormatException e) { throw new ServletException(e); } if (count < 0) { throw new ServletException("invalid value count " + count); } JSONObject root = new JSONObject(); DatastoreService ds = DatastoreServiceFactory.getDatastoreService(); PreparedQuery pq = ds.prepare(new Query("DocHash")); List<Entity> asList = pq.asList(FetchOptions.Builder.withOffset(count).limit(1000)); JSONArray array = new JSONArray(); try { root.put("hashes", array); for (Entity entity : asList) { count++; String key = entity.getKey().getName(); String hash = (String) entity.getProperty("hash"); JSONObject docHash = new JSONObject(); docHash.put("key", key); docHash.put("hash", hash); array.put(docHash); } resp.getWriter().write(root.toString()); } catch (JSONException e) { throw new ServletException(e); } }
From source file:com.collective.celos.servlet.RegisterServlet.java
protected void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException { try {//from w w w.j a va 2 s. co m BucketID bucket = getRequestBucketID(req); RegisterKey key = getRequestKey(req); try (StateDatabaseConnection connection = getStateDatabase().openConnection()) { JsonNode value = connection.getRegister(bucket, key); if (value == null) { res.sendError(HttpServletResponse.SC_NOT_FOUND, "Register not found"); } else { writer.writeValue(res.getOutputStream(), value); } } } catch (Exception e) { throw new ServletException(e); } }
From source file:com.cpjit.swagger4j.support.servlet.ApiServlet.java
@Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { String uri = req.getRequestURI(); if (uri.matches(".*/api/index(/?)(!/)*")) { toIndex(req, resp);//from w w w. j a va2 s.c om } else if (uri.matches(".*/api/statics/.+")) { queryStatic(req, resp); } else { try { queryApi(req, resp); } catch (Exception e) { throw new ServletException(e); } } }
From source file:com.granule.CompressorHandler.java
public void handle(HttpServletRequest request, HttpServletResponse response, String id) throws IOException, ServletException { if (id != null) { CompressorSettings settings = TagCacheFactory .getCompressorSettings(request.getSession().getServletContext().getRealPath("/")); CachedBundle bundle;/*from www . j av a2 s . c o m*/ try { bundle = TagCacheFactory.getInstance().getCompiledBundle(new RealRequestProxy(request), settings, id); } catch (JSCompileException e) { throw new ServletException(e); } if (bundle == null) { response.setStatus(404); return; } response.setHeader("Content-Type", bundle.getMimeType() + "; charset=utf-8"); response.setHeader("ETag", DigestUtils.md5Hex(bundle.getBundleValue())); HttpHeaders.setCacheExpireDate(response, 6048000); OutputStream os = response.getOutputStream(); try { if (settings.isGzipOutput() && gzipSupported(request)) { response.setHeader("Content-Encoding", "gzip"); os.write(bundle.getBundleValue()); } else { bundle.getUncompressedScript(os); } os.flush(); } finally { os.close(); } } }
From source file:edu.mayo.cts2.framework.webapp.rest.osgi.ProxyServlet.java
@Override public void init(ServletConfig config) throws ServletException { super.init(config); Assert.notNull(config.getServletContext()); try {/*from w w w . j a v a 2 s . c om*/ doInit(config); } catch (ServletException e) { throw e; } catch (Exception e) { throw new ServletException(e); } }
From source file:net.testdriven.psiprobe.ProbeServlet.java
@Override public void init(ServletConfig config) throws ServletException { super.init(config); if (wrapper != null) { getContainerWrapperBean().setWrapper(wrapper); } else {/* w w w . j ava 2 s. c om*/ throw new ServletException("Wrapper is null"); } }
From source file:org.examproject.websocket.SpringWebSocketServlet.java
@Override public void init() throws ServletException { try {/*w w w. ja v a 2s. c o m*/ // trying to load the Spring context file. // it's declared in Servlet web.xml. ServletConfig sc = getServletConfig(); String configLocation = sc.getInitParameter("contextConfigLocation"); context = new FileSystemXmlApplicationContext( getServletContext().getRealPath("/") + "/" + configLocation); // must call the superclass init method. super.init(); } catch (ServletException se) { throw se; } catch (Exception e) { throw new ServletException(e); } }
From source file:nl.flotsam.calendar.web.CalendarIcalView.java
@Override protected void renderMergedOutputModel(Map<String, Object> model, HttpServletRequest request, HttpServletResponse response) throws Exception { Calendar calendar = getCalendarToBeRendered(model); if (calendar == null) { throw new ServletException("Failed to locate Calendar to be rendered."); }// w w w . j ava 2s . c om response.setContentType("text/calendar"); // TODO: We can leverage data from the Calendar here response.setHeader("Cache-Control", "no-cache"); response.setCharacterEncoding("UTF-8"); Writer writer = response.getWriter(); calendar.toIcal(writer); writer.flush(); }