Tutorial :Random failures using CMISQL queries on Alfresco 3.3.0


[Solved, it seems that there was some bug affecting Alfresco 3.3.0, which is no longer present on Alfresco 3.3.0g]


I'm using OpenCMIS to retrieve data from Alfresco 3.3, but it's having a very weird behaviour on CMISQL queries. I've googled somebody else with the same problems, but it seems I'm the first one all over the world :), so I guess it's my fault, not OpenCMIS'.

This is how I'm querying Alfresco:

public Class CmisTest {      private static Session sesion;        private static final String QUERY = "select cmis:objectid, cmis:name from cmis:folder where cmis:name='MyFolder'";        public static void main(String[] args) {          // Open a CMIS session with Alfresco          Map<String, String> params = new HashMap<String, String>();          params.put(SessionParameter.USER, "admin");          params.put(SessionParameter.PASSWORD, "admin");          params.put(SessionParameter.ATOMPUB_URL, "http://localhost:8080/alfresco/s/api/cmis");          params.put(SessionParameter.BINDING_TYPE, BindingType.ATOMPUB.value());          params.put(SessionParameter.REPOSITORY_ID, "fa9d2553-1e4d-491b-87fd-3de894dc7ca9");          sesion = SessionFactoryImpl.newInstance().createSession(params);            // Ugly bug in Alfresco which raises an exception if we request more data than it's available          // See https://issues.alfresco.com/jira/browse/ALF-2859          sesion.getDefaultContext().setMaxItemsPerPage(1);            // We repeat the same query 20 times and count the number of elements retrieved each time          for (int i = 0; i < 20; i++) {              List<QueryResult> result = doQuery();              System.out.println(result.size() + " folders retrieved");          }      }        public static List<QueryResult> doQuery() {          List<QueryResult> result = new LinkedList<QueryResult>();          try {              int page = 0;              while (true) {                  ItemIterable<QueryResult> iterable = sesion.query(QUERY, false).skipTo(page);                  page++;                  for (QueryResult qr : iterable) {                      result.add(qr);                  }              }          } catch (Exception e) {              // We will always get an exception when Alfresco has no more data to retrieve... :(              // See https://issues.alfresco.com/jira/browse/ALF-2859          }          return result;      }    }  

As you can see, we just execute the same query, up to 20 times in a row. You would expect the same result each time, wouldn't you? Unfortunately, this is a sample of what we get:

1 folders retrieved  1 folders retrieved  1 folders retrieved  0 folders retrieved  0 folders retrieved  0 folders retrieved  0 folders retrieved  0 folders retrieved  1 folders retrieved  1 folders retrieved  

Sometimes we get 20 1 in a row, sometimes it's all 0. We have never get a "mix" of 1 and 0, though; we always get "a run" of them.

It does not matter if we create the session before each query, we still have the random issue. We have tried against two different Alfresco servers (both of them 3.3 Community), clean installation, and they both fail randomly. We also tried to measure the time for each query, but it doesn't seem to have any relation with the result being wrong (0 folders retrieved) or right (1 folders retrieved).

Alfresco seems to be working fine: if we go to "Administration --> Node browser" and launch the CMISQL query from there, it always retrieves one folder, which is right. So, it must be our code, or an OpenCMIS bug...

Any ideas?


I can't reproduce this behavior. It's running fine against http://cmis.alfresco.com . The issue https://issues.alfresco.com/jira/browse/ALF-2859 states that there have been bug fixes. Are you running the latest Alfresco version?


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »