I am new to webservices testing and i am trying to test a webservice which returns both a JSON as well as XML output .
my management wants me to do this with jackson jersery and other libraries for XML
i created a java client using jersey and i got the response . i am not sure how to validate this response against a POJO class .
i am not entitled to use sophisticated libraries like rest assured or json path . can some one explain me how will i validate/assert both json and xml response against a POJO step by step and make my life easy ?
kindly help
also list down the libraries needed for handling xml responses too ?
Karate is a new test-framework for testing web-services, and it supports both JSON and XML. You don't need to know Java and it does not need you to add any libraries. The documentation is extensive and the demo project has examples.
Disclaimer: am dev.
Related
In a very big Java app with lot's of DTOs, I want to export to an external project only the DTOs that are relevant to REST calls, and even better to export a part of them (the minimum required for REST calls).
The project uses Swagger and I am wondering if it is possible to take the output of Swagger (uses Java DTOs to create JSON\YAML files), which have the exact content I need, as an input to generate new Java DTO files. The generated files will be only those needed for REST and I will be able to easily export them.
Is this possible?
If not, what is the best approach to do that?
Maybe check out swagger.generator.io where you can generate a whole client library (including DTO classes) for your specified swagger definition file. For documentation please refer to their github page. You can also do the generation of the API client locally utizing the swagger codegen tools.
I would like to generate a Java object from JSON. All examples on the Internet use an ObjectMapper class and a Java class to serialize the JSON too.
The JSON is complicated, and I don't want to define the Java class by hand with annotations for properties.
I want to be able to generate the Java class with Jackson or GSON annotations with the JSON data with software.
The website jsonschema2pojo does this for you online. My JSON is offline in a private network where I cannot use jsonschema2pojo for a complicated JSON string.
How can I replicate the jsonschema2pojo code in my own environment? Is it easy to do with Jackson, or GSON?
I don't think Jackson or GSON have this support yet but lots of people have contributed code according to your requirement.
You can check:
https://github.com/astav/JsonToJava
or
https://github.com/wotifgroup/json2pojo
Moreover maybe you can try downloading that dependent jar manually and add it in your MAVEN repository manually.
You can use jsonschema2pojo offline. It can be used as a Maven plugin, a Gradle plugin, and command line tool or an Ant task.
At the bottom of the page at www.jsonschema2pojo.org you'll see links to help with each of these methods.
I'm trying to implement a simple java webservice in top down approach using Apache Axis2.
This webservice shall send list of values as output.
When I tried to configure java.util.List as response output, I did not find any mapping with xml types for this java collection.
How do we setup java collection(List) type to return as output.
I'm looking to get some help to resolve this issue.
Thanks!
Standard SOAP does NOT know about Java objects, it only knows about variables such as strings, numbers, etc.
If you really need to send Java objects, you could serialize them to an object stream and send the resulting binary as a SOAP attachment. See SAAJ - the SOAP with Attachments API for Java. This of course would require that your client side have access to the 3rd party library as well as your own custom class library.
I have the following requirements and thinking about how to best get java objects from a WSDL.
XML data comes from a public SOAP Webservice
I have to use JAXB
I want to automatically unmarshall the retrieved data to Java objects
Ideally I'd like to have java objects using JAXB Annotations. Are there any tools that I could combine to autogenerate these?
Sure, there are lots of ways to use JAX-WS (which uses JAXB for its XML binding) to generate a web service client.
You can execute it from the command-line:
http://www.mkyong.com/webservices/jax-ws/jax-ws-wsimport-tool-example/
As part of your Maven build:
https://jax-ws-commons.java.net/jaxws-maven-plugin/
Or from within your Eclipse environment:
http://help.eclipse.org/juno/index.jsp?topic=%2Forg.eclipse.jst.ws.cxf.doc.user%2Ftasks%2Fcreate_client.html
Yes, there are. With every jdk, there is an executable file called wsimport that does exactly what you want.
Here is an answer i gave to a similar question.
I need to create connection to web service with axis2. I would like to know how can I convert recieved xmls to Java objects. Is there any good tutorials to learn how to do this?
Axis2 is pretty well documented. Make sure to check the axis2 user guide.
On the other hand be aware of that using web services and axis2 is not a piece
of cake sort of think, so read the docs exhausitvly. ;)
Either the XML is part of the SOAP request. In that case, Axis2 will convert it to Java for you.
If XML is part of a "data blob", then you need to do this yourself. There are several options:
You can have a look at the generators which Axis2 uses. Try the docs.
Use an XML OO mapper like Castor.
You can write your own mapper (not really recommended).
If you can influence the sender side, you can try to create XML that follows the rules for XMLEncoder. That would allow you to use the standard Java Serialization API to build objects.
use axis wsdl2java tool and put generated classes to your source files. Then first create a service stub with YourServiceStub(Service_Adress) and use that instance to invoke necessary methods.
for wsdl2java i commonly use:
wsdl2java -uri wsdlLocation -ss -sd -uw -g -o outputLocation