List of usage examples for javax.servlet ServletException ServletException
public ServletException(Throwable rootCause)
From source file:org.remus.marketplace.servlets.RecentListing.java
@Override public void handleRequest(HttpServletRequest arg0, HttpServletResponse arg1) throws ServletException, IOException { arg1.setContentType("text/xml"); try {/*from w w w . ja v a 2s. c o m*/ JAXBContext newInstance = JAXBContext.newInstance(Marketplace.class, org.remus.marketplace.xml.Market.class); Marketplace marketplace = new Marketplace(); List<Node> findByCategoriesId = nodeDao .find(new AdvancedCriteria().setMaxResults(10).addOrder(Order.desc(Node.CHANGED))); Recent recent = new Recent(); recent.setCount(findByCategoriesId.size()); for (Node findById : findByCategoriesId) { org.remus.marketplace.xml.Node node = XMLBuilder.buildNode(serverPrefix, findById); recent.getNode().add(node); } marketplace.setRecent(recent); Marshaller createMarshaller = newInstance.createMarshaller(); XMLSerializer xmlSerializer = XMLBuilder.getXMLSerializer(arg1.getOutputStream()); createMarshaller.marshal(marketplace, xmlSerializer.asContentHandler()); } catch (JAXBException e) { throw new ServletException(e); } }
From source file:de.betterform.agent.web.servlet.XSLTServlet.java
/** * This method is only called when non-scripted mode is used to update the UI. This basically exists to support * the PFG (POST/FORWARD/GET) pattern that allows to use the browser back button without POSTDATA warning from the browser * and to re-initialize the preceding form (if any). * <p/>// w w w . j a v a 2 s . c o m * To make sure that an update is requested from the XFormsSession and not by the user clicking the reload button the * XFormsSession holds a property XFormsSession.UPDATE_REQUEST when coming from XFormsSession. If this property exists, * the UI is refreshed otherwise the form is re-inited with a GET. * * @param request servlet request * @param response servlet response * @throws javax.servlet.ServletException * @throws java.io.IOException */ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { ServletContext servletContext = getServletContext(); String stylePath = null; try { stylePath = WebFactory.getRealPath(editorHome, servletContext); } catch (XFormsConfigException e) { throw new ServletException(e); } File styleFile = new File(stylePath, xslFile); if (styleFile == null) { throw new ServletException("XSL stylesheet cannot be found: " + styleFile); } String contentType = null; Document doc = null; String xsl = null; contentType = (String) request.getAttribute("contenttype"); if (contentType == null) contentType = defContentType; // The servlet returns HTML. response.setContentType(contentType); if (cache == null) cache = new HashMap(); Transformer t = null; // Get the XML input document and the stylesheet. // Source xmlSource = new DOMSource(doc); String inputFile = request.getPathTranslated(); File input = new File(inputFile); if (input == null) { throw new ServletException("XML document cannot be found: " + inputFile); } Source xmlSource = new StreamSource(new FileInputStream(input)); // Perform the transformation, sending the output to the response. // XSL processing can be time consuming, but this is mainly due to the overhead // of compiling the XSL sheet. // By caching the compiled sheets, the process is speeded up dramatically. // Time saved on subsequent requests can be 99% or more (hundreds of milliseconds). try { // check if the XSL sheet was found in cache, and use that if available // if (cache.containsKey(xsl)) t = (Transformer)cache.get(xsl); // else // { // otherwise, load the XSL sheet from disk, compile it and store the compiled // sheet in the cache TransformerFactory tFactory = TransformerFactory.newInstance(); Source xslSource = new StreamSource(new FileInputStream(styleFile)); t = tFactory.newTransformer(xslSource); String contextName = request.getContextPath(); t.setParameter("APP_CONTEXT", contextName); t.setParameter("EDITOR_HOME", stylePath.substring(stylePath.indexOf("/betterform/")) + "/"); t.setParameter("filename", "file://" + inputFile); // cache.put(xsl, t); // } // perform the XSL transformation of the XML Document into the servlet outputstream // t.transform(xmlSource, new StreamResult(out)); Document resultDoc = DOMUtil.newDocument(true, false); t.transform(xmlSource, new DOMResult(resultDoc)); request.setAttribute(WebFactory.XFORMS_NODE, resultDoc); } catch (TransformerConfigurationException e) { e.printStackTrace(); throw new ServletException(e); } catch (TransformerFactoryConfigurationError e) { e.printStackTrace(); throw new ServletException(e); } catch (TransformerException e) { e.printStackTrace(); throw new ServletException(e); } }
From source file:com.adobe.communities.ugc.migration.export.GenericExportServlet.java
@Override protected void doGet(final SlingHttpServletRequest request, final SlingHttpServletResponse response) throws ServletException, IOException { if (!request.getRequestParameterMap().containsKey("path")) { throw new ServletException("No path specified for export. Exiting."); }/*ww w .ja va 2 s .c o m*/ final String path = StringUtils.stripEnd(request.getRequestParameter("path").getString(), "/"); final Resource resource = request.getResourceResolver().getResource(path); if (resource == null) { throw new ServletException("Could not find a valid resource for export"); } File outFile = null; try { outFile = File.createTempFile(UUID.randomUUID().toString(), ".zip"); if (!outFile.canWrite()) { throw new ServletException("Cannot write to specified output file"); } response.setContentType("application/octet-stream"); final String headerKey = "Content-Disposition"; final String headerValue = "attachment; filename=\"export.zip\""; response.setHeader(headerKey, headerValue); FileOutputStream fos = new FileOutputStream(outFile); BufferedOutputStream bos = new BufferedOutputStream(fos); zip = new ZipOutputStream(bos); OutputStream outStream = null; InputStream inStream = null; try { exportContent(resource, path); IOUtils.closeQuietly(zip); IOUtils.closeQuietly(bos); IOUtils.closeQuietly(fos); // obtains response's output stream outStream = response.getOutputStream(); inStream = new FileInputStream(outFile); // copy from file to output IOUtils.copy(inStream, outStream); } catch (final IOException e) { throw new ServletException(e); } catch (final Exception e) { throw new ServletException(e); } finally { IOUtils.closeQuietly(zip); IOUtils.closeQuietly(bos); IOUtils.closeQuietly(fos); IOUtils.closeQuietly(inStream); IOUtils.closeQuietly(outStream); } } finally { if (outFile != null) { outFile.delete(); } } }
From source file:com.hphoto.server.ApiServlet.java
public void init(ServletConfig config) throws ServletException { if (server != null) { return;//from w w w . j a va 2 s . c o m } try { ServletContext context = config.getServletContext(); this.server = (TableServer) context.getAttribute("hphoto.tableServer"); this.conf = (Configuration) context.getAttribute("hphoto.conf"); } catch (Exception e) { throw new ServletException(e); } }
From source file:ch.admin.suis.msghandler.servlet.TriggerServlet.java
/** * {@inheritDoc }//w w w .jav a2s . co m */ @Override public void init(ServletConfig config) throws ServletException { super.init(config); try { scheduler = mhContext.getSchedulerFactory().getScheduler(); } catch (SchedulerException e) { LOG.fatal("cannot initialize the scheduler for the trigger servlet", e); throw new ServletException(e); } }
From source file:com.legstar.c2ws.servlet.C2wsProxy.java
/** {@inheritDoc} */ @SuppressWarnings("unchecked") public void init(final ServletConfig config) throws ServletException { super.init(config); if (LOG.isDebugEnabled()) { LOG.debug("Initializing "); }// ww w .j a v a 2 s. c om Map<String, String> proxyConfig = new HashMap<String, String>(); Enumeration<String> en = getServletConfig().getInitParameterNames(); while (en.hasMoreElements()) { setInitParameter(proxyConfig, en.nextElement(), null); } try { _serviceProxy = new ServiceProxy(proxyConfig); } catch (ProxyConfigurationException e) { throw new ServletException(e); } }
From source file:com.example.getstarted.util.CloudStorageHelper.java
/** * Checks that the file extension is supported. *//*from w w w .ja va 2 s . c o m*/ private void checkFileExtension(String fileName) throws ServletException { if (fileName != null && !fileName.isEmpty() && fileName.contains(".")) { String[] allowedExt = { ".jpg", ".jpeg", ".png", ".gif" }; for (String ext : allowedExt) { if (fileName.endsWith(ext)) { return; } } throw new ServletException("file must be an image"); } }
From source file:com.adobe.communities.ugc.migration.legacyExport.GenericExportServlet.java
@Override protected void doGet(final SlingHttpServletRequest request, final SlingHttpServletResponse response) throws ServletException, IOException { if (!request.getRequestParameterMap().containsKey("path")) { throw new ServletException("No path specified for export. Exiting."); }/*from w ww. j av a2 s. c o m*/ final String path = StringUtils.stripEnd(request.getRequestParameter("path").getString(), "/"); final Resource resource = request.getResourceResolver().getResource(path); if (resource == null) { throw new ServletException("Could not find a valid resource for export"); } entries = new HashMap<String, Boolean>(); entriesToSkip = new HashMap<String, Boolean>(); File outFile = null; try { outFile = File.createTempFile(UUID.randomUUID().toString(), ".zip"); if (!outFile.canWrite()) { throw new ServletException("Cannot write to specified output file"); } response.setContentType("application/octet-stream"); final String headerKey = "Content-Disposition"; final String headerValue = "attachment; filename=\"export.zip\""; response.setHeader(headerKey, headerValue); FileOutputStream fos = new FileOutputStream(outFile); BufferedOutputStream bos = new BufferedOutputStream(fos); zip = new ZipOutputStream(bos); OutputStream outStream = null; InputStream inStream = null; try { exportContent(resource, path); if (entries.size() > 0) { exportCommentSystems(entries, entriesToSkip, resource, path); } IOUtils.closeQuietly(zip); IOUtils.closeQuietly(bos); IOUtils.closeQuietly(fos); // obtains response's output stream outStream = response.getOutputStream(); inStream = new FileInputStream(outFile); // copy from file to output IOUtils.copy(inStream, outStream); } catch (final IOException e) { throw new ServletException(e); } catch (final Exception e) { throw new ServletException(e); } finally { IOUtils.closeQuietly(zip); IOUtils.closeQuietly(bos); IOUtils.closeQuietly(fos); IOUtils.closeQuietly(inStream); IOUtils.closeQuietly(outStream); } } finally { if (outFile != null) { outFile.delete(); } } }
From source file:maimai.app.cas.sso.AuthenticationFilter.java
protected void initInternal(final FilterConfig filterConfig) throws ServletException { if (!isIgnoreInitConfiguration()) { super.initInternal(filterConfig); setCasServerLoginUrl(getPropertyFromInitParams(filterConfig, "casServerLoginUrl", null)); log.trace("Loaded CasServerLoginUrl parameter: " + this.casServerLoginUrl); setRenew(parseBoolean(getPropertyFromInitParams(filterConfig, "renew", "false"))); log.trace("Loaded renew parameter: " + this.renew); setGateway(parseBoolean(getPropertyFromInitParams(filterConfig, "gateway", "false"))); log.trace("Loaded gateway parameter: " + this.gateway); final String gatewayStorageClass = getPropertyFromInitParams(filterConfig, "gatewayStorageClass", null); if (gatewayStorageClass != null) { try { this.gatewayStorage = (GatewayResolver) Class.forName(gatewayStorageClass).newInstance(); } catch (final Exception e) { log.error(e, e);/* w w w . j a v a 2 s . c o m*/ throw new ServletException(e); } } } }
From source file:com.aliasi.demo.framework.DemoServlet.java
/** * Initialize the demo servlet. This is the initialization * called by the servlet container. It constructs the * demo using reflection given the parameters. *//*from w w w . ja v a 2 s . c o m*/ public void init() throws ServletException { String demoClass = getInitParameter("demoConstructor"); String demoConstructorArgs = getInitParameter("demoConstructorArgs"); try { mDemo = Constants.constructDemo(demoClass, demoConstructorArgs); } catch (IllegalArgumentException e) { String msg = "Error constructing demo=" + e; throw new ServletException(e); } catch (ClassCastException e) { String msg = "Could not convert class=" + demoClass + " to instance of StreamDemo."; throw new ServletException(e); } }