You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@hc.apache.org by Vijay <rn...@gmail.com> on 2004/12/13 17:26:03 UTC

Parsing Multipart

I am reading the multipart messge using code as follows:

method.getResponseBodyAsString()

What I get is a BIG string, with multiple parts( each part has
boundary, content-disposition type and name). Is there any smart way
of parsing this string into each part and put it into hashtable?
(Currently I can only think of using String operations to break the
BIGstring into multiple parts. But the problem is, sometimes I dont
know what the content disposition/part name is going to be)


Thanks
Vijay

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


Re: Parsing Multipart

Posted by Nicholas Rahn <ni...@mnc.ch>.
You could also use the Jakarta Commons FileUpload package instead of
JavaMail.  We use this to parse multi-part http requests, but i think it
should be usable as well for multi-part http responses.

nick

On Mon, 2004-12-13 at 18:29 +0100, Ortwin Glück wrote:
> 
> Vijay wrote:
> > I'm currently using httpclient to post the multipart data to an URL
> > and read the multipart response back. JavaMail doesn't support
> > http/https protocol requests, correct?
> 
> You are correct. But I didn't mean to use JavaMail for the transfer. 
> Only use it for parsing. Something along the lines of:
> 
> DataSource ds = new HttpClientDataSource(url);
> MimeMultipart top = new MimeMultipart(ds);
> for (int i=0; i < top.getCount(); i++) {
>    BodyPart part = top.getBodyPart(i);
>    // do something with the part here
> }
> 
> 
> You can then hide all Http code in the HttpClientDataSource implementation.
> 
> How about this?
> 
>     -og
> 
> 
> 
> > I saw the warning message on logs for using String. Thanks. I will use
> > getResponseAsStream().
> > 
> > Thanks
> > Vijay
> 


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


Re: Parsing Multipart

Posted by Ortwin Glück <or...@nose.ch>.

Vijay wrote:
> I'm currently using httpclient to post the multipart data to an URL
> and read the multipart response back. JavaMail doesn't support
> http/https protocol requests, correct?

You are correct. But I didn't mean to use JavaMail for the transfer. 
Only use it for parsing. Something along the lines of:

DataSource ds = new HttpClientDataSource(url);
MimeMultipart top = new MimeMultipart(ds);
for (int i=0; i < top.getCount(); i++) {
   BodyPart part = top.getBodyPart(i);
   // do something with the part here
}


You can then hide all Http code in the HttpClientDataSource implementation.

How about this?

    -og



> I saw the warning message on logs for using String. Thanks. I will use
> getResponseAsStream().
> 
> Thanks
> Vijay

-- 
  _________________________________________________________________
  NOSE applied intelligence ag

  ortwin glück                      [www]      http://www.nose.ch
  software engineer
  hardturmstrasse 171               [pgp id]           0x81CF3416
  8005 zürich                       [office]      +41-1-277 57 35
  switzerland                       [fax]         +41-1-277 57 12

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


Re: Parsing Multipart

Posted by Vijay <rn...@gmail.com>.
I'm currently using httpclient to post the multipart data to an URL
and read the multipart response back. JavaMail doesn't support
http/https protocol requests, correct?

I saw the warning message on logs for using String. Thanks. I will use
getResponseAsStream().

Thanks
Vijay

On Mon, 13 Dec 2004 17:57:08 +0100, Ortwin Glück <or...@nose.ch> wrote:
> 
> 
> Vijay wrote:
> > I am reading the multipart messge using code as follows:
> >
> > method.getResponseBodyAsString()
> >
> > What I get is a BIG string, with multiple parts( each part has
> > boundary, content-disposition type and name).
> 
> If your String is large, use of getResponseBodyAsString() is strongly
> discouraged. Please use getResponseAsStream().
> 
> > Is there any smart way
> > of parsing this string into each part and put it into hashtable?
> > (Currently I can only think of using String operations to break the
> > BIGstring into multiple parts. But the problem is, sometimes I dont
> > know what the content disposition/part name is going to be)
> >
> >
> > Thanks
> > Vijay
> 
> HttpClient does not handle Multipart-MIME parsing. You could use the
> JavaMail library for that:
> 
> http://java.sun.com/products/javamail/
> 
>    -og
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: httpclient-dev-help@jakarta.apache.org
> 
>

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


Re: Parsing Multipart

Posted by Ortwin Glück <or...@nose.ch>.

Vijay wrote:
> I am reading the multipart messge using code as follows:
> 
> method.getResponseBodyAsString()
> 
> What I get is a BIG string, with multiple parts( each part has
> boundary, content-disposition type and name). 

If your String is large, use of getResponseBodyAsString() is strongly 
discouraged. Please use getResponseAsStream().

 > Is there any smart way
> of parsing this string into each part and put it into hashtable?
> (Currently I can only think of using String operations to break the
> BIGstring into multiple parts. But the problem is, sometimes I dont
> know what the content disposition/part name is going to be)
> 
> 
> Thanks
> Vijay

HttpClient does not handle Multipart-MIME parsing. You could use the 
JavaMail library for that:

http://java.sun.com/products/javamail/

    -og

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


Parsing Multipart

Posted by Vijay <rn...@gmail.com>.
I am reading the multipart messge using code as follows:

method.getResponseBodyAsString()

What I get is a BIG string, with multiple parts( each part has
boundary, content-disposition type and name). Is there any smart way
of parsing this string into each part and put it into hashtable?
(Currently I can only think of using String operations to break the
BIGstring into multiple parts. But the problem is, sometimes I dont
know what the content disposition/part name is going to be)

Thanks
Vijay

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