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.
Related
As node.js still lacks important functionality which exists in Java, I would like to use Java instead of node.js, and create the client using a web language (html, js, css..).
Electron is cross platform and so does java so it seems fit to have a solution getting the best of both worlds.
Does someone know of a way to integrate electron with java or have a different solution to the problem?
I made something similar, Java back-end with Electron GUI.
You can do it in more ways, it depends on what you need.
You can create a jar file and then execute it like terminal:
https://nodejs.org/api/child_process.html
Or you can open a socket communication and talk on a Port. (A lot of documentation:
Java (web)socket - Node.js client.io)
In this second way, you can do everything you want, but you have to create your communication protocol.
Your path is not foolish, I am very satisfied of the communication and usage in my work with Java + Electron .
I've created a small PoC where Java process is integrated with Electron front-end: https://github.com/jreznot/electron-java-app There you will find a simple TODO List application built with Vaadin/Jetty and Electron.
Personally i made my back-end java communicate with the front-end by creating a file with te data then sending it to the main.js to be processed.
DBus and winDbus seems to be an option here.
It creates nice abstraction and separation between "frontend" and backend
https://sourceforge.net/projects/windbus/
I'm going to test it on my own soon
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.
I have created a java app and I would like to be able to execute actions in this app by calling some custom urls (ex: myapp://do_this)
I have already searched for this, and I have found some information about handling such urls in java (URLStreamHandler).
The only part I'm missing, is how to tell the OS to redirect the "myapp://" protocol to my application.
More and more apps are defining their own protocol and I was wondering whether it was possible to create such kind of things in Java.
Thanks
The protocol in URLStreamHandler will be used inside of the jvm. Typical usage is something like res://... for resources. The OS and the browsers have their own sets of protocols (ftp, mailto).
You could probably extend Firefox with a plugin to handle your protocol.
But then you have to send that to your app, running as a small "web" server.
Forget for a moment URLStreamHandler.
Embed the Jetty web server in your app, say on port 8765, and write a servlet to handle your URLs. Then you can in your browser type "http://localhost:8765/do_this". Should suffice.
To add a new protocol, one needs to implement an XPCOM component. Since XPCOM allows programming languages to talk to eachother, XPCOM components can be implemented in C++ or JavaScript currently in Mozilla.
http://www.nexgenmedia.net/docs/protocol/ will help you to understand more.
i think this is what you want.
As others have said, getting browsers to understand a new protocol name is browser (and OS) specific - you can't do it from the server.
However, would Java Web Start ( http://download.oracle.com/javase/tutorial/deployment/webstart/ ) fit your requirements? Most browsers are already set up to handle JWS applications correctly.
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.
I want to write an application that runs entirely locally on one machine - there is no need for connection to the internet or to any external machines.
I was thinking that it would be a good idea to use a web browser as the platform for this application so that I would not have to mess around with lots of UI stuff - I could just knock together the web pages fairly quickly and take advantage of CSS to get consistent styles throughout the application.
However I want to interact with a MYSQL database on the machine in question. With this in mind I was thinking that I could somehow use Java to process the information that the user inputs from the application and communicate it to the database via JDBC.
I know that I could use an applet to do this but the downside to that is that I would like the user to be able to save files to the local machine - and I have read that applets run in a sandbox which prevents them from gaining any access to the local machine.
I also know that I could use PHP but I would like to take advantage of object oriented design which Java is perfect for.
Does anyone have any thoughts, suggestions or links to tutorials/webpages which could help me to decide how best to go about this.
Any thoughts are very much appreciated..
I know you said you don't want to mess around with GUI stuff in java, but have you looked in to java web start? It does almost exactly what you need; a user clicks a link through a web browser and your application is deployed on their machine, it even checks to make sure the right JVM is used. Because it is a full application and not an applet, your app won't be sandboxed, and you don't have any access restrictions in your program (other than the normal java stuff..), and for example, it would be easy to do what you mentioned and talk to a mySQL DB. The only downside, is what I mentioned earlier, is that you would have to design a UI in java.
Web Start Wikipedia Page
Sun FAQ on Web Start
Grails may be a useful starting point. It'll provide you with a web server solution that's standalone, and it'll look after the JDBC requirements and the CRUD (create-read-update-delete) capability via dynamically generated web pages. It should take minimal effort to put together an app providing your database interfacing via web pages.
(fyi. Grails is the Java equivalent of Rails)
If you feel comfortable with Java EE-based web development, you could probably just bundle your application with Tomcat or Jetty.
If you do not want to run standalone servlet container just for one application, you can also embed Jetty into a runnable Java application (see documentation here).
Either way you can leverage existing Java EE frameworks (Spring JDBC, Hibernate, all those web frameworks) for abstracting away technical complexities, although with embedded Jetty, you'd probably need to write some kind of integration layer for the web application framework of your choice.
I think you should give Restlet, a lightweight rest framework a try. The tutorial shows you how to start a local webserver, and by that deliver a "Hello World" through the browser within minutes (no joke!), and there's plenty of extensions for any kind of need.
In combination with Java Web Start by which you can deploy and start the application to the local host this should be what you need.
as someone suggested already you can use embbeded jetty server on your application and just let your user to start it using somekind of shell script or batch script. You only need to make your layour directory complaint with a Java Web Application and your on it. ie:
MyApplication
app/
WEB-INF/
lib/
classes/
web.xml
start.bat |
start.cmd - depends on your client OS
start.sh |
Then you should only need to take care of launching Jetty in your start.[bat|cmd|sh] with your app as your webaplication context and your done!
Using JDBC doesn't mean that you have to write an applet, you can use JDBC in any kind of application: a desktop application, a web application, EJBs, MDBs, etc.
You want to use a browser and Java on the server side? Then go for it and use Servlets / JSPs. Consider maybe using an presentation framework (Wicket, Struts2, Spring MVC,...), Hibernate for data access and Spring for other facilities and wiring. Grails is a good idea too.
BTW, I'm not a PHP specialist but PHP has object-oriented capabilities (introduced in PHP4 , enhanced in PHP5) so you won't sacrifice everything if you choose PHP.
So it really depends of what you want to do. If you want to write some Java (webapp or desktop app): choose Java. If you want to put quickly a few web pages in place and have an apache server, choose PHP. If you look for really high productivity, go for RoR or Grails.
You can try GWT + Google Gears
GWT is a GUI toolkit similar to Swing for the browser. Google Gears is a browser side database. Your app is completely in Javascript in a single HTML file and cross-browser compatible.
GWT app can make Server calls and Gears can sync up with a Server database. So you need not restrict your app data completely to the local desktop.
If you're interested in some experimentation, like new stuff and would like to reuse the plethora of Java libs (including JDBC) then you might be interested in the lift web framework, which is Scala-based.
If you want to do it as an applet you can. Sign the applet and give it permissions to the local network (to connect to the MYSQL server that way)... that should be possible. Here is a tutorial on it.