"error": "Could not connect to websocket endpoint ws://localhost:8000/subscriptions. Please check if the endpoint url is correct." for graphql spqr - spring-webflux

I have my data stored in mongodb and I'm trying to implemet subscription using graphql spqr and project reactive.
I'm getting respones for when I'm trying to test mutations and query, but I keep on getting the following error message for subsctiptions:
{ "error": "Could not connect to websocket endpoint
ws://localhost:8080/subscriptions. Please check if the endpoint url is
correct." }
I've done some reserch on this issue and came accross this, including "spring-boot-starter-websocket" in my dependencies didn't solve this, anf I'm not using firefox as my browser for the playground gui.
I followed this example on how to implement subscriptions using graphql spqr, and when I trying to clone the project the subscription actualy worked just fine.
Can't fine any difference on my implementation from the project above...
Here is my build.gradle file:
configurations {
compile.exclude module: 'spring-boot-starter-tomcat'
compile.exclude group: 'org.apache.tomcat'
compileOnly {
extendsFrom annotationProcessor
}
}
dependencies {
// https://mvnrepository.com/artifact/de.flapdoodle.embed/de.flapdoodle.embed.mongo
testImplementation group: 'de.flapdoodle.embed', name: 'de.flapdoodle.embed.mongo', version: '3.0.0'
// https://mvnrepository.com/artifact/io.leangen.graphql/graphql-spqr-spring-boot-starter
implementation group: 'io.leangen.graphql', name: 'graphql-spqr-spring-boot-starter', version: '0.0.6'
implementation group: 'io.leangen.graphql', name: 'spqr', version: io_leangen_graphql_spqr
// https://mvnrepository.com/artifact/com.graphql-java-kickstart/playground-spring-boot-starter
implementation group: 'com.graphql-java-kickstart', name: 'playground-spring-boot-starter', version: '11.1.0'
// https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-websocket
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-websocket', version: '2.5.4'
// https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-data-mongodb-reactive
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-data-mongodb-reactive', version: '2.5.4'
// https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-webflux
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-webflux', version: '2.5.4'
compileOnly group: 'org.projectlombok', name: 'lombok', version: org_projectlombok_lombok_version
annotationProcessor group: 'org.projectlombok', name: 'lombok', version: org_projectlombok_lombok_version
}
I'm using
compile.exclude module: 'spring-boot-starter-tomcat'
compile.exclude group: 'org.apache.tomcat'
To start netty instead of tomcat
And here is my subsctiption implementation:
#Autowired
private ProductRepository productRepository;
private final ConcurrentMultiMap<Double, FluxSink<ProductDto>> subscribers = new ConcurrentMultiMap<>();
#GraphQLQuery
public Flux<ProductDto> getProducts(){
return productRepository.findAll().map(AppUtils::ProductEntityToDto);
}
#GraphQLSubscription
public Publisher<ProductDto> taskStatusChanged(double price) {
return Flux.create(subscriber -> subscribers.add(price, subscriber.onDispose(() -> subscribers.remove(price, subscriber))), FluxSink.OverflowStrategy.LATEST);
}
Is there something I'm missing in my code? Or a dependancy? Or any other configuration? Any help would be very appreciated...

By default it seems GraphQl SPQR mapped the WebSocket subscription handling endpoint to /graphql, not the general /subscriptions in other GraphQL framework.
See the following info in console when the application is starting.
2021-10-09 12:50:02.653 DEBUG 14632 --- [ Test worker] o.s.w.s.s.s.WebSocketHandlerMapping : Patterns [/graphql] in 'webSocketHandlerMapping'
It can be changed by customizing graphql.spqr.ws.endpoint property in your application.properties.
But it seems its GraphQL WebSocket subscription implementation is very confused, it does not follow the Appllo WebSocket subscription protocol or the new graphql-ws spec.

Related

How to enable swagger UI on micronaut?

I'm following the micronaut doc for openapi at https://micronaut-projects.github.io/micronaut-openapi/latest/guide/
and the UI is not being generated, every time when I try to access /swagger, /swagger-ui I got this error:
{
"message": "Not Found",
"_links": {
"self": {
"href": "/swagger",
"templated": false
}
},
"_embedded": {
"errors": [
{
"message": "Page Not Found"
}
]
}
}
The dependencies are installed:
implementation("io.swagger.core.v3:swagger-annotations")
annotationProcessor("io.micronaut.openapi:micronaut-openapi:4.5.2")
The router on application.yml is defined:
micronaut:
application:
name: myapp
router:
static-resources:
default:
enabled: true
swagger:
enabled: true
paths: classpath:META-INF/swagger
mapping: /swagger/**
and the file openapi.properties on the root folder is created:
swagger-ui.enabled=true
micronaut.openapi.views.spec=apidoc.enabled=true,swagger-ui.enabled=true,swagger-ui.theme=flattop
micronaut.openapi.expand.api.version=v0.1
micronaut.openapi.expand.openapi.description=myapp
according to the docs a .yml file should be generated at;
For Kotlin build/tmp/kapt3/classes/main/META-INF/swagger/myapp-0.1.yml
On my controllers I have the Operation and ApiResponses annotation as well, but when I run the application the file yml is not being generated, how can I properly enable swagger on my micronaut project?
Code sample: https://github.com/rafa-acioly/micronaut
You defined only swagger in your application.yml. You should add also add a section for swagger-ui with a similar definition:
micronaut:
application:
name: openapitest
router:
static-resources:
swagger:
paths: classpath:META-INF/swagger
mapping: /swagger/**
swagger-ui:
paths: classpath:META-INF/swagger/views/swagger-ui
mapping: /swagger-ui/**
Also, I used the default openapi.properties file:
swagger-ui.enabled=true
redoc.enabled=false
rapidoc.enabled=false
rapidoc.bg-color=#14191f
rapidoc.text-color=#aec2e0
rapidoc.sort-endpoints-by=method
And did you try to clean and build your project with gradlew?
I create a sample repository on GitHub and you can check it.
=========UPDATE========
Ok, I've found what is incorrect! You are using annotation-processing :
annotationProcessor("io.micronaut.openapi:micronaut-openapi:4.5.2")
But if you are using Kotlin, you should use kapt - Kotlin Annotation Processing Tool. Here is a few articles - link1, link2.
So you should change to:
kapt("io.micronaut.openapi:micronaut-openapi:4.5.2")

Gradle selenium(any) dependencies are not downloading

After creating new java gradle project added following dependencies in build file.
enter image description here
dependencies {
// Use JUnit Jupiter for testing.
testImplementation 'org.junit.jupiter:junit-jupiter:5.7.2'
// This dependency is used by the application.
implementation 'com.google.guava:guava:30.1.1-jre'
// https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java
implementation group: 'org.seleniumhq.selenium', name: 'selenium-java', version: '4.3.0'
// https://mvnrepository.com/artifact/io.github.bonigarcia/webdrivermanager
implementation group: 'io.github.bonigarcia', name: 'webdrivermanager', version: '5.3.0'
// https://mvnrepository.com/artifact/org.testng/testng
testImplementation group: 'org.testng', name: 'testng', version: '7.6.1'
// https://mvnrepository.com/artifact/org.apache.poi/poi
implementation group: 'org.apache.poi', name: 'poi', version: '5.2.2'
// https://mvnrepository.com/artifact/javax.annotation/javax.annotation-api
implementation("javax.annotation:javax.annotation-api:1.3.2")
}
Then following popup appeared on vs code.
"Do you want to synchronize the Java classpath/configuration" once and for all? with yes/always/never option
I tried selecting each option in new project. Still after doing gradle build none of dependency downloaded
So if I am writing WebDriver or WebDriverManager I am not getting import option in quick fix

Selenium4+Junit5 : Infinite browsers are launching while running scripts in Parallel with Selenium 4

I have well configure and designed framework using webdrivermanager = '5.0.3'( Selenium 3.141.5,) + Junit 5 + junit-platform.properties file to run the test scripts in parallel, which running seamlessly without any issues. I am able to run scripts based on tags and based on package.
Now I upgraded the selenium version to 4.1.2, when I run individual script it is perfectly fine but when run the scripts in parallel infinite browsers are launching even though thread count is restricted to 5 in junit-platform.properties file.
junit.jupiter.execution.parallel.enabled=false
junit.jupiter.execution.parallel.mode.default=same_thread
junit.jupiter.execution.parallel.mode.classes.default=concurrent
junit.jupiter.execution.parallel.config.strategy=fixed
junit.jupiter.execution.parallel.config.fixed.parallelism=5
I am using below mentioned dependencies in build gradle file.
repositories {
jcenter()
mavenCentral()
}
ext {
// selenium = '3.141.59'
webdrivermanager = '5.0.3'
// junitJupiterVersion = '5.8.2'
selenium = '4.1.2'
seleniumJupiterVersion = '4.0.1'
junitJupiterVersion = '5.7.0'
}
dependencies {
compile("org.junit.jupiter:junit-jupiter:${junitJupiterVersion}")
compile("org.seleniumhq.selenium:selenium-java:${selenium}")
// compile("io.github.bonigarcia:selenium-jupiter:${seleniumJupiterVersion}")
// compile("org.seleniumhq.selenium:selenium-java:${selenium}")
// compile("io.github.bonigarcia:webdrivermanager:${webdrivermanager}")
// testImplementation "org.seleniumhq.selenium:selenium-chrome-driver:${selenium}"
// testImplementation "org.seleniumhq.selenium:selenium-firefox-driver:${selenium}"
// testImplementation "org.seleniumhq.selenium:selenium-ie-driver:${selenium}"
// testImplementation "org.seleniumhq.selenium:selenium-edge-driver:${selenium}"
// testImplementation "org.seleniumhq.selenium:selenium-safari-driver:${selenium}"
// testImplementation "org.seleniumhq.selenium:selenium-remote-driver:${selenium}"
// testImplementation "org.seleniumhq.selenium:selenium-support:${selenium}"
// testImplementation('org.junit.jupiter:junit-jupiter:5.5.1')
// testImplementation 'org.hamcrest:hamcrest:2.1'
// testImplementation 'org.hamcrest:hamcrest-library:2.1'
// testCompile("org.junit.jupiter:junit-jupiter-api:5.6.2")
// testRuntime 'org.junit.jupiter:junit-jupiter-engine:5.6.2'
// testRuntime("org.junit.platform:junit-platform-launcher:1.4.2")
// testCompile('io.github.bonigarcia:selenium-jupiter:4.0.1')
compile group: 'io.qameta.allure', name: 'allure-junit5', version: '2.11.0'
compile group: 'org.apache.pdfbox', name: 'pdfbox', version: '2.0.16'
implementation group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.17.1'
// implementation group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.17.1'
compile group: 'io.qameta.allure', name: 'allure-gradle', version: '2.7.0'
compile 'org.apache.maven.plugins:maven-surefire-plugin:2.21.0'
// compile('com.assertthat:selenium-shutterbug:1.5')
compile 'org.slf4j:slf4j-nop:1.7.25'
implementation group: 'javax.mail', name: 'mail', version: '1.4.7'
// implementation group: 'javax.mail', name: 'javax.mail-api', version: '1.6.2'
// runtimeClasspath group: 'javax.mail', name: 'javax.mail-api', version: '1.6.2'
// compile group: 'net.lightbody.bmp', name: 'browsermob-core', version: '2.1.4'
// compile group: 'org.postgresql', name: 'postgresql', version: '42.2.14'
compile group: 'org.mongodb', name: 'mongo-java-driver', version: '3.12.4'
compile group: 'ru.yandex.qatools.ashot', name: 'ashot', version: '1.5.4'
// implementation group: 'org.json', name: 'json', version: '20201115'
implementation group: 'com.googlecode.json-simple', name: 'json-simple', version: '1.1.1'
// testImplementation group: 'org.junit.platform', name: 'junit-platform-launcher', version: '1.7.2'
// testImplementation group: 'org.junit.platform', name: 'junit-platform-runner', version: '1.7.2'
// testImplementation group: 'org.junit.platform', name: 'junit-platform-surefire-provider', version: '1.3.2'
}
Project component : Selenium 4 +Junit5 +junit-platform properties file
Any help to resolve this issue is highly appreciated.
Sorry, if the question is still relevant, of course.
First, you may just marked all your test classes with #ResourceLock("SYSTEM_OUT") annotation. see details here and below about Syncronization.
However this may not help. Then you may additionally implement ParrallelExecutionConfiguration and ParallelExecutionConfigurationStrategy and write this implementation in a junit-platform.properties file e.g.
junit.juipiter.execution.parallel.config.custom.class=base.ParallelStrategy
where "base" - package and "ParallelStrategy" - the implementation of the above interfaces (I just return numbers of thread values).
Also you have to state custom strategy explicitly:
junit.juipiter.execution.parallel.config.strategy=custom
Why it worked with Selenium3+, but stopped with the fourth - I don’t know. But these steps solved the same problem for me as yours.
There's a few components which might be causing this.
JUnit issue 'Parallelism value ignored for the fixed strategy' #2273 describes how the ForkJoinPool used will actually grow if threads are blocked
Selenium issue 'Can no longer limit the number of parallel sessions from JUnit 5 #9359' describes how the above issue impacts Selenium versions 4.0.0-alpha-4 and up.
Both issues suggest defining a custom strategy which limits the MaxPoolSize. This works, but only on JDK9 and up. The ForkJoinPool created in ForkJoinPoolHierarchicalTestExecutorService is different between JDK8 and JDK9+, with only the latter using the strategy MaxPoolSize.
So if you're on JDK8, I think the only option is to use ResourceLocks. Otherwise, define a custom strategy.
See my SO post maven-failsafe-plugin not honoring fixed parallelism in JUnit5 for pretty much the same issue.

java.lang.NoClassDefFoundError: com/google/api/core/ApiFuture

I have successfully added firebase admin to my kotlin jvm backend code and i can successfully send push notification with this:
object FirebaseUtils {
init {
val credentials = GoogleCredentials.fromStream(Gson().toJson(FIREBASECREDIENTIALS).byteInputStream())
val options = FirebaseOptions.Builder()
.setCredentials(credentials)
.setDatabaseUrl("url")
.build()
FirebaseApp.initializeApp(options)
}
fun sendPushNotification(registrationToken:String,notificationTitle:String,notificationMessage:String){
val messageBuilder = Message.builder()
.setNotification(Notification(notificationTitle,notificationMessage))
.setToken(registrationToken)
val message = messageBuilder.build()
// Send a message to the device corresponding to the provided
// registration token.
val response = FirebaseMessaging.getInstance().send(message)
// Response is a message ID string.
println("Successfully sent message: $response")
}}
To send:
FirebaseUtils.sendPushNotification(registrationToken, ,"testTitle","testMessage")
But when i uploaded this to an AWS Lamda i keep getting this exception every time i call it
com/google/api/core/ApiFuture: java.lang.NoClassDefFoundError
java.lang.NoClassDefFoundError: com/google/api/core/ApiFuture
at utils.FirebaseUtils.<clinit>(FirebaseUtils.kt:29)
at lamdas.CourseManagerLambda.handleRequest(CourseManagerLambda.kt:57)
I've tried importing com.google.api:api-common but that still didn't work.
Gradle:
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
implementation "org.jetbrains.exposed:exposed:$exposed_version"
implementation "com.amazonaws:aws-lambda-java-core:$awsLambdaCoreVersion"
implementation "com.google.code.gson:gson:$gsonVersion"
implementation "com.microsoft.sqlserver:mssql-jdbc:$sqljwcVersion"
implementation 'org.slf4j:slf4j-nop:1.7.25'
implementation 'am.ik.yavi:yavi:0.2.3'
// Core dependency
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.1.1'
// Koin for Kotlin
implementation "org.koin:koin-core:$koin_version"
// Koin extended & experimental features
implementation "org.koin:koin-core-ext:$koin_version"
// Koin for Unit tests
testImplementation "org.koin:koin-test:$koin_version"
// Koin for Java developers
implementation "org.koin:koin-java:$koin_version"
testCompile group: 'junit', name: 'junit', version: '4.12'
implementation 'io.github.rybalkinsd:kohttp:0.11.0'
implementation 'com.google.firebase:firebase-admin:6.10.0'
implementation group: 'software.amazon.awssdk', name: 'bom', version: '2.5.29', ext: 'pom'
implementation group: 'software.amazon.awssdk', name: 'kinesis', version: '2.9.14'
implementation group: 'com.google.api', name: 'api-common', version: '1.8.1'
}
I was building the zip i uploaded to AWS like this
task buildDist(type: Zip) {
appendix = "dist"
from sourceSets.main.output
from configurations.runtimeClasspath.findAll {
it.name.endsWith("jar")
}.collect {
zipTree(it)
}
}
And for some reason some dependencies were missing at runtime so i switched to using Shadow to generate a Fat Jar and everything works fine now.

Cannot change dependencies of configuration

After I added copyBootstrap to build.gradle I am getting the next error when try to run the build task:
FAILURE: Build failed with an exception.
What went wrong:
A problem occurred configuring root project '.
Cannot change dependencies of configuration ':providedCompile' after it has been included in dependency resolution.
How could this issue be solved? I have searched on Internet but no solutions were found. I got the copyBootstrap task from this link. Their goal is to extract all content from org.webjars group jars to a specific path.
I am using Gradle 3.2 and Intellij IDEA 2016.2.5
//group 'org'
//version '1.0-SNAPSHOT'
task wrapper(type: Wrapper) {
gradleVersion = '3.2'
distributionUrl = "https://services.gradle.org/distributions/gradle-$gradleVersion-all.zip"
}
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'org.akhikhl.gretty:gretty:1.4.0'
}
}
repositories {
mavenCentral()
jcenter()
}
//apply plugin: 'java'
//apply plugin: 'eclipse-wtp'
//apply from: 'https://raw.github.com/akhikhl/gretty/master/pluginScripts/gretty.plugin'
apply plugin: 'war'
apply plugin: 'org.akhikhl.gretty'
sourceCompatibility = 1.8
targetCompatibility = 1.8
dependencies {
//compile group: 'org.akhikhl.gretty', name: 'gretty', version: '1.4.0'
// ********************************************************************************************************
// SPRING FRAMEWORK, ORM Y H2DB
// ********************************************************************************************************
compile group: 'org.springframework', name: 'spring-webmvc', version: '4.3.4.RELEASE'
compile group: 'org.springframework', name: 'spring-orm', version: '4.3.4.RELEASE'
compile group: 'org.springframework', name: 'spring-jdbc', version: '4.3.4.RELEASE'
compile group: 'org.hibernate', name: 'hibernate-core', version: '5.2.3.Final'
// ********************************************************************************************************
// JACKSON DATABIND
// ********************************************************************************************************
compile group: 'com.fasterxml.jackson.core', name: 'jackson-core', version: '2.8.4'
compile group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.8.4'
// ********************************************************************************************************
// THYMELEAF
// ********************************************************************************************************
compile group: 'org.thymeleaf', name: 'thymeleaf-spring4', version: '3.0.2.RELEASE'
// ********************************************************************************************************
// SERVLET
// ********************************************************************************************************
compile group: 'javax.servlet', name: 'javax.servlet-api', version: '3.1.0'
// ********************************************************************************************************
// MYSQL CONNECTOR
// ********************************************************************************************************
//compile group: 'mysql', name: 'mysql-connector-java', version: '6.0.5' issues with time zone
compile 'mysql:mysql-connector-java:5.1.6'
// ********************************************************************************************************
// WEB RESOURCES
// ********************************************************************************************************
compile group: 'org.webjars', name: 'angularjs', version: '1.5.8'
compile group: 'org.webjars', name: 'jquery', version: '2.1.4'
compile group: 'org.webjars', name: 'bootstrap', version: '3.3.7'
compile group: 'org.webjars', name: 'jquery-ui', version: '1.12.1'
compile group: 'org.webjars', name: 'modernizr', version: '2.8.3'
// ********************************************************************************************************
// JUNIT AND SPRING TEST
// ********************************************************************************************************
testCompile group: 'junit', name: 'junit', version: '4.12'
testCompile group: 'org.springframework', name: 'spring-test', version: '4.3.4.RELEASE'
// ********************************************************************************************************
// GOOGLE DRIVE API
// ********************************************************************************************************
compile group: 'com.google.api-client', name: 'google-api-client', version: '1.22.0'
compile group: 'com.google.apis', name: 'google-api-services-drive', version: 'v2-rev245-1.22.0'
compile group: 'com.google.api-client', name: 'google-api-client-java6', version: '1.22.0'
compile group: 'com.google.oauth-client', name: 'google-oauth-client-jetty', version: '1.22.0'
// ********************************************************************************************************
// DROPBOX API
// ********************************************************************************************************
compile group: 'com.dropbox.core', name: 'dropbox-core-sdk', version: '1.8.2'
// ********************************************************************************************************
// TWITTER API
// ********************************************************************************************************
compile group: 'org.twitter4j', name: 'twitter4j-core', version: '4.0.5'
// compile group: 'org.slf4j', name: 'slf4j-mylearn.api', version: '1.7.21'
// compile group: 'org.slf4j', name: 'slf4j-log4j12', version: '1.7.21'
// compile files("twitter/main/webapp/") // add this path as a classpath
}
task copyBootstrap(type: Copy) {
into "$buildDir/static_resources"
configurations.compile
.files({ it.group.equals("org.webjars")})
.each {
from zipTree(it)
}
}
//build.dependsOn(copyBootstrap)
task copyToLib2(type: Copy) {
into "$buildDir/output/libs"
from configurations.runtime
}
war {
archiveName = 'ROOT.war'
destinationDir = file('webapps')
}
// ********************************************************************************************************
// GRETTY SETTINGS
// ********************************************************************************************************
/* Change context path (base url). otherwise defaults to name of project */
gretty {
port = 8081
contextPath = ''
}
This problem seems to be related to the org.akhikhl.gretty plugin you are trying to use. If I try to build a project using the above gradle file I get the following output:
C:\ws\PLAYGROUND\test123>gradle wrapper --stacktrace
Changed dependencies of configuration ':providedCompile' after it has been included in dependency resolution. This behaviour has been deprecated and is cheduled to be removed in Gradle 3.0.
Changed dependencies of parent of configuration ':compile' after it has been resolved. This behaviour has been deprecated and is scheduled to be removed in Gradle 3.0
Changed strategy of configuration ':compile' after it has been resolved. This behaviour has been deprecated and is scheduled to be removed in Gradle 3.0
Changed dependencies of configuration ':grettyProvidedCompile' after it has been included in dependency resolution. This behaviour has been deprecated and is scheduled to be removed in Gradle 3.0.
⋮
* Exception is:
org.gradle.api.ProjectConfigurationException: A problem occurred configuring root project 'test123'.
at org.gradle.configuration.project.LifecycleProjectEvaluator.addConfigurationFailure(LifecycleProjectEvaluator.java:79)
at org.gradle.configuration.project.LifecycleProjectEvaluator.notifyAfterEvaluate(LifecycleProjectEvaluator.java:74)
at org.gradle.configuration.project.LifecycleProjectEvaluator.evaluate(LifecycleProjectEvaluator.java:61)
⋮
Caused by: org.gradle.api.InvalidUserDataException: Cannot change dependencies of configuration ':compile' after it has been resolved.
at org.gradle.api.internal.artifacts.configurations.DefaultConfiguration.validateMutation(DefaultConfiguration.java:578)
at org.gradle.api.internal.artifacts.configurations.DefaultConfiguration$2.run(DefaultConfiguration.java:137)
⋮
at org.akhikhl.gretty.GrettyPlugin$_addDependencies_closure11.doCall(GrettyPlugin.groovy:130)
⋮
That is the gretty plugin seems to use functionality that has been removed with gradle 3.0
There is issue #306 that has been reported a short time ago which describes pretty much your problem.
Given the number of open issues for such a small project and the lack of activity on the issues, I don't think this plugin is much of a help and you will probably be better off using something different.