[Mulgara-svn] r1492 - in trunk/src/jar: content-mbox/java/org/mulgara/content/mbox/parser/model/impl query/java/org/mulgara/query/operation query/java/org/mulgara/server querylang/java/org/mulgara/itql querylang/java/org/mulgara/protocol/http resolver/java/org/mulgara/resolver server-rmi/java/org/mulgara/server/rmi web/java/org/mulgara/webquery

pag at mulgara.org pag at mulgara.org
Fri Feb 13 07:12:25 UTC 2009


Author: pag
Date: 2009-02-12 23:12:24 -0800 (Thu, 12 Feb 2009)
New Revision: 1492

Modified:
   trunk/src/jar/content-mbox/java/org/mulgara/content/mbox/parser/model/impl/MBoxManagerImpl.java
   trunk/src/jar/query/java/org/mulgara/query/operation/DataTx.java
   trunk/src/jar/query/java/org/mulgara/query/operation/Load.java
   trunk/src/jar/query/java/org/mulgara/server/Session.java
   trunk/src/jar/querylang/java/org/mulgara/itql/ItqlInterpreterBean.java
   trunk/src/jar/querylang/java/org/mulgara/itql/ItqlInterpreterBeanUnitTest.java
   trunk/src/jar/querylang/java/org/mulgara/protocol/http/ProtocolServlet.java
   trunk/src/jar/resolver/java/org/mulgara/resolver/DatabaseOperationContext.java
   trunk/src/jar/resolver/java/org/mulgara/resolver/DatabaseSession.java
   trunk/src/jar/resolver/java/org/mulgara/resolver/SetGraphOperation.java
   trunk/src/jar/server-rmi/java/org/mulgara/server/rmi/RemoteSession.java
   trunk/src/jar/server-rmi/java/org/mulgara/server/rmi/RemoteSessionWrapperSession.java
   trunk/src/jar/server-rmi/java/org/mulgara/server/rmi/SessionWrapperRemoteSession.java
   trunk/src/jar/web/java/org/mulgara/webquery/QueryServlet.java
Log:
Punched a hole through the APIs to expose MIME content types. This allows a content type to be specified with an InputStream, meaning that bogus URIs with filename extensions are no longer needed to indicate the type of data in the stream

Modified: trunk/src/jar/content-mbox/java/org/mulgara/content/mbox/parser/model/impl/MBoxManagerImpl.java
===================================================================
--- trunk/src/jar/content-mbox/java/org/mulgara/content/mbox/parser/model/impl/MBoxManagerImpl.java	2009-02-13 07:08:14 UTC (rev 1491)
+++ trunk/src/jar/content-mbox/java/org/mulgara/content/mbox/parser/model/impl/MBoxManagerImpl.java	2009-02-13 07:12:24 UTC (rev 1492)
@@ -27,14 +27,7 @@
 
 package org.mulgara.content.mbox.parser.model.impl;
 
-import java.io.InputStream;
-import java.net.URI;
-import java.util.ArrayList;
-
 import org.apache.log4j.*;
-import org.jrdf.graph.Graph;
-import org.jrdf.graph.mem.GraphImpl;
-import org.jrdf.graph.GraphException;
 
 import org.mulgara.content.Content;
 import org.mulgara.content.mbox.parser.model.*;
@@ -64,25 +57,16 @@
   /** Logger */
   private static Logger logger = Logger.getLogger(MBoxManagerImpl.class);
 
-  /** The arraylist to use as the cache */
-  private ArrayList cache;
-
   /** The current mbox we are dealing with */
   private MBox currentMBox;
 
   public MBoxManagerImpl() {
-
-    // Initialise the cache
-    cache = new ArrayList();
   }
 
   /**
    * Clears the cache of all stored mboxes.
    */
   public void clear() {
-
-    // Clear the array list
-    cache.clear();
   }
 
   /**
@@ -91,9 +75,6 @@
    * @param mbox The mbox to remove
    */
   public void delete(MBox mbox) throws ModelException {
-
-    // Remove the mbox
-    cache.remove(mbox.getURI().toString());
   }
 
   /**
@@ -110,9 +91,6 @@
    */
   public MBox getMBox(Content content) throws ModelException {
 
-    // Container for the mbox we are creating
-    MBox mbox = null;
-
     if (currentMBox != null) {
 
       // If we have an existing current mbox, check if we are using the same one
@@ -146,7 +124,7 @@
     }
 
     // Create an array of the types for the mbox constructor
-    Class [] parameterTypes = new Class [] {Content.class};
+    Class<?> [] parameterTypes = new Class [] {Content.class};
 
     // Create an array of parameters for the mbox constructor
     Object [] parameters = new Object [] {content};

Modified: trunk/src/jar/query/java/org/mulgara/query/operation/DataTx.java
===================================================================
--- trunk/src/jar/query/java/org/mulgara/query/operation/DataTx.java	2009-02-13 07:08:14 UTC (rev 1491)
+++ trunk/src/jar/query/java/org/mulgara/query/operation/DataTx.java	2009-02-13 07:12:24 UTC (rev 1492)
@@ -71,6 +71,7 @@
     return source;
   }
 
+
   /**
    * @return the destination URI for the data.
    */

Modified: trunk/src/jar/query/java/org/mulgara/query/operation/Load.java
===================================================================
--- trunk/src/jar/query/java/org/mulgara/query/operation/Load.java	2009-02-13 07:08:14 UTC (rev 1491)
+++ trunk/src/jar/query/java/org/mulgara/query/operation/Load.java	2009-02-13 07:12:24 UTC (rev 1492)
@@ -14,7 +14,10 @@
 import java.io.IOException;
 import java.io.InputStream;
 import java.net.URI;
+import java.net.URISyntaxException;
 
+import javax.activation.MimeType;
+
 import org.apache.log4j.Logger;
 import org.mulgara.connection.Connection;
 import org.mulgara.query.GraphResource;
@@ -33,13 +36,13 @@
 
   /** The logger */
   static final Logger logger = Logger.getLogger(Load.class.getName());
-  
-  /** Dummy source model URI to pass to the server when overriding with local stream. */
-  protected static final URI DUMMY_RDF_SOURCE = URI.create(Mulgara.NAMESPACE+"locally-sourced-inputStream.rdf");
-  
+
   /** Graph resource form of the source URI */
   private final GraphResource srcRsc;
-  
+
+  /** The type of data that may be in a stream. */
+  private MimeType contentType;
+
   /**
    * Build a load operation, loading data from one URI into a graph specified by another URI.
    * @param source The URI of the source of the RDF data.
@@ -52,7 +55,8 @@
     // Validate arguments.
     if (graphURI == null) throw new IllegalArgumentException("Need a valid destination graph URI");
     
-    srcRsc = new GraphResource(source == null ? DUMMY_RDF_SOURCE : source);
+    srcRsc = source == null ? null : new GraphResource(source);
+    contentType = null;
   }
 
 
@@ -60,12 +64,27 @@
    * Alternate constructor for creating a load operation whose source will be a local input stream.
    * @param graphURI The URI of the graph to receive the data.
    * @param stream The local input stream that is the source of data to load.
+   * @param contentType the content type for the stream.
    */
-  public Load(URI graphURI, InputStream stream) {
+  public Load(URI graphURI, InputStream stream, MimeType contentType) {
     this(null, graphURI, true);
     setOverrideInputStream(stream);
+    this.contentType = contentType;
   }
 
+  /**
+   * Alternate constructor for creating a load operation whose source will be a local input stream,
+   * and a filename has been provided. The filename is for informative purposes only.
+   * @param graphURI The URI of the graph to receive the data.
+   * @param stream The local input stream that is the source of data to load.
+   * @param contentType the content type for the stream.
+   * @param fileUri
+   */
+  public Load(URI graphURI, InputStream stream, MimeType contentType, String file) {
+    this(toUri(file), graphURI, true);
+    setOverrideInputStream(stream);
+    this.contentType = contentType;
+  }
 
   /**
    * Load the data into the destination graph through the given connection.
@@ -104,7 +123,7 @@
    */
   @Override
   protected Long doTx(Connection conn, InputStream inputStream) throws QueryException {
-    return conn.getSession().setModel(inputStream, getDestination(), srcRsc);
+    return conn.getSession().setModel(inputStream, getDestination(), srcRsc, contentType);
   }
 
 
@@ -118,4 +137,18 @@
     return text;
   }
 
+
+  /**
+   * Attempt to turn a filename into a URI. If unsuccessful return null.
+   * @param filename
+   * @return
+   */
+  private static URI toUri(String filename) {
+    if (filename == null) return null;
+    try {
+      return new URI(Mulgara.VIRTUAL_NS + filename);
+    } catch (URISyntaxException e) {
+      return null;
+    }
+  }
 }

Modified: trunk/src/jar/query/java/org/mulgara/server/Session.java
===================================================================
--- trunk/src/jar/query/java/org/mulgara/server/Session.java	2009-02-13 07:08:14 UTC (rev 1491)
+++ trunk/src/jar/query/java/org/mulgara/server/Session.java	2009-02-13 07:12:24 UTC (rev 1492)
@@ -33,6 +33,8 @@
 import java.net.*;
 import java.util.*;
 import java.io.*;
+
+import javax.activation.MimeType;
 import javax.transaction.xa.XAResource;
 
 // Locally written packages
@@ -298,7 +300,7 @@
    * @throws QueryException if the model can't be modified
    */
   public long setModel(InputStream inputStream, URI uri,
-      GraphExpression graphExpression) throws QueryException;
+      GraphExpression graphExpression, MimeType contentType) throws QueryException;
 
   /**
    * Extract {@link Rules} from the data found in a model.

Modified: trunk/src/jar/querylang/java/org/mulgara/itql/ItqlInterpreterBean.java
===================================================================
--- trunk/src/jar/querylang/java/org/mulgara/itql/ItqlInterpreterBean.java	2009-02-13 07:08:14 UTC (rev 1491)
+++ trunk/src/jar/querylang/java/org/mulgara/itql/ItqlInterpreterBean.java	2009-02-13 07:12:24 UTC (rev 1492)
@@ -41,6 +41,7 @@
 import java.util.List;
 import java.util.Map;
 
+import javax.activation.MimeType;
 import javax.xml.soap.SOAPException;
 
 import org.apache.axis.utils.DOM2Writer;
@@ -104,7 +105,10 @@
    * TODO: Bring this into line with the Mulgara.NAMESPACE, which may break existing client.
    */
   private final static String TQL_NS = "http://mulgara.org/tql#";
-  
+
+  /** A dummy URI to be used when none is provided on a data source. */
+  private final static URI DUMMY_RDF_URI = URI.create("http://dummy/data.rdf");
+
   /** The ITQL interpreter Bean. */
   private final TqlAutoInterpreter interpreter = new TqlAutoInterpreter();
   
@@ -301,7 +305,6 @@
    * @param name the name of the transaction ( debug purposes only ) *
    * @throws QueryException Unable to commit one of the connections.
    */
-  @SuppressWarnings("deprecation")
   public void commit(String name) throws QueryException {
 
     if (log.isDebugEnabled()) log.debug("Commit transaction for :" + name);
@@ -316,7 +319,6 @@
    * @param name the name of the transaction ( debug purposes only ) *
    * @throws QueryException Unable to rollback one of the connections
    */
-  @SuppressWarnings("deprecation")
   public void rollback(String name) throws QueryException {
 
     log.warn("Rollback transaction for :" + name);
@@ -809,6 +811,30 @@
 
 
   /**
+   * Load the contents of an InputStream into a database/model.
+   * <p>Note. <var>destinationURI</var> must be a valid URI, and does not include
+   * the angle brackets (&lt; and &gt;) used to delimit URLs in iTQL.</p>
+   *
+   * @param inputStream a locally supplied inputstream.
+   * @param destinationURI destination model for the source data.
+   * @param contentType The string representation of the content type of the data in the stream.
+   * @return number of rows inserted into the destination model
+   */
+  public long load(InputStream inputStream, URI destinationURI, String contentType) throws QueryException {
+    long numberOfStatements = 0;
+    try {
+      Load loadCmd = new Load(destinationURI, inputStream, new MimeType(contentType));
+      numberOfStatements = (Long)loadCmd.execute(interpreter.establishConnection(loadCmd.getServerURI()));
+    } catch (QueryException ex) {
+      throw ex;
+    } catch (Exception ex) {
+      throw new QueryException("Unable to load data: " + ex.getMessage(), ex);
+    }
+    return numberOfStatements;
+  }
+
+
+  /**
    * Load the contents of an InputStream or a URI into a database/model.
    * <p>
    *   Note. <var>destinationURI</var> must be a valid URI, and does not include
@@ -827,6 +853,7 @@
   public long load(InputStream inputStream, URI sourceURI, URI destinationURI) throws QueryException {
     long numberOfStatements = 0;
     try {
+      if (sourceURI == null) sourceURI = DUMMY_RDF_URI;
       Load loadCmd = new Load(sourceURI, destinationURI, true);
       loadCmd.setOverrideInputStream(inputStream);
       numberOfStatements = (Long)loadCmd.execute(interpreter.establishConnection(loadCmd.getServerURI()));

Modified: trunk/src/jar/querylang/java/org/mulgara/itql/ItqlInterpreterBeanUnitTest.java
===================================================================
--- trunk/src/jar/querylang/java/org/mulgara/itql/ItqlInterpreterBeanUnitTest.java	2009-02-13 07:08:14 UTC (rev 1491)
+++ trunk/src/jar/querylang/java/org/mulgara/itql/ItqlInterpreterBeanUnitTest.java	2009-02-13 07:12:24 UTC (rev 1492)
@@ -150,6 +150,7 @@
     suite.addTest(new ItqlInterpreterBeanUnitTest("testLoadApi2"));
     suite.addTest(new ItqlInterpreterBeanUnitTest("testLoadApi3"));
     suite.addTest(new ItqlInterpreterBeanUnitTest("testLoadApi4"));
+    suite.addTest(new ItqlInterpreterBeanUnitTest("testLoadApi4_1"));
     suite.addTest(new ItqlInterpreterBeanUnitTest("testLoadApi5"));
     suite.addTest(new ItqlInterpreterBeanUnitTest("testLoadApi6"));
     suite.addTest(new ItqlInterpreterBeanUnitTest("testLoadApi7"));
@@ -500,6 +501,26 @@
    *
    * @throws Exception if the test fails
    */
+  public void testLoadApi4_1() throws Exception {
+
+    // log that we're executing the test
+    log.debug("Starting load API test 4_1");
+
+    URI sourceURI = new URI("http://purl.org/dc/elements/1.1");
+    URI modelURI = new URI(testModel);
+
+    // execute the load locally
+    long statements = bean.load(sourceURI.toURL().openStream(), modelURI, "application/rdf+xml");
+
+    assertEquals("Incorrect number of statements inserted", 154, statements);
+
+  }
+
+  /**
+   * Test the interpreter using a load API locally
+   *
+   * @throws Exception if the test fails
+   */
   public void testLoadApi5() throws Exception {
 
     // log that we're executing the test

Modified: trunk/src/jar/querylang/java/org/mulgara/protocol/http/ProtocolServlet.java
===================================================================
--- trunk/src/jar/querylang/java/org/mulgara/protocol/http/ProtocolServlet.java	2009-02-13 07:08:14 UTC (rev 1491)
+++ trunk/src/jar/querylang/java/org/mulgara/protocol/http/ProtocolServlet.java	2009-02-13 07:12:24 UTC (rev 1492)
@@ -26,6 +26,8 @@
 import java.util.List;
 import java.util.Map;
 
+import javax.activation.MimeType;
+import javax.activation.MimeTypeParseException;
 import javax.mail.BodyPart;
 import javax.mail.MessagingException;
 import javax.servlet.http.HttpServlet;
@@ -422,15 +424,15 @@
    * @throws InternalErrorException A query exception occurred during the load operation.
    */
   protected long loadData(URI graph, BodyPart data, Connection cxt) throws IOException, ServletException, QueryException {
+    String contentType = "";
     try {
-      URI absoluteUri = new URI(HTTP_PUT_NS + data.getFileName());
-      Load loadCmd = new Load(absoluteUri, graph, true);
-      loadCmd.setOverrideInputStream(data.getInputStream());
+      contentType = data.getContentType();
+      Load loadCmd = new Load(graph, data.getInputStream(), new MimeType(contentType), data.getFileName());
       return (Long)loadCmd.execute(cxt);
     } catch (MessagingException e) {
       throw new BadRequestException("Unable to process data for loading: " + e.getMessage());
-    } catch (URISyntaxException e) {
-      throw new BadRequestException("Illegal filename: " + e.getInput());
+    } catch (MimeTypeParseException e) {
+      throw new BadRequestException("Bad Content Type in request: " + contentType + " (" + e.getMessage() + ")");
     }
   }
 

Modified: trunk/src/jar/resolver/java/org/mulgara/resolver/DatabaseOperationContext.java
===================================================================
--- trunk/src/jar/resolver/java/org/mulgara/resolver/DatabaseOperationContext.java	2009-02-13 07:08:14 UTC (rev 1491)
+++ trunk/src/jar/resolver/java/org/mulgara/resolver/DatabaseOperationContext.java	2009-02-13 07:12:24 UTC (rev 1492)
@@ -412,7 +412,7 @@
   public URI mapToModelTypeURI(URI graphURI) throws QueryException {
     try {
       if (logger.isDebugEnabled()) logger.debug("Finding graphTypeURI for " + graphURI);
-      long rawGraph = systemResolver.localize(new URIReferenceImpl(graphURI));
+      long rawGraph = systemResolver.localize(new URIReferenceImpl(graphURI, false));
       long canGraph = getCanonicalModel(rawGraph);
 
       URI graphTypeURI = findGraphTypeURI(canGraph);

Modified: trunk/src/jar/resolver/java/org/mulgara/resolver/DatabaseSession.java
===================================================================
--- trunk/src/jar/resolver/java/org/mulgara/resolver/DatabaseSession.java	2009-02-13 07:08:14 UTC (rev 1491)
+++ trunk/src/jar/resolver/java/org/mulgara/resolver/DatabaseSession.java	2009-02-13 07:12:24 UTC (rev 1492)
@@ -37,6 +37,7 @@
 import java.util.*;
 
 // Java 2 enterprise packages
+import javax.activation.MimeType;
 import javax.transaction.xa.XAResource;
 
 // Third party packages
@@ -77,7 +78,6 @@
    * The list of all registered {@link ResolverFactory} instances.
    * Not used in this implementation.
    */
-  @SuppressWarnings("unused")
   private final List<ResolverFactory> resolverFactoryList;
 
   /**
@@ -547,20 +547,20 @@
    * @throws QueryException if the model can't be modified
    */
   public synchronized long setModel(URI uri, GraphExpression graphExpression) throws QueryException {
-    return this.setModel(null, uri, graphExpression);
+    return this.setModel(null, uri, graphExpression, null);
   }
 
 
   /**
    * Define the contents of a model via an inputstream
    * @param inputStream a remote inputstream
-   * @param destinationModelURI the {@link URI} of the model to be redefined
-   * @param graphExpression the new content for the model
-   * @return RETURNED VALUE TO DO
+   * @param destinationModelURI the {@link URI} of the graph to be redefined
+   * @param graphExpression the new content for the graph
+   * @return The number of statements loaded into the graph
    * @throws QueryException if the model can't be modified
    */
   public synchronized long setModel(InputStream inputStream,
-      URI destinationModelURI, GraphExpression graphExpression) throws QueryException {
+      URI destinationModelURI, GraphExpression graphExpression, MimeType contentType) throws QueryException {
     if (logger.isDebugEnabled()) {
       logger.debug("SET-MODEL " + destinationModelURI + " to " + graphExpression + " from " + inputStream);
     }
@@ -568,22 +568,22 @@
     // Validate parameters
     if (destinationModelURI == null) {
       throw new IllegalArgumentException("Null 'destinationModelURI' parameter");
-    } else if (graphExpression == null) {
-      throw new IllegalArgumentException("Null 'modelExpression' parameter");
     }
+    if (graphExpression == null && contentType == null) {
+      throw new IllegalArgumentException("Null 'modelExpression' and 'contentType' parameters");
+    }
 
     // Convert the model expression into the source model URI
-    if (!(graphExpression instanceof GraphResource)) {
+    if (graphExpression != null && !(graphExpression instanceof GraphResource)) {
       throw new QueryException("Unsupported model expression " + graphExpression + " (" + graphExpression.getClass() + ")");
     }
-    assert graphExpression instanceof GraphResource;
 
-    URI sourceModelURI = ((GraphResource)graphExpression).getURI();
-    assert sourceModelURI != null;
+    URI sourceModelURI = graphExpression == null ? null : ((GraphResource)graphExpression).getURI();
+    assert sourceModelURI != null || contentType != null;
 
     // Perform the operation
     SetGraphOperation op = new SetGraphOperation(sourceModelURI, destinationModelURI,
-                                  inputStream, contentHandlers, this);
+                                  inputStream, contentType, contentHandlers, this);
     // preExcecute is a rather ugly hack, get rid of it once we support re-entrant transactions.
     if (op.preExecute()) {
       execute(op, "Unable to load " + sourceModelURI + " into " + destinationModelURI);

Modified: trunk/src/jar/resolver/java/org/mulgara/resolver/SetGraphOperation.java
===================================================================
--- trunk/src/jar/resolver/java/org/mulgara/resolver/SetGraphOperation.java	2009-02-13 07:08:14 UTC (rev 1491)
+++ trunk/src/jar/resolver/java/org/mulgara/resolver/SetGraphOperation.java	2009-02-13 07:12:24 UTC (rev 1492)
@@ -31,6 +31,8 @@
 import java.io.*;
 import java.net.URI;
 
+import javax.activation.MimeType;
+
 // Third party packages
 import org.apache.log4j.Logger;
 
@@ -76,6 +78,7 @@
   private final URI         srcModelURI;
   private final URI         destModelURI;
   private final InputStream inputStream;
+  private final MimeType    contentType;
 
   private Content               content;
   private final ContentHandlerManager contentHandlers;
@@ -102,14 +105,16 @@
   SetGraphOperation(URI         srcModelURI,
                     URI         destModelURI,
                     InputStream inputStream,
+                    MimeType    contentType,
                     ContentHandlerManager contentHandlers,
                     DatabaseSession databaseSession)
   {
     this.srcModelURI      = srcModelURI;
-    this.destModelURI = destModelURI;
-    this.inputStream         = inputStream;
-    this.contentHandlers = contentHandlers;
-    this.databaseSession    = databaseSession;
+    this.destModelURI     = destModelURI;
+    this.inputStream      = inputStream;
+    this.contentType      = contentType;
+    this.contentHandlers  = contentHandlers;
+    this.databaseSession  = databaseSession;
   }
 
   //
@@ -198,7 +203,11 @@
       if (logger.isDebugEnabled()) {
         logger.debug("Detected inputstream associated with " + srcModelURI );
       }
-      content = new StreamContent(inputStream, srcModelURI);
+      if (srcModelURI == null) {
+        content = new StreamContent(inputStream, contentType);
+      } else {
+        content = new StreamContent(inputStream, srcModelURI);
+      }
     } else {
       try {
         content = ContentFactory.getContent(srcModelURI);

Modified: trunk/src/jar/server-rmi/java/org/mulgara/server/rmi/RemoteSession.java
===================================================================
--- trunk/src/jar/server-rmi/java/org/mulgara/server/rmi/RemoteSession.java	2009-02-13 07:08:14 UTC (rev 1491)
+++ trunk/src/jar/server-rmi/java/org/mulgara/server/rmi/RemoteSession.java	2009-02-13 07:12:24 UTC (rev 1492)
@@ -34,6 +34,8 @@
 import java.util.*;
 import java.net.*;
 
+import javax.activation.MimeType;
+
 // Locally written packages
 import org.jrdf.graph.Triple;
 import org.mulgara.query.AskQuery;
@@ -253,8 +255,8 @@
    * @throws QueryException if the model can't be modified
    */
   public long setModel(InputStream inputStream, URI uri,
-                      GraphExpression graphExpression) throws QueryException,
-      RemoteException;
+                       GraphExpression graphExpression, MimeType contentType)
+      throws QueryException, RemoteException;
 
   /**
    * Sets the AutoCommit attribute of the RemoteSession object

Modified: trunk/src/jar/server-rmi/java/org/mulgara/server/rmi/RemoteSessionWrapperSession.java
===================================================================
--- trunk/src/jar/server-rmi/java/org/mulgara/server/rmi/RemoteSessionWrapperSession.java	2009-02-13 07:08:14 UTC (rev 1491)
+++ trunk/src/jar/server-rmi/java/org/mulgara/server/rmi/RemoteSessionWrapperSession.java	2009-02-13 07:12:24 UTC (rev 1492)
@@ -53,6 +53,7 @@
 import org.mulgara.server.NonRemoteSessionException;
 import org.mulgara.server.Session;
 
+import javax.activation.MimeType;
 import javax.naming.*;
 
 /**
@@ -159,16 +160,16 @@
    * @return The number of statements inserted into the model
    * @throws QueryException if the model can't be modified
    */
-  public long setModel(InputStream inputStream, URI uri, GraphExpression graphExpression) throws QueryException {
+  public long setModel(InputStream inputStream, URI uri, GraphExpression graphExpression, MimeType contentType) throws QueryException {
 
     try {
 
-      long r = remoteSession.setModel(inputStream, uri, graphExpression);
+      long r = remoteSession.setModel(inputStream, uri, graphExpression, contentType);
       resetRetries();
       return r;
     } catch (RemoteException e) {
       testRetry(e);
-      return setModel(inputStream, uri, graphExpression);
+      return setModel(inputStream, uri, graphExpression, contentType);
     }
   }
 

Modified: trunk/src/jar/server-rmi/java/org/mulgara/server/rmi/SessionWrapperRemoteSession.java
===================================================================
--- trunk/src/jar/server-rmi/java/org/mulgara/server/rmi/SessionWrapperRemoteSession.java	2009-02-13 07:08:14 UTC (rev 1491)
+++ trunk/src/jar/server-rmi/java/org/mulgara/server/rmi/SessionWrapperRemoteSession.java	2009-02-13 07:12:24 UTC (rev 1492)
@@ -35,6 +35,8 @@
 import java.rmi.server.Unreferenced;
 import java.util.*;
 
+import javax.activation.MimeType;
+
 // Third party packages
 import org.apache.log4j.Logger;
 
@@ -68,7 +70,6 @@
  */
 class SessionWrapperRemoteSession implements RemoteSession, Unreferenced  {
 
-  @SuppressWarnings("unused")
   /** Logger.  */
   private static final Logger logger = Logger.getLogger(SessionWrapperRemoteSession.class.getName());
 
@@ -118,9 +119,9 @@
    * @return The number of statements inserted into the model
    * @throws QueryException if the model can't be modified
    */
-  public long setModel(InputStream inputStream, URI uri, GraphExpression graphExpression) throws QueryException {
+  public long setModel(InputStream inputStream, URI uri, GraphExpression graphExpression, MimeType contentType) throws QueryException {
     try {
-      return session.setModel(inputStream, uri, graphExpression);
+      return session.setModel(inputStream, uri, graphExpression, contentType);
     } catch (Throwable t) {
       throw convertToQueryException(t);
     }

Modified: trunk/src/jar/web/java/org/mulgara/webquery/QueryServlet.java
===================================================================
--- trunk/src/jar/web/java/org/mulgara/webquery/QueryServlet.java	2009-02-13 07:08:14 UTC (rev 1491)
+++ trunk/src/jar/web/java/org/mulgara/webquery/QueryServlet.java	2009-02-13 07:12:24 UTC (rev 1492)
@@ -29,6 +29,8 @@
 import java.util.Map;
 import java.util.Set;
 
+import javax.activation.MimeType;
+import javax.activation.MimeTypeParseException;
 import javax.mail.BodyPart;
 import javax.mail.MessagingException;
 import javax.servlet.http.HttpServlet;
@@ -415,16 +417,16 @@
    * @throws QueryException A query exception occurred during the load operation.
    */
   protected Load loadData(URI graph, BodyPart data, Connection cxt) throws RequestException, IOException, QueryException {
+    String contentType = "";
     try {
-      URI absoluteUri = new URI(HTTP_PUT_NS + data.getFileName());
-      Load loadCmd = new Load(absoluteUri, graph, true);
-      loadCmd.setOverrideInputStream(data.getInputStream());
+      contentType = data.getContentType();
+      Load loadCmd = new Load(graph, data.getInputStream(), new MimeType(contentType));
       loadCmd.execute(cxt);
       return loadCmd;
     } catch (MessagingException e) {
       throw new RequestException("Unable to process data for loading: " + e.getMessage());
-    } catch (URISyntaxException e) {
-      throw new RequestException("Illegal filename: " + e.getInput());
+    } catch (MimeTypeParseException e) {
+      throw new RequestException("Bad Content Type in request: " + contentType + " (" + e.getMessage() + ")");
     }
   }
 




More information about the Mulgara-svn mailing list