Custom Java Process Help

If you have questions or if you want to share your opinion about Aware IM post your message on this forum
Post Reply
Bryan
Posts: 195
Joined: Fri Apr 03, 2009 12:46 am
Location: Cincy

Custom Java Process Help

Post by Bryan »

All,
I am in the process of developing my first Java plug in for AwareIM, my question is does any body have an example of a BSV that uses a external jar file. I am just looking for something simple that can steer me in the right direction. Also, is there anything I need to know that is not included in the Programmer's Reference?

Thanks for any and all assistance.
-Bryan
Version 8 (Build 2358)
BobK
Posts: 546
Joined: Thu Jan 31, 2008 2:14 pm
Location: Cincinnati, Ohio, USA

Post by BobK »

Bryan,

I have successfully implemented a Java plug in for AwareIM.

I don't think the jar file is saved in the bsv, so I don't know how helpful a sample bsv would be.

If you have any specific questions, I would be glad to try to answer them.
Bob
Bryan
Posts: 195
Joined: Fri Apr 03, 2009 12:46 am
Location: Cincy

Post by Bryan »

Bob,
Thanks for the reply.

I have a basic jar file that I would like to implement as a test but I am not sure that I have covered everything in the programmers references because I am new to Java. I coded in VB & .Net for years. Anyway I am looking for an example of a jar file used from within AwareIM as well as a simple java project file if possible to see how they reference each other.

Thanks again for the response.
-Bryan
Version 8 (Build 2358)
BobK
Posts: 546
Joined: Thu Jan 31, 2008 2:14 pm
Location: Cincinnati, Ohio, USA

Post by BobK »

Bryan,

My plugin implemented a function. If you are trying to implement a custom process or channel, I am not sure how much, if any, of the following will apply.


If you already have a jar file, here is what to do:

1) Move the jar file to AwareIM\Tomcat\shared\lib
2) (From page 6 of Programmers Reference) Specify the jar file in the CLASSPATH in AwareIM\bin\setenv.bat and AwareIM\bin\setenvClient.bat. If your using Linux, the previous files would have a sh extension instead of bat.
2A) To specify the jar file in the CLASSPATH, open the above files with you favorite editor.
2B) Find the line that starts with: SET CLASSPATH
2C) Add the following to the end of that line: %AWARE_HOME%\YourJarFile.jar;
3) (From page 50 of Programmers Reference) Add a definition of your new function to the AwareIM\bin\BASServer.props file.
3A) To add your definition, open BASServer.props with your favorite editor.
3B) at the bottom of the file, on a new line, add the following: FunctionLibraryYourFunction=com.yourpackage.yourfunciton
3C) NOTES: the FunctionLibrary prefix is required as is. YourFunction can be anything. com.yourpackage.yourfunction will be based on how your jar file is set up.

If all of the above is done correctly, your new function will now appear in AwareIM's list of functions and can be used in rules and processes.

Hope this helps.
Bob
Bryan
Posts: 195
Joined: Fri Apr 03, 2009 12:46 am
Location: Cincy

Post by Bryan »

Bob,
Thank you so much. I will give it a shot and let you know the results.
-Bryan
Version 8 (Build 2358)
Bryan
Posts: 195
Joined: Fri Apr 03, 2009 12:46 am
Location: Cincy

Post by Bryan »

All,
Thanks to Bob I was able to get custom functions to work properly within the application. What an awesome way to expand the abilities of an already robust application.

I do however still need a bit of guidance with custom processes.

I have a custom process that should open a pdf file stored locally (see code below). The issue I am running into is that every time the process is triggered I receive the following error message. "Process implementation component com.userguide.plugin is not found or has invalid format"

Here is the code for the process. I copied the process example from the Programmer's Reference and changed the execute procedure to open the pdf file.

___________________________________________________________
package com.userguide.plugin;

import com.bas.basserver.executionengine.ExecutionException;
import com.bas.basserver.executionengine.IExecutionEngine;
import com.bas.basserver.executionengine.SuspendProcessException;
import com.bas.connectionserver.server.AccessDeniedException;

public class GuideClass {

public GuideClass()
{
}

//@see com.bas.basserver.executionengine.IProcess#cancel()
public boolean cancel()
{
return true;
}

//@see com.bas.basserver.executionengine.IProcess#execute(com.bas.basserver.exe cutionengine.IExecutionEngine, java.lang.Object[])
public Object execute (IExecutionEngine engine, Object [] parameters)
throws SuspendProcessException, ExecutionException, AccessDeniedException
{
try
{
Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + "c:\\User Guide.pdf"); //open the file chart.pdf
return null;
}
catch (Exception e)
{}

return null;
}

//@see com.bas.basserver.executionengine.IProcess#resume(com.bas.basserver.executionengine.IExecutionEngine, java.lang.Object)
public Object resume (IExecutionEngine engine, Object reply)
throws SuspendProcessException, ExecutionException, AccessDeniedException
{
return null;
}
}
___________________________________________________________

The jar file was assembled using the following convention.
Again, Thank you Bob.

********************
The first line in AwarePlugin.java is: package com.sample.plugin;
This basically means that the program is in the following directory structure: com\sample\plugin.
To compile this, while in the parent directory of com, execute
c:\awareim\jdk\bin\javac -classpath c:\awareim\Tomcat\shared\lib\awareim.jar com/sample/plugin/AwarePlugin.java
c:\awareim\jdk\bin\javac is the java compiler that comes with aware. I use this to make sure it is compiled with the version of java aware expects.
-classpath c:\awareim\Tomcat\shared\lib\awareim.jar is pointing to some Aware functions that the program needs.
com/sample/plugin/AwarePlugin.java is the program being compiled.

To create the jar file, from the parent directory of com, execute
c:\sun\sdk\jdk\bin\jar cvf sample.jar com
c:\sun\sdk\jdk\bin\jar is where my version of jar.exe is located. jar.exe does not come with Aware so you have to use your own. It does not appear to matter what version of the jar.exe you use.
cvf sample.jar are options for jar.exe. c - create a new jar file. v - generate verbose output. f sample.jar - specifies the file name for the jar file.
com is the directory and all sub-directories to be put into the jar.

********************

Within the configuration tool I created a process that simply has the Custom Software Component Radio button selected with a value of com.userguide.plugin

Thanks for any assistance.
-Bryan
Version 8 (Build 2358)
BobK
Posts: 546
Joined: Thu Jan 31, 2008 2:14 pm
Location: Cincinnati, Ohio, USA

Post by BobK »

Bryan,

Here are a couple of suggestions:

1) Try changing the value in the configuration tool to com.userguide.plugin.GuideClass

2) In your java code your class needs to implement IProcess.
Change
public class GuideClass {
to
public class GuideClass implements IProcess {

Hope that helps
Bob
Bryan
Posts: 195
Joined: Fri Apr 03, 2009 12:46 am
Location: Cincy

Post by Bryan »

Bob,
Firstly - Thank again for the assistance.

Prior to changing the code and after changing the code in the jar file I tried to see if changing the value in the configuration tool made a difference.

Old Value = com.userguide.plugin

New Value = com.userguide.plugin.GuideClass

Unfortunately neither one worked before or after adding the implements IProcess piece of the code.

Below is the current code
*___________________________________________________________*
package com.userguide.plugin;

import com.bas.basserver.executionengine.ExecutionException;
import com.bas.basserver.executionengine.IExecutionEngine;
import com.bas.basserver.executionengine.IProcess;
import com.bas.basserver.executionengine.SuspendProcessException;
import com.bas.connectionserver.server.AccessDeniedException;

public class GuideClass implements IProcess{

public GuideClass()
{
}

//@see com.bas.basserver.executionengine.IProcess#cancel()
public boolean cancel()
{
return true;
}

//@see com.bas.basserver.executionengine.IProcess#execute(com.bas.basserver.exe cutionengine.IExecutionEngine, java.lang.Object[])
public Object execute (IExecutionEngine engine, Object [] parameters)
throws SuspendProcessException, ExecutionException, AccessDeniedException
{
try
{
Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + "c:\\User Guide.pdf"); //open the file chart.pdf
return null;
}
catch (Exception e)
{}

return null;
}

//@see com.bas.basserver.executionengine.IProcess#resume(com.bas.basserver.executionengine.IExecutionEngine, java.lang.Object)
public Object resume (IExecutionEngine engine, Object reply)
throws SuspendProcessException, ExecutionException, AccessDeniedException
{
return null;
}
}

*___________________________________________________________*


Support,
Any guidance on where I should look?

Thanks
-Bryan
Version 8 (Build 2358)
BobK
Posts: 546
Joined: Thu Jan 31, 2008 2:14 pm
Location: Cincinnati, Ohio, USA

Post by BobK »

To me, your code looks like it should work.

Since the error you are getting is:
Process implementation component com.userguide.plugin is not found or has invalid format
I am assuming that AwareIM can not find your custom process.

Did you add your jar file to the CLASSPATH in setenv.bat and setenvClient.bat?
Bob
Bryan
Posts: 195
Joined: Fri Apr 03, 2009 12:46 am
Location: Cincy

Post by Bryan »

Thank for keeping an eye on me : - )

Yep, I added each an entry in each file. Just double checked them.
-Bryan
Version 8 (Build 2358)
Post Reply