Home > Archive > Cobol > June 2007 > Accessing desktop COM components from Java
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Accessing desktop COM components from Java
|
|
| Pete Dashwood 2007-06-04, 6:55 pm |
| It was a long w end here so I took a few hours off from my current
endeavours to see if I could solve the problem of remotely accessing the AVS
Web Service from Java. (See discussion under the "Web Services and COBOL
(Fairly long post, but I don't have time to write a proper article on it)"
thread, in this forum).
I can't... :-) (Well, not yet, anyway...)
Jimmy Gavan kindly converted my Fujitsu COBOL to MicroFocus COBOL to do
this, Charlie Hottel was looking at some Java approaches, but has more
serious things on his plate at the moment (hope all is going well, Charlie),
and Frank Swarbrick posted a sample of some Java to access an apache web
service and asked if it would be simpler to use the SOAP COM object, as the
COBOL solutions from Jimmy and myself had done.
I want to get COM accessible from Java anyway (there are thousands of useful
COM/ActiveX/OLE components that are part of the Windows Operating system,
apart from any you may have acquired or written yourself - Check your system
with an Object Browser; you have a large amount of stuff you don't know
you've got, and it can do all kinds of interesting and even exciting
things...)
But I also want to use the SOAP Toolkit COM Component (MSSOAP.SOAPCLient30)
to access the AVS web Service running on a server in San Francisco, remotely
from anywhere on Earth, using Java. (We've already cracked it for MicroFocus
and Fujitsu COBOL, C# is a doddle (although for this I don't use SOAP; my C#
solution uses the preferred DotNET services instead), and Java is a language
that quite a few people may want to use.)
Why use Java to access COM? Many reasons, some not immediately obvious (it
may be a step towards opening up the mainframe to components - it is no
coincidence I am using an IBM supplied Java software package to do it...)
I also believe that if Java can unlock the SOAP Toolkit by using the
supplied COM components, the resulting Java solution would be very simple.
(It is, I just can't get it to work, at the moment -))
OK, so I had a look around the NET and found IBM's Interface Tool Kit called
"Bridge2Java". This is a Java app that will analyse the Typelib of a COM
component and generate Java Proxies for it, so it can be accessed easily in
Java. Suspending my skepticism, I downloaded it and pointed it at the AVS
engine, which is a COM server .DLL, written in Fujitsu NET COBOL. It was
blazingly fast and childishly easy to use...impressive. It generated a Java
Package and left it in the directory I had specified. I could hardly wait to
knock up some Java and try it. Here's the code....
// Description: This is a Bridge2Java demo. Bridge2Java is used to enable
COM interfacing from Java,
// via the Java JNI. The software is downloadable from IBM and
generates a series of proxy
// classes for the properties and methods in the target COM
Typelib.
// The steps are:
// 1. Generate proxies from the COM Typelib.
// 2. Import the proxies into your Java application
// 3. Write your Java app to use the methods and properties of
the COM component.
//
// This particular code will use the AVS COM component,
AVSCOMSVR.AVSCOMSVR.3,
// to access the AVS Engine running on the desktop (Address
Validation Services).
//
//
//
// Author: Pete Dashwood
//
import AVSCOM4Java.*; //This is the set of proxies generated by Bridge2Java
public class AVSCOMSvrAccess
{
public static void main(java.lang.String[] args) {
AVSCOMSVR objCOMSvr;
String inIB = "This is an invalid interface block"; //Should return
an error...
String outIB = "";
String[] IB = {""};
try
{
// Set up the COM environment. (Thanks IBM!)
com.ibm.bridge2java.OleEnvironment.Initialize();
// Instantiate the COM object.
objCOMSvr = new AVSCOMSVR();
System.out.println("Instantiated COM Component");
IB[0] = inIB;
System.out.println("IB[0]=" + IB[0]);
// invoke the Engine
objCOMSvr.FIB(IB); //Uses "Fill in Blanks" Method of AVS and
passes an Interface Block
outIB = IB[0];
// Show what happened...
System.out.println("Returned from AVSCOMSvr=" + outIB);
} catch (com.ibm.bridge2java.ComException e)
{
System.out.println( "COM Exception:" );
System.out.println( Long.toHexString((e.getHResult())) );
System.out.println( e.getMessage() );
} catch (Exception e)
{
System.out.println("message: " + e.getMessage());
} finally
{
objCOMSvr = null;
com.ibm.bridge2java.OleEnvironment.UnInitialize();
}
}
}
Not a lot of code...
To my amazement, it worked instantly :-)
Here's the output it wrote into the DOS Box I ran it in...
Instantiated COM Component
IB[0]=This is an invalid interface block
Returned from AVSCOMSvr=11111The interface block you have
presented to AVS is incorrectly formatted, or contains
invalid content.
Check the value of the INTERFACE-TYPE field.
This is exactly what it should have returned. The interface block was not
structured correctly, as it was in the COBOL examples, and the
INTERFACE-TYPE field was never set.
So, COM components can be easily accessed on the desktop from Java, using
the Bridge2Java component from IBM.
Next stop, the Web Service, using SOAP...
At the moment I can instantiate the SoapClient object, but when I invoke the
"MSSoapInit" method and provide the necessary WSDL, it gives a COM error...
I'm still trying to understand exactly what this error is trying to tell me,
but it involves the SOAP XML and is several lines long so I'll have another
look at it tomorrow. If I can't get it to work, I'll write it as an Applet
and embed it in a web page... that should do it :-)
Pete.
| |
| andrewmcdonagh 2007-06-20, 9:55 pm |
| On Jun 4, 2:40 pm, "Pete Dashwood"
<dashw...@removethis.enternet.co.nz> wrote:
snipped...
>
> But I also want to use the SOAP Toolkit COM Component (MSSOAP.SOAPCLient30)
> to access the AVS web Service running on a server in San Francisco, remotely
> from anywhere on Earth, using Java. (We've already cracked it for MicroFocus
> and Fujitsu COBOL, C# is a doddle (although for this I don't use SOAP; my C#
> solution uses the preferred DotNET services instead), and Java is a language
> that quite a few people may want to use.)
>
> Why use Java to access COM? Many reasons, some not immediately obvious (it
> may be a step towards opening up the mainframe to components - it is no
> coincidence I am using an IBM supplied Java software package to do it...)
>
> I also believe that if Java can unlock the SOAP Toolkit by using the
> supplied COM components, the resulting Java solution would be very simple.
> (It is, I just can't get it to work, at the moment -))
>
snipped...
Not sure I see any benefit of doing Java2COM to enable your Java apps
to connect to a remote webservice....
Take a look at:
http://java.sun.com/developer/techn...s/J2EE/j2ee_ws/
Regards
Andrew
| |
| Pete Dashwood 2007-06-20, 9:55 pm |
|
"andrewmcdonagh" <andrewmcdonagh@gmail.com> wrote in message
news:1182376697.455356.230840@n60g2000hse.googlegroups.com...
> On Jun 4, 2:40 pm, "Pete Dashwood"
> <dashw...@removethis.enternet.co.nz> wrote:
>
> snipped...
>
>
> snipped...
>
> Not sure I see any benefit of doing Java2COM to enable your Java apps
> to connect to a remote webservice....
> Take a look at:
>
> http://java.sun.com/developer/techn...s/J2EE/j2ee_ws/
>
> Regards
>
> Andrew
Andrew, it isn't about accessing web services in Java. I agree that's fairly
straightforward. The whole point is to enable COM components in Java. The
SOAP thing is just ONE spin-off, and an arguably "unnecessary" one. I've
been too busy with other things to pursue this, but I will when I get time.
Pete.
>
| |
|
|
| andrewmcdonagh 2007-06-21, 9:55 pm |
| On Jun 21, 12:36 am, "Pete Dashwood"
<dashw...@removethis.enternet.co.nz> wrote:
> "andrewmcdonagh" <andrewmcdon...@gmail.com> wrote in message
>
> news:1182376697.455356.230840@n60g2000hse.googlegroups.com...
>
>
>
>
>
>
>
>
>
>
>
>
>
> Andrew, it isn't about accessing web services in Java. I agree that's fairly
> straightforward. The whole point is to enable COM components in Java. The
> SOAP thing is just ONE spin-off, and an arguably "unnecessary" one. I've
> been too busy with other things to pursue this, but I will when I get time.
>
> Pete.
>
>
Oh ok ...I understand.
Regards
Andrew
PS: Been ages since I last visited....how's the OO C# going?
| |
| Pete Dashwood 2007-06-21, 9:55 pm |
|
"andrewmcdonagh" <andrewmcdonagh@gmail.com> wrote in message
news:1182463212.534723.242990@n60g2000hse.googlegroups.com...
<snipped>
[color=darkred]
>
> Oh ok ...I understand.
>
> Regards
>
> Andrew
> PS: Been ages since I last visited....how's the OO C# going?
>
Brilliant! Best thing I ever did. Whole new world... online video tutorials,
help that actually helps, Intellisense in the IDE (blows me away every day I
use it :-)) and a straightforward, consistent syntax. I am totally sold on
DotNET/Mono and the FCL.
For Web Development (I am currently udertaking a major one to support my
Address Validation Service engine, which is around 4000 lines of OO COBOL
and has integrated seamlessly and (almost :-)) effortlessly with C# through
the Framework Class Library Interop services), I love the autowired event
processing and pre-compiled code-behind pages so that everything runs
securely on the server. I've been looking at AJAX and may use this for the
next project. It certainly seems like a good way to organise and control
client side code.
A very happy bunny :-)!
Pete.
|
|
|
|
|