mirror of
https://github.com/fsouza/fake-gcs-server.git
synced 2026-04-25 13:45:52 +03:00
[GH-ISSUE #142] invalid character '\x1f' looking for beginning of value when uploading via java apis #2176
Labels
No labels
bug
compatibility-issue
docker
documentation
enhancement
help wanted
needs information
pull-request
question
stale
unfortunate
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/fake-gcs-server#2176
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @DanieleSassoli on GitHub (Nov 28, 2019).
Original GitHub issue: https://github.com/fsouza/fake-gcs-server/issues/142
Hi, I'm trying to create a bucket in the fake gcs server using the java apis(which don't seem to be documented, happy to contribute with some docs once I get this working) but getting
This is the code:
Can't really figure out what I'm doing wrong, does anybody have any idea?
@DanieleSassoli commented on GitHub (Nov 28, 2019):
Just an update on this, as a workaround I decided to try to create a bucket with a file when starting up the container, as documented in the read me, after which I tried doing
storage.list(bucketName)which worked, this makes me think that the StorageOptions are correct and something isn't quire right with the server when creating the bucket?I'm now not able to create files in it due to #84 but that's a different issue.
@fsouza commented on GitHub (Dec 9, 2019):
Hey @DanieleSassoli, sorry for the delayed response. Yeah currently we don't support the GRPC API. I haven't looked into how much work that would be, do you have an idea? If not, I can take a look over the holidays.
@fsouza commented on GitHub (Dec 9, 2019):
Opened #146 to track support for the grpc api
@dnatic09 commented on GitHub (Dec 9, 2020):
Hey Team. I have been investigating this issue. I am leaning towards a gzip compression issue. I am digging through the Java code and it clearly looks like HTTP. Furthermore, the \x1f is likely a character you would see in a gzipped POST payload over HTTP. See screenshot attached.
@dnatic09 commented on GitHub (Dec 9, 2020):
@fsouza , a follow-up. I simply hacked the debugger and set
this.disableGzipContenttotrue. The request WORKED! So, the Fake GCS server is failing to decode gzipped content. Either we need to find a way to disable gzip encoding in the SDK or the GCS server needs to parse theContent-EncodingHTTP header and decompress the data. Can we do this?@flylo commented on GitHub (Dec 10, 2020):
@dnatic09 I've made a bit of progress based on your finding.
I was able to patch the
HttpStorageRpcclass and use reflection to add a request initializer to the google HTTP client:I then specified a custom
ServiceRpcFactoryalongside the custom TransportFactory defined above:This allowed me to successfully create both buckets and blobs using the generated storage client:
Obviously it would be superior to just handle gzip on the server side, but I'm going to continue testing with this patch tomorrow to see if I can get this emulator working in a java environment.
@dnatic09 commented on GitHub (Dec 10, 2020):
@flylo , great work here! I think we may get some traction. Getting Google to accept a PR will likely be difficult. On the flip side, there are only a handful of methods that need to be changed on the server to check for the
Content-Encodingheader, verify that the content is indeed GZIP encoded, and then inline-decode the content prior to JSON parsing.I am not familiar in GO, but I imagine it will not be difficult to change. If I have spare time, I'll try it out and submit a PR against this repo.
@flylo commented on GitHub (Dec 10, 2020):
@dnatic09 Sorry for the confusion... when I said "server-side", I meant the server inside of this GCS emulator. The problem I'm running into now is this...
The response we get from the emulator for creating a
StorageObjectis missing the bucket-name:Which results in a
NullPointerExceptionwhen we try to parse the response on the receiving end:Specifically, it fails the
checkNotNull(bucket)in the following line:I assume the fix here is simple, but I've also never used GO and will need some time to read the code. @fsouza any ideas?
@dnatic09 commented on GitHub (Dec 10, 2020):
@flylo , I ran into the same problem. The funny thing is that you get an NPE, but the file is actually in the fake GCS server and can be pulled. I already tested it. We should definitely help fix it, but there is definitely a path forward here.
@flylo commented on GitHub (Dec 10, 2020):
Have made it a little further, but now we're running into issues where the golang server is returning uppercased field names that the java JSON parser doesn't catch:
I'm looking for a way to set global JSON-serialization settings but haven't found it yet.
@dnatic09 commented on GitHub (Dec 10, 2020):
@flylo , GOT IT !
Follow this:
github.com/fsouza/fake-gcs-server@297b8cdcd2/fakestorage/response.go (L35-L39)Then, you can change how the field is serialized. We do this and the casing will align!
@flylo commented on GitHub (Dec 10, 2020):
@dnatic09 nice! Yeah if there's no way to specify a global serialization option (like how you'd inject an
ObjectMapperinto your REST server in java), then we'll have to patch some of the google-owned structs. I patchedACLRulestruct and added my own serialization names, which un-blocked the specific test-case I was working on. That being said, I'm sure there's others. @fsouza if you know of any way to change that casing globally, then we could make this java-compatible with minimal tweaking.@dnatic09 commented on GitHub (Dec 10, 2020):
@flylo , I think Java users around the world would be WAY better off with just create-bucket and put-file functions working. The rest can be tacked on later. Your help is MUCH appreciated. There is no way I could have gotten to this anytime soon. I am so backed up with work.
@fsouza commented on GitHub (Dec 22, 2020):
hey @flylo @dnatic09 thanks for looking into this and apologies for being absent. So a quick of notes / questions:
(as a side note, there isn't a way to change that behavior globally, it's one of the issues with Go's struct tags and why I am calling it a mistake to use a third-party struct in our JSON response - our struct is not exported, so we can change this without introducing a breaking change though)
@flylo commented on GitHub (Dec 23, 2020):
@fsouza I'm not sure why that was happening if the google go library defines the struct tags... Maybe it has something to do with the fact that you're serializing an array of those
ObjectAccessControlinstances? That's the only difference I could see.@dnatic09 commented on GitHub (Dec 23, 2020):
@fsouza , I noticed that you closed #388 . Was that on purpose or did you take care of it under a different issue?
@fsouza commented on GitHub (Dec 23, 2020):
Yes, gzip should work now as of
github.com/fsouza/fake-gcs-server@f1a575d61fCan you give it a shot and let me know if you have any issues?
@dnatic09 commented on GitHub (Dec 23, 2020):
@fsouza , can you trigger a DockerHub push?
(Push image 1.22.0 as a docker tag in DockerHub)
EDIT: I think I can use
latest.@fsouza commented on GitHub (Dec 23, 2020):
@dnatic09 ohh it should be there, it's supposed to be automatic. I'll check what's up with github actions.
@dnatic09 commented on GitHub (Dec 23, 2020):
@fsouza , no joy.

I purged
latestfrom my MacBook. Verified the new digest.@fsouza commented on GitHub (Dec 23, 2020):
@dnatic09 do you have a small reproducer that I can run locally? This way I can figure something out that will definitely work (+ maybe add it as a runnable sample in CI).
I'm afk right now, but I'll try to fix this later today once I get to the computer (and figure out what's up with the automatic tagging)
Thanks for checking back!
@dnatic09 commented on GitHub (Dec 23, 2020):
I can make a reproducer overnight. I will message back when it is ready.
@dnatic09 commented on GitHub (Dec 24, 2020):
@fsouza (@flylo ), I got it.
https://github.com/dnatic09/Fake-Gcs-Test
Just clone and run
mvn test.One test will pass (rigged CURL).
One test will fail due to GZIP (using library).
@dnatic09 commented on GitHub (Jan 4, 2021):
Hey team. Just checking in. Any updates?
@fsouza commented on GitHub (Jan 4, 2021):
Hey @dnatic09, sorry ended-up taking an extended break but I'm back this week. I'll look at your example later today or tomorrow and see if I can figure out what's up.
@dnatic09 commented on GitHub (Jan 4, 2021):
No worries. Today is my first day back into work since Christmas. Completely understand. Thank you again for engaging on this.
@fsouza commented on GitHub (Feb 1, 2021):
Ohhh I see what's the problem here. I enabled compressed responses, but compressed requests are not standard and we have to implement it manually. Ugh.
@fsouza commented on GitHub (Feb 1, 2021):
@dnatic09 tests are passing now 😁
I was able to include a test for this, so will skip adding a Java example. Closing this issue for now, feel free to reopen or to open a new one if something doesn't work for you.