Commits

Daniel Blezek  committed b8068f9

All is working on the WebDAV side, but HTTP is broken (currently)

  • Participants
  • Parent commits a545cb3

Comments (0)

Files changed (8)

File Source/org/xnat/xnatfs/webdav/Bundle.java

 import net.sf.ehcache.Element;
 
 import org.apache.http.HttpEntity;
+import org.apache.log4j.Logger;
 import org.json.JSONArray;
 import org.json.JSONObject;
 import org.json.JSONTokener;
  * 
  */
 public class Bundle extends VirtualDirectory {
+  final static Logger logger = Logger.getLogger ( Bundle.class );
 
   /**
    * @param x
       }
 
       long size = Long.valueOf ( s.get ( childName ).get ( 1 ) ).longValue ();
-      RemoteFile remote = new RemoteFile ( xnatfs, mAbsolutePath, childName, mURL + "resources/" + childName, size );
+      RemoteFile remote = new RemoteFile ( xnatfs, mAbsolutePath, childName, mURL + "files/" + childName, size );
       Element element = new Element ( childPath, remote );
       XNATFS.sNodeCache.put ( element );
       return (Resource) element.getObjectValue ();

File Source/org/xnat/xnatfs/webdav/Experiment.java

 
 import net.sf.ehcache.Element;
 
+import org.apache.log4j.Logger;
+
 import com.bradmcevoy.http.Resource;
 
 /**
  * 
  */
 public class Experiment extends VirtualDirectory {
+  final static Logger logger = Logger.getLogger ( Experiment.class );
 
   /**
    * @param x

File Source/org/xnat/xnatfs/webdav/Node.java

  */
 package org.xnat.xnatfs.webdav;
 
-import java.io.Serializable;
 import java.util.Date;
 import java.util.List;
 
  * @author blezek
  * 
  */
-public abstract class Node implements Serializable, CollectionResource {
+public abstract class Node implements CollectionResource {
   protected String mPath;
   protected String mName;
   final XNATFS factory;
    * com.bradmcevoy.http.Resource#checkRedirect(com.bradmcevoy.http.Request)
    */
   public String checkRedirect ( Request request ) {
-    // TODO Auto-generated method stub
     return null;
   }
 

File Source/org/xnat/xnatfs/webdav/Project.java

 
 import net.sf.ehcache.Element;
 
+import org.apache.log4j.Logger;
+
 import com.bradmcevoy.http.Resource;
 
 /**
  * 
  */
 public class Project extends VirtualDirectory {
+  final static Logger logger = Logger.getLogger ( Project.class );
 
   /**
    * @param x
   @Override
   public Resource child ( String childName ) {
     logger.debug ( "child: create " + childName );
-    String childPath = mAbsolutePath + childName;
+    String childPath = mAbsolutePath + "/" + childName;
     HashSet<String> s = null;
     try {
       s = getElementList ( mElementURL, mChildKey );
     if ( s.contains ( childName ) ) {
       // Look up in the cache
       if ( XNATFS.sNodeCache.get ( childPath ) != null ) {
+        logger.debug ( "Found child: " + childName + " in the cache" );
         return (Resource) ( XNATFS.sNodeCache.get ( childPath ).getObjectValue () );
       }
       Element element = new Element ( childPath, new Subject ( xnatfs, mAbsolutePath, childName, mURL + "subjects/" + childName + "/" ) );
+      logger.debug ( "Created new subject " + mAbsolutePath + " " + childName + " as " + mURL );
       XNATFS.sNodeCache.put ( element );
       return (Resource) element.getObjectValue ();
     }

File Source/org/xnat/xnatfs/webdav/RemoteFile.java

       logger.error ( "getContents: Waiting for download failed", e );
       throw new IOException ( e.getLocalizedMessage () );
     }
-    return new FileInputStream ( mFile.getFD () );
+    logger.debug ( "getContents: sending FileInputStream from file: " + mCachedFile );
+    return new FileInputStream ( mCachedFile );
   }
 
   public void sendContent ( OutputStream out, Range range, Map<String, String> params, String contentType ) throws IOException, NotAuthorizedException {
         end = range.getFinish ();
       }
 
+      if ( mContentLength != mChannel.size () ) {
+        logger.error ( "The channel does not have the proper size" );
+        throw new IOException ( "The cached file is not the expected size" );
+      }
+
       // Seek to beginning of read
       in.skip ( start );
       long position = start;
         byte[] BackingBuffer = new byte[4096];
         ByteBuffer buffer = ByteBuffer.wrap ( BackingBuffer );
         InputStream in = entity.getContent ();
-        logger.debug ( "Fetching remote object " + mURL + " as virtual file " + mPath + " into real file " );
+        logger.debug ( "Fetching remote object " + mURL + " as virtual file " + mPath + " into real file " + mCachedFile );
         while ( true ) {
           int readCount = in.read ( BackingBuffer );
           if ( Thread.currentThread ().isInterrupted () ) {
       }
       Element n = new Element ( mAbsolutePath, mCachedFile );
       XNATFS.sContentCache.put ( n );
-      logger.debug ( "Cached " + mAbsolutePath );
+      logger.debug ( "Finished caching " + mAbsolutePath + " from " + mURL );
       return Boolean.TRUE;
     }
   }

File Source/org/xnat/xnatfs/webdav/VirtualDirectory.java

       logger.debug ( "got Child " + child );
       list.add ( child ( child ) );
     }
-    list.add ( child ( "Image1.dcm" ) );
-    list.add ( child ( "Image2.dcm" ) );
     return list;
   }
 
     w.open ( "body" );
     w.begin ( "h1" ).open ().writeText ( this.getName () ).close ();
     w.open ( "table" );
-    for ( Resource r : getChildren () ) {
-      if ( r == null ) {
-        logger.error ( "Child is null!" );
+    for ( Resource rr : getChildren () ) {
+      if ( rr == null || !( rr instanceof VirtualResource ) ) {
+        logger.error ( "Child is null or not a VirtualResource!" );
       } else {
+        VirtualResource r = (VirtualResource) rr;
         w.open ( "tr" );
 
         w.open ( "td" );
-        w.begin ( "a" ).writeAtt ( "href", r.getName () ).open ().writeText ( r.getName () ).close ();
+        w.begin ( "a" ).writeAtt ( "href", r.getAbsolutePath ().replaceFirst ( "/", "" ) ).open ().writeText ( r.getName () ).close ();
+        logger.debug ( "sendContent: added reference " + r.getName () + " to href " + r.getAbsolutePath ().replaceFirst ( "/", "" ) );
         w.close ( "td" );
 
         w.begin ( "td" ).open ().writeText ( r.getModifiedDate () + "" ).close ();
       JSONTokener tokenizer = new JSONTokener ( reader );
       JSONObject json = new JSONObject ( tokenizer );
       JSONArray subjects = json.getJSONObject ( "ResultSet" ).getJSONArray ( "Result" );
-      logger.debug ( "Found: " + subjects.length () + " elements" );
+      // logger.debug ( "Found: " + subjects.length () + " elements" );
       for ( int idx = 0; idx < subjects.length (); idx++ ) {
         if ( subjects.isNull ( idx ) ) {
           continue;
         String id = null;
         if ( inKey != null ) {
           id = subjects.getJSONObject ( idx ).getString ( inKey );
-          logger.debug ( "Found " + id + " from " + inKey );
+          // logger.debug ( "Found " + id + " from " + inKey );
         }
         if ( id == null ) {
           id = subjects.getJSONObject ( idx ).getString ( mChildKey );

File Source/org/xnat/xnatfs/webdav/VirtualResource.java

 
 import java.util.Date;
 
+import org.apache.log4j.Logger;
+
 import com.bradmcevoy.http.Auth;
 import com.bradmcevoy.http.PropFindableResource;
 import com.bradmcevoy.http.Request;
 import com.bradmcevoy.http.Request.Method;
 
 public abstract class VirtualResource implements Resource, PropFindableResource {
+  final static Logger logger = Logger.getLogger ( VirtualResource.class );
+
   public static final Date mDate = new Date ();
   String mPath;
   String mName;
         mAbsolutePath = path + "/" + mName;
       }
     }
+    logger.debug ( "Created virtual resource with name " + mName + " path " + mPath + " absolute Path " + mAbsolutePath );
   }
 
   /*
     return mName;
   }
 
+  public String getAbsolutePath () {
+    return mAbsolutePath;
+  }
+
   /*
    * (non-Javadoc)
    * 

File Source/org/xnat/xnatfs/webdav/xnatfsServlet.java

  */
 package org.xnat.xnatfs.webdav;
 
-import java.io.File;
 import java.io.IOException;
-import java.net.URL;
 
 import javax.servlet.Servlet;
 import javax.servlet.ServletConfig;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
-import org.apache.log4j.BasicConfigurator;
-import org.apache.log4j.PropertyConfigurator;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;