Java Code Examples for javax.servlet.ServletException#printStackTrace()
The following examples show how to use
javax.servlet.ServletException#printStackTrace() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DispatcherServletTests.java From java-technology-stack with MIT License | 6 votes |
@Test public void withNoViewAndSamePath() throws Exception { InternalResourceViewResolver vr = (InternalResourceViewResolver) complexDispatcherServlet .getWebApplicationContext().getBean("viewResolver2"); vr.setSuffix(""); MockServletContext servletContext = new MockServletContext(); MockHttpServletRequest request = new MockHttpServletRequest(servletContext, "GET", "/noview"); MockHttpServletResponse response = new MockHttpServletResponse(); try { complexDispatcherServlet.service(request, response); fail("Should have thrown ServletException"); } catch (ServletException ex) { ex.printStackTrace(); } }
Example 2
Source File: MaxKeyMgtApplication.java From MaxKey with Apache License 2.0 | 6 votes |
public static void main(String[] args) { _logger.info("Start MaxKeyMgtApplication ..."); ConfigurableApplicationContext applicationContext =SpringApplication.run(MaxKeyMgtApplication.class, args); InitializeContext initWebContext=new InitializeContext(applicationContext); try { initWebContext.init(null); } catch (ServletException e) { e.printStackTrace(); _logger.error("",e); } _logger.info("MaxKeyMgt at "+new Date(applicationContext.getStartupDate())); _logger.info("MaxKeyMgt Server Port "+applicationContext.getBean(ApplicationConfig.class).getPort()); _logger.info("MaxKeyMgt started."); }
Example 3
Source File: OnlineApplicationResource.java From ipst with Mozilla Public License 2.0 | 6 votes |
@POST @Path("logout") public void logout(@Context HttpServletRequest req) { try { req.logout(); } catch (ServletException e) { e.printStackTrace(); } HttpSession session = req.getSession(); if (session != null) { try { session.invalidate(); } catch (Exception ignored) { } } }
Example 4
Source File: DispatcherServletTests.java From spring4-understanding with Apache License 2.0 | 6 votes |
@Test public void withNoViewAndSamePath() throws Exception { InternalResourceViewResolver vr = (InternalResourceViewResolver) complexDispatcherServlet .getWebApplicationContext().getBean("viewResolver2"); vr.setSuffix(""); MockServletContext servletContext = new MockServletContext(); MockHttpServletRequest request = new MockHttpServletRequest(servletContext, "GET", "/noview"); MockHttpServletResponse response = new MockHttpServletResponse(); try { complexDispatcherServlet.service(request, response); fail("Should have thrown ServletException"); } catch (ServletException ex) { ex.printStackTrace(); } }
Example 5
Source File: MaxKeyApplication.java From MaxKey with Apache License 2.0 | 6 votes |
/** * @param args args */ public static void main(String[] args) { _logger.info("Start MaxKeyApplication ..."); VFS.addImplClass(SpringBootVFS.class); ConfigurableApplicationContext applicationContext = SpringApplication.run(MaxKeyApplication.class, args); InitializeContext initWebContext = new InitializeContext(applicationContext); try { initWebContext.init(null); } catch (ServletException e) { e.printStackTrace(); _logger.error("", e); } _logger.info("MaxKey at " + new Date(applicationContext.getStartupDate())); _logger.info("MaxKey Server Port " + applicationContext.getBean(ApplicationConfig.class).getPort()); _logger.info("MaxKey started."); }
Example 6
Source File: TestProcessCreateRequest.java From metalcon with GNU General Public License v3.0 | 6 votes |
@Before public void initializeTest() { this.request = mock(HttpServletRequest.class); HttpServlet servlet = mock(HttpServlet.class); when(this.servletConfig.getServletContext()).thenReturn( this.servletContext); SuggestTree generalIndex = new SuggestTree(7); when( this.servletContext .getAttribute(ProtocolConstants.INDEX_PARAMETER + "testIndex")).thenReturn(generalIndex); when( this.servletContext .getAttribute(ProtocolConstants.INDEX_PARAMETER + "defaultIndex")).thenReturn(generalIndex); try { servlet.init(this.servletConfig); } catch (ServletException e) { fail("could not initialize servlet"); e.printStackTrace(); } }
Example 7
Source File: AwsHttpServletRequestTest.java From aws-serverless-java-container with Apache License 2.0 | 6 votes |
@Test public void queryStringWithMultipleValues_generateQueryString_validQuery() { AwsProxyHttpServletRequest request = new AwsProxyHttpServletRequest(multipleParams, mockContext, null, config); String parsedString = null; try { parsedString = request.generateQueryString(request.getAwsProxyRequest().getMultiValueQueryStringParameters(), true, config.getUriEncoding()); } catch (ServletException e) { e.printStackTrace(); fail("Could not generate query string"); } assertTrue(parsedString.contains("one=two")); assertTrue(parsedString.contains("one=three")); assertTrue(parsedString.contains("json=%7B%22name%22%3A%22faisal%22%7D")); assertTrue(parsedString.contains("&") && parsedString.indexOf("&") > 0 && parsedString.indexOf("&") < parsedString.length()); }
Example 8
Source File: cfResourceServlet.java From openbd-core with GNU General Public License v3.0 | 5 votes |
/** * Handling the response requests * * @param request * @param response * @throws IOException */ private void onCfmlBugRequest(HttpServletRequest request, HttpServletResponse response) throws IOException { // Check to see we have the debug IP's if ( !cfSession.checkDebugIP( request.getRemoteAddr() ) ){ response.setStatus(401); return; } String f = request.getParameter("_f"); if ( f == null ) f = "index.cfm"; // Stop from being naughty and creeping around the system if ( f.indexOf("..") != -1 ){ response.setStatus(404); return; } // Forward now onto the main cfEngine RequestDispatcher rd = request.getRequestDispatcher( "/WEB-INF/webresources/cfmlbug/" + f ); try { rd.forward( request, response ); } catch (ServletException e) { e.printStackTrace(); } }
Example 9
Source File: AngularBeansServletContextListener.java From AngularBeans with GNU Lesser General Public License v3.0 | 5 votes |
@Override public void contextInitialized(ServletContextEvent servletContextEvent) { context = servletContextEvent.getServletContext(); try { if (sockJsServer == null) { initJSR356(); } } catch (ServletException e) { e.printStackTrace(); } StaticJsCacheFactory jsCacheFactory = new StaticJsCacheFactory(DefaultStaticJsCacheLoader.class); jsCacheFactory.BuildStaticJsCache(); }
Example 10
Source File: JavaEELoginService.java From java-webapp-security-examples with Apache License 2.0 | 5 votes |
@Override public LoginStatus login(String username, String password) { try { if (request.getRemoteUser() == null) { request.login(username, password); log.debug("Login succeeded!"); } return new LoginStatus(true, request.getRemoteUser()); } catch (ServletException e) { e.printStackTrace(); return new LoginStatus(false, null); } }
Example 11
Source File: UrlPathValidatorTest.java From aws-serverless-java-container with Apache License 2.0 | 5 votes |
@Test public void init_withWrongConfig_setsDefaultStatusCode() { UrlPathValidator pathValidator = new UrlPathValidator(); Map<String, String> params = new HashMap<>(); params.put(UrlPathValidator.PARAM_INVALID_STATUS_CODE, "hello"); FilterConfig cnf = mockFilterConfig(params); try { pathValidator.init(cnf); assertEquals(UrlPathValidator.DEFAULT_ERROR_CODE, pathValidator.getInvalidStatusCode()); } catch (ServletException e) { e.printStackTrace(); fail("Unexpected ServletException"); } }
Example 12
Source File: UrlPathValidatorTest.java From aws-serverless-java-container with Apache License 2.0 | 5 votes |
@Test public void init_withConfig_setsCorrectStatusCode() { UrlPathValidator pathValidator = new UrlPathValidator(); Map<String, String> params = new HashMap<>(); params.put(UrlPathValidator.PARAM_INVALID_STATUS_CODE, "401"); FilterConfig cnf = mockFilterConfig(params); try { pathValidator.init(cnf); assertEquals(401, pathValidator.getInvalidStatusCode()); } catch (ServletException e) { e.printStackTrace(); fail("Unexpected ServletException"); } }
Example 13
Source File: UrlPathValidatorTest.java From aws-serverless-java-container with Apache License 2.0 | 5 votes |
@Test public void init_noConfig_setsDefaultStatusCode() { UrlPathValidator pathValidator = new UrlPathValidator(); try { pathValidator.init(null); assertEquals(UrlPathValidator.DEFAULT_ERROR_CODE, pathValidator.getInvalidStatusCode()); } catch (ServletException e) { e.printStackTrace(); fail("Unexpected ServletException"); } }
Example 14
Source File: AtmosphereWebSocketServletDestination.java From cxf with Apache License 2.0 | 5 votes |
@Override public void finalizeConfig() { final ServletContext ctx = bus.getExtension(ServletContext.class); if (ctx != null) { try { framework.init(new ServletConfig() { @Override public String getServletName() { return null; } @Override public ServletContext getServletContext() { return ctx; } @Override public String getInitParameter(String name) { return null; } @Override public Enumeration<String> getInitParameterNames() { return null; } }); } catch (ServletException e) { // TODO Auto-generated catch block e.printStackTrace(); } } else { framework.init(); } }
Example 15
Source File: AwsHttpServletRequestTest.java From aws-serverless-java-container with Apache License 2.0 | 5 votes |
@Test public void queryString_generateQueryString_nullParameterIsEmpty() { AwsProxyHttpServletRequest request = new AwsProxyHttpServletRequest(queryStringNullValue, mockContext, null, config);String parsedString = null; try { parsedString = request.generateQueryString(request.getAwsProxyRequest().getMultiValueQueryStringParameters(), true, config.getUriEncoding()); } catch (ServletException e) { e.printStackTrace(); fail("Could not generate query string"); } assertTrue(parsedString.endsWith("three=")); }
Example 16
Source File: LoadBalancerTest.java From TeaStore with Apache License 2.0 | 5 votes |
private void setupAndAddTestTomcat(int i) { Tomcat testTomcat = new Tomcat(); testTomcat.setPort(0); testTomcat.setBaseDir(testWorkingDir); Context context; try { context = testTomcat.addWebapp(CONTEXT, testWorkingDir); testTomcat.getEngine().setName("Catalina" + i); TestServlet testServlet = new TestServlet(); testServlet.setId(i); testTomcat.addServlet(CONTEXT, "notFoundServlet", new NotFoundServlet()); testTomcat.addServlet(CONTEXT, "timeoutStatusServlet", new TimeoutStatusServlet()); testTomcat.addServlet(CONTEXT, "timeoutingServlet", new SlowTimeoutingServlet()); testTomcat.addServlet(CONTEXT, "restServlet", testServlet); context.addServletMappingDecoded("/rest/" + ENDPOINT, "restServlet"); context.addServletMappingDecoded("/rest/" + ENDPOINT + "/*", "restServlet"); context.addServletMappingDecoded("/rest/" + NOT_FOUND_ENDPOINT, "notFoundServlet"); context.addServletMappingDecoded("/rest/" + NOT_FOUND_ENDPOINT + "/*", "notFoundServlet"); context.addServletMappingDecoded("/rest/" + TIMEOUT_STATUS_ENDPOINT, "timeoutStatusServlet"); context.addServletMappingDecoded("/rest/" + TIMEOUT_STATUS_ENDPOINT + "/*", "timeoutStatusServlet"); context.addServletMappingDecoded("/rest/" + TIMEOUTING_ENDPOINT, "timeoutStatusServlet"); context.addServletMappingDecoded("/rest/" + TIMEOUTING_ENDPOINT + "/*", "timeoutStatusServlet"); testTomcats.add(testTomcat); } catch (ServletException e) { e.printStackTrace(); } }
Example 17
Source File: UndertowStartFilter.java From spring-cloud-formula with Apache License 2.0 | 5 votes |
@Override public boolean process(ApplicationExchange application, LauncherFilterChain filterChain) { int port = application.getServerPort(); ClassLoader classLoader = new LaunchedURLClassLoader(application.getClassPathUrls(), deduceParentClassLoader()); DeploymentInfo servletBuilder = Servlets.deployment() .setClassLoader(classLoader) .setContextPath(application.getContextPath()) .setDeploymentName(application.getApplication().getPath()); DeploymentManager manager = Servlets.defaultContainer().addDeployment(servletBuilder); manager.deploy(); Undertow server = null; try { server = Undertow.builder() .addHttpListener(port, "localhost") .setHandler(manager.start()).build(); server.start(); } catch (ServletException e) { e.printStackTrace(); } return false; }
Example 18
Source File: SSOCookieProviderTest.java From knox with Apache License 2.0 | 5 votes |
@Test public void testNoProviderURLJWT() { try { Properties props = getProperties(); props.remove("sso.authentication.provider.url"); handler.init(new TestFilterConfig(props)); } catch (ServletException se) { // no longer expected - let's ensure it mentions the missing authentication provider URL fail("Servlet exception should have been thrown."); se.printStackTrace(); } }
Example 19
Source File: CommandProxyServlet.java From Scribengin with GNU Affero General Public License v3.0 | 4 votes |
@Override protected void onResponseFailure(HttpServletRequest request, HttpServletResponse response, Response proxyResponse, Throwable failure){ //System.err.println("Response Failure!"); this.setForwardingUrl(); HttpClient c = null; try { c = this.createHttpClient(); } catch (ServletException e1) { e1.printStackTrace(); } final Request proxyRequest = c.newRequest(this.forwardingUrl) .method(request.getMethod()) .version(HttpVersion.fromString(request.getProtocol())); boolean hasContent = request.getContentLength() > 0 || request.getContentType() != null; for (Enumeration<String> headerNames = request.getHeaderNames(); headerNames.hasMoreElements();){ String headerName = headerNames.nextElement(); if (HttpHeader.TRANSFER_ENCODING.is(headerName)) hasContent = true; for (Enumeration<String> headerValues = request.getHeaders(headerName); headerValues.hasMoreElements();){ String headerValue = headerValues.nextElement(); if (headerValue != null) proxyRequest.header(headerName, headerValue); } } // Add proxy headers addViaHeader(proxyRequest); addXForwardedHeaders(proxyRequest, request); final AsyncContext asyncContext = request.getAsyncContext(); // We do not timeout the continuation, but the proxy request asyncContext.setTimeout(0); proxyRequest.timeout(getTimeout(), TimeUnit.MILLISECONDS); if (hasContent) try { proxyRequest.content(proxyRequestContent(proxyRequest, request)); } catch (IOException e) { e.printStackTrace(); } customizeProxyRequest(proxyRequest, request); proxyRequest.send(new ProxyResponseListener(request, response)); }
Example 20
Source File: TestProcessRetrieveRequest.java From metalcon with GNU General Public License v3.0 | 4 votes |
private HttpServletRequest initializeTest() { // setup the test. HttpServletRequest request = mock(HttpServletRequest.class); HttpServlet servlet = mock(HttpServlet.class); when(this.servletConfig.getServletContext()).thenReturn( this.servletContext); SuggestTree generalIndex = new SuggestTree(7); generalIndex.put("Metallica", 100, "Metallica"); generalIndex.put("Megadeth", 99, "Metallica"); generalIndex.put("Megaherz", 98, "Metallica"); generalIndex.put("Meshuggah", 97, "Metallica"); generalIndex.put("Menhir", 96, "Metallica"); generalIndex.put("Meat Loaf", 95, "Metallica"); generalIndex.put("Melechesh", 94, "Metallica"); when( this.servletContext.getAttribute("indexName:" + ProtocolConstants.DEFAULT_INDEX_NAME)).thenReturn( generalIndex); SuggestTree venueIndex = new SuggestTree(7); venueIndex.put("Das Kult", 55, "http://www.daskult.de"); venueIndex.put("Die Halle", 44, "http://www.diehalle-frankfurt.de"); venueIndex.put("Die Mühle", 30, "http://www.die-muehle.net"); venueIndex.put("Dreams", 30, "http://www.discothek-dreams.de"); venueIndex.put("Dudelsack", 27, "http://www.dudelsack-bk.de"); venueIndex.put("Das Haus", 25, "http://www.dashaus-lu.de/home.html"); venueIndex.put("Druckluftkammer", 25, "http://www.druckluftkammer.de/"); when(this.servletContext.getAttribute("indexName:" + "venueIndex")) .thenReturn(venueIndex); HashMap<String, String> imageIndex = new HashMap<String, String>(); when( this.servletContext .getAttribute(ProtocolConstants.IMAGE_SERVER_CONTEXT_KEY)) .thenReturn(imageIndex); try { servlet.init(this.servletConfig); } catch (ServletException e) { fail("could not initialize servlet"); e.printStackTrace(); } return request; }