Announcement Announcement Module
Collapse
No announcement yet.
Change DispatcherServlet map not to be the root of the app in social samples Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Change DispatcherServlet map not to be the root of the app in social samples

    Hi,

    I made a change in quickstart social sample by changing the appServlet mapping url to be /social/ instead of / since I don't want it to be the root of my app.
    From that point the quickstart social sample could not find the /social/signin no matter the changes I made also to ProviderSignInController, HomeController, UserInterceptor, signin.jsp.

    Can anyone write the changes that I need to do in order to change the appServlet mapping url

    Thanks in advance

  • #2
    The "/" mapping has special meaning in the servlet spec (refer to section SRV.11.2 of the servlet 2.5 spec) and indicates the default servlet. As the default servlet, there are some special rules regarding what values will be given to the servlet path and path info. The quickstart app is written to take advantage of this. You can change the path, but you'll need to make some additional adjustments to account for the fact that the DispatcherServlet is no longer the default servlet. These changes include:

    - Change the servlet mapping to "/social/*". You'll need to have the star so that the servlet won't be mapped just to "/social/" and so that the path info will contain anything represented by the *.
    - Since you're using a non-default servlet mapping, you'll need to change UserInterceptor's handleSignOut() and requestForSignIn() methods to call getPathInfo() instead of getServletPath().
    - You'll also need to change UserInterceptor's requireSignIn() to create a redirect view with "/social/signin"
    - The form action in signin.jsp and the link to signout in home.jsp will need to be adjusted to include the new base path.
    - Finally, in SocialConfig.java, you'll need to set ProviderSignInController's signInUrl property to "/social/signin" and the postSignInUrl property to "/social/".

    Once you make these changes, it should work if you go to http://localhost:8080/spring-social-quickstart/social/. You may want to make additional tweaks (for example handling requests for http://localhost:8080/spring-social-quickstart to redirect to the /social/ path), but the changes above will make it work.

    Comment


    • #3
      I'm running into some issues myself with this, but in regard to the "connect" code that needs to be executed in the ConnectController. I have a mapping to my dispatch servlet as /social/* and the form to provide the facebook connect submits to /social/connect/facebook:

      Code:
      <form action="<c:url value="/social/connect/facebook" />" method="POST">
      However, once it submits it seems to bounce around a bit when it deals with the oauth stuff (I haven't diligently looked at all that is happening) and eventually a call is made back to the ConnectController as a get request to /connect/facebook which would normally then return your proper view (eg facebookConnnected.) The issue appears to be that when it tries to make this redirect back it's lopping off the /social/ part of the URL so that my dispatchServlet obviously can not map to the ConnectController.

      Would it help if possibly in the method that handles the form post if the RedirectView was created with contextAware = "true":

      Code:
      @RequestMapping(value="/{providerId}", method=RequestMethod.POST)
      	public RedirectView connect(@PathVariable String providerId, NativeWebRequest request) {
      		ConnectionFactory<?> connectionFactory = connectionFactoryLocator.getConnectionFactory(providerId);
      		preConnect(connectionFactory, request);
      		return new RedirectView(webSupport.buildOAuthUrl(connectionFactory, request), true);
      	}
      
      I don't think ConnectController is going to be that easy to subclass and overwrite so I figured I'd ask her for some other suggestions.

      Comment


      • #4
        I'm going to try setting "applicationUrl" to "http://localhost:8080/social" on ConnectController to see if that helps.

        (I'm only stating it before trying it, since our work code is on virtual machines and they're having some crazy VM issues today so I'm stuck unable to work on the VM

        Comment


        • #5
          As discussed in this other thread (http://forum.springsource.org/showth...-authorization), I'm going to look into correcting ConnectController's behavior to consider the servlet path when doing the redirect. That should make this all easier to do without subclassing ConnectController. Once I get the fix in, I'll let you know and you can try it out and let me know if it addresses your problem.

          Comment


          • #6
            Originally posted by habuma View Post
            As discussed in this other thread (http://forum.springsource.org/showth...-authorization), I'm going to look into correcting ConnectController's behavior to consider the servlet path when doing the redirect. That should make this all easier to do without subclassing ConnectController. Once I get the fix in, I'll let you know and you can try it out and let me know if it addresses your problem.
            Cool thanks! I just cloned the project myself and was going to work on it since I realized subclassing it would be difficult (due some private methods in ConnectController.)

            Yes please post on the forum when it's updated (I'lll probably work on it it some myself in the meantime as well.)

            Thanks for all your work on SpringSocial. It's awesome!

            Comment


            • #7
              Originally posted by rickcr View Post
              Cool thanks! I just cloned the project myself and was going to work on it since I realized subclassing it would be difficult (due some private methods in ConnectController.)

              Yes please post on the forum when it's updated (I'lll probably work on it it some myself in the meantime as well.)

              Thanks for all your work on SpringSocial. It's awesome!
              Oh I see, looking at that thread you posted... I only need to concern myself with connectionStatusRedirect(), which is easy enough to override in a subclass (I thought I was going to need to override a few different controller methods.) (I'll subclass until the fix is in.)

              Thanks again!

              Comment


              • #8
                Just to let everyone on this thread know: I've just pushed a new 1.0.1.BUILD-SNAPSHOT which has some changes to ConnectController to support DispatcherServlet mappings to "/", "/somepath/*", or "*.ext" (where "ext" is some extension). I've tested this on some variants of the showcase sample where DispatcherServlet is mapped to "/", "/social/*", and "*.do" and had no troubles.

                This change included a change to connectionStatusRedirect()'s signature, so if you're extending ConnectController and overriding that method, you'll need to act accordingly. In many cases, however, the reason you're probably overriding that method is as a workaround for the problem that this change fixes--so you may be able to simply go back to using the out-of-the-box ConnectController.

                Let me know if this works for you or if you run into any problems.

                Comment


                • #9
                  What's the easiest way to grab the 1.0.1 snapshot builds if not using maven to pull them in? In the current project I'm stuck not using maven and just need to manually add the jars. I usually just grab things I need from here http://mvnrepository.com/ but they don't have the snapshots.

                  (Thanks for making this fix, look forward to trying it out.)
                  Last edited by rickcr; Sep 28th, 2011, 01:25 PM.

                  Comment


                  • #10
                    You should be able to grab them from https://s3browse.springsource.com/br...mework/social/. Or you can pull the source from GitHub and build them.

                    Comment


                    • #11
                      Originally posted by habuma View Post
                      Let me know if this works for you or if you run into any problems.
                      Working great! Thanks.

                      ( off topic type of question, but I'm still newbish in git. I do have spring-social cloned from github but I don't see a 1.0.1 branch. How would I be sure I'm building 1.0.1 and not 1.1.0 which is the latest in Master? )

                      Comment

                      Working...
                      X