Author: rwesten
Date: Wed Nov 30 16:49:25 2011
New Revision: 1208510

URL: http://svn.apache.org/viewvc?rev=1208510&view=rev
Log:
fixes STANBOL-401:

* added Integration tests for STANBOL-401
* added the httpqueryheader 
* fixed a Bug related to removal of headers

SolrYard

* Added a 1sec wait if the server is currently not available. This is only a 
temporary solution that makes is more likely to return null if the Server was 
initialised in the same request. This tries not to avoid YardExceptions in such 
cases. In future this will be replaced by splitting up the SolrYard in (1) 
SolrYardManager: A @Component that takes the configuration and tracks the 
required SolrServer ... (2) SolrYard: The service implementing Yard. This will 
be registered/unregistered by the SolrYardManager. Jira issue descibing that 
will come soon.

Commons Solr :

The RegisteredSolrServerTracker now tracks SolrCores instead of CoreContainers 
even if the CoreContainer is known by the parsed IndexReference. This has the 
advantage that no SolrServer is returned by the getService() method if the 
actually tracked core is not (yet) available on the CoreContainer.

Bug fixes:

*The GraphWriter (serialising of RDF Graphs) now correctly returns the 
"Content-Type" in cases wildcard types where requested
* The getServer() Method now always throws an YardException if the SolrServer 
is not available. NULL should no longer be returned.

 

Added:
    
incubator/stanbol/trunk/integration-tests/src/test/java/org/apache/stanbol/commons/httpqueryheaders/
    
incubator/stanbol/trunk/integration-tests/src/test/java/org/apache/stanbol/commons/httpqueryheaders/it/
Modified:
    incubator/stanbol/trunk/commons/httpqueryheaders/pom.xml
    
incubator/stanbol/trunk/commons/httpqueryheaders/src/main/java/org/apache/stanbol/commons/httpqueryheaders/OverwriteableHeaderHttpServletRequest.java
    incubator/stanbol/trunk/commons/pom.xml
    
incubator/stanbol/trunk/commons/solr/core/src/main/java/org/apache/stanbol/commons/solr/RegisteredSolrServerTracker.java
    
incubator/stanbol/trunk/commons/web/base/src/main/java/org/apache/stanbol/commons/web/base/writers/GraphWriter.java
    
incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/impl/SolrYard.java
    
incubator/stanbol/trunk/integration-tests/src/test/java/org/apache/stanbol/enhancer/it/EnhancerTestBase.java
    
incubator/stanbol/trunk/integration-tests/src/test/java/org/apache/stanbol/enhancer/it/StatelessEngineTest.java
    incubator/stanbol/trunk/launchers/basebundlelist/src/main/bundles/list.xml

Modified: incubator/stanbol/trunk/commons/httpqueryheaders/pom.xml
URL: 
http://svn.apache.org/viewvc/incubator/stanbol/trunk/commons/httpqueryheaders/pom.xml?rev=1208510&r1=1208509&r2=1208510&view=diff
==============================================================================
--- incubator/stanbol/trunk/commons/httpqueryheaders/pom.xml (original)
+++ incubator/stanbol/trunk/commons/httpqueryheaders/pom.xml Wed Nov 30 
16:49:25 2011
@@ -30,8 +30,8 @@
   <artifactId>org.apache.stanbol.commons.httpqueryheaders</artifactId>
   <packaging>bundle</packaging>
 
-  <name>Apache Stanbol Commons Web Home Page</name>
-  <description>Home page and common stylesheets for documenting HTTP 
endpoints.</description>
+  <name>Http Query Headers</name>
+  <description>Allows to parse HTTP headers as QueryParameters by prefixing it 
with "header_{http-header}". This feature allows to bypass the inability of 
Internet Explorer to set headers for multi domain (CORS) requests. This is a 
general utility and has no dependencies to Apache Stanbol.</description>
 <!--  <scm>
     <connection>
       
scm:svn:http://svn.apache.org/repos/asf/incubator/stanbol/trunk/commons/httpqueryheaders

Modified: 
incubator/stanbol/trunk/commons/httpqueryheaders/src/main/java/org/apache/stanbol/commons/httpqueryheaders/OverwriteableHeaderHttpServletRequest.java
URL: 
http://svn.apache.org/viewvc/incubator/stanbol/trunk/commons/httpqueryheaders/src/main/java/org/apache/stanbol/commons/httpqueryheaders/OverwriteableHeaderHttpServletRequest.java?rev=1208510&r1=1208509&r2=1208510&view=diff
==============================================================================
--- 
incubator/stanbol/trunk/commons/httpqueryheaders/src/main/java/org/apache/stanbol/commons/httpqueryheaders/OverwriteableHeaderHttpServletRequest.java
 (original)
+++ 
incubator/stanbol/trunk/commons/httpqueryheaders/src/main/java/org/apache/stanbol/commons/httpqueryheaders/OverwriteableHeaderHttpServletRequest.java
 Wed Nov 30 16:49:25 2011
@@ -57,7 +57,7 @@ public class OverwriteableHeaderHttpServ
             if(values[0] != null && !values[0].isEmpty()){
                 headerValues = Collections.singletonList(values[0]);
             } else { //no value found
-                return null; 
+                headerValues = Collections.emptyList(); 
             }
         }
         if(headerValues.isEmpty()){

Modified: incubator/stanbol/trunk/commons/pom.xml
URL: 
http://svn.apache.org/viewvc/incubator/stanbol/trunk/commons/pom.xml?rev=1208510&r1=1208509&r2=1208510&view=diff
==============================================================================
--- incubator/stanbol/trunk/commons/pom.xml (original)
+++ incubator/stanbol/trunk/commons/pom.xml Wed Nov 30 16:49:25 2011
@@ -61,5 +61,6 @@
     <!-- not in a stable state right now 
     <module>installer/jarprovider</module>
     -->
+    <module>httpqueryheaders</module>
     </modules>
 </project>

Modified: 
incubator/stanbol/trunk/commons/solr/core/src/main/java/org/apache/stanbol/commons/solr/RegisteredSolrServerTracker.java
URL: 
http://svn.apache.org/viewvc/incubator/stanbol/trunk/commons/solr/core/src/main/java/org/apache/stanbol/commons/solr/RegisteredSolrServerTracker.java?rev=1208510&r1=1208509&r2=1208510&view=diff
==============================================================================
--- 
incubator/stanbol/trunk/commons/solr/core/src/main/java/org/apache/stanbol/commons/solr/RegisteredSolrServerTracker.java
 (original)
+++ 
incubator/stanbol/trunk/commons/solr/core/src/main/java/org/apache/stanbol/commons/solr/RegisteredSolrServerTracker.java
 Wed Nov 30 16:49:25 2011
@@ -67,7 +67,7 @@ public class RegisteredSolrServerTracker
         super(context,
             reference != null ? 
                     reference.isPath() ? 
context.createFilter(reference.getIndexFilter()) : 
-                        context.createFilter(reference.getServerFilter()) :
+                        context.createFilter(reference.getIndexFilter()) :
                             null ,null);
         if(reference == null){
             throw new IllegalArgumentException("The parsed IndexReference MUST 
NOT be NULL!");
@@ -76,7 +76,7 @@ public class RegisteredSolrServerTracker
             trackingSolrCore = true;
             coreName = null;
         } else {
-            trackingSolrCore = false;
+            trackingSolrCore = true;
             coreName = reference.getIndex();
         }
     }
@@ -138,6 +138,7 @@ public class RegisteredSolrServerTracker
         ServiceReference ref = getServiceReference();
         return ref == null ? null : (SolrServer)getService(ref);
     }
+    
     /**
      * Overrides to provide a {@link SolrServer} instead of {@link Object}
      * @see ServiceTracker#getService(ServiceReference)

Modified: 
incubator/stanbol/trunk/commons/web/base/src/main/java/org/apache/stanbol/commons/web/base/writers/GraphWriter.java
URL: 
http://svn.apache.org/viewvc/incubator/stanbol/trunk/commons/web/base/src/main/java/org/apache/stanbol/commons/web/base/writers/GraphWriter.java?rev=1208510&r1=1208509&r2=1208510&view=diff
==============================================================================
--- 
incubator/stanbol/trunk/commons/web/base/src/main/java/org/apache/stanbol/commons/web/base/writers/GraphWriter.java
 (original)
+++ 
incubator/stanbol/trunk/commons/web/base/src/main/java/org/apache/stanbol/commons/web/base/writers/GraphWriter.java
 Wed Nov 30 16:49:25 2011
@@ -100,6 +100,7 @@ public class GraphWriter implements Mess
         long start = System.currentTimeMillis();
         String mediaTypeString = 
mediaType.getType()+'/'+mediaType.getSubtype();
         if (mediaType.isWildcardType() || TEXT_PLAIN.equals(mediaTypeString) 
|| APPLICATION_OCTET_STREAM.equals(mediaTypeString)) {
+            httpHeaders.putSingle("Content-Type", APPLICATION_JSON);
             getSerializer().serialize(entityStream, t, APPLICATION_JSON);
         } else {
             getSerializer().serialize(entityStream, t, mediaTypeString);

Modified: 
incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/impl/SolrYard.java
URL: 
http://svn.apache.org/viewvc/incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/impl/SolrYard.java?rev=1208510&r1=1208509&r2=1208510&view=diff
==============================================================================
--- 
incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/impl/SolrYard.java
 (original)
+++ 
incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/impl/SolrYard.java
 Wed Nov 30 16:49:25 2011
@@ -80,6 +80,7 @@ import org.osgi.service.cm.Configuration
 import org.osgi.service.component.ComponentContext;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.xml.sax.SAXException;
 
 /**
  * Implementation of the {@link Yard} interface based on a Solr Server.
@@ -470,27 +471,66 @@ public class SolrYard extends AbstractYa
     }
 
     /**
-     * @param config
-     * @throws ConfigurationException
-     * @throws YardException 
+     * Getter for the {@link SolrServer} used by this {@link SolrYard}.<p>
+     * This method tries to {@link #initSolrServer()} if both {@link #_server}
+     * and {@link #_registeredServerTracker} are <code>null</code>. The
+     * {@link #_server} is used for remote SolrServers or if the component is
+     * not running within an OSGI Environment. THe {@link 
#_registeredServerTracker}
+     * is used for tracking SolrServers that do run in the same JVM.
+     * @throws YardException if the {@link SolrServer} is currently not 
+     * active.
      */
     private SolrServer getServer() throws YardException {
+        SolrServer server = null;
         if(_server == null && _registeredServerTracker == null){
             initSolrServer();
         }
         //for remove servers and when running outside OSGI
         if(_server != null){
-            return _server;
+            server = _server;
         }
         //when an internally managed Solr server is used by this SolrYard
         //we dynamically return the tracked version
         if(_registeredServerTracker != null){
-            return _registeredServerTracker.getService();
+            server = _registeredServerTracker.getService();
+            //TODO: remove and replace with a setting where the SolrYard does 
not
+            //      not activate until the SolrServer is available.
+            if(server == null){
+                try {
+                    log.info(" ... waiting 1sec for SolrServer");
+                    server = 
(SolrServer)_registeredServerTracker.waitForService(1000);
+                } catch (InterruptedException e) {}
+            }
+        
+        }
+        //the server is not available -> throw an exception!
+        if(server != null){
+            return server;
+        } else {
+            throw new YardException(String.format("The SolrIndex '%s' for 
SolrYard '%s' is currently not active!",
+                
((SolrYardConfig)getConfig()).getSolrServerLocation(),getName()));
         }
-        return null;
     }
 
     /**
+     * If the {@link SolrServer} of this SolrYard is managed on the
+     * {@link #managedSolrServer}, than this method deactivates it. If a
+     * remote server is used than calling this method does not have any 
effect. 
+     */
+    private void deactivateSolrServer(){
+        SolrYardConfig config = (SolrYardConfig) this.getConfig();
+        String indexLocation = config.getSolrServerLocation();
+        if(!(indexLocation.startsWith("http") && indexLocation.indexOf("://") 
> 0)){
+            IndexReference indexReference = 
IndexReference.parse(indexLocation);
+            ManagedSolrServer managedSolrServer = this.managedSolrServer;
+            if(indexReference.isName() && managedSolrServer != null
+                    && (indexReference.getServer() == null ||
+                            
indexReference.getServer().equals(managedSolrServer.getServerName()))){
+                managedSolrServer.deactivateIndex(indexReference.getIndex());
+            } //else no managed index or index not managed on 
#managedSolrServer
+        }//an remote server
+    }
+    /**
      * Assumes that this method is only called if {@link #_server} and 
      * {@link #_registeredServerTracker} is <code>null</code>
      * @throws YardException
@@ -543,7 +583,7 @@ public class SolrYard extends AbstractYa
     }
 
     /**
-     * Checks if the SolrYard
+     * Checks if the SolrYard is active on the {@link #managedSolrServer}
      * @param config
      * @param indexReference
      * @throws YardException
@@ -558,7 +598,8 @@ public class SolrYard extends AbstractYa
             } else if(indexReference.getServer() == null || 
                         
indexReference.getServer().equals(managedSolrServer.getServerName())){
                 //check if the referenced Index is Managed
-                
if(!managedSolrServer.isManagedIndex(indexReference.getIndex())){
+                IndexMetadata indexMetadata = 
managedSolrServer.getIndexMetadata(indexReference.getIndex());
+                if(indexMetadata == null){
                     // not managed -> try to create
                     IndexReference createdIndexRef = 
createSolrIndex(managedSolrServer,config, indexReference.getIndex());
                     if(context == null){
@@ -568,7 +609,26 @@ public class SolrYard extends AbstractYa
                     }
                     //return the created IndexReference
                     return createdIndexRef;
-                } else { //already managed -> nothing to do
+                } else if(!indexMetadata.isActive()){ //already managed, but 
not active
+                    //try to activate
+                    try {
+                        IndexMetadata activatedMetadata = 
managedSolrServer.activateIndex(indexReference.getIndex());
+                        if(activatedMetadata == null){
+                            throw new YardException(String.format(
+                                "Unable to actiate SolrIndex '%s' for SolrYard 
'%s" +
+                                "on MnagedSolrServer '%s'!",indexReference,
+                                
getConfig().getName(),managedSolrServer.getServerName()));
+                        } else {
+                            return activatedMetadata.getIndexReference();
+                        }
+                    } catch (IOException e) {
+                        throw new YardException("Unable to actiate SolrIndex 
for SolrYard "+getConfig().getName(),e);
+                    } catch (SAXException e) {
+                        throw new YardException("Unable to actiate SolrIndex 
for SolrYard "+getConfig().getName(),e);
+                    } catch (RuntimeException e){
+                        throw new YardException("Unable to actiate SolrIndex 
for SolrYard "+getConfig().getName(),e);
+                    }
+                } else{ //already active ... noting todo
                     return indexReference;
                 }
             } else { //indexReference.getServer() != 
managedSolrServer.getServerName
@@ -650,8 +710,10 @@ public class SolrYard extends AbstractYa
         // reset the commitWithin and immediateCommit to the defaults
         this.commitWithin = DEFAULT_COMMIT_WITHIN_DURATION;
         this.immediateCommit = DEFAULT_IMMEDIATE_COMMIT_STATE;
+        //deactivates the SolrCore used by this Yard if running in the local 
JVM
+        deactivateSolrServer();
         super.deactivate(); // deactivate the super implementation
-        context = null;
+        this.context = null;
     }
     /**
      * This will case the SolrIndex to be optimised

Modified: 
incubator/stanbol/trunk/integration-tests/src/test/java/org/apache/stanbol/enhancer/it/EnhancerTestBase.java
URL: 
http://svn.apache.org/viewvc/incubator/stanbol/trunk/integration-tests/src/test/java/org/apache/stanbol/enhancer/it/EnhancerTestBase.java?rev=1208510&r1=1208509&r2=1208510&view=diff
==============================================================================
--- 
incubator/stanbol/trunk/integration-tests/src/test/java/org/apache/stanbol/enhancer/it/EnhancerTestBase.java
 (original)
+++ 
incubator/stanbol/trunk/integration-tests/src/test/java/org/apache/stanbol/enhancer/it/EnhancerTestBase.java
 Wed Nov 30 16:49:25 2011
@@ -71,10 +71,7 @@ public class EnhancerTestBase extends St
                     "org.apache.stanbol.*MetaxaEngine",
                     "org.apache.stanbol.*LangIdEnhancementEngine",
                     
"org.apache.stanbol.*NamedEntityExtractionEnhancementEngine",
-                    //"org.apache.stanbol.*OpenCalaisEngine", not available in 
offline mode
-                    "org.apache.stanbol.*NamedEntityTaggingEngine",
-                    "org.apache.stanbol.*CachingDereferencerEngine"
-                    //removed because not available in offline mode
+                    "org.apache.stanbol.*NamedEntityTaggingEngine"
                 );
                 
                 /*  List of expected referencedSites could also be made 

Modified: 
incubator/stanbol/trunk/integration-tests/src/test/java/org/apache/stanbol/enhancer/it/StatelessEngineTest.java
URL: 
http://svn.apache.org/viewvc/incubator/stanbol/trunk/integration-tests/src/test/java/org/apache/stanbol/enhancer/it/StatelessEngineTest.java?rev=1208510&r1=1208509&r2=1208510&view=diff
==============================================================================
--- 
incubator/stanbol/trunk/integration-tests/src/test/java/org/apache/stanbol/enhancer/it/StatelessEngineTest.java
 (original)
+++ 
incubator/stanbol/trunk/integration-tests/src/test/java/org/apache/stanbol/enhancer/it/StatelessEngineTest.java
 Wed Nov 30 16:49:25 2011
@@ -23,6 +23,31 @@ import org.junit.Test;
 public class StatelessEngineTest extends EnhancerTestBase {
     
     private final RequestDocumentor documentor = new 
RequestDocumentor(getClass().getName());
+    /**
+     * Contains values grouped by three elements: Accept header, 
+     * Expected content-type, Expected regexp
+     */
+    public final static String [] ACCEPT_FORMAT_TEST_DATA  = new String[] {
+        "application/json",
+        "application/rdf+json", 
+        "\\{.*http.*ontology.*confidence.*:",
+        
+        "application/rdf+xml",
+        "application/rdf+xml",
+        "xmlns:rdf=.http://www.w3.org/1999/02/22-rdf-syntax-ns";,
+    
+        "application/rdf+json", 
+        "application/rdf+json", 
+        "\\{.*value.*ontology.*TextAnnotation.*type.*uri.*}",
+    
+        "text/turtle", 
+        "text/turtle", 
+        "a.*ontology/TextAnnotation.*ontology/Enhancement.*;",
+    
+        "text/rdf+nt", 
+        "text/rdf+nt", 
+        
"<urn:enhancement.*www.w3.org/1999/02/22-rdf-syntax-ns#type.*ontology/TextAnnotation>",
+    };
     
     @Test
     public void testSimpleEnhancement() throws Exception {
@@ -52,41 +77,18 @@ public class StatelessEngineTest extends
     
     @Test
     public void testOutputFormats() throws Exception {
-        final String [] formats = {
-            // Each group of 3 elements is: Accept header, Expected 
content-type, Expected regexp     
-            "application/json",
-            "application/rdf+json", 
-            "\\{.*http.*ontology.*confidence.*:",
-            
-            "application/rdf+xml",
-            "application/rdf+xml",
-            "xmlns:rdf=.http://www.w3.org/1999/02/22-rdf-syntax-ns";,
-
-            "application/rdf+json", 
-            "application/rdf+json", 
-            "\\{.*value.*ontology.*TextAnnotation.*type.*uri.*}",
-
-            "text/turtle", 
-            "text/turtle", 
-            "a.*ontology/TextAnnotation.*ontology/Enhancement.*;",
-
-            "text/rdf+nt", 
-            "text/rdf+nt", 
-            
"<urn:enhancement.*www.w3.org/1999/02/22-rdf-syntax-ns#type.*ontology/TextAnnotation>",
-        };
-
-        for (int i = 0; i < formats.length; i += 3) {
+        for (int i = 0; i < ACCEPT_FORMAT_TEST_DATA.length; i += 3) {
             executor.execute(
                     builder.buildPostRequest("/engines")
-                    .withHeader("Accept", formats[i])
+                    .withHeader("Accept", ACCEPT_FORMAT_TEST_DATA[i])
                     .withContent("Nothing")
             )
             .assertStatus(200)
-            .assertContentType(formats[i+1])
-            .assertContentRegexp(formats[i+2])
+            .assertContentType(ACCEPT_FORMAT_TEST_DATA[i+1])
+            .assertContentRegexp(ACCEPT_FORMAT_TEST_DATA[i+2])
             .generateDocumentation(documentor,
-                    "title", "Output format: " + formats[i],
-                    "description", "Demonstrate " + formats[i] + " output"
+                    "title", "Output format: " + ACCEPT_FORMAT_TEST_DATA[i],
+                    "description", "Demonstrate " + ACCEPT_FORMAT_TEST_DATA[i] 
+ " output"
                     );
         }
     }

Modified: 
incubator/stanbol/trunk/launchers/basebundlelist/src/main/bundles/list.xml
URL: 
http://svn.apache.org/viewvc/incubator/stanbol/trunk/launchers/basebundlelist/src/main/bundles/list.xml?rev=1208510&r1=1208509&r2=1208510&view=diff
==============================================================================
--- incubator/stanbol/trunk/launchers/basebundlelist/src/main/bundles/list.xml 
(original)
+++ incubator/stanbol/trunk/launchers/basebundlelist/src/main/bundles/list.xml 
Wed Nov 30 16:49:25 2011
@@ -57,7 +57,7 @@
     </bundle>
   </startLevel>
 
-  <!-- HTTP service -->
+  <!-- HTTP service and Http related Utilities-->
   <startLevel level="5">
     <bundle>
       <groupId>org.apache.felix</groupId>
@@ -69,6 +69,12 @@
       <artifactId>org.osgi.compendium</artifactId>
       <version>1.4.0</version>
     </bundle>
+    <!-- Allows to parse Http Headers as QueryParameter -->
+    <bundle>
+      <groupId>org.apache.stanbol</groupId>
+      <artifactId>org.apache.stanbol.commons.httpqueryheaders</artifactId>
+      <version>0.9.0-incubating-SNAPSHOT</version>
+    </bundle>
   </startLevel>
 
   <!-- Sling installer and Stanbol extensions -->
@@ -92,7 +98,7 @@
       <groupId>org.apache.sling</groupId>
       <artifactId>org.apache.sling.installer.provider.file</artifactId>
       <version>1.0.0</version>
-    </bundle>
+    </bundle>    
   </startLevel>
 
   <!-- Felix web console and plugins -->


Reply via email to