You are viewing a plain text version of this content. The canonical link for it is here.
Posted to wsif-user@ws.apache.org by D <dk...@hotmail.com> on 2004/01/07 17:33:36 UTC

Can't call local java class outside of context

Hi All, I'm having a problem at the moment trying to invoke methods in local
classes located outside the project containing the DynamicInvoker. As the
classpath attribute is currently not supportted in the WSIF classes, I
extended the WSIFPort_Java class to add a hack to allow specifying where the
class is located. Below is the WSIFPort_Java method I've overridden in my
own class.

public java.lang.Object getObjectReference() throws WSIFException {
        Trc.entry(this);
        Object objRef = null;
        boolean localClass = true;
        try{
         objRef = super.getObjectReference();
        }
        catch(WSIFException wEx){
         localClass = false;
         System.out.println("Could not find class in current work
environment, checking local drives");
        }


        if (!localClass) {
            JavaAddress address = null;

            try {
                ExtensibilityElement portExtension =
                    (ExtensibilityElement)
this.getPortModel().getExtensibilityElements().get(0);

                if (portExtension == null) {
                    throw new WSIFException("missing port extension");
                }

                address = (JavaAddress) portExtension;
                String classPath = address.getClassPath();
                if(classPath.indexOf("file://") < 0)
                 classPath = "file://" + classPath;
                URL[] classUrl = {new URL(classPath)};
                String className = address.getClassName();
                URLClassLoader urlClassLoader = new
URLClassLoader(classUrl);
                Class c =
Class.forName(address.getClassName(),true,urlClassLoader);
//                Class c = urlClassLoader.loadClass(className); produces
same class as above
                objRef = c.newInstance();
            } catch (Exception ex) {
             Trc.exception(ex);
                throw new WSIFException(
                    "Could not create object of class '" +
address.getClassName() + "'",
                    ex);
            }
        }
        System.out.println(objRef.toString());
        Trc.exit(objRef);
        return objRef;
    }

There are 2 possibilities when this method is called, either the class is
local to the project or if not it is in a different folder or drive.
When the class is not local the location of the class is obtained from the
classPath attribute in the WSDL file and a URLClassLoader class is
instantiated. The object I return from this looks the same as the object
returned when the super.getObjectReference() method is called, however, I
get an exception in the

operation.executeRequestResponseOperation(input, output, fault)

call in the DynamicInvoker if I use the object returned using the
URLClassLoader. This exception is below:

WSIF0005E: An error occurred when invoking the method 'getTestOutput'.
('Java')
org.apache.wsif.WSIFException:
org.apache.wsif.providers.java.WSIFOperation_Java@1827284 : Could not invoke
'getTestOutput'; nested exception is:
 org.apache.wsif.WSIFException: Failed to invoke method 'getTestOutput'
 at
org.apache.wsif.providers.java.WSIFOperation_Java.executeRequestResponseOper
ation(Unknown Source)
 at
bait.adapter.utils.GenericDynamicServiceInvoker.invokeMethod(GenericDynamicS
erviceInvoker.java:249)
 at
bait.adapter.utils.GenericDynamicServiceInvoker.callService(GenericDynamicSe
rviceInvoker.java:115)
 at
bait.adapter.service_adapter_generated_classes.LocalTestClassServiceServiceA
dapter.invoke(LocalTestClassServiceServiceAdapter.java:37)
 at MainTestDynamicInvoker.main(MainTestDynamicInvoker.java:31)
Caused by: org.apache.wsif.WSIFException: Failed to invoke method
'getTestOutput'
 ... 5 more

I'm at a bit of a loss as to why this happens and would appreciate any help
or suggestions.

Thanks as always in advance

Damien

Re: Can't call local java class outside of context

Posted by D <dk...@hotmail.com>.
Hi All, I've gone a bit further on the problem mentioned below in my first
mail on the subject, in that I've debugged down to the exception in the
WSIFOperation_Java class. The exception happens in the

 public boolean executeRequestResponseOperation(
        WSIFMessage input,
        WSIFMessage output,
        WSIFMessage fault)

in the snippet of code below :

Object objRef = fieldPort.getObjectReference();
                            Trc.event(this, "Invoking object ", objRef, "
method ", fieldMethods[a]," with arguments ",
compatibleArguments);

result = fieldMethods[a].invoke(objRef,compatibleArguments); //exception
thrown here

The IllegalArgumentException ia's value is below:

"ia"= java.lang.IllegalArgumentException  (id=81)
 cause= java.lang.IllegalArgumentException  (id=81)
 detailMessage= "object is not an instance of declaring class"
 stackTrace= null

If anyone has any idea's why the exception is thrown here when the objRef
refers to an external object i.e. not in workspace, and not thrown when
exactly the same objRef is used except this time loaded from within the
workspace I'd be really happy to hear them.

Thanks

Damien
----- Original Message ----- 
From: "D" <dk...@hotmail.com>
To: <ws...@ws.apache.org>
Sent: Wednesday, January 07, 2004 4:33 PM
Subject: Can't call local java class outside of context


> Hi All, I'm having a problem at the moment trying to invoke methods in
local
> classes located outside the project containing the DynamicInvoker. As the
> classpath attribute is currently not supportted in the WSIF classes, I
> extended the WSIFPort_Java class to add a hack to allow specifying where
the
> class is located. Below is the WSIFPort_Java method I've overridden in my
> own class.
>
> public java.lang.Object getObjectReference() throws WSIFException {
>         Trc.entry(this);
>         Object objRef = null;
>         boolean localClass = true;
>         try{
>          objRef = super.getObjectReference();
>         }
>         catch(WSIFException wEx){
>          localClass = false;
>          System.out.println("Could not find class in current work
> environment, checking local drives");
>         }
>
>
>         if (!localClass) {
>             JavaAddress address = null;
>
>             try {
>                 ExtensibilityElement portExtension =
>                     (ExtensibilityElement)
> this.getPortModel().getExtensibilityElements().get(0);
>
>                 if (portExtension == null) {
>                     throw new WSIFException("missing port extension");
>                 }
>
>                 address = (JavaAddress) portExtension;
>                 String classPath = address.getClassPath();
>                 if(classPath.indexOf("file://") < 0)
>                  classPath = "file://" + classPath;
>                 URL[] classUrl = {new URL(classPath)};
>                 String className = address.getClassName();
>                 URLClassLoader urlClassLoader = new
> URLClassLoader(classUrl);
>                 Class c =
> Class.forName(address.getClassName(),true,urlClassLoader);
> //                Class c = urlClassLoader.loadClass(className); produces
> same class as above
>                 objRef = c.newInstance();
>             } catch (Exception ex) {
>              Trc.exception(ex);
>                 throw new WSIFException(
>                     "Could not create object of class '" +
> address.getClassName() + "'",
>                     ex);
>             }
>         }
>         System.out.println(objRef.toString());
>         Trc.exit(objRef);
>         return objRef;
>     }
>
> There are 2 possibilities when this method is called, either the class is
> local to the project or if not it is in a different folder or drive.
> When the class is not local the location of the class is obtained from the
> classPath attribute in the WSDL file and a URLClassLoader class is
> instantiated. The object I return from this looks the same as the object
> returned when the super.getObjectReference() method is called, however, I
> get an exception in the
>
> operation.executeRequestResponseOperation(input, output, fault)
>
> call in the DynamicInvoker if I use the object returned using the
> URLClassLoader. This exception is below:
>
> WSIF0005E: An error occurred when invoking the method 'getTestOutput'.
> ('Java')
> org.apache.wsif.WSIFException:
> org.apache.wsif.providers.java.WSIFOperation_Java@1827284 : Could not
invoke
> 'getTestOutput'; nested exception is:
>  org.apache.wsif.WSIFException: Failed to invoke method 'getTestOutput'
>  at
>
org.apache.wsif.providers.java.WSIFOperation_Java.executeRequestResponseOper
> ation(Unknown Source)
>  at
>
bait.adapter.utils.GenericDynamicServiceInvoker.invokeMethod(GenericDynamicS
> erviceInvoker.java:249)
>  at
>
bait.adapter.utils.GenericDynamicServiceInvoker.callService(GenericDynamicSe
> rviceInvoker.java:115)
>  at
>
bait.adapter.service_adapter_generated_classes.LocalTestClassServiceServiceA
> dapter.invoke(LocalTestClassServiceServiceAdapter.java:37)
>  at MainTestDynamicInvoker.main(MainTestDynamicInvoker.java:31)
> Caused by: org.apache.wsif.WSIFException: Failed to invoke method
> 'getTestOutput'
>  ... 5 more
>
> I'm at a bit of a loss as to why this happens and would appreciate any
help
> or suggestions.
>
> Thanks as always in advance
>
> Damien
>