From 207374853d7142ae067ff381cc197698aaa05ff4 Mon Sep 17 00:00:00 2001 From: Mele Sax-Barnett Date: Wed, 20 Mar 2019 16:21:30 -0700 Subject: [PATCH 1/6] update PR template test against real APIs fix broken link --- .github/PULL_REQUEST_TEMPLATE.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index cbf3834..41090bc 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -5,13 +5,14 @@ Please include link to open issue if applicable. * If applicable ### Testing +- [ ] If these changes added new functionality, I tested them against the live API with real auth - [ ] I wrote tests covering these changes - [ ] I ran the full test suite and it passed ### Test run results, including date and time: ### Urban Airship Contribution Agreement -https://docs.urbanairship.com/contribution-agreement/ +[Link here](https://docs.google.com/forms/d/e/1FAIpQLScErfiz-fXSPpVZ9r8Di2Tr2xDFxt5MgzUel0__9vqUgvko7Q/viewform) - [ ] I've filled out and signed UA's contribution agreement form. From 56a1d3f6a7c6ab82eb1d099085a9be16c98d551c Mon Sep 17 00:00:00 2001 From: Oskar Stephens Date: Wed, 29 May 2019 12:46:33 -0700 Subject: [PATCH 2/6] Add support for specifying connect endpoint URL This allows the use of other connect endpoints if/when they become available Fix equals method in StreamQueryDescriptor. This was not updated when the offsets enabled option was added --- CHANGELOG | 4 ++ README.md | 2 +- .../connect/client/StreamConnection.java | 7 +++ .../connect/client/StreamConsumeTask.java | 2 +- .../client/model/StreamQueryDescriptor.java | 45 ++++++++++++++----- .../connect/client/StreamConnectionTest.java | 41 +++++++++++++++++ 6 files changed, 88 insertions(+), 13 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 01b12be..7d58fce 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,7 @@ +2019-05-29 Release 5.1.0 + + Add support for specifying an alternate endpoint URL for stream consumption. + 2018-06-21 Release 5.0.2 Set AsyncHttpClient Max Request Retry to 0 to better handle disconnects and not restart at old offsets. diff --git a/README.md b/README.md index 4fd8bce..2eb68ba 100644 --- a/README.md +++ b/README.md @@ -107,7 +107,7 @@ StreamQueryDescriptor --------------------- Begin by creating a StreamQueryDescriptor instance. This will contain the app credentials, any request filters, - a starting offset, offset update preference, and any subset options. + a starting offset, offset update preference, endpoint URL, and any subset options. If offset updates are enabled, then regardless of other filters provided the stream may contain events with type OFFSET_UPDATE. These don't correspond to any activity in Urban Airship's systems and requests for the same stream diff --git a/src/main/java/com/urbanairship/connect/client/StreamConnection.java b/src/main/java/com/urbanairship/connect/client/StreamConnection.java index da3a5b5..dab5ef4 100644 --- a/src/main/java/com/urbanairship/connect/client/StreamConnection.java +++ b/src/main/java/com/urbanairship/connect/client/StreamConnection.java @@ -89,6 +89,13 @@ public StreamConnection(StreamQueryDescriptor descriptor, this.url = url; } + public StreamConnection(StreamQueryDescriptor descriptor, + AsyncHttpClient client, + ConnectionRetryStrategy connectionRetryStrategy, + Consumer eventConsumer) { + this(descriptor, client, connectionRetryStrategy, eventConsumer, descriptor.getEndpointUrl()); + } + /** * Opens up a connection to Urban Airship Connect and begins consuming data and passing it to the configured consumer * starting at the position specified by the startPosition parameter. diff --git a/src/main/java/com/urbanairship/connect/client/StreamConsumeTask.java b/src/main/java/com/urbanairship/connect/client/StreamConsumeTask.java index 10e190a..9addc09 100644 --- a/src/main/java/com/urbanairship/connect/client/StreamConsumeTask.java +++ b/src/main/java/com/urbanairship/connect/client/StreamConsumeTask.java @@ -269,7 +269,7 @@ private static class MobileEventStreamConnectionSupplier implements StreamConnec public StreamConnection get(StreamQueryDescriptor descriptor, AsyncHttpClient client, Consumer eventConsumer) { - return new StreamConnection(descriptor, client, CONNECTION_RETRY_STRATEGY, eventConsumer, Constants.API_URL); + return new StreamConnection(descriptor, client, CONNECTION_RETRY_STRATEGY, eventConsumer); } } diff --git a/src/main/java/com/urbanairship/connect/client/model/StreamQueryDescriptor.java b/src/main/java/com/urbanairship/connect/client/model/StreamQueryDescriptor.java index c15eb8f..512824a 100644 --- a/src/main/java/com/urbanairship/connect/client/model/StreamQueryDescriptor.java +++ b/src/main/java/com/urbanairship/connect/client/model/StreamQueryDescriptor.java @@ -7,9 +7,11 @@ import com.google.common.base.Optional; import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableSet; +import com.urbanairship.connect.client.Constants; import com.urbanairship.connect.client.StreamConnection; import com.urbanairship.connect.client.model.request.Subset; import com.urbanairship.connect.client.model.request.filters.Filter; +import org.apache.commons.lang3.StringUtils; import java.util.Collections; import java.util.HashSet; @@ -25,6 +27,7 @@ public final class StreamQueryDescriptor { private final Set filters; private final Optional subset; private final Optional offsetUpdatesEnabled; + private final String endpointUrl; /** * StreamDescriptor builder @@ -34,11 +37,12 @@ public static Builder newBuilder() { return new Builder(); } - private StreamQueryDescriptor(Creds creds, Set filters, Optional subset, Optional offsetUpdatesEnabled) { + private StreamQueryDescriptor(Creds creds, Set filters, Optional subset, Optional offsetUpdatesEnabled, String endpointUrl) { this.creds = creds; this.filters = filters; this.subset = subset; this.offsetUpdatesEnabled = offsetUpdatesEnabled; + this.endpointUrl = endpointUrl; } /** @@ -77,23 +81,30 @@ public Optional offsetUpdatesEnabled() { return offsetUpdatesEnabled; } + /** + * Get Configured endpoint URL + * + * @return endpoint URL + */ + public String getEndpointUrl() { + return endpointUrl; + } + @Override public boolean equals(Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; StreamQueryDescriptor that = (StreamQueryDescriptor) o; return Objects.equals(creds, that.creds) && Objects.equals(filters, that.filters) && - Objects.equals(subset, that.subset); + Objects.equals(subset, that.subset) && + Objects.equals(offsetUpdatesEnabled, that.offsetUpdatesEnabled) && + Objects.equals(endpointUrl, that.endpointUrl); } @Override public int hashCode() { - return Objects.hash(creds, filters, subset); + return Objects.hash(creds, filters, subset, offsetUpdatesEnabled, endpointUrl); } public static final class Builder { @@ -103,6 +114,7 @@ public static final class Builder { private Creds creds = null; private Subset subset = null; private Optional offsetUpdatesEnabled = Optional.absent(); + private String endpointUrl = Constants.API_URL; private Builder() {} @@ -159,14 +171,25 @@ public Builder disableOffsetUpdates() { return this; } + public Builder setEndpointUrl(String url) { + this.endpointUrl = url; + return this; + } + /** * Builder a StreamDescriptor object. * @return StreamDescriptor */ public StreamQueryDescriptor build() { Preconditions.checkNotNull(creds, "Creds object must be provided"); - - return new StreamQueryDescriptor(creds, ImmutableSet.copyOf(filters), Optional.fromNullable(subset), offsetUpdatesEnabled); + Preconditions.checkArgument(StringUtils.isNotBlank(endpointUrl), "Endpoint URL must not be null"); + + return new StreamQueryDescriptor( + creds, + ImmutableSet.copyOf(filters), + Optional.fromNullable(subset), + offsetUpdatesEnabled, + endpointUrl); } } } diff --git a/src/test/java/com/urbanairship/connect/client/StreamConnectionTest.java b/src/test/java/com/urbanairship/connect/client/StreamConnectionTest.java index d13d0be..73197d9 100644 --- a/src/test/java/com/urbanairship/connect/client/StreamConnectionTest.java +++ b/src/test/java/com/urbanairship/connect/client/StreamConnectionTest.java @@ -257,6 +257,47 @@ public Object answer(InvocationOnMock invocation) throws Throwable { assertEquals(offset, bodyObj.get("resume_offset").getAsString()); } + @Test + public void testRequestBodyWithDescriptorUrl() throws Exception { + final AtomicReference body = new AtomicReference<>(); + final CountDownLatch received = new CountDownLatch(1); + Answer httpAnswer = new Answer() { + @Override + public Object answer(InvocationOnMock invocation) throws Throwable { + HttpExchange exchange = (HttpExchange) invocation.getArguments()[0]; + + int length = Integer.parseInt(exchange.getRequestHeaders().getFirst(HttpHeaders.CONTENT_LENGTH)); + byte[] bytes = new byte[length]; + exchange.getRequestBody().read(bytes); + body.set(new String(bytes, UTF_8)); + + exchange.sendResponseHeaders(200, 0L); + received.countDown(); + + return null; + } + }; + + doAnswer(httpAnswer).when(serverHandler).handle(Matchers.any()); + + String offset = RandomStringUtils.randomAlphanumeric(32); + StreamQueryDescriptor descriptor = StreamQueryDescriptor.newBuilder() + .setEndpointUrl(url) + .setCreds( Creds.newBuilder() + .setAppKey(randomAlphabetic(22)) + .setToken(randomAlphabetic(5)) + .build()) + .build(); + + stream = new StreamConnection(descriptor, http, connectionRetryStrategy, consumer); + read(stream, Optional.of(StartPosition.offset(offset))); + + assertTrue(received.await(10, TimeUnit.SECONDS)); + + JsonObject bodyObj = parser.parse(body.get()).getAsJsonObject(); + assertEquals(offset, bodyObj.get("resume_offset").getAsString()); + } + @Test public void testRequestWithRelativeOffsetLatest() throws Exception { final AtomicReference body = new AtomicReference<>(); From b993d17cec3c2ebcf05d1801cbaebbd30ccbff63 Mon Sep 17 00:00:00 2001 From: Oskar Stephens Date: Thu, 30 May 2019 09:04:13 -0700 Subject: [PATCH 3/6] Add EU url as a constant --- src/main/java/com/urbanairship/connect/client/Constants.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/com/urbanairship/connect/client/Constants.java b/src/main/java/com/urbanairship/connect/client/Constants.java index 94bfe2c..a93308b 100644 --- a/src/main/java/com/urbanairship/connect/client/Constants.java +++ b/src/main/java/com/urbanairship/connect/client/Constants.java @@ -3,6 +3,7 @@ public final class Constants { public static final String API_URL = "https://connect.urbanairship.com/api/events/"; + public static final String EU_API_URL = "https://connect.asnapieu.com/api/events/"; private Constants() { } } From 2a20c5068d7aab19d8c9c176f40644271922ba86 Mon Sep 17 00:00:00 2001 From: Devin Smythe Date: Tue, 22 Oct 2019 16:44:59 -0700 Subject: [PATCH 4/6] Added device type filters for open, sms, and email --- .../connect/client/model/request/filters/DeviceType.java | 2 +- .../model/request/filters/DeviceTypeSerializationTest.java | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/urbanairship/connect/client/model/request/filters/DeviceType.java b/src/main/java/com/urbanairship/connect/client/model/request/filters/DeviceType.java index 8e1c8f8..f559565 100644 --- a/src/main/java/com/urbanairship/connect/client/model/request/filters/DeviceType.java +++ b/src/main/java/com/urbanairship/connect/client/model/request/filters/DeviceType.java @@ -9,7 +9,7 @@ public enum DeviceType { - IOS("ios"), ANDROID("android"), AMAZON("amazon"); + IOS("ios"), ANDROID("android"), AMAZON("amazon"), SMS("sms"), OPEN("open"), EMAIL("email"); private final String serializedValue; diff --git a/src/test/java/com/urbanairship/connect/client/model/request/filters/DeviceTypeSerializationTest.java b/src/test/java/com/urbanairship/connect/client/model/request/filters/DeviceTypeSerializationTest.java index 493fd51..2edf16c 100644 --- a/src/test/java/com/urbanairship/connect/client/model/request/filters/DeviceTypeSerializationTest.java +++ b/src/test/java/com/urbanairship/connect/client/model/request/filters/DeviceTypeSerializationTest.java @@ -20,10 +20,13 @@ public void testSerialization() throws Exception { types.add(DeviceType.AMAZON); types.add(DeviceType.ANDROID); types.add(DeviceType.IOS); + types.add(DeviceType.SMS); + types.add(DeviceType.EMAIL); + types.add(DeviceType.OPEN); JsonElement obj = GsonUtil.getGson().toJsonTree(types); - JsonElement expected = parser.parse("[\"amazon\", \"android\", \"ios\"]"); + JsonElement expected = parser.parse("[\"amazon\", \"android\", \"ios\", \"sms\", \"email\", \"open\"]"); assertEquals(expected, obj); } From d9e6308cfb9a17cb48d8f6023748ac6e1b7967ae Mon Sep 17 00:00:00 2001 From: Devin Smythe Date: Wed, 23 Oct 2019 12:13:19 -0700 Subject: [PATCH 5/6] Updated the changelog --- CHANGELOG | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG b/CHANGELOG index 7d58fce..afdf186 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,7 @@ +2019-XX-XX Release 5.2.0 + + Add device type filters for sms, email, and open channels. + 2019-05-29 Release 5.1.0 Add support for specifying an alternate endpoint URL for stream consumption. From a9a2ca57fdf5245641994e390d9b78f0404ec35b Mon Sep 17 00:00:00 2001 From: Devin Smythe Date: Thu, 24 Oct 2019 08:45:22 -0700 Subject: [PATCH 6/6] Updated the release date in changelog --- CHANGELOG | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG b/CHANGELOG index afdf186..b684740 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,4 +1,4 @@ -2019-XX-XX Release 5.2.0 +2019-10-24 Release 5.2.0 Add device type filters for sms, email, and open channels.