• Post Reply Bookmark Topic Watch Topic
  • New Topic

doubt: how to make a client (servlet) consuming webservice

 
ronald silva
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi.
my doubt:
I made a simple webservice:



how I would make a "Client-Servlet"?

for example: a myfile.jsp (containg two forms to put the numbers n1 and n2, and a bottom to calculate) and the myservlet.class to consume the webservice and show the result.

myfile.jsp -> myservlet.class -> webservice -> myservlet.class -> result.jsp

is it possible?

please, no IDE.
 
Paul Clapham
Sheriff
Posts: 21863
36
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, it's possible. In fact I can't tell what barriers you imagine are in your way. Perhaps you could explain in a little more detail why you are having trouble doing that little example.
 
ronald silva
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi, Paul, how are you?
I am learning java and webservices.
I made the webservice using AXIS. (I saw an example in the internet).
and... the internet teaches how to make a client to webservice using java without servlets.
I need to learn to make a client using servlets.
I went to the shopbooks, libraries, and I didnt find any book about client-servlet consuming the webservice.
can you help me?


 
Paul Clapham
Sheriff
Posts: 21863
36
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You already know how to write Java code which consumes a web service. So if you want to write a servlet which consumes a web service, you would take that Java code and insert it into the servlet.
 
ronald silva
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
well, in the site thai I have seen the example of webservice, there is the code:



how do I adapt the code above to servlet-code-client?

 
Paul Clapham
Sheriff
Posts: 21863
36
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
(I put code tags around your code so it's a bit more readable. Indented code would have been even nicer... anyway have a look at UseCodeTags for more information about how to do that in future.)

Anyway here's the relevant code which consumes the web service:



You'd start by putting that into the get() method of your servlet, or whatever method is being called when a request is sent to it. But you want your inputs to come from the request, so you would remove the hard-coding of the "param" variable and replace that by something which gets two numbers from the request parameters. Then you'd replace the last line by something which puts the result into the servlet's response.
 
ronald silva
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Paul,
well, and if we forget the form.jsp (with the forms)?
lets keep the servlet with fix parameters (number one = 15 and number two = 15)
and now? what do we need to do the servlet works?

this is the wsdl:



I am lost...
 
ronald silva
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
please, could you show me the complete code of servlet?
 
Paul Clapham
Sheriff
Posts: 21863
36
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Of course not. We aren't a service to do other people's work here.

But it should be simple enough. Why don't you start with a servlet which receives two parameters and just echoes them back to the requester? Nothing more than that. Forget about the web service consumer business for now, you can add that in later.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!