Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How do I serialize?  RSS feed

 
ravinderSingh singh
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have to pass a parameter to an ejb method which is an instance of ServletOutputStream. However, this class is not serializable so how can I make it so that it can be passed successfully?

Thanks!!
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The fact that it is not serializable should give you pause. Maybe passing it to an EJB method is not the best approach. In fact, EJBs should not concern themselves with implementation details like whether some piece of data goes to a servlet or to /dev/null. It should just return the business data, and let the client facade handle the rest.
 
ravinderSingh singh
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply.

I understand your point but I need to transfer/store/retrieve a file (uploaded through a HTML form) onto the server on which my EJBs reside so that the file in question can be accessed by any application with access to the EJBs.

I didn't think there would be any other way to achieve this than to pass the stream contain the file data to the EJB method.

Is it not possible to make ServletOutputStream serializable?
 
Don Morgan
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The EJB spec is firmly against file access from EJBs. For example, in v2.1 of the spec, pg 563, you will find:


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

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.


In the real world, sometimes this is not strictly followed (such as for logging). Does anyone out there follow this guideline to the letter?

Also, if you are talking about the need to transfer/store/retrieve the data, perhaps using a database for persistence is a better solution. For example, if you ever move to a clustered environment, you will have problems if Machine A handles the store file operation, creating the file on Machine A, and then when Machine B picks up the retrieve request it would be unable to find the file. It is not impossible to make this work in a cluster (think about an exported drive or shared file system), but it does add complexity.

Of course, you still need to pass the actual data through from the servlet to the EJB, regardless of how you persist it. Maybe an array of bytes would work for you.
[ January 12, 2006: Message edited by: Don Morgan ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!