class cast exception in engen eine jndi-reffrence in ejb

Ich bin versucht, zu schreiben eine einfache stateless sesssion Bohne aber ich habe ein problem mit schmalen Referenz gebe ich in lookup-Zeit.
Ich habe

Klasse cast Ausnahme

Benutze ich

eclipse IDE

meine bean-Klasse

package codes;
import java.rmi.RemoteException;

import javax.ejb.EJBException;
import javax.ejb.SessionBean;
import javax.ejb.SessionContext;


public class SinaBean implements SessionBean {


    /**
     * 
     */
    private static final long serialVersionUID = 1L;

    public String getHello()
    {
        return "hello";
    }
    public void ejbCreate(){

    }
    @Override
    public void ejbActivate() throws EJBException, RemoteException {
        //TODO Auto-generated method stub

    }

    @Override
    public void ejbPassivate() throws EJBException, RemoteException {
        //TODO Auto-generated method stub

    }

    @Override
    public void ejbRemove() throws EJBException, RemoteException {
        //TODO Auto-generated method stub

    }

    @Override
    public void setSessionContext(SessionContext arg0) throws EJBException,
            RemoteException {
        //TODO Auto-generated method stub

    }

}

mein home-Schnittstelle

package codes;

import java.rmi.RemoteException;

import javax.ejb.CreateException;
import javax.ejb.EJBHome;

public interface SinaHome extends EJBHome {

    public SinaObject create() throws RemoteException,CreateException;
}

meine Komponente

package codes;

import java.rmi.RemoteException;

import javax.ejb.EJBObject;

public interface SinaObject extends EJBObject {

    String getHello() throws RemoteException;
}

mein client

package codes;

import java.util.Properties;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.rmi.PortableRemoteObject;

public class Client {

    /**
     * @param args
     */
    public static void main(String[] args) {
        Context con=null;
        try {   
            Properties p=new Properties();
            p.setProperty(Context.INITIAL_CONTEXT_FACTORY,
            "org.jnp.interfaces.NamingContextFactory");
            p.setProperty(Context.PROVIDER_URL, "localhost:1099");
            p.setProperty(Context.URL_PKG_PREFIXES,
            "org.jboss.namingrg.jnp.interfaces");
            con = new InitialContext(p);
            Object o=con.lookup("SinaBean");
                       System.out.println(o);/***/untill know it works.it sysout : 
                       //org.jnp.interfaces.NamingContext@e83912*** 

            @SuppressWarnings("unused")
            SinaHome sh=(SinaHome)PortableRemoteObject.narrow(o, SinaHome.class);//***exeption is here!!***
        } catch (Exception e) {
            //TODO Auto-generated catch block
            e.printStackTrace();
        }


    }

}

meine xml-Datei

<?xml version="1.0" encoding="UTF-8"?>
<ejb-jar version="3.0" 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/ejb-jar_3_0.xsd">
  <display-name>Ejb </display-name> 
  <enterprise-beans>

  <session>

  <display-name>SinaBean</display-name>
  <ejb-name>SinaBean</ejb-name>
  <home>codes.SinaHome</home>
  <remote>codes.SinaObject</remote>
  <ejb-class>codes.SinaBean</ejb-class> 
  <session-type>Stateless</session-type>
  <transaction-type>Bean</transaction-type> 

  <security-identity>
  <description></description>
  <use-caller-identity></use-caller-identity>
  </security-identity> 

  </session>

  </enterprise-beans>

 </ejb-jar>

Ausnahme, die ich erhalten

java.lang.ClassCastException
    at com.sun.corba.se.impl.javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:229)
    at javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:137)
    at codes.Client.main(Client.java:27)
Caused by: java.lang.ClassCastException: org.jnp.interfaces.NamingContext cannot be cast to org.omg.CORBA.Object
    at com.sun.corba.se.impl.javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:212)
    ... 2 more

Werde ich sehr dankbar für Eure Ratschläge.

InformationsquelleAutor sara | 2011-07-25
Schreibe einen Kommentar