You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@manifoldcf.apache.org by kw...@apache.org on 2011/10/06 11:04:28 UTC

svn commit: r1179543 - /incubator/lcf/branches/CONNECTORS-256/connectors/wiki/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/wiki/WikiConnector.java

Author: kwright
Date: Thu Oct  6 09:04:28 2011
New Revision: 1179543

URL: http://svn.apache.org/viewvc?rev=1179543&view=rev
Log:
Hook up check operation fully.

Modified:
    incubator/lcf/branches/CONNECTORS-256/connectors/wiki/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/wiki/WikiConnector.java

Modified: incubator/lcf/branches/CONNECTORS-256/connectors/wiki/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/wiki/WikiConnector.java
URL: http://svn.apache.org/viewvc/incubator/lcf/branches/CONNECTORS-256/connectors/wiki/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/wiki/WikiConnector.java?rev=1179543&r1=1179542&r2=1179543&view=diff
==============================================================================
--- incubator/lcf/branches/CONNECTORS-256/connectors/wiki/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/wiki/WikiConnector.java (original)
+++ incubator/lcf/branches/CONNECTORS-256/connectors/wiki/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/wiki/WikiConnector.java Thu Oct  6 09:04:28 2011
@@ -676,7 +676,22 @@ public class WikiConnector extends org.a
         if (rval != 200)
           throw new ManifoldCFException("Unexpected response code: "+rval);
         // Read response and make sure it's valid
-        // MHL
+        InputStream is = executeMethod.getResponseBodyAsStream();
+        try
+        {
+          parseCheckResponse(is);
+        }
+        finally
+        {
+          try
+          {
+            is.close();
+          }
+          catch (IllegalStateException e)
+          {
+            // Ignore this error
+          }
+        }
       }
       catch (Throwable e)
       {
@@ -691,6 +706,155 @@ public class WikiConnector extends org.a
 
   }
 
+  /** Parse check response, e.g.:
+  * <api xmlns="http://www.mediawiki.org/xml/api/">
+  *   <query>
+  *     <allpages>
+  *       <p pageid="19839654" ns="0" title="Kre&#039;fey" />
+  *     </allpages>
+  *   </query>
+  *   <query-continue>
+  *     <allpages apfrom="Krea" />
+  *   </query-continue>
+  * </api>
+  */
+  protected static void parseCheckResponse(InputStream is)
+    throws ManifoldCFException, ServiceInterruption
+  {
+    // Parse the document.  This will cause various things to occur, within the instantiated XMLContext class.
+    XMLStream x = new XMLStream();
+    WikiCheckAPIContext c = new WikiCheckAPIContext(x);
+    x.setContext(c);
+    try
+    {
+      try
+      {
+        x.parse(is);
+        if (!c.hasResponse())
+          throw new ManifoldCFException("Valid API response not detected");
+      }
+      catch (IOException e)
+      {
+        long time = System.currentTimeMillis();
+        throw new ServiceInterruption(e.getMessage(),e,time + 300000L,time + 12L * 60000L,-1,false);
+      }
+    }
+    finally
+    {
+      x.cleanup();
+    }
+  }
+
+  /** Class representing the "api" context of a "check" response */
+  protected static class WikiCheckAPIContext extends SingleLevelContext
+  {
+    boolean responseSeen = false;
+    
+    public WikiCheckAPIContext(XMLStream theStream)
+    {
+      super(theStream,"api");
+    }
+
+    protected BaseProcessingContext createChild(String namespaceURI, String localName, String qName, Attributes atts)
+    {
+      return new WikiCheckQueryContext(theStream);
+    }
+    
+    protected void finishChild(BaseProcessingContext child)
+    {
+      responseSeen |= ((WikiCheckQueryContext)child).hasResponse();
+    }
+
+    protected void process()
+      throws ManifoldCFException
+    {
+    }
+    
+    public boolean hasResponse()
+    {
+      return responseSeen;
+    }
+
+  }
+
+  /** Class representing the "api/query" context of a "check" response */
+  protected static class WikiCheckQueryContext extends SingleLevelContext
+  {
+    protected boolean responseSeen = false;
+    
+    public WikiCheckQueryContext(XMLStream theStream)
+    {
+      super(theStream,"query");
+    }
+
+    protected BaseProcessingContext createChild(String namespaceURI, String localName, String qName, Attributes atts)
+    {
+      return new WikiCheckAllPagesContext(theStream);
+    }
+
+    protected void finishChild(BaseProcessingContext child)
+    {
+      responseSeen |= ((WikiCheckAllPagesContext)child).hasResponse();
+    }
+
+    protected void process()
+      throws ManifoldCFException
+    {
+    }
+    
+    public boolean hasResponse()
+    {
+      return responseSeen;
+    }
+    
+  }
+
+  /** Class recognizing the "api/query/allpages" context of a "check" response */
+  protected static class WikiCheckAllPagesContext extends SingleLevelContext
+  {
+    protected boolean responseSeen = false;
+    
+    public WikiCheckAllPagesContext(XMLStream theStream)
+    {
+      super(theStream,"allpages");
+    }
+
+    protected BaseProcessingContext createChild(String namespaceURI, String localName, String qName, Attributes atts)
+    {
+      return new WikiCheckPContext(theStream);
+    }
+
+    protected void finishChild(BaseProcessingContext child)
+    {
+      responseSeen |= true;
+    }
+
+    protected void process()
+      throws ManifoldCFException
+    {
+    }
+    
+    public boolean hasResponse()
+    {
+      return responseSeen;
+    }
+    
+  }
+  
+  /** Class representing the "api/query/allpages/p" context of a "check" response */
+  protected static class WikiCheckPContext extends BaseProcessingContext
+  {
+    public WikiCheckPContext(XMLStream theStream)
+    {
+      super(theStream);
+    }
+
+    protected void process()
+      throws ManifoldCFException
+    {
+    }
+    
+  }
 
   /** Execute an HttpClient method via thread, so we don't get stuck in socket wait */
   protected static int executeMethodViaThread(HttpClient client, HttpMethodBase executeMethod)