Project

General

Profile

« Previous | Next » 

Revision 798

Modified Metacat to support large data file uploads. This is accomplished
by supporting a new content type for data sent to metacat:
multipart/form-data
which allows multiple files to be sent in a standard MIME format. The
MetacatServlet.handleGetOrPost() method now checks the incoming content
type and sends multipart/form-data encoded submissions to
MetacatServlet.handleMultipartForm(), which in turn delegates to
MetacatServlet.handleUploadAction(). When a client wants to load a data
file to metacat, now create a "multipart/form-data" encoded stream that
contains an "action" parameter set to the value "upload", a "docid"
parameter set to the value of the accession number fro the file, and
a "datafile" part that contains the actual file contents. Because of a
bug / shortcoming in the com.oreilly.servlet library that I am using to parse
this mime encoding, the "action" and "docid" paramters MUST come before
the "datafile" part or metacat won't find the paramters.

The provided docid is inserted into xml_documents (after checking that it
meets expectations [unique, rev 1, etc]). Then the data file
recieved from the "upload" action is stored on the filesystem
using the Accession number provided in the docid. See
DocumentImpl.registerDocument for details.

This functionality completely replaces the socket-based functionality found
in DataFileUploadInterface and DataFileServer. It would still be nice to
abstract away the file storage functions so that they can be either written
to the filesystem or other locations (like the db ina BLOB) when they are
recieved in this new encoding format.

There are concomitant changes in Morpho to produce these types of file uploads.
Morpho now uses the HTTPClient library for http communication, which
allows streaming data between client and server (Sun's http protocol
handler buffers all data before sending, which limits data transfer size
to memory available). No changes in metacat were needed to accomodate this
switch of protocol handlers on the client side; all changes were due to the
need for an alternative data encoding (other than URL encoding) that
efficiently supports binary files).

The cos.jar file is now needed for parsing the new encoding.

View differences:

DocumentImpl.java
37 37
import java.io.Writer;
38 38
import java.io.InputStreamReader;
39 39

  
40
import java.text.SimpleDateFormat;
41

  
42
import java.util.Date;
40 43
import java.util.Iterator;
41 44
import java.util.Stack;
42 45
import java.util.TreeSet;
......
168 171
    writeDocumentToDB(action, user, pub, catalogid, serverCode);
169 172
  }
170 173
  
171
// NOT USED ANY MORE
172
//  public DocumentImpl(Connection conn, long rootnodeid, String docname, 
173
//                      String doctype, String docid, String action, String user)
174
//                      throws SQLException, Exception
175
//  {
176
//    this.conn = conn;
177
//    this.rootnodeid = rootnodeid;
178
//    this.docname = docname;
179
//    this.doctype = doctype;
180
//    this.docid = docid;
181
//    writeDocumentToDB(action, user);
182
//  }
174
  /**
175
   * Register a document that resides on the filesystem with the database.
176
   * (ie, just an entry in xml_documents, nothing in xml_nodes).
177
   * Creates a reference to a filesystem document (used for non-xml data files).
178
   *
179
   * @param conn the JDBC Connection to which all information is written
180
   * @param docname - the name of DTD, i.e. the name immediately following 
181
   *        the DOCTYPE keyword ( should be the root element name ) or
182
   *        the root element name if no DOCTYPE declaration provided
183
   *        (Oracle's and IBM parsers are not aware if it is not the 
184
   *        root element name)
185
   * @param doctype - Public ID of the DTD, i.e. the name immediately 
186
   *                  following the PUBLIC keyword in DOCTYPE declaration or
187
   *                  the docname if no Public ID provided or
188
   *                  null if no DOCTYPE declaration provided
189
   * @param accnum the accession number to use for the INSERT OR UPDATE, which 
190
   *               includes a revision number for this revision of the document 
191
   *               (e.g., knb.1.1)
192
   * @param user the user that owns the document
193
   * @param serverCode the serverid from xml_replication on which this document
194
   *        resides.
195
   */
196
  public static void registerDocument(
197
                     String docname, String doctype, String accnum, 
198
                     String user, int serverCode)
199
                     throws SQLException, AccessionNumberException, Exception
200
  {
201
    Connection dbconn = null;
202
    MetaCatUtil util = new MetaCatUtil();
183 203

  
204
    try {
205
      dbconn = util.openDBConnection();
206

  
207
      AccessionNumber ac = new AccessionNumber(dbconn, accnum, "insert");
208
      String docid = ac.getDocid();
209
      String rev = ac.getRev();
210
  
211
      SimpleDateFormat formatter = new SimpleDateFormat ("yy-MM-dd HH:mm:ss");
212
      Date localtime = new Date();
213
      String dateString = formatter.format(localtime);
214
  
215
      String sqlDateString = "to_date('" + dateString + "', 'YY-MM-DD HH24:MI:SS')";
216
  
217
      StringBuffer sql = new StringBuffer();
218
      sql.append("insert into xml_documents (docid, docname, doctype, ");
219
      sql.append("user_owner, user_updated, server_location, rev, date_created");
220
      sql.append(", date_updated, public_access) values ('");
221
      sql.append(docid).append("','");
222
      sql.append(docname).append("','");
223
      sql.append(doctype).append("','");
224
      sql.append(user).append("','");
225
      sql.append(user).append("','");
226
      sql.append(serverCode).append("','");
227
      sql.append(rev).append("',");
228
      sql.append(sqlDateString).append(",");
229
      sql.append(sqlDateString).append(",");
230
      sql.append("'0')");
231
      //System.out.println("sql: " + sql.toString());
232

  
233
      PreparedStatement pstmt = dbconn.prepareStatement(sql.toString());
234
      pstmt.execute();
235
      pstmt.close();
236
      dbconn.close();
237
    } finally {
238
      util.returnConnection(dbconn);
239
    }    
240
  }
241

  
184 242
  /**
185 243
   * get the document name
186 244
   */

Also available in: Unified diff