No suitable default RequestUpgradeStrategy found in a new generated jhipster application - spring

I'm working on Jhipster micro-services project, all works fine and good until i a
websocket spring-websocket
into the gateway application in my JDL file, now when I run the project I always get a failure
Failed to instantiate [org.springframework.web.servlet.HandlerMapping]: Factory method 'stompWebSocketHandlerMapping' threw exception; nested exception is java.lang.IllegalStateException: No suitable default RequestUpgradeStrategy found
the application I'am use is right of the box generated from jhipster generator 7.0.0
the JDL I use is :
application {
config {
baseName usergateway,
packageName fr.teamsyst.trade4talent.usergateway,
applicationType gateway,
authenticationType jwt,
databaseType mongodb,
devDatabaseType mongodb,
prodDatabaseType mongodb,
serviceDiscoveryType eureka,
testFrameworks [protractor],
nativeLanguage fr,
languages [fr, en],
jhiPrefix t4t,
websocket spring-websocket,
}
entities *
}

Add spring-boot-starter-tomcat dependency to pom.xml
Add spring.main.web-application-type: reactive to application.yml

Related

Springboot- oauth2 - websockets - Service Unavailable for async support

I have a springboot app , outh2 secure and now integrating websockets.
When I try connect , I get the error
Caused by:
org.springframework.web.socket.sockjs.SockJsTransportFailureException:
Failed to open session; nested exception is
java.lang.IllegalArgumentException: Async support must be enabled on a
servlet and for all filters involved in async request processing. This
is done in Java code using the Servlet API or by adding
"true" to servlet and filter
declarations in web.xml. Also you must use a Servlet 3.0+ container
As my app is springboot , and without web.xml. I added the below bean
#Bean
public ServletRegistrationBean dispatcherServlet() {
ServletRegistrationBean registration = new ServletRegistrationBean(new DispatcherServlet(), "/");
registration.setAsyncSupported(true);
return registration;
}
Now the new error is HTTP ERROR 503 Service Unavailable
The posts both didn't solve my problem
How to enable async support in a Springboot application packaged and deployed as WAR
Spring: Servlet 3.1 + SockJS = Async support must be enabled
How can I enable async and resolve my problem ?

Error setting custom trust store for Eureka Discovery client by overriding DiscoveryClient.DiscoveryClientOptionalArgs

I am upgrading a spring-boot project from an old version (2.2.9.RELEASE + Spring Cloud HOXTON.SR12) to v2.6.1 + Spring Cloud 2021.0.0
The issue I am currently hitting is with Trust Store enabled Eureka clients. In my old version, all eureka registering applications would use
import org.springframework.cloud.client.discovery.EnableDiscoveryClient; and be tagged with
#EnableDiscoveryClient
To use a custom trust store, I'd then include the following beans in a configuration class:
#Bean
public DiscoveryClient.DiscoveryClientOptionalArgs getTrustStoredEurekaClient(SSLContext sslContext) {
DiscoveryClient.DiscoveryClientOptionalArgs args = new DiscoveryClient.DiscoveryClientOptionalArgs();
args.setSSLContext(sslContext);
return args;
}
#Bean
public SSLContext sslContext() throws Exception {
return new SSLContextBuilder().loadTrustMaterial(new File(trustStore).toURI().toURL(), trustStorePassword.toCharArray()).build();
}
using import com.netflix.discovery.DiscoveryClient;
Following the upgrade, any microservice which attempts to use this custom truststore will not start, with the error thrown below:
*************************** APPLICATION FAILED TO START
Description:
Field optionalArgs in
org.springframework.cloud.netflix.eureka.EurekaClientAutoConfiguration$RefreshableEurekaClientConfiguration
required a bean of type
'com.netflix.discovery.AbstractDiscoveryClientOptionalArgs' that could
not be found.
The injection point has the following annotations:
#org.springframework.beans.factory.annotation.Autowired(required=true)
Action:
Consider defining a bean of type
'com.netflix.discovery.AbstractDiscoveryClientOptionalArgs' in your
configuration.
It doesn't seem to matter if I try to autowrire in a separate bean of type DiscoveryClientOptionalArgs and set the context to this, and I am currently unable to resolve this.
I could solve this by setting the following in the gateway's application.properties:
eureka.client.tls.enabled=true
eureka.client.tls.key-store=file:<path-to-key-store>
eureka.client.tls.key-store-password=<password>
eureka.client.tls.keyStoreType=PKCS12
eureka.client.tls.keyPassword=<password>
eureka.client.tls.trust-store=file:<path-to-trust-store>
eureka.client.tls.trust-store-password=<password>
What's not clear to me is why a keystore in addition to the truststore needs to be set (as above, it was only necessary to configure a trust store for the SSL context of the DiscoveryClient override for the previous versions using Zuul), which suggests I haven't fully understood what's actually happening here.

How to access keycloak with the admin-client?

I'm trying to change roles of a user in keycloak with the keycloak-admin-client in a spring boot application, but I can't even instanciate keycloak.
I'm trying to get the keycloak server here, but Im getting a InstantiationError
String serverUrl = "http://localhost:8080/auth";
String realm = "User-Service-Realm";
String clientId = "admin-cli";
Keycloak keycloak = Keycloak.getInstance(
serverUrl,
realm,
"admin",
"admin",
clientId);
Exception in thread "main" java.lang.InstantiationError: org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder
at org.keycloak.admin.client.Keycloak.<init>(Keycloak.java:58)
at org.keycloak.admin.client.Keycloak.getInstance(Keycloak.java:106)
at de.uni.stuttgart.isw.ccm.userservice.api.KeycloakAdminClientExample.main(KeycloakAdminClientExample.java:31)
Apparently its a problem with the admin-client itself, since the keycloak builder is based on the resteasyclientbuilder.
You seem to have incompatible libraries or library versions. The error message complains that ResteasyClientBuilder is abstract. That not the case in our working project.
So as a reference, here is an extract from our gradle file so you can see a working combination of library versions:
implementation 'org.keycloak:keycloak-admin-client:6.0.1'
implementation 'javax.ws.rs:javax.ws.rs-api:2.0'
implementation 'org.jboss.resteasy:resteasy-jaxrs:3.6.3.Final'
implementation 'org.jboss.resteasy:resteasy-client:3.6.3.Final'
implementation 'org.jboss.resteasy:resteasy-jackson2-provider:3.6.3.Final'
Update:
ResteasyClientBuilder has become an abstract class with version 4.0 of RESTEasy. So it looks as if you are using version 4.x, while Keycloak expects 3.x.

Spring cloud sleuth dependencies throwing RibbonLoadBalancerClientException in Spring boot stack application

We are planning to integrate spring sleuth in our Spring cloud microservices application. However when a Service A makes a call to Service B using RestTemplate we are getting RibbonLoadBalancerClient exception. Please find the stack trace below.
ResponseObject genericResponse = restTemplate.exchange(expandedUrl, HttpMethod.GET, new HttpEntity<>(null), ResponseObject.class).getBody();
Logger.log(DEBUG, "getDetails returned {} ", response);
return genericResponse.getData().getInformation();
The version are are using is as below
Spring Boot : springBootVersion = '1.5.3.RELEASE'
Spring Sleuth : spring-cloud-starter-sleuth:1.2.4.RELEASE
Spring cloud dependencies : spring-cloud-services dependencies:1.2.0.RELEASE,
spring-cloud-dependencies:Brixton.RELEASE
Exception - stacktrace :
org.springframework.web.util.NestedServletException: Handler dispatch failed; nested exception is java.lang.AbstractMethodError: org.springframework.cloud.netflix.ribbon.RibbonLoadBalancerClient.execute(Ljava/lang/String;Lorg/springframework/cloud/client/ServiceInstance;Lorg/springframework/cloud/client/loadbalancer/LoadBalancerRequest;)Ljava/lang/Object;| at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:978)| at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:897)| at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970)|
You should be using the release train to manage versions. Also Brixton is a very old release train. Please upgrade and don't set library versions manually.

JHipster with elasticsearch on cloudfoundry

Has anyone successfully used elasticsearch (searchly) through the Pivotal Web Services market place for a Jhipster generated application? I have correctly bound the searchly service to my application, but keep getting the following error:
Failed to instantiate [org.elasticsearch.client.Client]: Factory method 'elasticsearchClient' threw exception; nested exception is java.lang.IllegalStateException: java.lang.NumberFormatException: For input string: "//gopivotal:<redacted>#dori-us-east-1.searchly.com"
My jhipster production profile is as follows:
data:
elasticsearch:
cluster-name:
cluster-nodes: ${vcap.searchly.credentials.uri}
Any help appreciated.
cluster-nodes is actually used behind the scenes by TransportClientFactoryBean and it can't parse the username:password bit. It doesn't feel right to paste the URI of the service in the "cluster-nodes" property but I couldn't find anything else to configure it.
Can you please create an issue in the Spring Data ElasticSearch tracker?
In the meantime, I suggest to use Jest, you can create your own client easily from PWS as follows:
public JestClient jestClient(String url) {
HttpClientConfig clientConfig = new HttpClientConfig
.Builder(String url)
.readTimeout(6000)
.multiThreaded(true)
.build();
JestClientFactory factory = new JestClientFactory();
factory.setHttpClientConfig(clientConfig);
return factory.getObject();
}
And pass the property (as you did in your description) to that method.

Resources