Netty 4 Pipeline for JSON over Websocket - json

I want to use Netty as a websocket server. On top I'd like to send JSON between the browser and the server for data interchange.
The websocket part works already fine (I'm using this code: https://github.com/raphaelstary/jsug-netty-example). Now I'd like to integrate a JSON Encoder/Deocoder into the pipeline. I found some code in the Netty Repo I would like to use (still beta, but I wanna try: https://github.com/netty/netty/commit/479b0fe43b6f9a06143cb39f09c51615df90fd1e)
Question: how do I use the Encoder/Decoder in the Pipeline in order to receive and send JSON Objects in my Handler?

Instead of using the JSON codec you mentioned, you could just send and receive a TextWebSocketFrame which contains the JSON string as its content and feed the JSON string into your favorite JSON library such as Jackson

Related

Passing json body with Postman in mapper with REST POST - Snaplogic

How do you access the data sent from REST POST with Postman if you have an open mapper in Snaplogic?
For example, I have inserted some JSON code with key and values like this:
And I want to work with it and transform it in a Mapper snap but I can't access it. Normal expressions using "$" didn't work for me.
I assume that you are using a triggered task.
At the beginning of your pipeline, use a JSON Parser and you'll be able to capture the whole JSON that you are passing in the body of your API call.

How to force a DataSnap REST TStream method to respond as content stream instead of a JSON Array

I've a DataSnap REST method returning files as TStream.
The client side is Objective-C code on iOS, JavaScript code, and Delphi code.
I compiled the server side with Delphi Sydney 10.4.1, upgrading from Delphi XE3.
Testing the new version, I realized the stream response format now is a JSON Array, and no more a content stream of the response.
I can get a content stream with a client-side parameter:
http://host:port/datasnap/rest/[Class]/[Method]/?json=false
But this require to update the client software too, and I want to pospone this update and distribute updates progressively.
Is there a way to force DataSnap REST server to apply the "?json=false" behaviour for a specific method call? Or for any method involving TStream response?
The TWebModule1.DSHTTPWebDispatcher1FormatResult let me manage the result val but I need not to change the json response, but to have a content stream instead.

How to disable response parsing in Karate?

I'm using Karate 0.9.5. and am testing an endpoint that returns a 125MB json response (I know, shouldn't do that over json -- but am stuck for now). How can I disable Karate from parsing the response json and just treat it as plain text? The response takes milliseconds to come over the wire, but Karate just hangs trying to parse the response. I don't need to validate the response, just check for 200 OK.
Thanks.
You can't. I suggest you write a Java util (should be just 5-10 lines of code) to do a GET or whatever to this end-point and call it from Karate and save to something like target/temp.json or discard the response.
Refer to Java interop: https://github.com/intuit/karate#calling-java
If you use karate-apache then the Apache HTTP Client will be in the classpath. So you can refer to the docs: https://hc.apache.org/httpcomponents-client-4.5.x/tutorial/html/fundamentals.html#d5e49
Also look at the end of this test for an alternative example of making a GET / POST in Java: ProxyServerTest.java

How to convert a servlet request to a JSON request

I had an application that is running with servelets. I want to test that application using REST services or POSTMAN.
So, I want to know, whether it could be possible to convert a servelet application's request and response into JSON for testing it with Postman or REST services.
If this possible, how do I do this conversion?
Some context would be helpful. What does the request to your application look like?
You don't need to convert an application's request / response into JSON to use postman. Postman is pretty flexible, you can send a variety of request content types to your application.
As far as whether or not this is possible, absolutely. If you want to convert your request & response objects to JSON, consider using something like Jackson. You can use the ObjectMapper of this tool to go from JSON to POJO & vice versa

Using Rest assured to validate saved JSON response

I have a question regarding REST Assured. - https://code.google.com/p/rest-assured/wiki/Usage
I understand that I can use REST assured to make HTTP calls(.get .put etc.) and validate the response using when() etc. I would like to validate JSON responses that I have already saved in the database, instead of Calling the web service realtime and validating it's response.
Can I use REST-assured to Load a JSON response as a String and validate it?
Yes you can use Rest Assured's JsonPath project independently of Rest Assured (see getting started page). Once you have it in classpath you can do something like this:
JsonPath jsonPath = new JsonPath(<your json as string>);
String title = jsonPath.getString("x.y.title");