javax.servlet.ServletException#printStackTrace ( )源码实例Demo

下面列出了javax.servlet.ServletException#printStackTrace ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

@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();
	}
}
 
源代码2 项目: ipst   文件: OnlineApplicationResource.java
@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) {
        }
    }

}
 
@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();
	}
}
 
@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());
}
 
源代码5 项目: metalcon   文件: TestProcessCreateRequest.java
@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();
	}
}
 
源代码6 项目: MaxKey   文件: MaxKeyApplication.java
/**
 * @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.");
}
 
源代码7 项目: MaxKey   文件: MaxKeyMgtApplication.java
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.");
	
}
 
源代码8 项目: knox   文件: SSOCookieProviderTest.java
@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();
  }
}
 
@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;
}
 
源代码10 项目: TeaStore   文件: LoadBalancerTest.java
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();
	}
}
 
@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="));
}
 
@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();
    }
}
 
@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");
    }
}
 
@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");
    }
}
 
@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");
    }
}
 
@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);
    }
}
 
@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();
}
 
源代码18 项目: openbd-core   文件: cfResourceServlet.java
/**
 * 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();
	}
	
}
 
源代码19 项目: metalcon   文件: TestProcessRetrieveRequest.java
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;
}
 
源代码20 项目: Scribengin   文件: CommandProxyServlet.java
@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));
}