How can I provide a telnet interface to my Java application? - java

I want to provide a telnet interface to my Java application, primarily so that developers can interact with the app, view debugging information, etc - before we've implemented our full end-user facing GUI.
Can anyone recommend an easy and effective way to do this? I've looked at embedding the scala interpreter, but it doesn't seem to be accessible via telnet. Ditto for Beanshell (which I'm not too keen on anyway as I believe its unmaintained).

Couple of options:
Grizzly for embedding a generic server (http://grizzly.java.net/)
Mina is another similar option (http://mina.apache.org/)
Instead of Telnet, it might be easier to just embed a web server. Not that a CLI isn't cool and all, but it might be a bit easier/more friendly.
Jetty http://docs.codehaus.org/display/JETTY/Embedding+Jetty
Tomcat http://tomcat.apache.org/tomcat-5.5-doc/catalina/docs/api/org/apache/catalina/startup/Embedded.html
JMX is great for monitoring but the UI isn't very good for 'writing' data. NetBeans has some nice tutorial projects in it.
I think of all of the options above the embedded Jetty is probably the easiest.

Have you considered using JMX? It's built right into the jdk and can provide remote access via jconsole to any methods you configure it too.
Now it's not going to work exactly like ssh or telnet, so it might not meet your needs fully. But if your goals is access to invoking methods and debugging information remotely, that's kind of it's main purpose.
The bonus is after you build a UI you can still use the JMX stuff to monitor performance after it's goes live.

Try Jsh its good for telnet related stuff.

I faced this same issue and came up with a slightly ugly combination of nvt4j (telnet server code) plus JLine (Java command line history editor, tab completion, etc.). My application listens on localhost for telnet connections and runs a CLI console loop when it gets a connection.
One key trick is to get the rows and columns information (which is sent via the telnet protocol) transferred from nvt4j to JLine so things don't go haywire when you reach the end of the line.

If you only need a line-mode interface via Telnet, you could use my Java class TelnetStdioRedirector.

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

Remote desktop control using web application

We are planning to develop remote desktop sharing feature in out web application (written in Java) where one user will be able to connect other users desktop with full access.
I don't want to use applications like team-viewer. It has to be some kind of web browser plug-in or feature.
I found following couple of solutions like Adobe Connect & Java.awt.Robot class.
Can anyone please let me know best option available?
It will be great if there is any open source project which can satisfy these requirements.
Try RealVNC out of the box, it has a built in Java web-client that allows full control. Most of the standard flavors of Linux run it, this, of course, totally depends on your user base and what you're trying to do but for an internal tool it is perfect.
http://www.realvnc.com/products/free/4.1/man/vncserver.html
The above link is the documentation for VNC server. It can be configured to one-session per port, it is just a matter of making sure the ports are correct. It sounds like you're reinventing the wheel on this one. There's a horde of good free products out there to handle this. For an infinite user-base this probably wouldn't be the best solution. For an internal tool it works wonders.

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.

Call COM port from webpage

I'm looking for a way to call a COM port from a webpage.
I was thinking abut running a Java WebStart (or Flash?) program that opens a local web server that allows to interact with the COM port using JSONP.
Are there any show stopping security restrictions on the way that I don't know of? This should be possible:
use native libraries (Java COM bridge) from Java WS application
open a local port
access local port from javascript, likely using <script> tags
do all this without scaring users with "This website is trying to do something really nasty, get off as fast as you can" kind of messages :)
I've used a Java COM bridge before, so this shouldn't be the problem - at least as soon as I'm able to run native code.
So how would my JNLP file have to look like to get this working? Any alternatives to Java WS? Better install it as a daemon?
Impossible. This violates all sorts of very basic security principles, especially the part about do all this without scaring users with "This website is trying to do something really nasty, get off as fast as you can" kind of messages
This is EXACTLY what those messages are intended to prevent.
This article answers the first part of my question, the WS to COM approach that is: Juggling with DLLs, WebStart and Maven
Accessing an HTTP server on a local port should also be feasible as that's what Playdar does for instance.
What are you trying to achieve?
You need a standalone software that does the job. The user will have to install it. Like the security pathches.

How to get the details using telnet API

Is it possible to get the following information via Telnet?
Software version
config files
config register
information on traffic and errors
If you have sample code that you could share that would be really useful so that I can procceed further with your help .
I will be thankful for your valuable replies.
Telnet is nothing more than a communication protocol to generally a shell interface on another Unix machine. The remote telnet daemon will most likely invoke authentication and shell processes so everything that you are requesting is yes, possible though you will thus require authentication.
As you know telnet for shell is primarily used internally inside secured networks and rarely on the 'net any longer.
Telnet is wrong protocol to do this kind of stuff. It is an (out-dated) protocol for interactive terminal sessions. You should be looking at "ssh" to execute commands on the remote machines, and then figuring out which commands you need to execute to extract the information of interest to you.
Some of the information you are after may also (in theory) be available using SNMP, but things like configuration files and application versions won't. The "ssh" approach will allow you to harvest any information that is available via commands run from the command line.
Injecting Java into the mix is almost certainly a bad idea. Java is best at tasks that are platform independent, but what you are trying to do is inherently platform specific.

Categories

Resources