You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ignite.apache.org by "ericcox@outlook.com" <er...@outlook.com> on 2019/01/21 14:04:45 UTC

Ignite 2.7 REST API returning escape characters

To all,

I'm using Ignite 2.7 with the REST API enabled. When retrieving using the
GET method the API returns \ escape characters.

Am I doing something wrong with the ADD or am I doing something wrong with
the GET? 

The examples on the Apache Ignite pages don't show any escape characters or
mention their presence. Is this how Ignite works? How do I get the REST API
to return responses without escape characters?

Thanks,
E



--
Sent from: http://apache-ignite-users.70518.x6.nabble.com/

Re: Ignite 2.7 REST API returning escape characters

Posted by Glenn Wiebe <gl...@gridgain.com>.
Eric,

I might be misunderstand you, but the example you provided is:

A full REST/HTTP response which has request and response payloads, and the
response itself should have three constituent parts:
  - Start Line,
  - Headers, and
  - Body

Now, I cannot see your actual output and it is client log/trace dependent,
but from the example I copied and pasted:






*Date →Mon, 21 Jan 2019 16:41:09 GMTContent-Type
→application/json;charset=utf-8Content-Length →143Server
→Jetty(9.4.11.v20180605)http://abcdef00009d15:8080/ignite?cmd=get&key=107&cacheName=default&destId=8b13ac15-f503-4f4a-ab1f-a7fc3ce93596
<http://abcdef00009d15:8080/ignite?cmd=get&key=107&cacheName=default&destId=8b13ac15-f503-4f4a-ab1f-a7fc3ce93596>{"successStatus":0,"affinityNodeId":"8b13ac15-f503-4f4a-ab1f-a7fc3ce93596","sessionToken":null,"error":null,"response":"{\"name\":\"Ceasar\"}"}*

It sure looks like the body is:

*{"successStatus":0,"affinityNodeId":"8b13ac15-f503-4f4a-ab1f-a7fc3ce93596","sessionToken":null,"error":null,"response":"{\"name\":\"Ceasar\"}"}*

And that HTTP body when using the supplied Content-Type encoding header (
application/json;charset=utf-8) (including the back slash characters) is a
legitimate JSON. So an application that is parsing the REST HTTP response
body will correctly parse it as such (a visual representation of a JSON
DOM):

{
  "successStatus": 0,
  "affinityNodeId": "8b13ac15-f503-4f4a-ab1f-a7fc3ce93596",
  "sessionToken": null,
  "error": null,
  "response": "{\"name\":\"Ceasar\"}"
}

Where the "response" element is a correct string (protected by some
internal noise that might interfere from the value being properly seen as a
string.

I copied the body from your example (i.e. the text shown above in monotype
font) into https://jsonlint.com/ to validate this body is JSON (I also used
Eclipse and Atom also to validate it and give me the pretty-print view of
the DOM).

I agree with you, it would be nice if in addition to the entire REST
Response Body being JSON, that the internal response element inside the
body could also be fine-grained JSON, but alas not to my knowledge.

Cheers,
  Glenn




On Mon, Jan 21, 2019 at 3:01 PM EMCox <er...@outlook.com> wrote:

> Glenn,
>
> I don't want to or need to interogate the JSON being stored. I just need it
> to be returned as valid JSON.
>
> If you try to parse a simple response as i show with the escape characters
> it will fail JSON validation and does.
>
> I just need the dynamic JSON to be valid in the response, stored in
> whatever
> form. I just need the cache to leave it alone and I'll ensure it is valid
> going in to the cache. The committing of the data object to the cache
> should
> not change what is saved in any way. Here ignite is actually changing what
> I
> commit to the cache. I want ignite, the cache, to leave it alone and return
> only what I put in.
>
> Perhaps Ignite needs a second set of ADD and GET that returns the JSON
> structure as is and doesn't have all of the other fields and response:""
> object. I just want the JSON body that I submitted to the cache to be
> returned.
>
> It doesn't sound like Ignite supports this basic pattern.
>
> Thanks much for your thoughts.
> Eric
>
>
>
> --
> Sent from: http://apache-ignite-users.70518.x6.nabble.com/
>

Re: Ignite 2.7 REST API returning escape characters

Posted by EMCox <er...@outlook.com>.
Glenn,

I don't want to or need to interogate the JSON being stored. I just need it
to be returned as valid JSON.

If you try to parse a simple response as i show with the escape characters
it will fail JSON validation and does.

I just need the dynamic JSON to be valid in the response, stored in whatever
form. I just need the cache to leave it alone and I'll ensure it is valid
going in to the cache. The committing of the data object to the cache should
not change what is saved in any way. Here ignite is actually changing what I
commit to the cache. I want ignite, the cache, to leave it alone and return
only what I put in.

Perhaps Ignite needs a second set of ADD and GET that returns the JSON
structure as is and doesn't have all of the other fields and response:""
object. I just want the JSON body that I submitted to the cache to be
returned.

It doesn't sound like Ignite supports this basic pattern.

Thanks much for your thoughts.
Eric



--
Sent from: http://apache-ignite-users.70518.x6.nabble.com/

Re: Ignite 2.7 REST API returning escape characters

Posted by Glenn Wiebe <gl...@gridgain.com>.
Eric,

Just to be clear, the full REST response is legitimate and valid JSON, in
fact the escape characters around the quotes in the response element
(COMPARE REST Response to the Response element INSIDE the REST Response)
are there precisely to keep it valid. Unfortunately, what you would like is
the response element that is currently a string to be a response JSON
element. This would make the entire REST response a multi-level,
hierarchical JSON document. Unfortunately, I am new to using Ignite as
well, but I see this could be a challenge. I don't know if what you are
asking is possible. But I see challenges as that would dictate a dynamic
schema where each value within the response element within the REST
response payload would engender a different response schema.

It sounds to me like you will need to parse the string as JSON. There are
many utilities for this. I will try to look at options.

Regards,
  Glenn

On Mon, Jan 21, 2019 at 1:31 PM EMCox <er...@outlook.com> wrote:

> Glenn and Ilya,
>
> Can I take this string response and parse it as a JSON object using the
> Ignite REST API?
>
> Or am I forced into a programming language such as C# or Java to perform
> parse as JSON Object? I'm trying to use the Ignite REST API out of the box
> and have it return valid JSON. The string Ignite returns is not valid JSON
> with the escape characters included. I want to avoid having to do custom
> code to parse the string as a JSON object and return it. This is an extra
> step outside of the Ignite REST API I want to avoid at all cost. I do not
> have a full blown programming language and project to support this
> behavior.
> If I am forced to do this I must write custom C# or Java programs to
> perform
> this function because it is not in Ignite.
>
> Are there any plans to have Ignite be able to return a valid JSON Object
> without the escape characters?
>
> Thanks much,
> Eric
>
>
>
> --
> Sent from: http://apache-ignite-users.70518.x6.nabble.com/
>

Re: Ignite 2.7 REST API returning escape characters

Posted by EMCox <er...@outlook.com>.
Glenn and Ilya,

Can I take this string response and parse it as a JSON object using the
Ignite REST API?

Or am I forced into a programming language such as C# or Java to perform
parse as JSON Object? I'm trying to use the Ignite REST API out of the box
and have it return valid JSON. The string Ignite returns is not valid JSON
with the escape characters included. I want to avoid having to do custom
code to parse the string as a JSON object and return it. This is an extra
step outside of the Ignite REST API I want to avoid at all cost. I do not 
have a full blown programming language and project to support this behavior.
If I am forced to do this I must write custom C# or Java programs to perform
this function because it is not in Ignite.

Are there any plans to have Ignite be able to return a valid JSON Object
without the escape characters?

Thanks much,
Eric 



--
Sent from: http://apache-ignite-users.70518.x6.nabble.com/

Re: Ignite 2.7 REST API returning escape characters

Posted by Glenn Wiebe <gl...@gridgain.com>.
On the topic of the actual return, if you look at the documentation, I
believe the Cache Get returns a single level JSON structure that includes a
simple string "existing value" as below:

Get and put
<https://apacheignite.readme.io/docs/rest-api#section-get-and-put>

Get and put command stores the given key-value pair in cache and
returns an existing
value if one existed.
Which as you can see from your response (which I have "prettified"):
{
  "successStatus": 0,
  "affinityNodeId": "8b13ac15-f503-4f4a-ab1f-a7fc3ce93596",
  "sessionToken": null,
  "error": null,
  "response": "{\"name\":\"Ceasar\"}"
}

Which is "proper" if you understand that the "response" object is a simple
string value. In order to preserve the embedded features of the string
(i.e. a string that looks like JSON), the surrounding json document has to
be escaped such that elements of the string that might change the schema of
the object.

In other words, this looks right to me, even if that is not your desired
result. You will need to take this string response and parse it as a JSON
object.

Regards,
  Glenn

On Mon, Jan 21, 2019 at 12:48 PM Ilya Kasnacheev <il...@gmail.com>
wrote:
>
> Hello again!
>
> You will also have to supply an interceptor to do this transformation.
Ignite doesn't have native support for JSON so this step is necessary.
>
> Regards,
> --
> Ilya Kasnacheev
>
>
> пн, 21 янв. 2019 г. в 20:22, Ilya Kasnacheev <il...@gmail.com>:
>>
>> Hello!
>>
>> I guess this means you store JSON as String in cache. Is this the case?
>>
>> If you want data to be output as JSON you will have to store it
structured (such as with POJOs or Binary Objects).
>>
>> Regards,
>> --
>> Ilya Kasnacheev
>>
>>
>> пн, 21 янв. 2019 г. в 19:47, EMCox <er...@outlook.com>:
>>>
>>> Add request:
>>> Date →Mon, 21 Jan 2019 16:40:09 GMT
>>> Content-Type →application/json;charset=utf-8
>>> Content-Length →124
>>> Server →Jetty(9.4.11.v20180605)
>>> POST
>>> http://abcdef00009d15:8080/ignite?cmd=add&key=107&val={
"name":"Ceasar"}&cacheName=default&destId=8b13ac15-f503-4f4a-ab1f-a7fc3ce93596
>>>
{"successStatus":0,"affinityNodeId":"8b13ac15-f503-4f4a-ab1f-a7fc3ce93596","sessionToken":null,"error":null,"response":true}
>>>
>>> Get response:
>>> Date →Mon, 21 Jan 2019 16:41:09 GMT
>>> Content-Type →application/json;charset=utf-8
>>> Content-Length →143
>>> Server →Jetty(9.4.11.v20180605)
>>>
http://abcdef00009d15:8080/ignite?cmd=get&key=107&cacheName=default&destId=8b13ac15-f503-4f4a-ab1f-a7fc3ce93596
>>>
{"successStatus":0,"affinityNodeId":"8b13ac15-f503-4f4a-ab1f-a7fc3ce93596","sessionToken":null,"error":null,"response":"{\"name\":\"Ceasar\"}"}
>>>
>>> Status 200 is returned for both
>>>
>>>
>>>
>>>
>>> --
>>> Sent from: http://apache-ignite-users.70518.x6.nabble.com/

Re: Ignite 2.7 REST API returning escape characters

Posted by Ilya Kasnacheev <il...@gmail.com>.
Hello!

> What is the best practice way to do this in Ignite?

Creating your own ConnectorMessageInterceptor implementation.

Regards,
-- 
Ilya Kasnacheev


пн, 21 янв. 2019 г. в 21:05, EMCox <er...@outlook.com>:

> Ilya,
>
> Thanks for helping me.
>
> I am trying to store the JSON as a  string using the REST API Add method.
>
> For instance, i want to store {"name":"Jamie"} in the cache and when I do a
> get return the same JSON data structure. Of course, in real life the JSON
> data structure could be much more complex and will vary according to
> implementation.
>
> What is the best practice way to do this in Ignite?
>
> Thanks a ton for your assistance as I am new to Ignite and Cache in
> general.
>
> Thanks,
> Eric
>
>
>
>
>
> --
> Sent from: http://apache-ignite-users.70518.x6.nabble.com/
>

Re: Ignite 2.7 REST API returning escape characters

Posted by EMCox <er...@outlook.com>.
Ilya,

Thanks for helping me. 

I am trying to store the JSON as a  string using the REST API Add method.

For instance, i want to store {"name":"Jamie"} in the cache and when I do a
get return the same JSON data structure. Of course, in real life the JSON
data structure could be much more complex and will vary according to
implementation.

What is the best practice way to do this in Ignite?

Thanks a ton for your assistance as I am new to Ignite and Cache in general.

Thanks,
Eric





--
Sent from: http://apache-ignite-users.70518.x6.nabble.com/

Re: Ignite 2.7 REST API returning escape characters

Posted by Ilya Kasnacheev <il...@gmail.com>.
Hello again!

You will also have to supply an interceptor
<https://ignite.apache.org/releases/latest/javadoc/org/apache/ignite/configuration/ConnectorMessageInterceptor.html>
to do this transformation. Ignite doesn't have native support for JSON so
this step is necessary.

Regards,
-- 
Ilya Kasnacheev


пн, 21 янв. 2019 г. в 20:22, Ilya Kasnacheev <il...@gmail.com>:

> Hello!
>
> I guess this means you store JSON as String in cache. Is this the case?
>
> If you want data to be output as JSON you will have to store it structured
> (such as with POJOs or Binary Objects).
>
> Regards,
> --
> Ilya Kasnacheev
>
>
> пн, 21 янв. 2019 г. в 19:47, EMCox <er...@outlook.com>:
>
>> Add request:
>> Date →Mon, 21 Jan 2019 16:40:09 GMT
>> Content-Type →application/json;charset=utf-8
>> Content-Length →124
>> Server →Jetty(9.4.11.v20180605)
>> POST
>> http://abcdef00009d15:8080/ignite?cmd=add&key=107&val={
>> "name":"Ceasar"}&cacheName=default&destId=8b13ac15-f503-4f4a-ab1f-a7fc3ce93596
>>
>> {"successStatus":0,"affinityNodeId":"8b13ac15-f503-4f4a-ab1f-a7fc3ce93596","sessionToken":null,"error":null,"response":true}
>>
>> Get response:
>> Date →Mon, 21 Jan 2019 16:41:09 GMT
>> Content-Type →application/json;charset=utf-8
>> Content-Length →143
>> Server →Jetty(9.4.11.v20180605)
>>
>> http://abcdef00009d15:8080/ignite?cmd=get&key=107&cacheName=default&destId=8b13ac15-f503-4f4a-ab1f-a7fc3ce93596
>>
>> {"successStatus":0,"affinityNodeId":"8b13ac15-f503-4f4a-ab1f-a7fc3ce93596","sessionToken":null,"error":null,"response":"{\"name\":\"Ceasar\"}"}
>>
>> Status 200 is returned for both
>>
>>
>>
>>
>> --
>> Sent from: http://apache-ignite-users.70518.x6.nabble.com/
>>
>

Re: Ignite 2.7 REST API returning escape characters

Posted by Ilya Kasnacheev <il...@gmail.com>.
Hello!

I guess this means you store JSON as String in cache. Is this the case?

If you want data to be output as JSON you will have to store it structured
(such as with POJOs or Binary Objects).

Regards,
-- 
Ilya Kasnacheev


пн, 21 янв. 2019 г. в 19:47, EMCox <er...@outlook.com>:

> Add request:
> Date →Mon, 21 Jan 2019 16:40:09 GMT
> Content-Type →application/json;charset=utf-8
> Content-Length →124
> Server →Jetty(9.4.11.v20180605)
> POST
> http://abcdef00009d15:8080/ignite?cmd=add&key=107&val={
> "name":"Ceasar"}&cacheName=default&destId=8b13ac15-f503-4f4a-ab1f-a7fc3ce93596
>
> {"successStatus":0,"affinityNodeId":"8b13ac15-f503-4f4a-ab1f-a7fc3ce93596","sessionToken":null,"error":null,"response":true}
>
> Get response:
> Date →Mon, 21 Jan 2019 16:41:09 GMT
> Content-Type →application/json;charset=utf-8
> Content-Length →143
> Server →Jetty(9.4.11.v20180605)
>
> http://abcdef00009d15:8080/ignite?cmd=get&key=107&cacheName=default&destId=8b13ac15-f503-4f4a-ab1f-a7fc3ce93596
>
> {"successStatus":0,"affinityNodeId":"8b13ac15-f503-4f4a-ab1f-a7fc3ce93596","sessionToken":null,"error":null,"response":"{\"name\":\"Ceasar\"}"}
>
> Status 200 is returned for both
>
>
>
>
> --
> Sent from: http://apache-ignite-users.70518.x6.nabble.com/
>

Re: Ignite 2.7 REST API returning escape characters

Posted by EMCox <er...@outlook.com>.
Add request:
Date →Mon, 21 Jan 2019 16:40:09 GMT
Content-Type →application/json;charset=utf-8
Content-Length →124
Server →Jetty(9.4.11.v20180605)
POST
http://abcdef00009d15:8080/ignite?cmd=add&key=107&val={"name":"Ceasar"}&cacheName=default&destId=8b13ac15-f503-4f4a-ab1f-a7fc3ce93596
{"successStatus":0,"affinityNodeId":"8b13ac15-f503-4f4a-ab1f-a7fc3ce93596","sessionToken":null,"error":null,"response":true}

Get response:
Date →Mon, 21 Jan 2019 16:41:09 GMT
Content-Type →application/json;charset=utf-8
Content-Length →143
Server →Jetty(9.4.11.v20180605)
http://abcdef00009d15:8080/ignite?cmd=get&key=107&cacheName=default&destId=8b13ac15-f503-4f4a-ab1f-a7fc3ce93596
{"successStatus":0,"affinityNodeId":"8b13ac15-f503-4f4a-ab1f-a7fc3ce93596","sessionToken":null,"error":null,"response":"{\"name\":\"Ceasar\"}"}

Status 200 is returned for both




--
Sent from: http://apache-ignite-users.70518.x6.nabble.com/

Re: Ignite 2.7 REST API returning escape characters

Posted by Ilya Kasnacheev <il...@gmail.com>.
Hello!

Can you show an example of such output?

Note that Ignite will use JSON, which in turn will escape some characters
in strings.

Regards,
-- 
Ilya Kasnacheev


пн, 21 янв. 2019 г. в 17:04, ericcox@outlook.com <er...@outlook.com>:

> To all,
>
> I'm using Ignite 2.7 with the REST API enabled. When retrieving using the
> GET method the API returns \ escape characters.
>
> Am I doing something wrong with the ADD or am I doing something wrong with
> the GET?
>
> The examples on the Apache Ignite pages don't show any escape characters or
> mention their presence. Is this how Ignite works? How do I get the REST API
> to return responses without escape characters?
>
> Thanks,
> E
>
>
>
> --
> Sent from: http://apache-ignite-users.70518.x6.nabble.com/
>