I am working on web app with jquery, jqueryui, ajaxify and many jquery extensions.
At some point in the application I have to use Java applet.
The applet is run via ajax call, let's say jquery.load loads a page that generates applet code. I would like then to detect if Java is installed on the computer running the app, and if it is version 1.7+. The detection should occur only if applet is going to be used, since this functionality is to be used by limited number of users and only in certain circumstances.
I can't use deploy.js, as this script was not designed to be run via ajax call and simply fails.
I would like to detect java only when it it really needed, i.e. when user is going to launch the applet.
How can I do that?
I will appreciate your help.
You should use Java Deployment Toolkit in any case. When I need to some specific checks I open the java_deploy.js and see how this works. It not so hard to understand, really. For example, in Chrome it just inserts a specific tag with certaing uid. Nothing complicated. Then I just exec the code doing this manually.
At the end of deploy.js it just launch Java check after the page load. One method call. I've just removed this code and launch it manually in my own code.
Finally I found a way to detect if java is installed.
At first I tried with navigator.javaEnabled(), but it didn't work properly with IE.
Then I tried Java deployment toolkit, but didn't succeed due to window.write which was not compatible with pages fetched via ajax.
Then I tried to customize Java deployment toolkit following odiszapc advice ... but by the end of the day I used unmodified Java development toolkit, simply I used its versionCheck method.
If java is not detected, the user is told to download and install JRE, and link is provided.
If correct version of Java is installed then the subpage is reloaded via ajax with parameter javaOK=1. In such a case there is no java detection, just pure applet tags, in short:
$SuccessUrl = FileName . "?javaOK=1&" . $_SERVER['QUERY_STRING'];
(...)
$java_detect=EOQ (heredoc shoud be here, some tags don't work)
var version = '1.7'; //required version
var check = deployJava.versionCheck(version+"+"); //1.7 and higher
if(!check){
$("#sign_dialog").html("$java_err"); //wrong java or no java at all
}else{
$("#sign_dialog").load("$SuccessUrl");
}
EOQ;
(...)
if(isset($_GET['javaOK']) && $_GET['javaOK']=='1'){
echo $applet;
}else{
echo $java_detect;
}
Related
I have bumped into a weird problem in feature that works well on all other installations, but not for one particular client.
The "feature" involves an xpage with code in beforerenderrespons that picks up an uploaded file, gets filename etc and creates a context document. The context document is then passed as parameter to a java agent which process the file.
The java agent is set to Run as web user and has Allow restricted operations. As I said - it works in all installations at other clients, but fails all of sudden on one installation.
The only error message I get from beforerenderrespons event is "Error:Exception occurred calling method NotesAgent.runWithDocumentContext(lotus.domino.local.Document) null".
I have confirmed that the agent is found but it never gets called. I have also confirmed that the context document also exists.
The server console says nada.
I have tested calling the agent with different run methods as in agent.run() but it does not make a difference.
Now to the weird stuff - if I call a java agent that does not include a scriptlibrary it works! But as soon as I add a script library to the agent I get the error above.
Why is that? Any help or clue appreciated. It feels like I have missed a security setting somewhere.
The server doc includes the agent signer in "Sign agents to run on behalf of someone else", "Sign or run unrestricted methods and operations" and "Sign or run restricted LotusScript/Java agents"
edit:
Tested using a "pass-thru" agent that calls my original java agent that contains script libraries and that works! The pass-thru agent doesnt contain any scriptlibrary and simply calls my java agent and passes on the context document.
Even so - I still want to know why calling a java agent directy fails if it contains a script library.
/Katarina
One possiblity is the server version. That would explain why it works in some installations and not another. runWithDocumentContext() was only added in 8.5.2 http://blog.nashcom.de/nashcomblog.nsf/dx/passing-a-document-to-an-agent-without-saving-it-first.htm
Since your agent is Java anyway, you can save the trouble of spinning up a new class loader and jvm environment. Move the code into a jar and call it directly from the XPage.
I can't think of a good reason to use the agent (because it was there isn't a good reason in this case)
I have a Java applet embedded into a web page which generates a file that the user must download. I understand there is a way to do this by communicating with a Javascript API.
Could somebody please explain to me how to do it this particular way?
Javascript doesn't allow file saving just yet, and the hacks that "work" need modern browser that understands data URI:s. In that case you would simply send the binary data as base64 and make the browser navigate to the data URI by setting document.location.href = 'data:application/octet-stream...' The download prompt would look like this in firefox:
http://img824.imageshack.us/img824/5080/octetstream.png
Flash allows for real download/save dialogs though so you could also look into that... or find out if java applets have that too.
If the user can be expected to have (or be willing to upgrade to) a Plug-In 2 architecture JRE (e.g. Sun's 1.6.0_10+)1, it is possible to launch the applet using Java Web Start. When an app. is launched using JWS, it can access the JNLP API, that offers file services that allow even sand-boxed code to save information to the local file-system.
Here is a demo of the JNLP files services.
That is if the applet needs to be embedded. JWS could launch applets free-floating since it was introduced in 1.2.
IDEA: Implement a recent web browser into a java application (for saved offline, non server content).
The question is this: can I have a java application implement a webbrowser with jquery / html / css support within a java program?
So I am asking anyone who has played with JRex for advice: I want to know how complicated will it be to integrate an open source webbrowser into java. I am not all that keen on the idea of compiling Mozilla from source build. Is there a ready made compiled version?
Is there a simplified method to have latest compiled version (most current in terms of support for HTML css & javascript), and integrate that into an application?
Also: I appreciate the amount of work required to support for HTML4 nevermind 5, and CSS2 compliance. How close is JRex to that?
Application: My intention with the webbrowser is to render a webpage from offline content. It will not need to be online content, and will simply be for file based displays = e.g. file:///C:...
Does the webbrowser have to be wrapped into a server to function, e.g. to pass files to the browser to render is how complicated? I am not keen to have to implement Jetty or another server type application just for this.
If JRex is not the solution... what then? Is it possible to start a browser implementation within Java and can Java interact with the information and traverse the Dom?
Or alternatively is there .hta equivalent in recent browsers like firefox?
If you need to have the embedded browser interact with your application code, you could try the SWT Browser control, it's actually maintained as opposed to JRex. Browser uses either WebKit or Gecko or embedded IE as appropriate, or lets you choose which one you want, so it should run jQuery and familiar Javascript. And since SWT is a JNI library to begin with they probably already have guidance on how to deploy an app that uses JNI.
You can feed HTML into the control from a string (example) or a java Url - which can point to local files or resource files in your JAR, which I assume will let you split your app into different files.
To call Java code, you need to expose it as Javascript functions. example
To manipulate the HTML from Java code, you need to call Javascript functions from Java. example
To make the previous two tasks easier, you might want to look into a JSON library to simplify passing around complex data.
Does it have to be implemented within a Java program? Could you let the user use the default browser on their machine (ie does it matter what browser)?
If not would use the Java Desktop API.
if (desktop.isSupported(Desktop.Action.BROWSE)) {
txtBrowserURI.setEnabled(true);
btnLaunchBrowser.setEnabled(true);
}
If you are using Java 1.5 try http://javadesktop.org/articles/jdic/
I am newbie in wkhtmltopdf. I am wondering how to use wkhtmltopdf with my Dynamic Web Project in Eclipse? How to integrate wkhtmltopdf with my Java dynamic web application?
Is there any tutorials available for beginners of wkhtmltopdf ?
(Basically, I would like to use wkhtmltopdf in my web application so that when user click a save button , the current page will be saved to PDF file).
First, a technical note: Because you want to use wkhtmltopdf in a web project, if and when you deploy to a Linux server machine that you access via ssh (i.e. over the network), you will need to either use the patched Qt version, or run an X server, e.g. the dummy X server xvfb. (I don't know what happens if you deploy to a server running an operating system other than Linux.)
Second, it should be really quite simple to use wkhtmltopdf from any language in a web project.
If you just want to save the server-generated version of the current page, i.e. without any changes which might have been made like the user filling on forms, or Javascript adding new DOM elements, you just need to have an extra optional argument like ?generate=pdf on the end of your URL, which will cause that page to be generated as a PDF, and then the PDF button will link to that URL. This may be a lot of work to add to each page manually if you are just using simple JSP or something, but depending on which web framework you are using, the web framework may offer some help to implement the same action on every page, if you need to implement that.
To implement this approach, you would probably want to capture the response by wrapping the response object and overridding its getWriter() and getOutputStream() methods.
Another approach is to have a button "submit and generate PDF" which will generate the next page as a PDF. This might make more sense if you have a form the user needs to fill in - I don't know. It's a design decision really.
A third approach is to use Javascript to upload the current state of the page back to the server, and process that using wkhtmltopdf. This will work on any page. (This can even be used on any site, not just yours, if you make it a bookmarklet. Just an idea that occurred to me - it may not be a good idea.)
A fourth approach is, because wkhtmltopdf can fetch URLs, to pass the URL of your page instead of the contents of the page (which will only work if the request was a HTTP GET, or if it's equivalent to a HTTP GET on the same URL). This has some small amount of overhead over capturing your own response output, but it will probably be negligible. You will also very likely need to copy the cookie(s) into a cookie jar with this approach, since presumably your user might be logged in or have an implicit session.
So as you can see there are quite a lot of choices!
Now, the question remains: when your server has the necessary HTML, from any of the above approaches, how to feed it into wkhtmltopdf? This is pretty simple. You will need to spawn an external process using either Runtime.getRuntime().exec(), or the newer API called ProcessBuilder - see http://www.java-tips.org/java-se-tips/java.util/from-runtime.exec-to-processbuilder.html for a comparison. If you are smart about it you should be able to do this without needing to create any temporary files.
One of the wkhtmltopdf websites is currently down, but the main README is available here, which explains the command line arguments.
This is merely an outline answer which gives some pointers. If you need more details, let us know what specifically you need to know.
Additional info:
If you do end up trying to call wkhtmltopdf in an external process from java (or for that matter, any language), please note that the "normal" output that you see when using wkhtmltopdf from the command line (i.e. what you would expect to see in STDOUT) is not not in STDOUT but in STDERR. I raised this issue in the project page
http://code.google.com/p/wkhtmltopdf/issues/detail?id=825
and was replied that this is by design because wkhtmltopdf supports giving the actual pdf output in STDOUT. Please see the link for more details and java code.
java-wkhtmltopdf-wrapper provides an easy API for using wkhtmltopdf in Java.
It also works out-of-the-box on a headless server with xvfb.
E.g., on a Ubuntu or Debian server:
aptitude install wkhtmltopdf xvfb
Then in Java:
Pdf pdf = new Pdf();
pdf.addPage("http://www.google.com", PageType.url);
pdf.saveAs("output.pdf");
See the examples on their Github page for more options.
I have an ASP .NET website that hosts a Java applet. The Java applet requires version 1.6 Update 11 of the Java runtime.
How can I detect that a client has the appropriate runtime installed so that I can display an informative message if they do not?
Thanks,
Carl.
EDIT: The solution must be platform independant.
This page describes how to and lists some plugins that will allow you to detect Java with JavaScript: http://www.pinlady.net/PluginDetect/JavaDetect.htm
Other than that, try out this snippet as well:
if (navigator.javaEnabled()) {
//Java is enabled
}
The link below details on the deployment tips for java apps.
http://java.sun.com/javase/6/docs/technotes/guides/jweb/deployment_advice.html
Quoting from the link
Deployment Toolkit
To avoid browser compatibility issues, the Deployment Toolkit (deployJava.js) provides JavaScript functions that automatically generate HTML required to deploy applets and Java Web Start applications. Developers should invoke these functions to deploy their solutions in a consistent fashion across various browsers.
My approach would be to use the JavaScript navigator.javaEnabled() to check if there is some Java version available.
Then you can use System.getProperty("java.version") from within a Java applet itself. That should be enough to get you the version information, such as 1.6.0_03.
Although most of the answers so far are all around detection on the user agent (browser) itself, it sounds like from your mention of ASP.NET that you'd like to make this detection happen on the server-side. If so, you have a couple of options.
First you can sniff the HTTP request headers coming from the user agent. A computer and browser with Java installed will usually include a header providing a hint of this to the server that you can pick up on. Here are some useful links on this approach:
http://www.developershome.com/wap/detection/
https://metacpan.org/pod/HTTP::Browscap
The other option you have is to send down javascript to the user agent to perform the detection using one of the techniques in the other answers in this question and then use ajax callbacks to tell the server what you discovered.
If you don't mind using a basic java applet that requires a much older version to run, you could use this article and continue based on that result.
Maybe this script will help. This is Windows-only, though.
<script language='javascript' type='text/javascript'>
var javaVersion;
var shell;
try
{
// Create WSH(WindowsScriptHost) shell, available on Windows only
shell = new ActiveXObject("WScript.Shell");
if (shell != null)
{
// Read JRE version from Window Registry
try
{
javaVersion = shell.regRead("HKEY_LOCAL_MACHINE\\Software\\JavaSoft\\Java Runtime Environment\\");
}
catch(e)
{
// handle exceptions raised by 'shell.regRead(...)' here
// so that the outer try-catch block would receive only
// exceptions raised by 'shell = new ActiveXObject(...)'
alert('error reading registry');
}
}
}
catch(e)
{
// Creating ActiveX controls thru script is disabled
// in InternetExplorer security options
// To enable it:
// a. Go to the 'Tools --> Internet Options' menu
// b. Select the 'Security' tab
// c. Select zone (Internet/Intranet)
// d. Click the 'Custom Level..' button which will display the
// 'Security Settings' window.
// e. Enable the option 'Initialize and script ActiveX controls
// not marked as safe'
activeXDisabled = true;
}
// Check whether we got required (1.6) Java Plugin
if ( javaVersion != null && javaVersion.indexOf("1.6"))
{
pluginDetected = true;
alert('it is installed!')
}
if (pluginDetected)
{
// show applet page
}
else if (confirm("Java Plugin 1.6 not found"))
{
// show install page
alert('not found')
}
else
{
// show error page
alet('error')
}
</script>
If the solution must be platform independent. I'll exclude all solution provided by javascript.
You can write a very simple Applet which support by the oldish Classic VM. Let the applet detect the JRE version, and display messsage.
If you accept Javascript, you may also interest to this article which is about auto-installer for WebStart applications.
Use deployJava.js function getJREs() to build a dynamic page depending on the user's Java version.
Use http://cowwoc.blogspot.com/2008/12/tracking-java-versions-using-google.html to track the Java version being used by your web visitors using Google Analytics.
Bonus step: use the source-code from step 2 as an example of how step 1 should be implemented.
Just copy amd paste this code in your browser address bar!
Check if it is useful for you.
javascript: for(i = 0; i < navigator.plugins.length; i++) alert(navigator.plugins[i].name);
You need to obtain the position of Java in the plugins array and maybe you can check the versions with a regular expression or something. You could take a look to the plugin javascript object.
Regards!
check this
http://simple-java-detection-script.blogspot.com/2010/03/simple-browser-java-installed-or.html
The link below was the way I got it to work. It has a JS you can get which was made for Java deployment. The link was mentioned above, but I thought an example with it would be nice.
These are samples that I ended up needing to fix my problem.
http://download.oracle.com/docs/cd/E17409_01/javase/6/docs/technotes/guides/jweb/deployment_advice.html#deplToolkit
Once you have downloaded the deployJava.js file you could put something to make sure java is installed:
if (deployJava.getJREs().length > 0) {
//Your code to start java
}
Make sure a specific version is installed:
if (deployJava.versionCheck(version)) {
//Your version specific code
}
Start the installer of the latest Java:
deployJava.installLatestJava();
Or a specific version if you would like:
deployJava.installJRE(version);
Copy and paste into your browser address bar to check:
javascript:alert(navigator.javaEnabled())
Works in Mozilla (FF3) and IE7. (x64)