Calling Java class files from PLSQL [message #246086] |
Tue, 19 June 2007 19:51 |
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 #246249 is a reply to message #246086] |
Wed, 20 June 2007 07:29 |
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 #246269 is a reply to message #246086] |
Wed, 20 June 2007 08:16 |
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 #246291 is a reply to message #246086] |
Wed, 20 June 2007 09:20 |
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 #272237 is a reply to message #247304] |
Thu, 04 October 2007 05:09 |
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 #272862 is a reply to message #272845] |
Mon, 08 October 2007 01:32 |
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 #273184 is a reply to message #272900] |
Tue, 09 October 2007 07:00 |
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 #274034 is a reply to message #273602] |
Fri, 12 October 2007 16:29 |
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 #348330 is a reply to message #274034] |
Tue, 16 September 2008 07:46 |
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 |
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.
|
|
|
|