简体   繁体   English

我可以将 HandshakeInterceptor 与 graphql-spring-boot-starter 一起使用来获取 Cookies 吗?

[英]Can I use HandshakeInterceptor With graphql-spring-boot-starter To Get Cookies?

I have a Spring Boot java app which serves up GraphQL subscriptions via graphql-spring-boot-starter.我有一个 Spring 启动 java 应用程序,它通过 graphql-spring-boot-starter 提供 GraphQL 订阅。

I would like to access cookies in some fashion.我想以某种方式访问 cookies。

In other (not graphql) contexts, I've seen people use HandshakeInterceptor to get cookies before the websocket handshake.在其他(不是 graphql)上下文中,我看到人们在 websocket 握手之前使用 HandshakeInterceptor 来获取 cookies。

I don't manually set up the websocket code, it is autowired via graphql-spring-boot-starter.我没有手动设置 websocket 代码,它是通过 graphql-spring-boot-starter 自动装配的。 I see non-graphql examples of people overriding registerStompEndpoints on their websocket configuration, but in my case I don't have any explicit websocket configuration, it is auto created.我看到人们在他们的 websocket 配置上覆盖 registerStompEndpoints 的非 graphql 示例,但在我的情况下,我没有任何明确的 websocket 配置,它是自动创建的。

Is there a way I can wire a HandshakeInterceptor into graphql-spring-boot-starter's functionality?有没有办法可以将 HandshakeInterceptor 连接到 graphql-spring-boot-starter 的功能中? I already tried creating a HandshakeInterceptor bean, but that appears to do nothing.我已经尝试过创建一个 HandshakeInterceptor bean,但这似乎无济于事。

My setup was assuming some things about graphql-java that are no longer true.我的设置是假设有关 graphql-java 的一些事情不再正确。 And I was not familiar with the websocket context.而且我不熟悉 websocket 上下文。

The solution is to use GraphQLWebSocketContext, which provides HandshakeRequest, allows you to do:解决方案是使用 GraphQLWebSocketContext,它提供了 HandshakeRequest,可以让你做:

graphQLWebSocketContext.getHandshakeRequest().getHeaders().get( "cookie" )

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 graphql-spring-boot-starter 应用程序只有 websockets - graphql-spring-boot-starter Application with only websockets 使用 graphql-java-tools 和 graphql-spring-boot-starter 进行错误处理 - Error handling with graphql-java-tools and graphql-spring-boot-starter spring boot starter graphql无法正常工作 - spring boot starter graphql not working 我们如何从 GraphQL 的 RequestContextHolder 中获取 GraphQL 的 HttpServletRequest(DefaultGlobalContext)(使用 graphql-spqr-spring-boot-starter)? - How can we get HttpServletRequest(DefaultGlobalContext) for GraphQL from RequestContextHolder for GraphQL (using graphql-spqr-spring-boot-starter)? 我可以轻松地用spring-boot替换spring-boot-starter以避免使用spring-boot-starter-parent吗? - Can I easily replace spring-boot-starter by spring-boot to avoid use of spring-boot-starter-parent? 如何使用我自己的 parent.pom 而不是“spring-boot-starter-parent”? - How can I use my own parent.pom instead of the “spring-boot-starter-parent”? 如何使用 spqr-spring-boot-starter 在 graphql 中获取模式文件? - How to get a schema file in graphql using spqr-spring-boot-starter? 无法在自定义 spring 引导启动器中使用 WebSecurityConfigurerAdapter - Can't use WebSecurityConfigurerAdapter in a custom spring boot starter 无法使用来自 spring 启动程序的注释 - Can't use annotation from spring boot starter 为什么我会收到与使用 graphql-spqr-spring-boot-starter 的“类型名称冲突”相关的警告? - Why am I getting a warning related to 'type name collision' using graphql-spqr-spring-boot-starter?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM