incubator-connectors-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kwri...@apache.org
Subject svn commit: r1150719 - in /incubator/lcf/branches/CONNECTORS-221/connectors/cmis/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/cmis: CmisAuthorityConnector.java CmisRepositoryConnector.java
Date Mon, 25 Jul 2011 14:28:06 GMT
Author: kwright
Date: Mon Jul 25 14:28:05 2011
New Revision: 1150719

URL: http://svn.apache.org/viewvc?rev=1150719&view=rev
Log:
Fix exception handling

Modified:
    incubator/lcf/branches/CONNECTORS-221/connectors/cmis/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/cmis/CmisAuthorityConnector.java
    incubator/lcf/branches/CONNECTORS-221/connectors/cmis/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/cmis/CmisRepositoryConnector.java

Modified: incubator/lcf/branches/CONNECTORS-221/connectors/cmis/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/cmis/CmisAuthorityConnector.java
URL: http://svn.apache.org/viewvc/incubator/lcf/branches/CONNECTORS-221/connectors/cmis/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/cmis/CmisAuthorityConnector.java?rev=1150719&r1=1150718&r2=1150719&view=diff
==============================================================================
--- incubator/lcf/branches/CONNECTORS-221/connectors/cmis/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/cmis/CmisAuthorityConnector.java
(original)
+++ incubator/lcf/branches/CONNECTORS-221/connectors/cmis/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/cmis/CmisAuthorityConnector.java
Mon Jul 25 14:28:05 2011
@@ -17,21 +17,12 @@
 package org.apache.manifoldcf.crawler.connectors.cmis;
 
 import java.io.IOException;
-import java.io.InterruptedIOException;
-import java.rmi.NotBoundException;
-import java.rmi.RemoteException;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 
-import org.apache.chemistry.opencmis.client.api.Session;
-import org.apache.chemistry.opencmis.client.api.SessionFactory;
-import org.apache.chemistry.opencmis.client.runtime.SessionFactoryImpl;
-import org.apache.chemistry.opencmis.commons.SessionParameter;
-import org.apache.chemistry.opencmis.commons.enums.BindingType;
 import org.apache.commons.lang.StringUtils;
-import org.apache.manifoldcf.agents.interfaces.ServiceInterruption;
 import org.apache.manifoldcf.authorities.authorities.BaseAuthorityConnector;
 import org.apache.manifoldcf.authorities.interfaces.AuthorizationResponse;
 import org.apache.manifoldcf.core.interfaces.CacheManagerFactory;
@@ -75,27 +66,13 @@ public class CmisAuthorityConnector exte
   private static final String TAB_NAME_REPOSITORY = "Repository";
   private static final String TAB_NAME_USER_MAPPING = "User Mapping";
   
-  private static final String DEFAULT_VALUE_USERNAME = "admin";
-  private static final String DEFAULT_VALUE_PASSWORD = "pwd";
   private static final String DEFAULT_VALUE_ENDPOINT = "http://localhost:8080/cmis/";
   private static final String DEFAULT_VALUE_REPOSITORY_ID = "uuid";
 
-  
-  /**
-   * CMIS Session handle
-   */
-  Session session = null;
-  
-  protected String username = null;
-  protected String password = null;
   protected String endpoint = null;
   protected String repositoryId = null;
 
-  protected SessionFactory factory = SessionFactoryImpl.newInstance();
   protected Map<String, String> parameters = new HashMap<String, String>();
-
-  protected static final long timeToRelease = 300000L;
-  protected long lastSessionFetch = -1L;
   
   /** The cache manager. */
   protected ICacheManager cacheManager = null;
@@ -139,102 +116,6 @@ public class CmisAuthorityConnector exte
     super();
   }
   
-  protected class CheckConnectionThread extends Thread {
-    protected Throwable exception = null;
-
-    public CheckConnectionThread() {
-      super();
-      setDaemon(true);
-    }
-
-    public void run() {
-      try {
-        session.getRepositoryInfo();
-      } catch (Throwable e) {
-        this.exception = e;
-      }
-    }
-
-    public Throwable getException() {
-      return exception;
-    }
-
-  }
-  
-  protected class GetSessionThread extends Thread {
-    protected Throwable exception = null;
-
-    public GetSessionThread() {
-      super();
-      setDaemon(true);
-    }
-
-    public void run() {
-      try {
-        // Create a session
-        parameters.clear();
-
-        // user credentials
-        parameters.put(SessionParameter.USER, username);
-        parameters.put(SessionParameter.PASSWORD, password);
-
-        // connection settings
-        parameters.put(SessionParameter.ATOMPUB_URL, endpoint);
-        parameters.put(SessionParameter.BINDING_TYPE, BindingType.ATOMPUB.value());
-
-        // get a session from the repository specified in the
-        // configuration with its own ID
-        parameters.put(SessionParameter.REPOSITORY_ID, repositoryId);
-        session = factory.createSession(parameters);
-        
-      } catch (Throwable e) {
-        this.exception = e;
-      }
-    }
-
-    public Throwable getException() {
-      return exception;
-    }
-  }
-  
-  protected class DestroySessionThread extends Thread {
-    protected Throwable exception = null;
-
-    public DestroySessionThread() {
-      super();
-      setDaemon(true);
-    }
-
-    public void run() {
-      try {
-        session = null;
-      } catch (Throwable e) {
-        this.exception = e;
-      }
-    }
-
-    public Throwable getException() {
-      return exception;
-    }
-
-  }
-  
-  /**
-   * This method create a new CMIS session for a CMIS repository, if the
-   * repositoryId is not provided in the configuration, the connector will
-   * retrieve all the repositories exposed for this endpoint the it will start
-   * to use the first one.
-   */
-  @Override
-  public void connect(ConfigParams configParams) {
-    super.connect(configParams);
-    username = params.getParameter(CONFIG_PARAM_USERNAME);
-    password = params.getParameter(CONFIG_PARAM_PASSWORD);
-    endpoint = params.getParameter(CONFIG_PARAM_ENDPOINT);
-    repositoryId = params.getParameter(CONFIG_PARAM_REPOSITORY_ID);
-    String userNameMapping = params.getParameter(CONFIG_PARAM_USERMAPPING);
-    matchMap = new MatchMap(userNameMapping);
-  }
   
   /**
    * Output the configuration body section. This method is called in the body
@@ -258,15 +139,9 @@ public class CmisAuthorityConnector exte
       IHTTPOutput out, ConfigParams parameters, String tabName)
       throws ManifoldCFException, IOException {
 
-    String username = parameters.getParameter(CONFIG_PARAM_USERNAME);
-    String password = parameters.getParameter(CONFIG_PARAM_PASSWORD);
     String endpoint = parameters.getParameter(CONFIG_PARAM_ENDPOINT);
     String repositoryId = parameters.getParameter(CONFIG_PARAM_REPOSITORY_ID);
     
-    if(StringUtils.isEmpty(username))
-      username = DEFAULT_VALUE_USERNAME;
-    if(StringUtils.isEmpty(password))
-      password = DEFAULT_VALUE_PASSWORD;
     if(StringUtils.isEmpty(endpoint))
       endpoint = DEFAULT_VALUE_ENDPOINT;
     if(StringUtils.isEmpty(repositoryId))
@@ -287,13 +162,6 @@ public class CmisAuthorityConnector exte
     {
     out.print("<table class=\"displaytable\">\n"
         + "  <tr><td class=\"separator\" colspan=\"2\"><hr/></td></tr>\n");
-    out.print(
-        "<tr><td class=\"description\"><nobr>Username:</nobr></td>\n"
-       +"<td class=\"value\"><input type=\"text\" name=\""
-        + CONFIG_PARAM_USERNAME + "\" value=\""+Encoder.attributeEscape(username)+"\"/></td></tr>\n");
-    out.print("<tr><td class=\"description\"><nobr>Password:</nobr></td>"
+
-        "<td class=\"value\"><input type=\"password\" name=\""
-        + CONFIG_PARAM_PASSWORD + "\" value=\""+Encoder.attributeEscape(password)+"\"/></td></tr>\n");
     out.print("<tr><td class=\"description\"><nobr>Endpoint:</nobr></td>"
+
         "<td class=\"value\"><input type=\"text\" name=\""
         + CONFIG_PARAM_ENDPOINT + "\" value=\""+Encoder.attributeEscape(endpoint)+"\" size=\"50\"/></td></tr>\n");
@@ -304,8 +172,6 @@ public class CmisAuthorityConnector exte
     }
     else
     {
-      out.print("<input type=\"hidden\" name=\""+CONFIG_PARAM_USERNAME+"\" value=\""+Encoder.attributeEscape(username)+"\"/>\n");
-      out.print("<input type=\"hidden\" name=\""+CONFIG_PARAM_PASSWORD+"\" value=\""+Encoder.attributeEscape(password)+"\"/>\n");
       out.print("<input type=\"hidden\" name=\""+CONFIG_PARAM_ENDPOINT+"\" value=\""+Encoder.attributeEscape(endpoint)+"\"/>\n");
       out.print("<input type=\"hidden\" name=\""+CONFIG_PARAM_REPOSITORY_ID+"\" value=\""+Encoder.attributeEscape(repositoryId)+"\"/>\n");
     }
@@ -366,24 +232,12 @@ public class CmisAuthorityConnector exte
     
     out.print("<script type=\"text/javascript\">\n" + "<!--\n"
         + "function checkConfig()\n" + "{\n"
-        + "  if (editconnection.username.value == \"\")\n" + "  {\n"
-        + "    alert(\"The username must be not null\");\n"
-        + "    editconnection.username.focus();\n" + "    return false;\n"
-        + "  }\n" + "  if (editconnection.password.value == \"\")\n" + "  {\n"
-        + "    alert(\"The password must be not null\");\n"
-        + "    editconnection.password.focus();\n" + "    return false;\n"
-        + "  }\n" + "  if (editconnection.endpoint.value == \"\")\n" + "  {\n"
+        + "  if (editconnection.endpoint.value == \"\")\n" + "  {\n"
         + "    alert(\"The endpoint must be not null\");\n"
         + "    editconnection.endpoint.focus();\n" + "    return false;\n"
         + "  }\n" + "\n" + "  return true;\n" + "}\n" + " \n"
         + "function checkConfigForSave()\n" + "{\n"
-        + "  if (editconnection.username.value == \"\")\n" + "  {\n"
-        + "    alert(\"The username must be not null\");\n"
-        + "    editconnection.username.focus();\n" + "    return false;\n"
-        + "  }\n" + "  if (editconnection.password.value == \"\")\n" + "  {\n"
-        + "    alert(\"The password must be not null\");\n"
-        + "    editconnection.password.focus();\n" + "    return false;\n"
-        + "  }\n" + "  if (editconnection.endpoint.value == \"\")\n" + "  {\n"
+        + "  if (editconnection.endpoint.value == \"\")\n" + "  {\n"
         + "    alert(\"The endpoint must be not null\");\n"
         + "    editconnection.endpoint.focus();\n" + "    return false;\n"
         + "  }\n" + "  if (editconnection.repositoryId.value == \"\")\n" + "  {\n"
@@ -418,14 +272,6 @@ public class CmisAuthorityConnector exte
       throws ManifoldCFException {
 
     //Repository
-    String username = variableContext.getParameter(CONFIG_PARAM_USERNAME);
-    if (StringUtils.isNotEmpty(username))
-      parameters.setParameter(CONFIG_PARAM_USERNAME, username);
-
-    String password = variableContext.getParameter(CONFIG_PARAM_PASSWORD);
-    if (StringUtils.isNotEmpty(password))
-      parameters.setParameter(CONFIG_PARAM_PASSWORD, password);
-
     String endpoint = variableContext.getParameter(CONFIG_PARAM_ENDPOINT);
     if (StringUtils.isNotEmpty(endpoint) && endpoint.length() > 0)
       parameters.setParameter(CONFIG_PARAM_ENDPOINT, endpoint);
@@ -448,167 +294,6 @@ public class CmisAuthorityConnector exte
     return null;
 
   }
-
-  @Override
-  public String check() throws ManifoldCFException {
-    try {
-      checkConnection();
-      return super.check();
-    } catch (ServiceInterruption e) {
-      return "Connection temporarily failed: " + e.getMessage();
-    } catch (ManifoldCFException e) {
-      return "Connection failed: " + e.getMessage();
-    }
-  }
-
-  protected void checkConnection() throws ManifoldCFException,
-      ServiceInterruption {
-    while (true) {
-      boolean noSession = (session == null);
-      getSession();
-      long currentTime;
-      CheckConnectionThread t = new CheckConnectionThread();
-      try {
-        t.start();
-        t.join();
-        Throwable thr = t.getException();
-        if (thr != null) {
-          if (thr instanceof RemoteException)
-            throw (RemoteException) thr;
-          else
-            throw (Error) thr;
-        }
-        return;
-      } catch (InterruptedException e) {
-        t.interrupt();
-        throw new ManifoldCFException("Interrupted: " + e.getMessage(), e,
-            ManifoldCFException.INTERRUPTED);
-      } catch (RemoteException e) {
-        Throwable e2 = e.getCause();
-        if (e2 instanceof InterruptedException
-            || e2 instanceof InterruptedIOException)
-          throw new ManifoldCFException(e2.getMessage(), e2,
-              ManifoldCFException.INTERRUPTED);
-        if (noSession) {
-          currentTime = System.currentTimeMillis();
-          throw new ServiceInterruption(
-              "Transient error connecting to filenet service: "
-                  + e.getMessage(), currentTime + 60000L);
-        }
-        session = null;
-        lastSessionFetch = -1L;
-        continue;
-      }
-    }
-  }
-  
-  protected void getSession() throws ManifoldCFException, ServiceInterruption {
-    if (session == null) {
-      // Check for parameter validity
-      if (StringUtils.isEmpty(username))
-        throw new ManifoldCFException("Parameter " + CONFIG_PARAM_USERNAME
-            + " required but not set");
-
-      if (Logging.connectors.isDebugEnabled())
-        Logging.connectors.debug("CMIS: Username = '" + username + "'");
-
-      if (StringUtils.isEmpty(password))
-        throw new ManifoldCFException("Parameter " + CONFIG_PARAM_PASSWORD
-            + " required but not set");
-
-      Logging.connectors.debug("CMIS: Password exists");
-
-      if (StringUtils.isEmpty(endpoint))
-        throw new ManifoldCFException("Parameter " + CONFIG_PARAM_ENDPOINT
-            + " required but not set");
-
-      long currentTime;
-      GetSessionThread t = new GetSessionThread();
-      try {
-        t.start();
-        t.join();
-        Throwable thr = t.getException();
-        if (thr != null) {
-          if (thr instanceof java.net.MalformedURLException)
-            throw (java.net.MalformedURLException) thr;
-          else if (thr instanceof NotBoundException)
-            throw (NotBoundException) thr;
-          else if (thr instanceof RemoteException)
-            throw (RemoteException) thr;
-          else
-            throw (Error) thr;
-        }
-      } catch (InterruptedException e) {
-        t.interrupt();
-        throw new ManifoldCFException("Interrupted: " + e.getMessage(), e,
-            ManifoldCFException.INTERRUPTED);
-      } catch (java.net.MalformedURLException e) {
-        throw new ManifoldCFException(e.getMessage(), e);
-      } catch (NotBoundException e) {
-        // Transient problem: Server not available at the moment.
-        Logging.connectors.warn(
-            "CMIS: Server not up at the moment: " + e.getMessage(), e);
-        currentTime = System.currentTimeMillis();
-        throw new ServiceInterruption(e.getMessage(), currentTime + 60000L);
-      } catch (RemoteException e) {
-        Throwable e2 = e.getCause();
-        if (e2 instanceof InterruptedException
-            || e2 instanceof InterruptedIOException)
-          throw new ManifoldCFException(e2.getMessage(), e2,
-              ManifoldCFException.INTERRUPTED);
-        // Treat this as a transient problem
-        Logging.connectors.warn(
-            "CMIS: Transient remote exception creating session: "
-                + e.getMessage(), e);
-        currentTime = System.currentTimeMillis();
-        throw new ServiceInterruption(e.getMessage(), currentTime + 60000L);
-      }
-
-    }
-
-    lastSessionFetch = System.currentTimeMillis();
-  }
-  
-  @Override
-  public void poll() throws ManifoldCFException {
-    if (lastSessionFetch == -1L)
-      return;
-
-    long currentTime = System.currentTimeMillis();
-    if (currentTime >= lastSessionFetch + timeToRelease) {
-      DestroySessionThread t = new DestroySessionThread();
-      try {
-        t.start();
-        t.join();
-        Throwable thr = t.getException();
-        if (thr != null) {
-          if (thr instanceof RemoteException)
-            throw (RemoteException) thr;
-          else
-            throw (Error) thr;
-        }
-        session = null;
-        lastSessionFetch = -1L;
-      } catch (InterruptedException e) {
-        t.interrupt();
-        throw new ManifoldCFException("Interrupted: " + e.getMessage(), e,
-            ManifoldCFException.INTERRUPTED);
-      } catch (RemoteException e) {
-        Throwable e2 = e.getCause();
-        if (e2 instanceof InterruptedException
-            || e2 instanceof InterruptedIOException)
-          throw new ManifoldCFException(e2.getMessage(), e2,
-              ManifoldCFException.INTERRUPTED);
-        session = null;
-        lastSessionFetch = -1L;
-        // Treat this as a transient problem
-        Logging.connectors.warn(
-            "CMIS: Transient remote exception closing session: "
-                + e.getMessage(), e);
-      }
-
-    }
-  }
   
   /**
    * View configuration. This method is called in the body section of the
@@ -636,18 +321,10 @@ public class CmisAuthorityConnector exte
     while (iter.hasNext()) {
       String param = (String) iter.next();
       String value = parameters.getParameter(param);
-      if (param.length() >= "password".length()
-          && param.substring(param.length() - "password".length())
-              .equalsIgnoreCase("password")) {
-        out.print("      <nobr>"
-            + org.apache.manifoldcf.ui.util.Encoder.bodyEscape(param)
-            + "=********</nobr><br/>\n");
-      } else {
         out.print("      <nobr>"
             + org.apache.manifoldcf.ui.util.Encoder.bodyEscape(param) + "="
             + org.apache.manifoldcf.ui.util.Encoder.bodyEscape(value)
             + "</nobr><br/>\n");
-      }
     }
     out.print("</td>\n" + "  </tr>\n" + "</table>\n");
   }
@@ -795,5 +472,5 @@ public class CmisAuthorityConnector exte
       }
       
     }
-  
-}
+    
+}
\ No newline at end of file

Modified: incubator/lcf/branches/CONNECTORS-221/connectors/cmis/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/cmis/CmisRepositoryConnector.java
URL: http://svn.apache.org/viewvc/incubator/lcf/branches/CONNECTORS-221/connectors/cmis/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/cmis/CmisRepositoryConnector.java?rev=1150719&r1=1150718&r2=1150719&view=diff
==============================================================================
--- incubator/lcf/branches/CONNECTORS-221/connectors/cmis/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/cmis/CmisRepositoryConnector.java
(original)
+++ incubator/lcf/branches/CONNECTORS-221/connectors/cmis/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/cmis/CmisRepositoryConnector.java
Mon Jul 25 14:28:05 2011
@@ -34,7 +34,6 @@ import org.apache.chemistry.opencmis.cli
 import org.apache.chemistry.opencmis.client.api.Document;
 import org.apache.chemistry.opencmis.client.api.Folder;
 import org.apache.chemistry.opencmis.client.api.ItemIterable;
-import org.apache.chemistry.opencmis.client.api.OperationContext;
 import org.apache.chemistry.opencmis.client.api.Property;
 import org.apache.chemistry.opencmis.client.api.QueryResult;
 import org.apache.chemistry.opencmis.client.api.Repository;
@@ -88,8 +87,6 @@ public class CmisRepositoryConnector ext
    * CMIS Session handle
    */
   Session session = null;
-  
-  OperationContext oc = null;
 
   protected String username = null;
   protected String password = null;
@@ -144,18 +141,29 @@ public class CmisRepositoryConnector ext
 
           // get a session from the first CMIS repository exposed by
           // the endpoint
-          List<Repository> repos = factory.getRepositories(parameters);
-          session = repos.get(0).createSession();
+          List<Repository> repos = null;
+          try {
+            repos = factory.getRepositories(parameters);
+            session = repos.get(0).createSession();
+          } catch (Exception e) {
+            Logging.connectors.error("CMIS: Error during getting CMIS repositories: please
check the endpoint parameters");
+            this.exception = e;
+          }
+          
         } else {
 
           // get a session from the repository specified in the
           // configuration with its own ID
           parameters.put(SessionParameter.REPOSITORY_ID, repositoryId);
-          session = factory.createSession(parameters);
-        }
+          
+          try {
+            session = factory.createSession(parameters);
+          } catch (Exception e) {
+            Logging.connectors.error("CMIS: Error during the creation of the new session:
please check the endpoint parameters");
+            this.exception = e;
+          }
         
-        oc = session.createOperationContext();
-        oc.setIncludeAcls(true);
+        }
 
       } catch (Throwable e) {
         this.exception = e;
@@ -876,7 +884,7 @@ public class CmisRepositoryConnector ext
             + nodeId + "'");
 
       CmisObject cmisObject = session.getObject(nodeId);
-
+      
       String errorCode = "OK";
       String errorDesc = StringUtils.EMPTY;
 



Mime
View raw message