• Post Reply Bookmark Topic Watch Topic
  • New Topic

Deep Copy of request object

 
Uday Kiran
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I need to make a copy of the request object. What is the recommended way of doing this. I am currently looking at using HttpServletRequestWrapper class and it doesn't seem to work...
thanks in advance
 
Junilu Lacar
Sheriff
Posts: 10028
120
Android Eclipse IDE IntelliJ IDE Java Linux Mac Scala Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not sure why you'd want to do that but you might try to use instanceof to see if the underlying object is Cloneable (remember that request is an interface reference) then invoke clone() if it is. This still may not guarantee you a deep copy though.
HTH,
Junilu
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'd be wary of trying to clone the request object since you could be inclined to do dangerous things with it.
ie persist it, share it between resources, share it between tiers, hold onto it then pass it to the RequestDispatcher...
It would be far better to map the data to another object if you need another version...
Dave
 
Junilu Lacar
Sheriff
Posts: 10028
120
Android Eclipse IDE IntelliJ IDE Java Linux Mac Scala Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just realized a problem with the clone suggestion: Cloneable is a marker interface (it doesn't have any methods) and Object.clone() is protected. Even if the underlying object were Cloneable, you may still not be able to invoke clone() directly. In short, I don't think the clone approach is workable.
Junilu
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!