-
Notifications
You must be signed in to change notification settings - Fork 214
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: resolve failure in uploading files to a presigned AWS S3 upload …
…url (#1645) * bug: sending data to an AWS S3 presigned upload url does not work #1643 * fix checkstyle * documentation * apply review from @jimmarino * fix checkstyle * fix test * apply review - rename to transferInOneGo and reverse logic * fix test * apply review from @jimmarino - rename to "transfer in one go" to "nonChunkedTransfer" * apply review * fix changelog for proper milestone * fix NonChunkedTransferRequestBodyTest.java - use the new faker import Co-authored-by: Andrei-Laurentiu Coman <andrei.coman@siemens.com>
- Loading branch information
1 parent
a82e288
commit e323243
Showing
14 changed files
with
277 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
...org/eclipse/dataspaceconnector/dataplane/http/pipeline/NonChunkedTransferRequestBody.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
* Copyright (c) 2021 Microsoft Corporation | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Apache License, Version 2.0 which is available at | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* Contributors: | ||
* Microsoft Corporation - initial API and implementation | ||
* | ||
*/ | ||
|
||
package org.eclipse.dataspaceconnector.dataplane.http.pipeline; | ||
|
||
import okhttp3.MediaType; | ||
import okhttp3.RequestBody; | ||
import okio.BufferedSink; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.util.function.Supplier; | ||
|
||
/** | ||
* Writes content into an OK HTTP buffered sink. | ||
* | ||
* The extra Transfer-Encoding is not created because the Content-Length is provided upfront. | ||
* Note that means that the all content is loaded into memory, so this method can be used for small files (up to 50MB) for e.g. | ||
* | ||
* @see <a href="https://github.com/square/okhttp/blob/master/docs/features/calls.md">OkHttp Dcoumentation</a> | ||
*/ | ||
public class NonChunkedTransferRequestBody extends RequestBody { | ||
private byte[] bytes; | ||
private final String contentType; | ||
|
||
public NonChunkedTransferRequestBody(Supplier<InputStream> contentSupplier, String contentType) { | ||
try { | ||
this.bytes = contentSupplier.get().readAllBytes(); | ||
} catch (IOException e) { | ||
//do nothing | ||
} | ||
this.contentType = contentType; | ||
} | ||
|
||
@Override | ||
public long contentLength() { | ||
return bytes == null ? 0 : bytes.length; | ||
} | ||
|
||
@Override | ||
public MediaType contentType() { | ||
return MediaType.parse(contentType); | ||
} | ||
|
||
@Override | ||
public void writeTo(@NotNull BufferedSink sink) throws IOException { | ||
if (bytes == null) { | ||
return; | ||
} | ||
|
||
try (var os = sink.outputStream()) { | ||
os.write(bytes); | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.