first program in J2EE


Z

zbiszko

Hi

I was trying to write my first program in J2EE, but something is wrong
in my code and I cannot find the bug:(

I have create EJB Module :Conv-ejb containning such files:
ConverterBean, ConverterLocal, ConverterRemote.
Also I have created client aplication. When I am running the clint I
get such exception:
Wyj±tek!!
javax.naming.NameNotFoundException
at
com.sun.enterprise.naming.TransientContext.resolveContext(TransientContext.java:
268)
at
com.sun.enterprise.naming.TransientContext.lookup(TransientContext.java:
191)
at
com.sun.enterprise.naming.SerialContextProviderImpl.lookup(SerialContextProviderImpl.java:
74)
at
com.sun.enterprise.naming.RemoteSerialContextProviderImpl.lookup(RemoteSerialContextProviderImpl.java:
129)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:
39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl..java:
25)
at java.lang.reflect.Method.invoke(Method.java:597)
at
com.sun.corba.ee.impl.presentation.rmi.ReflectiveTie._invoke(ReflectiveTie.java:
154)
at
com.sun.corba.ee.impl.protocol.CorbaServerRequestDispatcherImpl.dispatchToServant(CorbaServerRequestDispatcherImpl.java:
687)
at
com.sun.corba.ee.impl.protocol.CorbaServerRequestDispatcherImpl.dispatch(CorbaServerRequestDispatcherImpl.java:
227)
at
com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.handleRequestRequest(CorbaMessageMediatorImpl.java:
1846)
at
com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.handleRequest(CorbaMessageMediatorImpl.java:
1706)
at
com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.handleInput(CorbaMessageMediatorImpl.java:
1088)
at
com.sun.corba.ee.impl.protocol.giopmsgheaders.RequestMessage_1_2.callback(RequestMessage_1_2.java:
223)
at
com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.handleRequest(CorbaMessageMediatorImpl.java:
806)
at
com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.dispatch(CorbaMessageMediatorImpl.java:
563)
at
com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.doWork(CorbaMessageMediatorImpl.java:
2567)
at
com.sun.corba.ee.impl.orbutil.threadpool.ThreadPoolImpl
$WorkerThread.run(ThreadPoolImpl.java:555)

What is wrong in my code? I am using netbeans.

Thanks for any help:)
Best Regards
Mariusz

################
files:

################ file: ConverterBean

package conv;

import java.rmi.RemoteException;
import javax.ejb.EJBException;
import javax.ejb.Remote;
import javax.ejb.SessionBean;
//import javax.ejb.Stateless;
import javax.ejb.SessionContext;
import javax.ejb.Stateless;

/**
*
* @author mariusz
*/
@Stateless
@Remote(ConverterRemote.class)
public class ConverterBean implements SessionBean{

public int getValue(String letter)
throws RemoteException
{
if (letter.equals("a"))
return 1;
else
return 2;
}

public ConverterBean() {}
public void setSessionContext(SessionContext arg0){ }
public void ejbRemove() { }
public void ejbActivate() { }
public void ejbPassivate() { }

}

################

################ file: ConverterLocal

package conv;

import java.rmi.RemoteException;
import javax.ejb.CreateException;
import javax.ejb.EJBHome;
import javax.ejb.Local;

/**
*
* @author mariusz
*/
@Local
public interface ConverterLocal extends EJBHome
{
ConverterRemote create()
throws RemoteException, CreateException;
}

################

################ file ConverterRemote
package conv;

import java.rmi.RemoteException;
import javax.ejb.EJBObject;
import javax.ejb.Remote;

/**
*
* @author mariusz
*/
@Remote
public interface ConverterRemote extends EJBObject
{
public int getValue(String letter)
throws RemoteException;
################

################ client aplication
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

package convClient;

import conv.ConverterLocal;
import conv.ConverterRemote;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.rmi.PortableRemoteObject;

/**
*
* @author mariusz
*/
public class Main {

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
try {
Context initial = new InitialContext();
Context myEnv = (Context) initial.lookup("java:comp/env");
Object objRef = myEnv.lookup("MyConverterBean");
ConverterLocal home = (ConverterLocal)
PortableRemoteObject.narrow(objRef, ConverterLocal.class);
ConverterRemote conv = home.create();

int a1 = conv.getValue("a");
int a2 = conv.getValue("b");

System.out.println("\nlicz1 = "+a1);
System.out.println("\nlicz2 = "+a2);
System.exit(0);

} catch (Exception ex)
{
System.err.println("Wyj±tek!!");
ex.printStackTrace();
}
}
}

################

################ application-client.xml
<?xml version="1.0" encoding="UTF-8"?>
<application-client version="5" xmlns="http://java.sun.com/xml/ns/
javaee";
xmlns:xsi="http://www.w3.org/2001/XMLSchema-
instance";
xsi:schemaLocation="http://java.sun.com/xml/ns/
javaee

http://java.sun.com/xml/ns/javaee/application-client_5.xsd">;

<display-name>Conv-app-client</display-name>
<ejb-ref>
<ejb-ref-name>MyConverterBean</ejb-ref-name>
<ejb-ref-type>Session</ejb-ref-type>
<remote>conv.ConverterRemote</remote>
</ejb-ref>

</application-client>
 
Ad

Advertisements


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top