Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

Calling Bing translate API in oracle using the LoadJava utility

user13780543Sep 4 2015 — edited Sep 8 2015


Hi ,

We are trying to load the java class into Oracle which does the translation using the Bing API. Here, while using the LoadJava utility, we are specifying the java class which contains the translation code and the Jars which is used by this class.

There was no error while running this command and the Java Class type is in VALID status, but while we are running the function we are getting the below error,

Error :  ORA-29531: no method translator in class BingTranslator

Can anyone help to resolve this issue. I have posted the code used below,

Java Code:

import com.memetix.mst.language.Language;
import com.memetix.mst.translate.Translate;

public class BingTranslator {
  public String translator(String clientID, String clientValue,String value) throws Exception{
   Translate.setClientId(clientID);
      Translate.setClientSecret(clientValue);
      String outValue = Translate.execute(value, Language.AUTO_DETECT, Language.ENGLISH);
   return outValue;
  } 
}

Load Java:

loadjava -u username/password -v -resolve microsoft-translator-java-api-0.6.2.jar microsoft-translator-java-api-0.6.2-jar-with-dependencies.jar BingTranslator.java

Function:

CREATE OR REPLACE FUNCTION FN_translate (clientID VARCHAR2,clientValue VARCHAR2,value VARCHAR2)

   RETURN VARCHAR2

AS LANGUAGE JAVA

   NAME 'BingTranslator.translator(java.lang.String, java.lang.String, java.lang.String) return java.lang.String';

Comments

Solomon Yakobson

Did you test java code outside Oracle? Does it work at all?

SY.

user13780543

Hi Solomon,

Yes we have tested this from outside Oracle and it is working fine.


Solomon Yakobson

import com.memetix.mst.language.Language;
import com.memetix.mst.translate.Translate;

public class BingTranslator {
  public static String translator(String clientID, String clientValue,String value) throws Exception{
  Translate.setClientId(clientID);
      Translate.setClientSecret(clientValue);
      String outValue = Translate.execute(value, Language.AUTO_DETECT, Language.ENGLISH);
  return outValue;
  } 
}

SY.

user13780543

Hi,

I have updated the java source code with STATIC and executed the scripts. I have got the below error,

ORA-29532: Java call terminated by uncaught Java exception: java.lang.Exception: [microsoft-translator-api] Error retrieving translation : the Permission (java.net.SocketPermission datamarket.accesscontrol.windows.net:443 connect,resolve) has not been granted to <<USERNAME>>. The PL/SQL to grant this is dbms_java.grant_permission( <<USERNAME>>, 'SYS:java.net.SocketPermission', 'datamarket.accesscontrol.windows.net:443', 'connect,resolve' )
29532. 00000 -  "Java call terminated by uncaught Java exception: %s"
*Cause:    A Java exception or error was signaled and could not be
           resolved by the Java code.
*Action:   Modify Java code, if this behavior is not intended.

Executed the below script and still the error exists,


exec dbms_java.grant_permission( <<USERNAME>>, 'SYS:java.net.SocketPermission', 'datamarket.accesscontrol.windows.net:443', 'connect,resolve' );

PeterValencic

It's ok..

you must grant permission to socket on port 443...

Execute that script

dbms_java.grant_permission( <<USERNAME>>, 'SYS:java.net.SocketPermission', 'datamarket.accesscontrol.windows.net:443', 'connect,resolve' )


instead of <<USERNAME>> put 'your_username'... for example


dbms_java.grant_permission( 'JOHNDOE', 'SYS:java.net.SocketPermission', 'datamarket.accesscontrol.windows.net:443', 'connect,resolve' )


I can't remember but execute that script as SYS user...


Try to reconnect after dbms_java.grant_permission... and execute your function which call java stored procedure...



1 - 5
Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Oct 6 2015
Added on Sep 4 2015
5 comments
771 views