Announcement Announcement Module
Collapse
No announcement yet.
Grails filter and custom taglib not working when deployed Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Grails filter and custom taglib not working when deployed

    we are progressing on a Grails project. Grails version we are using is 1.3.7 and tomcat 7.0.14 is used for deployment. We are using a filter class to manage our logins and other access restrictions and also using a taglib to show the success and error messages from request or params generically

    The problem is everything works charm on local system when ran with (grails run-app) but when created the war and deployed on tomcat the filters and taglibs are not working even the flow doesn't seem hitting both

    My code for filter is as below. Any comments on this will be greatly helpful as we are stuck with this

    Code:
    class MyFilters {
    def userService
    
        def filters = {
            all(controller:'*', action:'*') {
                before = {
                        request.serverUrl = "http://${request?.getServerName()}"
                        if(request.getServerPort())
                            request.serverUrl = "http://${request.getServerName()}:${request.getServerPort()}"
                        if(request?.getCookie("ftCookie"))
                        request?.user = userService?.getUserCredentialFor(request?.getCookie("ftCookie"))
    
                        if(!request.getCookie("ftCookie") && ((!controllerName.equals('public')) && (!controllerName.equals('login') && actionName.equals('show')) && (!controllerName.equals('onBoarding'))))
                        {
                           //Login by giving username and password to login/show
                           redirect(controller:'public', action:'index')
                          //return false
                        }
                        if(request.getCookie("ftCookie") && ((controllerName.equals('login') && actionName.equals('show')) || (controllerName.equals('public')) || (controllerName.equals('onBoarding'))))
                        {
                            request.user = userService.getUserCredentialFor(request.getCookie("ftCookie"))
                            if(request.user instanceof UserDTO)
                            {
                                if(request?.user?.role  == 1)
                                {
                                    redirect(controller:'dashboard', action:'siteAdmin')
                                }
                                else if(request?.user?.role  == 2){
                                    redirect(controller:'organization', action:'site')
                                }
                                else
                                {
                                    response.deleteCookie("ftCookie")
                                    redirect(controller:'public', action:'index')
                                }
                            }
                            else
                            {
                                response.deleteCookie("ftCookie")
                                redirect(controller:'public', action:'index')
                            }
                       }
                }
                after = {
                    
                }
                afterView = {
                    
                }
            }
        }

  • #2
    Does it work with
    Code:
    grails run-war
    ? If not, unpack the WAR file and look for a 'grails.xml' file. What's in that?

    Comment


    • #3
      Hi Pledbrook, Thanks for your reply.. The problem was not with the grails filter, I am using cookies in my site, it was one logical error from my part. But the custom taglib is not working i went through a couple of forums but was not able to find a solution. we create war with command grails test-war. The grails.xml is fine but it doesnt have that custom taglib <resource> entry. I thought that will be auto injected by grails. Will adding the custom taglib to the grails.xml fix the issue ? I will try that part. Once again thanking for your time and effort. Anyway i am quoting the grails.xml file

      Code:
      - <grails>
      - <resources>
        <resource>DefaultAuthorizeNetConfig</resource> 
        <resource>com.vinomis.authnet.AuthorizeNet</resource> 
        <resource>com.vinomis.authnet.AuthorizeNetResponse</resource> 
        <resource>net.zorched.constraints.ComparisonConstraint</resource> 
        <resource>net.zorched.constraints.SsnConstraint</resource> 
        <resource>net.zorched.constraints.UsPhoneConstraint</resource> 
        <resource>net.zorched.constraints.UsZipConstraint</resource> 
        <resource>com.studentuniverse.grails.plugins.cookie.services.CookieService</resource> 
        <resource>com.studentuniverse.grails.plugins.cookie.taglib.CookieTagLib</resource> 
        <resource>JQueryConfig</resource> 
        <resource>JQueryPluginResources</resource> 
        <resource>JQueryService</resource> 
        <resource>JQueryResourceTagLib</resource> 
        <resource>JQueryTagLib</resource> 
        <resource>JqueryValidationResources</resource> 
        <resource>org.grails.jquery.validation.JqueryValidationTagLib</resource> 
        <resource>org.grails.jquery.validation.ui.JQueryRemoteValidatorController</resource> 
        <resource>org.grails.jquery.validation.ui.JqueryValidationService</resource> 
        <resource>org.grails.jquery.validation.ui.JQueryValidationUiTagLib</resource> 
        <resource>org.grails.jquery.validation.ui.AlphanumericConstraint</resource> 
        <resource>org.grails.jquery.validation.ui.LettersonlyConstraint</resource> 
        <resource>org.grails.jquery.validation.ui.LetterswithbasicpuncConstraint</resource> 
        <resource>org.grails.jquery.validation.ui.PhoneConstraint</resource> 
        <resource>org.grails.jquery.validation.ui.PhoneUSConstraint</resource> 
        <resource>grails.plugin.mail.MailService</resource> 
        <resource>grails.plugin.mail.PlainTextMailTagLib</resource> 
        <resource>AuthorizeNetConfig</resource> 
        <resource>BootStrap</resource> 
        <resource>BuildConfig</resource> 
        <resource>Config</resource> 
        <resource>DataSource</resource> 
        <resource>force.SecurityFilters</resource> 
        <resource>resources</resource> 
        <resource>UrlMappings</resource> 
        <resource>AuthController</resource> 
        <resource>DashboardController</resource> 
        <resource>LoginController</resource> 
        <resource>OnBoardingController</resource> 
        <resource>OrganizationController</resource> 
        <resource>PatientController</resource> 
        <resource>PaymentController</resource> 
        <resource>ProfileController</resource> 
        <resource>PublicController</resource> 
        <resource>TherapistController</resource> 
        <resource>UserController</resource> 
        <resource>branchV2.Account</resource> 
        <resource>branchV2.Address</resource> 
        <resource>branchV2.Appointment</resource> 
        <resource>branchV2.Clinic</resource> 
        <resource>branchV2.ClinicAdmin</resource> 
        <resource>branchV2.DiagnosticCode</resource> 
        <resource>branchV2.Done</resource> 
        <resource>branchV2.Equipment</resource> 
        <resource>branchV2.Evaluation</resource> 
        <resource>branchV2.Exercise</resource> 
        <resource>branchV2.Gear</resource> 
        <resource>branchV2.InCase</resource> 
        <resource>branchV2.Intake</resource> 
        <resource>branchV2.MailSettings</resource> 
        <resource>branchV2.Message</resource> 
        <resource>branchV2.Organization</resource> 
        <resource>branchV2.OrganizationAdmin</resource> 
        <resource>branchV2.Patient</resource> 
        <resource>branchV2.Pnote</resource> 
        <resource>branchV2.Prescription</resource> 
        <resource>branchV2.State</resource> 
        <resource>branchV2.Therapist</resource> 
        <resource>branchV2.Treatment</resource> 
        <resource>branchV2.TreatmentCode</resource> 
        <resource>branchV2.User</resource> 
        <resource>ClinicService</resource> 
        <resource>CustomCookieService</resource> 
        <resource>EmailerService</resource> 
        <resource>OrganizationService</resource> 
        <resource>UserService</resource> 
        <resource>branchv2.UtilsTagLib</resource> 
        <resource>CustomEmailConstraint</resource> 
        <resource>SubDomainConstraint</resource> 
        <resource>UsPhoneConstraint</resource> 
        <resource>UsZipConstraint</resource> 
        </resources>
      - <plugins>
        <plugin>AuthorizeNetGrailsPlugin</plugin> 
        <plugin>ConstraintsGrailsPlugin</plugin> 
        <plugin>CookieGrailsPlugin</plugin> 
        <plugin>DtoGrailsPlugin</plugin> 
        <plugin>HibernateGrailsPlugin</plugin> 
        <plugin>JqueryGrailsPlugin</plugin> 
        <plugin>JqueryValidationGrailsPlugin</plugin> 
        <plugin>JqueryValidationUiGrailsPlugin</plugin> 
        <plugin>MailGrailsPlugin</plugin> 
        </plugins>
        </grails>

      Comment


      • #4
        The TagLib class should appear in grails.xml as a <resource> element. I notice that CookieTagLib is there, as is UtilsTagLib. So those tag libraries should be loaded fine in WAR mode.

        Comment

        Working...
        X