我的 spring-social ConnectController 有什么问题? [英] What's wrong with my spring-social ConnectController?

查看:79
本文介绍了我的 spring-social ConnectController 有什么问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试制作一个 Spring Boot 应用程序,该应用程序将使用 spring-social 连接到 Fitbit 的 api.我已经(中途)实现了一个 ConnectionFactory 并且它是 Fitbit 的依赖项,我正在尝试从我的应用程序中使用它.其中一部分涉及启动一个 ConnectController 来处理 OAuth2舞蹈".

I'm trying to make a Spring Boot app that will connect to Fitbit's api using spring-social. I've (half-way) implemented a ConnectionFactory and it's dependencies for Fitbit, and am trying to consume it from my app. Part of this involves starting up a ConnectController to handle the OAuth2 "dance".

当我尝试通过我的浏览器在 http://localhost:8080/connecthttp://localhost:8080/connect 上点击 ConnectController/fitbit 我被重定向到带有以下消息的可白化错误页面:

When I try to hit the ConnectController through my browser at http://localhost:8080/connect or http://localhost:8080/connect/fitbit I get redirected to the whitelable error page with the message:

出现意外错误(type=Method Not Allowed,status=405).

There was an unexpected error (type=Method Not Allowed, status=405).

不支持请求方法GET"

Request method 'GET' not supported

我不太明白我看到了什么,但是当我设置 DEBUG 级别的日志记录并使用一些断点时,它看起来像是从浏览器结果中点击了 /connect在 Spring 中试图找到名为 connect/status 的东西并点击 /connect/fitbit 导致 spring 试图找到名为 /connect/fitbitConnect 的东西和然后尝试在内部向 /connect/connect/fitbitConnect 发出 GET 请求.

I don't really understand what I'm seeing, but when I set DEBUG level logging and use some breakpoints it looks like hitting /connect from the browser results in Spring trying to find something called connect/status and hitting /connect/fitbit result in spring trying to find something named /connect/fitbitConnect and then trying to internally make a GET request to /connect/connect/fitbitConnect.

在这两种情况下,与 /connect/connect/{providerId} 对应的 ConnectController 上的方法看起来都可以正常调用,并且然后当它去寻找所有其他东西时,Spring 会爆炸.

In both cases it looks like the methods on ConnectController corresponding to /connect and /connect/{providerId} get called fine, and then Spring bombs when it goes looking for all that other stuff.

这是我正在使用的 SocialConfigurer 实现,它创建了 ConnectController bean:

Here is the SocialConfigurer implementation I'm using which creates the ConnectController bean:

@Configuration
@EnableSocial
@PropertySource("${properties.path}/fitbot-service.properties")
public class SpringSocialConfig implements SocialConfigurer{
    @Override
    public void addConnectionFactories(ConnectionFactoryConfigurer connectionFactoryConfigurer, Environment environment) {
        connectionFactoryConfigurer.addConnectionFactory(new FitbitConnectionFactory(
                environment.getProperty("fitbit.clientId"),
                environment.getProperty("fitbit.clientSecret")
        ));
    }

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

    @Override
    public UsersConnectionRepository getUsersConnectionRepository(ConnectionFactoryLocator connectionFactoryLocator) {
        return new InMemoryUsersConnectionRepository(connectionFactoryLocator);
    }

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

}

这到底是怎么回事?我究竟做错了什么?

What on earth is going on here? What am I doing wrong?

推荐答案

我相信这与您关于 ConnectController 中 GET 与 POST 的问题有关,因此您可能已经为自己回答了这个问题.尽管如此,让我澄清一下它为什么要寻找 connect/status 和 connect/fitbitConnect.

I believe this to be related to your question regarding GET vs. POST in ConnectController, so you may have already answered this for yourself. Nonetheless, let me clarify why it's looking for connect/status and connect/fitbitConnect.

那些是视图名称.当您对/connect 执行 GET 时,您要求 ConnectController 获取所有提供者的连接状态并将其放置在模型中,之后它将将该模型转发到逻辑名称为connect/status"的视图.通常这是路径/connect/status.jsp"的 JSP 或者/connect/status.html"的 Thymeleaf 模板,但它可以是遵循任何 Spring MVC 视图解析器的规则的任何视图.

Those are view names. When you do a GET for /connect, you're asking ConnectController to fetch connection status for all providers and to place it in the model, after which it will forward that model to a view whose logical name is "connect/status". Usually this is a JSP at the path "/connect/status.jsp" or maybe a Thymeleaf template at "/connect/status.html", but it can be any view following the rules of whatever Spring MVC view resolvers are in play.

同样,/connect/fitbit 的 GET 请求要求 ConnectController 获取fitbit"提供程序的连接状态,并将该信息放入模型并将其转发到名称为/connect/fitbitConnect"的视图(如果没有连接)或/connect/fitbitConnected"(如果有连接).

Likewise, a GET request for /connect/fitbit is asking ConnectController to fetch connection status for the "fitbit" provider and to place that information in the model and forward it on to a view whose name is "/connect/fitbitConnect" (if there isn't a connection) or "/connect/fitbitConnected" (if there is a connection).

除了回答您的问题之外,我还可以要求您告诉我更多有关您的 FitBit Spring Social 提供商项目的信息吗?它是否以其他社区主导的 Spring Social 项目为蓝本?换句话说,它是其他人可能使用的 Spring Social 的独立扩展吗?如果是这样,请告诉我它在 GitHub 中的位置,我很乐意将其添加到 http://projects.spring.io/spring-social/.

Aside from answering your question, may I also request that you tell me more about your FitBit Spring Social provider project? Is it modeled after other community-led Spring Social projects? In other words, is it a standalone extension to Spring Social that others may use? If so, tell me where it is in GitHub and I'll be happy to add it to the "Community Projects" section at http://projects.spring.io/spring-social/.

这篇关于我的 spring-social ConnectController 有什么问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆