[prev in list] [next in list] [prev in thread] [next in thread] 

List:       jakarta-commons-user
Subject:    Antwort: Re: Commons Upload: Can not read parameters if input type file is
From:       michael.laube () hilgmbh ! de
Date:       2010-10-18 13:19:56
Message-ID: OF84CB008A.45307D85-ONC12577C0.0048F765-C12577C0.00493CD7 () hilgmbh ! de
[Download RAW message or body]

--=_alternative 00493CD6C12577C0_Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: quoted-printable

Hallo Brian,

its couious, at first i have programmed a little example Application with 
a form and one Servlet. It works ...

But in my productive Code something strange happens ...

Know i hava some Debugging Code added to the servlet.

System.out.println("-------------------------------------------------");
                boolean isMultipart = ServletFileUpload.isMultipartContent
(request);
                ParameterContainer paramContainer = new 
ParameterContainer();
                request.getSession().setAttribute("paramContainer", 
paramContainer);
                Enumeration<String> headerNames = request.getHeaderNames()
;
                while(headerNames.hasMoreElements()){
                        String nameH = headerNames.nextElement();
 
                        System.out.println("Header Name: " + nameH + " 
Header Value: " + request.getHeader(nameH));
                }
 
                System.out.println("Path Info: " + request.getPathInfo());
                System.out.println("Content Type: " + 
request.getContentType());
                System.out.println("Content Length: " + 
request.getContentLength());
                System.out.println("Path Translated: " + 
request.getPathTranslated());
                Enumeration<String> parameterNames = 
request.getParameterNames();
                while(parameterNames.hasMoreElements()){
                        String pName = parameterNames.nextElement();
                        System.out.println("Parametername: " + pName + " 
Parametervalue: " + request.getParameter(pName));
                }
 
                System.out.println("Query String: " + 
request.getQueryString());
                ServletInputStream sI = request.getInputStream();
 
 
 
 
                String s = null;
                BufferedReader in = new BufferedReader(new 
InputStreamReader(request.getInputStream()));
                for (String buffer;(buffer = in.readLine()) != null
;s+=buffer + "\n");

                System.out.println(s);
 

The result in the logging File of Tomcat is: 

-------------------------------------------------
Header Name: content-type Header Value: multipart/form-data; 
boundary=---------------------------66541697221457
Header Name: connection Header Value: keep-alive
Header Name: accept-language Header Value: 
de-de,de;q=0.8,en-us;q=0.5,en;q=0.3
Header Name: host Header Value: 10.83.17.121:8443
Header Name: content-length Header Value: 967
Header Name: accept Header Value: 
text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Header Name: keep-alive Header Value: 115
Header Name: user-agent Header Value: Mozilla/5.0 (Windows; U; Windows NT 
5.2; de; rv:1.9.2.8) Gecko/20100728 Firefox/3.6.8
Header Name: referer Header Value: 
https://10.83.17.121:8443/adminhil/CentralControl;jsessionid=C368C37647A58E4D7C0E3283E320A56E?servletName=addNews
 Header Name: accept-charset Header Value: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Path Info: null
Content Type: multipart/form-data; 
boundary=---------------------------66541697221457
Content Length: 967
Path Translated: null
Query String: null
null-----------------------------66541697221457
Content-Disposition: form-data; name="ueberschrift"

TEST ...
-----------------------------66541697221457
Content-Disposition: form-data; name="neuigkeit"

TEST Content
-----------------------------66541697221457
Content-Disposition: form-data; name="userfile1"; filename=""
Content-Type: application/octet-stream


-----------------------------66541697221457
Content-Disposition: form-data; name="newsuan"

1
-----------------------------66541697221457
Content-Disposition: form-data; name="hiddenNewsId"

0
-----------------------------66541697221457
Content-Disposition: form-data; name="servletName"

saveNews
--------------------Cookie: JSESSIONID=540AC1AC08A682FEA1F838EEDE7E8A53
---------66541697221457
Content-Disposition: form-data; name="jsessionid"

540AC1AC08A682FEA1F838EEDE7E8A53
-----------------------------66541697221457
Content-Disposition: form-data; name="sendIt"

Speic

Is Multipart Content: true
Nach Try Upload ... ------->>>>>>
Nach dem Auslesen der Parameter --------->>>>>>

Best Regards 

Michael




Von:    Brian Pontarelli <brian@pontarelli.com>
An:     "Commons Users List" <user@commons.apache.org>
Datum:  15.10.2010 16:39
Betreff:        Re: Commons Upload: Can not read parameters if input type 
file is empty ...



The code and HTML look good. I've gotten that message a number of times 
and what it generally means is that the request body isn't properly 
formatted. More specifically, when the MultipartStream is asking the 
underlying stream (in this case the ServletInputStream) for more bytes it 
returns -1 signifying the end of the body.

Is anything else touching the InputStream before your code does? That 
could cause issues.

Another thing I would try is to read in the request body and output to 
stdout. This will help you determine if it looks like properly formatted 
multipart body. You could also post that output to the list and we can 
take a look as well.

-bp


On Oct 15, 2010, at 4:38 AM, michael.laube@hilgmbh.de wrote:

> Hello developers, 
> 
> i try to use the upload function. I use a form with a text Field, a 
> Textare and some checkoxs and an input Type of file. If write somthing 
in 
> these fields and choose a file to upload the behavior is good. The 
Upload 
> will be executed. When i write only somthing to the other input elements 

> (file choose is empty) I get an exception like this: 
> 
> Processing of multipart/form-data request failed. Stream ended 
> unexpectedly 
> 
> This happens only if no file is choosen. Only the values of the other 
> fields will be submitted.  This Part of code throw the exception. 
> 
> items = upload.parseRequest(request); 
> 
> Perhaps i make somthing wrong ... 
> 
> Perhaps it is a bug .... 
> 
> I don't now .... 
> 
> 
> 
> Best regards 
> 
> Michael Laube 
> 
> 
> 
> 
> 
> Source of the form: 
> 
> 
> <form  action="/xxx/CentralControl" method="post" class="admin" enctype=
> "multipart/form-data"> 
> 
> <fieldset class="admin"> 
> <legend>News</legend> 
> <label class="admin">&Uuml;berschrift:</label> 
> <input type="text" name="ueberschrift" value="
> ${hN.ueberschrift}" size="68"/><br/> 
> <label class="admin">Inhalt</label> 
> <textarea class="admin" name="neuigkeit" 
rows="30" 
> cols="60">${hN.text_aktuelles}</textarea> 
> 
> 
> 
> 
> <label class="admin">Datei hochladen:</label><
> INPUT name="userfile1" type="file"/> 
> 
> 
> 
> 
> 
> 
> 
> <label class="admin">Publizieren</label> 
> 
> <%if(hN.getVeroeffentlich_status()!=null){ %> 
> <input type="checkbox" class="admin" name=
> "publizieren" value="1" checked="checked"/><br/> 
> <%} 
> else{ 
> %> 
> <input type="checkbox" class="admin" name=
> "publizieren" value="1" /><br/> 
> <%} %> 
> 
> 
> 
> <label class="admin">News Bw </label> 
> 
> <%if(hN.getNewsbw()!=null){ %> 
> <input type="checkbox" class="admin" 
name="newsbw" 
> value="1" checked="checked"/> 
> <%} 
> else{ 
> %> 
> <input type="checkbox" class="admin" 
name="newsbw" 
> value="1"/> 
> <%} %> 
> 
> <label class="admin">News UAN</label> 
> 
> <%if(hN.getNewsuan()!=null){ %> 
> <input type="checkbox" class="admin" name=
> "newsuan" value="1" checked="checked"/> 
> <%}else{ %> 
> <input type="checkbox" class="admin" name=
> "newsuan" value="1"/> 
> <%} %> 
> 
> 
> <label class="admin">Löschkennzeichen: </label> 
> <%if(hN.getLoeschkennzeichen()!=null){ %> 
> <input type="checkbox" class="admin" name=
> "loeschkennzeichen" value="1" checked="checked"/> 
> <%}else{ %> 
> <input type="checkbox" class="admin" name=
> "loeschkennzeichen" value="1" /> 
> <%} %> 
> 
> 
> <label class="admin">E-Mail Nachricht: </label> 
> <input type="checkbox" class="admin" name=
> "newsuansendmail" value="1"/> 
> 
> <input type="hidden" name="hiddenNewsId" value="
> ${hN.id}" /> 
> </fieldset> 
> <fieldset class="button"> 
> <input type="hidden" name="servletName" value=
> "saveNews"/> 
> <input type="hidden" name="jsessionid" value="<%=
> session.getId()%>"/> 
> <input type="submit" name="sendIt" value=
> "Speichern"/> 
> </fieldset> 
> </form> 
> 
> Source of Servlet Logic: 
> 
> System.out.println("Multi Form Data Parameter auslesen ------->:"); 
> PrintWriter pw = response.getWriter(); 
> String n="";String v=""; 
> 
> 
> FileItemFactory   factory = new 
> DiskFileItemFactory(); 
> 
> 
> 
> 
> 
> ServletFileUpload upload = new 
> ServletFileUpload(factory); 
> upload.setFileSizeMax(50000000); 
> upload.setSizeMax(-1); 
> 
> 
> List items = null; 
> 
> try { 
> 
> items = upload.parseRequest(request); 
> 
> 
> } 
> catch (FileUploadException e) { 
> System.out.println(e.getMessage()); 
> System.out.println("Exception:-) 
> --------->>>>>>"); 
> } 
> if(items!=null){ 
> System.out.println("Nach Try Upload ... 
> ------->>>>>>"); 
> 
> Iterator itr = items.iterator(); 
> 
> 
> while (itr.hasNext()) { 
> FileItem item = (FileItem) itr.next(); 
> 
> if (item.isFormField()){ 
> n=item.getFieldName(); 
> if(n.equalsIgnoreCase("jsessionid"
> )){ 
> v=item.getString(); 
> 
> } 
> else if(n.equalsIgnoreCase(
> "ueberschrift")){ 
> v=item.getString(); 
> paramContainer.setUeberschrift(v); 
> } 
> else if(n.equalsIgnoreCase(
> "neuigkeit")){ 
> v=item.getString(); 
> paramContainer.setNeuigkeit(v); 
> } 
> else if(n.equalsIgnoreCase(
> "publizieren")){ 
> v=item.getString(); 
> paramContainer.setPublizieren(v); 
> } 
> else if(n.equalsIgnoreCase(
> "newsbw")){ 
> v=item.getString(); 
> paramContainer.setNewsbw(v); 
> } 
> else if(n.equalsIgnoreCase(
> "newsuan")){ 
> v=item.getString(); 
> paramContainer.setNewsuan(v); 
> } 
> else if(n.equalsIgnoreCase(
> "loeschkennzeichen")){ 
> v=item.getString(); 
> paramContainer.setLoeschkennzeichen(v); 
> } 
> else if(n.equalsIgnoreCase(
> "newsuansendmail")){ 
> v=item.getString(); 
> paramContainer.setNewsuansendmail(v); 
> } 
> else if(n.equalsIgnoreCase(
> "hiddenNewsId")){ 
> v=item.getString(); 
> paramContainer.setHiddenNewsId(Integer.parseInt(v)); 
> } 
> else if(n.equalsIgnoreCase(
> "servletName")){ 
> v=item.getString(); 
> paramContainer.setServletName(v); 
> } 
> } 
> else{ 
> System.out.println(
> "-----------------------------------------------"); 
> System.out.println("Es handelt 
> sich um eine Datei ..."); 
> String itemName = item.getName(); 
 
> 
> try{ 
> System.out.println("Datei 

> speichern ..."); 
> InputStream is = 
> item.getInputStream(); 
> 
> paramContainer.setFileNews(is); 
> } 
> catch (Exception e){ 
> System.out.println("Datei 

> speichern mißlungen ..."); 
> System.out
> .println(e.getMessage()); 
> System.out.println(
> "Exception:-) --------->>>>>>"); 
> } 
> } 
> } 
> 
> 
> ====================================================
> HIL Heeresinstandsetzungslogistik GmbH
> Sitz Bonn
> Amtsgericht-Registergericht-Bonn - HRB 13651
> Geschäftsführer: Ulrich Frieling (Sprecher), Günter Schwarz
> Aufsichtsratsvorsitzender: Willi Walgenbach


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org





====================================================
HIL Heeresinstandsetzungslogistik GmbH
Sitz Bonn
Amtsgericht-Registergericht-Bonn - HRB 13651
Geschäftsführer: Ulrich Frieling (Sprecher), Günter Schwarz
Aufsichtsratsvorsitzender: Willi Walgenbach

--=_alternative 00493CD6C12577C0_=--


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic