Skip to content

Integrate Springboot JavaFX Client with feathersjs Server, communicate via socketio-client-java

Notifications You must be signed in to change notification settings

bwgjoseph/feathers-spring-javafx

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 

Repository files navigation

Feathers Spring JavaFX

This is a project showcase on how to integrate Springboot JavaFX Client with feathersjs Server, communicate via socketio-client-java. It also uses numerous features from Spring, and applying Spring best practices

The key concept is to demo on how to:

  1. Create JavaFX client integration with Springboot and Javafx-weaver
  2. Initialize websocket connection to feathersjs server via socketio-client-java, including auto-reconnection
  3. Use of SmartInitializingSingleton to wait until after bean has initialized before performing some actions. See WebSocketInitializer
  4. Use of ApplicationListener either through implements or @EventListener to trigger some action, where we can use SpEL to conditional listen to certain event. See UserSocketListener and MainController
  5. Use of ApplicationEventPublisher to publish (custom) events and @EventListener to subscribe for events
  6. Use of constructor-injection as DI best practice
  7. Use of @ConfigurationProperties for typesafe configuration. See FeathersConfig
  8. Use of configuration-metadata to provide auto-completion in application.properties
  9. Use of Spring-Security org.springframework.security.core.Authentication to store authenticated user into SecurityContextHolder and allow to retrieve via @AuthenticatedPrincipal or @CurrentUser
  10. Easily use of POJO object and send through websocket using ObjectMapper and JSONObject. See AuthenticationRequest or User entity class toJSONObject method
  11. Use of spring-boot-starter-data-mongodb to construct Query object

The following are yet to be done:

  1. Use of Transports and HTTP Headers?
  2. Use of JWT Token for re-authentication after disconnect
  3. Use of @Validated in @ConfigurationProperties
  4. Use of automatic-versioning-of-java-applications-using-git-version-gradle-plugin
  5. Add support for params in CRUD
  6. Use native query builder (like mongo-sdk) to write the query, and then output to json which will be sent to server through socket
  7. Initialize ObjectMapper with default prettyprint and timeformat etc
  8. Use of Converter to convert to JSONObject - See spring-data-custom-converter
  9. Use of Annotation to auto convert POJO to JSONObject? https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/web/reactive/result/method/annotation/PrincipalMethodArgumentResolver.html https://github.com/rwinch/spring-security51-by-example-reactive/blob/master/message/src/main/java/sample/message/CurrentUserIdArgumentResolver.java https://stackoverflow.com/questions/18343129/custom-annotation-binding-in-spring-controller

Configuration

  1. Enable Automatic Project Synchronization in Preference > Gradle
  2. Add the following to build.gradle which will output build.info in .jar\BOOT-INF\classes\META-INF\ when build
springBoot {
  buildInfo()
}

// optionally can add
eclipse {
    autoBuildTasks bootBuildInfo
}

Note

  1. No VM args is required (especially for JavaFX) in Run Configurations nor is it required after build and run as jar
  2. Google Guava EventBus or Spring-Reactor is an alternative to Spring's ApplicationEventPublisher
  3. More advance usage of ApplicationEventPublisher includes usage of @TransactionalEventListener and @Async
  4. Can also publish event asynchronously by using ApplicationEventMulticaster

Known Issues

  1. Whenever client reconnects, the socket events received will multiply. For example, after reconnection, instead of receiving 1x onUserCreated event, it will receive n times depending on how many times it has reconnected
  2. src/main/resources/META-INF/additional-spring-configuration-metadata.json has to be generated via Eclipse manually to provide auto-completion

Usage

  1. Start server by cd feathers-server && npm ci && npm run dev
  2. Start client by cd spring-javafx-client && gradlew clean build bootRun

Resources

Github

Stackoverflow

Others

About

Integrate Springboot JavaFX Client with feathersjs Server, communicate via socketio-client-java

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published