Java.io.NotSerializableException  exception in session beans

Hey experts,
I have written the following code to call a session bean method from a portal application.
               Object obj1 = context.lookup("applications/knet");
               UserInfoHome userInfoHome =
                                   (UserInfoHome) javax.rmi.PortableRemoteObject.narrow(
                                   obj1,
                                   UserInfoHome.class);
               UserInfo userInfo = userInfoHome.create();
               Collection col =
                              userInfo.getAllrooms();
               out.println("The size is  " + col.size() + "<br>");
The following is the implementation of the getAllrooms() method in the session bean
     public Collection getAllrooms() {
          Collection col = null;
          try {
               InitialContext ctx = new InitialContext();
               roomsHome = (RoomsLocalHome) ctx.lookup("java:comp/env/ejb/RoomsBean");
               col = roomsHome.findAllRooms();
          } catch (NamingException e) {
               // TODO Auto-generated catch block
               e.printStackTrace();
          } catch (FinderException e) {
               // TODO Auto-generated catch block
               e.printStackTrace();
          return col;
In the entity bean the following EJB QL has been used
<EJB QL>
    select object(r) from Rooms r
</<EJB QL>>
I get the following error
com.sap.engine.services.rmi_p4.exception.P4BaseRuntimeException: I/O operation failed : java.io.NotSerializableException: com.sap.engine.services.ejb.entity.finder.EJBLocalCollection :
        at com.sap.engine.services.rmi_p4.server.P4ObjectBrokerServerImpl.getException(P4ObjectBrokerServerImpl.java:926)
        at com.sap.engine.services.rmi_p4.reflect.LocalInvocationHandler.replicateReturnValue(LocalInvocationHandler.java:115)
        at com.sap.engine.services.rmi_p4.reflect.LocalInvocationHandler.invokeInternal(LocalInvocationHandler.java:90)
        at com.sap.engine.services.rmi_p4.reflect.AbstractInvocationHandler.invoke(AbstractInvocationHandler.java:50)
        at $Proxy180.getAllrooms(Unknown Source)
        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:324)
        at com.sap.engine.services.ejb.session.stateless_sp5.ObjectStubProxyImpl.invoke(ObjectStubProxyImpl.java:187)
        at $Proxy181.getAllrooms(Unknown Source)
        at com.watercorp.BMS.test.EJBTest.doContent(EJBTest.java:120)
        at com.sapportals.portal.prt.component.AbstractPortalComponent.serviceDeprecated(AbstractPortalComponent.java:209)
        at com.sapportals.portal.prt.component.AbstractPortalComponent.service(AbstractPortalComponent.java:114)
        at com.sapportals.portal.prt.core.PortalRequestManager.callPortalComponent(PortalRequestManager.java:328)
        ... 29 more
Caused by: java.io.NotSerializableException: com.sap.engine.services.ejb.entity.finder.EJBLocalCollection
        at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1054)
        at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:278)
        at com.sap.engine.services.rmi_p4.reflect.LocalInvocationHandler.replicateReturnValue(LocalInvocationHandler.java:110)
        ... 42 more
Please help

Hi Sabbir,
You are trying to expose a Collection of Entity local interfaces (RoomsLocal) that is the result of RoomsLocalHome.findAllRooms(), through the Session bean's remote interface method getAllrooms(). This is forbidden by the EJB specification and of course cannot work. You have to use remote interfaces of Entity beans when you want to expose them to remote clients - although this is not a good practice either since Entity beans are fine-grained components. Data transfer objects (<a href="http://en.wikipedia.org/wiki/Data_Transfer_Object">DTO</a>) with Session facades should be used for this purpose (you already have a Session facade - the UserInfo bean).
Hope this clarifies it!
-Vladimir
Message was edited by:
        Vladimir Pavlov

Similar Messages

  • The client is a pure-Java client, how to invoke session bean in oc4j server

    I WOULD LIKE TO INVOKE MY SESSION BEAN FROM MY STRUT WEB PROJECT AS A PURE JAVA CLIENT . I SETUP THE JNDI INITIAL CONTEXT PROPERTY BUT I HAVE NO IDEA TO WHERE I SHALL PUT MY application-client.xml and orion-application-client.xml. MY APPLICATION THROW EXCEPTION
    NamingException: StoreEJB not found
    IF YOU ANY EXAMPLE PLEASE SEND ME
    THIS IS MY CLIENT PROGRAME
    package ejbs;
    import java.io.*;
    import javax.ejb.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import javax.naming.*;
    import javax.rmi.*;
    import java.rmi.*;
    import java.util.*;
    public class StrutInt {
         * @param args
         public static void main(String[] args) {
              //System.out.print("The application Checkup");
              try
                   Hashtable env = new Hashtable();
                   env.put (Context.INITIAL_CONTEXT_FACTORY,
                   "oracle.j2ee.naming.ApplicationClientInitialContextFactory");
                   env.put (Context.SECURITY_PRINCIPAL, "oc4jadmin");
                   env.put (Context.SECURITY_CREDENTIALS, "admin");
                   //env.put (Context.PROVIDER_URL, "http://localhost:8888");
                   env.put (Context.PROVIDER_URL, "ormi://localhost:23791/EjbIntegrationEAR");
                   env.put ("dedicated.rmicontext", "true"); // for 9.0.2.1 and above
                   Context context = new InitialContext (env);
                   System.out.println("work up to this");
              Object homeObject =
    context.lookup("StoreEJB");
              System.out.print("Hi Integration");
         StoreHome storeHome = (StoreHome) PortableRemoteObject
                   .narrow(homeObject, StoreHome.class);
         Store exa= storeHome.create();
              String s =exa.foo("The foul guy");
              System.out.print(s);
         catch(NamingException e1) {
         System.err.println("NamingException: " + e1.getMessage());
         catch(RemoteException e2) {
         System.err.println("RemoteException: " + e2.getMessage());
         catch(CreateException e3) {
         System.err.println("FinderException: " + e3.getMessage());
         catch(Exception e4) {
         System.err.println("FinderException: " + e4.getMessage());
         }

    Create the object of InitialContest class. Then pass in hashTable put WLContextFactory.
    then lookup to the sessionJNDI. then call the create method u will get the remote object, from the remote object u can call to the business method

  • Java.io in J2ee stateless session bean, general questions about debugging

    Doing conventional Java IO (with java.io functions and classes such as
    PrintWriter and println) in a Enterprise bean has been discussed before
    in this and other forum. We know that the EJB specification says not to do it.
    (For example the EJB 2.0 spec, 24.1.2) says that an enterprise
    bean must not use the java.io package to attempt to access files and
    directories int he file system."
    The discussion in various forums including this one is that
    a) using java.io in a bean would impact portability, ability to
    move the bean for load balancing
    b) However, this is not always an an issue and it may be reasonable
    to use these functions anyway. e. g. see the response by "maozhoulu"
    on Jun 21, 2002.
    I tried it in Sun Application Server Nine in my stateless Session Bean:
    package RS;
    import RS.CourseHome;
    import RS.CoursePK;
    import java.rmi.RemoteException;
    import javax.naming.InitialContext;
    import javax.naming.Context;
    import javax.rmi.PortableRemoteObject;
    import javax.ejb.EJBException;
    import java.io.*;
    public class AddCourseBean implements javax.ejb.SessionBean {
       public void ejbCreate(){};
       public void CreateCourse (int CourseNumber, String CourseName) {
        try {
         System.out.println("in Create Course");
         PrintWriter F = null;
         try {
          F = new PrintWriter (new FileOutputStream("/tmp/v/af"));
         catch (java.io.FileNotFoundException fe){}
         F.println ("here zero");F.flush();
         InitialContext jndiContext = new InitialContext();
         F.println ("here one");F.flush();
         Object o = jndiContext.lookup("ejb/X");
             ...I got a Null pointer exception on the line:
    "F.println("here zero"); Is there anyway one can do simple debugging with print lines in one's beans?
    Or is there something obviousthat I am overlooking? (I saw mention of doing
    debugging with System.out.println but to where would the bean write?)
    I tried using the Jakarta Commons Logging, but I got a
    java.lang.NoClassDefFoundError on org/apache/commons/logging/LogFactory
    Which logging system does one use in GlassFish, hopefully one with minimal
    configuration? I want to do some debugging, not set up logging for a full
    enterprise system.
    Thanks for your insight and advice.
    Dr. Laurence Leff, Associate Professor of Computer Science WIU ST447 61455
    Pager 309 367 0787, Fax 309 298 2302

    My apology for posting this message twice. I looked for it before and
    did not see it. I thought I forget to click the "Post message" button.
    Also, I did resolve one problem. System.out.println does go to
    the log file, which in my case turned out to be:
    /opt/j2ee/SUNWappserver/domains/domain1/logs/server.log
    (Obvously, the first part would vary based upon where you installed your
    Application Server Nine.)
    However, it would be nice if there was some way to use FILE I/O inside of
    beans. I am teaching some J2EE in the graduate software engineering course,
    and I believe this would be pedagogically sound even if other techniques
    would be appropriate for a production environment.
    Thanks for your patience with this problem and my duplicate post.

  • Getting java.io.NotSerializableException exception

    Hi All,
    I am getting the java.io.NotSerializableException when using FacesContext.getCurrentInstance().getExternalContext().getSessionMap().put("DATA_LIST",dataList); in the bean. Can any one tell me the solution.
    WARNING: Cannot serialize session attribute DATA_LIST for session B4270E3F0D63D10FF5E83D057AF4EE88
    java.io.NotSerializableException: com.ColorBO
    at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1054)
    at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:278)
    at java.util.ArrayList.writeObject(ArrayList.java:529)
    at sun.reflect.GeneratedMethodAccessor164.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:324)
    at java.io.ObjectStreamClass.invokeWriteObject(ObjectStreamClass.java:809)
    at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1296)
    at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1247)
    at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1052)
    at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:278)
    at org.apache.catalina.session.StandardSession.writeObject(StandardSession.java:1445)
    at org.apache.catalina.session.StandardSession.writeObjectData(StandardSession.java:920)
    at org.apache.catalina.session.StandardManager.doUnload(StandardManager.java:516)
    at org.apache.catalina.session.StandardManager.unload(StandardManager.java:462)
    at org.apache.catalina.session.StandardManager.stop(StandardManager.java:664)
    at org.apache.catalina.core.StandardContext.stop(StandardContext.java:4255)
    at org.apache.catalina.manager.ManagerServlet.undeploy(ManagerServlet.java:1283)
    at org.apache.catalina.manager.ManagerServlet.doGet(ManagerServlet.java:372)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
    at org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:168)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:482)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:856)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:744)
    at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
    at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
    at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
    at java.lang.Thread.run(Thread.java:534)
    Oct 25, 2006 11:28:38 PM org.apache.catalina.session.StandardSession writeObject
    WARNING: Cannot serialize session attribute DATA_LIST for session 46A81579BFE42E28F2AE5BBA7D091710
    java.io.NotSerializableException: com.ColorBO
    at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1054)
    at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:278)
    at java.util.ArrayList.writeObject(ArrayList.java:529)
    at sun.reflect.GeneratedMethodAccessor164.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:324)
    at java.io.ObjectStreamClass.invokeWriteObject(ObjectStreamClass.java:809)
    at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1296)
    at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1247)
    at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1052)
    at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:278)
    at org.apache.catalina.session.StandardSession.writeObject(StandardSession.java:1445)
    at org.apache.catalina.session.StandardSession.writeObjectData(StandardSession.java:920)
    at org.apache.catalina.session.StandardManager.doUnload(StandardManager.java:516)
    at org.apache.catalina.session.StandardManager.unload(StandardManager.java:462)
    at org.apache.catalina.session.StandardManager.stop(StandardManager.java:664)
    at org.apache.catalina.core.StandardContext.stop(StandardContext.java:4255)
    at org.apache.catalina.core.ContainerBase.removeChild(ContainerBase.java:892)
    at org.apache.catalina.startup.HostConfig.undeployApps(HostConfig.java:1143)
    at org.apache.catalina.startup.HostConfig.stop(HostConfig.java:1115)
    at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:313)
    at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
    at org.apache.catalina.core.ContainerBase.stop(ContainerBase.java:1053)
    at org.apache.catalina.core.ContainerBase.stop(ContainerBase.java:1065)
    at org.apache.catalina.core.StandardEngine.stop(StandardEngine.java:447)
    at org.apache.catalina.core.StandardService.stop(StandardService.java:512)
    at org.apache.catalina.core.StandardServer.stop(StandardServer.java:717)
    at org.apache.catalina.startup.Catalina.stop(Catalina.java:586)
    at org.apache.catalina.startup.Catalina.start(Catalina.java:561)
    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:324)
    at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:271)

    The object in the list should implement serializable

  • Java.lang.NoSuchMethodError implementing stateless session bean

    Hello all,
    I am running Weblogic 5.1 on Windows 2000 using the JDK 1.2.2 and the
    J2SDKEE 1.2.1.
    I have created and successful deployed a state session bean as provided
    by the example given at this url:
    http://www.weblogic.com/docs51/examples/ejb/basic/statelessSession/index.html
    Upon running the client I get the following error:
    Beginning TraderClient...
    user: system
    Creating a trader
    There was an exception while creating and using the Trader.
    This indicates that there was a problem communicating with the server:
    java.rmi.RemoteException: ; nested exception is:
         weblogic.rmi.ServerError: A RemoteException occurred in the server method
    - with nested exception:
    [java.lang.NoSuchMethodError: weblogic.ejb.internal.EJBHomeImpl: method
    findMethodInfo(Ljava/lang/String;)Lweblogic/ejb/internal/MethodInfo; not
    found]
    End statelessSession.Client...
    Here is my classpath for starting the Trader Client:
    java -ms64m -mx128m -classpath
    %WEBLOGIC_HOME%\classes;%WEBLOGIC_HOME%\lib\weblogic510sp11.jar;%WEBLOGIC_HOME%\lib\weblogic510sp11boot.jar;%WEBLOGIC_HOME%\lib\weblogicaux.jar;%WEBLOGIC_HOME%\lib\weblogicbeans.jar;%WEBLOGIC_HOME%\lib\weblogic-tags-510.jar;%WEBLOGIC_HOME%\lib\rmiForMs;%J2SDK_HOME%/lib/j2ee.jar;D:\jdk1.2.2/lib/dt.jar;%PM_ROOT%/lib/hoejbserver.jar;%PM_ROOT%/lib/jcert.jar;%PM_ROOT%/lib/jndi.jar;%PM_ROOT%/lib/jnet.jar;%PM_ROOT%/lib/jsse.jar;%PM_ROOT%/lib/junit.jar;%PM_ROOT%/lib/ldap.jar;%PM_ROOT%/lib/pminput.jar;%PM_ROOT%/lib/pmipdr.jar;%PM_ROOT%/lib/pmopenview.jar;%PM_ROOT%/lib/pmtmn.jar;%PM_ROOT%/lib/pmtools.jar;%PM_ROOT%/lib/pmutil.jar;%PM_ROOT%/lib/pricemaker.jar;%PM_ROOT%/lib/providerutil.jar;%PM_ROOT%/lib/test.jar;%PM_ROOT%/lib/classes12.zip;%PM_ROOT%/lib/hoejbserver.jar;%PM_ROOT%/lib/hoejbclient.jar
    com.rii.pricemaker.ho.ejb.client.trader.TraderClient
    "t3://localhost:7001" "system" "weblogic"
    Here is my startup script for the web logic server:
    java -classpath c:\weblogic\classes\boot
    -Dweblogic.class.path=c:\weblogic\classes;c:\weblogic\license;c:\weblogic\lib\weblogicaux.jar;c:\weblogic\myserver\serverclasses
    -Djava.security.manager
    -Djava.security.policy==c:\weblogic\weblogic.policy
    -Dweblogic.system.home=c:\weblogic weblogic.Server
    Could anyone please give me a clue as to what I might be doing wrong?
    Thanks
    Bediako George

    Thanks alot Matthew, reordering my classpath as follows when starting
    the server did the trick:
    java -classpath
    c:\weblogic\lib\weblogic510sp11boot.jar;c:\weblogic\classes\boot;
    -Dweblogic.class.path=C:\weblogic\lib\weblogic510sp11.jar;c:\weblogic\classes;c:\weblogic\license;c:\weblogic\lib\weblogicaux.jar;c:\weblogic\myserver\serverclasses
    -Djava.security.manager
    -Djava.security.policy==c:\weblogic\weblogic.policy
    -Dweblogic.system.home=c:\weblogic weblogic.Server
    I am placing this here as a benefit to others.
    Thanks again,
    Bediako
    Matthew Shinn wrote:
    Hi,
    You might try running ejbc on the jar file again. Also, if your server has a service pack installed, make sure it is at the head of the classpath when invoking ejbc.
    - Matt
    Bediako George wrote:
    Hello all,
    I am running Weblogic 5.1 on Windows 2000 using the JDK 1.2.2 and the
    J2SDKEE 1.2.1.
    I have created and successful deployed a state session bean as provided
    by the example given at this url:
    http://www.weblogic.com/docs51/examples/ejb/basic/statelessSession/index.html
    Upon running the client I get the following error:
    Beginning TraderClient...
    user: system
    Creating a trader
    There was an exception while creating and using the Trader.
    This indicates that there was a problem communicating with the server:
    java.rmi.RemoteException: ; nested exception is:
    weblogic.rmi.ServerError: A RemoteException occurred in the server method
    - with nested exception:
    [java.lang.NoSuchMethodError: weblogic.ejb.internal.EJBHomeImpl: method
    findMethodInfo(Ljava/lang/String;)Lweblogic/ejb/internal/MethodInfo; not
    found]
    End statelessSession.Client...
    Here is my classpath for starting the Trader Client:
    java -ms64m -mx128m -classpath
    %WEBLOGIC_HOME%\classes;%WEBLOGIC_HOME%\lib\weblogic510sp11.jar;%WEBLOGIC_HOME%\lib\weblogic510sp11boot.jar;%WEBLOGIC_HOME%\lib\weblogicaux.jar;%WEBLOGIC_HOME%\lib\weblogicbeans.jar;%WEBLOGIC_HOME%\lib\weblogic-tags-510.jar;%WEBLOGIC_HOME%\lib\rmiForMs;%J2SDK_HOME%/lib/j2ee.jar;D:\jdk1.2.2/lib/dt.jar;%PM_ROOT%/lib/hoejbserver.jar;%PM_ROOT%/lib/jcert.jar;%PM_ROOT%/lib/jndi.jar;%PM_ROOT%/lib/jnet.jar;%PM_ROOT%/lib/jsse.jar;%PM_ROOT%/lib/junit.jar;%PM_ROOT%/lib/ldap.jar;%PM_ROOT%/lib/pminput.jar;%PM_ROOT%/lib/pmipdr.jar;%PM_ROOT%/lib/pmopenview.jar;%PM_ROOT%/lib/pmtmn.jar;%PM_ROOT%/lib/pmtools.jar;%PM_ROOT%/lib/pmutil.jar;%PM_ROOT%/lib/pricemaker.jar;%PM_ROOT%/lib/providerutil.jar;%PM_ROOT%/lib/test.jar;%PM_ROOT%/lib/classes12.zip;%PM_ROOT%/lib/hoejbserver.jar;%PM_ROOT%/lib/hoejbclient.jar
    com.rii.pricemaker.ho.ejb.client.trader.TraderClient
    "t3://localhost:7001" "system" "weblogic"
    Here is my startup script for the web logic server:
    java -classpath c:\weblogic\classes\boot
    -Dweblogic.class.path=c:\weblogic\classes;c:\weblogic\license;c:\weblogic\lib\weblogicaux.jar;c:\weblogic\myserver\serverclasses
    -Djava.security.manager
    -Djava.security.policy==c:\weblogic\weblogic.policy
    -Dweblogic.system.home=c:\weblogic weblogic.Server
    Could anyone please give me a clue as to what I might be doing wrong?
    Thanks
    Bediako George

  • Handling Rollback exception in Session Beans

    From my session bean,I am making calls to other entity beans in a single Transaction in Websphere.The code is like this:
    UserTransaction trans=getSessionContext().getUserTransaction();
    trans.begin();
    //ejb calls to entity beans
    trans.commit();
    The problem is that the commit never happens and it always throws a rollback exception and I am unable to proceed further and I am not able to understand the reason behind this at all.Please help out.

    Hi
    First tell whether ur Tables supports Transactions.
    u plz forward the exception,
    b'cos i tried
    UserTransaction ut = (UserTransaction)initial.lookup("java:comp/UserTransaction");
    & it works perfectly in tomcat.
    Parag

  • Any difference in creating a web service from a java class or session bean?

    Hi,
    The JDeveloper tutorial at http://www.oracle.com/technology/obe/obe1013jdev/10131/devdepandmanagingws/devdepandmanagingws.htm demonstrates creating a web service from a plain java class. I'm wondering:
    - Is it possible to create a web service from a stateless session bean instead of a java class? If so, what's the proper way to do this in JDeveloper? When I tried doing so in JDeveloper 10.1.3.0.4 (SU5) using the J2EE Web Service wizard, the wizard did not list the session bean in the Component To Publish dropdown (it does list any java classes available in the project). I can proceed by manually typing in the name of the session bean. After the wizard completes though, the @Stateless annotation that had been in my session bean class code is removed and replaced by a @WebService annotation. The end result is that it looks like it made no difference whether I had tried to create the web service from a session bean or plain java class as the annotations in the resulting web service code are the same (although if I had started from a session bean, the class for the web service still implements the Local/Remote EJB interface that the session bean originally implemented).
    - Assuming it's possible to create a web service from a stateless session bean, is there any advantage/disadvantage creating a web service from a java class vs a stateless session bean? I'm creating the web service from scratch so I also need to either build the java class or stateless session bean the web service would be based on from scratch too.
    Thanks for any ideas about this.

    Hi,
    EJB Session beans (EJB 3.0) are deployed as WebServices by annotating the class with @WebService and the methds with @WebMethod (both tags require you to add the JSR-181 library to your project (available in the JDeveloper list of libraries)). Unlike the J2E WebService, the EJB session bean service is turned into a WebService upon deployment. This means you obtain teh WSDL file after deployment
    - Assuming it's possible to create a web service from a stateless session bean, is there any advantage/disadvantage creating a web service from a java class vs a stateless session bean?
    The difference is that EJB Session bean based web services are integrated with the J2EE container, which means that they can leverage container services like transaction handling, data sources, security, JMS etc.
    Frank

  • Java.lang.NullPointerException in session bean

    Hi !
    I am trying to get a Entity bean through "LocalHome.findByPrimaryKey".I get an error:java.lang.NullPointerException.
    this is session bean:
    public class LoginBean implements javax.ejb.SessionBean {
    private javax.ejb.SessionContext mySessionCtx;
    public UsersLocal usersBean = null;
    public List list_app = null,list_userapp = null,list_userappmd = null;
    public List list_userapppg = null,list_rol = null,list_rolapp = null;
    public UsersLocalHome usersLocalHome = null;
    public Hashtable getUsersLocal(String id){
    Hashtable usersLocal = null;
    UsersLocal usersLocaltmp = null;
    UsersKey primarykey = new UsersKey(id);
    System.out.println("id="+id);
    System.out.println("primarykey="+primarykey.toString());
    try {
    InitialContext initialContext = new InitialContext();
    usersLocalHome = (UsersLocalHome)initialContext.lookup("local:ejb/ejb/pingtai/UsersLocalHome");
    System.out.println("usersLocalHome="+usersLocalHome);
    try {
    usersLocaltmp = usersLocalHome.findByPrimaryKey(primarykey);
    usersLocal.put("id",id);
    usersLocal.put("mm",usersLocaltmp.getMm());
    } catch (FinderException e1) {
    } catch (NamingException e) {
    e.printStackTrace();
    System.out.println(usersLocal.get("mm"));
    return usersLocal;
    Thanks!

    Hi aniseed !
    The occurring at "usersLocaltmp =
    usersLocalHome.findByPrimaryKey(primarykey);"I would guess that your lookup for the local home is returning null. Did you check that?
    If that is the case, you might want to check your JNDI URL.

  • Java.io.NotSerializableException  for Mail Client

    Hi All,
    While running a simple SendMail client I am getting following Exception from
    the server (using weblgoic 7.0). Any idea what could be wrong?
    Start server side stack trace:
    java.io.NotSerializableException: javax.mail.Session
    at
    java.io.ObjectOutputStream.outputObject(ObjectOutputStream.java:1143)
    at
    java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:361)
    at
    weblogic.common.internal.ChunkedObjectOutputStream.writeObject(ChunkedObject
    OutputStream.java:107)
    at
    weblogic.rjvm.MsgAbbrevOutputStream.writeObject(MsgAbbrevOutputStream.java:8
    2)
    at weblogic.jndi.internal.RootNamingNode_WLSkel.invoke(Unknown
    Source)
    at
    weblogic.rmi.internal.BasicServerRef.invoke(BasicServerRef.java:362)
    at
    weblogic.rmi.cluster.ReplicaAwareServerRef.invoke(ReplicaAwareServerRef.java
    :114)
    at
    weblogic.rmi.internal.BasicServerRef$1.run(BasicServerRef.java:313)
    at
    weblogic.security.service.SecurityServiceManager.runAs(SecurityServiceManage
    r.java:785)
    at
    weblogic.rmi.internal.BasicServerRef.handleRequest(BasicServerRef.java:308)
    at
    weblogic.rmi.internal.BasicExecuteRequest.execute(BasicExecuteRequest.java:3
    0)
    at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:153)
    at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:134)
    End server side stack trace
    thanks in advance
    --rk

    Forgive me if I'm misunderstanding your question and pointing out the
    obvious, but it looks like you are trying to pass an instance of
    javax.mail.Session from your server to your client, but since Session is
    not serializable it cannot be passed across JVMs. If you are returning
    the Session instance for the purpose of allowing your client to use it
    to send an email message, you'll want to refactor your code so that the
    client instead sends a representation of the email message to the
    server, which then uses the Session (and, through it, the appropriate
    Transport) to send the message. Please let me know if I've
    misunderstood your question...hope this helps.
    Tim Perrigo

  • How to make a session bean interact with a entity bean?

    hi,
    An entity bean has been created and tested successfully. Values entered into the test app are successfully entered into the pointbase db.
    Now trying to create the same feature through session beans. when the method is invoked, it appears ok, but when the database is queried the values have not been entered. Is there anything that could have been missed or incorrect?
    the steps to setting up session bean
    1)add code to create for JNDI lookup
    public void ejbCreate() {
    System.out.println("Entering oneManagerEJB.ejbCreate()");
    Context c = null;
    Object result = null;
    if (this.myoneHome == null) {
    try {
    c = new InitialContext();
    result =
    c.lookup("java:comp/env/ejb/one");
    myoneHome =
    (oneHome)javax.rmi.PortableRemoteObject.narrow(result,
    oneHome.class);
    catch (Exception e) {System.out.println("Error: "+
                e); }
    2) add business method to enter values into entity bean
    public void createone(int number) {
    System.out.println("Entering ");
    try {
    one oneinfo =
    myoneHome.create(number);
    } catch (Exception e) {
    // Join the following two lines in the Source Editor
    System.out.println("Error in " + e);
    // Join the following two lines in the Source Editor
    System.out.println("Leaving ");
    3) declare variables and namings
    import javax.naming.*;
    private oneHome myoneHome;
    4) add reference to logical session bean
    ejb/one
    5) create test app and add entity bean "one" to module. check mappings.
    run app

    I would do several things which will help track down the problem:
    1. Where you have println statements you may want to change these to exceptions, the session bean won't really work if these problems occur and may silently fail. For example, throw a runtime exeption or EJBException to indicate that the entity bean home interface cannot be found.
    2. When you create the test application you should replace the ejb module which is automatically created with the ejb module or module(s) containing both of the ejb's. This will ensure that the configuration is preserved. The test application is a standard J2EE application, so modules can be added (you could even have multiple test applications each testing a different ejb, make sure that you use different context roots).
    Chris

  • Session bean versus normal bean

    Hi,
    I am at design decision whether to uses a normal Java class or a stateless session bean. I basically need to get data in a list format (read only). I don?t have many users in the system. May be max 60 users online.
    I am thinking of using a fast lane reader. For this I will use a helper class in my web layer maybe doing data access through a DAO. My friends say to use a session bean because of object pooling, clustering etc. I am still convinced a normal class will do. Please help me out with any advice.
    Thanks,
    Gavin

    A Session Bean can be a fast lane reader if you want. The data-reading aspect relates more to Entity Beans than to Session Beans.
    If you're simply after a snapshot of the data then I'd opt for a Session Bean that hits the database directly through a utility class (your fast lane reader).
    EJBs are useful for providing configurable access to resources and get you security, transactional isolation, pooling etc.. These advantages carry an overhead - the EJB life-cycle - which can become prohibitive in some circumstances. However, you'd be unwise to throw away the benefits without first gauging the impact of this overhead.
    It must be noted here that most of the benefits (except security) are probably of little interest to your situation; you don't really need much in the way of clustering or pooling as there's no state being maintained, transactional isolation isn't really relevant either. But then again, how else will you write a server-side component that accesses the database? Or are you going to access the database directly from the client (your web server)? Is the latter a good idea with your dataset? What does this do to your application's configuration? What are the security considerations? Is the number of users likely to increase in future?
    There's no single answer to your problem as it will depend on many factors. I tend to opt for the simplest solution (Entity Beans for a small dataset or a Session Bean accessing the database for a large one) and defer optimisation until bottlenecks can successfully be measured.
    Hope this helps.

  • Urgent: java.io.NotSerializableException

    Hi.
    I'm trying to develop a webapp that uses a EJB to query a database and to produce xml outputs.
    There's a helper class that instantiates the bean and invokes one of its methods, say getUsers(), that will return an org.w3c.dom.Document with all the users.
    The getUsers() method runs ok but when it tries to return the xml document, a java.io.NotSerializableException exception is thrown.
    What can I do about this?
    Thanks!

    Hi.
    I'm using ant for compilation, deploytool for deployment and j2ee server as the application server. I got no errors at deployment time...
    I've been looking through some other posts about this issue and it seems to me a bit stupid not to have a serializable DOM document right in j2skee development kit.
    I mean: in this day and age, how can I put other systems talking with this webapp if I can't pass xml docs around?! Of course there should be a serializable option for this!
    Some guy refered a org.jdom.Document class witch implements the serializable interface and thus solves the problem.
    Do you know where I can find this package or can you suggest another way of getting around the problem?
    Thanks!

  • Should the session bean (stateful/stateless) be created once?

    hi
    I have a sessionBean called BusinessSessionBean and it interacts with a persistent layer session bean (stateful) called PersistenceSessionBean (which acts as a session facade).
    so
    in constructor of BusinessSessionBean I ,
    a) create an instance of home interface PersistenceSessionBeanHome
    b) create an instance of remote interface PersistenceSession
    c) keep it as a member variable
    Then whenever i invoke a method of BusinessSessionBean , the method will invoke a method of PersistenceSessionBean.
    Now should I create an instance of PersistenceSessionBean in the constructor of BusinessSessionBean and keep it as a member variable and use that instance to invoke methods in PersistenceSessionBean ?
    or each time a method in BusinessSessionBean is invoked, I create an instance of PersistenceSessionBean from its home interface and then invoke the method?
    What will be the approach for stateless PersistenceSessionBean ?
    thanks in advance
    Tanveer

    "What will be the approach for stateless PersistenceSessionBean ?"
    Hi stateless bean cannot maintain data inbetween multiple client calls. So if ur Business Session Bean is stateless every time you have to lookup the PersistenceSessionBean. no other go.
    But I don't understand y do u need such a setup.
    Have a normal java class instead of Business Session Bean (in desing patterns term it is called as Business Delegate). Instead of having the lookup machanism in this java class itself move it to a differenct class (design patterns calls it service locator). have a session bean in (session facade) which could do the task for you in the server side calling other beans........
    - Paul

  • Connect Java Application with a Session Bean

    Hi,
    my Problem is following:
    I have session bean (stateless) and i try to write i client for it!
    I get always the same error message, when i call the java ClientApplication from the Command line:
    java -jar Betting_server.jar BettingServer
    StartBetting Server
    Part1
    Caught an unexpected exception!
    javax.naming.NoInitialContextException: Cannot instantiate class: org.jnp.interfaces.NamingContextFactory. Root exception is java.lang.ClassNotFoundException: org.jnp.interfaces.NamingContextFactory
    at java.net.URLClassLoader$1.run(URLClassLoader.java:198)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:186)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:299)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:265)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:255)
    at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:315)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:217)
    at com.sun.naming.internal.VersionHelper12.loadClass(VersionHelper12.java:42)
    at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:649)
    at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:243)
    at javax.naming.InitialContext.init(InitialContext.java:219)
    at javax.naming.InitialContext.<init>(InitialContext.java:195)
    at at.siemens.mma.iap.betting.server.CreateQRunTimer$RemindTask.run(CreateQRunTimer.java:47)
    at java.util.TimerThread.mainLoop(Timer.java:432)
    at java.util.TimerThread.run(Timer.java:382)
    My configuration:
    jboss-3.2.1_tomcat-4.1.24
    j2sdkee1.3.1
    j2sdk1.4.1_02
    My Client Class:
    package betting.server;
    import javax.naming.InitialContext;
    import javax.rmi.PortableRemoteObject;
    import java.util.*;
    import betting.ejb.*;
    public class CreateQRunTimer {
         Timer timer;
         public CreateQRunTimer() {
              timer = new Timer();
              timer.schedule(new RemindTask(),
                        0, //initial delay
                        1*60*1000); //subsequent rate 30 minutes
         class RemindTask extends TimerTask {
              public void run() {
                   String logicalBettingBeanName = "MyBetting";
                   Betting bet;
                   BettingHome bethome;
                   try
                        System.out.println("Part1");
                        Properties props = new Properties();
                             props.put("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
                             props.put("java.naming.factory.url.pkgs", "org.jboss.naming:org.jnp.interfaces");
                             props.put("java.naming.provider.url", "localhost:1099");
                        InitialContext ic = new InitialContext(props);
                        System.out.println("Part2");
                        Object objref = ic.lookup(logicalBettingBeanName);
                        System.out.println("Part3");
                        bethome =(BettingHome)PortableRemoteObject.narrow(objref,BettingHome.class);
                        bet = bethome.create();
                        long qRunMagicNum = bet.DB_CreateQRun();
                        if(bet.CreateConfigurationFileQuery(qRunMagicNum) == false)
                             // failed
                             System.out.print("CreateConfigFileQuery failed");
                        else
                             bet.TransferXMLFiles("tvbetqrun.conf",0);
                             System.out.print("CreateConfigFileQuery succed");
                   catch (Exception ex)
                        System.err.println("Caught an unexpected exception!");
                        ex.printStackTrace();
                   System.out.println("Run GG");
                   //System.exit(0); //Stops the AWT thread (and everything else)

    Normally, if you are executing the client from the command line, you do not specify the classpath in a XML file (unless you are using ant or something similar). You can specify the classpath by using the -classpath option.
    Try something like
    java -classpath <path_to_jboss>/client/jbossall-client.jar;Betting_server.jar BettingServer
    You can check the classpath in your client with the statement
    System.out.print(System.getProperty("java.class.path"));

  • How to avoid Invalidation of Stateful Session Bean in case of an Exception?

    Hi developers,
    I'm working on a project using JSF, Toplink and EJB 3.0 using JDev.
    I'm using a statefull session bean that is stored in the session but when an exception occurs in a business method in the stateful bean the bean crashed and can never be reused and returns the following trace :
    06/06/05 10:19:12 java.rmi.NoSuchObjectException: Session has timed out or was invalidated
    06/06/05 10:19:12      at com.evermind.server.ejb.StatefulSessionEJBObject.throwPassivisationException(StatefulSessionEJBObject.java:335)
    06/06/05 10:19:12      at com.evermind.server.ejb.StatefulSessionEJBObject.OC4J_transactionPreExecute(StatefulSessionEJBObject.java:717)
    06/06/05 10:19:12      at com.evermind.server.ejb.interceptor.system.TxRequiredInterceptor.invoke(TxRequiredInterceptor.java:51)
    06/06/05 10:19:12      at com.evermind.server.ejb.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:69)
    06/06/05 10:19:12      at com.evermind.server.ejb.interceptor.system.DMSInterceptor.invoke(DMSInterceptor.java:52)
    06/06/05 10:19:12      at com.evermind.server.ejb.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:69)
    06/06/05 10:19:12      at com.evermind.server.ejb.StatefulSessionEJBObject.OC4J_invokeMethod(StatefulSessionEJBObject.java:840)
    06/06/05 10:19:12      at PriseChargePS_StatefulSessionBeanWrapper21.trouverAssure(PriseChargePS_StatefulSessionBeanWrapper21.java:1747)
    06/06/05 10:19:12      at Pensions.Traitements.AssureTraitement.donnerAssure(AssureTraitement.java:130)
    06/06/05 10:19:12      at Pensions.view.backing.priseCharge.PriseCharge.chercherAssure_action(PriseCharge.java:189)
    06/06/05 10:19:12      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    06/06/05 10:19:12      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    06/06/05 10:19:12      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    06/06/05 10:19:12      at java.lang.reflect.Method.invoke(Method.java:585)
    06/06/05 10:19:12      at com.sun.faces.el.MethodBindingImpl.invoke(MethodBindingImpl.java:126)
    06/06/05 10:19:12      at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:72)
    06/06/05 10:19:12      at javax.faces.component.UICommand.broadcast(UICommand.java:312)
    06/06/05 10:19:12      at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:267)
    06/06/05 10:19:12      at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:381)
    06/06/05 10:19:12      at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:75)
    06/06/05 10:19:12      at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:200)
    06/06/05 10:19:12      at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:90)
    06/06/05 10:19:12      at javax.faces.webapp.FacesServlet.service(FacesServlet.java:197)
    06/06/05 10:19:12      at com.evermind.server.http.ResourceFilterChain.doFilter(ResourceFilterChain.java:64)
    06/06/05 10:19:12      at oracle.adfinternal.view.faces.webapp.AdfFacesFilterImpl._invokeDoFilter(AdfFacesFilterImpl.java:367)
    06/06/05 10:19:12      at oracle.adfinternal.view.faces.webapp.AdfFacesFilterImpl._doFilterImpl(AdfFacesFilterImpl.java:336)
    06/06/05 10:19:12      at oracle.adfinternal.view.faces.webapp.AdfFacesFilterImpl.doFilter(AdfFacesFilterImpl.java:196)
    06/06/05 10:19:12      at oracle.adf.view.faces.webapp.AdfFacesFilter.doFilter(AdfFacesFilter.java:87)
    06/06/05 10:19:12      at com.evermind.server.http.ServletRequestDispatcher.invoke(ServletRequestDispatcher.java:629)
    06/06/05 10:19:12      at com.evermind.server.http.ServletRequestDispatcher.forwardInternal(ServletRequestDispatcher.java:376)
    06/06/05 10:19:12      at com.evermind.server.http.HttpRequestHandler.doProcessRequest(HttpRequestHandler.java:870)
    06/06/05 10:19:12      at com.evermind.server.http.HttpRequestHandler.processRequest(HttpRequestHandler.java:451)
    06/06/05 10:19:12      at com.evermind.server.http.HttpRequestHandler.serveOneRequest(HttpRequestHandler.java:218)
    06/06/05 10:19:12      at com.evermind.server.http.HttpRequestHandler.run(HttpRequestHandler.java:119)
    06/06/05 10:19:12      at com.evermind.server.http.HttpRequestHandler.run(HttpRequestHandler.java:112)
    06/06/05 10:19:12      at oracle.oc4j.network.ServerSocketReadHandler$SafeRunnable.run(ServerSocketReadHandler.java:260)
    06/06/05 10:19:12      at oracle.oc4j.network.ServerSocketAcceptHandler.procClientSocket(ServerSocketAcceptHandler.java:230)
    06/06/05 10:19:12      at oracle.oc4j.network.ServerSocketAcceptHandler.access$800(ServerSocketAcceptHandler.java:33)
    06/06/05 10:19:12      at oracle.oc4j.network.ServerSocketAcceptHandler$AcceptHandlerHorse.run(ServerSocketAcceptHandler.java:831)
    06/06/05 10:19:12      at com.evermind.util.ReleasableResourcePooledExecutor$MyWorker.run(ReleasableResourcePooledExecutor.java:303)
    Please help !

    Your question is not how to create/compile a stateless session bean, you are asking how to use those weblogic specific annotations. A weblogic forum is a better place to ask that.

Maybe you are looking for

  • How to install and where to get kernal source for Oracle VM Server

    Hi guys Can someone point me in the right direction for oracle VM Server kernal source, as the server I am using won't ping, and found its cause it doesnt recognise the network adapter, says there is no drivers. But the HP website states I have to ha

  • Excel 2010 to Adobe X Cell Contents Cut Off

    Trying to create an Adobe X file from an Excel 2010 workbook. Issue is multiple cells have contents cut off. The entire contents of the cell does not display in the pdf file. Tried using both the Excel built-in Acrobat "Create pdf" method and the Exc

  • How do i complain to apple about a multifunctional with my divice

    i recently updated my i phone to the new ios settings it deleated my photos contacts and my apps when i finaly got my apps back and started getting my numbers back i plughed it into my computer to sink it up so it couldnot happen again then it did th

  • Using the result of Get-ADOrganizationalUnit into an array.

    Hello all! I'm hoping you can help me with the following challange. What I want to accomplish: I'm building a PowerShell script that will parse all the servernames from multiple OU's through the RDCman Set-Rdg script build by timdun @ http://blogs.ms

  • Reader Extensions to retrieve data from form?

    Hello Will it possible to retrieve the formdata of a PDF form by an external program if I have Adobe Reader Extensions? Thank you Sincerely Lore P.S.: Will this be possible also by Form Based Pricing Reader Extensions?