xpage calling Java agent fails when script library is included in agent - java

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)

Related

How do I find out which libraries a Java program uses on start-up?

Trying to debug a Java based program that works on one machine with Ubuntu 16.04 and not the other one (same OS). Is there a way that I can find out what programs/libraries are called upon starting this Java program? In other words, I think I am missing a file/library on one machine that is causes the Java program to crash. Is this called a backtrace?
You have two versions of the same jar library, or multiple libraries.
For example, you have bla‌​st2go.old.jar version and bla‌​st2go.new.jar version.
Class B2GPluginInitializer from a bla‌​st2go.new.jar creates object of UserInfo calling its constructor.
But, unfortunately, class loader loads UserInfo from bla‌​st2go.old.jar, not from bla‌​st2go.new.jar, as it should.
So, to check path to the incorrect library you can use the code below.
You can do this check somewhere in the code before exception
URL url = Thread.currentThread().getContextClassLoader()
.getResource("com/biobam/blast2go/api/user/UserInfo.class");
System.out.println(url);
The second step is check the class B2GPluginInitializer from which a constructor is called.

Using itext/xfaworker from IBM Notes/Domino via LS2J

I have used itext in the past where I have created a Java library with a class using the iText jars. This has worked perfectly in the past.
I now have some PDF's the gets corrupted when using setFormFlattening(true), therefor I have tried using the XFAFlattener, and this one works fine.
My problem is that I now need to load a license file via LicenseKey.loadLicenseFile and this works fine if I use my Java class from a Java agent. But if I try to use my Java class form a LotusScript agent, I get an "Certificate not found" error when LicenseKey.loadLicenseFile is called.
I can see that there is a itext.cer certificate inside the itext-licensekey-1.0.3.jar file. I guess it is this certificate that can't be found when running from a LotusScript agent.
Anyone knows how to get this to work?, maybe someone with deep iText knowledge know how this certificate is being loaded from the iText LicenceKey code, and can figure out what the problem can be.
There is no way to read a resource file in Java code if Java code is executed by LS2J.
As a workaround in my LS2J projects, I put the file content into a constant as base64 string and read this instead of resource file.
Another way is to put the code into an Java agent and to call the agent from LotusScript. This way Java code works as expected. Use an in-memory-document to "communicate" between LotusScript and Java.

How to detect Java and its version in AJAX app

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;
}

Java codes for USB

I want to create a program using Java for Automatically copied USB's data when it's insert to machine. How I do it?
There is no such thing as "USBs data", the very concept doesn't exist.
There is nothing specific in Java SE for do this job.
I may think of two ways to get that working:
Write a Java program that starts on boot (maybe a service), the prog scans continously available "drives" (D:,E:,F: ... in Windows, mount on Linux), the USB flash may be marked with a specific folder/file name (eg. COPY_USB_). That can be done with the File class.
Write a Java program that get invoked on plug-in. I know that can be done on Linux with hotplug-script support.

applet fails to load class from jar

Some users are complaining that the applet no longer works, When they view the java console they are greeted with a java.lang.noClassDefFoundError and checking my access log's I see they have downloaded the jar file that contains the class, and then issue a get request for the particular class.
Different users break on different classes.
Some users are fine.
Any ideas what could cause this/fix this.
I have checked to make sure the file is in their java cache, cleared the cache etc. nothing seems to fix them.
If they hit a qa site it breaks as well.
The jar is getting corrupted in transit, We are looking at getting patches from oracle/bea for the server.
It appears that if a connection is too slow (Modem speeds) that weblogic will signal the end of a transfer by sending a packet with len=0.
The network will signal java saying the download completed successfully and then java fails with a java.lang.noClassDefFoundError.
This can occur if the class itself can be loaded but some dependency of that class cannot be. Are there external JARs that are dependencies?
Are you sure the jar file contains all the necessary classes? Open it up in your favorite Zip application and double check. Maybe a recent build of that jar got messed up and doesn't have everything in it.
I'm assuming that you have made some updates by your wording. It is highly likely that some users have a previous Jar file cached.
When deploying a new applet version in a live configuration I perform the following:
Ensure the page holding the applet is not cached - use HTTP no-caching techniques. You may want to redeploy from a new page with these headers to ensure that it's not the case.
Deploy the jar file from a different URL for each update (I encode the version number in a directory, but you can equally rename the jar file).
If applet performs any client server interaction ensure that you check version numbers and report incorrect version to the user.
Even if you follow this the user may still have a problem, ask them to try these one at a time (listed in order they should try):
Press refresh on the browser window.
Restart all browser windows
Uninstall all Java VMs found on "Add/Remove programmes" and reinstall latest Java (yes, they must do this at their own risk!)

Categories

Resources