I have a website that implements a JavaScript that generates some messages elements.
I would like to write a Java program that will read from this messages once they will generate. Is this possible to do?
Yes. You can use HtmlUnit.
It has fairly good JavaScript support (which is constantly improving)
and is able to work even with quite complex AJAX libraries, simulating
either Firefox or Internet Explorer depending on the configuration you
want to use.
Related
I have a project that is built on Applets and that also comprises of Corba calls to backend (which is in C language). Now I need to remove Applets and convert it into JSP and Javascript combination. But the code seems to be complex as it also consist of backend calls. I am facing problem in figuring out what is to be converted in JSP and what in Javascript.
If I convert all the applet logic in Javascript, how will I pass the javascript data to the Java objects to pass it as input for corba calls.
I can't implement all the logic in JSP as the existing logic depends on the dynamic change of data by user.
I tried various links but couldn't find the proper solution to my problem.
I read somewhere that Google Web Toolkit (GWT) might help me converting Java Logic to Javascript, but couldn't figure out what exactly needs to be done for that.
Can anyone guide me how should I start and what exactly should I do to complete my project?
First the bad news. There is no generic and magic solution that can convert your legacy (as you are describing it) into modern n-tiers web application.
I can suggest you the following steps.
decide what kind of client and server side technologies you are going to use and learn them to become familiar enough to start coding.
learn your legacy code and re-design it. Decide which parts of the code must be re-written, what you can use as-is and what you have to change and/or re-package.
To choose client side technology try to search for "client side javascript frameworks" or something like this. Popularity of GWT that you mentioned is going down now. The most modern framework these days are AngularJS.
Concerning server side technologies I personally prefer Spring but you can take a look on Guice and EJB too. You can also implement whole server side as as collection of servlets. It is up to you.
Start learning this amazing world and come back with more concrete questions. Good luck.
I'm trying to get java and javascript to talk to each other. Ideally, I would want them to share objects, but it would be enough that a java-application calls a javascript function. I've tried Rhino but struggle a bit, because it doesn't seem able to call functions in a running js-engine (maybe it can I just couldn't figure out how?). Any tips on how to make this link happen? Performance is an issue but not extremely critical.
Basically; I have a web application that uses javascript to update the content of the page dynamically. The content of the page is created through java-code, so I need a way for the java-code to tell the javascript when something changes and what changes.
Thanks
LiveConnect seems to do the trick, but applet would be a security-leak. Would Nashorn in Java8 do the same as Rhino or will it be able to keep a running JVM and listen to calls?
There's no way to make the Java back end and JavaScript talk directly to each other the way you imply you want to do. The only way to make them communicate is through AJAX or WebSockets.
I know there are multiple Java API to interface with MS Exchange, but it seems to me that no one that offers methods for mailbox creation. Does anyone know a way to do this?
I believe that you can do it using HtmlUnit API.
HtmlUnit is a "GUI-Less browser for Java programs". It models HTML
documents and provides an API that allows you to invoke pages, fill
out forms, click links, etc... just like you do in your "normal"
browser.
It has fairly good JavaScript support (which is constantly improving)
and is able to work even with quite complex AJAX libraries, simulating
either Firefox or Internet Explorer depending on the configuration you
want to use.
It is typically used for testing purposes or to retrieve information
from web sites.
I'm not a java programmer (I come from asp.net c#) but I'm considering writing a small java application to upload files. In my web app, the user needs to upload a spreadsheet to my server and I want to check the file size and extension before the upload. Most uploader seems overly bloated for what I'm looking to do and I want to build something really simple.
What do I need to do to make this? Eclipse seems to be the best IDE for java. What else do I need and how difficult would it be to write an uploader?
Thanks.
I don't want to steer you away from Java, but you should be able to check file size and extension with javascript. That should only be a dozen or less lines of javascript and should be pretty fast (runtime) since an applet doesn't have to load.
I've been working on REST java ee webservices using Jersey (jax-rs). These allow you to define custom paths, accept and return types (ie text/xml, multipart, etc), methods (GET,POST,etc) and be just about has finely grained as you would like. I haven't done anything with file upload, but I found an example here to get you started. Jersey is a stable, growing, highly-extensible framework (did I mention it supports MVC) and that's why I'm suggesting that you adopt it. Here is a tutorial to get you started with jax-rs, and of course there's always the project site for reference.
Hope this helps.
Thinking outside of the box here...
What possible basic approaches could be taken in an effort to create a Flex component that could run Java?
I know I can easily use flex to browse to or launch a Java app, but there are things I can only do if I can run the Java from WITHIN an MXML Component.
I the strictest sense, I know it's not impossible (ie: if you had all the source code for flex and for the jvm), but what's the least impractical means to this end?
Edit:
Lots of people are interested in the reason WHY someone might want to do this. I see it as irrelevant to HOW to do it, but here goes: I have over 100 proprietary pixel-reading windows programs that I could port to Mac in this way, much easier than any other way. But instead of arguing the premises, the winning answer will ignore the reasons why, and focus on the HOW.
Showcase your creativity.
This sounds crazy insane to me. My answer is to not go down this route. It may be a fun technical challenge for fun; but has little practical value that I can see.
Answer the question, Why would you want to run a JVM inside a Flex app?
Also, How would you use a Flex App to browse or launch a Java App? As best I understood, the security sandbox of the browser prevents you from launching other local applications.
I don't believe you are correct about not being able to accomplish certain things you "can only do if I can run the Java from WITHIN an MXML Component". With proper communication set up, you can have the Applet and the SWF simply communicating with each other through an external set of processes.
The easiest way to accomplish this is to "fake it". Load a Java Applet (This should be possible by use of the SWF's ExternalInterface API -- generate the Object tag and add it to the HTML around the swf. To make this even more convincing, use CSS to have to Applet appear "on top" of the swf. ) and have it communicate with the original swf through JavaScript calls. If that is not possible, then it may be possible to have the Java Applet generate some form of pseudo-server which the swf could then communicate with.
If neither of those work, then there is always the SWF bytearray syntax. It would need to load a ByteArray, manipulate the internal data, and then send it... somehow.
A while back I prototyped something like this. I exposed a window / native app via a VNC server and then used an open source VNC client library to connect to the VNC server. It was totally hacky but it worked. Performance was not great but was usable. Here is the Flash VNC client library I used:
http://www.wizhelp.com/flashlight-vnc/index.html
I'm with Flextras, you need to explain why before a reasonable solution can be proposed.
Unreasonable solution:
Implement the jvm in AS3. Read jars in as bytearrays. Pass the bytearrays to you new jvm.
Reasons for unreasonableness:
Implementing even a partial jvm would be at least thousands of man hours of work.
Running a virtual machine inside of Flash's already (relatively) slow vm would be like riding a golf cart that's being towed by a tortoise: either one by itself would be faster.
You can interface between Air & a Java app using merapi (although that's just communication, not actually running the api inside air)