I have searched to send the data as a batch to rest end points. But didn't got a correct solution. Could you please help me on this.
PFB the sample body of the data.
--batch
Content-Type: multipart/mixed; boundary=changeset
--changeset
Content-Type: application/http
Content-Transfer-Encoding: binary
POST CorporateAccountCollection HTTP/1.1
Content-Type: application/json
Content-ID: 2
Content-Length: 10000
{
"Name":"Testing Batch Operation MB",
"RoleCode":"XXXXX",
"CountryCode":"US",
"CorporateAccountIdentification" : [
{
"IDTypeCode":"XXXXXX",
"IDNumber":"9999999999"
}
]
}
--changeset--
--batch--
Related
I'm currently working building an endpoint that will make a couple of requests to an external API. In this endpoint I'm logging all of the request bodies to the terminal. But I'm having an issue where jerseys LoggingFeature doesn't log the complete response body for a request that is done. The log gets cut in the middle of the body. I've tried messing around with the logger level, verbosity but that did nothing. I tried changing maxEntitySize to be a large value but that doesn't change anything either, I'm not really sure what the issue is and why it won't log the complete response body. I've also tried logging to a file instead of the terminal but unfortunately I got the same result.
Here's what the log looks like (as it's proprietary software I had to change some information)
INFO [2022-10-06 13:54:04,261] se.bla.bla.bla.clients.BlaClientImpl: 1 * Sending client request on thread dw-18 - GET /api/bla/log/98014384
1 > GET https://url.com/2574339575
1 > Accept: application/json
1 > Authorization: Bearer tokenstuff
INFO [2022-10-06 13:54:04,475] se.bla.bla.bla.clients.BlaClientImpl: 1 * Client response received on thread dw-18 - GET /api/bla/log/98014384
1 < 200
1 < Cache-Control: no-cache
1 < Content-Type: application/json; charset=utf-8
1 < Date: Thu, 06 Oct 2022 13:54:04 GMT
1 < Etag: Yee
1 < Server-Response-Time: 169.44395400000002
1 < Transfer-Encoding: chunked
1 < Vary: Origin
1 < X-Request-Id: Woo
1 < X-Runtime: 0.169337
{example1: "2134123123",example2: "2134123123",example3: "2134123123",example4: "2134123123",example5: "2134123123",example6: "2134123123",example7: "2134123123",example8: "2134123123",example9: "2134123123",example10: "2134123123",example11: "2134123123",example12: "2134123123",example13: "2134123123",example14: "2134123123",example15: "2134123123",example16: "2134123123",example17: "2134123123",example18: "21341
And I've registered the logger like so.
val restlog = getLogger(BlaClientImpl::class.java.name)
restlog.addHandler(FileHandler("rest.log", 83886080, 1))
val requestBuilder =
client
.register(
LoggingFeature(
restlog,
Level.INFO,
LoggingFeature.Verbosity.PAYLOAD_ANY,
83886080
)
)
I'm quite new to the Kotlin/Java world so maybe I'm missing something fundamental.
The issue was a settings with Dropwizard/Jersey. Apparently I had to set gzipEnabled = true
I'm using Apache HttpClient to work with a web service that returns a multipart/form-data response which contains json.
I'm having a very hard time extracting each JSON string separately so I can read the json string.
I did read similar posts on Stackoverflow, and some suggested using Apache commons fileupload, but I am not sure how that can separate the JSON strings from the whole response that has a bunch of other text such as the boundary string, content type, etc
The response looks something like below.
--Boundary_16003419_2104021487_1483424496169
Content-Type: application/json
Content-RequestId: GetMailboxes
Status-Code: 200
X-Server-Response-Time: 4ms
X-Server-Chain: domain.com
Content-RequestDuration: 5
{JSON}
--Boundary_16003419_2104021487_1483424496169
Content-Type: application/json
Content-RequestId: GetFolders
Status-Code: 200
X-Server-Response-Time: 8ms
X-Server-Chain: domain.com
Content-RequestDuration: 10
{JSON}
--Boundary_16003419_2104021487_1483424496169
Content-Type: application/json
Content-RequestId: GetAlerts
Status-Code: 200
X-Server-Response-Time: 10ms
X-Server-Chain: domain.com
Content-RequestDuration: 12
{JSON}
--Boundary_16003419_2104021487_1483424496169
Content-Type: application/json
Content-RequestId: GetAccounts
Status-Code: 200
X-Server-Response-Time: 11ms
X-Server-Chain: domain.com
Content-RequestDuration: 12
{JSON}
--Boundary_16003419_2104021487_1483424496169
Content-Type: application/json
Content-RequestId: GetAllSavedSearches
Status-Code: 200
X-Server-Response-Time: 10ms
X-Server-Chain: domain.com
Content-RequestDuration: 12
{JSON}
--Boundary_16003419_2104021487_1483424496169
Content-Type: application/json
Content-RequestId: GetAthenaSegment
Status-Code: 200
X-Server-Response-Time: 14ms
Content-RequestDuration: 21
{JSON}
--Boundary_16003419_2104021487_1483424496169
Content-Type: application/json
Content-RequestId: ListFolderThreads
Status-Code: 200
X-Server-Response-Time: 110ms
Content-RequestDuration: 116
{JSON}
--Boundary_16003419_2104021487_1483424496169
Content-Type: application/json
Content-RequestId: GetUserInfo
Status-Code: 200
X-Server-Response-Time: 197ms
Content-RequestDuration: 204
{JSON}
--Boundary_16003419_2104021487_1483424496169
Content-RequestId: Status
Content-Type: application/json
{JSON}
--Boundary_16003419_2104021487_1483424496169--
Any way to do this reliably?
One option would be Apache Mime4j. You would likely want to use MimeTokenStream or MimeStreamParser as described here if you want your application to handle response content without building a complete DOM tree in memory.
I'm trying to send usage data to Microsoft Recommendation API. Here is my request:
POST /recommendations/v4.0/models/ccfb261a-ae96-4ae8-be43-15571fc47a66/usage?usageDisplayName=instasell
Ocp-Apim-Subscription-Key: xxxxxxxx
Content-Length: 409
Content-Type: text/plain; charset=ISO-8859-1
Host: westus.api.cognitive.microsoft.com
Connection: Keep-Alive
User-Agent: InstaSell.ru
Accept-Encoding: gzip,deflate
"19vu1oowsiupsrnnln7eu82ln,8,2016/06/15T01:16:30,AddShopCart[\n]"
"19vu1oowsiupsrnnln7eu82ln,8,2016/06/15T01:16:30,AddShopCart[\n]"
"77,8,2016/06/15T01:16:30,AddShopCart[\n]"
"77,9,2016/06/15T01:16:30,AddShopCart[\n]"
"77,134,2016/06/15T01:16:30,Click[\n]"
"77,134,2016/06/15T01:16:30,AddShopCart[\n]"
"77,134,2016/06/15T01:16:30,AddShopCart[\n]"
"77,8,2016/06/15T01:16:30,AddShopCart[\n]"
"77,8,2016/06/15T01:16:30,AddShopCart[\n]"
"77,8,2016/06/15T01:16:30,Click"
But receive the following response:
{
"fileId":"c224766e-1e2a-405e-9367-37a0d36973d0",
"processedLineCount":10,
"errorLineCount":1,
"importedLineCount":9,
"errorSummary":[
]
}
I don't see any differences in 10 lines. However microsoft api comlaints. Could you please help?
Ah! I finally understood the issue. It looks like I was trying to import usage about items unknown to API.
When I imported catalog, I filtered some of the invalid products/items. But usage data included them.
It's normal to reject invalid usage data during production. I was testing integration, so it should be perfectly clear why some usage points were rejected
I am downloading a file with okhttp and things work fine - now I want to show the progress and hit a road-bump. The returned content-length is -1.
It comes back correctly from the server:
⋊> ~ curl -i http://ipfs.io/ipfs/QmRMHb4Vhv8LtYqw8RkDgkdZYxJHfrfFeQaHbNUqJYmdF2 13:38:11
HTTP/1.1 200 OK
Date: Tue, 14 Jun 2016 11:38:16 GMT
Content-Type: application/octet-stream
Content-Length: 27865948
I traced the problem down to OkHeaders.java here:
public static long contentLength(Headers headers) {
return stringToLong(headers.get("Content-Length"));
}
I see all the other headers here in headers - but not Content-Length - so headers.get("Content-Length") returns null. Anyone has a clue how this can get lost?
Interestingly if I change the url to "http://google.com" I get a content-length from okhttp - but with curl both look same Content-Length wise - this really confuses me
Update: it seems to correlate with he size of the file. If I use smaller content from the same server I get a Content-Length with okhttp. The problem only happens when the file is big
It looks like above a certain size the server uses chunked encoding and you won't get a content length.
HTTP/1.1 200 OK
Date: Tue, 14 Jun 2016 14:30:07 GMT
Content-Type: application/octet-stream
Transfer-Encoding: chunked
I'm trying to upload a presentation, using the google api drive, but the presentation goes incomplete some slides are blank, watching the logs this is what shows
com.google.api.client.http.HttpRequest execute: -------------- REQUEST --------------
PUT https://www.googleapis.com/upload/drive/v2/files? uploadType=resumable&upload_id=AEnB2UrDPJgLIehcqH--aWgwl- R_atDhqdvbXnJiWMXKE0V0euJGOvULbM4y5YmvUePWaHSrYyFdOgsmTASJGe-Dtvg09NCkzQ
Accept-Encoding: gzip
Authorization: Bearer ya29.AHES6ZTfSaK77NGCcZO1bK_aTbT8zVX3eslOAb8BkrvpeXARK94XsXY
Content-Range: bytes 0-1048575/6774302
User-Agent: Google-HTTP-Java-Client/1.11.0-beta (gzip)
Content-Type: application/vnd.openxmlformats-officedocument.presentationml.presentation
Content-Length: 1048576
com.google.api.client.http.HttpRequest execute: curl -v --compressed -X PUT -H 'Accept- Encoding: gzip' -H 'Authorization: Bearer ya29.AHES6ZTfSaK77NGCcZO1bK_aTbT8zVX3eslOAb8BkrvpeXARK94XsXY' -H 'Content-Range: bytes 0- 1048575/6774302' -H 'User-Agent: Google-HTTP-Java-Client/1.11.0-beta (gzip)' -H 'Content-Type: application/vnd.openxmlformats-officedocument.presentationml.presentation' -d '#-' -- https://www.googleapis.com/upload/drive/v2/files? uploadType=resumable&upload_id=AEnB2UrDPJgLIehcqH--aWgwl- R_atDhqdvbXnJiWMXKE0V0euJGOvULbM4y5YmvUePWaHSrYyFdOgsmTASJGe-Dtvg09NCkzQ << $$$
com.google.api.client.http.HttpResponse <init>: -------------- RESPONSE --------------
308 OK
server: HTTP Upload Server Built on Oct 3 2012 16:52:30 (1349308350)
range: bytes=0-1048575
x-range-md5: 19230c1c1a0fc493f3431f46cf30c14c
date: Mon, 05 Nov 2012 22:00:33 GMT
pragma: no-cache
expires: Fri, 01 Jan 1990 00:00:00 GMT
cache-control: no-cache, no-store, must-revalidate
content-length: 0
content-type: text/html; charset=UTF-8
x-google-cache-control: remote-fetch
via: HTTP/1.1 GWA
and this is the code that am using:
byte[] myFile = readImageData(blobKey,size);
ByteArrayContent mediaContent = new ByteArrayContent(mimeType, myFile);
Drive.Files.Insert insert = service.files().insert(body, mediaContent);
insert.getMediaHttpUploader().setChunkSize(1024 * 1024);
File file = insert.execute();
UPDATE
doing some testing, it seems the error only occurs when upload presentations with extension .pptx
is there any problem with the mimeType of that extension?
I hope someone can help me, thx in advance.
It seems like the resumable upload protocol is not being implemented correctly. The 308 response code indicates that only a chunk of the request has been uploaded and you should proceed with the next chunk.
Does it work correctly if you remove the following line from your code?
insert.getMediaHttpUploader().setChunkSize(1024 * 1024);