I have a REST service that produces a JSON output. I'm using Jersey. I can see my WADL in XML format when I type <server>/<rest>application.wadl and I get, for example, the following keys:
<response>
<ns2:representation xmlns:ns2="http://wadl.dev.java.net/2009/02" xmlns="" element="script" mediaType="application/json"/>
</response>
Now I need to describe the json that the service returns. How can I do that?
EDIT: There seems to be a solution here:
http://java.net/jira/browse/JERSEY-638
There is a patch available, but I don't know how to use this patch. What do I do with the ".patch" file?
The .patch file can be applied using SVN Apply Patch command.
The Jersey source code version 1.x can be found here. There is a checkout URL specified. I think that patch was not officially accepted thou you can use it locally, accepting all the risks, probably.
Related
I'm running a Spring Boot REST application with Spring HATEOAS support and generating OpenAPIv3 docs with the Springdoc Maven plugin. However when I call my REST endpoints I get links the in HAL formatted JSON ("_links"). But the generated OpenAPIv3 documentation is giving me a different format for the links ("links").
How can I get the generated OpenAPIv3 docs to match the HAL formatted links?
The only resource I've found is this link: https://github.com/springdoc/springdoc-openapi/issues/446
However, the solution given there involves using spring-data-rest which I am not using (do I need to?)
I've also tried adding #EnableHyperMediaSupport which says it configures the JSON rendering, but that had no effect on the OpenAPIv3 docs.
The answer was simple enough, I needed to pull in the springdoc-openapi-hateoas dependency (https://springdoc.org/#spring-hateoas-support). After pulling this in the JSON documentation was generated correctly with no additional configuration (I did not need #EnableHypermediaSupport or spring-data-rest).
However, if you are using the Swagger UI be aware that it will automatically generate bogus 'additionalProperty' links as an example for the resource schema. This is only in the Swagger UI, if you look at the generated openapiv3 json the structure is correct (cf: https://github.com/springdoc/springdoc-openapi/issues/237). To remedy this you can provide your own example of the resource schema.
Is there a tool that allows me to create random JSON test data starting from a RAML file?
Example: starting from a RAML file describing an API generate random static JSON responses to register in a WireMock mock server mappings so that I can run automated tests against the API.
I'm working with Java but tools/libraries in other languages would fit too.
Thanks
Maybe one of these suits your needs:
RAML Mock Server: Library for validating MockServer calls against a RAML API specification
RAML Tester: Test if a request/response matches a given raml definition
soapui-raml-plugin
Allows you to import RAML files into SoapUI for testing your REST APIs
Allows you to generate a REST Mock Service for a RAML file being imported
Otherwise check: http://raml.org/projects/projects and filter by type 'test' and language.
Perhaps https://github.com/wavesoft/raml-lipsum might be useful.
That seems to indicate that it can do as you ask. I didn't think that the other answers seemed to generate sample requests for a raml service, which is I think what the question asks for, and I was asked today at work.
I've started using Apache Nifi and I'm still learning it and experimenting with it. I really want to use Nifi to get JSON documents from API's and put them in my Elasticsearch database. So far using the built-in getTwitter and putElasticsearch controllers this works.
However now I want to do this with other APIs than Twitter, and I'm kinda stuck here. First off I really don't even know which controller to use? I would think getHttp or invokeHttp even with 'GET' as http verb then but it doesn't seem to work. If I use the getHttp I have to give an SSL service with keystore and truststore .. like why would I have to do that?
Apache Nifi is still quite new so hard to find decent guides / information about these kinds of things. I have read and searched the documentation but haven't gotten the wiser.
An example JSON to pick up from an API is:
https://api.ssllabs.com/api/v2/getEndpointData?host=www.bnpparibasfortis.be&s=193.58.4.82
Thanks in advance for anyone that can offer some help / insight.
What processor you use to get the JSON data is entirely dependent on the API you want to hit. The GetHttp or InvokeHttp processors should work to grab the data from a URL. If you'll notice, the SSL service is an optional property for both GetHttp and InvokeHttp so you only need to you use it when you want to communicate via HTTPS. Also, from the UI you can right click on a processor and then click "usage" to bring up the documentation for that processor.
At this link[1] you can find a NiFi template that uses GetHttp to get JSON data from randomuser.me and does various processing on it. It's primarily a template to show-case the different Avro processors but the method of grabbing the JSON should be relevant.
[1] https://github.com/hortonworks-gallery/nifi-templates/blob/master/templates/Convert_To_Avro_From_CSV_and_JSON.xml
I am trying to pass JSON data in a post to a Jersey- based REST service. After getting HTTP 415 errors, I researched and learned that Jersey needs certain Jackson Jars in order to handle JSON.
I have been trying to find the correct Jars, but every link I am finding seems to point to places where there are a lot of README files and XML files but no Jars!
There are also several links provided here on Stack Overflow to Jackson jars. They either don't work, point to links without jars, or point to versions that will not work with Jersey v2.
Worse, I cannot find a consistent list of the Jackson jars needed for Jersey! I keep seeing different lists of Jar files that I cannot find.
Can someone please point me to the correct Jackson jars needed to provide Jersey with JSON processing??? Where can I find and download them?
Just grab all the below Jars.
You can find all of them here. Just search for them individually.
If you are registering your providers individually, regiser
JacksonJaxbJsonProvider for basic JSON/POJO support.
JsonMappingExceptionMapper for an ExceptionMapper for JsonMappingException
JsonParseExceptionMapper for an ExceptionMapper for JsonParseException
Or if you are registering packages to be scanned, add this package
com.fasterxml.jackson.jaxrs.json
Note: The above image is from an older post. Jackson is at 2.6.1 right now. If you want, you can get the newest version. Doesn't make a difference. Just make sure all the jars are the same version
As Horst Keller mentioned in his ABAP and JSON post, "with Releases 7.02 and 7.03/7.31 (Kernelpatch 116) JSON is supported natively in ABAP".
Appartently 7.02 in my case of too generic because the line below:
writer = cl_sxml_string_writer=>create( type = if_sxml=>co_xt_json ).
returns the error: "The field CO_XT_JSON is unknown, but there is a field with the similar name CO_XT_XOP".
So is there any way to easily generate JSON?
Edit: Screenshot from SAP - Status
About the class CL_TREX_JSON_SERIALIZER: I also used this class during developping a mobile sap application and I found the created JSON not being valid, thus I started googling and found this http://scn.sap.com/community/mobile/blog/2012/09/24/serialize-abap-data-into-json-format (which also explains how to create a valid JSON serializer).
Validate your json with json lint http://jsonlint.com/ to see if it is valid.. otherwise, thats for sure, you get a lot of trouble in debugging why it doenst work and dont get the point that the serializer is corrupt. regards, zY
take a look at the ZCL_MDP_JSON Library. You can parse/encode any JSON. So, it is best suited for JSON scenarios that requires flexibility.
It is easy to understand if you have used JSON in other languages. You only need to study methods of ZCL_MDP_JSON_NODE class once & look at the examples.
Here is an extended overview of the library:
http://scn.sap.com/community/abap/blog/2016/07/03/an-open-source-abap-json-library--zclmdpjson
GitHub repo with examples directory: https://github.com/fatihpense/zcl_mdp_json
Disclaimer: I'm the author of the project. If you have questions, don't hesitate to contact me.
Here is some code I wrote for ABAP data <-> JSON conversion some time ago before the new capabilities were included with ABAP (or maybe it was just an older system).
https://gist.github.com/mydoghasworms/2291540
Include the code in your ABAP source and use the method data_to_json of the class.
A nice overview of custom ABAP <-> JSON serializers including yet another one can be found in this blog post
Most popular from my point of view is SE38's ZJSON-library which can be installed using SAPLINK (and which - in contrast to many others) has an explicit license attached to it: Apache 2.0
If upgrading to a newer patch isn't an option in the short term, you can also use class CL_TREX_JSON_SERIALIZER to serialise objects to JSON. A little bit of a quick-and-dirty solution but it works well.