aspose file tools*
The moose likes Servlets and the fly likes  Javax.servlet.http.HttpServletRequest'  is received as weblogic.servlet.internal.ServletRequestImpl Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark " Javax.servlet.http.HttpServletRequest Watch " Javax.servlet.http.HttpServletRequest New topic
Author

Javax.servlet.http.HttpServletRequest' is received as weblogic.servlet.internal.ServletRequestImpl

patt rich
Greenhorn

Joined: Apr 07, 2008
Posts: 21
If I send a Javax.servlet.http.HttpServletRequest from a servlet to another simple Java class method as a parameter, it is received in the simple java class as 'weblogic.servlet.internal.ServletRequestImpl' Any idea why this is happening?

BTW, I have deployed the servlet in the weblogic server.

Thank you
Ravi Kiran Va
Ranch Hand

Joined: Apr 18, 2009
Posts: 2234

whats your requirement ?? why are you sending servlet as a parameter to Java class ??


Save India From Corruption - Anna Hazare.
patt rich
Greenhorn

Joined: Apr 07, 2008
Posts: 21
Ravi,
I have a servlet class. From that servlet class I call a simple java class since I need to do some specific things with the request. Meanwhile I also have to forward the request to another URL.

Do you know why this conversion is happening?
thanks for taking interest on my question
Ravi Kiran Va
Ranch Hand

Joined: Apr 18, 2009
Posts: 2234

first tell me, Why are you opting for a simple java class rather it being an other servlet
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42289
    
  64
What do you mean by "it is received as"? Are you doing a "getClass().getName()" on that object? That'll get you the the name of the implementing class, but it's still an HttpServletRequest. Maybe you can clarify what exactly you're doing, what you were expecting, and whether it's an actual problem.


Ping & DNS - my free Android networking tools app
patt rich
Greenhorn

Joined: Apr 07, 2008
Posts: 21
"Are you doing a "getClass().getName()" on that object? That'll get you the the name of the implementing class, but it's still an HttpServletRequest"...

Yes, I load this simple class using java's reflection mechanism. So I do 'request.getClass()' .
That could be the reason why this is happening?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61434
    
  67

HttpServletRequest is an interface. You shouldn't have any care about what the implementing class is. If you do, that is a serious design flaw.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
patt rich
Greenhorn

Joined: Apr 07, 2008
Posts: 21
I believe I am not taking the actual HttpServletRequest interface into account when I pass the parameter using reflection.

This is what I am doing:
In my servlet, I have the HTTPServletRequest and Response are available.

cl = Class.forName(receivingClassName);
Class[] classArray = { string1.getClass(),
string2.getClass(), request.getClass(), response.getClass() };
Object[] argVals = new Object[] {string1,string2, request , response};
Method method = cl.getMethod("loadRequestData", classArray);
objVal = method.invoke(cl.newInstance(), argVals);



And in my receiving class, the method "loadRequestData" looks like this:


public String loadRequestData(String string1, String string2,HttpServletRequest request, HttpServletResponse response) {
System.out.println("invoked successfully");
}

Looking at this do you think I am doing something wrong?
Thanks in advance for taking time to look at this..
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42289
    
  64
I don't understand where the need for the reflection gymnastics comes from, but a proper structuring of the code would suggest not to let the HTTP-specific objects propagate to anywhere outside of the servlet class. It'd be better to extract all relevant data from them into an appropriate data structure (maybe a Map), and then pass that along instead of the request and response object.
patt rich
Greenhorn

Joined: Apr 07, 2008
Posts: 21
The reason for using Reflection :- Actually the name of the receiving class "receivingClassName" will be decided only at run time in my project. Out of my 10 classes which are available, anyone of them can be taken the value of this "receivingClassName".

The reason for forwarding the HTTPRequest-Response as it is : - In the method 'loadRequestData', I want to redirect this request to a different URL, where this URL is again fetched from outside sources like properties files, depending on the name of the class. That's why I am trying to send the request as it is:

So I guess you are not recommending to send the request-response as it is right?

Thanks for spending time on this.
Ravi Kiran Va
Ranch Hand

Joined: Apr 18, 2009
Posts: 2234

hello ,

why don't you use a jsp page inside scriptlet you can do all your stuff and redirect it to where you want . (Not to my web page)
patt rich
Greenhorn

Joined: Apr 07, 2008
Posts: 21
Ravi, I cannot use jsp page instead of a servlet because I need this servlet for many other reasons in the whole picture of the project.
Thank you

Ravi Kiran Va
Ranch Hand

Joined: Apr 18, 2009
Posts: 2234

patt rich wrote:If I send a Javax.servlet.http.HttpServletRequest from a servlet to another simple Java class


you didn't get me , what i am saying is instead of our simple Java class use a JSP.



Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61434
    
  67

Ravi Kiran Varre wrote: why don't you use a jsp page inside scriptlet you can do all your stuff and redirect it to where you want . (Not to my web page)

Scriplets are more than 7 years out of date at this point. They should not be used on JSP pages.

And even suggesting the use of JSP for this non-view functionality is rather ridiculous.
patt rich
Greenhorn

Joined: Apr 07, 2008
Posts: 21
If anyone has any suggestions please let me know...
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61434
    
  67

Although I'm still not quite sure what you are trying to do...

patt rich wrote:The reason for using Reflection :- Actually the name of the receiving class "receivingClassName" will be decided only at run time in my project. Out of my 10 classes which are available, anyone of them can be taken the value of this "receivingClassName".

OK, sounds like a classic use-case for interfaces. If all ten classes implement the interface, they can be used interchangeably. I'm not sure what that has to do with the request implementation.

The reason for forwarding the HTTPRequest-Response as it is : - In the method 'loadRequestData', I want to redirect this request to a different URL, where this URL is again fetched from outside sources like properties files, depending on the name of the class. That's why I am trying to send the request as it is:

Not grokking that. Why do you need the request to do a redirect? Should you not be doing the redirect at the higher level in any case?

So I guess you are not recommending to send the request-response as it is right?

Absolutely. Passing container instances around is a sure recipe for trouble.
patt rich
Greenhorn

Joined: Apr 07, 2008
Posts: 21
I am not exactly sure how to aswer your thoughts from the first paragraph. Out of my 10 classes, each half is implementing different intefaces.

But about the second paragraph...
Before redirecting to another URL, I wanted use the request for other tasks like saving the request in a database etc. Also the URL is decided at run time. So i thought of doing all these specific tasks for each specific type requets, outside the servlet.

Since it's not recommended, now I decided to load the specific class reflectively, then save the request in DB etc, come back to servlet and do the redirect. Again call the specific class reflectively and do the rest of the tasks.

Anyway thank you so much for your suggestions. It was very helpful.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61434
    
  67

patt rich wrote:I am not exactly sure how to aswer your thoughts from the first paragraph. Out of my 10 classes, each half is implementing different intefaces.

The how can they possibly be treated the same? Or are you doing some massive switch statement?

like saving the request in a database etc

Please tell me this is a typo! How can you save a request in the database? It's a transient class! Are you rather, talking about saving thre request parameters?

If so, then only pass the parameter Map.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Javax.servlet.http.HttpServletRequest' is received as weblogic.servlet.internal.ServletRequestImpl