Skip to content

Commit dc73c77

Browse files
committed
Merge branch 'main' of github.com:XRPLF/xrpl4j into releases/3.5
2 parents eb2ce7a + 5675497 commit dc73c77

File tree

4 files changed

+62
-2
lines changed

4 files changed

+62
-2
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ current [BOM](https://howtodoinjava.com/maven/maven-bom-bill-of-materials-depend
3333
<dependency>
3434
<groupId>org.xrpl</groupId>
3535
<artifactId>xrpl4j-bom</artifactId>
36-
<version>3.4.0</version>
36+
<version>3.5.0</version>
3737
<type>pom</type>
3838
<scope>import</scope>
3939
</dependency>

xrpl4j-client/src/main/java/org/xrpl/xrpl4j/client/JsonRpcClient.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import com.google.common.annotations.Beta;
2828
import feign.Feign;
2929
import feign.Headers;
30+
import feign.Request.Options;
3031
import feign.RequestLine;
3132
import feign.jackson.JacksonDecoder;
3233
import feign.jackson.JacksonEncoder;
@@ -71,18 +72,34 @@ public interface JsonRpcClient {
7172
/**
7273
* Constructs a new client for the given url.
7374
*
74-
* @param rippledUrl url for the faucet server.
75+
* @param rippledUrl The {@link HttpUrl} of the node to connect to.
7576
*
7677
* @return A {@link JsonRpcClient} that can make request to {@code rippledUrl}
7778
*/
7879
static JsonRpcClient construct(final HttpUrl rippledUrl) {
7980
Objects.requireNonNull(rippledUrl);
8081

82+
return construct(rippledUrl, new Options());
83+
}
84+
85+
/**
86+
* Constructs a new client for the given url with the given client options.
87+
*
88+
* @param rippledUrl The {@link HttpUrl} of the node to connect to.
89+
* @param options An {@link Options}.
90+
*
91+
* @return A {@link JsonRpcClient}.
92+
*/
93+
static JsonRpcClient construct(HttpUrl rippledUrl, Options options) {
94+
Objects.requireNonNull(rippledUrl);
95+
Objects.requireNonNull(options);
96+
8197
return Feign.builder()
8298
.encoder(new JacksonEncoder(objectMapper))
8399
// rate limiting will return a 503 status that can be retried
84100
.errorDecoder(new RetryStatusDecoder(RETRY_INTERVAL, SERVICE_UNAVAILABLE_STATUS))
85101
.decode404()
102+
.options(options)
86103
.decoder(new OptionalDecoder(new JacksonDecoder(objectMapper)))
87104
.target(JsonRpcClient.class, rippledUrl.toString());
88105
}

xrpl4j-client/src/main/java/org/xrpl/xrpl4j/client/XrplClient.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
import com.google.common.collect.Range;
2929
import com.google.common.primitives.UnsignedInteger;
3030
import com.google.common.primitives.UnsignedLong;
31+
import feign.Request;
32+
import feign.Request.Options;
3133
import okhttp3.HttpUrl;
3234
import org.slf4j.Logger;
3335
import org.slf4j.LoggerFactory;
@@ -99,8 +101,10 @@
99101
import org.xrpl.xrpl4j.model.transactions.Transaction;
100102
import org.xrpl.xrpl4j.model.transactions.TransactionMetadata;
101103

104+
import java.time.Duration;
102105
import java.util.Objects;
103106
import java.util.Optional;
107+
import java.util.concurrent.TimeUnit;
104108

105109
/**
106110
* <p>A client which wraps a rippled network client and is responsible for higher order functionality such as signing
@@ -127,6 +131,31 @@ public XrplClient(final HttpUrl rippledUrl) {
127131
this(JsonRpcClient.construct(rippledUrl));
128132
}
129133

134+
/**
135+
* Public constructor that allows for configuration of connect and read timeouts.
136+
*
137+
* <p>Note that any {@link Duration} passed in that is less than one millisecond will result in the actual timeout
138+
* being zero milliseconds. It is therefore advised to never set {@code connectTimeout} or {@code readTimeout} to a
139+
* {@link Duration} less than one millisecond.
140+
*
141+
* @param rippledUrl The {@link HttpUrl} of the node to connect to.
142+
* @param connectTimeout A {@link Duration} indicating the client's connect timeout.
143+
* @param readTimeout A {@link Duration} indicating the client's read timeout.
144+
*/
145+
public XrplClient(
146+
HttpUrl rippledUrl,
147+
Duration connectTimeout,
148+
Duration readTimeout
149+
) {
150+
this(
151+
JsonRpcClient.construct(
152+
rippledUrl,
153+
new Options(connectTimeout.toMillis(), TimeUnit.MILLISECONDS, readTimeout.toMillis(), TimeUnit.MILLISECONDS,
154+
true)
155+
)
156+
);
157+
}
158+
130159
/**
131160
* Required-args constructor (exists for testing purposes only).
132161
*

xrpl4j-client/src/test/java/org/xrpl/xrpl4j/client/XrplClientTest.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,11 @@
122122
import org.xrpl.xrpl4j.model.transactions.XrpCurrencyAmount;
123123

124124
import java.math.BigDecimal;
125+
import java.time.Duration;
125126
import java.time.ZonedDateTime;
126127
import java.util.Optional;
127128
import java.util.Set;
129+
import java.util.concurrent.TimeUnit;
128130
import java.util.concurrent.atomic.AtomicReference;
129131

130132
/**
@@ -599,6 +601,18 @@ public void getXrplClientTest() {
599601
assertThat(new XrplClient(rippledUrl) instanceof JsonRpcClient).isFalse();
600602
}
601603

604+
@Test
605+
void createXrplClientWithDurationTimeouts() {
606+
HttpUrl rippledUrl = HttpUrl.parse("https://s.altnet.rippletest.net:51234");
607+
XrplClient client = new XrplClient(
608+
rippledUrl,
609+
Duration.ofSeconds(1),
610+
Duration.ofMinutes(2)
611+
);
612+
613+
assertThat(client).isInstanceOf(XrplClient.class);
614+
}
615+
602616
@Test
603617
public void submitSingleSignedTransaction() {
604618
BcSignatureService bcSignatureService = new BcSignatureService();

0 commit comments

Comments
 (0)