How to prevent Grails from rendering the default view

grails

I'm using Grails 1.2.1. I have this method in my controller …

class SocialMediaCacheProxyController {

    def index = {       
        def url = params.url
        if (params.dumpAll != null) {
            transportCacheService.processCacheDump(request.getRemoteAddr(), response)
        } else if (url != null) {
            doCacheTransport(request, response)
        }   // if
    }

Problem is, both execution paths write content to the response. However, I think Grails is trying to render a page at the end of the index method, because I repeatedly get the below error after invoking this method …

1339754 [http-8080-4] ERROR org.apache.catalina.core.ContainerBase.[Tomcat].[localhost].[/socialmediaproxy].[default]  - Servlet.service() for servlet default threw exception
java.lang.IllegalStateException: response.getWriter() called after response.getOutputStream()
    at org.codehaus.groovy.grails.web.sitemesh.GrailsPageResponseWrapper$GrailsBuffer.getWriter(GrailsPageResponseWrapper.java:284)
    at org.codehaus.groovy.grails.web.sitemesh.GrailsPageResponseWrapper$3.activateDestination(GrailsPageResponseWrapper.java:125)

Any ideas how I can get Grails to stop rendering anything after my method is complete? Thanks, – Dave

Best Solution

If you don't tell Grails what to render, it will render based on convention. In your case, it is looking for an index.gsp. Controllers must return something. That's the whole point. So you can either use the convention and create an index.gsp that gets returned, or you can manually implement the render() method.

http://grails.org/doc/latest/ref/Controllers/render.html

Related Question