• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

String SOAP xml to java object

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 558
2
Hibernate Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What are you trying to test, by not invoking the webservice? Something you wanted to work on the SOAP xml.
 
Sebastian Fresta
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 558
2
Hibernate Spring Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot for the info. i will test it and post how it went
 
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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/
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 2198
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!
 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
I suggest huckleberry pie. But the only thing on the gluten free menu is this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic