Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

HttpServletRequest - not building it from an html form nor from urlcon 1

Status
Not open for further replies.

iza

Programmer
Apr 4, 2000
1,804
FR
hi :)
i know how to call servlets from html forms
i also know how to call them from a class using urlconnection - if they are running (= if the server is up)
but now, for testing purpose, i NEED to call my servlets from a "normal" class, while the server can be down
i just want to call this function :
doGet(HttpServletRequest request, HttpServletResponse response)
from another class ... but the "HttpServletRequest" is an interface, i can't "create" one :(
the only implementing class is HttpServletRequestWrapper but you need to have a non-null HttpServletRequest to build one :(
so if anyone has any idea, please tell me !
------
please review FAQ183-874 - this will help you to get the best out of tt
[ "you" is not someone in particular - don't take it too personnal ]
 
no, you can create an instance of interface but u can create your own object that implements the interface. you can pass in that as a parameter. because it implements the interface, it will be accepted as a valid object of that type

i.e.

class myRequest implements HttpServletRequest

you are going to have a headache doing this but it should work.

why do you have to test this is the server is down? is will never work if the server is down :)
 
i'll try to implement a sub-class, thanx for the tip :))
(and sure i'll have a headache !!!!!! but that's just the rush before going on va.ca.tions :))))))))))))))))

i don't think having the server up or down will affect the servlet class itself - i mean, if i have this :
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException
{
PrintWriter out = response.getWriter();
out.write("something");
}
and IF i manage to write an implementation class for response that returns a printwriter, this should work wheter the server is here or not

and if i'm not running the servers to test it's 1- part of the requirements (i didn't write them !) and 2- because my tomcat/apache run under linux while my test tool runs under win2000 :(((((((( ------
please review FAQ183-874 - this will help you to get the best out of tt
[ "you" is not someone in particular - don't take it too personnal ]
 
Doh!!!!

best of luck and let us know if it worked

off anywhere nice for your holidays? south of france??
 
i got the response.getWriter() returning a file output stream (roughly) - still i can't build the http request but hopefully i soon will (i already can build a data input stream, now have to find a way to transform it to a servlet inputstream or something ........ but as it's 19h00 (sorry, 7:00 pm) here and starting to rain, i'll go back home, cure my headache, a rethink everything tomorrow morning !)

and i'm going to an even nicer place than the south of france :]]]]] i'm going to tunisia, south of it, very very south (souther than zarzis and djerba if you know) - where there are only sun, sun, sun, camels, snakes, scorpions, sand, rocks, heat, and palm trees (and yes, awesome beatches, the sea is hot, the sand is very fine and there's almost nobody :)) - oh, and i'm almost sure i won't find a computer there :)) ------
please review FAQ183-874 - this will help you to get the best out of tt
[ "you" is not someone in particular - don't take it too personnal ]
 
guess what ?? doPost & doGet are protected ... and i can't place my test classes under their packages (javax.servlet.http...) - neither can i inherit from a servlet (as i already inherit from test case) ...
sounds like i'll leave without the tests ready :(
i'm still seeking any help from anyone !! ------
please review FAQ183-874 - this will help you to get the best out of tt
[ "you" is not someone in particular - don't take it too personnal ]
 
no ! i was thinking that if doPost is a protected method, then i should inherit from its class (servlet ...) so that i'm allowed to use it :(
anyway i guess i finally found a site that will save me : this is so great :))))) they've coded everything for me :)))))))))
i'll let you know (IF ... if i don't run away in vacations as soon as the code works !!!) ------
please review FAQ183-874 - this will help you to get the best out of tt
[ "you" is not someone in particular - don't take it too personnal ]
 
grand, enjoy tunisia and remmeber...leave the camels alone!!!!! i've heard what you french men are like!! :)
 
will that work? it allows u to access your site without a browser but a web server is probably still needed i.e. the servlet should work as normal. i didn't think this is what you wanted??? :-/
 
liam, i'm a woman, so i'm not interested in camels at all ;]]] - and what's more, my boyfriend is already in tunisia, waiting for me (! i hope he isn't fooling around with some camels meanwhile ... i'll call him right now !) ;-)

and yes, quickly reading the doc made me thought starting the server wasn't needed, but it is :(
but there MUST be a way to call doPost(HttpServletRequest request, HttpServletResponse response) with 2 fake class pretending they are HttpServletResponse and HttpServletRequest ... i just can't figure how, but there is to be a way !!!! (1 hours remaining to find it ... good luck !) ------
please review FAQ183-874 - this will help you to get the best out of tt
[ "you" is not someone in particular - don't take it too personnal ]
 
You would have to write your own "server". Servlets are dependant on a bunch of services being available from the Servlet Engine. Wushutwist
 
thank you wushutwist :)))
i think something like "ant" (apache project) would help me - does anyone know if i'm wrong or not, and where i could find more details (appart from on the apache/ant website) ? and do you think i'd better ask for this in the apache forum ? ------
please review FAQ183-874 - this will help you to get the best out of tt
[ "you" is not someone in particular - don't take it too personnal ]
 
ant is a build program. Definitely not going to help.

There is not much you can do. The problem is, you would need to remotely instantiate the servlet's init method and pass a it a ServletConfig object. Only then could you think about called doPost/doGet. It would at this point be a trival matter to form a request and response to pass. But if you are going to try this and you have no problem remotely instantiating then you could use another Web Server to manage the Servlets for you (much easier). You would need some kind of VPN between you and the server machine to set this up without compromising security completely.

The reason you need to do this is the Servlet Specification requires that init() be run before any requests are processed. There would be no telling what kind of wacky results you would get if init() was never called, most likely about a thousand runtime errors.

Wushutwist
 
the ant project is just like the make facility on unix, it compiles and builds files.

i think you should go to your project manager and tell him it isn't possible to execute servlets outside a servlet engine, thats why servlets engines EXIST!! :)

if he disagrees, tell him your off on holidays and you'll look forward to seeing his code by the time you've got back from your holidays :)

Sorry about the french man remark :)

A tourist walked into a pet shop and was looking at the animals on display. While he was there, another customer walked in and said to the shopkeeper, "I'll have a C monkey please." The shopkeeper nodded, went over to a cage at the side of the shop and took out a monkey.
He fit a collar and leash, handed it to the customer, saying, "That'll be $5000."
The customer paid and walked out with his monkey. Startled, the tourist went over to the shopkeeper and said, "That was a very expensive monkey. Why did
it cost so much? "
The shopkeeper answered, "Ah, that monkey can program in C, very fast, tight code, no bugs, well worth the money".
The tourist looked at the monkey in another cage. "That one's even more expensive! $10,000! What does it do?"
"Oh, that! one's a C++ monkey; it can manage object-oriented
programming, Visual C++, even some Java. All the really useful stuff," said the shopkeeper.
The tourist looked around for a little longer and saw a third monkey in a cage of its own. The price tag around its neck read $50,000.
He gasped to the shopkeeper, "That one costs more than all the others put together! What on earth does it do?" The shopkeeper replied, "Well, I haven't actually seen it do anything, but the other monkeys call him the project manager."
 
thank you both :)))
well i'll give up and go happily on holidays (now i'm totally worried about that camel thing, i have to hurry ;) ! but i'm totally reassured to know it can't be done - i was starting to think i was stupid not to figure out how to call servlets without a server ;) and about to buy a java-monkey ;]])


------
please review FAQ183-874 - this will help you to get the best out of tt
[ "you" is not someone in particular - don't take it too personnal ]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top