AnsweredAssumed Answered

WSSecurityException when using fetchMore method

Question asked by rubberballman on Dec 9, 2014
Can someone tell me what's wrong with my code here… I'm always getting this exception on the first call to <strong>contentService.read(…)</strong> after the first fetchMore has occurred.

<strong>org.apache.ws.security.WSSecurityException: The security token could not be authenticated or authorized</strong>


// Here we're setting the endpoint address manually, this way we don't need to use
// webserviceclient.properties
WebServiceFactory.setEndpointAddress(wsRepositoryEndpoint);
AuthenticationUtils.startSession(wsUsername, wsPassword);

// Set the batch size in the query header
int batchSize = 5000;
QueryConfiguration queryCfg = new QueryConfiguration();
queryCfg.setFetchSize(batchSize);
       
RepositoryServiceSoapBindingStub repositoryService = WebServiceFactory.getRepositoryService();
repositoryService.setHeader(new RepositoryServiceLocator().getServiceName().getNamespaceURI(), "QueryHeader", queryCfg);
       
ContentServiceSoapBindingStub contentService = WebServiceFactory.getContentService();

String luceneQuery = buildLuceneQuery(categories, properties);

// Call the repository service to do search based on category
Query query = new Query(Constants.QUERY_LANG_LUCENE, luceneQuery);

// Execute the query
QueryResult queryResult = repositoryService.query(STORE, query, true);
       
String querySession = queryResult.getQuerySession();
while (querySession != null) {           
    ResultSet resultSet = queryResult.getResultSet();
    ResultSetRow[] rows = resultSet.getRows();
    for (ResultSetRow row : rows) {
        // Read the content from the repository
        Content[] readResult = contentService.read(new Predicate(new Reference[] { new Reference(STORE, row.getNode().getId(), null) },
            STORE, null), Constants.PROP_CONTENT);
        Content content = readResult[0];
        […]
    }           
    // Get the next batch of results
    queryResult = repositoryService.fetchMore(querySession);
    // process subsequent query results
    querySession = queryResult.getQuerySession();
}

Outcomes