Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions block-node/base/src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

requires transitive org.hiero.block.node.spi;
requires com.hedera.pbj.runtime;
requires org.hiero.block.common;
requires com.github.luben.zstd_jni;
requires java.net.http;
requires java.xml;
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// SPDX-License-Identifier: Apache-2.0
package org.hiero.block.node.base.s3;

/**
* A checked exception to act as a base for all S3 client exceptions.
*/
public class S3ClientException extends Exception {
public S3ClientException() {
super();
}

Check warning on line 10 in block-node/base/src/main/java/org/hiero/block/node/base/s3/S3ClientException.java

View check run for this annotation

Codecov / codecov/patch

block-node/base/src/main/java/org/hiero/block/node/base/s3/S3ClientException.java#L9-L10

Added lines #L9 - L10 were not covered by tests

public S3ClientException(final String message) {
super(message);
}

Check warning on line 14 in block-node/base/src/main/java/org/hiero/block/node/base/s3/S3ClientException.java

View check run for this annotation

Codecov / codecov/patch

block-node/base/src/main/java/org/hiero/block/node/base/s3/S3ClientException.java#L13-L14

Added lines #L13 - L14 were not covered by tests

public S3ClientException(final Throwable cause) {
super(cause);
}

Check warning on line 18 in block-node/base/src/main/java/org/hiero/block/node/base/s3/S3ClientException.java

View check run for this annotation

Codecov / codecov/patch

block-node/base/src/main/java/org/hiero/block/node/base/s3/S3ClientException.java#L17-L18

Added lines #L17 - L18 were not covered by tests

public S3ClientException(final String message, final Throwable cause) {
super(message, cause);
}

Check warning on line 22 in block-node/base/src/main/java/org/hiero/block/node/base/s3/S3ClientException.java

View check run for this annotation

Codecov / codecov/patch

block-node/base/src/main/java/org/hiero/block/node/base/s3/S3ClientException.java#L21-L22

Added lines #L21 - L22 were not covered by tests
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// SPDX-License-Identifier: Apache-2.0
package org.hiero.block.node.base.s3;

public class S3ClientInitializationException extends S3ClientException {
public S3ClientInitializationException() {
super();
}

Check warning on line 7 in block-node/base/src/main/java/org/hiero/block/node/base/s3/S3ClientInitializationException.java

View check run for this annotation

Codecov / codecov/patch

block-node/base/src/main/java/org/hiero/block/node/base/s3/S3ClientInitializationException.java#L6-L7

Added lines #L6 - L7 were not covered by tests

public S3ClientInitializationException(final String message) {
super(message);
}

Check warning on line 11 in block-node/base/src/main/java/org/hiero/block/node/base/s3/S3ClientInitializationException.java

View check run for this annotation

Codecov / codecov/patch

block-node/base/src/main/java/org/hiero/block/node/base/s3/S3ClientInitializationException.java#L10-L11

Added lines #L10 - L11 were not covered by tests

public S3ClientInitializationException(final Throwable cause) {
super(cause);
}

Check warning on line 15 in block-node/base/src/main/java/org/hiero/block/node/base/s3/S3ClientInitializationException.java

View check run for this annotation

Codecov / codecov/patch

block-node/base/src/main/java/org/hiero/block/node/base/s3/S3ClientInitializationException.java#L14-L15

Added lines #L14 - L15 were not covered by tests

public S3ClientInitializationException(final String message, final Throwable cause) {
super(message, cause);
}

Check warning on line 19 in block-node/base/src/main/java/org/hiero/block/node/base/s3/S3ClientInitializationException.java

View check run for this annotation

Codecov / codecov/patch

block-node/base/src/main/java/org/hiero/block/node/base/s3/S3ClientInitializationException.java#L18-L19

Added lines #L18 - L19 were not covered by tests
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
// SPDX-License-Identifier: Apache-2.0
package org.hiero.block.node.base.s3;

import edu.umd.cs.findbugs.annotations.Nullable;
import java.net.http.HttpHeaders;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

/**
* A checked exception thrown when an S3 response is not successful.
*/
public final class S3ResponseException extends S3ClientException {
/** The size limit for the toString response body length */
private static final int MAX_RESPONSE_BODY_STRING_LENGTH = 2048;
/** The size limit for the toString headers length */
private static final int MAX_HEADER_STRING_LENGTH = 2048;
/** The four-space indent used for formatting the exception string */
private static final String FOUR_SPACE_INDENT = " ";
/** The response status code */
private final int responseStatusCode;
/** The response body, nullable */
private final byte[] responseBody;
/** The response headers, nullable */
private final HttpHeaders responseHeaders;

public S3ResponseException(
final int responseStatusCode,
@Nullable final byte[] responseBody,
@Nullable final HttpHeaders responseHeaders) {
super();
this.responseStatusCode = responseStatusCode;
this.responseBody = responseBody;
this.responseHeaders = responseHeaders;
}

Check warning on line 35 in block-node/base/src/main/java/org/hiero/block/node/base/s3/S3ResponseException.java

View check run for this annotation

Codecov / codecov/patch

block-node/base/src/main/java/org/hiero/block/node/base/s3/S3ResponseException.java#L31-L35

Added lines #L31 - L35 were not covered by tests

public S3ResponseException(
final int responseStatusCode,
@Nullable final byte[] responseBody,
@Nullable final HttpHeaders responseHeaders,
final String message) {
super(message);
this.responseStatusCode = responseStatusCode;
this.responseBody = responseBody;
this.responseHeaders = responseHeaders;
}

Check warning on line 46 in block-node/base/src/main/java/org/hiero/block/node/base/s3/S3ResponseException.java

View check run for this annotation

Codecov / codecov/patch

block-node/base/src/main/java/org/hiero/block/node/base/s3/S3ResponseException.java#L42-L46

Added lines #L42 - L46 were not covered by tests

public S3ResponseException(
final int responseStatusCode,
@Nullable final byte[] responseBody,
@Nullable final HttpHeaders responseHeaders,
final Throwable cause) {
super(cause);
this.responseStatusCode = responseStatusCode;
this.responseBody = responseBody;
this.responseHeaders = responseHeaders;
}

Check warning on line 57 in block-node/base/src/main/java/org/hiero/block/node/base/s3/S3ResponseException.java

View check run for this annotation

Codecov / codecov/patch

block-node/base/src/main/java/org/hiero/block/node/base/s3/S3ResponseException.java#L53-L57

Added lines #L53 - L57 were not covered by tests

public S3ResponseException(
final int responseStatusCode,
@Nullable final byte[] responseBody,
@Nullable final HttpHeaders responseHeaders,
final String message,
final Throwable cause) {
super(message, cause);
this.responseStatusCode = responseStatusCode;
this.responseBody = responseBody;
this.responseHeaders = responseHeaders;
}

Check warning on line 69 in block-node/base/src/main/java/org/hiero/block/node/base/s3/S3ResponseException.java

View check run for this annotation

Codecov / codecov/patch

block-node/base/src/main/java/org/hiero/block/node/base/s3/S3ResponseException.java#L65-L69

Added lines #L65 - L69 were not covered by tests

public int getResponseStatusCode() {
return responseStatusCode;

Check warning on line 72 in block-node/base/src/main/java/org/hiero/block/node/base/s3/S3ResponseException.java

View check run for this annotation

Codecov / codecov/patch

block-node/base/src/main/java/org/hiero/block/node/base/s3/S3ResponseException.java#L72

Added line #L72 was not covered by tests
}

public byte[] getResponseBody() {
return responseBody;

Check warning on line 76 in block-node/base/src/main/java/org/hiero/block/node/base/s3/S3ResponseException.java

View check run for this annotation

Codecov / codecov/patch

block-node/base/src/main/java/org/hiero/block/node/base/s3/S3ResponseException.java#L76

Added line #L76 was not covered by tests
}

public HttpHeaders getResponseHeaders() {
return responseHeaders;

Check warning on line 80 in block-node/base/src/main/java/org/hiero/block/node/base/s3/S3ResponseException.java

View check run for this annotation

Codecov / codecov/patch

block-node/base/src/main/java/org/hiero/block/node/base/s3/S3ResponseException.java#L80

Added line #L80 was not covered by tests
}

/**
* @return a {@link String} representation of this exception including the
* response code, headers if available and body if available. Header and
* body strings are limited to a maximum length: header limit - {@value MAX_HEADER_STRING_LENGTH}
* and body limit - {@value MAX_RESPONSE_BODY_STRING_LENGTH}.
*/
@Override
public String toString() {
// start with standard exception string building
final String className = getClass().getName();
final String message = getLocalizedMessage();
final StringBuilder sb = new StringBuilder(className);

Check warning on line 94 in block-node/base/src/main/java/org/hiero/block/node/base/s3/S3ResponseException.java

View check run for this annotation

Codecov / codecov/patch

block-node/base/src/main/java/org/hiero/block/node/base/s3/S3ResponseException.java#L92-L94

Added lines #L92 - L94 were not covered by tests
if (message != null) {
// if there is a message, append it
sb.append(": ").append(message);

Check warning on line 97 in block-node/base/src/main/java/org/hiero/block/node/base/s3/S3ResponseException.java

View check run for this annotation

Codecov / codecov/patch

block-node/base/src/main/java/org/hiero/block/node/base/s3/S3ResponseException.java#L97

Added line #L97 was not covered by tests
}
sb.append(System.lineSeparator());
appendResponseCode(sb);
appendHeaders(sb);
appendBody(sb);
return sb.toString();

Check warning on line 103 in block-node/base/src/main/java/org/hiero/block/node/base/s3/S3ResponseException.java

View check run for this annotation

Codecov / codecov/patch

block-node/base/src/main/java/org/hiero/block/node/base/s3/S3ResponseException.java#L99-L103

Added lines #L99 - L103 were not covered by tests
}

/**
* Append the response code to the StringBuilder.
*/
private void appendResponseCode(final StringBuilder sb) {
// append the response status code
sb.append(FOUR_SPACE_INDENT).append("Response status code: ").append(responseStatusCode);
}

Check warning on line 112 in block-node/base/src/main/java/org/hiero/block/node/base/s3/S3ResponseException.java

View check run for this annotation

Codecov / codecov/patch

block-node/base/src/main/java/org/hiero/block/node/base/s3/S3ResponseException.java#L111-L112

Added lines #L111 - L112 were not covered by tests

/**
* Append the response headers to the StringBuilder.
* If there are no headers, this method does nothing.
* Size limit for the headers string is {@value MAX_HEADER_STRING_LENGTH}.
*/
private void appendHeaders(final StringBuilder sb) {
if (responseHeaders != null) {
final Map<String, List<String>> headersMap = responseHeaders.map();

Check warning on line 121 in block-node/base/src/main/java/org/hiero/block/node/base/s3/S3ResponseException.java

View check run for this annotation

Codecov / codecov/patch

block-node/base/src/main/java/org/hiero/block/node/base/s3/S3ResponseException.java#L121

Added line #L121 was not covered by tests
if (headersMap != null && !headersMap.isEmpty()) {
// for each header, append the header name and value(s)
sb.append(System.lineSeparator());
sb.append(FOUR_SPACE_INDENT).append("Response headers:");

Check warning on line 125 in block-node/base/src/main/java/org/hiero/block/node/base/s3/S3ResponseException.java

View check run for this annotation

Codecov / codecov/patch

block-node/base/src/main/java/org/hiero/block/node/base/s3/S3ResponseException.java#L124-L125

Added lines #L124 - L125 were not covered by tests
// we limit the size of the printed headers
int headerSizeCount = 0;

Check warning on line 127 in block-node/base/src/main/java/org/hiero/block/node/base/s3/S3ResponseException.java

View check run for this annotation

Codecov / codecov/patch

block-node/base/src/main/java/org/hiero/block/node/base/s3/S3ResponseException.java#L127

Added line #L127 was not covered by tests
for (final Entry<String, List<String>> entry : headersMap.entrySet()) {
// for each header, we get the key and values
final String headerKey = entry.getKey() + ": ";
sb.append(System.lineSeparator());

Check warning on line 131 in block-node/base/src/main/java/org/hiero/block/node/base/s3/S3ResponseException.java

View check run for this annotation

Codecov / codecov/patch

block-node/base/src/main/java/org/hiero/block/node/base/s3/S3ResponseException.java#L130-L131

Added lines #L130 - L131 were not covered by tests
if (headerSizeCount + headerKey.length() > MAX_HEADER_STRING_LENGTH) {
// if string limit size is exceeded, break
sb.append(FOUR_SPACE_INDENT.repeat(2)).append("...");
break;

Check warning on line 135 in block-node/base/src/main/java/org/hiero/block/node/base/s3/S3ResponseException.java

View check run for this annotation

Codecov / codecov/patch

block-node/base/src/main/java/org/hiero/block/node/base/s3/S3ResponseException.java#L134-L135

Added lines #L134 - L135 were not covered by tests
} else {
// append the header key
sb.append(FOUR_SPACE_INDENT.repeat(2)).append(headerKey);
headerSizeCount += headerKey.length();

Check warning on line 139 in block-node/base/src/main/java/org/hiero/block/node/base/s3/S3ResponseException.java

View check run for this annotation

Codecov / codecov/patch

block-node/base/src/main/java/org/hiero/block/node/base/s3/S3ResponseException.java#L138-L139

Added lines #L138 - L139 were not covered by tests
}
// append the header values, usually we expect only one value per header
final List<String> values = entry.getValue();
boolean isFirstValue = true;

Check warning on line 143 in block-node/base/src/main/java/org/hiero/block/node/base/s3/S3ResponseException.java

View check run for this annotation

Codecov / codecov/patch

block-node/base/src/main/java/org/hiero/block/node/base/s3/S3ResponseException.java#L142-L143

Added lines #L142 - L143 were not covered by tests
for (final String value : values) {
// if string limit size is exceeded, break
if (headerSizeCount + value.length() > MAX_HEADER_STRING_LENGTH) {
// if the value size exceeds the limit, break
sb.append(" ...");
break;

Check warning on line 149 in block-node/base/src/main/java/org/hiero/block/node/base/s3/S3ResponseException.java

View check run for this annotation

Codecov / codecov/patch

block-node/base/src/main/java/org/hiero/block/node/base/s3/S3ResponseException.java#L148-L149

Added lines #L148 - L149 were not covered by tests
} else {
// append the value, separate with a comma for multi-value headers
if (!isFirstValue) {
sb.append(", ");
headerSizeCount += 2;

Check warning on line 154 in block-node/base/src/main/java/org/hiero/block/node/base/s3/S3ResponseException.java

View check run for this annotation

Codecov / codecov/patch

block-node/base/src/main/java/org/hiero/block/node/base/s3/S3ResponseException.java#L153-L154

Added lines #L153 - L154 were not covered by tests
} else {
isFirstValue = false;

Check warning on line 156 in block-node/base/src/main/java/org/hiero/block/node/base/s3/S3ResponseException.java

View check run for this annotation

Codecov / codecov/patch

block-node/base/src/main/java/org/hiero/block/node/base/s3/S3ResponseException.java#L156

Added line #L156 was not covered by tests
}
sb.append(value);
headerSizeCount += value.length();

Check warning on line 159 in block-node/base/src/main/java/org/hiero/block/node/base/s3/S3ResponseException.java

View check run for this annotation

Codecov / codecov/patch

block-node/base/src/main/java/org/hiero/block/node/base/s3/S3ResponseException.java#L158-L159

Added lines #L158 - L159 were not covered by tests
}
}
}

Check warning on line 162 in block-node/base/src/main/java/org/hiero/block/node/base/s3/S3ResponseException.java

View check run for this annotation

Codecov / codecov/patch

block-node/base/src/main/java/org/hiero/block/node/base/s3/S3ResponseException.java#L161-L162

Added lines #L161 - L162 were not covered by tests
}
}
}

Check warning on line 165 in block-node/base/src/main/java/org/hiero/block/node/base/s3/S3ResponseException.java

View check run for this annotation

Codecov / codecov/patch

block-node/base/src/main/java/org/hiero/block/node/base/s3/S3ResponseException.java#L165

Added line #L165 was not covered by tests

/**
* Append the response body to the StringBuilder.
* If there is no response body, this method does nothing.
* Size limit for the response body string is {@value MAX_RESPONSE_BODY_STRING_LENGTH}.
*/
private void appendBody(final StringBuilder sb) {
if (responseBody != null && responseBody.length > 0) {
// if there is a response body, append it
sb.append(System.lineSeparator());

Check warning on line 175 in block-node/base/src/main/java/org/hiero/block/node/base/s3/S3ResponseException.java

View check run for this annotation

Codecov / codecov/patch

block-node/base/src/main/java/org/hiero/block/node/base/s3/S3ResponseException.java#L175

Added line #L175 was not covered by tests
// we limit the size of the printed response body
sb.append(" Response body: ");

Check warning on line 177 in block-node/base/src/main/java/org/hiero/block/node/base/s3/S3ResponseException.java

View check run for this annotation

Codecov / codecov/patch

block-node/base/src/main/java/org/hiero/block/node/base/s3/S3ResponseException.java#L177

Added line #L177 was not covered by tests
if (responseBody.length > MAX_RESPONSE_BODY_STRING_LENGTH) {
sb.append(new String(responseBody, 0, MAX_RESPONSE_BODY_STRING_LENGTH))
.append(" ...");

Check warning on line 180 in block-node/base/src/main/java/org/hiero/block/node/base/s3/S3ResponseException.java

View check run for this annotation

Codecov / codecov/patch

block-node/base/src/main/java/org/hiero/block/node/base/s3/S3ResponseException.java#L179-L180

Added lines #L179 - L180 were not covered by tests
} else {
// if the response body is small enough, append it fully
sb.append(new String(responseBody));

Check warning on line 183 in block-node/base/src/main/java/org/hiero/block/node/base/s3/S3ResponseException.java

View check run for this annotation

Codecov / codecov/patch

block-node/base/src/main/java/org/hiero/block/node/base/s3/S3ResponseException.java#L183

Added line #L183 was not covered by tests
}
}
}

Check warning on line 186 in block-node/base/src/main/java/org/hiero/block/node/base/s3/S3ResponseException.java

View check run for this annotation

Codecov / codecov/patch

block-node/base/src/main/java/org/hiero/block/node/base/s3/S3ResponseException.java#L186

Added line #L186 was not covered by tests
}

This file was deleted.

Loading
Loading