Hi!
Here is a short description of my situation :- I need to add a line of text ( A signature) to a Word document( downloaded from a server) at the end of a range. I am able to do this correctly as a standalone application. But the actual functionality needs to be invoked from an applet( I do not have any security issues, since i have signed the applet). This method runs in a separate thread that is spawned from the main applet's init method : Here is the code for the same -
class ESignThread extends Thread
{
@Override
public void run()
{
synchronized(_threadLockES)
{
while( true )
{
try
{
_threadLockES.wait();
String durl=url+"download_doc.php?filename="+_launchPathES;
String tmpDir = "Undefined";
tmpDir = System.getProperty("java.io.tmpdir");
File tmpEs = new File(tmpDir+"Esd");
tmpEs.mkdir();
BufferedInputStream in = new BufferedInputStream(new java.net.URL(durl).openStream());
FileOutputStream fos = new FileOutputStream(tmpDir+_launchPathES);
BufferedOutputStream bout = new BufferedOutputStream(fos,1024);
InputStream input = new FileInputStream(new File(tmpDir+_launchPathES));
OutputStream op = new FileOutputStream(new File(tmpEs+"\\"+_launchPathES));
File EsignedFile = new File(tmpEs+"\\"+_launchPathES);
byte data[] = new byte[1024];
while(in.read(data,0,1024)>=0)
{
bout.write(data);
}
bout.close();
in.close();
HWPFDocument testWord = new HWPFDocument(input);
org.apache.poi.hwpf.usermodel.Range r = testWord.getRange();
String DATE_FORMAT_NOW = "yyyy-MM-dd HH:mm:ss";
String TimeNow=null;
Calendar cal = Calendar.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT_NOW);
TimeNow=sdf.format(cal.getTime());
System.out.println(testWord.characterLength());
r.insertAfter("\r\n This document has been Electronically Signed by Erica Green, MD on " +TimeNow +"." );
System.out.println(testWord.characterLength());
testWord.write(op);
input.close();
op.close();
upLoad(EsignedFile) ;
}
catch( Exception ex )
{
System.out.println( "Exception in E-Sign Thread " + ex.getMessage() );
}
}
}
}
}
What I am actually doing is downloading the file from a server(using PHP), writing it to a output stream. Then associating it with a File object( and an input stream), creating a HWPF document, getting the range and using the insertAfter() function, and then writing it out to a different location. This seems to be working just fine when i run it outside the applet. But when i put it in the applet and invoke the corresponding functionality , I get the following stack - trace on the applet console :
Exception in thread "Thread-17" java.lang.NoClassDefFoundError: org/apache/poi/POIDocument
at java.lang.ClassLoader.defineClass1(Native Method)...
at java.security.SecureClassLoader.defineClass(Unknown Source)
at sun.plugin2.applet.Applet2ClassLoader.findClass(Unknown Source)...
at CbayThreadApplet$ESignThread.run(CbayThreadApplet.java:850)
Caused by: java.lang.ClassNotFoundException: org.apache.poi.POIDocument
at sun.plugin2.applet.Applet2ClassLoader.findClass(Unknown Source)
... 8 more
Caused by: java.io.IOException: open HTTP connection failed:http://devscribe/ascendum/org/apache/poi/POIDocument.class
at sun.plugin2.applet.Applet2ClassLoader.getBytes(Unknown Source)...
at java.security.AccessController.doPrivileged(Native Method)
... 12 more
It seems to suggest that the applet cannot find the POI classess. Could you please tell me how i can overcome this problem? I have tried putting the POI jar files on the server/ within the applet( jar) - but to no avail.
Any suggestions please?