<commit_before>package org.codehaus.grails.struts.action

import org.springframework.web.struts.DelegatingActionProxy
import org.apache.struts.action.ActionMapping
import org.springframework.web.context.support.WebApplicationContextUtils
import org.codehaus.groovy.grails.commons.ApplicationHolder
import org.codehaus.groovy.grails.commons.ControllerArtefactHandler
import org.apache.struts.action.ActionForward
import org.apache.struts.action.ActionForm
import javax.servlet.http.HttpServletRequest
import javax.servlet.http.HttpServletResponse
import org.codehaus.groovy.grails.web.servlet.mvc.GrailsWebRequest
import org.springframework.web.context.request.RequestContextHolder
//import org.codehaus.groovy.grails.web.servlet.mvc.SimpleGrailsControllerHelper
import org.springframework.web.servlet.ModelAndView
import org.codehaus.groovy.grails.web.servlet.mvc.MethodGrailsControllerHelper

/**
 * A Proxy that can be configured in struts-config.xml that allows Grails controllers to act like Struts actions. 
 *
 * @author <NAME>
 * @since 1.0
 *
 * Created: Mar 3, 2008
*/
class ControllerActionProxy extends DelegatingActionProxy {

    public ActionForward execute(ActionMapping actionMapping, ActionForm actionForm, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) {
        def applicationContext = WebApplicationContextUtils.getRequiredWebApplicationContext(getServlet().getServletContext())
        def application = ApplicationHolder.getApplication()

        String path = actionMapping.getPath()
        def controllerClass = application.getArtefactForFeature(ControllerArtefactHandler.TYPE, path)

        if(controllerClass) {
            def controller = applicationContext.getBean(controllerClass.fullName)
            def webRequest = RequestContextHolder.currentRequestAttributes()

            def actionName = controllerClass.getClosurePropertyName(path)
            def viewName = controllerClass.getViewByURI(path)
            
            webRequest.actionName = actionName

            def request = webRequest.request

            request.setAttribute('org.codehaus.grails.struts.ACTION_MAPPING',actionMapping)
            request.setAttribute('org.codehaus.grails.struts.ACTION_FORM', actionForm)

            def result = controller[actionName].call()

            def helper = new MethodGrailsControllerHelper(application, applicationContext, getServlet().getServletContext())
            //helper.configureStateForWebRequest(webRequest, webRequest.getRequest())
            // helper.set
            helper.setApplicationContext()
            ModelAndView mv = helper.handleActionResponse(controller, result, actionName, viewName)
            if(mv) {
                mv.getModel()?.each { k, v ->
                    request.setAttribute(k,v)                    
                }
                if(mv.viewName)
                    return new ActionForward("${mv.viewName}.gsp")
            }
        }
        else {
            return super.execute(actionMapping, actionForm, httpServletRequest, httpServletResponse);
        }

    }
}<commit_msg>fixing controller proxy for Grails 2.x<commit_after>package org.codehaus.grails.struts.action

import org.springframework.web.struts.DelegatingActionProxy
import org.apache.struts.action.ActionMapping
import org.springframework.web.context.support.WebApplicationContextUtils
import org.codehaus.groovy.grails.commons.ApplicationHolder
import org.codehaus.groovy.grails.commons.ControllerArtefactHandler
import org.apache.struts.action.ActionForward
import org.apache.struts.action.ActionForm
import javax.servlet.http.HttpServletRequest
import javax.servlet.http.HttpServletResponse
import org.codehaus.groovy.grails.web.servlet.mvc.GrailsWebRequest
import org.springframework.web.context.request.RequestContextHolder
//import org.codehaus.groovy.grails.web.servlet.mvc.SimpleGrailsControllerHelper
import org.springframework.web.servlet.ModelAndView
import org.codehaus.groovy.grails.web.servlet.mvc.MethodGrailsControllerHelper

/**
 * A Proxy that can be configured in struts-config.xml that allows Grails controllers to act like Struts actions. 
 *
 * @author <NAME>
 * @since 1.0
 *
 * Created: Mar 3, 2008
*/
class ControllerActionProxy extends DelegatingActionProxy {

    public ActionForward execute(ActionMapping actionMapping, ActionForm actionForm, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) {
        def applicationContext = WebApplicationContextUtils.getRequiredWebApplicationContext(getServlet().getServletContext())
        def application = ApplicationHolder.getApplication()

        String path = actionMapping.getPath()
        def controllerClass = application.getArtefactForFeature(ControllerArtefactHandler.TYPE, path)

        if(controllerClass) {
            def controller = applicationContext.getBean(controllerClass.fullName)
            def webRequest = RequestContextHolder.currentRequestAttributes()

            def actionName = controllerClass.getMethodActionName(path)
            def viewName = controllerClass.getViewByURI(path)
            
            webRequest.actionName = actionName + "()"

            def request = webRequest.request

            request.setAttribute('org.codehaus.grails.struts.ACTION_MAPPING',actionMapping)
            request.setAttribute('org.codehaus.grails.struts.ACTION_FORM', actionForm)

            def result = controller.actionName+"()"


            def helper = new MethodGrailsControllerHelper()
            helper.setApplicationContext(applicationContext)
            helper.setServletContext(getServlet().getServletContext())
            helper.setGrailsApplication(application)
            GrailsWebRequest grailsWebRequest = new GrailsWebRequest(httpServletRequest,httpServletResponse,getServlet().getServletContext())

            ModelAndView mv = helper.handleActionResponse(controller, result, grailsWebRequest, new HashMap(),actionName, viewName)
            if(mv) {
                mv.getModel()?.each { k, v ->
                    request.setAttribute(k,v)                    
                }
                if(mv.viewName)
                    return new ActionForward("${mv.viewName}.gsp")
            }
        }
        else {
            return super.execute(actionMapping, actionForm, httpServletRequest, httpServletResponse);
        }

    }
}
{'fraction_non_alphanumeric': 0.08053166536356529, 'fraction_numerical': 0.0023455824863174357, 'mean_word_length': 3.4540389972144845, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4825782', 'n_tokens_mistral': 1641, 'n_tokens_neox': 1574, 'n_words': 282}