4

Here's my problem: When I try to pass a query string in CMIS Query that contains single or double quotes it doesn't execute and gives an error as below:

06:19:23,306 ERROR [DispatcherPortlet:561] Could not complete request
org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException: Internal Server Error
at org.apache.chemistry.opencmis.client.bindings.spi.atompub.AbstractAtomPubService.convertStatusCode(AbstractAtomPubService.java:506)
at org.apache.chemistry.opencmis.client.bindings.spi.atompub.AbstractAtomPubService.post(AbstractAtomPubService.java:661)
at org.apache.chemistry.opencmis.client.bindings.spi.atompub.DiscoveryServiceImpl.query(DiscoveryServiceImpl.java:179)
at org.apache.chemistry.opencmis.client.runtime.SessionImpl$6.fetchPage(SessionImpl.java:935)
at org.apache.chemistry.opencmis.client.runtime.util.AbstractIterator.getCurrentPage(AbstractIterator.java:132)
at org.apache.chemistry.opencmis.client.runtime.util.AbstractIterator.getPageNumItems(AbstractIterator.java:57)
at org.apache.chemistry.opencmis.client.runtime.util.AbstractIterable.getPageNumItems(AbstractIterable.java:86)
at com.zeetv.util.UtilMethods.getQueryResults(UtilMethods.java:349)
at com.zeetv.action.twitter.TwitterController.checkTitle(TwitterController.java:121)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:175)
at org.springframework.web.portlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:369)
at org.springframework.web.portlet.mvc.annotation.AnnotationMethodHandlerAdapter.doHandle(AnnotationMethodHandlerAdapter.java:356)
at org.springframework.web.portlet.mvc.annotation.AnnotationMethodHandlerAdapter.handleResource(AnnotationMethodHandlerAdapter.java:302)
at org.springframework.web.portlet.DispatcherPortlet.doResourceService(DispatcherPortlet.java:859)
at org.springframework.web.portlet.FrameworkPortlet.processRequest(FrameworkPortlet.java:527)
at org.springframework.web.portlet.FrameworkPortlet.serveResource(FrameworkPortlet.java:479)

Here's my query string:

select * from my:content where cmis:name Like 'test's new content1'

I've also tried like this:

select * from my:content where cmis:name Like '"test's new content1"'

Thanks in advance.

TT.
  • 15,774
  • 6
  • 47
  • 88
User14141111
  • 355
  • 2
  • 19
  • 3
    You may want to use the OpenCMIS QueryStatement class (https://chemistry.apache.org/java/0.13.0/maven/apidocs/org/apache/chemistry/opencmis/client/api/QueryStatement.html). It does all the escaping for you. – Florian Müller Jan 22 '16 at 08:28
  • As you tag this with "Liferay": Is this related to Liferay's CMIS store or a query that you execute yourself towards Alfresco that just happens to be within a Liferay application? – Olaf Kock Jan 22 '16 at 09:31
  • @OlafKock yes, I am calling alfresco from liferay. – User14141111 Jan 22 '16 at 11:48
  • @FlorianMüller thanks for the help. It worked with QueryStatement. :) – User14141111 Jan 22 '16 at 11:50

1 Answers1

3

Please consider reviewing this :

String literals are enclosed in single quotes. Escaping does not follow SQL-92 escaping. Two single quotes within a string literal do not represent a quote character: '''' is not a single quote literal.

CMIS defines backslash-based escaping with the available escape characters, determined by context.

'bob\'s' is used in place of 'bob''s'

SELECT * from cmis:document WHERE cmis:name = 'bob\'s'

Basic escaping:

  • \\ represents \
  • \' represents '

...

Younes Regaieg
  • 4,156
  • 2
  • 21
  • 37