I'm trying to build a portlet within a grails application, and I've created a simple controller extending AbstractController which returns
new ModelAndView('myportlet') from handleRequestInternal. I also have a standard Jstl view resolver setup for /WEB-INF/jsp but no matter what I try, when I try to view the portlet within liferay I get the following stacktrace:
13:19:39,723 ERROR [DispatcherPortlet:559] Could not complete request
java.lang.ClassCastException: org.springframework.web.portlet.context.PortletRequestAttributes cannot be cast to org.codehaus.groovy.grails.web.servlet.mvc.GrailsWebRequest
at org.codehaus.groovy.grails.web.util.WebUtils.retrieveGrailsWebRequest(WebUtils.java:497)
at org.codehaus.groovy.grails.web.servlet.view.GrailsViewResolver.loadView(GrailsViewResolver.java:87)
at org.codehaus.groovy.grails.scaffolding.view.ScaffoldingViewResolver.loadView(ScaffoldingViewResolver.java:61)
at org.springframework.web.servlet.view.AbstractCachingViewResolver.createView(AbstractCachingViewResolver.java:158)
at org.springframework.web.servlet.view.UrlBasedViewResolver.createView(UrlBasedViewResolver.java:384)
at org.springframework.web.servlet.view.AbstractCachingViewResolver.resolveViewName(AbstractCachingViewResolver.java:77)
at org.springframework.web.portlet.DispatcherPortlet.resolveViewName(DispatcherPortlet.java:1110)
It seems that if I could get around the GrailsViewResolver, I should be able to get my portlet up and running as I would in a normal spring application.
I'm using liferay 6, so the grails liferay plugin isn't an option. Is there anything I can do to make sure GrailsViewResolver doesn't try to resolve my view in /WEB-INF/jsp?
If you're using Grails, use it 100% and don't try to mix wildly different technologies. It'll save you pain in the long run.
Related
I have a pretty basic vaadin application running. The application is spring-boot backed and I defined some rest API.
I've added OpenAPI documentation using org.springdoc:springdoc-openapi-ui:1.4.4, which worked perfectly before adding vaadin.
After adding the vaadin dependencies as shown in the vaadin spring-boot tutorial, and creating a view (which works), the swagger UI is no longer reachable.
It seems to me that vaadin completely takes over all web requests. Digging deeper, I've found that vaadin registers a new servlet and catches all requests.
I don't find any docs on how to configure this -- I'd expect that one could configure vaadin such that it serves UI from a different path, say /ui or similar.
I've tried to set
vaadin:
url-mapping: "/ui/*"
in my application.yaml -- but this results in blank pages (no errors) for my vaadin views,
and the vaadin servlet does still take over /.
I use spring.boot 2.3.2.RELEASE, vaadin 14.3.1.
The value to override is (note the camelCase instead of the kebab-case):
vaadin:
urlMapping: /ui/*
Using the kebab-case did (does) not work. As expected, this is a bug. See https://github.com/vaadin/spring/issues/637
From the docs at the point of time:
You can set properties for Spring Boot in your application.properties file.
Example: Setting Spring URL mapping in application.properties.
vaadin.urlMapping=/my_mapping/*
By default, URL mapping is /*.
An additional servlet, such as /my_mapping/*, is required to handle the frontend resources for non-root servlets. The servlet can be defined in your application class. See this Application class for a example.
Source: https://vaadin.com/docs/v14/flow/spring/tutorial-spring-configuration.html#using-spring-boot-properties
I'm trying to create a portlet with liferay 6.2 and using spring. If I create a bean without using constructor-arg or factory-method then everything works fine. But if I use either of these then I get exceptions when the portlet is deployed.
an example:
the exception I'm getting is:
01:28:21,884 ERROR [ContextLoader:323] Context initialization failed
java.lang.IncompatibleClassChangeError: class org.springframework.core.LocalVariableTableParameterNameDiscoverer$ParameterNameDiscoveringVisitor has interface org.springframework.asm.ClassVisitor as super class
I realize that this can be caused by having 2 versions of ams, but im using the spring jars that come with liferay.
You give an option yourself - duplicate classes. But without knowing how you build and what you're doing, there's hardly anything to do apart from asking you to make extra extra extra sure that you don't have duplicate resources on the classpath:
Check your deployed web application (once it's deployed to your application server) and its WEB-INF/lib folder for such duplicates. They might come in only during the buildprocess, e.g. they might not be in your IDE's workspace. Or Liferay might inject them (due to declared dependencies) during deployment.
You'll have to figure out how (and in which phase) those resources get there, then eliminate that option (e.g. through proper maven scope, e.g. "provided")
I am trying exception handling in spring portlet based UI application,
I have used spring globalexception handling using #ControllerAdvice.
It works fine in servlet based application but its not working in portlet application.I have noticed that spring container has not processed #ControllerAdvice in portlet. I tried searching in internet on the same issue but no luck.
Is there any other way to handle exceptions in portlet applications?
Thanks in advance.
The Portlet support in Spring is rapidly declining, with very little code or documentation of such. You'll notice that the DispatcherPortlet auto-registers an instance of AnnotationMethodHandlerExceptionResolver, not the newer ExceptionHandlerExceptionResolver.
Even if you manually define an instance of the latter in your portlet.xml file, it won't get picked up by the DispatcherPortlet because it specifically looks for implementers of the org.springframework.web.portlet.HandlerExceptionResolver, which is a different hierarchy than the org.springframework.web.servlet.HandlerExceptionResolver (of which ExceptionHandlerExceptionResolver is a descendent).
I have embedded Jetty container inside my main server and I also use Jersey 2.5 for handling REST resources.
everything seems to work well and now I would like to pass my server's context class into each of my REST resources.
I'm having hard time understanding how to do that...
If someone can provide full code example - it could be awesome!
Many thanks
What exactly do you mean when you say you have a Jetty container inside your "main server"? Are you programmatically executing Jetty within the application? Also, when you say "context" are you referring to the ServletContext?
I am new to Spring portlet i am unable to run a sample spring portlet project.. I am trying to run the project from eclipse as run on server on jboss server. My questions are 1. How can we run a portlet project. Do i need some kind of portlet container(I have no idea of this container i just know few names like liferay etc)?? I cant find a full documented example any where.. In Spring mvc based on the request mapping i can call that purticular Controller class but in Spring mvc portlet how can we call this controllers( or Portlets). Is it possible to call a portlet directly by an url?? The sample project is deployed without any error but i cant find a way by which i can call or trigger a portlet. Any help would be much appriciated.
thx
nkovi
Yes, you will need to deploy to a portlet container like Liferay etc, or uPortal. Once you have the portlet container up and running, things should hopefully become more obvious.
Regarding your other questions, I strongly suggest you read some documentation - the Spring portlet docs are not too bad although they are a little behind on annotations.