HTTP 500 when trying to upload a file - box-api

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--

Related

AEM JCR - Get response as JSON

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

In jmeter unable to upload the profile pic in web application which is using "Multipart Streamprovider" and kerberos authentication

I am trying to upload the pic in my web application using the JMeter tool.But I am getting the 501 : not Implemented error.
After done some surfing I came to know that it is using the Kerberos authentication, So configured that too in the System.properties file of JMeter. But still, I am getting the same error : 501 .Please, anyone, help me to resolve this .
Sample Result :
Thread Name: Thread Group_Tester Profile_updated 1-1
Sample Start: 2016-08-28 14:51:26 IST
Load time: 48503
Connect Time: 570
Latency: 48503
Size in bytes: 362
Headers size in bytes: 303
Body size in bytes: 59
Sample Count: 1
Error Count: 1
Data type ("text"|"bin"|""): text
Response code: 501
Response message: Not Implemented
Response headers:
HTTP/1.1 501 Not Implemented
Cache-Control: no-cache
Pragma: no-cache
Content-Length: 59
Content-Type: application/json; charset=utf-8
Expires: -1
Server: Microsoft-IIS/8.0
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
Access-Control-Allow-Origin: *
Date: Sun, 28 Aug 2016 09:22:10 GMT
HTTPSampleResult fields:
ContentType: application/json; charset=utf-8
DataEncoding: utf-8
Request :
POST http://revflexgatewaysit.azurewebsites.net/api/TesterProfile/UploadTesterProfile?Id=69437&UpdateAdminId=0
POST data:
--np-Zxf5w6hXofm0a8SNXC5632tmk_IV45
Content-Disposition: form-data; name="hprofileUploadPhoto"
TestPhoto.jpg
--np-Zxf5w6hXofm0a8SNXC5632tmk_IV45
Content-Disposition: form-data; name="firstName"
hammee ham
--np-Zxf5w6hXofm0a8SNXC5632tmk_IV45
Content-Disposition: form-data; name="lastName"
hamm1
--np-Zxf5w6hXofm0a8SNXC5632tmk_IV45
Content-Disposition: form-data; name="emailId"
hammee#yopmail.com
--np-Zxf5w6hXofm0a8SNXC5632tmk_IV45
Content-Disposition: form-data; name="phoneNumber"
98789990
--np-Zxf5w6hXofm0a8SNXC5632tmk_IV45
Content-Disposition: form-data; name="gender"
Male
--np-Zxf5w6hXofm0a8SNXC5632tmk_IV45
Content-Disposition: form-data; name="occupationStatusName"
string:2
--np-Zxf5w6hXofm0a8SNXC5632tmk_IV45
Content-Disposition: form-data; name="workHoursName"
string:3
--np-Zxf5w6hXofm0a8SNXC5632tmk_IV45
Content-Disposition: form-data; name="city"
Cheannai
--np-Zxf5w6hXofm0a8SNXC5632tmk_IV45
Content-Disposition: form-data; name="state"
Tamilnadu
--np-Zxf5w6hXofm0a8SNXC5632tmk_IV45
Content-Disposition: form-data; name="countryName"
76
--np-Zxf5w6hXofm0a8SNXC5632tmk_IV45
Content-Disposition: form-data; name="postalCodeName"
600005
--np-Zxf5w6hXofm0a8SNXC5632tmk_IV45
Content-Disposition: form-data; name="skypeId"
--np-Zxf5w6hXofm0a8SNXC5632tmk_IV45
Content-Disposition: form-data; name="aboutMe"
hiiiii
--np-Zxf5w6hXofm0a8SNXC5632tmk_IV45
Content-Disposition: form-data; name="facebookId"
https://abc#facebook.com
--np-Zxf5w6hXofm0a8SNXC5632tmk_IV45
Content-Disposition: form-data; name="twitterId"
https://abcd#twitter.com
--np-Zxf5w6hXofm0a8SNXC5632tmk_IV45
Content-Disposition: form-data; name="linkedinId"
https://kfljlj#linkedin.com
--np-Zxf5w6hXofm0a8SNXC5632tmk_IV45
Content-Disposition: form-data; name="googlePlusId"
https://flk#plus.google.com
--np-Zxf5w6hXofm0a8SNXC5632tmk_IV45
Content-Disposition: form-data; name="accessToken"
WooZaoSuVwF5xaNisPbw0xYoofkpTRMRXcc0AYYumP8xi-]a6LPuRpPuDU4sbGibcMRF1dcNREKQqCp u9a9XllrYntgXOqQFLAvl8w8d85T_2j6jIjp5eZh4XCNxrSOIRs--ttNsqLYuBdGLKIquK8oCy0iyjEPhaUvl79mtLd8Fz91lPnT m8-PIU3E7_00hRpYDN1rx1X8SvlghdA5ZAAiSWZX-YS9iHZ6LYgb09QKPNhaU0gxSYK9L8lH7ksMJOEfNmlPp5kFkj_fQ-EDxyKI NeTRTfjKwCkmcNdfY6mnF36itrD_pxL65y-e5_8sAUlFQ_3UgzfWE9ytibxyvnfMvydZ3aQm4xvUcnhCb_QLgwnW0UYpq8aZw89I JScGZySEd3bT38V5p1ktNoqud9CoTOAfDUlFXxJcFTfipX9_LJelO1masOp4gJcdfcY3N_mcAmR4ixwswCNXRcgTLSZDHBSSTYSF1XMgIGEVpehDSBdDY
--np-Zxf5w6hXofm0a8SNXC5632tmk_IV45
Content-Disposition: form-data; name="profileUploadPhoto"filename="Jellyfish.jpg"
Content-Type: image/jpeg
<actual file content, not shown here>
--np-Zxf5w6hXofm0a8SNXC5632tmk_IV45--
Cookie Data:
ARRAffinity=dab3b2a48d5eeba2e398c4272dad09fe1b0f7e17abfbf187e75f241b8f6737e4
Request Headers:
Connection: keep-alive
Referer: http://revflexsit.azurewebsites.net/
Accept-Language: en-US,en;q=0.5
Origin: http://revflexsit.azurewebsites.net
Organziation: 1
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:48.0) Gecko/20100101 Firefox/48.0
Accept: application/json, text/plain, */*
Authorization: Bearer x_7zFLPhUrHQwIssBFVvFOlIMlNDpDNBCjohwJG5qjJWQ3zWIAC7cPpnv5f1vH6ZEfIxRS28ui2cD6u5aW8CMZCm1BhhbcaRGxXwmZEBtGIwIANWu7r6RdaIIeIrq6AYNixDo6L4O7tfALHcTLpbiElgbHrKJ3YKbWqNdEXC7fNmI74Aq- _0D2y1id5plxoTJclOQ5UKFHssMUCh0MWpcRE_lKFM1JqNzlp37wVQUoQjCzXo- HW_MxNUqF9zgbnf_XPXRKEB1wZpYwbK30hno- GWD85P3NPknhzCGgkW3rTPsBalULHeSbrGGYIKACNhi8CKtC_8YbwM8RL1UC-fW_tm- e_jqICocs6zwySNzcg7X9BsFe2RrDFielbs41iDSNanAxfFlqdgVhZLOiyR8NxvCLZxrwq2WEvEtdk83scF8LnOTKiCXUFpmkGjGcMOfvOw_s8DtXLugfJBLEyh7Dvc6gyGjGHBmp6eWThs_bb20bmU
Content-Length: 778351
Content-Type: multipart/form-data; boundary=np- Zxf5w6hXofm0a8SNXC5632tmk_IV45; charset=US-ASCII
Host: revflexgatewaysit.azurewebsites.net
Response data :
"Error in application. Please contact Revolution IT admin."
But Manually the pic uploading is working fine.
As per HTTP response status codes sheet
501 Not Implemented
The request method is not supported by the server and cannot be handled. The only methods that servers are required to support (and therefore that must not return this code) are GET and HEAD.
So it might be the case your server expects HTTP PUT method.
So I would suggest using one of the following methods:
Record your request using HTTP(S) Test Script Recorder, it is fine for building a request "skeleton", you can apply parametrization and correlation later on
Compare the requests which are being sent with a browser and with JMeter using a sniffer tool. The best one is Wireshark. Amend JMeter configuration so it would be a complete match (apart from dynamic parameters if any)
If you still need to build your request manually, check out Testing REST API File Uploads in JMeter guide for step-by-step instructions and examples
P.S. looking into Authorization header, it seems your server uses OAuth, not Kerberos

How to read json data of a bad request (status code 400) using Alamofire

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.

Error creating DocuSign Envelope via DocuSign Rest API (with multiple documents and multiple recipients)

I am trying to create an Envelope in DocuSign with multiple documents using the DocuSign REST API, I'm using a multipart/form-data request, I use JSON to define the attributes of the envelope, I check my JSON and I think it is OK. Below that I define a multipart/mixed section where I set the header and PDF bytes of the documents. I receive a Bad Request error code that said "NO_DOCUMENT_RECEIVED" and have as message "The document element did not contain the encoded document, or there is a problem with the encoding. ". I post the request result from fiddler below:
// Request
POST https://demo.docusign.net/restapi/v2/accounts/295724/envelopes HTTP/1.1
X-DocuSign-Authentication: {"Username":"email","Password":"password","IntegratorKey":"key"}
Content-Type: multipart/form-data; boundary=9a56da749dc04804819460f6499ab80b
Accept: application/json
Host: demo.docusign.net
Content-Length: 31476
Expect: 100-continue
--9a56da749dc04804819460f6499ab80b
Content-Type: application/json
Content-Disposition: form-data
{"emailBlurb":"EMAIL BODY HERE OK OK","emailSubject":"EMAIL SUBJECT HERE IS MANDATORY","status":"sent","documents":[{"documentId":1,"name":"ABC.pdf"},{"documentId":2,"name":"AB.pdf"}],"recipients":{"signers":[{"email":"dn#brenock.com","name":"Dubhe","recipientId":"1","routingOrder":"1"},{"email":"dubhe.dnacimiento#gmail.com","name":"DubheF","recipientId":"2","routingOrder":"1"}]}}
--9a56da749dc04804819460f6499ab80b
Content-Disposition: form-data
Content-Type: multipart/mixed; boundary=e8bc9555e9634110bba63547b2552460
--e8bc9555e9634110bba63547b2552460
Content-Type: application/pdf
Content-Disposition: file; filename=ABC.pdf; documentId=1
<PDF Bytes Document 1>
--e8bc9555e9634110bba63547b2552460
Content-Type: application/pdf
Content-Disposition: file; filename=AB.pdf; documentId=2
<PDF BytesDocument Two>
--e8bc9555e9634110bba63547b2552460--
--9a56da749dc04804819460f6499ab80b--
You shouldn't need these lines that define a second boundary (or any of the subsequent references to that second boundary):
Content-Disposition: form-data
Content-Type: multipart/mixed; boundary=e8bc9555e9634110bba63547b2552460
Try removing that (and all subsequent references to boundary e8bc9555e9634110bba63547b2552460), so that your request looks like this:
POST https://demo.docusign.net/restapi/v2/accounts/295724/envelopes HTTP/1.1
X-DocuSign-Authentication: {"Username":"email","Password":"password","IntegratorKey":"key"}
Content-Type: multipart/form-data; boundary=9a56da749dc04804819460f6499ab80b
Accept: application/json
Host: demo.docusign.net
Content-Length: 31476
Expect: 100-continue
--9a56da749dc04804819460f6499ab80b
Content-Type: application/json
Content-Disposition: form-data
JSON_REQUEST_BODY_HERE
--9a56da749dc04804819460f6499ab80b
Content-Type:application/pdf
Content-Disposition: file; filename="ABC.pdf"; documentid=1
DOCUMENT_1_BYTES_HERE
--9a56da749dc04804819460f6499ab80b
Content-Type:application/pdf
Content-Disposition: file; filename="AB.pdf"; documentid=2
DOCUMENT_2_BYTES_HERE
--9a56da749dc04804819460f6499ab80b--

SoapUI - Syntactical error in REST JSON

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