Changing java system property - Headless java - PJA

Is it possible to do this? I’m seeing if I can get the eteks PJA to work for headless java operation and one of the requirements is the following:

System.setProperty (“awt.toolkit”, “com.eteks.awt.PJAToolkit”);

This gives me an access denied violation.

I tried adding:

// Add permissions for PJA

permission java.util.PropertyPermission "java.awt.toolkit", "read, write";

to the java.policy file on the server but that didn’t help.

Is it possible, before I waste any more time?

I have the pja.jar in my JavaUserClasses too.

TIA, George :slight_smile:

Subject: Changing java system property - Headless java - PJA

And where are you doing this? application?, agent?, servlet?

Subject: RE: Changing java system property - Headless java - PJA

relates to this

http://www-10.lotus.com/ldd/nd6forum.nsf/DateAllThreadedweb/0695a012497f660f85256e2e004515fb?OpenDocument

Subject: RE: Changing java system property - Headless java - PJA

Give this a whirl on your system and see if it does the same thing if you have a moment. You’ll need to set your in and out paths for the icons obviously.

The call to create the graphics on the thumbImage crashes the server.

George :slight_smile:

import lotus.domino.*;

import java.io.BufferedOutputStream ;

import java.io.FileOutputStream ;

import java.io.FileInputStream ;

import java.awt.image.* ;

import java.awt.Image ;

import com.sun.image.codec.jpeg.*;

import com.eteks.awt.* ;

import com.eteks.java2d.* ;

import java.awt.Graphics2D ;

public class processImage extends AgentBase

{

// Get the file path variables from the constants library

String iconPath 							= 	StringConstants.ICON_PATH ; 

String slash								=   StringConstants.SLASH ; 		

String originals 							=   StringConstants.ORIGINALS ; 



public void NotesMain() 

{

	try 

	{

		System.out.println("System is using Java version " + System.getProperty("java.version"));			

    		   	

		String inPath = iconPath + slash +  originals +  slash + "Winter.jpg" ;

    	

    		JPEGImageDecoder decoder = JPEGCodec.createJPEGDecoder ( new FileInputStream ( inPath ) );

    		BufferedImage image = ( BufferedImage ) decoder.decodeAsBufferedImage ();

   		ColorModel cm = image.getColorModel ();

    		Raster raster = image.getRaster ();

    		SampleModel sm = raster.getSampleModel ();

    

    		DataBuffer buffy = (DataBufferInt) raster.getDataBuffer ();

    		int dt = buffy.getDataType ();

    		System.out.println ( "The raster's data type is " + dt );

    		System.out.println ( "It's data size is " + buffy.getDataTypeSize ( dt ) );

    

    		DataBufferInt buffer = (DataBufferInt) raster.getDataBuffer ();

    		int[] data = buffer.getData ();     

   		 // 1st thing: see if we can just write out the original image.

		DataBuffer resultBuffer = new DataBufferInt ( data, data.length );

        	WritableRaster resultRaster = Raster.createWritableRaster ( sm, resultBuffer, null );

        	PJABufferedImage thumbImage = new PJABufferedImage ( cm, resultRaster, false, null );

        	BufferedOutputStream out = new BufferedOutputStream ( new FileOutputStream ( iconPath + slash + "outImage.jpg" ) );

        	JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder ( out );

        	JPEGEncodeParam param = encoder.getDefaultJPEGEncodeParam ( thumbImage );

        	param.setQuality ( 1.0f, false);

       	encoder.setJPEGEncodeParam ( param );

       	encoder.encode ( thumbImage ) ;                                  

    

    		Graphics2D graphics2d = thumbImage.createGraphics() ; 



   		System.out.println ( "Done" ) ;

          		   

	} 

	catch(Exception e) 

	{

		e.printStackTrace();

	}

}

}

Subject: RE: Changing java system property - Headless java - PJA

It’s in an agent that executes on the server. I’ve been in the forum for PJA and am waiting on a a response - I’ve asked if it’s possible to use it without setting the system property - if not, and if you cannot set it in Domino then it’s a non starter.

I’d hoped you’d actually done it :slight_smile: I spent a few days trying to get it to work but to no avail and saw your message as a ray of hope. How are the mighty fallen :slight_smile:

Subject: Changing java system property - Headless java - PJA

You have to add:

permission java.util.PropertyPermission “awt.toolkit”, “read, write”;

to the java.policy file on the server.

I just tried your example agent, and although I am running on Windows it worked just fine.

Subject: RE: Changing java system property - Headless java - PJA

Thanks for that Kristjan - but it never falls over on Windows - have you got a linux server you could try it on?

Has anyone???

George :slight_smile:

Subject: RE: Changing java system property - Headless java - PJA

What kind of crash is this, does the whole linux server go down or just the notes server or are you talking about java stacktrace, what is the error?

Subject: RE: Changing java system property - Headless java - PJA

Crashes the linux server I have to reboot - can dig out the NSD if you know how to interpret them.

I’m going to run take a step back and run it in NetBeans, see if I can get any more information - whatever’s crashing the linux server may only throw an error in Netbeans and I’ll keep you posted.

Subject: RE: Changing java system property - Headless java - PJA

You have seriously piqued my interest here. Let me see if I have this straight. You have a headless Linux system, right? Do you mean just no monitor attached or headless in a more encompassing sense (ie. no X, etc). And then you are trying to replace the AWT system with this PJA system (with which I am unfamiliar). In terms of the crash, it doesn’t actually crash until some time after you change the system property, correct? An exact copy of the fatal stack in the NSD would be helpful.

In general, it is usually a very bad idea to change any of the core system properties after the JVM has already started. Usually, the system properties you see are just reflective of the the true underlying values and are not themselves what is keyed on. Some are, however, and changing such a property after a subsystem has already initialized can have unexpected consequences, like crashes, etc.

Can you give us a better idea of what you are trying to accomplish?

Joseph Millar

Principal Software Engineer

Brightline Technology

Subject: RE: Changing java system property - Headless java - PJA

Certainly Joseph. It’s all turned out to be a red herring slightly, albeit an interesting one. I’ve now found a way to do this with JIMI, as suggested by the guy who wrote PJA.

If you go back to

http://www-10.lotus.com/ldd/nd6forum.nsf/DateAllThreadedweb/0695a012497f660f85256e2e004515fb?OpenDocument

What I’m doing is this. Users choose a JPEG from their own file system, I force the user to rename it to something sensible, post/save it, extract it to the Linux file system, pick it up, create a thumbnail, create a full size image of the desired size, post back to the user to show them the results. All was fine in Windows then I tranferred dev to Linux.

You’ll see where the discussion began but the long story short is that the Linux box is running headless, no X so no libraries that the JVM needs for processing 2D graphics are available. Domino /is/ running in a console, no X is loaded.

So, I did fiddle with PJA for a bit, you modify the java.policy file to allow awt.toolkit to be read/write and then set the property to point at the eteks PJA solution, which doesn’t use the overlying system’s graphics, it renders graphics ‘pure’ using native java and Brasenham algorithms. Well, you would, wouldn’t you :slight_smile:

Also modified the notes.ini to include the pja.jar file and made the output verbose so I could see what’s going on. I can see that PJA is being used in the verbose output. There comes a point in the code where you call createGraphics(), and this is where is crashes.

It’s totally reproducible but the JIMI way is vastly superior. All you need is the X11 libraries to be loaded on the server, no X is needed to run and no modifications are required to the java.policy file or notes.ini. I merely added JIMI.zip or whatever it’s called to the project for the agent in use.

Subject: RE: Changing java system property - Headless java - PJA

Well, I’m glad you found a solution. Replacing the JVM’s AWT subsystem is a dangerous thing, especially after startup, I’m sure that some path is still trying to use the JVM’s original installed AWT toolkit and that’s what is leading to the crash.

As an alternative to JIMI, why not just run X? It’s hardly a strain on your system, and if it is, then the system is very likely marginal in the first place, I know this probably offends Unix purists ;-), but let’s face it, it’s a GUI world out there for the most part. And you need the X libraries to be installed anyway. Running headless doesn’t necessarily preclude running X.

But whatever suits your needs is all that counts, I guess.

Joseph Millar

Principal Software Engineer

Brightline Technology

Subject: RE: Changing java system property - Headless java - PJA

It’s the Unix purist in me too. Ridiculous overhead, graphics :slight_smile:

No, this app is to be commercially hosted and they don’t run X on the server. I like the JIMI solution, it’s quick and easy and is two lines of code.

Thanks for your interest though, and hopefully my postings will help someone, I noticed there was virtually nothing about such matters on the forum, and I cannot be the only person who wants to process images in this way.

George :slight_smile:

Subject: RE: Changing java system property - Headless java - PJA

hehe…ok, then JIMI is your answer. Others may decide to just run X. It’s good to have choices.

Joseph Millar

Principal Software Engineer

Brightline Technology