This discussion is archived
10 Replies Latest reply: Mar 15, 2013 6:05 PM by Siberia RSS

Problem using a jar file : java.lang.ClassNotFoundException: ApiConn

Siberia Newbie
Currently Being Moderated
Hi everyone.
i am running a form that use a bean_area to call a jar.
but i am getting this error, thanks in advnce for any tip.

-------------


Java Plug-in 1.6.0_33
Using JRE version 1.6.0_33-b05 Java HotSpot(TM) Client VM
User home directory = C:\Users\user1
----------------------------------------------------
c: clear console window
f: finalize objects on finalization queue
g: garbage collect
h: display this help message
l: dump classloader list
m: print memory usage
o: trigger logging
q: hide console
r: reload policy configuration
s: dump system and deployment properties
t: dump thread list
v: dump thread stack
x: clear classloader cache
0-5: set trace level to <n>
----------------------------------------------------
java.lang.ClassNotFoundException: ApiConn
     at sun.plugin2.applet.Applet2ClassLoader.findClass(Unknown Source)
     at sun.plugin2.applet.Plugin2ClassLoader.loadClass0(Unknown Source)
     at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Unknown Source)
     at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Unknown Source)
     at java.lang.ClassLoader.loadClass(Unknown Source)
     at java.lang.Class.forName0(Native Method)
     at java.lang.Class.forName(Unknown Source)
     at oracle.forms.handler.UICommon.instantiate(Unknown Source)
     at oracle.forms.handler.UICommon.onCreate(Unknown Source)
     at oracle.forms.handler.JavaContainer.onCreate(Unknown Source)
     at oracle.forms.engine.Runform.onCreateHandler(Unknown Source)
     at oracle.forms.engine.Runform.processMessage(Unknown Source)
     at oracle.forms.engine.Runform.processSet(Unknown Source)
     at oracle.forms.engine.Runform.onMessageReal(Unknown Source)
     at oracle.forms.engine.Runform.onMessage(Unknown Source)
     at oracle.forms.engine.Runform.processEventEnd(Unknown Source)
     at oracle.ewt.lwAWT.LWComponent.redispatchEvent(Unknown Source)
     at oracle.ewt.lwAWT.LWComponent.processEvent(Unknown Source)
     at java.awt.Component.dispatchEventImpl(Unknown Source)
     at java.awt.Container.dispatchEventImpl(Unknown Source)
     at java.awt.Component.dispatchEvent(Unknown Source)
     at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
     at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
     at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
     at java.awt.Container.dispatchEventImpl(Unknown Source)
     at java.awt.Component.dispatchEvent(Unknown Source)
     at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
     at java.awt.EventQueue.access$000(Unknown Source)
     at java.awt.EventQueue$1.run(Unknown Source)
     at java.awt.EventQueue$1.run(Unknown Source)
     at java.security.AccessController.doPrivileged(Native Method)
     at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
     at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
     at java.awt.EventQueue$2.run(Unknown Source)
     at java.awt.EventQueue$2.run(Unknown Source)
     at java.security.AccessController.doPrivileged(Native Method)
     at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
     at java.awt.EventQueue.dispatchEvent(Unknown Source)
     at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
     at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
     at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
     at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
     at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
     at java.awt.EventDispatchThread.run(Unknown Source)
Dumping class loader cache...
Live entry: key=http://192.168.10.100:7778/forms/java/,frmall.jar,siberia_jpg.jar,ApiConn.jar,Hasher.jar,ReadCommand.jar,WriteCommand.jar,libAPI.jar, refCount=1, threadGroup=sun.plugin2.applet.Applet2ThreadGroup[name=http://192.168.10.100:7778/forms/java/-threadGroup,maxpri=4]
Done.



in my form i have created a bean_area and used as implementation class :ApiConn

in my formsweb.cfg i used this configuration: archive=frmall.jar,siberia_jpg.jar,ApiConn.jar,Hasher.jar,ReadCommand.jar,WriteCommand.jar,libAPI.jar

in my forms/java i have placed my jar files listed in the frmall.jar


i guess i am missing something but i dont know what it is.
here is my ApiConn.java from wich i generate my jar file:

-------------------

package libAPI;

/*
* This contains connection. Everything should be here,
* should operate with this class only
*/


import java.io.*;
import java.net.*;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
*
* @author janisk
*/
public class ApiConn extends Thread {

private Socket sock = null;
private DataOutputStream out = null;
private DataInputStream in = null;
private String ipAddress;
private int ipPort;
private boolean connected = false;
private String message = "Not connected";
private ReadCommand readCommand = null;
private WriteCommand writeCommand = null;
private Thread listener = null;
LinkedBlockingQueue queue = new LinkedBlockingQueue(40);

/**
* Constructor of the connection class
* @param ipAddress - IP address of the router you want to conenct to
* @param ipPort - port used for connection, ROS default is 8728
*/
public ApiConn(String ipAddress, int ipPort) {
this.ipAddress = ipAddress;
this.ipPort = ipPort;
this.setName("settings");
}

/**
* State of connection
* @return - if connection is established to router it returns true.
*/
public boolean isConnected() {
return connected;
}
public void disconnect() throws IOException{
listener.interrupt();
sock.close();
}
private void listen() {
if (this.isConnected()) {
if (readCommand == null) {
readCommand = new ReadCommand(in, queue);
}
listener = new Thread(readCommand);
listener.setDaemon(true);
listener.setName("listener");
listener.start();

}
}

/**
* to get IP address of the connection. Reads data from socket created.
* @return InetAddress
*/
public InetAddress getIpAddress() {
return sock == null ? null : sock.getInetAddress();
}

/**
* returns ip address that socket is asociated with.
* @return InetAddress
*/
public InetAddress getLocalIpAddress() {
return sock == null ? null : sock.getLocalAddress();
}

/**
* Socket remote port number
* @return
*/
public int getPort() {
return sock == null ? null : sock.getPort();
}

/**
* return local prot used by socket
* @return
*/
public int getLocalPort() {
return sock == null ? null : sock.getLocalPort();
}

/**
* Returns status message set up bu class.
* @return
*/
public String getMessage() {
return message;
}

/**
* sets and exectues command (sends it to RouterOS host connected)
* @param s - command will be sent to RouterOS for example "/ip/address/print\n=follow="
* @return
*/
public String sendCommand(String s) {
return writeCommand.setCommand(s).runCommand();
}

/**
* exeecutes already set command.
* @return returns status of the command sent
*/
public String runCommand() {
return writeCommand.runCommand();
}

/**
* Tries to fech data that is repllied to commands sent. It will wait till it can return something.
* @return returns data sent by RouterOS
* @throws java.lang.InterruptedException
*/
public String getData() throws InterruptedException {
String s = (String) queue.take();
return s;
}

/**
* returns command that is set at this moment. And will be exectued if runCommand is exectued.
* @return
*/
public String getCommand() {
return writeCommand.getCommand();
}

/**
* set up method that will log you in
* @param name - username of the user on the router
* @param password - password for the user
* @return
*/
public String login(String name, char[] password) {
this.sendCommand("/login");
String s = "a";
try {
s = this.getData();
} catch (InterruptedException ex) {
Logger.getLogger(ApiConn.class.getName()).log(Level.SEVERE, null, ex);
return "failed read #1";
}
if (!s.contains("!trap") && s.length() > 4) {
String[] tmp = s.trim().split("\n");
if (tmp.length > 1) {
tmp = tmp[1].split("=ret=");
s = "";
String transition = tmp[tmp.length - 1];
String chal = "";
chal = Hasher.hexStrToStr("00") + new String(password) + Hasher.hexStrToStr(transition);
chal = Hasher.hashMD5(chal);
String m = "/login\n=name=" + name + "\n=response=00" + chal;
s = this.sendCommand(m);
try {
s = this.getData();
} catch (InterruptedException ex) {
Logger.getLogger(ApiConn.class.getName()).log(Level.SEVERE, null, ex);
return "failed read #2";
}
if (s.contains("!done")) {
if (!s.contains("!trap")) {
return "Login successful";
}
}
}
}
return "Login failed";
}
@Override
public void run() {
try {
InetAddress ia = InetAddress.getByName(ipAddress);
if (ia.isReachable(1000)) {
sock = new Socket(ipAddress, ipPort);
in = new DataInputStream(sock.getInputStream());
out = new DataOutputStream(sock.getOutputStream());
connected = true;
readCommand = new ReadCommand(in, queue);
writeCommand = new WriteCommand(out);
this.listen();
message = "Connected";
} else {
message = "Not reachable";
}
} catch (UnknownHostException ex) {
connected = false;
message = ex.getMessage();
ex.printStackTrace();
} catch (IOException ex) {
connected = false;
message = ex.getMessage();
ex.printStackTrace();
}
}
}
  • 1. Re: Problem using a jar file : java.lang.ClassNotFoundException: ApiConn
    Michael Ferrante (Oracle) Guru Moderator
    Currently Being Moderated
    Take a look at my last comment in this post where I mention extracting the contents of the jar to verify the directory structure.

    bean area
  • 2. Re: Problem using a jar file : java.lang.ClassNotFoundException: ApiConn
    Siberia Newbie
    Currently Being Moderated
    Hi Michael, thanks for soon answer.
    i have looked the file and when i opened with winrar i see one folder and one file:
    META-INF (folder)
    ApiConn.java (file)

    i am really new using about java files in oracle forms 10, i think that maybe i created my jar file in a wrong way. i used :
    jar cf ApiConn.jar ApiConn.java

    thanks for any tip
  • 3. Re: Problem using a jar file : java.lang.ClassNotFoundException: ApiConn
    Michael Ferrante (Oracle) Guru Moderator
    Currently Being Moderated
    Before you build the jar, you must first compile the java file so you end up with a .class file. The jar should contain the META directory (and its contents) and ApiConn.class when you are done.

    Notice the error:

    java.lang.*ClassNotFoundException*: ApiConn

    The key is "Class Not Found"
  • 4. Re: Problem using a jar file : java.lang.ClassNotFoundException: ApiConn
    Siberia Newbie
    Currently Being Moderated
    excellent observation Michale, sorry for this question.
    can you give some step to compile the jar ??
    thanks
  • 5. Re: Problem using a jar file : java.lang.ClassNotFoundException: ApiConn
    Michael Ferrante (Oracle) Guru Moderator
    Currently Being Moderated
    Let Google be your friend:

    Check out this doc:

    http://docs.oracle.com/javase/tutorial/getStarted/cupojava/win32.html
  • 6. Re: Problem using a jar file : java.lang.ClassNotFoundException: ApiConn
    Siberia Newbie
    Currently Being Moderated
    Hi Michael.
    look i made the compilation and i generated the classes. but i have still some errors, i know this is more a java question but i need your help.
    thanks in advance.


    1.- i opened the jar file in a winrar and got this structure:
    META-INF (folder)
    .....|MANIFEST.MF (file)
    build (folder)
    .....|classes (folder)
    ...........|libAPI (folder)
    ..................|ApiConn.class (file)
    ..................|Hasher.class (file)
    ..................|ReadCommand.class (file)
    ..................|WriteCommand.class (file)

    2.- in oracle forms java bean implementation class property i put : build.classes.libAPI.ApiConn


    3.- but i got this error in my console:
    Exception in thread "AWT-EventQueue-6" java.lang.NoClassDefFoundError: build/classes/libAPI/ApiConn (wrong name: libAPI/ApiConn)
         at java.lang.ClassLoader.defineClass1(Native Method)
         at java.lang.ClassLoader.defineClassCond(Unknown Source)
         at java.lang.ClassLoader.defineClass(Unknown Source)
         at java.security.SecureClassLoader.defineClass(Unknown Source)
         at java.net.URLClassLoader.defineClass(Unknown Source)
         at java.net.URLClassLoader.defineClass(Unknown Source)
         at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
         at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
         at java.lang.reflect.Method.invoke(Unknown Source)
         at sun.plugin2.applet.Plugin2ClassLoader.defineClassHelper(Unknown Source)
         at sun.plugin2.applet.Plugin2ClassLoader.access$100(Unknown Source)
         at sun.plugin2.applet.Plugin2ClassLoader$2.run(Unknown Source)
         at java.security.AccessController.doPrivileged(Native Method)
         at sun.plugin2.applet.Plugin2ClassLoader.findClassHelper(Unknown Source)
         at sun.plugin2.applet.Applet2ClassLoader.findClass(Unknown Source)
         at sun.plugin2.applet.Plugin2ClassLoader.loadClass0(Unknown Source)
         at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Unknown Source)
         at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Unknown Source)
         at java.lang.ClassLoader.loadClass(Unknown Source)
         at java.lang.Class.forName0(Native Method)
         at java.lang.Class.forName(Unknown Source)
         at oracle.forms.handler.UICommon.instantiate(Unknown Source)
         at oracle.forms.handler.UICommon.onCreate(Unknown Source)
         at oracle.forms.handler.JavaContainer.onCreate(Unknown Source)
         at oracle.forms.engine.Runform.onCreateHandler(Unknown Source)
         at oracle.forms.engine.Runform.processMessage(Unknown Source)
         at oracle.forms.engine.Runform.processSet(Unknown Source)
         at oracle.forms.engine.Runform.onMessageReal(Unknown Source)
         at oracle.forms.engine.Runform.onMessage(Unknown Source)
         at oracle.forms.engine.Runform.processEventEnd(Unknown Source)
         at oracle.ewt.lwAWT.LWComponent.redispatchEvent(Unknown Source)
         at oracle.ewt.lwAWT.LWComponent.processEvent(Unknown Source)
         at java.awt.Component.dispatchEventImpl(Unknown Source)
         at java.awt.Container.dispatchEventImpl(Unknown Source)
         at java.awt.Component.dispatchEvent(Unknown Source)
         at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
         at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
         at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
         at java.awt.Container.dispatchEventImpl(Unknown Source)
         at java.awt.Component.dispatchEvent(Unknown Source)
         at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
         at java.awt.EventQueue.access$000(Unknown Source)
         at java.awt.EventQueue$1.run(Unknown Source)
         at java.awt.EventQueue$1.run(Unknown Source)
         at java.security.AccessController.doPrivileged(Native Method)
         at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
         at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
         at java.awt.EventQueue$2.run(Unknown Source)
         at java.awt.EventQueue$2.run(Unknown Source)
         at java.security.AccessController.doPrivileged(Native Method)
         at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
         at java.awt.EventQueue.dispatchEvent(Unknown Source)
         at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
         at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
         at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
         at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
         at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
         at java.awt.EventDispatchThread.run(Unknown Source)

    Edited by: Siberia on Mar 14, 2013 7:26 PM
  • 7. java.lang.InstantiationException
    Siberia Newbie
    Currently Being Moderated
    I need your help again, i think this is a minor thing.
    i have compiled the class file that i needed and i signed it too. but now it is giving me a new error and need your tip.
    here is the java console loyout and my java file ((i think here is the problem in java file, something must be missing)).
    thanks in advance for any help.

    Java Plug-in 10.17.2.02
    Using JRE version 1.7.0_17-b02 Java HotSpot(TM) Client VM
    User home directory = C:\Users\Administrator
    ----------------------------------------------------
    c: clear console window
    f: finalize objects on finalization queue
    g: garbage collect
    h: display this help message
    l: dump classloader list
    m: print memory usage
    o: trigger logging
    q: hide console
    r: reload policy configuration
    s: dump system and deployment properties
    t: dump thread list
    v: dump thread stack
    x: clear classloader cache
    0-5: set trace level to <n>
    ----------------------------------------------------
    network: Connecting http://192.168.10.100:7778/forms/lservlet;jsessionid=c0a80a6430d6e191eded93774f2f8d1bed73056e66ef.e3mObhiMbxeKe34PahiKbx4Nbh90n6jAmljGr5XDqQLvpAe with proxy=DIRECT
    security: Validate the certificate chain using CertPath API
    security: The certificate hasnt been expired, no need to check timestamping info
    security: Cannot find jurisdiction list file
    security: The CRL support is disabled
    security: The OCSP support is disabled
    security: This OCSP End Entity validation is disabled
    security: Checking if certificate is in Deployment denied certificate store
    security: Checking if certificate is in Deployment permanent certificate store
    basic: updateValidationResultsForApplet update
    cache: Mark prevalidated: http://192.168.10.100:7778/forms/java/ApiConn.jar true tm=1363335797289 cert=1371107987000
    basic: Plugin2ClassLoader.getPermissions CeilingPolicy allPerms
    java.lang.InstantiationException: oracle.forms.siberia.ApiConn
         at java.lang.Class.newInstance0(Unknown Source)
         at java.lang.Class.newInstance(Unknown Source)
         at oracle.forms.handler.UICommon.instantiate(Unknown Source)
         at oracle.forms.handler.UICommon.onCreate(Unknown Source)
         at oracle.forms.handler.JavaContainer.onCreate(Unknown Source)
         at oracle.forms.engine.Runform.onCreateHandler(Unknown Source)
         at oracle.forms.engine.Runform.processMessage(Unknown Source)
         at oracle.forms.engine.Runform.processSet(Unknown Source)
         at oracle.forms.engine.Runform.onMessageReal(Unknown Source)
         at oracle.forms.engine.Runform.onMessage(Unknown Source)
         at oracle.forms.engine.Runform.processEventEnd(Unknown Source)
         at oracle.ewt.lwAWT.LWComponent.redispatchEvent(Unknown Source)
         at oracle.ewt.lwAWT.LWComponent.processEvent(Unknown Source)
         at java.awt.Component.dispatchEventImpl(Unknown Source)
         at java.awt.Container.dispatchEventImpl(Unknown Source)
         at java.awt.Component.dispatchEvent(Unknown Source)
         at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
         at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
         at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
         at java.awt.Container.dispatchEventImpl(Unknown Source)
         at java.awt.Component.dispatchEvent(Unknown Source)
         at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
         at java.awt.EventQueue.access$200(Unknown Source)
         at java.awt.EventQueue$3.run(Unknown Source)
         at java.awt.EventQueue$3.run(Unknown Source)
         at java.security.AccessController.doPrivileged(Native Method)
         at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
         at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
         at java.awt.EventQueue$4.run(Unknown Source)
         at java.awt.EventQueue$4.run(Unknown Source)
         at java.security.AccessController.doPrivileged(Native Method)
         at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
         at java.awt.EventQueue.dispatchEvent(Unknown Source)
         at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
         at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
         at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
         at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
         at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
         at java.awt.EventDispatchThread.run(Unknown Source)
    network: Connecting http://192.168.10.100:7778/forms/lservlet;jsessionid=c0a80a6430d6e191eded93774f2f8d1bed73056e66ef.e3mObhiMbxeKe34PahiKbx4Nbh90n6jAmljGr5XDqQLvpAe with proxy=DIRECT
    Exception in thread "Forms-DialogThread2" java.lang.NullPointerException
         at oracle.forms.handler.JavaContainer.onDestroy(Unknown Source)
         at oracle.forms.engine.Runform.destroyHandlers(Unknown Source)
         at oracle.forms.handler.DialogThread.doAlert(Unknown Source)
         at oracle.forms.handler.DialogThread.run(Unknown Source)
         at java.lang.Thread.run(Unknown Source)
    Dumping class loader cache...
    Live entry: key=http://192.168.10.100:7778/forms/java/,frmall.jar,siberia_jpg.jar,ApiConn.jar,ConcealTextField.jar, refCount=1, threadGroup=sun.plugin2.applet.Applet2ThreadGroup[name=http://192.168.10.100:7778/forms/java/-threadGroup,maxpri=4]
    Done.



    ----------------------------------------------------
    here is my java file
    /*
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    */

    package oracle.forms.siberia;

    /*
    * This contains connection. Everything should be here,
    * should operate with this class only
    */


    import java.io.*;
    import java.net.*;
    import java.util.concurrent.LinkedBlockingQueue;
    import java.util.logging.Level;
    import java.util.logging.Logger;
    import oracle.forms.*;

    /**
    *
    * @author janisk
    */
    public class ApiConn extends Thread {

    private Socket sock = null;
    private DataOutputStream out = null;
    private DataInputStream in = null;
    private String ipAddress;
    private int ipPort;
    private boolean connected = false;
    private String message = "Not connected";
    private ReadCommand readCommand = null;
    private WriteCommand writeCommand = null;
    private Thread listener = null;
    LinkedBlockingQueue queue = new LinkedBlockingQueue(40);

    /**
    * Constructor of the connection class
    * @param ipAddress - IP address of the router you want to conenct to
    * @param ipPort - port used for connection, ROS default is 8728
    */
    public ApiConn(String ipAddress, int ipPort) {
    this.ipAddress = ipAddress;
    this.ipPort = ipPort;
    this.setName("settings");
    }

    /**
    * State of connection
    * @return - if connection is established to router it returns true.
    */
    public boolean isConnected() {
    return connected;
    }
    public void disconnect() throws IOException{
    listener.interrupt();
    sock.close();
    }
    private void listen() {
    if (this.isConnected()) {
    if (readCommand == null) {
    readCommand = new ReadCommand(in, queue);
    }
    listener = new Thread(readCommand);
    listener.setDaemon(true);
    listener.setName("listener");
    listener.start();

    }
    }

    /**
    * to get IP address of the connection. Reads data from socket created.
    * @return InetAddress
    */
    public InetAddress getIpAddress() {
    return sock == null ? null : sock.getInetAddress();
    }

    /**
    * returns ip address that socket is asociated with.
    * @return InetAddress
    */
    public InetAddress getLocalIpAddress() {
    return sock == null ? null : sock.getLocalAddress();
    }

    /**
    * Socket remote port number
    * @return
    */
    public int getPort() {
    return sock == null ? null : sock.getPort();
    }

    /**
    * return local prot used by socket
    * @return
    */
    public int getLocalPort() {
    return sock == null ? null : sock.getLocalPort();
    }

    /**
    * Returns status message set up bu class.
    * @return
    */
    public String getMessage() {
    return message;
    }

    /**
    * sets and exectues command (sends it to RouterOS host connected)
    * @param s - command will be sent to RouterOS for example "/ip/address/print\n=follow="
    * @return
    */
    public String sendCommand(String s) {
    return writeCommand.setCommand(s).runCommand();
    }

    /**
    * exeecutes already set command.
    * @return returns status of the command sent
    */
    public String runCommand() {
    return writeCommand.runCommand();
    }

    /**
    * Tries to fech data that is repllied to commands sent. It will wait till it can return something.
    * @return returns data sent by RouterOS
    * @throws java.lang.InterruptedException
    */
    public String getData() throws InterruptedException {
    String s = (String) queue.take();
    return s;
    }

    /**
    * returns command that is set at this moment. And will be exectued if runCommand is exectued.
    * @return
    */
    public String getCommand() {
    return writeCommand.getCommand();
    }

    /**
    * set up method that will log you in
    * @param name - username of the user on the router
    * @param password - password for the user
    * @return
    */
    public String login(String name, char[] password) {
    this.sendCommand("/login");
    String s = "a";
    try {
    s = this.getData();
    } catch (InterruptedException ex) {
    Logger.getLogger(ApiConn.class.getName()).log(Level.SEVERE, null, ex);
    return "failed read #1";
    }
    if (!s.contains("!trap") && s.length() > 4) {
    String[] tmp = s.trim().split("\n");
    if (tmp.length > 1) {
    tmp = tmp[1].split("=ret=");
    s = "";
    String transition = tmp[tmp.length - 1];
    String chal = "";
    chal = Hasher.hexStrToStr("00") + new String(password) + Hasher.hexStrToStr(transition);
    chal = Hasher.hashMD5(chal);
    String m = "/login\n=name=" + name + "\n=response=00" + chal;
    s = this.sendCommand(m);
    try {
    s = this.getData();
    } catch (InterruptedException ex) {
    Logger.getLogger(ApiConn.class.getName()).log(Level.SEVERE, null, ex);
    return "failed read #2";
    }
    if (s.contains("!done")) {
    if (!s.contains("!trap")) {
    return "Login successful";
    }
    }
    }
    }
    return "Login failed";
    }
    @Override
    public void run() {
    try {
    InetAddress ia = InetAddress.getByName(ipAddress);
    if (ia.isReachable(1000)) {
    sock = new Socket(ipAddress, ipPort);
    in = new DataInputStream(sock.getInputStream());
    out = new DataOutputStream(sock.getOutputStream());
    connected = true;
    readCommand = new ReadCommand(in, queue);
    writeCommand = new WriteCommand(out);
    this.listen();
    message = "Connected";
    } else {
    message = "Not reachable";
    }
    } catch (UnknownHostException ex) {
    connected = false;
    message = ex.getMessage();
    ex.printStackTrace();
    } catch (IOException ex) {
    connected = false;
    message = ex.getMessage();
    ex.printStackTrace();
    }
    }
    }
  • 8. Re: java.lang.InstantiationException
    Michael Ferrante (Oracle) Guru Moderator
    Currently Being Moderated
    I don't see the "new" error, but it does look like you changed JRE versions and are not trying to use Java 7. It also looks like you might be using Forms 10. If this is the case, you cannot use Java 7 with Forms 10.

    Also, I would recommend that you clear the JRE cache between each test you run.
  • 9. Re: java.lang.InstantiationException
    Siberia Newbie
    Currently Being Moderated
    Hi Michael, thanks for reply.
    OK, if you see the error now says "java.lang.InstantiationException: oracle.forms.siberia.ApiCon", i looked for this error in the forum before posting and found this thread: https://forums.oracle.com/forums/thread.jspa?messageID=1938141&#1938141
    but really could not understand.
    what i can understand about the problem, is that it's something wrong about the java structure in the file, it seems to me that need some "adjust" to be used in a forms java bean. but i don't have a clue where to check.

    i used java 7 because when i compiled the java i got an error about this command "@Override", so i checked out and found that is only compatible with java 7, any way, my forms run perfectly using java RE 7.

    thanks
  • 10. Re: java.lang.InstantiationException
    Siberia Newbie
    Currently Being Moderated
    I've been reading on the web and I think I found the cause of my problem with java routine. in my forms I am using a java bean, but yet in the java file I'm using *"extends Thread"* instead of using *"extends VBean"* someone can suggest me how to change my java file to use "extends VBean"??

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points