unable to read mime boundary headers

View: New views
3 Messages — Rating Filter:   Alert me  

unable to read mime boundary headers

by Richard Jones-28 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Folks,

I'm trying to read headers from a mime boudary, with no success.  Can
anyone tell me what I'm doing wrong here (with version 3.1 of http client):

FileItemFactory factory = new DiskFileItemFactory();
ServletFileUpload upload = new ServletFileUpload(factory);
List<DiskFileItem> items = upload.parseRequest(request);

for (DiskFileItem item : items)
{
    String ct = item.getContentType();
    FileItemHeaders hed = item.getHeaders();
    String cd = hed.getHeader("Content-Disposition");
}

At this point, hed is always null (so the final line throws an NPE).  
Perplexingly, though, the content type variable contains the content
type.  The http request is definitely valid, and contains a mime
boundary thus:

--NlWHLgeBI76ZytSdNwyoMKnfTjSG8ocZuIh
Content-Disposition: form-data; name="atom"; filename="atom.xml"
Content-Type: text/xml; charset=UTF-8
Content-Transfer-Encoding: binary

Any suggestions?  Something wrong with the DiskFileItem implementation?  
A mis-use of getHeaders?

Cheers,

Richard

--
Richard Jones
Head Repository Systems Architect, Symplectic Limited
e: richard@...
t: 0845 026 4755
t: +44 (0)207 7334036
w: http://www.symplectic.co.uk/


---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@...
For additional commands, e-mail: httpclient-users-help@...


RE: unable to read mime boundary headers

by Pete Keyes :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

The boundary is declared in the header of the "original" HTTP request.  All you have below is a single mime body part.

The original request would have had a content-type header something like this:
        content-type: multipart/report; report-type=disposition-notification; boundary="----=_Part_6_17038270.1191609292302"

That is, if it were valid...

You need to get the boundary from the header of the original HTTP request.
 
...Pete
Starbucks Coffee Co.
2401 Utah Ave S.
Seattle, WA. 98134
(work)206-318-5933
(cell)206-226-4552
 
After hours emergency pager:
  206-314-2054 or page-pkeyes@...
 

-----Original Message-----
From: Richard Jones [mailto:richard@...]
Sent: Monday, June 08, 2009 3:38 AM
To: httpclient-users@...
Subject: unable to read mime boundary headers

Hi Folks,

I'm trying to read headers from a mime boudary, with no success.  Can
anyone tell me what I'm doing wrong here (with version 3.1 of http client):

FileItemFactory factory = new DiskFileItemFactory();
ServletFileUpload upload = new ServletFileUpload(factory);
List<DiskFileItem> items = upload.parseRequest(request);

for (DiskFileItem item : items)
{
    String ct = item.getContentType();
    FileItemHeaders hed = item.getHeaders();
    String cd = hed.getHeader("Content-Disposition");
}

At this point, hed is always null (so the final line throws an NPE).  
Perplexingly, though, the content type variable contains the content
type.  The http request is definitely valid, and contains a mime
boundary thus:

--NlWHLgeBI76ZytSdNwyoMKnfTjSG8ocZuIh
Content-Disposition: form-data; name="atom"; filename="atom.xml"
Content-Type: text/xml; charset=UTF-8
Content-Transfer-Encoding: binary

Any suggestions?  Something wrong with the DiskFileItem implementation?  
A mis-use of getHeaders?

Cheers,

Richard

--
Richard Jones
Head Repository Systems Architect, Symplectic Limited
e: richard@...
t: 0845 026 4755
t: +44 (0)207 7334036
w: http://www.symplectic.co.uk/


---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@...
For additional commands, e-mail: httpclient-users-help@...


---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@...
For additional commands, e-mail: httpclient-users-help@...


Re: unable to read mime boundary headers

by Richard Jones-28 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Pete,

> The boundary is declared in the header of the "original" HTTP request.  All you have below is a single mime body part.
>
> The original request would have had a content-type header something like this:
> content-type: multipart/report; report-type=disposition-notification; boundary="----=_Part_6_17038270.1191609292302"
>
> That is, if it were valid...
>
> You need to get the boundary from the header of the original HTTP request.
>  

I only included the part of the http request which contained the mime
boundary and subsequent headers that I was looking at; it is part of a
much larger http request containing full headers, and a number of other
mime parts.  Consequent to that, the mime boundary itself is extracted
from the main http headers, and parsed just fine, and I can access all
of the content of the mime parts, and the content type from those
headers that I included.  What doesn't work is doing a getHeaders
request on the DiskFileItem; it always returns null.

Cheers,

Richard

>  
> ...Pete
> Starbucks Coffee Co.
> 2401 Utah Ave S.
> Seattle, WA. 98134
> (work)206-318-5933
> (cell)206-226-4552
>  
> After hours emergency pager:
>   206-314-2054 or page-pkeyes@...
>  
>
> -----Original Message-----
> From: Richard Jones [mailto:richard@...]
> Sent: Monday, June 08, 2009 3:38 AM
> To: httpclient-users@...
> Subject: unable to read mime boundary headers
>
> Hi Folks,
>
> I'm trying to read headers from a mime boudary, with no success.  Can
> anyone tell me what I'm doing wrong here (with version 3.1 of http client):
>
> FileItemFactory factory = new DiskFileItemFactory();
> ServletFileUpload upload = new ServletFileUpload(factory);
> List<DiskFileItem> items = upload.parseRequest(request);
>
> for (DiskFileItem item : items)
> {
>     String ct = item.getContentType();
>     FileItemHeaders hed = item.getHeaders();
>     String cd = hed.getHeader("Content-Disposition");
> }
>
> At this point, hed is always null (so the final line throws an NPE).  
> Perplexingly, though, the content type variable contains the content
> type.  The http request is definitely valid, and contains a mime
> boundary thus:
>
> --NlWHLgeBI76ZytSdNwyoMKnfTjSG8ocZuIh
> Content-Disposition: form-data; name="atom"; filename="atom.xml"
> Content-Type: text/xml; charset=UTF-8
> Content-Transfer-Encoding: binary
>
> Any suggestions?  Something wrong with the DiskFileItem implementation?  
> A mis-use of getHeaders?
>
> Cheers,
>
> Richard
>
>  


--
Richard Jones
Head Repository Systems Architect, Symplectic Limited
e: richard@...
t: 0845 026 4755
t: +44 (0)207 7334036
w: http://www.symplectic.co.uk/


---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@...
For additional commands, e-mail: httpclient-users-help@...