• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Is it possible to return a web form through a web service?

Colin Brampton
Posts: 1
Java Netbeans IDE Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there,

I'm so sorry to bust up your day with this, but I've been wrestling with this for over a week now. I'm completely stuck, and I would be very grateful for any assistance you can offer. I've had some experience with J2SE, but J2EE is new ground for me and I'm still finding my way, so please, be gentle...

Current system
I'm trying to modify an existing system to provide some additional functionality. The original system comprises of two separate web applications and looks like this:

JSP1<===>Servlet1<===>W.S.Client<==========>Web Service

The user completes a form in JSP1, the form data is submitted to Servlet1, and the data is passed to a web service client. The client sends the data to the web service in WebApp2, the data is processed, and a result is sent back through the client to Servlet1 in WebApp1.

New requirements
It is now required that when data is delivered to the web service, the user should be presented with a second form which is also to be hosted by WebApp2. It is also required that the web service should defer returning data to its client until after the user has completed entering data in the second form.

Clearly, it would be easier and preferable to call a servlet or JSP in WebApp2 directly from Servlet1. Unfortunately, I'm dealing with a legacy system and I'm stuck with trying to modify the existing web service.

Attempted solutions
As the second form has to be visible over the web, my first thought was to use a servlet or JSP, so by way of an initial trial I implemented a servlet (WebServiceServlet) with a single doPost() method in WebApp2:

JSP1<===>Servlet1<===>W.S.Client<==========>Web Service<===>WebServiceServlet

In the web service, I used a URLConnection to connect with the servlet:

WebServiceServlet is only required to accept the values which are sent by the web service, display them on the screen, and concatenate them into a string which is returned:

When I ran WebApp1, the system behaved correctly in that data from JSP1 was delivered through Servlet1 and the W.S.Client to the Web Service in WebApp2, and forwarded to WebServiceServlet; the data items were concatenated into a single string which was returned through the chain to Servlet1. Only problem is, nothing from WebServiceServlet was displayed on the screen!

I ran the system again, and I noticed that the browser bar remained stuck at Servlet1 in WebApp1. In an effort to resolve the problem, I ran searches with various permutations of "call/invoke (a) servlet from (a) web service", and I eventually found some sensible guidance for this in a response by Ulf to a query from Lillo Birillo in the web services forum: http://www.coderanch.com/t/221999/Web-Services/java/Invoking-servlet-web-service

The challenge here is to write a servlet that can be instantiated, and I was lucky to find some good advice in Frank Carver's feedback to Sanjay Karanjkar at:

By way of an initial trial, I implemented Frank's (not so) SillyServlet code to see what would happen, substituting the main() method for a similar run() method.

JSP1<===>Servlet1<===>W.S.Client<==========>Web Service<===>SillyServlet

When SillyServlet is run independently, it performs exactly as expected, with both constructors and doGet() being called. However, when SillyServlet is called through the web service client in WebApp1, it behaves very differently; every method in the class is called except DoGet() and as before, the browser bar remains stuck at Servlet1.

Data from WebApp1 can be successfully sent through a web service to a servlet in WebApp2, the data is correctly processed in the servlet, and values are correctly returned to WebApp1. The problem is that I can't persuade the servlet in WebApp2 to display anything to the user. Yet.

1. Still the main question - is it possible to return a web form through a web service?
2. If it is possible, what would you consider to be the best strategy and technology to use?
3. If a servlet or JSP is to be used, how can I get either of them to display data on the screen?

Finally, as this is my first posting to JavaRanch, I would greatly appreciate feedback from experienced ranchers regarding the quality of my question.

Thank you for your kind attention,

  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic