aspose file tools*
The moose likes Web Services and the fly likes String SOAP xml to java object Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Web Services
Bookmark "String SOAP xml to java object" Watch "String SOAP xml to java object" New topic
Author

String SOAP xml to java object

Sebastian Fresta
Greenhorn

Joined: Mar 09, 2011
Posts: 3
Hi All,

i'm a bit new with webservices and i need to do some test code without the need to contact the webservice. I extracted a sample call soap xml using SoapUI and i would like to know if its possible to convert this string into an object using something like Jaxb or some other framework.

Thanks a lot for the help
Kumar Raja
Ranch Hand

Joined: Mar 18, 2010
Posts: 519
    
    2

What are you trying to test, by not invoking the webservice? Something you wanted to work on the SOAP xml.


Regards
KumarRaja

Sebastian Fresta
Greenhorn

Joined: Mar 09, 2011
Posts: 3
Hi,

I was asked to create a sample class which behaves like the webservice and that would return the class returned by the webservice. this is required so to test the remaining of the application without the need of the webservice since we use a test server and most of the time this is down
Creating a sample class manually will be too much because it has a lot of data and subclasses. I finished up parsing the xml manually using javax.xml.parsers and org.w3c.dom.Document, etc. but i would still would like to know if there is a way to accomplish this.

thanks again
Kumar Raja
Ranch Hand

Joined: Mar 18, 2010
Posts: 519
    
    2

Sebastian Fresta wrote:Hi,

I was asked to create a sample class which behaves like the webservice and that would return the class returned by the webservice. this is required so to test the remaining of the application without the need of the webservice since we use a test server and most of the time this is down
Creating a sample class manually will be too much because it has a lot of data and subclasses. I finished up parsing the xml manually using javax.xml.parsers and org.w3c.dom.Document, etc. but i would still would like to know if there is a way to accomplish this.

thanks again


Hi Sebastian,

I'm not sure, if I understood completely, but you basically wanted to test your service, by not having the service deployed in some web or ejb container. If that is the case, javax.xml.ws.Endpoint is at your rescue. I don't know, if this is ever used in production, but certainly a good option for testing, where proper containers are not available. But please be aware that using this, you may not be able to get benefited by the features the containers provide.
Sebastian Fresta
Greenhorn

Joined: Mar 09, 2011
Posts: 3
Thanks a lot for the info. i will test it and post how it went
Aj Deschanel
Ranch Hand

Joined: Oct 20, 2009
Posts: 40
Sebastian Fresta wrote:Hi,

I was asked to create a sample class which behaves like the webservice and that would return the class returned by the webservice. this is required so to test the remaining of the application without the need of the webservice since we use a test server and most of the time this is down
Creating a sample class manually will be too much because it has a lot of data and subclasses. I finished up parsing the xml manually using javax.xml.parsers and org.w3c.dom.Document, etc. but i would still would like to know if there is a way to accomplish this.

thanks again

use JAX-WS, if you want to deal with the SOAP/XML manually, it has special classes for SOAP
check saaj-api.jar file package javax.xml.soap.*

Resources
http://jax-ws.java.net/
http://www.mkyong.com/webservices/jax-ws/jax-ws-soap-handler-in-server-side/

SCJP 1.6, SCWCD 1.5
Nic pearce
Greenhorn

Joined: Mar 19, 2011
Posts: 1
The foundation of Web services lies in the sending and receiving of messages in a standard format so that all systems can understand them. Typically, that format is SOAP. A SOAP message can be generated and sent manually, but the SOAP with Attachments API for Java (SAAJ) -- an offshoot of the Java API for XML Messaging (JAXM) -- automates many of the required steps, such as creating connections or creating and sending the actual messages. This tip chronicles the creation and sending of a synchronous SOAP message.

The process involves five steps:

Creating a SOAP connection

Creating a SOAP message

Populating the message

Sending the message

Retrieving the reply
.................
Nic
Payroll India
Ivan Krizsan
Ranch Hand

Joined: Oct 04, 2006
Posts: 2198
    
    1
Hi!
Instead of writing a mock service yourself, I suggest looking at soapUI.
It can help you generate a mock service very quickly and can even create a WAR file containing the mock service, which then can be deployed to a regular web container (Tomcat).
soapUI can also start a server from within soapUI itself, exposing the mock service.
Best wishes!


My free books and tutorials: http://www.slideshare.net/krizsan
Lingan Rajan
Ranch Hand

Joined: Jan 26, 2011
Posts: 30
Hi
If a container is going to be up during the testing then you could as well have a simple servlet that will be return a hard coded SOAP response.
The caller of webservice will invoke the webservice with no change.

Lingan.
Grant Gortsema
Greenhorn

Joined: Apr 19, 2011
Posts: 1
We had a similar situation in that we needed to mock a web service for various reasons. We used a factory method to get the manager class that interacts with the service and so rather than having to stub out the ws we just had to mock up an implementation class for the interface. This has the added benefits of hiding your web service details from the parts of the code that just care about what it does and not how. It's also helpful if you use more than 2 web services so you can just use the factory to get what you need. This may not be what you need, but this is how we solved the type of problem you are facing.


"Anyone who says 'as easy as taking candy from a baby' has never tried taking candy from a baby." R. Hood
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: String SOAP xml to java object