XMLDoc doc = new XMLDoc( list[0].toString() );
doc.processPath(nodeList, "*", null);
if (nodeList.size() != 1)
{
throw new ManifoldCFException("Bad xml - missing outer 'ns1:dsQueryResponse' node - there are "+Integer.toString(nodeList.size())+" nodes");
}
Object parent = nodeList.get(0);
//System.out.println( "Outer NodeName = " + doc.getNodeName(parent) );
if (!doc.getNodeName(parent).equals("ns1:dsQueryResponse"))
throw new ManifoldCFException("Bad xml - outer node is not 'ns1:dsQueryResponse'");
nodeList.clear();
doc.processPath(nodeList, "*", parent);
if ( nodeList.size() != 2 )
{
throw new ManifoldCFException( " No results found." );
}
// Now, extract the files from the response document
XMLDoc docs = doc;
ArrayList nodeDocs = new ArrayList();
docs.processPath( nodeDocs, "*", null );
parent = nodeDocs.get(0); // ns1:dsQueryResponse
nodeDocs.clear();
docs.processPath(nodeDocs, "*", parent);
Object documents = nodeDocs.get(1);
nodeDocs.clear();
docs.processPath(nodeDocs, "*", documents);
StringBuilder sb = new StringBuilder();
for( int j =0; j < nodeDocs.size(); j++)
{
Object node = nodeDocs.get(j);
Logging.connectors.debug( node.toString() );
String relPath = docs.getData( docs.getElement( node, "FileRef" ) );
fileStream.addFile( relPath );
}
}
else
{
// New code
MCPermissionsWS itemService = new MCPermissionsWS( baseUrl + site, userName, password, configuration, httpClient );
com.microsoft.sharepoint.webpartpages.PermissionsSoap itemCall = itemService.getPermissionsSoapHandler( );
int startingIndex = 0;
int amtToRequest = 10000;
while (true)
{
com.microsoft.sharepoint.webpartpages.GetListItemsResponseGetListItemsResult itemsResult =
itemCall.getListItems(guid,Integer.toString(startingIndex),Integer.toString(amtToRequest));
MessageElement[] itemsList = itemsResult.get_any();
if (Logging.connectors.isDebugEnabled()){
Logging.connectors.debug("SharePoint: getListItems xml response: '" + itemsList[0].toString() + "'");
}
if (itemsList.length != 1)
throw new ManifoldCFException("Bad response - expecting one outer 'GetListItems' node, saw "+Integer.toString(itemsList.length));
MessageElement items = itemsList[0];
if (!items.getElementName().getLocalName().equals("GetListItems"))
throw new ManifoldCFException("Bad response - outer node should have been 'GetListItems' node");
int resultCount = 0;
Iterator iter = items.getChildElements();
while (iter.hasNext())
{
MessageElement child = (MessageElement)iter.next();
if (child.getElementName().getLocalName().equals("GetListItemsResponse"))
{
Iterator resultIter = child.getChildElements();
while (resultIter.hasNext())
{
MessageElement result = (MessageElement)resultIter.next();
if (result.getElementName().getLocalName().equals("GetListItemsResult"))
{
resultCount++;
String relPath = result.getAttribute("FileRef");
fileStream.addFile( relPath );
}
}
}
}
if (resultCount < amtToRequest)
break;
startingIndex += resultCount;
}
}
return true;
}
catch (java.net.MalformedURLException e)
{
throw new ManifoldCFException("Bad SharePoint url: "+e.getMessage(),e);
}
catch (javax.xml.rpc.ServiceException e)
{
if (Logging.connectors.isDebugEnabled())
Logging.connectors.debug("SharePoint: Got a service exception getting documents for site "+site+" guid "+guid+" - retrying",e);
currentTime = System.currentTimeMillis();
throw new ServiceInterruption("Service exception: "+e.getMessage(), e, currentTime + 300000L,
currentTime + 12 * 60 * 60000L,-1,true);
}
catch (org.apache.axis.AxisFault e)
{
currentTime = System.currentTimeMillis();
if (e.getFaultCode().equals(new javax.xml.namespace.QName("http://xml.apache.org/axis/","HTTP")))
{
org.w3c.dom.Element elem = e.lookupFaultDetail(new javax.xml.namespace.QName("http://xml.apache.org/axis/","HttpErrorCode"));
if (elem != null)
{
elem.normalize();
String httpErrorCode = elem.getFirstChild().getNodeValue().trim();
if (httpErrorCode.equals("404"))
{
// Page did not exist
if (Logging.connectors.isDebugEnabled())
Logging.connectors.debug("SharePoint: The page at "+baseUrl+site+" did not exist; assuming library deleted");
return false;
}
else if (httpErrorCode.equals("401"))
{
// User did not have permissions for this library to get the acls
if (Logging.connectors.isDebugEnabled())
Logging.connectors.debug("SharePoint: The crawl user did not have access to list documents for "+baseUrl+site+"; skipping documents within");
return false;
}
else if (httpErrorCode.equals("403"))
throw new ManifoldCFException("Http error "+httpErrorCode+" while reading from "+baseUrl+site+" - check IIS and SharePoint security settings! "+e.getMessage(),e);
else
throw new ManifoldCFException("Unexpected http error code "+httpErrorCode+" accessing SharePoint at "+baseUrl+site+": "+e.getMessage(),e);
}
throw new ManifoldCFException("Unknown http error occurred: "+e.getMessage(),e);
}
else if (e.getFaultCode().equals(new javax.xml.namespace.QName("http://schemas.xmlsoap.org/soap/envelope/","Server")))
{
org.w3c.dom.Element elem = e.lookupFaultDetail(new javax.xml.namespace.QName("http://schemas.microsoft.com/sharepoint/soap/","errorcode"));
if (elem != null)
{
elem.normalize();
String sharepointErrorCode = elem.getFirstChild().getNodeValue().trim();
if (sharepointErrorCode.equals("0x82000006"))
{
// List did not exist
if (Logging.connectors.isDebugEnabled())
Logging.connectors.debug("SharePoint: The list "+guid+" in site "+site+" did not exist; assuming library deleted");
return false;
}
else
{
if (Logging.connectors.isDebugEnabled())
{
org.w3c.dom.Element elem2 = e.lookupFaultDetail(new javax.xml.namespace.QName("http://schemas.microsoft.com/sharepoint/soap/","errorstring"));
String errorString = "";
if (elem != null)
errorString = elem2.getFirstChild().getNodeValue().trim();
Logging.connectors.debug("SharePoint: Getting child documents for the list "+guid+" in site "+site+" failed with unexpected SharePoint error code "+sharepointErrorCode+": "+errorString+" - Skipping",e);
}
return false;
}
}
if (Logging.connectors.isDebugEnabled())
Logging.connectors.debug("SharePoint: Unknown SharePoint server error getting child documents for site "+site+" guid "+guid+" - axis fault = "+e.getFaultCode().getLocalPart()+", detail = "+e.getFaultString()+" - retrying",e);
throw new ServiceInterruption("Unknown SharePoint server error: "+e.getMessage()+" - retrying", e, currentTime + 300000L,
currentTime + 3 * 60 * 60000L,-1,false);
}
if (e.getFaultCode().equals(new javax.xml.namespace.QName("http://schemas.xmlsoap.org/soap/envelope/","Server.userException")))
{
String exceptionName = e.getFaultString();
if (exceptionName.equals("java.lang.InterruptedException"))
throw new ManifoldCFException("Interrupted",ManifoldCFException.INTERRUPTED);
}
if (Logging.connectors.isDebugEnabled())
Logging.connectors.debug("SharePoint: Got an unknown remote exception getting child documents for site "+site+" guid "+guid+" - axis fault = "+e.getFaultCode().getLocalPart()+", detail = "+e.getFaultString()+" - retrying",e);
throw new ServiceInterruption("Remote procedure exception: "+e.getMessage(), e, currentTime + 300000L,
currentTime + 3 * 60 * 60000L,-1,false);
}
catch (java.rmi.RemoteException e)
{
// We expect the axis exception to be thrown, not this generic one!
// So, fail hard if we see it.
if (Logging.connectors.isDebugEnabled())
Logging.connectors.debug("SharePoint: Got an unexpected remote exception getting child documents for site "+site+" guid "+guid,e);
throw new ManifoldCFException("Unexpected remote procedure exception: "+e.getMessage(), e);
}
}