• 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
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

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

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
whats your requirement ?? why are you sending servlet as a parameter to Java class ??
 
patt rich
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
first tell me, Why are you opting for a simple java class rather it being an other servlet
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
patt rich
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"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?
 
Sheriff
Posts: 67756
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
patt rich
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Sheriff
Posts: 67756
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If anyone has any suggestions please let me know...
 
Bear Bibeault
Sheriff
Posts: 67756
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 67756
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic