• Post Reply Bookmark Topic Watch Topic
  • New Topic

Trying to test a web service from TestClient.jsp but unable to succeed and find cause of error

 
Arunoday Das Gupta
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Everybody,

I am just trying to develop a short example for a web service and test it through TestClient.jsp available on Apache Tomcat. Here are the steps that I took:

1) Develop a wsdl to create Topdown web service. Here's my wsdl:



2) After creating the wsdl, I created service and implementation classes using start service and top down approach.

3) Lastly, I tried to test it via TestClient.jsp. I get the interface to feed in the parameters but when I invoke the web service I get teh error beneath as an attachement. Here's the error

Exception: org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 3; The markup in the document preceding the root element must be well-formed. Message: ; nested exception is: org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 3; The markup in the document preceding the root element must be well-formed.

I see nothing on the Tomcat console. I think it probably has to do with the wsdl. Can anybody please help?

Regards,
Arun
Capture.PNG
[Thumbnail for Capture.PNG]
 
Prabjhot Singh
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1. you can enclose Java code & wsdl with in
[ code = java ]


that way your shared code will look easy to read.
e.g.




2. you have following exception -

Exception: org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 3;
passed value must be well-formed


3) Lastly, I tried to test it via TestClient.jsp. I get the interface to feed in the parameters but when I invoke the web service I get teh error beneath as an attachement. Here's the error

The markup in the document preceding the root element must be well-formed.


 
Chris Barrett
Bartender
Posts: 317
24
Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Arunoday,

Adding a TestClient.jsp layer to your project before knowing if the WSDL or WebService implementation is working as expected makes your job of testing much more difficult. You really have no easy way of knowing which piece of the puzzle is broken.

Firstly, I would suggest you run your WSDL through the W3C WSDL Validator to check if it's valid: https://www.wsdl-analyzer.com

Then, look for a SOAP tester so you don't need to build TestClient.jsp yet. Now, you can isolate the WebService Implementation more easily.
SOAP-UI is popular, but sometimes overly complex (it's a complete TestSuite system).
There are also Chrome extensions (such as Boomerang)and Firefox extensions (such as SOA) if you need something more lightweight.

Touch base once you have validated the WSDL and tried testing your WebService Implementation using a SOAP tester. I think you'll find the issue is either in your WebService Implementation or the TestClient.jsp.


PS. Always use code tags when posting code to the forums, as Prabjhot suggested (thanks Prabjhot!). Unformatted or unindented code is extremely hard to read and many people that might be able to help you will just move along to posts that are easier to read. Please click this link ⇒ UseCodeTags ⇐ for more information. Properly indented and formatted code greatly increases the probability that your question will get quicker, better answers. I added the code tags for you. See how much easier the code is to read?
 
Arunoday Das Gupta
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Chris and Prabhjot!

I will take care of the forum etiquettes in future.

I did go through the route of Chris and was able to validate the wsdl and get a response while passing a SOAP message on soapUI. I tried again with TestClient.jsp but got the same error which suggests really that the message is not being passed in the right format by the TestClient.jsp.

I am happy that the web service is working. Let me know if there is a way to debug how TestClient. jsp is posting message. I will close and mark the thread as resolved anyways.

Cheers!
Arun
 
Chris Barrett
Bartender
Posts: 317
24
Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Arunoday Das Gupta wrote:I tried again with TestClient.jsp but got the same error which suggests really that the message is not being passed in the right format by the TestClient.jsp.


Good to hear you made headway. How are you implementing the marshalling of the form data to XML within the client's controller or service layer?
 
Arunoday Das Gupta
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Chris Barrett wrote:
Arunoday Das Gupta wrote:I tried again with TestClient.jsp but got the same error which suggests really that the message is not being passed in the right format by the TestClient.jsp.


Good to hear you made headway. How are you implementing the marshalling of the form data to XML within the client's controller or service layer?



Hi Chris,

Actually, I was testing the web service following an online material using top-down approach. In particular, I am not handling the marshalling of the XML explicitly anywhere.

Regards,
Arun
 
Chris Barrett
Bartender
Posts: 317
24
Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When you have a moment, perhaps you could post your TestClient.jsp? Based on the screen shot you posted, it looks like the user entered three fields. I would expect that the form would then be passed to a controller/servlet that would generate the required PackagingRequest object, which it term would be passed to your service layer that implements the WebService's WSDL port.
 
Arunoday Das Gupta
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Chris,

Here is TestClient.jsp



Regards,
Arun
 
Chris Barrett
Bartender
Posts: 317
24
Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I suggest you scrap that and start fresh. You already know the SOAP WebService is working (SoapUI proved that). If you want to build out your own test harness, please, please do NOT use scriplets in JSP. No programming logic should ever be in them. Scriplets have been obsolete for about 15 years now. Instead, look at setting up a Model View Controller (MVC) design pattern. Your JSP should only be for view. If you are not familiar with the MVC design pattern, this post should help you out.

The process for setting up the client/consumer SOAP side is not much different than the WebService Implementation/producer. The primary difference is that this time you will be using the WSDL generated by the WebService Implementation (and not the file based WSDL your WebService Implementation used). Your client Controller Servlet will obtain the request parameters from the JSP form, generate a PackagingRequest object with the parameters, and pass the PackagingRequest to the @WebServiceClient @WebEndpoint created during the Top-Down process.

To help you see what I mean, I've posted a snippet below of the code that should be in the Controller Servlet. The id, product and stringDate Strings would have already been retrieved by the Controller from the request object:

Once you have the returned PackagingResponse object, you can display as you see fit.

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!