Discussions

EJB design: Performing I/O in EJBs

  1. Performing I/O in EJBs (2 messages)

    Hi,

    Having read a thread on passing xml between ejbs which also mentioned that one cannot perform io within ejbs I need to ask a question....

    I have a session bean which creates/uses a normal java class, which through an utility class loads an xml file from within the jar file (that contains the same utility class). Obviously initial tests of just this java class have posed no problems. But...will I have problems once the ejbs are deployed and I attempt to load the file from with the container which is executing the session bean?

    If yes, then 1) shit! 2) how might I be able to load resources from within ejbs?

    regards,

    Paul W.

    Threaded Messages (2)

  2. Performing I/O in EJBs[ Go to top ]

    IMHO it's OK, if you put the code that does this inside a helper class, not in the bean itself.

    People will disagree, and argue that the location of the code is irrelevant, and they may very well be correct (no one ever said this stuff was easy.) However, the spec is vague on these kinds of topics so you often have to go with your own judgement.

    Since you can be a socket client, you could always contact some other socket process which returns the XML after reading it in from a file. That is definitely OK according to the spec, but in reality what you are doing is not that complex and you shouldn't have any real problem.

    Chz

    Tony
  3. Performing I/O in EJBs[ Go to top ]

    You should not put I/O code in a bean. You are ok putting the I/O calls in a helper class which the bean uses, provided the helper class gets loaded higher up in the classloader hierarchy as compared to the bean class loader. Dedpends on the container/server you are using , you can specify this. Also put the file in the class path that the class loader that loads your helper class would find it.