You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by to...@apache.org on 2011/04/06 09:58:00 UTC

svn commit: r1089344 - in /uima/sandbox/trunk/Solrcas/src: main/java/org/apache/uima/solrcas/ test/java/org/apache/uima/solrcas/ test/resources/

Author: tommaso
Date: Wed Apr  6 07:57:59 2011
New Revision: 1089344

URL: http://svn.apache.org/viewvc?rev=1089344&view=rev
Log:
[UIMA-2097] - using URI along with File for file:// protocols fixes the problem in Solrcas

Modified:
    uima/sandbox/trunk/Solrcas/src/main/java/org/apache/uima/solrcas/SolrCASConsumer.java
    uima/sandbox/trunk/Solrcas/src/test/java/org/apache/uima/solrcas/EmbeddedSolrCASConsumer.java
    uima/sandbox/trunk/Solrcas/src/test/java/org/apache/uima/solrcas/SolrCasConsumerIntegrationTest.java
    uima/sandbox/trunk/Solrcas/src/test/resources/TestSolrcasAE.xml

Modified: uima/sandbox/trunk/Solrcas/src/main/java/org/apache/uima/solrcas/SolrCASConsumer.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/Solrcas/src/main/java/org/apache/uima/solrcas/SolrCASConsumer.java?rev=1089344&r1=1089343&r2=1089344&view=diff
==============================================================================
--- uima/sandbox/trunk/Solrcas/src/main/java/org/apache/uima/solrcas/SolrCASConsumer.java (original)
+++ uima/sandbox/trunk/Solrcas/src/main/java/org/apache/uima/solrcas/SolrCASConsumer.java Wed Apr  6 07:57:59 2011
@@ -22,6 +22,7 @@ package org.apache.uima.solrcas;
 import java.io.IOException;
 import java.io.InputStream;
 import java.net.URI;
+import java.net.URISyntaxException;
 import java.net.URL;
 import java.util.Map;
 
@@ -137,26 +138,23 @@ public class SolrCASConsumer extends Cas
   }
 
 
-  /* allows retrieving of input stream from a path specifying one of:
+  /* allows retrieving of a URI from a path specifying one of:
    * file://absolute/path
    * http://something.com/res.ext
    * classpath:/path/to/something.xml
    * data/path/relative/file.ext
    */
-  protected URL getURL(String path) throws ResourceAccessException, IOException {
-    URL url;
+  protected URI getURI(String path) throws ResourceAccessException, IOException, URISyntaxException {
+    URI uri;
     if (path.startsWith(CLASSPATH)) {
-      url = System.class.getResource(path.replaceFirst(CLASSPATH, EMPTY_STRING));
+      uri = System.class.getResource(path.replaceFirst(CLASSPATH, EMPTY_STRING)).toURI();
     } else {
-        URI uriPath = UriUtils.create(path);
-        if (uriPath.isAbsolute()) // this supports file://ABSOLUTE_PATH and http://URL
-          url = uriPath.toURL();
-        else // path is not absolute
-          url = UriUtils.create(new StringBuilder(FILEPATH).append(getContext().getDataPath()).
-                  append("/").append(path.replace(FILEPATH, EMPTY_STRING)).toString()).
-                  toURL(); // this supports relative file paths
+      uri = UriUtils.create(path); // this supports file://ABSOLUTE_PATH and http://URL
+      if (!uri.isAbsolute())
+         uri = UriUtils.create(new StringBuilder(FILEPATH).append(getContext().getDataPath()).
+                append("/").append(path.replace(FILEPATH, EMPTY_STRING)).toString()); // this supports relative file paths
     }
-    return url;
+    return uri;
   }
 
   private boolean getAutoCommitValue() {
@@ -168,11 +166,11 @@ public class SolrCASConsumer extends Cas
   }
 
   private SolrMappingConfiguration createSolrMappingConfiguration()
-          throws IOException, ResourceAccessException, ParserConfigurationException, SAXException {
+          throws IOException, ResourceAccessException, ParserConfigurationException, SAXException, URISyntaxException {
     FieldMappingReader fieldMappingReader = new FieldMappingReader();
     String mappingFileParam = String.valueOf(getContext().getConfigParameterValue("mappingFile"));
 
-    InputStream input = getURL(mappingFileParam).openStream();
+    InputStream input = getURI(mappingFileParam).toURL().openStream();
 
     SolrMappingConfiguration solrMappingConfiguration = fieldMappingReader.getConf(input);
     return solrMappingConfiguration;

Modified: uima/sandbox/trunk/Solrcas/src/test/java/org/apache/uima/solrcas/EmbeddedSolrCASConsumer.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/Solrcas/src/test/java/org/apache/uima/solrcas/EmbeddedSolrCASConsumer.java?rev=1089344&r1=1089343&r2=1089344&view=diff
==============================================================================
--- uima/sandbox/trunk/Solrcas/src/test/java/org/apache/uima/solrcas/EmbeddedSolrCASConsumer.java (original)
+++ uima/sandbox/trunk/Solrcas/src/test/java/org/apache/uima/solrcas/EmbeddedSolrCASConsumer.java Wed Apr  6 07:57:59 2011
@@ -19,13 +19,15 @@
 
 package org.apache.uima.solrcas;
 
-import java.net.URL;
-
 import org.apache.solr.client.solrj.SolrServer;
 import org.apache.solr.client.solrj.SolrServerException;
 import org.apache.solr.client.solrj.embedded.EmbeddedSolrServer;
 import org.apache.solr.core.CoreContainer;
 
+import java.io.File;
+import java.net.URI;
+import java.net.URL;
+
 public class EmbeddedSolrCASConsumer extends SolrCASConsumer {
 
   @Override
@@ -39,8 +41,8 @@ public class EmbeddedSolrCASConsumer ext
               getConfigParameterValue("solrPath"));
   
       if (solrInstanceTypeParam.equals("embedded")) {
-        URL solrURL = getURL(solrPathParam);
-        System.setProperty("solr.solr.home", solrURL.getFile());
+        URI solrURI = getURI(solrPathParam);
+        System.setProperty("solr.solr.home", new File(solrURI).getAbsolutePath());
         CoreContainer.Initializer initializer = new CoreContainer.Initializer();
         CoreContainer coreContainer = initializer.initialize();
         solrServer = new EmbeddedSolrServer(coreContainer, "");

Modified: uima/sandbox/trunk/Solrcas/src/test/java/org/apache/uima/solrcas/SolrCasConsumerIntegrationTest.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/Solrcas/src/test/java/org/apache/uima/solrcas/SolrCasConsumerIntegrationTest.java?rev=1089344&r1=1089343&r2=1089344&view=diff
==============================================================================
--- uima/sandbox/trunk/Solrcas/src/test/java/org/apache/uima/solrcas/SolrCasConsumerIntegrationTest.java (original)
+++ uima/sandbox/trunk/Solrcas/src/test/java/org/apache/uima/solrcas/SolrCasConsumerIntegrationTest.java Wed Apr  6 07:57:59 2011
@@ -39,6 +39,7 @@ import org.apache.uima.test.junit_extens
 import org.apache.uima.util.CasCreationUtils;
 import org.junit.Test;
 
+import java.io.File;
 import java.net.URL;
 import java.util.Collection;
 
@@ -70,7 +71,7 @@ public class SolrCasConsumerIntegrationT
 
       /* create a Solr instance to check document has been indexed as expected */
       URL solrURL = this.getClass().getResource("/org/apache/uima/solrcas/");
-      System.setProperty("solr.solr.home", solrURL.getFile());
+      System.setProperty("solr.solr.home", new File(solrURL.toURI()).getAbsolutePath());
       CoreContainer.Initializer initializer = new CoreContainer.Initializer();
       CoreContainer coreContainer = initializer.initialize();
       SolrServer solrServer = new EmbeddedSolrServer(coreContainer, "");

Modified: uima/sandbox/trunk/Solrcas/src/test/resources/TestSolrcasAE.xml
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/Solrcas/src/test/resources/TestSolrcasAE.xml?rev=1089344&r1=1089343&r2=1089344&view=diff
==============================================================================
--- uima/sandbox/trunk/Solrcas/src/test/resources/TestSolrcasAE.xml (original)
+++ uima/sandbox/trunk/Solrcas/src/test/resources/TestSolrcasAE.xml Wed Apr  6 07:57:59 2011
@@ -61,7 +61,7 @@
       <nameValuePair>
         <name>mappingFile</name>
         <value>
-          <string>src/test/resources/solrmapping.xml</string>
+          <string>classpath:/solrmapping.xml</string>
         </value>
       </nameValuePair>
       <nameValuePair>