core icon indicating copy to clipboard operation
core copied to clipboard

Licensing: Improvements for Request Code REST Endpoint

Open joseorsini opened this issue 9 years ago • 7 comments

Under unknown circumstances, the License Request code feature returns error 500 on the dotCMS application. Despite that the actual call to the REST Endpoint that handles the Request Code generating includes all required values :

screen shot 2017-02-02 at 5 10 37 pm

Something is stripping the required values/params once the REST endpoint is invoked, the license level and license type values are null, therefore it throws an exception

[18/01/17 12:53:10:652 EST] ERROR rest.LicenseResource: can't request license
com.dotmarketing.business.DotStateException: invalid License Type
    at com.dotcms.rest.LicenseResource.requestLicense(LicenseResource.java:293) [dotcms_3.6.1_cfa5586.jar:?]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_45]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_45]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_45]
    at java.lang.reflect.Method.invoke(Method.java:497) ~[?:1.8.0_45]
    at com.dotcms.repackage.org.glassfish.jersey.server.model.internal.ResourceMethodInvocationHandlerFactory$1.invoke(ResourceMethodInvocationHandlerFactory.java:81) [dot.jersey-server-2.22.1_1.jar:?]
    at com.dotcms.repackage.org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher$1.run(AbstractJavaResourceMethodDispatcher.java:144) [dot.jersey-server-2.22.1_1.jar:?]
    at com.dotcms.repackage.org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.invoke(AbstractJavaResourceMethodDispatcher.java:161) [dot.jersey-server-2.22.1_1.jar:?]
    at com.dotcms.repackage.org.glassfish.jersey.server.model.internal.JavaResourceMethodDispatcherProvider$ResponseOutInvoker.doDispatch(JavaResourceMethodDispatcherProvider.java:160) [dot.jersey-server-2.22.1_1.jar:?]
    at com.dotcms.repackage.org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.dispatch(AbstractJavaResourceMethodDispatcher.java:99) [dot.jersey-server-2.22.1_1.jar:?]
    at com.dotcms.repackage.org.glassfish.jersey.server.model.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:389) [dot.jersey-server-2.22.1_1.jar:?]
    at com.dotcms.repackage.org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:347) [dot.jersey-server-2.22.1_1.jar:?]
    at com.dotcms.repackage.org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:102) [dot.jersey-server-2.22.1_1.jar:?]
    at com.dotcms.repackage.org.glassfish.jersey.server.ServerRuntime$2.run(ServerRuntime.java:326) [dot.jersey-server-2.22.1_1.jar:?]
    at com.dotcms.repackage.org.glassfish.jersey.internal.Errors$1.call(Errors.java:271) [dot.jersey-common-2.22.1_1.jar:?]
    at com.dotcms.repackage.org.glassfish.jersey.internal.Errors$1.call(Errors.java:267) [dot.jersey-common-2.22.1_1.jar:?]
    at com.dotcms.repackage.org.glassfish.jersey.internal.Errors.process(Errors.java:315) [dot.jersey-common-2.22.1_1.jar:?]
    at com.dotcms.repackage.org.glassfish.jersey.internal.Errors.process(Errors.java:297) [dot.jersey-common-2.22.1_1.jar:?]
    at com.dotcms.repackage.org.glassfish.jersey.internal.Errors.process(Errors.java:267) [dot.jersey-common-2.22.1_1.jar:?]
    at com.dotcms.repackage.org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:317) [dot.jersey-common-2.22.1_1.jar:?]
    at com.dotcms.repackage.org.glassfish.jersey.server.ServerRuntime.process(ServerRuntime.java:305) [dot.jersey-server-2.22.1_1.jar:?]
    at com.dotcms.repackage.org.glassfish.jersey.server.ApplicationHandler.handle(ApplicationHandler.java:1154) [dot.jersey-server-2.22.1_1.jar:?]
    at com.dotcms.repackage.org.glassfish.jersey.servlet.WebComponent.serviceImpl(WebComponent.java:471) [dot.jersey-container-servlet-core-2.22.1_1.jar:?]
    at com.dotcms.repackage.org.glassfish.jersey.servlet.WebComponent.service(WebComponent.java:425) [dot.jersey-container-servlet-core-2.22.1_1.jar:?]
    at com.dotcms.repackage.org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:383) [dot.jersey-container-servlet-core-2.22.1_1.jar:?]
    at com.dotcms.repackage.org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:336) [dot.jersey-container-servlet-core-2.22.1_1.jar:?]
    at com.dotcms.repackage.org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:223) [dot.jersey-container-servlet-core-2.22.1_1.jar:?]
    at com.dotcms.rest.servlet.ReloadableServletContainer.service(ReloadableServletContainer.java:106) [dotcms_3.6.1_cfa5586.jar:?]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291) [catalina.jar:8.0.18]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) [catalina.jar:8.0.18]
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) [tomcat-websocket.jar:8.0.18]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239) [catalina.jar:8.0.18]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) [catalina.jar:8.0.18]
    at com.dotmarketing.filters.CMSFilter.doFilter(CMSFilter.java:259) [dotcms_3.6.1_cfa5586.jar:?]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239) [catalina.jar:8.0.18]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) [catalina.jar:8.0.18]
    at com.dotmarketing.filters.AutoLoginFilter.doFilter(AutoLoginFilter.java:61) [dotcms_3.6.1_cfa5586.jar:?]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239) [catalina.jar:8.0.18]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) [catalina.jar:8.0.18]
    at com.dotmarketing.cms.urlmap.filters.URLMapFilter.doFilter(URLMapFilter.java:308) [dotcms_3.6.1_cfa5586.jar:?]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239) [catalina.jar:8.0.18]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) [catalina.jar:8.0.18]
    at com.dotcms.repackage.org.tuckey.web.filters.urlrewrite.RuleChain.handleRewrite(RuleChain.java:176) [dot.urlrewritefilter-4.0.3_2.jar:4.0.3]
    at com.dotcms.repackage.org.tuckey.web.filters.urlrewrite.RuleChain.doRules(RuleChain.java:145) [dot.urlrewritefilter-4.0.3_2.jar:4.0.3]
    at com.dotcms.repackage.org.tuckey.web.filters.urlrewrite.UrlRewriter.processRequest(UrlRewriter.java:92) [dot.urlrewritefilter-4.0.3_2.jar:4.0.3]
    at com.dotcms.repackage.org.tuckey.web.filters.urlrewrite.UrlRewriteFilter.doFilter(UrlRewriteFilter.java:394) [dot.urlrewritefilter-4.0.3_2.jar:4.0.3]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239) [catalina.jar:8.0.18]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) [catalina.jar:8.0.18]
    at com.dotmarketing.filters.TimeMachineFilter.doFilter(TimeMachineFilter.java:130) [dotcms_3.6.1_cfa5586.jar:?]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239) [catalina.jar:8.0.18]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) [catalina.jar:8.0.18]
    at com.dotmarketing.filters.ThreadNameFilter.doFilter(ThreadNameFilter.java:90) [dotcms_3.6.1_cfa5586.jar:?]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239) [catalina.jar:8.0.18]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) [catalina.jar:8.0.18]
    at com.dotmarketing.filters.CookiesFilter.doFilter(CookiesFilter.java:33) [dotcms_3.6.1_cfa5586.jar:?]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239) [catalina.jar:8.0.18]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) [catalina.jar:8.0.18]
    at com.dotmarketing.filters.CharsetEncodingFilter.doFilter(CharsetEncodingFilter.java:146) [dotcms_3.6.1_cfa5586.jar:?]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239) [catalina.jar:8.0.18]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) [catalina.jar:8.0.18]
    at com.aquent.filters.AquentLanguageFilter.doFilter(AquentLanguageFilter.java:55) [AquentLanguageFilter.class:?]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239) [catalina.jar:8.0.18]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) [catalina.jar:8.0.18]
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219) [catalina.jar:8.0.18]
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106) [catalina.jar:8.0.18]
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501) [catalina.jar:8.0.18]
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142) [catalina.jar:8.0.18]
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79) [catalina.jar:8.0.18]
    at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:610) [catalina.jar:8.0.18]
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88) [catalina.jar:8.0.18]
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:516) [catalina.jar:8.0.18]
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1086) [tomcat-coyote.jar:8.0.18]
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:659) [tomcat-coyote.jar:8.0.18]
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:147) [tomcat-coyote.jar:8.0.18]
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:279) [tomcat-coyote.jar:8.0.18]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [?:1.8.0_45]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [?:1.8.0_45]
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) [tomcat-util.jar:8.0.18]
    at java.lang.Thread.run(Thread.java:745) [?:1.8.0_45]

From the screenshot above, we can see that the formData info has valid values for requesting a License Request code. However, if we remote debug the application, the values are read as null objects.

A regular request proven as working on local demo site shows the following data on the browser's Network tab:

screen shot 2017-02-02 at 4 24 01 pm 2

The proposed fix on this ticket modifies the actual REST endpoint call:

  1. The LicenseResource class handles data as JSON instead of Text objects.
  2. JS code that calls the REST endpoint includes additional validations and logging messages according to the response generated from the server.
  3. Java code form the REST endpoint handles potential null values in a better way than the current implementation.
  4. Implementation was tested on two different clients running same version of dotCMS, with http and https enabled for backend access. Request code can be generated and License can be later requested.

Context:

Reported on the following Support tickets:

  • https://my.dotcms.com/tickets/detail.dot?id=f81f62c0-19ec-4e15-9d82-a68e513b4a60
  • https://my.dotcms.com/tickets/detail.dot?id=f44e19d6-443d-4cc0-92a4-12e7111e7901
  • https://my.dotcms.com/tickets/detail.dot?id=8bfd37b0-2b2e-4af6-953e-01587c62dff0

Your Environment

  • dotCMS 3.5.1, 3.6.1.
  • Firefox, Google Chrome, Safari Browsers.
  • Any OS.
  • Tomcat 8.0.18.
  • Java 8.
  • Postgres, MySQL, SQL Server.

joseorsini avatar Feb 03 '17 15:02 joseorsini

Test:

curl -u [email protected]:admin --data "licenseLevel=300&licenseType=dev" http://demo.dotcms.com/api/license/requestCode/ 

Returns a valid Code Request key.

curl -u [email protected]:admin --data-urlencode "licenseLevel=300&licenseType=dev" http://demo.dotcms.com/api/license/requestCode/

Returns error 500.

joseorsini avatar Feb 03 '17 19:02 joseorsini

After troubleshooting with @joseorsini, we noticed this is not reproducible neither on Local or Demo environments (even with the previous comment seems like it is). When using "curl" with "--data-urlencode" option, each name/value pair should be separated in a different "--data-urlencode" parameter. Thus, tests on previous comment may be read like this:

Test: curl -u [email protected]:admin --data "licenseLevel=300&licenseType=dev" http://demo.dotcms.com/api/license/requestCode/ Result: Returns a valid Code Request key

Test: curl -u [email protected]:admin --data-urlencode "licenseLevel=300" --data-urlencode "licenseType=dev" http://demo.dotcms.com/api/license/requestCode/ Result: Returns a valid Code Request key

This does not seem to be an issue with Dotcms code itself but it seems to be environment specific issue concerning the special network device configuration that the clients have. To offer a more detailed diagnostic, it is required either:

  1. To reproduce it in a Local development environment
  2. To have access to the server where Tomcat is running in order to sniff the traffic and then be able to inspect how the data in the HTTP request arrive to the server

agomez-dotcms avatar Feb 03 '17 22:02 agomez-dotcms

Hi @joseorsini,

After thinking more about it, I just realized and am wondering if we have access to install a patch over Client's server in order to test sending/receive the parameters over query string (instead of form data)? If that's the case, we could test something like this:

Test: curl -u [email protected]:admin -X POST "http://demo.dotcms.com/api/license/requestCode/?licenseType=dev&licenseLevel=300"

Patch: package com.dotcms.rest; ... import com.dotcms.repackage.javax.ws.rs.QueryParam; ... @Path("/license") public class LicenseResource { ... public Response requestLicense(... @QueryParam ("licenseLevel") String licenseLevel, @QueryParam ("licenseType") String licenseType ...){ ... } }

I think this is my quickest alternative/workaround to troubleshoot this issue (call it, quick and dirty), if taking into account the fact that server access is restricted. At this moment, I believe that would probably make the request work/succeed since the data travels over URL; which does not seem to be rewritten by any intermediate networking device. I will touch base with you on Monday!

Thanks, Anibal

agomez-dotcms avatar Feb 04 '17 06:02 agomez-dotcms

Note to QA: test clusterpack and reset ad request license again

dsilvam avatar Feb 07 '17 19:02 dsilvam

PR: https://github.com/dotCMS/core/pull/10657

agomez-dotcms avatar Feb 07 '17 21:02 agomez-dotcms

Hey @dsilvam,

I just submitted Pull Request to master-3.7 branch in order to replicate fix made by @joseorsini, which was tested on client's environment and done as part of https://github.com/dotCMS/core/pull/10631. Please notice:

  1. After the replication, I have done tests on my local environment and all of them were successful (ie. requested code, applied license, applied clusted pack, reset license, applied enterprise license, etc).
  2. Trial.jsp did not require any changes. I tested current version of trial.jsp after the changes and worked successfully.
  3. After PR be merged into master-3.7 branch, it is required to merge branch master-3.7 into release-3.7.1.

I am now moving ticket to In Review. Thanks, Anibal

agomez-dotcms avatar Feb 07 '17 21:02 agomez-dotcms

Passed QA. Tested locally successful application of clusterpack and through "Reset License Identity" button was able to reapply single enterprise license(trial.jsp), in both cases the License Information was updated. Cluster pack: image

Trial.jsp image

Verified with @joseorsini and confirmed that customers experiencing issue (HCA, Aquent) are not having this error after hotfix.

Tested on master-3.7 distribution / Ubuntu 14.04.1 / Postgres 9.3.5 / Chrome v54.0.2840.98 / Tomcat 8 / Java 8

shaydotcms avatar Feb 14 '17 13:02 shaydotcms