HttpUnit ... não consegue compilar jsp's

1 resposta
G

Estou tentando usar o httpunit, mas sempre que a minha servlet retorna um jsp da aplicação, ele não acha o arquivo para compilar. Aparentemente o servidor é iniciado corretamente, e inclusive o spring carrega certinho, porém no processamento do retorno eu "ganho um stack". Segue o código de inicialização do ServletRunner, e o stack:

URL url = Thread.currentThread().getContextClassLoader()
			.getResource("./");
		InputStream is = new FileInputStream(new File(url.getFile(), "../web.xml"));
		
		runner = new ServletRunner(is, "/controle");
		System.out.println(runner.JASPER_DESCRIPTOR.getInitializationParameters(new File(url.getFile(), "../..").getCanonicalPath(), new File(url.getFile(), "../..").getCanonicalPath()));
java.io.FileNotFoundException: D:\<<aplicacao>>\source\trunk\bla.jsp (O sistema não pode encontrar o arquivo especificado)
	at java.io.FileInputStream.open(Native Method)
	at java.io.FileInputStream.<init>(FileInputStream.java:106)
	at java.io.FileInputStream.<init>(FileInputStream.java:66)
	at sun.net.www.protocol.file.FileURLConnection.connect(FileURLConnection.java:70)
	at sun.net.www.protocol.file.FileURLConnection.getInputStream(FileURLConnection.java:161)
	at org.apache.jasper.compiler.Compiler.isOutDated(Compiler.java:352)
	at org.apache.jasper.compiler.Compiler.isOutDated(Compiler.java:315)
	at org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:553)
	at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:293)
	at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
	at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
	at com.meterware.servletunit.RequestDispatcherImpl.forward(RequestDispatcherImpl.java:54)
	at org.bla.web.servlet.LoginOperatorServlet.doPost(LoginOperatorServlet.java:67)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
	at com.meterware.servletunit.InvocationContextImpl.service(InvocationContextImpl.java:76)
	at com.meterware.servletunit.InvocationContextImpl$1.doFilter(InvocationContextImpl.java:153)
	at org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:174)
	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:77)
	at com.meterware.servletunit.InvocationContextImpl.service(InvocationContextImpl.java:74)
	at com.meterware.servletunit.ServletUnitClient.newResponse(ServletUnitClient.java:126)
	at com.meterware.httpunit.WebClient.createResponse(WebClient.java:647)
	at com.meterware.httpunit.WebWindow.getResource(WebWindow.java:220)
	at com.meterware.httpunit.WebWindow.getSubframeResponse(WebWindow.java:181)
	at com.meterware.httpunit.WebWindow.getResponse(WebWindow.java:158)
	at com.meterware.httpunit.WebClient.getResponse(WebClient.java:122)
	at org.bla.web.servlet.LogEventMonitorServletTestCase.setUp(LogEventMonitorServletTestCase.java:39)
	at junit.framework.TestCase.runBare(TestCase.java:128)
	at junit.framework.TestResult$1.protect(TestResult.java:106)
	at junit.framework.TestResult.runProtected(TestResult.java:124)
	at junit.framework.TestResult.run(TestResult.java:109)
	at junit.framework.TestCase.run(TestCase.java:120)
	at junit.framework.TestSuite.runTest(TestSuite.java:230)
	at junit.framework.TestSuite.run(TestSuite.java:225)
	at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:130)
	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)

1 Resposta

G

Caso alguém queira saber. consegui resolver o problema. Para setar o lugar certo de onde serão compiladas as JSP's, deve ser usado o construtor ServletRunner(File webXml, String contextPath) e não o ServletRunner(InputStream webXml, String contextPath), que era como eu tentava fazer.
Olhando o fonte do httpunit, vi que quando usado passando um File ao invés de InputStream, ele pega o webXml.parentFile().parentFile() e seta esse path como o default das JSP's.
Então a correção fica com a inicialização do ServletRunner assim:

URL url = Thread.currentThread().getContextClassLoader()
			.getResource("./");
		
		runner = new ServletRunner(new File(new File(url.getFile()).getParentFile(), "web.xml"), "/controle");

o trecho "new File(new File(url.getFile()).getParentFile()" parece meio porco, mas foi o único jeito de fazer o java entender os paths. Tentei usar inicialmento como url.getFile() e no construtor passar new ServletRunner(url.getFile(), "../web.xml") mas o java se perde com isso. Ele pega o parent errado!

Criado 15 de julho de 2008
Ultima resposta 16 de jul. de 2008
Respostas 1
Participantes 1