Discussions

EJB design: Session Bean must read a XML file

  1. Session Bean must read a XML file (2 messages)

    Hi all,
    in my application I read infos from a Postgres DB
    using this architecture:

    Stateless Session Beans + DAO classes

    (inside DAO classes I wrote the SQL code to
    retrieve infos from the DB).

    Now I have to retrieve other infos from a XML file.

    The question are:

    1) Is it correct that a Session Beans reads infos
    from a "normal" file or it must must be connected
    only to a database ?

    2) There are differences, for what concerne question n.1,
    among Session Beans and Entity Beans ?

    My Application Server (JBoss) runs on a linux server
    and PostgresDB on another linux server, but is simple
    to say to JBoss where PostgresDB is.

    If the file resides on a server different from
    the Server Linux where JBoss runs, how can
    I read the file ?

    Thank you in advance
    Moreno

    p.s. sorry for my english :-)
  2. 1) Is it correct that a Session Beans reads infosfrom a "normal" file or it must must be connected only to a database
    EJB2.0 specification in section 24.1.2 lists the "Programming Restrictions" that a bean developer should follow. One of them says -

    "An enterprise bean must not use java.io package to attempt to access files and directories in the file system."


    As an explanation for this restriction it says -

    The file system APIs are not well suited for business components to access data. Business components should use a resource manager API such as JDBC to store data.

    So if you want to strictly follow the "rules" the answer is - No, you should not read from the file.

    But then, I can't see any technical difficulty as such on reading a file. You can certainly open and read a file from a session bean (don't think the appserver will prevent such a thing). The messy part would be - how do you obtain the location of the file. You can use an environment variable (java -D option or through the session bean environment set up in the deployment descriptor) that points to the file location.
    2) There are differences, for what concerne question n.1,among Session Beans and Entity Beans ?
    Did not understand your question.
    My Application Server (JBoss) runs on a linux serverand PostgresDB on another linux server, but is simpleto say to JBoss where PostgresDB is.If the file resides on a server different from the Server Linux where JBoss runs, how can I read the file ?
    You can share the file on the network and use NFS to read the file from the computer where your application server is running.

    Kingshuk
  3. Session Bean must read a XML file[ Go to top ]

    Thank you Kingshuk.

    Question two was a stupid question :-)
    I asked if there were differences between Session
    and Entity Beans for what concerne reading
    file on file system (for example: Entities must
    be used only for DB, Sessions can also manage
    file) ... it had no sense.

    My final solution is :

    1) I write a Java Application that reads
    XML file and then populates an equivalent
    table in PostgresDB.

    2) JBoss refers to table in DB and not to XML file

    I repeat every week point n. 1)
    (data in XML file rarely change)

    Moreno