]> source.dussan.org Git - archiva.git/commitdiff
[MRM-468] incorrect URL reported from failures in WebDAV
authorJoakim Erdfelt <joakime@apache.org>
Tue, 16 Oct 2007 00:52:42 +0000 (00:52 +0000)
committerJoakim Erdfelt <joakime@apache.org>
Tue, 16 Oct 2007 00:52:42 +0000 (00:52 +0000)
Corrected locally the error message being reported by it.could.webdav

git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/trunk@584986 13f79535-47bb-0310-9956-ffa450edef68

archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/repository/ProxiedDavServer.java

index 39bfe9b26a8e3492933130fe6ceee3d21976acc3..07b58c5bb6cc67e5242d50848e4cb0f074d68bdc 100644 (file)
@@ -46,6 +46,7 @@ import java.io.File;
 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 @@ public class ProxiedDavServer
 
         // 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 )