System.out.println and EJBs

Hi,
I'm trying to develop an application that has 2 main components:
1) A stateless session EJB, which is called by the container timer service periodically and makes some DB uptades.
2) A servlet which basically calls the create method in the EJB.
I've implemented a prototype of the app and the servlet code looks like this:
try {
Context context = new InitialContext();
MyClassLocalHome home = (MyClassLocalHome)PortableRemoteObject.narrow(
               context.lookup("java:comp/env/ejb/MyClass"),
          MyClassLocalHome.class);
System.out.println("Narrowed");
MyClassLocal timer;
// create a new instance
timer = home.create();
System.out.println("Created!");
In the ejbCreate() in MyClass callback, all I have is a System.out.println("ejbCreate() called") to show the method was called.
My problem is the even though the servlet code runs without errors and I can see the output in the application server's SystemOut.log, I can't find "ejbCreate() called" message. Am I looking in the wrong place? Am I doing something wrong?
Thanks in advance.
Pedro

Hi Pedro,
You're not necessarily doing something wrong. Where are you actually invoking a business method on the Stateless Session bean? In the Stateless Session Bean lifecycle, the actual bean instance creation is not required to be linked to the Home.create() call. That's because Stateless Session bean instances have no client-specific state. The container can delay the bean instance creation until an actual business method is called. Only then would the bean instance's ejbCreate method be called.
--ken                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

Similar Messages

  • System.out.println in EJB

    Hi I have given System.out.println in my EJB object. But I am not able to see the output in my console. But when I give printStackTrace in my JSP(from where I can EJB)....it is displaying the exception....
    So my question is Can we give System.out... in EJB?. Should we set any property to see the output of System.out...in the console?.

    Here is my code
    From UserManager I call the EJB
    public boolean validateSignOn(String strUserName,String strPassword) throws ProdSchedException{
    try{
    UserMgrHome home = (UserMgrHome)getEJBHome("UserMgr",UserMgrHome.class);
    UserMgr userMgr = home.create();
    return userMgr.validateSignOn(strUserName,strPassword);
    catch(RemoteException rex){
    ServerLog.log(rex.getMessage(),ServerLog.ERROR);
    throw new ProdSchedException(rex,"Server Failed");
    catch(CreateException cex){
    ServerLog.log(cex.getMessage(),ServerLog.ERROR);
    throw new ProdSchedException(cex,"Create Exception");
    This is my EJB code
    import javax.ejb.*;
    import java.rmi.RemoteException;
    import java.util.*;
    import javax.xml.parsers.*;
    import org.xml.sax.*;
    import org.w3c.dom.*;
    import java.io.*;
    * User Manager Session Bean
    public class UserMgrEJB implements SessionBean {
    SessionContext cntx;
    public boolean validateSignOn(String strUserName,String strPassword) throws ProdSchedException{     
    UserDAO dao = new UserDAO();
         System.out.println("Inside EJB");
    boolean bValidUser = dao.validateUser(strUserName,strPassword);
    if(!bValidUser){
    throw new ProdSchedException("Invalid User");
    return bValidUser;
    //Bean methods
    public void ejbCreate(){
         System.out.println("Inside EJB Create");
    public void ejbRemove(){
    public void ejbActivate(){
         System.out.println("Inside EJB Activate");
    public void ejbPassivate(){
    public void setSessionContext(SessionContext cntx){
    this.cntx = cntx;
    This is mu UserDAO code
    public class UserDAO extends DAO{
    public boolean validateUser(String userName,String password) throws ProdSchedException{
    Connection conn = null;
    PreparedStatement stmt = null;
    ResultSet result = null;
         System.out.println("Inside validateUser in DAO");
    try{
              boolean bIsValidUser = true;
         String selectStatement = "SELECT SYSDATE from DUAL";
         conn = getConnection();
    stmt = conn.prepareStatement(selectStatement);
    result = stmt.executeQuery();
    while(result.next()){
    bIsValidUser = true;
    return bIsValidUser;
    catch(SQLException sqex){
    ServerLog.log(sqex.getMessage(),ServerLog.ERROR);
    throw new ProdSchedException(sqex,sqex.getMessage());
         finally{
    try{
    close(conn,stmt,result);
    catch(ProdSchedException slex){
                   ServerLog.log(slex.getMessage(),ServerLog.ERROR);
    throw slex;
    } // end class
    And the error I get in the console is this(since I have given printStackTrace in my JSP)
    ProdSchedException: SQL Error
    at UserDAO.validateUser(UserDAO.java:
    44)
    at UserMgrEJB.validateSignOn(
    UserMgrEJB.java:26)
    at UserMgrEJB_p3hctp_EOImpl.v
    alidateSignOn(UserMgrEJB_p3hctp_EOImpl.java:46)
    at UserManager.validateSignOn(User
    Manager.java:20)
    at jsp_servlet._public.__login._jspService(__login.java:123)
    at weblogic.servlet.jsp.JspBase.service(JspBase.java:27)
    at weblogic.servlet.internal.ServletStubImpl$ServletInvocationAction.run
    (ServletStubImpl.java:1094)
    at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubIm
    pl.java:437)
    at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubIm
    pl.java:319)
    at weblogic.servlet.internal.WebAppServletContext$ServletInvocationActio
    n.run(WebAppServletContext.java:5626)
    at weblogic.security.service.SecurityServiceManager.runAs(SecurityServic
    eManager.java:685)
    at weblogic.servlet.internal.WebAppServletContext.invokeServlet(WebAppSe
    rvletContext.java:3213)
    at weblogic.servlet.internal.ServletRequestImpl.execute(ServletRequestIm
    pl.java:2555)
    at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:251)
    at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:219)

  • System.out.println and out.println

    Sir,
    i wana know the diff between System.out.println() and println plz help in this regard. how they work in jsp .
    thanks

    Hi
    System.out.println is a method of PrintStream in IO which is used to print the output on console in java progs.Here in jsp ,the o/p is printed on server's console window.But out.println is totally different as, out is implicit object derived from JspWriter and is used sly to PrinWriter 's object is used in servlets.It's work is to write upon Browser.
    System.out.println() is normally used in jsp for debugging purposes only.
    Ashish

  • System.out.println() and System.err.println()

    Can any one tell me the difference between System.out.println()
    and System.err.println() ?

    Can any one tell me the difference between
    System.out.println() Sends the output to the 'stdout' stream
    and System.err.println() ?sends the output to the 'stderr' stream.
    http://en.wikipedia.org/wiki/Standard_input

  • Difference between System.out.println() and out.println()

    Hi,
    In JSP we want to write the JNLP file contents to a ouput stream using "out.printl()".
    The content of the JNLP file i am having in a String.
    The "System.out.println()" is printing the correct JNLP file contents but "out.println()" writing wrong contents which are taken from Server JNLP file.
    How to solve this problem?
    Please guide me in this.
    Thanks and Regards:
    Dheeraj

    Where is the "System.out.println()" running from? I don't think your problem has anything to do with the difference between System.out.println and out.println. Both methods print what is passed to them. It sounds like you are printing two different files because you are running in two different environments.
    JSPs run on a server and only have access to files on the server or on a network the server is on. If you are trying to print a file on a user's system, JSP can't do it.

  • System.out.println and Network Adapter problem

    Hello,
    I am encountering a 2 strange problems. I have 2 oracle application server instances, one dev and one production.
    The first problem is when I type System.out.println in the JSP's i am able to see the output in both \opmn\logs\oc4jinstance. But the System.out.println in the java classes or bean show up only in development logs but not in production box.
    Is there a setting I am missing here?
    The second problem is on our development machine the application works fine, but as soon as we deploy the application on production I encounter:
    could not open new connection: Io exception: The Network Adapter could not establish the connection
    I have a class called DBUtils, which uses a 3rd party library to get connections from the connection pool as below. Using JSP I call the getConnection(). On my dev Oracle Application Server Instance it works fine, but on production I get the error. Can it be there is a setting that I am missing on the production box?
    When I use a JSP and connect to the database without using the DBUtil class. I can connect to the database fine. Also using the DBUtil class with production oracle IP address on the development machine lets me connect with no problem, but production machine does not let me.
    public class DBUtils {
    static ConnectionPoolBean pool;
    static {
    System.out.println("DBUtils() - before connection pool bean");
    pool = new ConnectionPoolBean();
    pool.setDriverClassName("oracle.jdbc.driver.OracleDriver");
    pool.setdbURL("jdbc:oracle:thin:@IPADDRESS:PORT:SID");
    pool.setUser("USERNAME");
    pool.setPassword("PASSWORD");
    pool.setInitialConnections(1);
    pool.setIncrement(1);
    pool.setSoftMaxConnections(40);
    public static Connection getConnection() throws SQLException {
    System.out.println("Getting Oracle Connection");
    return pool.getConnection();
    public static void returnConnection(Connection conn) throws SQLException {
    System.out.println("Returning Connection");
    pool.returnConnection(conn);
    Thanks for your help in advance.

    Hi
    System.out.println is a method of PrintStream in IO which is used to print the output on console in java progs.Here in jsp ,the o/p is printed on server's console window.But out.println is totally different as, out is implicit object derived from JspWriter and is used sly to PrinWriter 's object is used in servlets.It's work is to write upon Browser.
    System.out.println() is normally used in jsp for debugging purposes only.
    Ashish

  • What is the different  between System.out.println and out.print

    we move a project , jsp form to servlet to mysql db
    suddenly we get Chinese input problem
    on meantime only Thing I know is
    if( chineseName!=null) {
                           chineseName= new String( chineseName.getBytes("ISO-8859-1"),"UTF-8");
                         out.print(chineseName); //display Chinese
                          System.out.println("Hello1"+chineseName ); // display unread symbol
                 }I don't know why when we insert the value into db by StudentInsert(university_ID, surName, english_Name, chineseName, Address)
    the db get the value from System.out.println
    what setting decide my out put through System.out.println

    Thank you for the reply!
    after two days of search and guess.... I found out
    for Web application , which under glassfish , you need to put your jsp page under WEB-INF,
    other wise the server jsp turn your Chinese character that come from jsp request form to UTF8 symbol.
    not ideal how to change the configuration in glassfish yet!

  • System.out.println and OAS

    Hello All,
    I have few System.out.println statements in my J2EE application which is running on OAS. I'm not sure where it is writing. I couldn't find anything in the server.log. Really appreciate any ideas.
    Thanks

    I know this is a couple of months old but it's a useful tip for anyone else having the same problem.
    You can't see the System.out.println statements in any logs through the administration web pages of the OAS. You have to go through the filesystem, which is annoying and in my opinion a massive error by Oracle. But never mind.
    The filepath is:
    %ORACLE_HOME%/opmn/logs/default_group~***~default_group~1.log
    replace *** with the name of your oc4j instance
    HTH
    Paul

  • System.out.println and log file

              I am developing jsp on BEA Weblogic 613 on Solaris.
              What if i run the following statement
              System.out.println("Hello world");
              I understand that Hello World will be printed to the server console. I do not
              have access to this console. Is there any log file or temporary log file it gets
              sent to? If not, is there anyway to redirect output from the console to someplace
              else?
              Thanks!
              

    You can redirect console output for stdout on Solaris like so:
              java weblogic.Server > consoleoutput.txt
              then in a terminal window you can see whats going on with
              tail -f consoleoutput.txt
              Sam
              Brian Schneider wrote:
              > I am developing jsp on BEA Weblogic 613 on Solaris.
              >
              > What if i run the following statement
              > System.out.println("Hello world");
              >
              > I understand that Hello World will be printed to the server console. I do not
              > have access to this console. Is there any log file or temporary log file it gets
              > sent to? If not, is there anyway to redirect output from the console to someplace
              > else?
              >
              > Thanks!
              

  • What is the difference between System.out.println() and System.out.print()?

    Hi everyone,
    I am only a new comer and know very little about Java. I will appreciate a lot if anyone teaches me what the difference between two method println and print is? Thank you so much.

    The PrintStream class defines a number of print() methods that ... print
    things. System.out is a commonly used PrintStream.
    The difference between the print(...) and println(...) methods is that the
    second one prints a new line at the end. What it actually prints varies
    from system to system: sometimes it will output a '\n' sometimes not.
    There is a system property called line.separator that determines
    how a new line is output.

  • System.out.println() Print to JFrame

    I just wrote a rather large java application and now want to develop a GUI for it. I have never developed GUI and am trying to use the API's for help. Can anyone point me in the right direction: I am trying to take everything that is printed out with System.out.println() and print it inside a JFrame. Any help would be magnificent.
    -Alex

    Add a JTextArea to your frame, create a TextAreaOutputStream with it, and use System.setOut(...) to set System.ouot
    * Created on Mar 13, 2005 by @author Tom Jacobs
    package tjacobs;
    import java.io.IOException;
    import java.io.OutputStream;
    import javax.swing.JTextArea;
    import javax.swing.text.JTextComponent;
    * TextAreaOutputStream creates an outputstream that will output to the
    * given textarea. Useful in setting System.out
    public class TextAreaOutputStream extends OutputStream {
         public static final int DEFAULT_BUFFER_SIZE = 1;
         JTextArea mText;
         byte mBuf[];
         int mLocation;
         public TextAreaOutputStream(JTextArea component) {
              this(component, DEFAULT_BUFFER_SIZE);
         public TextAreaOutputStream(JTextArea component, int bufferSize) {
              mText = component;
              if (bufferSize < 1) bufferSize = 1;
              mBuf = new byte[bufferSize];
              mLocation = 0;
         @Override
         public void write(int arg0) throws IOException {
              //System.err.println("arg = "  + (char) arg0);
              mBuf[mLocation++] = (byte)arg0;
              if (mLocation == mBuf.length) {
                   flush();
         public void flush() {
              mText.append(new String(mBuf, 0, mLocation));
              mLocation = 0;
              try {
                   Thread.sleep(1);
              catch (Exception ex) {}
    }

  • System.out.println(STX +"HELLO"+ ETX) ; ???

    I hava one question I tried to display String which is begins with a sign "STX - this is a sign 0x02 in Ascii Table and ended with "ETX - this is a sign 0x03 in Ascii Table" using System.out.println, and nothing,
    console was empty. When I deleted STX and ETX i got HELLO. I have question where is a problem. If you know answer on my question please write it.
    Thank you and Regards Sebastian

    I hava one question I tried to display String which is
    begins with a sign "STX - this is a sign 0x02 in Ascii
    Table and ended with "ETX - this is a sign 0x03 in
    Ascii Table" using System.out.println, and nothing,
    console was empty. When I deleted STX and ETX i got
    HELLO. I have question where is a problem. If you
    know answer on my question please write it.
    Thank you and Regards Sebastianhow do you define STX and ETX ?
    either of these should be valid
    public static final char STX = (char)0x02;
    public static final char ETX = (char)0x03;or
    public static final char STX = \u0002;
    public static final char ETX = \u0003;if they still don't work, it may be because these two characters are unprintable

  • Intercepting System.exit() and System.out.println() calls

    hi there,
    I have often problems when working with code that uses System.exit() and System.out.println() extensively, because it becomes difficult to debug.
    Basically I do have wrappers for System.exit() (my own static exit function) and for System.out.println() (log4j).
    Still not all programmers are using these methods; Probably the only way to enforce this is some kind of code warrior, but I was hoping to be able to intercept the two System.XXX calls (and throw an appropriate Exception). is this possible ??

    Why not simply make your own security manager andhandle checkExit() and checkWrite?
    Does anyone have a simple example of this? Please?System.exit() can be intercepted using a security manager, but not System.out.xxx.
    Here is a short example:
    //set your security manager
    static{
         SecurityManager s = new OwnSecurityManager();
         System.setSecurityManager(s);
    //redirect the out stream
    try{
         PrintStream ps = new PrintStream(new FileOutputStream("output.txt"));
         System.setOut(ps);
    }catch(IOException ioe){
         ioe.printStackTrace();
    //some tests
    System.out.println("Test");
    System.exit(2);
    //your security manager
    class OwnSecurityManager extends SecurityManager{
         public void checkExit(int code){
           if(code > 0){
             super.checkExit(code);
             throw new SecurityException("Not allowed here->" + code);
         public void checkRead(FileDescriptor fd){
         public void checkRead(String file){
         public void checkRead(String file, Object context){
         public void checkPermission(Permission perm){
           if(perm.getName().equals("exitVM")){
             System.out.println("exitVM");
    }

  • Log4j and System.out.println

    I have to implement log4j onto a running application, the whole application uses System.out.println for logging.
    Can implement log4j without changing the code.
    Regards,
    Sabari

    Create a PrintStream which writes to log4j. Make sure the PrintStream writes to the current System.out if called when it is already being called.
    Set this as the default out and err with System.setOut() and setErr().

  • System.out.print and System.out.println

    is it true that the System.out.print("\n") will print a new line character in all platforms?
    in other words is it ok to assume that System.out.print("\n") and System.out.println(); will give the same output regardless of platform?

    System.out.print("\n") Chances are that will produce different results on different platforms as some platforms use \n, some use \r some use \n\r (or is it \r\n?).
    The question is why do you care when System.out.println() will do what you want? An alternative:
    System.out.print(System.getProperty("line.separator"));

Maybe you are looking for