Olivier Le Diouris
May 4th, 2006.
Prompt> regsvr32 .\PhysServer.dll
In case you need to unregister it, use
Prompt> regsvr32 /u .\PhysServer.dll
package wrapper;
import com.jacob.com.Dispatch;
import com.jacob.com.Variant;
public class Main
{
public static void main(String[] args)
{
Dispatch test = new Dispatch("PhysServer.Temperature");
Dispatch.put(test, "Fahrenheit", new Variant(70));
System.out.println("Calling COM function GetCelsius for 70...");
System.out.println("70 Fahrenheit = " + Dispatch.call(test, "GetCelsius") + " Celsius");
Dispatch.put(test, "Celsius", new Variant(120));
System.out.println("120 Celsius = " + Dispatch.call(test, "GetFahrenheit") + " Fahrenheit");
}
}
Such a class would be run as follow:
java -classpath .\classes;[JACOB_HOME]\jacob.jar -Djava.library.path=[JACOB_HOME] wrapper.Main
Calling COM function GetCelsius for 70...
70 Fahrenheit = 21.1111111111111 Celsius
120 Celsius = 248 Fahrenheit
package wrapper;
import com.jacob.com.Dispatch;
import com.jacob.com.Variant;
public class TempUtil
{
public static double fahrenheit2celsius(double f)
{
Dispatch test = new Dispatch("PhysServer.Temperature");
Dispatch.put(test, "Fahrenheit", new Variant(f));
return Dispatch.call(test, "GetCelsius").getDouble();
}
public static double celsius2fahrenheit(double c)
{
Dispatch test = new Dispatch("PhysServer.Temperature");
Dispatch.put(test, "Celsius", new Variant(c));
return Dispatch.call(test, "GetFahrenheit").getDouble();
}
}
There is nothing in such a class that would prevent it from being exposed as a Java Web Service.
It would come with a WSDL document, and from now on, it is just another regular Web Service.
As such, it can be consumed from BPEL through a Partner Link.
<bpelx:exec import="org.w3c.dom.Element"/>
<bpelx:exec import="com.jacob.com.Dispatch"/>
<bpelx:exec import="com.jacob.com.Variant"/>
<bpelx:exec name="DirectCOMCall" language="Java" version="1.4">
<![CDATA[
try
{
Element input = (Element)getVariableData("inputVariable",
"payload",
"/client:BPELcallsCOMProcessRequest/client:input");
String value = input.getNodeValue();
double celsius = Double.parseDouble(value);
Dispatch test = new Dispatch("PhysServer.Temperature");
Dispatch.put(test, "Celsius", new Variant(celsius));
double fahrenheit = com.jacob.com.Dispatch.call(test, "GetFahrenheit").getDouble();
setVariableData("outputVariable",
"payload",
"/client:BPELcallsCOMProcessResponse/client:result",
value + " Celsius = " + Double.toString(fahrenheit) + " Fahrenheit");
}
catch (Exception ex)
{
ex.printStackTrace();
}]]>
</bpelx:exec>
This is obviously not as flexible as before, but it avoid the SOAP/HTTP overhead.