Return-Path: X-Original-To: apmail-manifoldcf-commits-archive@www.apache.org Delivered-To: apmail-manifoldcf-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 053EF1127D for ; Tue, 17 Jun 2014 19:34:27 +0000 (UTC) Received: (qmail 21727 invoked by uid 500); 17 Jun 2014 19:34:26 -0000 Delivered-To: apmail-manifoldcf-commits-archive@manifoldcf.apache.org Received: (qmail 21679 invoked by uid 500); 17 Jun 2014 19:34:26 -0000 Mailing-List: contact commits-help@manifoldcf.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@manifoldcf.apache.org Delivered-To: mailing list commits@manifoldcf.apache.org Received: (qmail 21670 invoked by uid 99); 17 Jun 2014 19:34:26 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 17 Jun 2014 19:34:26 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 17 Jun 2014 19:34:25 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 397FA2388980; Tue, 17 Jun 2014 19:34:05 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1603270 - /manifoldcf/trunk/connectors/gridfs/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/gridfs/GridFSRepositoryConnector.java Date: Tue, 17 Jun 2014 19:34:04 -0000 To: commits@manifoldcf.apache.org From: kwright@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20140617193405.397FA2388980@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: kwright Date: Tue Jun 17 19:34:04 2014 New Revision: 1603270 URL: http://svn.apache.org/r1603270 Log: Fix CONNECTORS-966 for gridfs connector Modified: manifoldcf/trunk/connectors/gridfs/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/gridfs/GridFSRepositoryConnector.java Modified: manifoldcf/trunk/connectors/gridfs/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/gridfs/GridFSRepositoryConnector.java URL: http://svn.apache.org/viewvc/manifoldcf/trunk/connectors/gridfs/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/gridfs/GridFSRepositoryConnector.java?rev=1603270&r1=1603269&r2=1603270&view=diff ============================================================================== --- manifoldcf/trunk/connectors/gridfs/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/gridfs/GridFSRepositoryConnector.java (original) +++ manifoldcf/trunk/connectors/gridfs/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/gridfs/GridFSRepositoryConnector.java Tue Jun 17 19:34:04 2014 @@ -25,6 +25,7 @@ import com.mongodb.MongoClient; import com.mongodb.gridfs.GridFS; import com.mongodb.gridfs.GridFSDBFile; import java.io.IOException; +import java.io.InterruptedIOException; import java.io.InputStream; import java.net.UnknownHostException; import java.util.Date; @@ -449,39 +450,57 @@ public class GridFSRepositoryConnector e validURL = false; } if (validURL) { - InputStream is = document.getInputStream(); long fileLenght = document.getLength(); - Date indexingDate = new Date(); - rd.setBinary(is, fileLenght); - rd.setCreatedDate(document.getUploadDate()); - rd.setFileName(document.getFilename()); - rd.setIndexingDate(indexingDate); - rd.setMimeType(document.getContentType()); - if (acl != null) { - try { - Object aclObject = document.getMetaData().get(acl); - if (aclObject != null) { - List acls = (List) aclObject; - rd.setACL((String[]) acls.toArray()); + InputStream is = document.getInputStream(); + try { + Date indexingDate = new Date(); + rd.setBinary(is, fileLenght); + rd.setCreatedDate(document.getUploadDate()); + rd.setFileName(document.getFilename()); + rd.setIndexingDate(indexingDate); + rd.setMimeType(document.getContentType()); + String[] aclsArray = null; + String[] denyAclsArray = null; + if (acl != null) { + try { + Object aclObject = document.getMetaData().get(acl); + if (aclObject != null) { + List acls = (List) aclObject; + aclsArray = (String[]) acls.toArray(); + } + } catch (ClassCastException e) { + // This is bad because security will fail + Logging.connectors.warn("GridFS: Document " + _id + " metadata ACL field doesn't contain List type."); + throw new ManifoldCFException("Security decoding error: "+e.getMessage(),e); } - } catch (ClassCastException e) { - Logging.connectors.warn("GridFS: Document " + _id + " metadata ACL field doesn't contain List type."); } - } - if (denyAcl != null) { - try { - Object denyAclObject = document.getMetaData().get(denyAcl); - if (denyAclObject != null) { - List denyAcls = (List) denyAclObject; - denyAcls.add(GLOBAL_DENY_TOKEN); - rd.setDenyACL((String[]) denyAcls.toArray()); + if (denyAcl != null) { + try { + Object denyAclObject = document.getMetaData().get(denyAcl); + if (denyAclObject != null) { + List denyAcls = (List) denyAclObject; + denyAcls.add(GLOBAL_DENY_TOKEN); + denyAclsArray = (String[]) denyAcls.toArray(); + } + } catch (ClassCastException e) { + // This is bad because security will fail + Logging.connectors.warn("GridFS: Document " + _id + " metadata DenyACL field doesn't contain List type."); + throw new ManifoldCFException("Security decoding error: "+e.getMessage(),e); } - } catch (ClassCastException e) { - Logging.connectors.warn("GridFS: Document " + _id + " metadata DenyACL field doesn't contain List type."); + } + rd.setSecurity(RepositoryDocument.SECURITY_TYPE_DOCUMENT,aclsArray,denyAclsArray); + try { + activities.ingestDocumentWithException(_id, version, urlValue, rd); + } catch (IOException e) { + handleIOException(e); + } + } finally { + try { + is.close(); + } catch (IOException e) { + handleIOException(e); } } - activities.ingestDocument(_id, version, urlValue, rd); - IOUtils.closeQuietly(is); gfs.getDB().getMongo().getConnector().close(); session = null; activities.recordActivity(startTime, ACTIVITY_FETCH, @@ -501,6 +520,14 @@ public class GridFSRepositoryConnector e } } + protected static void handleIOException(IOException e) throws ManifoldCFException, ServiceInterruption { + if (e instanceof InterruptedIOException) { + throw new ManifoldCFException(e.getMessage(), e, ManifoldCFException.INTERRUPTED); + } else { + throw new ManifoldCFException(e.getMessage(), e); + } + } + /** * Get document versions given an array of document identifiers. This method * is called for EVERY document that is considered. It is therefore