List of usage examples for javax.servlet ServletException ServletException
public ServletException(String message, Throwable rootCause)
From source file:com.boazlev.fnf.web.IndexerServlet.java
@Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/xml;charset=UTF-8"); PrintWriter out = response.getWriter(); out.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); out.println("<?xml-stylesheet type=\"text/xsl\" href=\"out.xslt\"?>"); out.println("<catalog>"); DiskFileItemFactory factory = new DiskFileItemFactory(); ServletFileUpload fileUpload = new ServletFileUpload(factory); try {/*from www. ja v a 2 s. c o m*/ FileItemIterator iterator = fileUpload.getItemIterator(request); while (iterator.hasNext()) { FileItemStream item = iterator.next(); InputStream mathMLContent = item.openStream(); if (!item.isFormField()) { Map<String, Integer> index = indexer.index(mathMLContent, "./lines.txt"); for (Map.Entry<String, Integer> mapEntry : index.entrySet()) { out.println("<cd>"); out.print("<index>"); out.print(mapEntry.getKey()); out.println("</index>"); out.print("<count>"); out.print(mapEntry.getValue()); out.println("</count>"); out.println("</cd>"); } } } } catch (FileUploadException e) { throw new ServletException("Cannot parse multipart request.", e); } out.print("</catalog>"); }
From source file:be.fedict.eid.dss.webapp.DocumentViewerServlet.java
private void handleDownloadRequest(String resourceId, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { LOG.debug("handle download: " + resourceId); HttpSession httpSession = request.getSession(); DocumentRepository documentRepository = new DocumentRepository(httpSession); String contentType = documentRepository.getDocumentContentType(); if (null == contentType) { response.setContentType("text/plain"); PrintWriter printWriter = response.getWriter(); printWriter.println("No document to be signed."); return;//w ww . ja v a 2 s.c om } byte[] documentData = documentRepository.getDocument(); DSSDocumentService documentService = super.findDocumentService(contentType); if (null != documentService) { DocumentVisualization documentVisualization; try { documentVisualization = documentService.findDocument(documentData, resourceId); } catch (Exception e) { throw new ServletException("error finding the document: " + e.getMessage(), e); } if (null != documentVisualization) { contentType = documentVisualization.getBrowserContentType(); documentData = documentVisualization.getBrowserData(); } } setResponseHeaders(request, response); response.setContentType(contentType); response.setContentLength(documentData.length); ServletOutputStream out = response.getOutputStream(); out.write(documentData); out.flush(); }
From source file:com.marvelution.gadgets.sonar.servlet.SonarMakeRequestServlet.java
/** * {@inheritDoc}/*from ww w . j a v a2s. c o m*/ */ @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { String requestUrl = req.getParameter("url"); String requestType = req.getParameter("type"); if (StringUtils.isNotBlank(requestUrl)) { logger.debug("Got a makeRequest request for " + requestUrl); try { URI uri = new URI(requestUrl); Sonar sonar = new Sonar(new HttpClient4Connector(getHost(uri))); String json = sonar.getConnector().execute(new QueryWrapper(uri)); resp.setCharacterEncoding("UTF-8"); if (StringUtils.isBlank(requestType) || "json".equalsIgnoreCase(requestType)) { resp.setContentType(MediaType.APPLICATION_JSON); } else { resp.setContentType(MediaType.APPLICATION_XML); } resp.getWriter().write(json); resp.getWriter().flush(); } catch (ConnectionException e) { throw new ServletException( "Failed to execute query. Please verify the correctness of the query and " + "that the Sonar server is up.", e); } catch (URISyntaxException e) { throw new ServletException("Invalid query url specified", e); } } }
From source file:com.huateng.ebank.framework.web.struts.ActionExceptionHandler.java
/** * This method handles any java.lang.Exceptions that are not caught in * previous classes. It will loop through and get all the causes (exception * chain), create ActionErrors, add them to the request and then forward to * the input.//from www . j a v a2 s . co m * * @see org.apache.struts.action.ExceptionHandler#execute ( * java.lang.Exception, org.apache.struts.config.ExceptionConfig, * org.apache.struts.action.ActionMapping, * org.apache.struts.action.ActionForm, * javax.servlet.http.HttpServletRequest, * javax.servlet.http.HttpServletResponse ) */ @Override public ActionForward execute(Exception ex, ExceptionConfig ae, ActionMapping mapping, ActionForm formInstance, HttpServletRequest request, HttpServletResponse response) throws ServletException { ActionForward forward = super.execute(ex, ae, mapping, formInstance, request, response); // log the exception to the default logger //ex.printStackTrace(); //log.error("",ex); String msg = convertErrorMessage(ex); throw new ServletException(msg, ex); }
From source file:ldap.LdapClient.java
public LdapClient() throws Exception { try {//from ww w.j a v a 2 s . c om resources = ResourceBundle.getBundle("ldap/LdapClient", SessionManager.getSession().getLocale()); } catch (MissingResourceException e) { throw new ServletException("resource bundle not found", e); } frame = new SFrame("LDAP Client"); SContainer contentPane = frame.getContentPane(); tabbedPane = new STabbedPane(); contentPane.setLayout(null); settingsForm = new SForm(new SGridLayout(2)); tabbedPane.add(settingsForm, resources.getString("provider")); urlTextField = new STextField(); urlTextField.setColumns(columns); urlTextField.setText((String) SessionManager.getSession().getProperty("java.naming.provider.url")); settingsForm.add(new SLabel(resources.getString("provider.url"))); settingsForm.add(urlTextField); basednTextField = new STextField(); basednTextField.setColumns(columns); basednTextField.setText((String) SessionManager.getSession().getProperty("java.naming.provider.basedn")); settingsForm.add(new SLabel(resources.getString("provider.basedn"))); settingsForm.add(basednTextField); binddnTextField = new STextField(); binddnTextField.setColumns(columns); binddnTextField.setText((String) SessionManager.getSession().getProperty("java.naming.security.principal")); settingsForm.add(new SLabel(resources.getString("provider.binddn"))); settingsForm.add(binddnTextField); passwordTextField = new SPasswordField(); passwordTextField.setColumns(columns); passwordTextField .setText((String) SessionManager.getSession().getProperty("java.naming.security.credentials")); settingsForm.add(new SLabel(resources.getString("provider.password"))); settingsForm.add(passwordTextField); connectButton = new SButton(resources.getString("provider.connect")); disconnectButton = new SButton(resources.getString("provider.disconnect")); disconnectButton.setVisible(false); settingsForm.add(connectButton); settingsForm.add(disconnectButton); mainPanel = new SPanel(); try { mainPanel.setLayout(new STemplateLayout(getClass().getResource("ldapclientlayout.html"))); } catch (Exception e) { logger.warn("no template", e); mainPanel.setLayout(new SFlowLayout()); } tabbedPane.add(mainPanel, resources.getString("browser")); createTreeModel(null); tree = new STree(treeModel); tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); tree.addTreeSelectionListener(this); SessionManager.getSession().setProperty("tree", tree); editPanel = new EditObjectPanel(); mainPanel.add(tree, "tree"); mainPanel.add(editPanel, "editor"); addPanel = new AddObjectPanel(); tabbedPane.add(addPanel, resources.getString("add")); contentPane.add(tabbedPane); connectButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { Session session = SessionManager.getSession(); String url = urlTextField.getText(); if (url != null && url.length() > 0) session.setProperty("java.naming.provider.url", url); String basedn = basednTextField.getText(); if (basedn != null && basedn.length() > 0) session.setProperty("java.naming.provider.basedn", basedn); String binddn = binddnTextField.getText(); if (binddn != null && binddn.length() > 0) session.setProperty("java.naming.security.principal", binddn); String password = passwordTextField.getText(); if (password != null && password.length() > 0) session.setProperty("java.naming.security.credentials", password); try { context = new InitialDirContext(new Hashtable(session.getProperties())); createTreeModel(context); tree.setModel(treeModel); tabbedPane.setSelectedIndex(1); urlTextField.setVisible(true); basednTextField.setVisible(true); binddnTextField.setVisible(true); passwordTextField.setVisible(true); connectButton.setVisible(true); disconnectButton.setVisible(false); passwordTextField.setText(null); } catch (NamingException e) { passwordTextField.setText(null); logger.warn("no initial context", e); } } }); disconnectButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { createTreeModel(null); tree.setModel(treeModel); urlTextField.setVisible(false); basednTextField.setVisible(false); binddnTextField.setVisible(false); passwordTextField.setVisible(false); connectButton.setVisible(false); disconnectButton.setVisible(true); passwordTextField.setText(null); } }); frame.show(); }
From source file:org.echocat.jemoni.jmx.support.SpringUtils.java
@Nonnull public static Object getApplicationContext(@Nonnull ServletContext servletContext) throws ServletException { assertSpringAvailable();//w ww.j a v a 2 s. co m final Object applicationContext; try { applicationContext = GET_WEB_APPLICATION_CONTEXT.invoke(null, servletContext); } catch (Exception e) { final Throwable target = e instanceof InvocationTargetException ? ((InvocationTargetException) e).getTargetException() : null; throw new ServletException("Could not retrieve spring context from " + servletContext + ".", target != null ? target : e); } if (applicationContext == null) { throw new ServletException("Could not find a spring context."); } return applicationContext; }
From source file:org.zilverline.web.IndexDefaultsController.java
/** Method updates an existing CollectionManager. */ /*//w ww . j a v a 2 s. co m * (non-Javadoc) * * @see org.springframework.web.servlet.mvc.SimpleFormController#onSubmit(javax.servlet.http.HttpServletRequest, * javax.servlet.http.HttpServletResponse, java.lang.Object, org.springframework.validation.BindException) */ protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object command, BindException errors) throws ServletException { try { collectionManager.store(); } catch (IndexException e) { throw new ServletException("Error storing new Index Defaults", e); } return new ModelAndView(getSuccessView()); }
From source file:de.ingrid.interfaces.csw.server.CSWServlet.java
/** * @see javax.servlet.http.HttpServlet#doGet(javax.servlet.http.HttpServletRequest, * javax.servlet.http.HttpServletResponse) *//* ww w . j a va2s . co m*/ @Override public final void doGet(final HttpServletRequest request, final HttpServletResponse response) throws ServletException { if (this.serverFacade == null) { throw new RuntimeException("CSWServlet is not configured properly: serverFacade is not set."); } try { this.serverFacade.handleGetRequest(request, response); } catch (Exception ex) { throw new ServletException("GET failed: " + ex.getMessage(), ex); } }
From source file:com.consol.citrus.simulator.servlet.AbstractSimulatorServlet.java
/** * Compiles handlebars template and translates possible exceptions to servlet exception. * @param templateName//from www. ja v a 2s. c o m * @return * @throws ServletException */ protected Template compileHandlebarsTemplate(String templateName) throws ServletException { try { return getHandlebars().compile(templateName); } catch (IOException e) { throw new ServletException("Failed to load html handlebars template", e); } }
From source file:org.eclipse.virgo.snaps.core.internal.webapp.StaticResourceServlet.java
/** * {@inheritDoc}/*from w w w .ja v a2 s. co m*/ */ @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // As an alternative of the Tomcat's escaping utility we can use one of the following libraries: // - org.springframework.web.util.HtmlUtils.htmlEscape(String) // - org.apache.commons.lang3.StringEscapeUtils.escapeHtml4(String) String pathInfo = RequestUtil.filter(request.getPathInfo()); try { URL resource = getServletContext().getResource(pathInfo); if (resource == null) { logger.warn("Resource {} not found", pathInfo); response.sendError(HttpServletResponse.SC_NOT_FOUND, "Resource '" + pathInfo + "' not found."); } else { logger.info("Resource {} found", pathInfo); InputStream input = null; try { input = new BufferedInputStream(resource.openStream()); OutputStream output = response.getOutputStream(); byte[] buffer = new byte[4096]; int len; while ((len = input.read(buffer)) > 0) { output.write(buffer, 0, len); } output.flush(); } finally { if (input != null) { IOUtils.closeQuietly(input); } } } } catch (MalformedURLException e) { logger.error(String.format("Malformed servlet path %s", pathInfo), e); throw new ServletException("Malformed servlet path " + pathInfo, e); } }