You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@archiva.apache.org by Brett Porter <br...@apache.org> on 2007/10/16 08:23:38 UTC

Re: svn commit: r584986 - /maven/archiva/trunk/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/repository/ProxiedDavServer.java

This couldn't be fixed in the webdav library, since there are related  
changes being made there already?

Cheers,
Brett

On 16/10/2007, at 8:52 AM, joakime@apache.org wrote:

> Author: joakime
> Date: Mon Oct 15 17:52:42 2007
> New Revision: 584986
>
> URL: http://svn.apache.org/viewvc?rev=584986&view=rev
> Log:
> [MRM-468] incorrect URL reported from failures in WebDAV
> Corrected locally the error message being reported by it.could.webdav
>
>
> Modified:
>     maven/archiva/trunk/archiva-web/archiva-webapp/src/main/java/ 
> org/apache/maven/archiva/web/repository/ProxiedDavServer.java
>
> Modified: maven/archiva/trunk/archiva-web/archiva-webapp/src/main/ 
> java/org/apache/maven/archiva/web/repository/ProxiedDavServer.java
> URL: http://svn.apache.org/viewvc/maven/archiva/trunk/archiva-web/ 
> archiva-webapp/src/main/java/org/apache/maven/archiva/web/ 
> repository/ProxiedDavServer.java? 
> rev=584986&r1=584985&r2=584986&view=diff
> ====================================================================== 
> ========
> --- maven/archiva/trunk/archiva-web/archiva-webapp/src/main/java/ 
> org/apache/maven/archiva/web/repository/ProxiedDavServer.java  
> (original)
> +++ maven/archiva/trunk/archiva-web/archiva-webapp/src/main/java/ 
> org/apache/maven/archiva/web/repository/ProxiedDavServer.java Mon  
> Oct 15 17:52:42 2007
> @@ -46,6 +46,7 @@
>  import java.io.FileNotFoundException;
>  import java.io.FileReader;
>  import java.io.IOException;
> +import java.io.PrintWriter;
>
>  import javax.servlet.ServletConfig;
>  import javax.servlet.ServletException;
> @@ -161,7 +162,64 @@
>
>          // TODO: [MRM-524] determine http caching options for  
> other types of files (artifacts, sha1, md5, snapshots)
>
> -        davServer.process( request, response );
> +        if( resourceExists( request ) )
> +        {
> +            davServer.process( request, response );
> +        }
> +        else
> +        {
> +            respondResourceMissing( request, response );
> +        }
> +    }
> +
> +    private void respondResourceMissing( DavServerRequest request,  
> HttpServletResponse response )
> +    {
> +        response.setStatus( HttpServletResponse.SC_NOT_FOUND );
> +
> +        try
> +        {
> +            StringBuffer missingUrl = new StringBuffer();
> +            missingUrl.append( request.getRequest().getScheme 
> () ).append( "://" );
> +            missingUrl.append( request.getRequest().getServerName 
> () ).append( ":" );
> +            missingUrl.append( request.getRequest().getServerPort 
> () );
> +            missingUrl.append( request.getRequest().getServletPath 
> () );
> +            // missingUrl.append( request.getRequest().getPathInfo 
> () );
> +
> +            String message = "Error 404 Not Found";
> +
> +            PrintWriter out = new PrintWriter 
> ( response.getOutputStream() );
> +
> +            response.setContentType( "text/html; charset=\"UTF-8 
> \"" );
> +
> +            out.println( "<html>" );
> +            out.println( "<head><title>" + message + "</title></ 
> head>" );
> +            out.println( "<body>" );
> +
> +            out.print( "<p><h1>" );
> +            out.print( message );
> +            out.println( "</h1></p>" );
> +
> +            out.print( "<p>The following resource does not exist:  
> <a href=\"" );
> +            out.print( missingUrl.toString() );
> +            out.println( "\">" );
> +            out.print( missingUrl.toString() );
> +            out.println( "</a></p>" );
> +
> +            out.println( "</body></html>" );
> +
> +            out.flush();
> +        }
> +        catch ( IOException e )
> +        {
> +            e.printStackTrace();
> +        }
> +    }
> +
> +    private boolean resourceExists( DavServerRequest request )
> +    {
> +        String resource = request.getLogicalResource();
> +        File resourceFile = new File( managedRepository.getRepoRoot 
> (), resource );
> +        return resourceFile.exists();
>      }
>
>      private void fetchContentFromProxies( DavServerRequest request )
>

--
Brett Porter - brett@apache.org
Blog: http://www.devzuz.org/blogs/bporter/

Re: svn commit: r584986 - /maven/archiva/trunk/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/repository/ProxiedDavServer.java

Posted by Joakim Erdfelt <jo...@erdfelt.com>.
I traced this bug down to the the plexus-webdav code to this line.

this.base.lookup( resource ).toAsciiString();

base is a URI object, resource is the relative path (String) to the 
resource.
At first look, this appears to be a bug in the java.net.URI object!!
(or at least an unexpected response from that object)

It was easier to put the logic on the archiva side.
Also, we can use the work from MRM-490 to make this a more pretty error. ;-)

- Joakim

Brett Porter wrote:
> This couldn't be fixed in the webdav library, since there are related 
> changes being made there already?
>
> Cheers,
> Brett
>
> On 16/10/2007, at 8:52 AM, joakime@apache.org wrote:
>
>> Author: joakime
>> Date: Mon Oct 15 17:52:42 2007
>> New Revision: 584986
>>
>> URL: http://svn.apache.org/viewvc?rev=584986&view=rev
>> Log:
>> [MRM-468] incorrect URL reported from failures in WebDAV
>> Corrected locally the error message being reported by it.could.webdav
>>
>>
>> Modified:
>>     
>> maven/archiva/trunk/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/repository/ProxiedDavServer.java 
>>
>>
>> Modified: 
>> maven/archiva/trunk/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/repository/ProxiedDavServer.java 
>>
>> URL: 
>> http://svn.apache.org/viewvc/maven/archiva/trunk/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/repository/ProxiedDavServer.java?rev=584986&r1=584985&r2=584986&view=diff 
>>
>> ============================================================================== 
>>
>> --- 
>> maven/archiva/trunk/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/repository/ProxiedDavServer.java 
>> (original)
>> +++ 
>> maven/archiva/trunk/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/repository/ProxiedDavServer.java 
>> Mon Oct 15 17:52:42 2007
>> @@ -46,6 +46,7 @@
>>  import java.io.FileNotFoundException;
>>  import java.io.FileReader;
>>  import java.io.IOException;
>> +import java.io.PrintWriter;
>>
>>  import javax.servlet.ServletConfig;
>>  import javax.servlet.ServletException;
>> @@ -161,7 +162,64 @@
>>
>>          // TODO: [MRM-524] determine http caching options for other 
>> types of files (artifacts, sha1, md5, snapshots)
>>
>> -        davServer.process( request, response );
>> +        if( resourceExists( request ) )
>> +        {
>> +            davServer.process( request, response );
>> +        }
>> +        else
>> +        {
>> +            respondResourceMissing( request, response );
>> +        }
>> +    }
>> +
>> +    private void respondResourceMissing( DavServerRequest request, 
>> HttpServletResponse response )
>> +    {
>> +        response.setStatus( HttpServletResponse.SC_NOT_FOUND );
>> +
>> +        try
>> +        {
>> +            StringBuffer missingUrl = new StringBuffer();
>> +            missingUrl.append( request.getRequest().getScheme() 
>> ).append( "://" );
>> +            missingUrl.append( request.getRequest().getServerName() 
>> ).append( ":" );
>> +            missingUrl.append( request.getRequest().getServerPort() );
>> +            missingUrl.append( request.getRequest().getServletPath() );
>> +            // missingUrl.append( request.getRequest().getPathInfo() );
>> +
>> +            String message = "Error 404 Not Found";
>> +
>> +            PrintWriter out = new PrintWriter( 
>> response.getOutputStream() );
>> +
>> +            response.setContentType( "text/html; charset=\"UTF-8\"" );
>> +
>> +            out.println( "<html>" );
>> +            out.println( "<head><title>" + message + 
>> "</title></head>" );
>> +            out.println( "<body>" );
>> +
>> +            out.print( "<p><h1>" );
>> +            out.print( message );
>> +            out.println( "</h1></p>" );
>> +
>> +            out.print( "<p>The following resource does not exist: <a 
>> href=\"" );
>> +            out.print( missingUrl.toString() );
>> +            out.println( "\">" );
>> +            out.print( missingUrl.toString() );
>> +            out.println( "</a></p>" );
>> +
>> +            out.println( "</body></html>" );
>> +
>> +            out.flush();
>> +        }
>> +        catch ( IOException e )
>> +        {
>> +            e.printStackTrace();
>> +        }
>> +    }
>> +
>> +    private boolean resourceExists( DavServerRequest request )
>> +    {
>> +        String resource = request.getLogicalResource();
>> +        File resourceFile = new File( 
>> managedRepository.getRepoRoot(), resource );
>> +        return resourceFile.exists();
>>      }
>>
>>      private void fetchContentFromProxies( DavServerRequest request )
>>
>
> -- 
> Brett Porter - brett@apache.org
> Blog: http://www.devzuz.org/blogs/bporter/
>


-- 
- Joakim Erdfelt
  joakim@erdfelt.com
  Open Source Software (OSS) Developer