Issue with enableing Spring Controller.

417 views
Skip to first unread message

Saurabh Tripathi

unread,
Oct 26, 2017, 3:02:16 AM10/26/17
to dot...@googlegroups.com
Dear All,

I am using dotCMS 4.1.1. I want to enable spring rest controller in dotCMS
for saving form data using REST API in the backend. For the trial purpose,
I have done following:
1. Downloaded com.dotcms.spring example from
https://github.com/dotCMS/plugin-seeds/tree/release-4.1.1
2. Run gradlew clean command.
3. Run gradlew build command to build the jar of the example.
4. Uploaded jar file to plugins using dotCMS UI.

But it shows following error:
*org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find
clas
s [com.dotmarketing.osgi.spring.ExampleController] for bean with name
'exampleCo
ntroller' defined in ServletContext resource [/spring/example-servlet.xml];
nest
ed exception is java.lang.ClassNotFoundException:
com.dotmarketing.osgi.spring.E
xampleController*

Please help me in finding what I am doing wrong.

Thanks.



--
Sent from: http://forumarchive.dotcms.com/

Chris Schmitt

unread,
Oct 26, 2017, 8:36:19 AM10/26/17
to dot...@googlegroups.com
Looking at that repo, it looks like there's a pull request that fixes/updates that plugin to work with 4.1.1, it just hasn't been merged yet.

You could make all the changes Will did in his commits, but that would be kinda painful. There's ways in git to make patches out of commits, but I'm not familiar enough with git to know how to do that with pull request commits. Thankfully, there's Google: https://www.google.com/search?q=git+create+patch+from+pull+request
--
http://dotcms.com - Open Source Java Content Management
---
You received this message because you are subscribed to the Google Groups "dotCMS User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dotcms+un...@googlegroups.com.
To post to this group, send email to dot...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/dotcms/1509001333391-0.post%40n5.nabble.com.
For more options, visit https://groups.google.com/d/optout.

Jonathan Gamba

unread,
Oct 26, 2017, 10:32:01 AM10/26/17
to dotCMS User Group
Good morning, we recently released the 4.2 version of dotCMS, in that release we addressed multiple issues with OSGI, you could try to use the 4.2 version of the Spring OSGI plugin https://github.com/dotCMS/plugin-seeds/tree/release-4.2/OSGi/com.dotcms.spring
You will find multiple small but important changes on that plugin so my recommendation is that even if you are using dotCMS 4.1.1 (also if possible, probably not, but moving completely to 4.2 will be a good choice) try to use the 4.2 version of the plugin.
Please start from there and I will follow this thread in order to help in case you find more problems with the plugin.

--
Jonathan Gamba 

Saurabh Tripathi

unread,
Oct 27, 2017, 1:58:44 AM10/27/17
to dot...@googlegroups.com
Thanks, Jonathan.

As suggested by you, I tried to test plugin for 4.2.0 release with dotCMS 4.1.1 and then for dotCMS 4.2.0 as well. In both the cases, I got the success log. Log for 4.2.0 release is:

[INFO] Initializing Spring FrameworkServlet 'class org.springframework.web.servlet.DispatcherServlet_1'
DEBUG: DYNAMIC WIRE: [com.dotcms.spring [11](R 11.0)] osgi.wiring.package; (osgi.wiring.package=*) -> [org.apache.felix.framework [0](R 0)]
DEBUG: DYNAMIC WIRE: [com.dotcms.spring [11](R 11.0)] osgi.wiring.package; (osgi.wiring.package=*) -> [org.apache.felix.framework [0](R 0)]
Started bundle: file:/E:/Dotcms/dotcms_4.2.0/dotserver/tomcat-8.0.18/webapps/ROOT/WEB-INF/felix/load/com.dotcms.spring-0.1.jar
But when I tried to access the HelloWorld page on the browser with http://localhost:8080/app/spring/examplecontroller, I got 404 page.

One more question how and where I can get the controller calling log to debug?

Thanks.

Sent from the dotCMS Users Group mailing list archive at Nabble.com.

Jason Tesser

unread,
Oct 27, 2017, 7:18:41 AM10/27/17
to dot...@googlegroups.com

--
http://dotcms.com - Open Source Java Content Management
---
You received this message because you are subscribed to the Google Groups "dotCMS User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dotcms+un...@googlegroups.com.
To post to this group, send email to dot...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.
--



3059 Grand Avenue
Suite 410-B
Miami FL 33133
Main: 
305-900-2001 | Direct: 978.294.9429

Nathan Keiter

unread,
Oct 27, 2017, 9:34:18 AM10/27/17
to dot...@googlegroups.com

Also, if you just want to create a simple RESTful endpoint, the dotCMS plugin framework actually makes this very easy now. You don’t need the complexity of Spring anymore.

 

You can make a simply annotated class and then in the activator use RestServiceutil.addResource( MyRestService.class );

 

com.dotcms.rest.config.RestServiceUtil is the import.

 

com.dotcms.rest.WebResource is also helpful.

 

Nathan I. Keiter | Lead Network Applications Programmer | Benefits Advisory Council Member | I.D.E.A Council Member
Gettysburg College | Information Technology | DataSystems
Campus Box 2453 | 300 North Washington Street | Gettysburg, PA 17325
Phone: 717.337.6993

https://www.gettysburg.edu

Saurabh Tripathi

unread,
Oct 30, 2017, 1:45:34 AM10/30/17
to dot...@googlegroups.com

Thanks, Nathan,

As suggested by you, I have tried to add a simple RESTful-endpoint in dotCMS plugin framework, but I got the following WARNING messages:

30-Oct-2017 10:58:48.690 WARNING [fileinstall-E:\dotcms_4.1.1\dotserver\tomcat-8.0.18\webapps\ROOT\WEB-INF\felix\load] com.dotcms.repackage.org.glassfish.jersey.internal.inject.Providers.checkProviderRuntime A provider com.dotmarketing.osgi.spring.FormDataController registered in SERVER runtime does not implement any provider interfaces applicable in the SERVER runtime. Due to constraint configuration problems the provider com.dotmarketing.osgi.spring.FormDataController will be ignored.
DEBUG: Bundle com.dotcms.spring [11] jersey-multipart-config.properties not found by com.dotcms.spring [11]
30-Oct-2017 10:58:49.336 WARNING [fileinstall-E:\dotcms_4.1.1\dotserver\tomcat-8.0.18\webapps\ROOT\WEB-INF\felix\load] com.dotcms.repackage.org.glassfish.jersey.internal.Errors.logErrors The following warnings have been detected: WARNING: A HTTP GET method, public com.dotcms.repackage.javax.ws.rs.core.Response com.dotcms.rest.elasticsearch.ESContentResourcePortlet.search(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse,java.lang.String) throws com.dotmarketing.exception.DotDataException,com.dotmarketing.exception.DotSecurityException, should not consume any entity.
example-Servlet.xml read succefully.
Started bundle: jardir:E:\dotcms_4.1.1\dotserver\tomcat-8.0.18\webapps\ROOT\WEB-
INF\felix\load\com.dotcms.spring-0.1

Please find the files in the attachment.

Also, it will be helpful if you can provide some relevant code for a POST request with JSON response in the context with dotCMS.

Looking forward to your support.

Thanks.

build.gradle
Activator.java
ExampleController.java
FormDataController.java
example-servlet.xml

Jason Tesser

unread,
Oct 30, 2017, 10:16:36 AM10/30/17
to dot...@googlegroups.com
So a couple of things. 

1. On your original issue did you try what I mentioned about the URL?  Cause it would return 404 without the trailing slash. 
2. I do NOT think you should do the class loader hack you added to your activator. We have ways of handling this as does OSGi.  
For example see here https://dotcms.com/docs/latest/override-a-dotcms-class-plugin  notice the Override-Classes

This being said as a best practice I would recommend having your OSGi plugins as isolated as possible.  By this I mean have the plugin provide all the libs it needs. https://github.com/dotCMS/plugin-seeds/tree/master/OSGi/com.dotcms.custom.spring



--
http://dotcms.com - Open Source Java Content Management
---
You received this message because you are subscribed to the Google Groups "dotCMS User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dotcms+un...@googlegroups.com.
To post to this group, send email to dot...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Nathan Keiter

unread,
Oct 31, 2017, 10:04:34 AM10/31/17
to dot...@googlegroups.com

There is a great example of how to use REST in OSGI here: https://github.com/wezell/com.dotcms.rest.page/blob/master/src/main/java/com/dotcms/plugin/rest/page/ContentWithRelationsResource.java Everything I’ve done with REST is based on Will’s plugin example.

 

Also, the source code of the built-in REST services gives good hints on how to use it.  You can see examples of POST, PUT, and GET here: https://github.com/dotCMS/core/blob/master/dotCMS/src/main/java/com/dotcms/rest/ContentResource.java#L648

 

Finally, you could look at one of my example REST OSTI plugins: https://github.com/nkeiter/generic-dotCMS-plugin-code-examples/blob/master/dotcms4.1.1/osgi/org.example.nkeiter.contentlet.rest.light/src/main/java/org/example/nkeiter/contentlet/rest/light/service/ContentletRestServiceLight.java

 

Hope that helps.

 

Nathan I. Keiter | Lead Network Applications Programmer | Benefits Advisory Council Member | I.D.E.A Council Member
Gettysburg College | Information Technology | DataSystems
Campus Box 2453 | 300 North Washington Street | Gettysburg, PA 17325
Phone: 717.337.6993

https://www.gettysburg.edu

 

--

http://dotcms.com - Open Source Java Content Management
---
You received this message because you are subscribed to the Google Groups "dotCMS User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dotcms+un...@googlegroups.com.
To post to this group, send email to dot...@googlegroups.com.

Jason Tesser

unread,
Nov 1, 2017, 6:46:49 AM11/1/17
to saurabh...@singsys.com, dot...@googlegroups.com
I can help with that. Please do not email me directly but email the goggle group. 



On Wed, Nov 1, 2017 at 12:36 AM <saurabh...@singsys.com> wrote:
Thanks Jason for your support.

Basically, I wish to save a content from front-end using dotCMS REST endpoint but it requires the user to be authenticated to have permission to save data.
That's the pain point for me as I don't want to use user credentials on the front-end ajax call.

For the above-stated purpose, I want to enable a REST API endpoint for me where I just have to pass the content data with content type id and in the backend, it adds authentication credentials and hits the dotCMS REST endpoint for saving data from.

Is there any way to do so.

Currently, I have succeeded in enabling rest call as the following example illustrates:
https://github.com/dotCMS/plugin-seeds/tree/master/OSGi/com.dotcms.spring
https://github.com/dotCMS/plugin-seeds/tree/master/OSGi/com.dotcms.rest

_____________________________________
Sent from http://forumarchive.dotcms.com

Nathan Keiter

unread,
Nov 1, 2017, 9:22:28 AM11/1/17
to dot...@googlegroups.com
It's best to reply in the Google group.

Why not just create a save endpoint that doesn't require a log in? You don't need to do this in multiple steps.

In fact, you could just set up permissions to allow the anonymous user to edit the contentlets and avoid a plugin altogether.

Nathan I. Keiter | Lead Network Applications Programmer | Benefits Advisory Council Member | I.D.E.A Council Member
Gettysburg College | Information Technology | DataSystems
Campus Box 2453 | 300 North Washington Street | Gettysburg, PA 17325
Phone: 717.337.6993
https://www.gettysburg.edu

-----Original Message-----
From: saurabh...@singsys.com [mailto:saurabh...@singsys.com]
Sent: Wednesday, November 01, 2017 12:33 AM
To: Nathan Keiter
Subject: Re: Issue with enabling Spring Controller.

Thanks Nathan for your support.

Basically, I wish to save a content from front-end using dotCMS REST endpoint but it requires the user to be authenticated to have permission to save data.
That's the pain point for me as I don't want to use user credentials on the front-end ajax call.

For the above-stated purpose, I want to enable a REST API endpoint for me where I just have to pass the content data with content type id and in the backend, it adds authentication credentials and hits the dotCMS REST endpoint or the method associated with it for saving content data.
Reply all
Reply to author
Forward
0 new messages