generator-jhipster: Code generation error with Reactive, JWT & Websockets selected

Overview of the issue

When you select reactive, websockets and JWT the code generated won’t compile.In JWTFilter::resolveToken, the new reactive type for ServerHttpRequest does not have a getParameter method. This code does not exist if you don’t select websockets.

JWTFilter.java:43: error: cannot find symbol String jwt = request.getParameter(AUTHORIZATION_TOKEN); ^ symbol: method getParameter(String) location: variable request of type ServerHttpRequest

Additionally, there are some warnings related to JWT generated code (not a direct issue with this bug but just FYI):

In JWTFilter, Mono::subscriberContext is deprecated

return chain.filter(exchange).subscriberContext(ReactiveSecurityContextHolder.withAuthentication(authentication));

And in TokenProvider, there is a n unchecked warning for the JacksonSerializer is not parameterized

return Jwts .builder() .... .serializeToJsonWith(new JacksonSerializer()) ....

Motivation for or Use Case

Code won’t build once generated

Reproduce the error

Should be reproducible doing a monolith (but should also affect microservices) with reactive to true and security set to JWT

Related issues

None found

Suggest a Fix

In JWTFilter replace

String jwt = request.getParameter(AUTHORIZATION_TOKEN);

with

String jwt = request.getQueryParams().getFirst(AUTHORIZATION_TOKEN);

JHipster Version(s)

7.0.1

JHipster configuration

This JDL will reproduce

JDL definitions
application {
  config {
    applicationType monolith
    authenticationType jwt
    baseName reactivejwtbug
    buildTool gradle
    packageName com.foo.bar
    reactive true
    websocket spring-websocket
  }

entities * }

entity A { a Boolean required }

Browsers and Operating System

Fedora 33 Not browser related

  • Checking this box is mandatory (this is just to show you read everything)

About this issue

  • Original URL
  • State: open
  • Created 3 years ago
  • Comments: 15 (13 by maintainers)

Commits related to this issue

Most upvoted comments

Additionally I have found, once you make that fix so it compiles and start it via boot run, seems there is another misconfiguration for websockets with this exception:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'stompWebSocketHandlerMapping' defined in class path resource [org/springframework/web/socket/config/annotation/DelegatingWebSocketMessageBrokerConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.web.servlet.HandlerMapping]: Factory method 'stompWebSocketHandlerMapping' threw exception; nested exception is java.lang.IllegalStateException: No suitable default RequestUpgradeStrategy found at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:658) at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:638) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1334) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1177) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:564) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:524) at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208) at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:944) at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:918) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:583) at org.springframework.boot.web.reactive.context.ReactiveWebServerApplicationContext.refresh(ReactiveWebServerApplicationContext.java:63) at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:769) at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:761) at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:426) at org.springframework.boot.SpringApplication.run(SpringApplication.java:326) at com.foo.bar.ReactivejwtbugApp.main(ReactivejwtbugApp.java:69) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:566) at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49) Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.web.servlet.HandlerMapping]: Factory method 'stompWebSocketHandlerMapping' threw exception; nested exception is java.lang.IllegalStateException: No suitable default RequestUpgradeStrategy found at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185) at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:653) ... 23 common frames omitted Caused by: java.lang.IllegalStateException: No suitable default RequestUpgradeStrategy found at org.springframework.web.socket.server.support.AbstractHandshakeHandler.initRequestUpgradeStrategy(AbstractHandshakeHandler.java:159) at org.springframework.web.socket.server.support.AbstractHandshakeHandler.<init>(AbstractHandshakeHandler.java:122) at org.springframework.web.socket.server.support.DefaultHandshakeHandler.<init>(DefaultHandshakeHandler.java:35) at com.foo.bar.config.WebsocketConfiguration$2.<init>(WebsocketConfiguration.java:77) at com.foo.bar.config.WebsocketConfiguration.defaultHandshakeHandler(WebsocketConfiguration.java:77) at com.foo.bar.config.WebsocketConfiguration.registerStompEndpoints(WebsocketConfiguration.java:43) at org.springframework.web.socket.config.annotation.DelegatingWebSocketMessageBrokerConfiguration.registerStompEndpoints(DelegatingWebSocketMessageBrokerConfiguration.java:60) at org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurationSupport.stompWebSocketHandlerMapping(WebSocketMessageBrokerConfigurationSupport.java:91) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:566) at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154) ... 24 common frames omitted

In the past websocket was implemented only for non-reactive gateways, but since it was mandatory to switch gateways to reactive now it is missing this functionality. So, yes I agree this needs new development.

i tried to disable reactive in my JDL but it always turn to be true in my yo-rc file

If you’re creating a gateway, reactive is forced. This is because Spring Cloud no longer supports a non-reactive gateway with Zuul in its latest version.