You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stanbol.apache.org by rw...@apache.org on 2012/12/23 08:13:14 UTC

svn commit: r1425426 - in /stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/impl: SolrFieldMapper.java SolrYard.java

Author: rwesten
Date: Sun Dec 23 07:13:14 2012
New Revision: 1425426

URL: http://svn.apache.org/viewvc?rev=1425426&view=rev
Log:
fix for STANBOL-863

Modified:
    stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/impl/SolrFieldMapper.java
    stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/impl/SolrYard.java

Modified: stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/impl/SolrFieldMapper.java
URL: http://svn.apache.org/viewvc/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/impl/SolrFieldMapper.java?rev=1425426&r1=1425425&r2=1425426&view=diff
==============================================================================
--- stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/impl/SolrFieldMapper.java (original)
+++ stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/impl/SolrFieldMapper.java Sun Dec 23 07:13:14 2012
@@ -25,6 +25,9 @@ import static org.apache.stanbol.entityh
 import static org.apache.stanbol.entityhub.yard.solr.defaults.SolrConst.SPECIAL_CONFIG_FIELD;
 
 import java.io.IOException;
+import java.security.AccessController;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
@@ -762,15 +765,9 @@ public class SolrFieldMapper implements 
                 log.debug("add namespace prefix '{}' for '{}'",prefix,namespace);
                 prefixMap.put(prefix, namespace);
                 namespaceMap.put(namespace, prefix);
-                saveNamespaceConfig(); // save the configuration
-                //make sure the namespaces are committed to the Solr Server
-                try {
-                    server.commit();
-                } catch (SolrServerException e) {
-                    log.error("Unable to commit NamespaceConfig to SolrServer",e);
-                } catch (IOException e) {
-                    log.error("Unable to commit NamespaceConfig to SolrServer",e);
-                }
+                // save the configuration and parse true to make  sure the 
+                //namespaces are committed to the Solr Server
+                saveNamespaceConfig(true); 
             } finally {
                 prefixNamespaceMappingsLock.writeLock().unlock();
             }
@@ -864,26 +861,30 @@ public class SolrFieldMapper implements 
      * Saves the current configuration to the index! This does NOT commit the
      * changes!
      */
-    public void saveNamespaceConfig() {
+    public void saveNamespaceConfig(final boolean commit) {
         if(server != null){
             prefixNamespaceMappingsLock.writeLock().lock();
             try {
                 log.debug("saveNamespaceConfig on {}",server);
                 Map<String,String> prefixMap = getPrefixMap();
-                SolrInputDocument inputDoc = new SolrInputDocument();
+                final SolrInputDocument inputDoc = new SolrInputDocument();
                 inputDoc.addField(getDocumentIdField(), FieldMapper.URI);
                 for (Entry<String,String> entry : prefixMap.entrySet()) {
                     log.debug("  > {}: {}",entry.getKey(),entry.getValue());
                     inputDoc.addField(getConfigFieldName(entry.getKey()), entry.getValue());
                 }
                 try {
-                    server.add(inputDoc);
-                } catch (IOException e) {
-                    log.error("Unable save Configuration to SolrProvider", e);
-                } catch (SolrServerException e) {
-                    log.error("Unable save Configuration to SolrProvider", e);
-                } catch (SolrException e) {
-                    log.error("Unable save Configuration to SolrProvider", e);
+                    AccessController.doPrivileged(new PrivilegedExceptionAction<Object>() {
+                        public Object run() throws IOException, SolrServerException {
+                                server.add(inputDoc);
+                                if(commit){
+                                    server.commit();
+                                }
+                                return null;
+                        }
+                    });
+                } catch (PrivilegedActionException pae) {
+                    log.error("Unable save Configuration to SolrProvider", pae.getException());
                 }
             } finally {
                 prefixNamespaceMappingsLock.writeLock().unlock();
@@ -903,13 +904,29 @@ public class SolrFieldMapper implements 
         if(server == null){
             return null;
         }
-        SolrQuery solrQuery = new SolrQuery();
+        final SolrQuery solrQuery = new SolrQuery();
         solrQuery.addField("*"); // select all fields
         solrQuery.setRows(1); // we query for the id, there is only one result
         String queryString = String.format("%s:%s", this.getDocumentIdField(),
             SolrUtil.escapeSolrSpecialChars(uri));
         solrQuery.setQuery(queryString);
-        QueryResponse queryResponse = server.query(solrQuery);
+        QueryResponse queryResponse;
+        try {
+            queryResponse = AccessController.doPrivileged(new PrivilegedExceptionAction<QueryResponse>() {
+                public QueryResponse run() throws IOException, SolrServerException {
+                    return server.query(solrQuery);
+                }
+            });
+        } catch (PrivilegedActionException pae) {
+            Exception e = pae.getException();
+            if(e instanceof SolrServerException){
+                throw (SolrServerException)e;
+            } else if(e instanceof IOException){
+                throw (IOException)e;
+            } else {
+                throw RuntimeException.class.cast(e);
+            }
+        }
         if (queryResponse.getResults().isEmpty()) {
             return null;
         } else {

Modified: stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/impl/SolrYard.java
URL: http://svn.apache.org/viewvc/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/impl/SolrYard.java?rev=1425426&r1=1425425&r2=1425426&view=diff
==============================================================================
--- stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/impl/SolrYard.java (original)
+++ stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/impl/SolrYard.java Sun Dec 23 07:13:14 2012
@@ -17,6 +17,9 @@
 package org.apache.stanbol.entityhub.yard.solr.impl;
 
 import java.io.IOException;
+import java.security.AccessController;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
@@ -47,12 +50,12 @@ import org.apache.solr.client.solrj.Solr
 import org.apache.solr.client.solrj.SolrServer;
 import org.apache.solr.client.solrj.SolrServerException;
 import org.apache.solr.client.solrj.SolrRequest.METHOD;
-import org.apache.solr.client.solrj.impl.CommonsHttpSolrServer;
+import org.apache.solr.client.solrj.impl.HttpSolrServer;
 import org.apache.solr.client.solrj.request.UpdateRequest;
 import org.apache.solr.client.solrj.response.QueryResponse;
+import org.apache.solr.client.solrj.response.UpdateResponse;
 import org.apache.solr.common.SolrDocument;
 import org.apache.solr.common.SolrInputDocument;
-import org.apache.solr.core.SolrCore;
 import org.apache.stanbol.commons.namespaceprefix.NamespacePrefixService;
 import org.apache.stanbol.commons.solr.IndexReference;
 import org.apache.stanbol.commons.solr.RegisteredSolrServerTracker;
@@ -76,7 +79,6 @@ import org.apache.stanbol.entityhub.serv
 import org.apache.stanbol.entityhub.yard.solr.defaults.IndexDataTypeEnum;
 import org.apache.stanbol.entityhub.yard.solr.impl.SolrQueryFactory.SELECT;
 import org.apache.stanbol.entityhub.yard.solr.model.FieldMapper;
-import org.apache.stanbol.entityhub.yard.solr.model.IndexDataType;
 import org.apache.stanbol.entityhub.yard.solr.model.IndexField;
 import org.apache.stanbol.entityhub.yard.solr.model.IndexValue;
 import org.apache.stanbol.entityhub.yard.solr.model.IndexValueFactory;
@@ -584,7 +586,7 @@ public class SolrYard extends AbstractYa
         if(indexLocation.startsWith("http") && indexLocation.indexOf("://") > 0){
             //init remote server
             try {
-                _server = new CommonsHttpSolrServer(indexLocation);
+                _server = new HttpSolrServer(indexLocation);
                 _server.ping(); //test if remove service is available
             } catch (RuntimeException e) {
                 throw new YardException("Unable to connect to remote SolrServer '"+
@@ -826,20 +828,31 @@ public class SolrYard extends AbstractYa
             selected = null;
         }
 
-        SolrQuery query = getSolrQueryFactory().parseFieldQuery(fieldQuery, select);
+        final SolrQuery query = getSolrQueryFactory().parseFieldQuery(fieldQuery, select);
         long queryGeneration = System.currentTimeMillis();
-
+        final SolrServer server = getServer();
         QueryResponse response;
         try {
-            StreamQueryRequest request = new StreamQueryRequest(query);
-            response = request.process(getServer());
-        } catch (SolrServerException e) {
-            if ("unknown handler: /mlt".equals(e.getCause().getMessage())) {
-                throw new YardException("Solr is missing '<requestHandler name=\"/mlt\""
-                                        + " class=\"solr.MoreLikeThisHandler\" startup=\"lazy\" />'"
-                                        + " in 'solrconfig.xml'", e);
+            response = AccessController.doPrivileged(new PrivilegedExceptionAction<QueryResponse>() {
+                public QueryResponse run() throws IOException, SolrServerException {
+                    StreamQueryRequest request = new StreamQueryRequest(query);
+                     return request.process(server);
+                }
+            });
+        } catch (PrivilegedActionException pae) {
+            Exception e = pae.getException();
+            if(e instanceof SolrServerException){
+                if ("unknown handler: /mlt".equals(e.getCause().getMessage())) {
+                    throw new YardException("Solr is missing '<requestHandler name=\"/mlt\""
+                        + " class=\"solr.MoreLikeThisHandler\" startup=\"lazy\" />'"
+                        + " in 'solrconfig.xml'", e);
+                }
+                throw new YardException("Error while performing Query on SolrServer: " + query.getQuery(), e);
+            } else if(e instanceof IOException){
+                throw new YardException("Unable to access SolrServer",e);
+            } else {
+                throw RuntimeException.class.cast(e);
             }
-            throw new YardException("Error while performing Query on SolrServer: " + query.getQuery(), e);
         }
         if(query.getQueryType() == SolrQueryFactory.MLT_QUERY_TYPE){
             log.info("{}",response);
@@ -870,18 +883,31 @@ public class SolrYard extends AbstractYa
         //create a clone of the query, because we need to refine it because the
         //query (as executed) needs to be included in the result set
         FieldQuery fieldQuery = parsedQuery.clone();
-        SolrQuery query = getSolrQueryFactory().parseFieldQuery(fieldQuery, SELECT.ID);
-        QueryResponse respone;
+        final SolrQuery query = getSolrQueryFactory().parseFieldQuery(fieldQuery, SELECT.ID);
+        QueryResponse response;
+        final SolrServer server = getServer();
         try {
-            respone = getServer().query(query, METHOD.POST);
-        } catch (SolrServerException e) {
-            throw new YardException("Error while performing query on the SolrServer", e);
+            response = AccessController.doPrivileged(new PrivilegedExceptionAction<QueryResponse>() {
+                public QueryResponse run() throws IOException, SolrServerException {
+                        return server.query(query, METHOD.POST);
+                }
+            });
+        } catch (PrivilegedActionException pae) {
+            Exception e = pae.getException();
+            if(e instanceof SolrServerException){
+                throw new YardException("Error while performing query on the SolrServer (query: "
+                        + query.getQuery()+")!", e);
+            } else if(e instanceof IOException){
+                throw new YardException("Unable to access SolrServer",e);
+            } else {
+                throw RuntimeException.class.cast(e);
+            }
         }
         final FieldMapper fieldMapper = getFieldMapper();
         // return a queryResultList
         return new QueryResultListImpl<String>(fieldQuery,
         // by adapting SolrDocuments to Representations
-                new AdaptingIterator<SolrDocument,String>(respone.getResults().iterator(),
+                new AdaptingIterator<SolrDocument,String>(response.getResults().iterator(),
                 // inline Adapter Implementation
                         new AdaptingIterator.Adapter<SolrDocument,String>() {
                             @Override
@@ -1037,33 +1063,43 @@ public class SolrYard extends AbstractYa
     }
 
     @Override
-    public final void remove(String id) throws YardException, IllegalArgumentException {
+    public final void remove(final String id) throws YardException, IllegalArgumentException {
         if (id == null) {
             throw new IllegalArgumentException("The parsed Representation id MUST NOT be NULL!");
         }
         if (id.isEmpty()) {
             throw new IllegalArgumentException("The parsed Representation id MUST NOT be empty!");
         }
-        SolrServer server = getServer();
-        SolrYardConfig config = (SolrYardConfig)getConfig();
-        SolrFieldMapper fieldMapper = getFieldMapper();
+        final SolrServer server = getServer();
+        final SolrYardConfig config = (SolrYardConfig)getConfig();
+        final SolrFieldMapper fieldMapper = getFieldMapper();
         try {
-            if(config.isMultiYardIndexLayout()){
-                //make sure we only delete the Entity only if it is  managed by 
-                //this Yard. Entities of other Yards MUST NOT be deleted!
-                server.deleteByQuery(String.format("%s:%s AND %s:%s",
-                    fieldMapper.getDocumentDomainField(),
-                    SolrUtil.escapeSolrSpecialChars(getId()),
-                    fieldMapper.getDocumentIdField(),
-                    SolrUtil.escapeSolrSpecialChars(id)));
+            AccessController.doPrivileged(new PrivilegedExceptionAction<Object>() {
+                public Object run() throws IOException, SolrServerException {
+                    if(config.isMultiYardIndexLayout()){
+                        //make sure we only delete the Entity only if it is  managed by 
+                        //this Yard. Entities of other Yards MUST NOT be deleted!
+                        server.deleteByQuery(String.format("%s:%s AND %s:%s",
+                            fieldMapper.getDocumentDomainField(),
+                            SolrUtil.escapeSolrSpecialChars(getId()),
+                            fieldMapper.getDocumentIdField(),
+                            SolrUtil.escapeSolrSpecialChars(id)));
+                    } else {
+                        server.deleteById(id);
+                    }
+                    server.commit();
+                    return null;
+                }
+            });
+        } catch (PrivilegedActionException pae) {
+            Exception e = pae.getException();
+            if(e instanceof SolrServerException){
+                throw new YardException("Error while deleting document " + id + " from the Solr server", e);
+            } else if(e instanceof IOException){
+                throw new YardException("Unable to access SolrServer",e);
             } else {
-                server.deleteById(id);
+                throw RuntimeException.class.cast(e);
             }
-            server.commit();
-        } catch (SolrServerException e) {
-            throw new YardException("Error while deleting document " + id + " from the Solr server", e);
-        } catch (IOException e) {
-            throw new YardException("Unable to access SolrServer", e);
         }
         // NOTE: We do not need to update all Documents that refer this ID, because
         // only the representation of the Entity is deleted and not the
@@ -1076,35 +1112,45 @@ public class SolrYard extends AbstractYa
         if (ids == null) {
             throw new IllegalArgumentException("The parsed IDs MUST NOT be NULL");
         }
-        List<String> toRemove = new ArrayList<String>();
+        final List<String> toRemove = new ArrayList<String>();
         for (String id : ids) {
             if (id != null && !id.isEmpty()) {
                 toRemove.add(id);
             }
         }
-        SolrServer server = getServer();
-        SolrYardConfig config = (SolrYardConfig)getConfig();
-        SolrFieldMapper fieldMapper = getFieldMapper();
+        final SolrServer server = getServer();
+        final SolrYardConfig config = (SolrYardConfig)getConfig();
+        final SolrFieldMapper fieldMapper = getFieldMapper();
         try {
-            if(config.isMultiYardIndexLayout()){
-                //make sure we only delete Entities managed by this Yard
-                //if someone parses an ID managed by an other yard we MUST NOT
-                //delete it!
-                for(String id : toRemove){
-                    server.deleteByQuery(String.format("%s:%s AND %s:%s",
-                        fieldMapper.getDocumentDomainField(),
-                        SolrUtil.escapeSolrSpecialChars(getId()),
-                        fieldMapper.getDocumentIdField(),
-                        SolrUtil.escapeSolrSpecialChars(id)));
+            AccessController.doPrivileged(new PrivilegedExceptionAction<Object>() {
+                public Object run() throws IOException, SolrServerException {
+                    if(config.isMultiYardIndexLayout()){
+                        //make sure we only delete Entities managed by this Yard
+                        //if someone parses an ID managed by an other yard we MUST NOT
+                        //delete it!
+                        for(String id : toRemove){
+                            server.deleteByQuery(String.format("%s:%s AND %s:%s",
+                                fieldMapper.getDocumentDomainField(),
+                                SolrUtil.escapeSolrSpecialChars(getId()),
+                                fieldMapper.getDocumentIdField(),
+                                SolrUtil.escapeSolrSpecialChars(id)));
+                        }
+                    } else {
+                        server.deleteById(toRemove);
+                    }
+                    server.commit();
+                    return null;
                 }
+            });
+        } catch (PrivilegedActionException pae) {
+            Exception e = pae.getException();
+            if(e instanceof SolrServerException){
+                throw new YardException("Error while deleting documents from the Solr server", e);
+            } else if(e instanceof IOException){
+                throw new YardException("Unable to access SolrServer",e);
             } else {
-                server.deleteById(toRemove);
+                throw RuntimeException.class.cast(e);
             }
-            server.commit();
-        } catch (SolrServerException e) {
-            throw new YardException("Error while deleting documents from the Solr server", e);
-        } catch (IOException e) {
-            throw new YardException("Unable to access SolrServer", e);
         }
         // NOTE: We do not need to update all Documents that refer this ID, because
         // only the representation of the Entity is deleted and not the
@@ -1113,31 +1159,42 @@ public class SolrYard extends AbstractYa
     }
     @Override
     public void removeAll() throws YardException {
-        SolrServer server = getServer();
-        SolrYardConfig config = (SolrYardConfig)getConfig();
+        final SolrServer server = getServer();
+        final SolrYardConfig config = (SolrYardConfig)getConfig();
         try {
-            //ensures that the fildMapper is initialised and reads the
-            //namespace config before deleting all documents
-            getFieldMapper();
             //delete all documents
-            if(config.isMultiYardIndexLayout()){
-                //only delete entities of this referenced site
-                server.deleteByQuery(String.format("%s:%s", 
-                    getFieldMapper().getDocumentDomainField(),
-                    SolrUtil.escapeSolrSpecialChars(getId())));
-            } else { //we can delete all
-                server.deleteByQuery("*:*");
-            }
-            //ensure that the namespace config is stored again after deleting
-            //all documents
-            getFieldMapper().saveNamespaceConfig();
-            server.commit();
-        } catch (SolrServerException e) {
-            throw new YardException("Error while deleting documents from the Solr server", e);
-        } catch (IOException e) {
-            throw new YardException("Unable to access SolrServer", e);
-        }
-        
+            AccessController.doPrivileged(new PrivilegedExceptionAction<Object>() {
+                public Object run() throws IOException, SolrServerException, YardException {
+                    //ensures that the fildMapper is initialised and reads the
+                    //namespace config before deleting all documents
+                    FieldMapper fieldMapper = getFieldMapper();
+                    if(config.isMultiYardIndexLayout()){
+                        //only delete entities of this referenced site
+                        server.deleteByQuery(String.format("%s:%s", 
+                            fieldMapper.getDocumentDomainField(),
+                            SolrUtil.escapeSolrSpecialChars(getId())));
+                    } else { //we can delete all
+                        server.deleteByQuery("*:*");
+                    }
+                    //ensure that the namespace config is stored again after deleting
+                    //all documents
+                    getFieldMapper().saveNamespaceConfig(false);
+                    server.commit();
+                    return null;
+                }
+            });
+        } catch (PrivilegedActionException pae) {
+            Exception e = pae.getException();
+            if(e instanceof SolrServerException){
+                throw new YardException("Error while deleting documents from the Solr server", e);
+            } else if(e instanceof IOException){
+                throw new YardException("Unable to access SolrServer",e);
+            } else if(e instanceof YardException){
+                throw (YardException)e;
+            } else {
+                throw RuntimeException.class.cast(e);
+            }
+        }        
     }
 
     @Override
@@ -1147,30 +1204,38 @@ public class SolrYard extends AbstractYa
         if (representation == null) {
             throw new IllegalArgumentException("The parsed Representation MUST NOT be NULL!");
         }
-        SolrServer server = getServer();
+        final SolrServer server = getServer();
         FieldMapper fieldMapper = getFieldMapper();
         long start = System.currentTimeMillis();
-        SolrInputDocument inputDocument = createSolrInputDocument(fieldMapper,representation);
+        final SolrInputDocument inputDocument = createSolrInputDocument(fieldMapper,representation);
         long create = System.currentTimeMillis();
         try {
-            UpdateRequest update = new UpdateRequest();
+            final UpdateRequest update = new UpdateRequest();
             if (!immediateCommit) {
                 update.setCommitWithin(commitWithin);
             }
             update.add(inputDocument);
-            update.process(server);
-            if (immediateCommit) {
-                server.commit();
-            }
+            AccessController.doPrivileged(new PrivilegedExceptionAction<Object>() {
+                public Object run() throws IOException, SolrServerException {
+                    update.process(server);
+                    if (immediateCommit) {
+                        server.commit();
+                    }
+                    return null; // nothing to return
+                }
+            });
             long stored = System.currentTimeMillis();
-            log.debug("  ... done [create={}ms|store={}ms|sum={}ms]", new Object[] {(create - start),
-                                                                                    (stored - create),
-                                                                                    (stored - start)});
-        } catch (SolrServerException e) {
-            throw new YardException(String.format("Exception while adding Document to Solr",
-                representation.getId()), e);
-        } catch (IOException e) {
-            throw new YardException("Unable to access SolrServer", e);
+            log.debug("  ... done [create={}ms|store={}ms|sum={}ms]", 
+                new Object[] {(create - start),(stored - create),(stored - start)});
+        } catch (PrivilegedActionException pae){
+            if(pae.getException() instanceof SolrServerException){
+                throw new YardException(String.format("Exception while adding Document to Solr",
+                    representation.getId()), pae.getException());
+            } else if( pae.getException() instanceof IOException){
+                throw new YardException("Unable to access SolrServer", pae.getException());
+            } else {
+                throw RuntimeException.class.cast(pae.getException());
+            }
         }
         return representation;
     }
@@ -1359,7 +1424,7 @@ public class SolrYard extends AbstractYa
                 ids.add(representation.getId());
             }
         }
-        SolrServer server = getServer();
+        final SolrServer server = getServer();
         FieldMapper fieldMapper = getFieldMapper();
         int numDocs = ids.size(); // for debuging
         try {
@@ -1384,19 +1449,29 @@ public class SolrYard extends AbstractYa
         long created = System.currentTimeMillis();
         if (!inputDocs.isEmpty()) {
             try {
-                UpdateRequest update = new UpdateRequest();
+                final UpdateRequest update = new UpdateRequest();
                 if (!immediateCommit) {
                     update.setCommitWithin(commitWithin);
                 }
                 update.add(inputDocs);
-                update.process(server);
-                if (immediateCommit) {
-                    server.commit();
+                AccessController.doPrivileged(new PrivilegedExceptionAction<Object>() {
+                    public UpdateResponse run() throws IOException, SolrServerException {
+                        update.process(server);
+                        if (immediateCommit) {
+                            server.commit();
+                        }
+                        return null;
+                    }
+                });
+            } catch (PrivilegedActionException pae){
+                if(pae.getException() instanceof SolrServerException){
+                    throw new YardException("Error while adding updated Documents to the SolrServer", 
+                        pae.getException());
+                } else if( pae.getException() instanceof IOException){
+                    throw new YardException("Unable to access SolrServer", pae.getException());
+                } else {
+                    throw RuntimeException.class.cast(pae.getException());
                 }
-            } catch (SolrServerException e) {
-                throw new YardException("Error while adding updated Documents to the SolrServer", e);
-            } catch (IOException e) {
-                throw new YardException("Unable to access Solr server", e);
             }
         }
         long ready = System.currentTimeMillis();
@@ -1415,9 +1490,23 @@ public class SolrYard extends AbstractYa
      * @param inputDoc
      *            the document to store
      */
-    protected final void storeSolrDocument(SolrServer server, SolrInputDocument inputDoc) 
+    protected final void storeSolrDocument(final SolrServer server, final SolrInputDocument inputDoc) 
                                            throws SolrServerException,IOException {
-        server.add(inputDoc);
+        try {
+            AccessController.doPrivileged(new PrivilegedExceptionAction<UpdateResponse>() {
+                public UpdateResponse run() throws IOException, SolrServerException {
+                    return server.add(inputDoc);
+                }
+            });
+        } catch (PrivilegedActionException pae) {
+            if(pae.getException() instanceof SolrServerException){
+                throw (SolrServerException)pae.getException();
+            } else if( pae.getException() instanceof IOException){
+                throw (IOException)pae.getException();
+            } else {
+                throw RuntimeException.class.cast(pae.getException());
+            }
+        }
     }
 
     /**
@@ -1431,13 +1520,13 @@ public class SolrYard extends AbstractYa
         return getSolrDocument(server, fieldMapper, uri, null);
     }
 
-    protected final Collection<SolrDocument> getSolrDocuments(SolrServer server,
+    protected final Collection<SolrDocument> getSolrDocuments(final SolrServer server,
                                                               FieldMapper fieldMapper,
                                                               Collection<String> uris, 
                                                               Collection<String> fields) 
                                                               throws SolrServerException, IOException {
         SolrYardConfig config = (SolrYardConfig) getConfig();
-        SolrQuery solrQuery = new SolrQuery();
+        final SolrQuery solrQuery = new SolrQuery();
         if (fields == null || fields.isEmpty()) {
             solrQuery.addField("*"); // select all fields
         } else {
@@ -1483,7 +1572,23 @@ public class SolrYard extends AbstractYa
             // set the number of results to the number of parsed IDs.
             solrQuery.setRows(num);
             num = 0; // reset to 0
-            QueryResponse queryResponse = server.query(solrQuery, METHOD.POST);
+            QueryResponse queryResponse;
+            try {
+                queryResponse = AccessController.doPrivileged(new PrivilegedExceptionAction<QueryResponse>() {
+                    public QueryResponse run() throws IOException, SolrServerException {
+                        return server.query(solrQuery, METHOD.POST);
+                    }
+                });
+            } catch (PrivilegedActionException pae) {
+                Exception e = pae.getException();
+                if(e instanceof SolrServerException){
+                    throw (SolrServerException)e;
+                } else if(e instanceof IOException){
+                    throw (IOException)e;
+                } else {
+                    throw RuntimeException.class.cast(e);
+                }
+            }
             if (resultDocs == null) {
                 resultDocs = queryResponse.getResults();
             } else {
@@ -1499,12 +1604,12 @@ public class SolrYard extends AbstractYa
         return resultDocs;
     }
 
-    protected final SolrDocument getSolrDocument(SolrServer server,
+    protected final SolrDocument getSolrDocument(final SolrServer server,
                                                  FieldMapper fieldMapper,
                                                  String uri, 
                                                  Collection<String> fields) 
                                                  throws SolrServerException, IOException {
-        SolrQuery solrQuery = new SolrQuery();
+        final SolrQuery solrQuery = new SolrQuery();
         if (fields == null || fields.isEmpty()) {
             solrQuery.addField("*"); // select all fields
         } else {
@@ -1518,7 +1623,23 @@ public class SolrYard extends AbstractYa
         String queryString = String.format("%s:%s", fieldMapper.getDocumentIdField(),
             SolrUtil.escapeSolrSpecialChars(uri));
         solrQuery.setQuery(queryString);
-        QueryResponse queryResponse = server.query(solrQuery, METHOD.POST);
+        QueryResponse queryResponse;
+        try {
+            queryResponse = AccessController.doPrivileged(new PrivilegedExceptionAction<QueryResponse>() {
+                public QueryResponse run() throws IOException, SolrServerException {
+                    return server.query(solrQuery, METHOD.POST);
+                }
+            });
+        } catch (PrivilegedActionException pae) {
+            Exception e = pae.getException();
+            if(e instanceof SolrServerException){
+                throw (SolrServerException)e;
+            } else if(e instanceof IOException){
+                throw (IOException)e;
+            } else {
+                throw RuntimeException.class.cast(e);
+            }
+        }
         if (queryResponse.getResults().isEmpty()) {
             return null;
         } else {