tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bugzi...@apache.org
Subject DO NOT REPLY [Bug 44405] - regression with tomcat 6.0.16, NullPointerException on getServletContext().getResourceAsStream()
Date Wed, 13 Feb 2008 10:29:51 GMT
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG·
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=44405>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND·
INSERTED IN THE BUG DATABASE.

http://issues.apache.org/bugzilla/show_bug.cgi?id=44405





------- Additional Comments From omichels@web.de  2008-02-13 02:29 -------
Servlets source code:

public class ViewResource extends
		javax.servlet.http.HttpServlet implements
		javax.servlet.Servlet {
	static final long serialVersionUID = 1L;

	public ViewResource() {
		super();
	}

	protected void doGet(HttpServletRequest request,
			HttpServletResponse response)
			throws ServletException, IOException {
		ServletOutputStream servletOutputStream = response
				.getOutputStream();
		byte[] bytes = new byte[4096];
		InputStream is;
		try {
			is = this.getServletContext()
					.getResourceAsStream(
							"WEB-INF/foobar.txt");
			is.read(bytes, 0, 4096);
			response.reset();
			response.setContentType("text/plain");
			response.setContentLength(bytes.length);
			response.setHeader("Cache-control",
					"must-revalidate");
			servletOutputStream.write(bytes, 0,
					bytes.length);
			servletOutputStream.flush();
			servletOutputStream.close();
		} catch (NullPointerException e) {
			StringWriter stringWriter = new StringWriter();
			PrintWriter printWriter = new PrintWriter(
					stringWriter);
			e.printStackTrace(printWriter);
			response.setContentType("text/plain");
			response.getOutputStream().print(
					stringWriter.toString());
		}
	}

	protected void doPost(HttpServletRequest request,
			HttpServletResponse response)
			throws ServletException, IOException {
		doGet(request, response);
	}
}

-- 
Configure bugmail: http://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Mime
View raw message