Java GUI + Server Issue - java

So far, I've been searching far and wide on the internet for the best practice when it comes to writing a Java server with a GUI (for stopping and starting it). I know that I have to run the server in a separate thread as the GUI but I was also thinking that it my be a little less complicated if I made each piece, the server and the GUI, in its own Java program or process. If I go with the latter, how do I interact with the server from the GUI if they aren't the same application. Would I just kill the process from Java. I really need some help (or maybe a tutorial).
P.S. I'm going to write the client for other PC's and android phones in the house so I could create a simple messaging system in the network for easy copy and paste between devices so I was considering building the GUI and server in with the client so I could distribute that and it would be two way but I'm not sure if thats the right approach or not.
Thanks!

You sir, are looking for an Application Server, like JBoss. Interact with it using web pages as the GUI. Use HTTP as your messaging protocol (POST and GET). Use Eclipse for Java EE
and read some tutorial / guide. It might be some to learn now, but you'll benefit from it later.
For your requested functionality, create a web application with a servlet for receieving HTTP requests first.

I don't think there is a 'right' way to do this. If as you say, you want to have more than one client (an app running on PCs and an app running on android phones), then you are better off going for a client-server architecture, where your server and your client are two (or more in the case of the different GUIs you want to create) different programs.
The way they can communicate is also open for you to choose. You can go low level and connect through sockets, or you could use HTTP and create web clients.
If you give us a bit more context about what you want to create (server and client are way too generic words) then we could give more tailored questions.

Related

Does client-side java work on a server?

Can I write client side java in intelliJ, and then simply put it on a server for it to run on a server? Or will I need to write in a specialised version of Java and need to use a specialised IDE instead?
I'm trying to make an app and run the primary functions on a server then have the app send requests and fetch the data from the server. (It will esentially be a search engine of sorts and queries will be made to the server, which will then apply filters and use my algorithms to perform a search, before returning a result to the mobile device). But I'm not sure if I can begin writing this java on intellij, just as I would when making say, a simple calculator, or if I would need to write the java using a specialised server variation and server IDE.
Thank you.
The Java language is the same no matter what, so your logic can be ported easily. However on a server you may use a framework that's different from one you'd use on a client (for example you tagged this android- there wouldn't be Activities or Views on a server. You'd use another framework instead, possibly Spring.) Or you could go frameworkless, but then you'll have to write a lot of code that the frameworks do for you.
As for IDE- an IDE is an editor. You can write Java in notepad if you want. There's no difference, its just what features make your life easier. And yes, IntelliJ is a common choice.
If you would like make your own website, you should go with JavaEE or better with Spring.
If you would like to make simple server side application which will listen on specific port then respond something, go with Sockets
Netty is interesting NIO Socket library

Database for Google App Engine and desktop application

I need some advice. I'm new to Java EE technologies. Anyway, I would like to make my first JAVA EE project.
Imagine 2 client applications and server application.
1) Server. I picked up Google App Enginge technology to create server application. I would like to connect it to some easy database.
2) Client applications. I would like them to be desktop applications (or applications launched from the desktop) and these 2 apps also have to be connected to the same database as sever.
There was no problem to create this in Java SE environment - I had two clients applications with sockets staff and server application with socket staff. All worked locally.
But now I want to have server and database on the Internet and I want to make it in more professional way.
My problems are:
How to create free database from GAE? Is datastore the best option or something else? What's important - the client desktop application will also use this database. I'm looking for the easiest solution.
Maybe the solution is to create web client application instead of the desktop one - but make it look like it was desktop app (I would like to avoid using browser). I have no idea how to do this and if this is even possible.
Any help will be really appreciated. I'm stuck because my knowledge is too little to start. I have ma GAE app and I don't know what should I choose next.
Thank you in advance.
If you want make desktop application, you need to build backend application first.
check this out. You can use same concept with that. Build back end, and then create API to connect to your backend, and use that API in your desktop application.
Datastore is easiest way to store data. Check this out. Datastore have some limitation (such as didnt support join, many to many relationship, etc). Please consider wisely. Otherwise you can use Google Cloud SQL for your option, but AFAIK its not free.

Monitor and control remote Java servers

I have to deploy some Java servers in a bunch of different networks. For each server, I need to monitor its status and send it tasks to be executed in that specific server. Something like distributed workers.
This servers would be used from different platforms and languages so I need to find a way to communicate with them and obtain the needed information. Which is the best way to do this? I've been reading about use JSONs to communicate with my servers but I'm trying to figure out if there is a better approach.
Another solution could be to have a web dashboard and control all through web petitions but I prefer the servers to be standalone. Any ideas on what I can do?
At the moment I would suggest REST interfaces for your Java server. Since REST with Json is easy to implement in other languages too and you can even use HTML and JavaScript to write a Monitor client. So from my point of view this is the most flexible solution.
An other solution would be to use XMPP to "talk" with the server and "ask" them about there state. I remeber this as a solution for machine to machine communication, but this was before the Json and REST boom so I would not suggest to go with this.
When your other platforms consists of Java and C# mostly SOAP could also be a solution, since there are good code generator for both languages which can create the WSDL from code and vice versa. But its kinda difficult to use SOAP in JavaScript (as far as I experienced) and maybe other languages have the same problem with SOAP.
If multiple platforms are involved, web services are probably your best bet. You can have you java servers expose web services (for status and task execution) and you can call them from anywhere/any system.

Converting desktop application into server + browser application

I am relatively new to web development, but I have some C++/Java experience. I have got the following conversion to do:
Current:
Desktop Application (Automation Software) developed in C# that communicates with remote PLC (Controller that overlooks different sensors in realtime) using TCP Sockets over the Web.
My Idea:
Convert the application into a server side software that will still communicate with the PLC over TCP/Socket. And use a browser to operate it, so the remote site can be monitored and controlled from any computer in our Intranet (possibly Tablets in the future).
Motive for doing it:
We had a computer fault which left the operators without control.
The new app:
I am planning on writing the server app using Java and OOP (so far no problem). And use HTML/CSS/Javascript for the WebApp and AJAX to update the page.
But I am still lost at how can I transport all this data between them in a proper and decent manner. I have read about SOAP and JSON in this Post. Although, I am not sure if I need to use them at all, is it a good solution to use either JSON or SOAP? Or is there any other solution that you may recommend?
Cheers,
Leo
If you consider skipping the development work to convert your app into a server-side software and just go for a third party solution, I suggest you take a look to Thinfinity VirtualUI.
"...offers a GUI remoting solution for in-house Windows desktop
developments, allowing them to be delivered as Windows/HTML5 dual-platform applications
simply by adding one line of code.
These Windows applications can keep their standard desktop environment behavior and,
alternatively, be accessed remotely from any modern web browser in a multi-user,
multi-instance fashion when hosted on a Thinfinity VirtualUI Server environment."
https://www.cybelesoft.com/docs/thinfinity_virtualui_whitepaper.pdf
SOAP is for defining public APIs that are published on the internet for other people to use, which does not seem like your use case. It is not particularly awesome to have to deal with it from inside a browser either, although there are javascript SOAP-client libraries. There is also going to be a fair bit more overhead on the server side parsing and validating XML than de/serializing between JSON and POJOs.
JSON is much easier to deal with in a browser, being natively understood and all that. Everything you need is built into the core of jQuery, no dependence on plugins that may have unknown levels of future support.

Single sign-on in Java / VNC

Background
On the project I work on we have GUI applications running on several different servers. Due to their user interface similarities I am investigating combining their OMIs into a single unified interface. Currently these applications are all remotely viewable via VNC. I plan to take advantage of this by having the master display run several VNC viewers under the covers and wrap an interface around these VNC sessions to make them appear like native applications.
Problem
I am looking for pointers for architecting a single sign-on solution. I want to eliminate each application's individual login and instead have users login to the unified display only. When they do that they would then be automatically logged in to each of the individual apps.
Constraints
The applications are all Swing-based Java apps running on Linux.
Authentication is performed by a Windows 2003 Server machine with Active Directory.
I'd strongly prefer an off-the-shelf solution to a custom-built one.
Ideas
My investigation has pointed me towards Kerberos and GSSAPI. Kerberos's ticket-based mechanism seems well-suited to the task.
One tricky bit is that these applications are always running. I need the unified display to somehow "tell" them when the user has logged in. It's not like normal Kerberized programs where they will perform a Kerberos login at startup.
If I use Kerberos I'm not sure how to transfer tickets to the various application servers. Is there a standard way to transfer them? Do I just use "scp" or something? Or do I develop my own socket-based network protocol and have the Java programs connect to each other and transfer tickets that way?
I don't want to get too bogged down in the details, though. I'd appreciate even general ideas like "have you considered Technology X?" or "try XYZ instead of VNC, it does this for you."
Updates
I'll edit in answers and clarifications here...
Have you considered that some authentication must take place anyway and that VNC only exports the view to a running program, so a VNC session cannot transport tickets?
Yes, indeed. Java + VNC is what we have right now. I could change out VNC for something else if there's a better way to remotely view the apps. Without rewriting them, that is. The ideal solution would be to separate them into distinct client and server pieces and put all the GUI code into the client, but that's 5-star difficulty and I need 1- or 2-star.
Have you considered the case when two users log in the same time? Will they see the same app? Or will this be forbidden?
Yeah, I've considered that. They will either see the same app or it will be forbidden. Either solution is okay as far as this particular system goes, so this isn't a big deal.
Have you considered just using an X Server on your local host and export the clients applications windows?
Yeah, this would be great. Can this be done with already-running apps? I have to connect to these apps after they've already started. I can't start them on demand when somebody fires up the central viewer.
RealVNC Enterprise Edition supports AD authentication (~$50 per exported desktop). Perhaps you can simply let people auth into the apps that way. FreeNX supports PAM authentication so you could perhaps hack something together with winbind, especially if your linux dist makes AD setup easy.
One last thing is running your apps in VirtualBox which can run in a headless mode via RDP. You can authenticate against PAM and thus winbind. This also has the advantage of being windows friendly on the client side via Remote Desktop which is pre-installed or readily available for windows.
Okey, I will try and start this list. Have you considered...
JAAS? Should include the GSS API, but was very cumbersome the last time I tried it.
that some authentication must take place anyway and that VNC only exports the view to a running program, so a VNC session cannot transport tickets?
a browser based solution with an embedded Java VNC client? At least the IE is able to carry out kerberos authentication, I don't know about the other browsers, or HOW the IE does that.
the case when two users log in the same time? Will they see the same app? Or will this be forbidden?
just using an X Server on your local host and export the clients applications windows?
EDIT: More considerations:
When using the X Server variant, use Xmove to move the programs to the X Server.
You can use SSH authentication with private/secret keys and let the user enter one passphrase to connect all your servers. SSH agent is the keyword.
With the existing SSH connections, start XMove on all the machines, collect all GUIs and send them to the client. You could even write a little MainWindow, with Buttons for each app, and when clicked, export only one of the apps, so it seems like they have been started from the main GUI.

Categories

Resources