Home » Developer & Programmer » Forms » Calling Java class files from PLSQL
Calling Java class files from PLSQL [message #246086] Tue, 19 June 2007 19:51 Go to next message
krishkrish
Messages: 6
Registered: June 2007
Junior Member
HI All,

I have imported a java class file that inturn gets content from a webservice. One of the functions on that imported class file is as follows ...

Funtion getcontent(A1 JOBJECT,A2 JOBJECT, A3 String) return JOBJECT ....

In my PLSQL package ...How do I invoke this class file ?

So far I have done this ...

Declare
abc ORA_JAVA.JOBJECT;
xyz ORA_JAVA.JOBJECT;
xxx VARCHAR2(25);
value ORA_JAVA.JOBJECT;
BEGIN
abc := ECPORACLE.new;
xyz := ECPORACLE.new;
xxx := 'www.orafaq.com';

value := ECPORACLE.getcontent(abc,xyz,xxx);

EXCEPTION
...........
.............

END;

I am getting an error saying the object type is wrong ....

I am pretty new to calling Java from PLSQL. I would apprecaite any kind of help in this regard. I would like to know how to assign a hardcoded value to the JOBJECT just to test before I continue.


Re: Calling Java class files from PLSQL [message #246104 is a reply to message #246086] Tue, 19 June 2007 23:25 Go to previous messageGo to next message
Michel Cadot
Messages: 64103
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
Welcome to the forum.

First, Please read and follow How to format your posts and How to get a quick answer to your question: TIPS AND TRICKS
Break your lines to max 80-100 characters when you format.
Please always post your Oracle version (4 decimals).

Always post exactly what you've done that is use SQL*Plus and copy and paste your screen.
"I am getting an error saying the object type is wrong ...." which object type, what is wrong, what is the Oracle error? How can we know what there is on your screen? How can we help without accurrate information?

Regards
Michel
Re: Calling Java class files from PLSQL [message #246249 is a reply to message #246086] Wed, 20 June 2007 07:29 Go to previous messageGo to next message
krishkrish
Messages: 6
Registered: June 2007
Junior Member
Forms [32 Bit] Version 6.0.8.11
PL/SQL Version 8.0.6.0

Imported Class File(Package) is as follows:

FUNCTION new RETURN ORA_JAVA.JOBJECT IS
BEGIN
cls := JNI.GET_CLASS('com/optiosoftware/ecompresent/oracle/wf/OracleECPWebService');
mid := JNI.GET_METHOD(FALSE, cls, '<init>', '()V');
args := NULL;
RETURN (JNI.NEW_OBJECT(cls, mid, args));
END;

The Procedure that I use is as follows:

PROCEDURE getcontent IS
raisedException ORA_JAVA.JOBJECT;
data_type ORA_JAVA.JOBJECT;
content_data ORA_JAVA.JOBJECT;
num PLS_INTEGER := 2;
retval ORA_JAVA.JOBJECT;
BEGIN
data_type := ORACLEECPWEBSERVICE.new;
content_data := ORACLEECPWEBSERVICE.new;
retval := ORACLEECPWEBSERVICE.queryContent(data_type,content_data,num);
EXCEPTION
WHEN ORA_JAVA.JAVA_ERROR then
message ('Unable to call out to Java, ' || ORA_JAVA.LAST_ERROR);
ORA_JAVA.CLEAR_EXCEPTION;
WHEN ORA_JAVA.EXCEPTION_THROWN THEN
raisedException := ORA_JAVA.LAST_EXCEPTION;
message('Java Exception : ' || Exception_.getMessage(raisedException));
ORA_JAVA.CLEAR_EXCEPTION;
END;

The Error I get is as follows:
Unable to call out to Java, Invalid object type for argument 1.

My question is how do I assign a value 'QScannedInvoices' to the 'data_type' object and
the value 'Status' to the 'content_data'object ?

Appreciate any help with regards to this. Thanks.
Re: Calling Java class files from PLSQL [message #246261 is a reply to message #246249] Wed, 20 June 2007 08:05 Go to previous messageGo to next message
Michel Cadot
Messages: 64103
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
See the link I posted to format the code and format your post.

Post exactly what you've done that is use SQL*Plus and copy and paste your screen.

Regards
Michel

Re: Calling Java class files from PLSQL [message #246269 is a reply to message #246086] Wed, 20 June 2007 08:16 Go to previous messageGo to next message
krishkrish
Messages: 6
Registered: June 2007
Junior Member
Forms [32 Bit] Version 6.0.8.11
PL/SQL Version 8.0.6.0

Imported Class File(Package) is as follows:

FUNCTION New
RETURN Ora_java.Jobject
IS
BEGIN
  cls := jni.Get_Class('com/optiosoftware/ecompresent/oracle/wf/OracleECPWebService');
  
  Mid := jni.Get_Method(False,cls,'<init>','()V');
  
  args := NULL;
  
  RETURN (jni.New_Object(cls,Mid,args));
END;

The Procedure that I use is as follows:

PROCEDURE GetContent
IS
  RaisedException  Ora_java.Jobject;
  Data_Type        Ora_java.Jobject;
  Content_Data     Ora_java.Jobject;
  num              PLS_INTEGER := 2;
  reTval           Ora_java.Jobject;
BEGIN
  Data_Type := OracleecpWebService.New;
  
  Content_Data := OracleecpWebService.New;
  
  reTval := OracleecpWebService.QueryContent(Data_Type,Content_Data,num);
EXCEPTION
  WHEN Ora_java.java_Error THEN
    Message('Unable to call out to Java, '
            ||Ora_java.Last_Error);
    
    Ora_java.Clear_Exception;
  WHEN Ora_java.Exception_Thrown THEN
    RaisedException := Ora_java.Last_Exception;
    
    Message('Java Exception : '
            ||Exception_.GetMessage(RaisedException));
    
    Ora_java.Clear_Exception;
END;

The Error I get is as follows:
Unable to call out to Java, Invalid object type for argument 1.

My question is how do I assign a value 'QScannedInvoices' to the 'data_type' object and
the value 'Status' to the 'content_data'object ?

Appreciate any help with regards to this. Thanks.
Re: Calling Java class files from PLSQL [message #246282 is a reply to message #246269] Wed, 20 June 2007 08:41 Go to previous messageGo to next message
Michel Cadot
Messages: 64103
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
Third time:

Post exactly what you've done that is use SQL*Plus and copy and paste your screen

Regards
Michel

[Updated on: Wed, 20 June 2007 08:41]

Report message to a moderator

Re: Calling Java class files from PLSQL [message #246291 is a reply to message #246086] Wed, 20 June 2007 09:20 Go to previous messageGo to next message
krishkrish
Messages: 6
Registered: June 2007
Junior Member
I'm using Oracle Forms to try and access a webservice. the code that been shown is PLSQL and when I run the Forms, I get the error mentioned. Hope this helps. I've copied and pasted as mentioned. Not sure what other information is needed.
Re: Calling Java class files from PLSQL [message #247198 is a reply to message #246291] Mon, 25 June 2007 00:56 Go to previous messageGo to next message
djmartin
Messages: 10180
Registered: March 2005
Location: Canberra ACT Australia
Senior Member
Account Moderator
Out of curiosity, does Oracle 8 support Ora_java?

David
Re: Calling Java class files from PLSQL [message #247304 is a reply to message #246086] Mon, 25 June 2007 08:15 Go to previous messageGo to next message
krishkrish
Messages: 6
Registered: June 2007
Junior Member
David,

I'm using Oracle database version 9i, but the PLSQL version of forms is 8.0. Any suggestions ?

Krish
Re: Calling Java class files from PLSQL [message #272237 is a reply to message #247304] Thu, 04 October 2007 05:09 Go to previous messageGo to next message
bbaz
Messages: 138
Registered: April 2007
Senior Member
Does anyone know how to Resolve this? How can we assign Values to Ora_Java.jobject?

Is there a way to do this?

Quote:

Unable to call out to Java, Invalid object type for argument 1.

My question is how do I assign a value 'QScannedInvoices' to the 'data_type' object and
the value 'Status' to the 'content_data'object ?



Thanks
Re: Calling Java class files from PLSQL [message #272845 is a reply to message #272237] Mon, 08 October 2007 01:00 Go to previous messageGo to next message
djmartin
Messages: 10180
Registered: March 2005
Location: Canberra ACT Australia
Senior Member
Account Moderator
I ran the following code:
declare
  Data_Type         Ora_java.Jobject;
BEGIN
  dbms_output.put_line ('start');
  Data_Type     := OracleecpWebService.New;
  dbms_output.put_line ('end');
END;
on both Oracle 9.2.0.1 and 10.2.0 received the same messages:
ORA-06550: line 2, column 21:
PLS-00201: identifier 'ORA_JAVA.JOBJECT' must be declared
ORA-06550: line 2, column 21:
PL/SQL: Item ignored
ORA-06550: line 5, column 3:
PLS-00320: the declaration of the type of this expression is incomplete or malfo
ORA-06550: line 5, column 3:
PL/SQL: Statement ignored

Do you need to install another product to use 'Ora_java'?

Where are you getting your sample code? Is this an independant product?

David
Re: Calling Java class files from PLSQL [message #272862 is a reply to message #272845] Mon, 08 October 2007 01:32 Go to previous messageGo to next message
bbaz
Messages: 138
Registered: April 2007
Senior Member
Hi David,

Before using this Sample code directly into your Forms, we are creating the JAVA Class in JDeveloper and then Importing this CLASS into Oracle Forms. Once this is done then the Ora_Java.JObject is recognized.

Here is the Complete Document we are using as a Reference for doing the complete cycle:
http://www.oracle.com/technology/products/forms/htdocs/Forms_WebService_How_To.htm

A Sample Webservice that can be used for a Similar example can be this:
http://www.webservicex.com/CurrencyConvertor.asmx

With the following Description File:
http://www.webservicex.com/CurrencyConvertor.asmx?wsdl

Try It.

***********************************************
In my case, I have tried a similar Service and I came across the Same problem of Passing VALUES into Ora_java.JObject. THEN I CHANGED THE PARAMETERS OF THE JAVA FUNCTION MANUALLY (in the JDeveloper) IN ORDER TO PASS STRING DATATYPE:

New JAVA Function Header:
public Vector GetPIValue(String TagName, String ReadingTime) throws Exception
.
.
Vector requestBodyEntries = new Vector();

    requestBodyEntries.addElement(TagName);
    requestBodyEntries.addElement(ReadingTime);


Old JAVA Function Header:
public Vector GetPIValue(Elements requesteElement) throws Exception
.
.
Vector requestBodyEntries = new Vector();

    requestBodyEntries.addElement(requesteElement);





Now I can call the Function but the Webservice is not Returning any Value, failing at "RETURN JNI.CALL_OBJECT_METHOD(obj, mid, args); " in my Forms Package Function:

FUNCTION GetPIValue(
    obj   ORA_JAVA.JOBJECT,
    a0    VARCHAR2,
    a1    VARCHAR2) RETURN ORA_JAVA.JOBJECT IS
  BEGIN
    Message('param passed: '||a0||' - '||a1);
    cls := JNI.GET_CLASS('oracle/forms/demos/webservice/ConnectToPIStub');
    mid := JNI.GET_METHOD(FALSE, cls, 'GetPIValue', '(Ljava/lang/String;Ljava/lang/String;)Ljava/util/Vector;');
    args := JNI.CREATE_ARG_LIST(2);
    JNI.ADD_STRING_ARG(args, a0);
    JNI.ADD_STRING_ARG(args, a1);
    Message('I am Here');
    RETURN JNI.CALL_OBJECT_METHOD(obj, mid, args); 
  END;


please note that this WebService is Running perfectly from the Web Browser.

Any Help is Much Appreciated.

Regards,
Baz

Re: Calling Java class files from PLSQL [message #272900 is a reply to message #272862] Mon, 08 October 2007 02:32 Go to previous messageGo to next message
djmartin
Messages: 10180
Registered: March 2005
Location: Canberra ACT Australia
Senior Member
Account Moderator
I have no idea. Hopefully, someone else here can help you.

David
Re: Calling Java class files from PLSQL [message #273184 is a reply to message #272900] Tue, 09 October 2007 07:00 Go to previous messageGo to next message
bbaz
Messages: 138
Registered: April 2007
Senior Member
Quote:


THEN I CHANGED THE PARAMETERS OF THE JAVA FUNCTION MANUALLY (in the JDeveloper) IN ORDER TO PASS STRING DATATYPE



As an update, Changing the Parameters of the Java Function was not a good Idea.

Back to calling the Webservice from Oracle Forms, I managed to IMPORT the Element class from: org.w3c.dom.Element

Now the issue is here, when I call the setAttribute Procedure of the ELEMENT package, I am getting the following error when using the code below:

Element.setAttribute(param_1,
    'attribName',
    'attribValue');


ERROR:
Quote:


Unable to call out to Java, Argument 1 can not be null.




HOW CAN I INITIALIZE "param_1" as an DOM Element in PL/SQL? since there is NO FUNCTION like param_1 := Element.new;

param_1 is of type obj_java.jobject. Here is the setAttribute Procedure structure:

PROCEDURE setAttribute(
    obj   ORA_JAVA.JOBJECT,
    a0    VARCHAR2,
    a1    VARCHAR2) IS
  BEGIN
    cls := JNI.GET_CLASS('org/w3c/dom/Element');
    mid := JNI.GET_METHOD(FALSE, cls, 'setAttribute', '(Ljava/lang/String;Ljava/lang/String;)V');
    args := JNI.CREATE_ARG_LIST(2);
    JNI.ADD_STRING_ARG(args, a0);
    JNI.ADD_STRING_ARG(args, a1);
    JNI.CALL_VOID_METHOD(obj, mid, args); 
  END;


I couldn't find much help on the web on this topic. If anyone has tried this before, we would all appreciate his/her help on how to move ahead.

thanks in advance,
Baz

[Updated on: Tue, 09 October 2007 07:03]

Report message to a moderator

Re: Calling Java class files from PLSQL [message #273375 is a reply to message #273184] Wed, 10 October 2007 03:39 Go to previous messageGo to next message
bbaz
Messages: 138
Registered: April 2007
Senior Member

Hi all,

I found the following LINK very informative and I would like to share it with you:

http://forums.oracle.com/forums/thread.jspa?messageID=329678&#329678

A Web Service created in .NET defaults to be generated as document style interface whereas JDeveloper defaults to generating an RPC style interface. The end result is that JDeveloper wraps the document interface and thus we END UP WITH "ELEMENT" argument for the JAVA class generated methods.

Since I have JDeveloper 9.0.2, the link recommends referring to a Sample document in order to parse the XML. I haven't tried this solution as I couldn't Track the document.

Has anyone tried this???

This is really driving me crazy Mad , I hope that some one can help.

Regards,
Baz
Re: Calling Java class files from PLSQL [message #273602 is a reply to message #273375] Thu, 11 October 2007 01:20 Go to previous messageGo to next message
djmartin
Messages: 10180
Registered: March 2005
Location: Canberra ACT Australia
Senior Member
Account Moderator
I also wish that someone could help you. Please keep posting your findings as you work through your problem.

David
Re: Calling Java class files from PLSQL [message #274034 is a reply to message #273602] Fri, 12 October 2007 16:29 Go to previous messageGo to next message
bbaz
Messages: 138
Registered: April 2007
Senior Member

More updates on this topic:

It was recommended by other users to download and install a NEWER version of JDeveloper that will handle Wrapping the Datatype of the WSDL file of the Web Service in JDeveloper Java Classes.

I downloaded JDev 10.1.3.3 from the Oracle Website around 500MB file, and then I created a Web Service Proxy in JDev 10(formally Web Service Stub/Skeleton in JDev 9) based on my WSDL file. I tested the Java Class (Service1SoapClient)and it is properly Calling the Web Service passing in String Paramters (2 Strings) and returning a Double Datatype.

So far, things are pretty good from the JDeveloper side.



package project1.proxy;

import oracle.webservices.transport.ClientTransport;
import oracle.webservices.OracleStub;
import javax.xml.rpc.ServiceFactory;
import javax.xml.rpc.Stub;

public class Service1SoapClient {
    private project1.proxy.Service1Soap _port;
    
    public Service1SoapClient() throws Exception {
        ServiceFactory factory = ServiceFactory.newInstance();
        _port = ((project1.proxy.Service1)factory.loadService(project1.proxy.Service1.class)).getService1Soap();
    }
    
    /**
     * @param args
     */
    public static void main(String[] args) {
        try {
            project1.proxy.Service1SoapClient myPort = new project1.proxy.Service1SoapClient();
            System.out.println("calling " + myPort.getEndpoint());
            // Add your own code here
        
             double testResponse = myPort.getPIValue("A3LI004.pv", "9/9/2007 9:20 am");
            System.out.println("response from PI " + testResponse);
        
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
    
    /**
     * delegate all operations to the underlying implementation class.
     */
    
    /**
    Connect to PI Server

    **/
    public void connect() throws java.rmi.RemoteException {
        _port.connect();
    }
    
    /**
    Disconnect from PI Server

    **/
    public void disconnect() throws java.rmi.RemoteException {
        _port.disconnect();
    }
    
    /**
    Retrieve PI Values

    **/
    public double getPIValue(String piTAG, String piTS) throws java.rmi.RemoteException {
        return _port.getPIValue(piTAG, piTS);
    }



When I try to import this same CLASS into Oracle Forms I am getting an Error:
Quote:


Importing Class project1.proxy.Service1SoapClient...
Exception occurred: java.lang.NoClassDefFoundError: oracle/webservices/transport/ClientTransport



Can someone shed some light on this Error? I have read that this has to do with my CLASSPATH Environment Variable...?

Is this the right Class to Import into Oracle Forms to call the Web Servie from Forms?

Thanks in advance,
Baz
Re: Calling Java class files from PLSQL [message #274171 is a reply to message #274034] Sun, 14 October 2007 21:24 Go to previous messageGo to next message
djmartin
Messages: 10180
Registered: March 2005
Location: Canberra ACT Australia
Senior Member
Account Moderator
Remember that for the 'forms_path' you place your directory as the beginning of the list but for 'java' paths you place your code at the end of the list. Hope this helps.

David
Re: Calling Java class files from PLSQL [message #348330 is a reply to message #274034] Tue, 16 September 2008 07:46 Go to previous messageGo to next message
ralphkill
Messages: 1
Registered: September 2008
Junior Member
I am using jdeveloper 10.1.2.1 to do a similar thing, like you I am calling a currency conversion web service and generating the java from jbuilder.

I found that by adding the jar files in to the deployment options in jdeveloper, these errors were resolved.

select the .deploy part of your project, right click and bring up the properties. You should see a 'contributors' leaf in the tree diagram. Select this and add a java jar file

I had to add

C:/oracle/DevSuiteHome10gR2/jdev/lib/jdev-rt.jar!/
C:/oracle/DevSuiteHome10gR2/soap/lib/soap.jar!/

Your pathnames will be different and you may need different jar files.

I have got to the position where I am calling the web service, but the parameters being passed through seem to have &apos appended to them.

Investigation continues.
Re: Calling Java class files from PLSQL [message #416414 is a reply to message #348330] Sat, 01 August 2009 15:49 Go to previous messageGo to next message
symphony
Messages: 4
Registered: July 2009
Junior Member
Hi I know it has been a long time since this one was posted.. I am also facing the same issue .. When i call the new function of the imported java class to instantiate the object it is throwing me exception. Has anyone solved this...

Thanks.
Re: Calling Java class files from PLSQL [message #560394 is a reply to message #416414] Thu, 12 July 2012 08:45 Go to previous message
fpp1975
Messages: 1
Registered: July 2012
Junior Member
I have the same problem.

java.lang.NoClassDefFoundError: javax/xml/rpc/Service

Any suggestion...

Thanks.
Previous Topic: Forms 10g on a terminal emulator DRIFT, PUTTY
Next Topic: how to restrict update
Goto Forum:
  


Current Time: Sun Dec 04 02:49:35 CST 2016

Total time taken to generate the page: 0.09821 seconds