Spring social / connect return 404

I am trying to set up spring social inside my (maven) spring secure MVC (spring) application, but when I try to access /connect/

or /connect/providerid

, I always geterror 404

Here is my Glassfish log when I try to access:

Info:   Mapped "{[/connect/{providerId}],methods=[POST],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public org.springframework.web.servlet.view.RedirectView org.springframework.social.connect.web.ConnectController.connect(java.lang.String,org.springframework.web.context.request.NativeWebRequest)
Info:   Mapped "{[/connect/{providerId}],methods=[DELETE],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public org.springframework.web.servlet.view.RedirectView org.springframework.social.connect.web.ConnectController.removeConnections(java.lang.String,org.springframework.web.context.request.NativeWebRequest)
Info:   Mapped "{[/connect/{providerId}],methods=[GET],params=[error],headers=[],consumes=[],produces=[],custom=[]}" onto public org.springframework.web.servlet.view.RedirectView org.springframework.social.connect.web.ConnectController.oauth2ErrorCallback(java.lang.String,java.lang.String,java.lang.String,java.lang.String,org.springframework.web.context.request.NativeWebRequest)
Info:   Mapped "{[/connect/{providerId}/{providerUserId}],methods=[DELETE],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public org.springframework.web.servlet.view.RedirectView org.springframework.social.connect.web.ConnectController.removeConnection(java.lang.String,java.lang.String,org.springframework.web.context.request.NativeWebRequest)
Info:   Mapped "{[/connect],methods=[GET],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.String org.springframework.social.connect.web.ConnectController.connectionStatus(org.springframework.web.context.request.NativeWebRequest,org.springframework.ui.Model)
Info:   Mapped "{[/connect/{providerId}],methods=[GET],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.String org.springframework.social.connect.web.ConnectController.connectionStatus(java.lang.String,org.springframework.web.context.request.NativeWebRequest,org.springframework.ui.Model)
Info:   Mapped "{[/connect/{providerId}],methods=[GET],params=[oauth_token],headers=[],consumes=[],produces=[],custom=[]}" onto public org.springframework.web.servlet.view.RedirectView org.springframework.social.connect.web.ConnectController.oauth1Callback(java.lang.String,org.springframework.web.context.request.NativeWebRequest)
Info:   Mapped "{[/connect/{providerId}],methods=[GET],params=[code],headers=[],consumes=[],produces=[],custom=[]}" onto public org.springframework.web.servlet.view.RedirectView org.springframework.social.connect.web.ConnectController.oauth2Callback(java.lang.String,org.springframework.web.context.request.NativeWebRequest)
Info:   Mapped URL path [/resources/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
Info:   Looking for @ControllerAdvice: Root WebApplicationContext: startup date [Thu May 14 16:06:15 PDT 2015]; root of context hierarchy
Info:   Using DataSource [org.apache.commons.dbcp2.BasicDataSource@65a12534] of Hibernate SessionFactory for HibernateTransactionManager
Info:   Creating filter chain: org.springframework.security.web.util.matcher.AnyRequestMatcher@1, [org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter@5b252c00, org.springframework.security.web.context.SecurityContextPersistenceFilter@22de3dd7, org.springframework.security.web.header.HeaderWriterFilter@17b3d10, org.springframework.security.web.csrf.CsrfFilter@2bffe1ad, org.springframework.security.web.authentication.logout.LogoutFilter@68a35517, org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter@4d85d53d, org.springframework.security.web.savedrequest.RequestCacheAwareFilter@3d704ff, org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter@57243fe2, org.springframework.security.web.authentication.AnonymousAuthenticationFilter@53e99103, org.springframework.security.web.session.SessionManagementFilter@1917c313, org.springframework.security.web.access.ExceptionTranslationFilter@7977c9b0, org.springframework.security.web.access.intercept.FilterSecurityInterceptor@a742949]
Info:   Root WebApplicationContext: initialization completed in 3718 ms
Info:   WebModule[null] ServletContext.log():Initializing Spring FrameworkServlet 'DispatcherServlet'
Info:   FrameworkServlet 'DispatcherServlet': initialization started
Info:   FrameworkServlet 'DispatcherServlet': initialization completed in 37 ms
Info:   Loading application [social] at [/social]
Info:   social was successfully deployed in 6,291 milliseconds.
Severe:   PWC6117: File "null" not found

      

Here is my social config class:

@Configuration
@EnableSocial
public class SocialConfig implements SocialConfigurer {

    @Autowired
    DataSource dataSource;

    @Override
    public void addConnectionFactories(ConnectionFactoryConfigurer cfConfig, Environment env) {
        cfConfig.addConnectionFactory(new LinkedInConnectionFactory("consumerKey", "consumerSecret"));
    }

    @Override
    public UsersConnectionRepository getUsersConnectionRepository(ConnectionFactoryLocator connectionFactoryLocator) {
        return new JdbcUsersConnectionRepository(dataSource, connectionFactoryLocator, Encryptors.noOpText());
    }

    @Override
    public UserIdSource getUserIdSource() {
        return new AuthenticationNameUserIdSource();
    }

    @Bean
    public ConnectController connectController(ConnectionFactoryLocator connectionFactoryLocator, ConnectionRepository connectionRepository) {
        return new ConnectController(connectionFactoryLocator, connectionRepository);
    }
}

      

Here is my WebAppliactionInitializer class:

public class WebInitializer implements WebApplicationInitializer {

@Override
 public void onStartup(ServletContext servletContext) throws ServletException {
    WebApplicationContext context = getContext();
    servletContext.addListener(new ContextLoaderListener(context));
    ServletRegistration.Dynamic dispatcher = servletContext.addServlet("DispatcherServlet", new DispatcherServlet(context));
    dispatcher.setLoadOnStartup(1);
    dispatcher.addMapping("/");
}

 private AnnotationConfigWebApplicationContext getContext() {
    AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
    context.setConfigLocation("com.gfz.social.springmvc.config"); // java package with all configs
    return context;
}

      

}

I have already checked the pom.xml

<!-- Spring Social -->
<dependency>
    <groupId>org.springframework.social</groupId>
    <artifactId>spring-social-core</artifactId>
        <version>1.1.0.RELEASE</version>
    </dependency>

<dependency>
    <groupId>org.springframework.social</groupId>
    <artifactId>spring-social-web</artifactId>
    <version>1.1.0.RELEASE</version>
</dependency>

<dependency>
    <groupId>org.springframework.social</groupId>
    <artifactId>spring-social-security</artifactId>
    <version>1.1.0.RELEASE</version>
</dependency>

<dependency>
    <groupId>org.springframework.social</groupId>
    <artifactId>spring-social-config</artifactId>
    <version>1.1.0.RELEASE</version>
</dependency>

      

Can anyone help me? (I already tried to read the link code and showcase examples) Thanks

+3


source to share


2 answers


Just guess, but do you have any views (JSP, Thymeleaf or otherwise) on "connect / {providerId} Connect" or "connect / {providerId} Connected"? Do you have a view of "connect / status"? If not, then this opportunity is for 404s.

The controller method responding to the "/ connect" path collects the connection status information for all known providers in the application and then sends them to a view named "connect / status". For most projects (using JSPs) this means that you need a JSP file called "status.jsp" in a directory called "/ connect" (relative to where your views are saved).



For the provider you need 2 files for each provider. For example, if you are dealing with Facebook, you will request "/ connect / facebook" and the controller will collect connection information and send it to a view named "connect / facebookConnect" (if you have no connection) or "connect / facebookConnected "(if you have a connection). This means (in the case of JSPs) you need JSPs at "/connect/facebookConnect.jsp" and "/connect/facebookConnected.jsp".

Take a look at https://github.com/spring-projects/spring-social-samples/tree/master/spring-social-showcase . This example uses Thymeleaf instead of JSP, but it demonstrates the basic idea. You will find templates in src / main / resources / views / connect. If it was a JSP-viewed application, you will most likely put them in src / main / webapp or some directory under src / main / webapp.

+3


source


the error PWC6117: File "null" not found

occurs when spring cannot render model and views correctly.

In your controller class, you need to have some configuration like

return new ModelAndView("WEB_INF/whereverSpringCanFindYourJSP");



hope this helps!

Good luck!

0


source







All Articles