• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

How do I serialize?

 
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!!
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
permaculture is giving a gift to your future self. After reading this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic