Access to the httprequest object within POJO called by WebSphere Command/JSP/etc?

732 views Asked by At

Short version: How can I access to HttpRequest object from a POJO code that is called by a Command/JSP which is executed by WebContainer?

  • POJO is not aware of the CommandContext or HttpRequest (or its cousins).
  • POJO is pretty deep down in the execution stack, so changing the method signature means changing all the parent method signatures and the places these methods are called.

I did check a similar post as well (my POJO is called by the WebContainer and there has to be a way to access to the request somehow without going thru the hoops like this): Retrieving Web Session from a POJO Outside the Web Container

Long version: I have been trying to find this needle in a haystack: trying to figure out a way to access to the HttpRequest object (or its cousins) in WebSphere application server (Commerce actually) by means of going thru the current WebContainer thread (or any other means, similar to getting the Transaction via TransactionManager).

Knowing that these Container threads are tied to a single executing page/command/etc I was wondering if there is a way of doing this without employing WorkArea, ThredLocal style not so desired approaches?

The issue we are facing is that, there had been many pieces of code written over the years that had not cared about the storeId or langId. So, rather than fixing all these pieces of code, we would like to access to Session context somehow (with HttpRequest object) so we can get the CommandContext and/or other structures to find out our storeId and langId and other data tied to the session.

Any further details required, please feel free to ask.

One example pseudo-code snippet:

public class MyLittleHelper {

. . . 

void unawareMethod() {
  // I know it is really bad practice not to pass the actual objects around...  
  // But hear me out for a sec... 
  // This could be the easiest way of changing things, however bad it looks. 

  // my storeId and langId unaware method now needs to access to storeId and langId

}

. . .
} // end of class

Any help would be greatly appreciated.

0

There are 0 answers