I have JSON objects coming back from ASP.Net oData services which I am reading through JayData oData provider. On one service, JSON object is read into an array without any problems. On another service (from same server), the resulting array contains only etag data for all the elements.
I am not sure if there is a format mismatch or JayData is not decoding the JSON format correctly.
Could someone take a look and see where the problem is located?
Here is the header
GET /GCSData.svc/Customers HTTP/1.1
Referer: http://localhost:56786/HTMLClient/
MaxDataServiceVersion: 2.0
DataServiceVersion: 2.0
Accept: application/atomsvc+xml;q=0.8, application/json;odata=verbose;q=0.5, */*;q=0.1
Accept-Language: en-US
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko
Connection: Keep-Alive
DNT: 1
Host: localhost:56786
HTTP/1.1 200 OK
Cache-Control: no-cache
Content-Length: 2051
Content-Type: application/json;odata=verbose;charset=utf-8
Server: Microsoft-IIS/8.0
X-Content-Type-Options: nosniff
DataServiceVersion: 1.0;
X-AspNet-Version: 4.0.30319
X-SourceFiles: =?UTF-8?B?QzpcVXNlcnNcQ2hpIFJvd1xkb2N1bWVudHNcdmlzdWFsIHN0dWRpbyAyMDEzXFByb2plY3RzXEdDU2xzXEdDU2xzXGJpblxEZWJ1Z1xHQ1NEYXRhLnN2Y1xDdXN0b21lcnM=?=
X-Powered-By: ASP.NET
Date: Mon, 31 Mar 2014 19:35:09 GMT
and here is the JSON data.
{"d":[{"__metadata":{"id":"http://localhost:56786/GCSData.svc/Customers(1)","uri":"http://localhost:56786/GCSData.svc/Customers(1)","etag":"W/\"'John%20%20%20%20%20%20','Doe%20%20%20%20%20%20%20','1234567890'\"","type":"LightSwitchApplication.Customer"},"Orders":{"__deferred":{"uri":"http://localhost:56786/GCSData.svc/Customers(1)/Orders"}},"CustID":1,"FName":"John ","LName":"Doe ","Phone":"1234567890"},{"__metadata":{"id":"http://localhost:56786/GCSData.svc/Customers(2)","uri":"http://localhost:56786/GCSData.svc/Customers(2)","etag":"W/\"'Jane%20%20%20%20%20%20','Smith%20%20%20%20%20','7703211234'\"","type":"LightSwitchApplication.Customer"},"Orders":{"__deferred":{"uri":"http://localhost:56786/GCSData.svc/Customers(2)/Orders"}},"CustID":2,"FName":"Jane ","LName":"Smith ","Phone":"7703211234"},{"__metadata":{"id":"http://localhost:56786/GCSData.svc/Customers(3)","uri":"http://localhost:56786/GCSData.svc/Customers(3)","etag":"W/\"'Dan%20%20%20%20%20%20%20','Handy%20%20%20%20%20','6789876543'\"","type":"LightSwitchApplication.Customer"},"Orders":{"__deferred":{"uri":"http://localhost:56786/GCSData.svc/Customers(3)/Orders"}},"CustID":3,"FName":"Dan ","LName":"Handy ","Phone":"6789876543"},{"__metadata":{"id":"http://localhost:56786/GCSData.svc/Customers(4)","uri":"http://localhost:56786/GCSData.svc/Customers(4)","etag":"W/\"'Mike%20%20%20%20%20%20','Smith%20%20%20%20%20','4041231234'\"","type":"LightSwitchApplication.Customer"},"Orders":{"__deferred":{"uri":"http://localhost:56786/GCSData.svc/Customers(4)/Orders"}},"CustID":4,"FName":"Mike ","LName":"Smith ","Phone":"4041231234"},{"__metadata":{"id":"http://localhost:56786/GCSData.svc/Customers(5)","uri":"http://localhost:56786/GCSData.svc/Customers(5)","etag":"W/\"'Aaron%20%20%20%20%20','Hayes%20%20%20%20%20','2431235678'\"","type":"LightSwitchApplication.Customer"},"Orders":{"__deferred":{"uri":"http://localhost:56786/GCSData.svc/Customers(5)/Orders"}},"CustID":5,"FName":"Aaron ","LName":"Hayes ","Phone":"2431235678"}]}
In the resulting array, for each Customer, all the fields (FName, LName, phone) contain the exact data (which equals to the "etag" field). Here is an example for Customer(1)
{"CustID":1,"FName":"W/\"'John%20%20%20%20%20%20','Doe%20%20%20%20%20%20%20','1234567890'\"","LName":"W/\"'John%20%20%20%20%20%20','Doe%20%20%20%20%20%20%20','1234567890'\"","Phone":"W/\"'John%20%20%20%20%20%20','Doe%20%20%20%20%20%20%20','1234567890'\""}
The JSON data is read through toLiveArray() method.
Make sure you use the [TimeStamp] attribute on server-side to publish your ETag in byte array format:
[Timestamp]
public byte[] token { get; set; }
Related
We are adding some metadata under a specific location in JCR:
POST /some/jcr/location/_jcr_content/json HTTP/1.1
Accept: application/json
Authorization: Basic YWRtaW46YWRtaW4=
Cache-Control: no-cache
Host: localhost:4502
Accept-Encoding: gzip, deflate, br
Connection: keep-alive
Content-Type: multipart/form-data; boundary=--------------------------554953211468377919703514
Cookie: cq-authoring-mode=TOUCH
Content-Length: 383
----------------------------554953211468377919703514
Content-Disposition: form-data; name="./value"
{ "test": "test" }
----------------------------554953211468377919703514
Content-Disposition: form-data; name=":cq_csrf_token"
ey***our csrf token***-c5Oa0
----------------------------554953211468377919703514--
But when we fetch this same resource, the response type is test/html`:
GET /some/jcr/location/jcr:content/json/value HTTP/1.1
Accept: application/json
Cache-Control: no-cache
Host: localhost:4502
Accept-Encoding: gzip, deflate, br
Connection: keep-alive
Cookie: cq-authoring-mode=TOUCH
HTTP/1.1 200 OK
Date: Fri, 26 Feb 2021 13:49:38 GMT
X-Content-Type-Options: nosniff
Content-Type: text/plain;charset=utf-8
Content-Length: 18
{ "test": "test" }
What configuration do we need to add in JCR, or what do we need to edit in our request to make sure that JCR returns content type application/json.
UPDATE: As Sharath Madappa replied, you can request the data in JSON format by suffixing the location with the .json extension. However, that results in the following format:
{
"value": "{ \"test\": \"test\" }"
}
While I expect it to be:
{
"test": "test"
}
use GET /some/jcr/location/jcr:content/json/value.json while making the request. Sling is able to render/return the resource in multiple formats based on the extension in the request. By default, if no extension is provided it goes with HTML. The path tells which resource, the extension, and selectors tell how and what renders the resource.
You can also specify the depth you want to go for besides having JSON format response.
E.g
Depth of 1(just the node) in JSON format:
curl -u <user>:<pass> -v <URL>/some/jcr/location/jcr:content/json/value.1.json
All child nodes under a certain path in JSON format:
curl -u <user>:<pass> -v <URL>/some/jcr/location.-1.json
Posting JSON content and then retrieving it as Content-Type: application/json can be done by file upload instead of adding properties.
Here is a javascript example:
const data = { test: "test" };
const jsonData = new Blob([JSON.stringify(data)], { type: 'application/json' });
const formData = new FormData();
formData.append(`myFile.json`, jsonData, `myFile.json`);
return fetch(path, {
method: 'POST',
body: formData
});
This example does not take in account Authn/Authz.
To fetch you data as application/json, you just issue a GET call to the location of the JSON file:
http://localhost:4502/path/to/the/folder/jcr:content/files/myFile.json
I was calling a Rest API locally from terminal. This was like below:
http -v -f --timeout=60 GET 'http://localhost:8080/api/v1/public/users/signin?email=myemail#email.com&password=mypassword'
It is returning following output:
GET /api/v1/public/users/signin?email=myemail#email.com&password=mypassword HTTP/1.1
Accept: */*
Accept-Encoding: gzip, deflate
Content-Type: application/x-www-form-urlencoded; charset=utf-8
Host: localhost:8080
User-Agent: HTTPie/0.8.0
HTTP/1.1 400 Bad Request
Content-Type: application/json
Date: Mon, 28 Mar 2016 16:59:08 GMT
Set-Cookie: rememberMe=deleteMe; Path=/; Max-Age=0; Expires=Sun, 27- Mar-2016 16:59:13 GMT
Transfer-Encoding: chunked
{
"debugMessage": "Submitted credentials for token [org.apache.shiro.authc.UsernamePasswordToken - najmul#qianalysis.com, rememberMe=true] did not match the expected credentials.Submitted credentials for token [org.apache.shiro.authc.UsernamePasswordToken - najmul#qianalysis.com, rememberMe=true] did not match the expected credentials.: The subject was expected to be true, but was false",
"errorCode": "INCORRECT_CREDENTIALS",
"logId": "50a695c1a81e0542",
"stackTrace": "org.niopack.r.....
}
Now I want to read this JSON data using Alamofire. I tried with responseJSON serialiser with following way:
Alamofire.request(method, urlString, parameters: parameters, encoding: .URL, headers: cookieHeader)
.validate()
.responseJSON {
alamofireResponse in
let jsonData = alamofireResponse.result.value
}
But this I am getting jsonData as nil. What you will do if you were are here?
Thanks.
For me removing the validate() allowed me to see the reason the request was failing. For some reason when validate fails, the data of the response is not parsed.
Here is my Box upload POST to upload a file into a specific folder:
POST /api/2.0/files/content HTTP/1.1
Authorization: Bearer ACCESS_TOKEN
Accept: application/json
User-Agent: SOASoftware/7-HttpCore/4
Transfer-Encoding: chunked
Content-Type: multipart/form-data
Host: upload.box.com
Connection: Keep-Alive
attributes='{"name":"lead.txt", "parent":{"id":"2890481033"}}'&file=C:\SOA\Software\sm70\instances\nd\leads.txt
-----------------------------9051914041544843365972754266
<file-data>
-----------------------------9051914041544843365972754266
but I get this response, that doesn't help me to understand what the problem is:
HTTP/1.1 500
Age: 0
Date: Fri, 02 Jan 2015 09:06:09 GMT
Connection: close
EMPTY MESSAGE
Can anyone tell me what I'm doing wrong in my request to cause the HTTP 500, please?
It looks like your multipart request isn't properly formatted. The easiest way to do this is to use an SDK or find a library that can build a multipart request for you.
If you really want to build the request manually, then here's an example of what an upload request should look like:
POST https://upload.box.com/api/2.0/files/content HTTP/1.1
Host: upload.box.com
Authorization: Bearer ACCESS_TOKEN
Content-Length: 346
Content-Type: multipart/form-data; boundary=------------------------393329c2f2238ab4
--------------------------393329c2f2238ab4
Content-Disposition: form-data; name="attributes"
{"name":"my-file.txt", "parent":{"id":"0"}}
--------------------------393329c2f2238ab4
Content-Disposition: form-data; name="file"; filename="my-file.txt"
Content-Type: application/octet-stream
<file-data>
--------------------------393329c2f2238ab4--
I am trying to run a login REST service in SoapUIPro with jason.
But I am getting the following syntactical error.
It's working fine when I switch to xml
Request
POST http://122.122.232.112/services/public/login HTTP/1.1
Accept-Encoding: gzip,deflate
Content-Type: application/json
Accept: application/json
Content-Length: 115
Host: 122.122.232.112
Connection: Keep-Alive
User-Agent: Apache-HttpClient/4.1.1 (java 1.5)
{
"com.abc.dmb.cons.model.LoginInfo": {
"userId": "cons31312061521360",
"password": "Arif#1212"
}
}
Response
HTTP/1.1 400 Bad Request
Date: Fri, 06 Dec 2013 05:02:59 GMT
Vary: Accept-Charset, Accept-Encoding, Accept-Language, Accept
Accept-Ranges: bytes
Server: abcd.setup.com.au
Content-Type: application/json;charset=ISO-8859-1
Transfer-Encoding: chunked
Connection: close
{"errorCode":"400","errorDescription":"The request sent by the client was syntactically incorrect."}
Please clarify
Cheers
I'm having an issue where the Places Search API returns ZERO_RESULTS on the m.site whatever the parameter. API Response attached. The search function had been working correctly until January when we began experiencing problems despite no change to the coding. I would appreciate any help. Thanks, Kyle.
GET https://maps.googleapis.com/maps/api/js/PlaceService.FindPlaces?1m6&1m2&1d53.46731217725638&2d-2.2817558287549673&2m2&1d53.46731217725638&2d-2.2817558287549673&2sen-GB&3sphones%204u&6sstore&8e1&callback=_xdc_._7otmgw&token=86621 HTTP/1.1
Host: maps.googleapis.com
Referer: http://m.phones4u.co.uk/stores/my-phones4u-stores/53.46731217725638/-2.2817558287550095/?mweb=640-0-3
Proxy-Connection: keep-alive
Accept-Encoding: gzip, deflate
Accept: */*
Accept-Language: en-gb
Connection: keep-alive
User-Agent: Mozilla/5.0 (iPhone; CPU iPhone OS 6_0_1 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A525 Safari/8536.25
HTTP/1.1 200 OK
Content-Type: text/javascript; charset=UTF-8
Access-Control-Allow-Origin: *
Date: Fri, 25 Jan 2013 11:25:45 GMT
Server: mafe
Cache-Control: private
Content-Length: 115
X-XSS-Protection: 1; mode=block
X-Frame-Options: SAMEORIGIN
_xdc_._7otmgw && _xdc_._7otmgw( {
"html_attributions" : [],
"results" : [],
"status" : "ZERO_RESULTS"
}
)