W3C home > Mailing lists > Public > www-jigsaw@w3.org > January to February 2002

MimeParser

From: Kristjan Sander <kristjan@webmedia.ee>
Date: Wed, 27 Feb 2002 13:18:45 -0500 (EST)
Message-ID: <002a01c1bfbb$42534eb0$2e28a8c0@kristjan>
To: <www-jigsaw@w3.org>
Hello

I am seeking for help on using MimeParser class. My trouble is, I can get
the streams responding to every part but I cannot parse them with
MimeParser. I get an exception in notifyBeginParsing because I try to parse
it as I parse the whole reply and that is apparently wrong because there are
no HTTP version strings, status codes etc in single parts.

I am developing a system where I get multipart data from replies, not
requests and I use MimeParserReplyFactory and HttpReplyMessage.

Sample code (with the help of
http://lists.w3.org/Archives/Public/www-jigsaw/msg01250.html):

public boolean saveParts(int maxLen) throws java.io.IOException,
MimeParserException {
      boolean result = true;
      MimeParserReplyFactory factory = new MimeParserReplyFactory();
      MimeParser parser  = new MimeParser(in, factory);
      // Read each part:
      System.out.println("Starting to read parts...");
      while (in.nextInputStream()) {
      // these are themselves MIME streams (!)
        file://MimeHeaders headers = (MimeHeaders) parser.parse() ;
        MimeHeaders headers = (MimeHeaders) parser.parse();
        System.out.println ("----- headers:") ;
        headers.dump(System.out) ;
        System.out.println ("----- body:") ;
        int  got      = -1 ;
        byte buffer[] = new byte[4096] ;
        InputStream body = parser.getInputStream();
        while ((got = body.read(buffer)) > 0)
        System.out.println (new String (buffer, 0, 0, got)) ;
        System.out.println ("----- end of body") ;
      }
[....]
}

Output traceback:

org.w3c.www.http.HttpInvalidValueException: parseInt: No number available.
        at org.w3c.www.http.HttpParser.error(HttpParser.java:34)
        at org.w3c.www.http.HttpParser.parseInt(HttpParser.java:125)
        at org.w3c.www.http.HttpParser.parseInt(HttpParser.java:133)
        at
org.w3c.www.http.HttpReplyMessage.notifyBeginParsing(HttpReplyMessage.java:1
90)
        at org.w3c.www.mime.MimeParser.parse(MimeParser.java:197)
        at
ee.hansa.thnet.eservices.MimeMultipartParser.saveParts(MimeMultipartParser.j
ava:53)
        at
ee.hansa.thnet.eservices.EPartnerPage.execPage(EPartnerPage.java:97)
        at
ee.hansa.framework.site.SiteManager.servicePage(SiteManager.java:1178)
        at ee.hansa.thnet.ThnetServlet.service(ThnetServlet.java:39)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
        at
org.apache.tomcat.core.ServletWrapper.doService(ServletWrapper.java:404)
        at org.apache.tomcat.core.Handler.service(Handler.java:286)
        at
org.apache.tomcat.core.ServletWrapper.service(ServletWrapper.java:372)
        at
org.apache.tomcat.core.ContextManager.internalService(ContextManager.java:79
7)
        at
org.apache.tomcat.core.ContextManager.service(ContextManager.java:743)
        at
org.apache.tomcat.service.http.HttpConnectionHandler.processConnection(HttpC
onnectionHandler.java:210)
        at
org.apache.tomcat.service.TcpWorkerThread.runIt(PoolTcpEndpoint.java:416)
        at
org.apache.tomcat.util.ThreadPool$ControlRunnable.run(ThreadPool.java:498)
        at java.lang.Thread.run(Thread.java:484)

Any help to my private address would be very much appreciated.

Thanks in advance,

Kristjan Sander
O Webmedia
www.webmedia.ee
Received on Thursday, 28 February 2002 06:07:36 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Monday, 9 April 2012 12:13:36 GMT