Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

In spring MVC portlet, @resourceMapping doesn't work. [SPR-10791] #15417

Closed
spring-projects-issues opened this issue Jul 29, 2013 · 6 comments
Closed
Assignees
Labels
status: backported An issue that has been backported to maintenance branches type: bug A general bug
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Jul 29, 2013

Laurent CHARLOIS opened SPR-10791 and commented

Using a method like this :
@ResourceMapping(value = "homeTemplate")
public @ResponseBody
ModelAndView homeTemplate() {
return new ModelAndView("home");
}

Return a blank response.

In 3.1.2 it works fine.


Affects: 3.1.3, 3.1.4

Issue Links:

Backported to: 3.2.6

1 votes, 3 watchers

@spring-projects-issues
Copy link
Collaborator Author

spring-projects-issues commented Jul 31, 2013

Juergen Hoeller commented

Are you sure that this worked in 3.1.2 in the context of a Portlet controller? @ResponseBody support has only ever been implemented for Servlets... So I wonder why it could have worked for you before.

Juergen

@spring-projects-issues
Copy link
Collaborator Author

spring-projects-issues commented Jul 31, 2013

Laurent CHARLOIS commented

I think it works.

This is a code snippet that works in 3.1.2 and doesn't work in 3.1.3 & >.

@ResourceMapping(value = "resendInvitationEmail")
public @ResponseBody
ModelAndView resendInvitationEmail(@RequestParam("invitationToken") String invitationToken, ResourceRequest request, ResourceResponse response, String email) {

	ModelAndView view = new ModelAndView();
	view.setView("ajaxResult");

	try {
		SubscriptionPortletUtils.resendInvitationEmail(request, invitationToken);
		view.addObject("ajaxResult", true);
	} catch (Exception e) {
		LOG.error("error on resend invitation email", e);
		view.addObject("ajaxResult", false);
	}

	return view;

}

In 3.1.2 the response contains true or false in 3.1.3 the response is empty.

I use Liferay 6.1.1.

I see that DispatcherPortlet from spring framework has changed between 3.1.2 and 3.1.3.
This method has been added :
protected void doDispatch(PortletRequestDispatcher dispatcher, PortletRequest request, MimeResponse response)
throws Exception {
lines 1178 -> 1196.

Perhaps it's an issue with Liferay because in this method dispatcher is an instance of a Liferay object.

Hope it's helping you.

Laurent.

@spring-projects-issues
Copy link
Collaborator Author

spring-projects-issues commented Nov 8, 2013

Eric Borisow commented

I am also able to reproduce the same behavior in 3.1.4.

In my case, I am returning a ModelAndView object from the @ResourceMapping annotated method.

@ResourceMapping(value = "showPage")
public ModelAndView showPage(ResourceRequest request)
{
ModelAndView modelAndView = new ModelAndView();

modelAndView.setViewName("test");
return modelAndView;

}

In the calling page:

Test page

The test.jsp just has some test content.

And, the resolver is just similar to the standard:

<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass"
value="org.springframework.web.servlet.view.JstlView" />
<property name="prefix" value="/WEB-INF/jsp/" />
<property name="suffix" value=".jsp" />
</bean>

In 3.1.4, it appears that the resolver is obtained, but the page is empty. If I simply switch back to 3.1.2, it works fine.

2013-11-08 14:35:08,508 [http-bio-8080-exec-26] DEBUG org.springframework.web.bind.annotation.support.HandlerMethodInvoker(HandlerMethodInvoker.java:173) - Invoking request handler method: public java.lang.String com.ims.qms.incident.controllers.PortletReferencePortletController.showTest(javax.portlet.RenderResponse)
2013-11-08 14:35:08,509 [http-bio-8080-exec-26] DEBUG org.springframework.web.portlet.DispatcherPortlet(DispatcherPortlet.java:1124) - Setting portlet response content type to view-determined type [text/html;charset=ISO-8859-1]
2013-11-08 14:35:08,509 [http-bio-8080-exec-26] DEBUG org.springframework.web.servlet.view.JstlView(InternalResourceView.java:227) - Including resource [/WEB-INF/jsp/test.jsp] in InternalResourceView 'test'
2013-11-08 14:35:08,540 [http-bio-8080-exec-26] DEBUG org.springframework.web.portlet.DispatcherPortlet(FrameworkPortlet.java:562) - Successfully completed request

Thanks,
Eric

@spring-projects-issues
Copy link
Collaborator Author

spring-projects-issues commented Dec 10, 2013

Juergen Hoeller commented

This seems to be caused by #14509 where we switched from include to forward for resource requests, which apparently is the better choice in uPortal at least. So on Liferay, a forward for a resource request leads to an empty page? Is there any documentation on forward/include behavior in Liferay?

Juergen

@spring-projects-issues
Copy link
Collaborator Author

spring-projects-issues commented Dec 11, 2013

Juergen Hoeller commented

After some research on the web, it indeed seems to be Liferay at fault here: When using resource forwards, it always simply displays an empty page...

As a consequence, I'm adding a specific Liferay check to DispatcherPortlet's doDispatch implementation, never using a forward on Liferay.

Note that doDispatch is an existing protected method, so a custom subclass of DispatcherPortlet could easily override it to always use an include.

Juergen

@spring-projects-issues
Copy link
Collaborator Author

spring-projects-issues commented Dec 13, 2013

Laurent CHARLOIS commented

Thanks for this Juergen.

Laurent.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: backported An issue that has been backported to maintenance branches type: bug A general bug
Projects
None yet
Development

No branches or pull requests

2 participants