Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

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!

Can a EJB Client Application use javax.comm

843829May 21 2003 — edited May 22 2003
I post a message a couple of days ago trying to find out if you could use javax.comm with an EJB. I have now found out this is not allowed within the specification of EJB's. However I have changed my design and now I`m thinking of using a client machine, which will access EJB's, to access the Javax.comm api and thus the serial ports. Here`s my problem...

I have a simple entity bean to access on a app server but when I try and run my client with the javax.comm api and try to ennumerate the ports I get several error messages, shown below.

Initiating login
Enter Username: //no password needed
Enter Password: //no password needed
Binding name:`java:comp/env/ejb/RmciHomeRemote`
Caught java.lang.NullPointerException: name can't be null while loading driver
java.lang.NullPointerException: name can't be null
at java.io.FilePermission.init(FilePermission.java:165)
at java.io.FilePermission.<init>(FilePermission.java:253)
at java.lang.SecurityManager.checkDelete(SecurityManager.java:1002)
at javax.comm.CommPortIdentifier.getPortIdentifiers(CommPortIdentifier.j
ava:70)
at uk.ac.york.clients.RmciClient.getPortNames(Unknown Source)
at uk.ac.york.clients.RmciClient.<init>(Unknown Source)
at uk.ac.york.clients.RmciClient.main(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at com.sun.enterprise.util.Utility.invokeApplicationMain(Utility.java:22
9)
at com.sun.enterprise.appclient.Main.main(Main.java:155)
The system cannot find the path specified.

-------
What does all this mean?? I get the feeling its something to do with the policy files that are executed when using runclient.bat but i don`t really understand them.

I don`t know why its so hard to perform this opereation. If a client cannot access i/o (files or ports) whats the point of this whole EJB stuff if your client, for example, cannot save simple data to a file or other medium. I agree that the Entity and session beans be strictly platform independant but why do the clients have to be??

any help would be most appreciated. please find below the code thats giving me so much trouble...

Michael B
public class RmciClient {
    private Vector portVector;
    private String portNames[];
    private String names[];
    private CommPortIdentifier portId;

    public RmciClient(){
       try {
           Context jndiContext = getInitialContext();
           Object obj = jndiContext.lookup("RmciHomeRemote");
           RmciHomeRemote home = (RmciHomeRemote)  PortableRemoteObject.narrow(obj, RmciHomeRemote.class);

           System.out.println("attempting to get port names...");
           names = getPortNames();
           System.out.println("got names...");
           if (names!=null){

             for ( int i=0; i < names.length; i++ ){
                System.out.println("about to print name...");
                System.out.println("port: "+names[i]+" Found");
                 Integer primaryKey = new Integer(i+1);
                    //put port names in first and last name 
                    RmciRemote rmci = home.create(primaryKey);
                    rmci.setFirstName("portName:"+names);
rmci.setLastName("portName:"+names[i]);
rmci.setHasGoodCredit(true);
System.out.println("sent the name :"+names[i]+" to server to hold");
rmci.remove();
System.out.println("remove the name :"+names[i]+" from the server");
}
}
else{
System.out.println("No names to give");
}
}catch (java.rmi.RemoteException re){re.printStackTrace();}
catch (Throwable t){t.printStackTrace();}

}


public String[] getPortNames(){
String drivername = "com.sun.comm.Win32Driver";
try {
CommDriver driver = (CommDriver)Class.forName
(drivername).newInstance();
driver.initialize();
System.out.println("Got Win32Driver");
}
catch (Throwable th) {
System.err.println( "Caught " + th+ " while loading driver ");
}
//***i think this is the main problem -> getPortIdentifiers()***
Enumeration en = CommPortIdentifier.getPortIdentifiers();
// iterate through the serial ports.
Vector portVector = new Vector();
while (en.hasMoreElements()) {
portId = (CommPortIdentifier) en.nextElement();
if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL){
portVector.addElement(portId.getName());
}
}
//place all names in array of strings
portNames = new String[ portVector.size() ];
for (int i = 0 ; i < portNames.length ; i++){
portNames[i] = (String)portVector.elementAt(i);
}
//returns array of strings with port names
return portNames;
}

public static void main(String [] args) {
RmciClient client = new RmciClient();
System.exit(0);
}

public static Context getInitialContext()
throws javax.naming.NamingException {
return new InitialContext();
}
}

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 19 2003
Added on May 21 2003
2 comments
114 views