I have an web application that takes OpenOffice 1.1 files and converts
them to web pages. I have a single sxw file that causes an exception
but only when run in the servlet.
When running in the servlet I get:
java.lang.InternalError: jzentry == 0,
jzfile = 138986592,
total = 6,
name = /content/xenei.net/coffeehouse/docs/calendar/Feb2007.sxw,
i = 3,
message = invalid LOC header (bad signature)
java.util.zip.ZipFile$3.nextElement(ZipFile.java:429)
java.util.zip.ZipFile$3.nextElement(ZipFile.java:415)
java.util.jar.JarFile$1.nextElement(JarFile.java:217)
java.util.jar.JarFile$1.nextElement(JarFile.java:216)
org.xenei.cm.servlets.jarTest.list(jarTest.java:74)
org.xenei.cm.servlets.jarTest.doGet(jarTest.java:84)
javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
I have isolated the code in a small servlet:
public class jarTest extends HttpServlet {
public jarTest()
{
}
private void digest(HttpServletRequest req, HttpServletResponse
resp) throws IOException, NoSuchAlgorithmException
{
String urlString = req.getParameter("digest");
PrintWriter writer = resp.getWriter();
writer.println( "=====> "+urlString );
URL myURL = new URL( "file:"+urlString );
MessageDigest md = MessageDigest.getInstance("MD5");
try
{
DigestInputStream dis = new DigestInputStream(
myURL.openStream(), md );
byte[] buffer = new byte[1024];
BufferedInputStream bis = new BufferedInputStream( dis );
while (bis.read(buffer, 0, 1024 ) > -1)
{
// do nothing
}
byte[] digest = dis.getMessageDigest().digest();
writer.println( myURL.toString()+" digest is: "+Hex.encode(
digest ) );
}
catch (Exception e)
{
writer.println( "ERROR" );
e.printStackTrace( writer );
}
}
private void list(HttpServletRequest req, HttpServletResponse resp)
throws IOException
{
String urlString = req.getParameter("url");
PrintWriter writer = resp.getWriter();
writer.println( "=====> "+urlString );
URL myURL = new URL( "jar:file:"+urlString+"!/" );
writer.println( "Opening URL: "+myURL );
JarFile jarFile;
// open the jarfile.
JarURLConnection conn = (JarURLConnection) myURL.openConnection();
jarFile = conn.getJarFile();
Enumeration entries = jarFile.entries();
JarEntry entry;
while (entries.hasMoreElements() )
{
entry = (JarEntry)entries.nextElement(); // <-----------
Error occurs here
writer.println( "processing: "+entry.getName() );
}
writer.println( "<=====" );
}
protected void doGet(HttpServletRequest req, HttpServletResponse
resp) throws ServletException, IOException
{
if (req.getParameter("url") != null)
{
list( req, resp );
}
if (req.getParameter("digest") != null)
{
try {
digest( req, resp );
} catch (NoSuchAlgorithmException e) {
// TODO Auto-generated catch block
throw new ServletException( e.getMessage(), e );
}
}
}
}
This servlet will either list the the contents of the jar (sxw) file
with the url= argument or provide the MD5 digest for the contents of the
file if called with the digest= argument.
I have placed the same code in a stand alone app and it will read the
file without problem. The MD5 digest of the bytes is the same both in
the servlet and in the stand alone.
This fails only in the servlet and, thus far, only with the one file.
All other tools that can read zip files that I have access to are able
to read the file, furthermore OpenOffice 1.1 can read it as well. I
have not tried to rewrite it as I want to make sure that I understand
why the servlet fails in this case so that I can attempt to account for
it in future cases.
Any help with this would be appreciated. I will gladly provide the
servlet, stand alone, and sxw file for anyone that is interested in
looking at this problem.
Many Thanks,
Claude Warren
---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]