Issue
I have a project that was started and orchestrated by someone wayyyyyy more talented than I, and I've hit a point that I can't figure how to bridge.
This is a Java/JavaFX/Spring Boot project, and NOT a Swing project. I see a lot of answers re: Swing. Both applications are also set up in Gradle, so both applications have their own separate ./gradlew bootRun
commands and are running in CentOS 7. Both applications have their own, separate, main() methods
. I believe the original design was intended, purposefully, to remove any access to the data from the GUI, entirely, which is the reason for the separation. I'm just having a tough time finding a way to pass necessary data back and forth.
There are separate applications that are designed to work together.
**Kiosk**
which houses the GUI elements and GUI-related controllers
**Governor**
which houses an API and an APP application. The API, as of now, is helping with Source and File interfaces. The APP houses an H2 database (all stored from JSON files, but the content is irrelevant for this particular question), a User package (which houses the User data that feeds the H2 database), and a Source package (which does all the files methods)
What I want to do is:
- Get the
username
andpassword
, supplied by the user at the**Kiosk**
level, and pass that somehow into the**Governor**
. - Once I can pass the data, I know how to do the rest, to check against the db and verify if the user has valid credentials or not, etc.
- Once I have a boolean value (let's call id
validUser
), I want to pass that information back from the**Governor**
to the**Kiosk**
, and I can move on from there.
I don't have any code to copy and paste, so I am hoping that the description above is enough to point me in the right direction. I have tried googling all over for "pass data between separate java applications", "separate gui and logic java application", and everything you can think of, but I've hit a wall.
I'm happy to provide any other information you might need, and I'm not looking for anyone to write the code for me, but if you have any examples you've seen, or a concept I may not be familiar with that would help me pass this data back and forth, I would be eternally grateful!
*** Edit *** Trying to add MVP as best I can. Hopefully everything needed to answer question above can be gleaned from below.
Kiosk/LoginController
@Component
public class LoginController extends Controller {
@FXML
TextField username;
@FXML
TextField password;
@FXML
Button loginButton;
@FXML
public void tryLogin() {
UserServices userServices = new UserServices();
String usernameEntered = username.textProperty().getValue();
String passwordEntered = password.textProperty().getValue();
userServices.validateUser(usernameEntered, passwordEntered);
// ... other non-related methods re: tryLogin()
}
}
Kiosk/UserServices
public class UserServices {
public boolean validateUser(String username, String password) {
// **** How do I pass the args (username and password) to Governor?
if (!userFound) {
return false; // user not found, deny entry
}
return true; // allow entry
}
}
}
Governor/API/FileEntry
Note: This file is only a sample of an API module interacting with KIOSK--I do not understand this completely--again, doing the best I can with my limited resources; I believe I need to create my own API User module, but unsure how to proceed)
@JsonDeserialize(as = DefaultFileEntry.class)
public interface FileEntry {
Path getPath();
boolean isDirectory();
@JsonIgnore
default Optional<String> getName() {
if (getPath().getFileName() == null) {
return Optional.empty();
} else {
return Optional.of(getPath().getFileName().toString());
}
}
}
Governor/APP/UserRepository
public interface UserRepository extends JpaRespository<User, String> {
User findByUsername(String username);
}
Governor/APP/UserService
@Service
public class UserService {
private UserRepository userRepository;
public UserService(UserRepository userRepository) {
this.userRepository = userRepository;
}
// SQL methods to create database, if necessary, search, create, update, and delete users
}
Solution
There are several ways to for applications to share data with one another:
- JMS, AMQ, or some other messaging system.
- A shared database where applications poll for changes.
- Open up a REST endpoint that each application can call to update each other. Be sure to secure with certs so outsider can't use them.
Answered By - Ryan
Answer Checked By - Katrina (JavaFixing Volunteer)