I am a complete Camel FNG migrating from a JMS service to a RESTful service; part of that is integrating with an elasticsearch server. I am using Fuse with the Spring DSL.
The main idea is to poll for data from a whole bunch of servers running a REST service, marshal them to XML (if necessary, see below), strip the top level key (foo:{...}) and push each of the keys to an elasticsearch database. a reply from the service would be of the form:
{"foo": {"bar":{"type":"tweet","info":"blahblah"},"baz":{"type":"tweet","info":"blahblah"}}}
My questions are as follows:
1-How do I get data from the webservice? I dug around looking for a concise example, to no avail. If I understand correctly, it involves the jetty component in camel. say I want to pull json from http://myrestservice:7700.
2- Does the json need to be marshaled to XML to remove the top-level key?
Thanks in advance!
You can use camel-cxf [2] producer to call those running REST services and pass the result which will be your json to a processor and then use JSonPath [2] to traverse over your json and customize it the way you want it.
[1] http://camel.apache.org/cxfrs.html (see "Consuming a REST Request - Default Binding Style" section)
[2] http://camel.apache.org/jsonpath.html
Related
We need a JSON mapper from Type-A to Type-B ( i.e. JSON to JSON string). I'm aware of ESB tools which has mapping for XML to XML like IBM ESB.
So do we have any open source tool or paid application
Which has an editor to do mapping of JSON to other JSON , with capability to do some basic operations like formatting, etc
Can this transformation be exposed as REST service
If needed be, extract this transformation logic as JAR file and other team can use it
Thanks.
Manjesh,
I have good news for you. There is indeed an open source program that will accomplish this for you. Talend Open Studio (TOS) ESB (not to be confused with their TOS for Data Integration). Any ESB tool should do this quite easily. See below:
Image 1 shows in SoapUI where I am calling a REST service, passing the JSON prefix: team1, team: Giants is sent in. I return: Prefix: Cowboys are better than, Team: Giants. I could have done other manipulations (including changing the json structure) but put together a simple example.
The next image shows the Talend REST service implementation within Talend:
finally, I show the internals of the component (tXMLMap_2) where I manipulate the json data.
I am looking for either guidance or a good example where I can map data coming from rest services to JSON "type" object which can then be used in a number of different react components.
The JSON Object will be used to map data from a few different rest services, which essentially hold very similar data which makes it better to use one object and then to bind the data to the respective React Components.
I am fairly new to React.JS and I have googled around to find a data mapper to JSON from Rest Service example.
Can anyone help?
You typically don't have to do too much, at least on the front end side. As long as the REST endpoint can return JSON responses you'll be fine. Just make sure you set the appropriate Content-Type headers in the request. Note that setting the header doesn't guarantee a JSON response, the server has to be able to send it in that format.
If you're creating the REST service yourself, you have many options. If you're using node, you can simply return a javascript object. If you're using some other language like Java, C#, etc., they come with libraries that can serialize objects into JSON for you. I use JSON.net when working with C#. In these cases, because the data will be returned as a string, you'll just need to JSON.parse() it upon receiving it and then set it to the appropriate React component's state.
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
How to call a rest service that returns JSON in a APIKit based message flow. I want to prepare the request for Rest service and want to extract the JSON message in a message flow.
Can any one help me to do this?
Thanks
The recommended way to invoke/consume REST services in mule is the use of HTTP Request
Do let us know if there is a specific you are facing
The request connector is especially handy when consuming a RESTful API
that is described in a RAML file. If you reference the API's RAML file
in the connector's configuration, it will proactively offer you the
set of available resources and operations contained in the RAML file,
as well as enforce the policies described in the file. It will also
expose the API metadata to Studio, which can then be used by other
elements such as DataWeave to autocomplete fields and make
configuration much easier
Use Rest URI path to invoke the Service and you can also get json response as output based on the type of service you invoke
I am trying to create a REST web service using JAX-RS. In that, I have PUT method or POST method which consumes the json as mediatype in the REST web service. Can I know how to call these methods from the client side. How do we pass that json as input from client side to those PUT and POST method and how would we consume the json format in the PUT or POST method from server side. If we want to consume xml, then we are using JAXBElement. For consuming json, how to do that ?
This may help get you going: http://blog.sertik.net/labels/jersey.html
From my (extremely rusty) recollection, you sort of treat the #PUT methods the same way you treat #POST methods. So as shown in that blog entry, try using the #FormParam annotations. Also, read over the Jersey API to see if anything looks useful.
The main difference between them (PUT/POST) is in the meaning; PUT typically creates a new resource at the uri, whereas POST can 'append to' it (there are also a few other meanings to what exactly POST does).
PS almost forgot to mention, cURL is so.... nice.
Hey there is a built in support for JSON in JAX-RS.For this you just need to write the POJO class with JAXB annotations. JAX-RS has built in MessageBodyReaders and MessageBodyWriters to support.If you want to POST i.e., sending the Custom Data you need to write your own MessageBodyReaders/Writers and register them with the Client.