Announcement Announcement Module
Collapse
No announcement yet.
URL issue when using existing Spring MVC Controller with Grails Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • URL issue when using existing Spring MVC Controller with Grails

    Hi,

    In my Grails application, I added a dependency to "spring-social" project (not the grails plugin but the actual spring-social project developed in Spring MVC). Further, I configured the beans as described in the spring social documentation.

    I did NOT create Grails Controllers and instead I'm using the controllers declared in the spring-social project. However, I created GSP views so the controllers in the spring-social render those views.

    Here is a summary of what I have done:
    1) BuildConfig.groovy

    Code:
        dependencies {
            def springSocialVersion = "1.0.2.RELEASE"
            def springSocialFacebookVersion = "1.0.1.RELEASE"
            
            // specify dependencies here under either 'build', 'compile', 'runtime', 'test' or 'provided' scopes eg.
            compile "org.springframework.social:spring-social-core:${springSocialVersion}"
            compile "org.springframework.social:spring-social-web:${springSocialVersion}"
            compile "org.springframework.social:spring-social-facebook:${springSocialFacebookVersion}"
            
            compile "org.springframework.security:spring-security-crypto:3.1.0.RC3"
        }
    2) under src/java, created "com.splitpen.social.config.SocialConfig.java" that contains bean configurations as described in the spring social documentation and samples

    3) config.groovy, I pointed to the config package so Grails can scan the bean configuration
    Code:
    // packages to include in Spring bean scanning
    grails.spring.bean.packages = ["com.splitpen.social.config"]
    I omitted some customization I did such as user domain class and related DAOs, but long story short I got it working with a caveat.

    In the GSP file, I had to add ".dispatch" suffix to the post URL like this
    Code:
        <form name="fb_signin" id="fb_signin" action="signin/facebook.dispatch" method="POST">
            <input type="hidden" name="scope" value="email,publish_stream,user_photos,offline_access" />
            <button type="submit" class="connectButton">Facebook</button>
        </form>
    If I omit the ".dispatch" suffix, I get 404 error. I also found that if I omit the suffix in the view but add a URL mapping, it also works:
    Code:
    UrlMappings.groovy
        "/signin/facebook"(uri:"/signin/facebook.dispatch")
    I'm not happy with either workaround:
    1) I don't like adding the "dispatch" suffix in view because I don't have to do that when I use Grails Controller. So whoever implements the view now needs to know that the controller is either implemented in Grails or Spring MVC.
    2) I don't like adding the URL Mapping either because I couldn't figure out how to use wildcards so I wouldn't have to add a mapping for every URL combination. Specifically I tried to do something like this with no success
    Code:
         "signin/**.dispatch"(uri:"signin/**")
    Otherwise I have to add a mapping for every action that is handled by signin controller that is declared in Spring MVC.

    I'm looking for some guidance and suggestions on either how to better integrate existing Spring MVC controllers into Grails so that I don't have to use the suffix or a convenient way to the URL mapping as I described above.

    Thanks,
    Ali

  • #2
    Hi melicin,

    I appreciated your post, as it gave me a hint of integrating spring-social to grails. However, you wrote "However, I created GSP views so the controllers in the spring-social render those views."

    How did you do that? I was testing a lot of things and the spring social controllers always want to find a JSP, e.g. /WEB-INF/grails-app/viewsconnect/facebookConnect.jsp

    I might have found out, that this is a fallback behaviour, but where did you put your GSPs to get used.

    Sry for warming up that thread.

    Comment

    Working...
    X