Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Session Bean Reading an XML File  RSS feed

 
JasmineS Saeid
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I have a problem. I have a session Bean (Server: JBOSS) which is parsing an XML file for reading some values. My Problem is that if i package my config.xml inside the META-INF folder, the method of Session bean that reads this xml throws a File Not Found Exception.
After lot of trials and errors i found that Jboss was trying to locate the xml file from the folder C:\JBoss\bin by default. And So i have to explicitly paste the xml file in the bin folder of JBOSS
But i want it to be picked up from my bean's META-INF Folder
How can i acheive that ?

Appreciate if anyone could help.....
 
Chris Brat
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Why are you trying to read the xml ? What data does it hold?

It is a bad idea to perform IO operations on the local system in an EJB - its actually discouraged in the spec .

If possible rather try another scenario ; store the data in a database or have the xml file read by an init servlet which then binds the file contents to a JNDI name which will then be accessible to the beans.

Javaranchers : Please let me know if you have a better solution. Thanks.

Chris
 
Roger Chung-Wee
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
EJBs are for doing business logic processing. A bean should receive and return objects. If a bean's client is a servlet, then that servlet should read the XML file, convert the XML to an object and use that object in an EJB method call.

In any case, the use of the java.io package is forbidden by the EJB spec. As there is no resource manager involved in java.io operations, the container has no control of files and is also unable to incorporate files in EJB transactions.
 
Mark Spritzler
ranger
Sheriff
Posts: 17309
11
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, the big question is what creates the xml file, and what is it used for. There are many options to find the best solution.

However, like everyone pointed out, no using IO in EJBs.

Mark
 
JasmineS Saeid
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for that Valuable Suggestion !!!
Actually i was trying to get something done faster so that crude method.
But i shall keep that in mind.

Anyways i could do it with the following 2 lines of Code:
URL oConfig = getClass().getResource("/config.xml");
oDocument = oDocBuilder.parse(oConfig.toExternalForm());
 
Roger Chung-Wee
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you are going to pass a Document as an arg in an EJB method call from a remote client, just make sure that the class which implements the Document interface also implements the serializable interface. This is a requirement of the EJB spec.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!