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

List:       slide-dev
Subject:    Re: cvs commit: jakarta-slide/src/webdav/server/org/apache/slide/webdav/method LockMethod.java PropF
From:       Martin Gronberg <martyg () everest ! com>
Date:       2001-01-31 19:38:10
[Download RAW message or body]

In WebdavMethod.readRequestContent(), the old version used to use reader 
and catch IOException - new version uses static 
NodeRevisionContent.readFromStream() method.  In the case where an 
IOException is thrown within the readFromStream() method, it catches it 
and returns 'null'.  I was using Enhydra 3.1 to test this release (we 
have some patches that make it work with the previous code) and now I'm 
getting 'java.lang.NullPointerException' because there is no checking 
for the null case within WebdavMethod.readRequestContent().

Is there a reason readFromStream() doesn't just throw the IOException?  
I can submit a patch for this by just updating readRequestContent() to 
check for the null case and report it as a likely IOException, however, 
the exception information is lost.   Seems like it would be better to 
have readFromStream() go ahead and throw the exception or at least 
report it.  Any thoughts? 

   Marty

juergen@apache.org wrote:

> juergen     01/01/29 04:18:11
> 
> Modified:    src/webdav/server/org/apache/slide/webdav/method
> LockMethod.java PropFindMethod.java
> PropPatchMethod.java WebdavMethod.java
> Log:
> if the body of a propfind method was coded in utf-8, the body was not properly \
> decoded by the Reader wrapper.. Now a Stream is used and the bytes are converted to \
> a String using the right encoding. Remy, isn't this a reader bug in Tomcat? The \
> encoding stays quoted in speachmarks, do we want to change this? [...]
> @@ -427,31 +427,28 @@
> return;
> 
> // TODO : Modify this and make it chunking aware
> -        
> -        int contentLength = req.getContentLength();
> -        
> -        char[] result = null;
> 
> -        if (contentLength > 0) {
> -            try {
> -                BufferedReader reader = null;
> -                requestBody = new char[contentLength];
> -                int position = 0;
> -                reader = req.getReader();
> -                while (position < contentLength) {
> -                    int nChar = reader.read(requestBody, position,
> -                                            contentLength - position);
> -                    position = position + nChar;
> -                }
> -                reader.close();
> -            } catch (IOException e) {
> -                System.out.println(e.getMessage());
> -            } catch (RuntimeException e) {
> -                e.printStackTrace();
> -            }
> +        try {
> +            requestBody = new \
> String(NodeRevisionContent.readFromStream(req.getInputStream()), +                  \
> getEncodingString(req.getCharacterEncoding())); }
> +        catch (Exception e) { e.printStackTrace();}
> +
> 
> }
> +
> +    
> +    
> +    /**
> +     * Translate the encoding string into a proper Java encoding String.
> +     */
> +    public static String getEncodingString(String httpEncoding) {
> +        String result = httpEncoding;
> +        if (result == null) result = System.getProperty("file.encoding");
> +        if (result.startsWith("\"")) result = result.substring(1, \
> result.length()); +        if (result.endsWith("\""))   result = \
> result.substring(0, result.length()-1); +        return result;
> +    }
> 
> 
> [...]


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

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