Skip to content

Commit 859c865

Browse files
committed
Fix URL resolver to consdier path in baseURL. closes #263
1 parent 816a625 commit 859c865

File tree

5 files changed

+23
-37
lines changed

5 files changed

+23
-37
lines changed

android/app/src/main/AndroidManifest.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,10 @@
7878
<meta-data
7979
android:name="com.google.firebase.messaging.default_notification_channel_id"
8080
android:value="@string/notification_channel_default" />
81-
<meta-data android:name="io.sentry.dsn" android:value="https://b0b98a8c44844eb9bed3f58ccbb3ac5c@o291224.ingest.sentry.io/6539757" />
81+
<meta-data android:name="io.sentry.dsn" android:value="https://3413741bb211a873f5f93a00b8974a03@o291224.ingest.sentry.io/6539757" />
8282
<!-- Set tracesSampleRate to 1.0 to capture 100% of transactions for performance monitoring.
8383
We recommend adjusting this value in production. -->
84-
<meta-data android:name="io.sentry.traces.sample-rate" android:value="1.0" />
84+
<meta-data android:name="io.sentry.traces.sample-rate" android:value="0.5" />
8585
<!-- Enable user interaction tracing to capture transactions for various UI events (such as clicks or scrolls). -->
8686
<meta-data android:name="io.sentry.traces.user-interaction.enable" android:value="true" />
8787

android/app/src/main/java/com/httpsms/FirebaseMessagingService.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,14 @@ class MyFirebaseMessagingService : FirebaseMessagingService() {
6969

7070
private fun scheduleJob(messageID: String) {
7171
// [START dispatch_job]
72+
val constraints = Constraints.Builder()
73+
.setRequiredNetworkType(NetworkType.CONNECTED)
74+
.build()
75+
7276
val inputData: Data = workDataOf(Constants.KEY_MESSAGE_ID to messageID)
7377
val work = OneTimeWorkRequest
7478
.Builder(SendSmsWorker::class.java)
79+
.setConstraints(constraints)
7580
.setInputData(inputData)
7681
.addTag(messageID)
7782
.build()

android/app/src/main/java/com/httpsms/HttpSmsApiService.kt

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import okhttp3.RequestBody.Companion.toRequestBody
88
import org.apache.commons.text.StringEscapeUtils
99
import timber.log.Timber
1010
import java.net.URI
11+
import java.net.URL
1112
import java.time.ZonedDateTime
1213
import java.time.format.DateTimeFormatter
1314
import java.util.logging.Level
@@ -35,7 +36,7 @@ class HttpSmsApiService(private val apiKey: String, private val baseURL: URI) {
3536

3637
fun getOutstandingMessage(messageID: String): Message? {
3738
val request: Request = Request.Builder()
38-
.url(baseURL.resolve("/v1/messages/outstanding?message_id=${messageID}").toURL())
39+
.url(resolveURL("/v1/messages/outstanding?message_id=${messageID}"))
3940
.header(apiKeyHeader, apiKey)
4041
.header(clientVersionHeader, BuildConfig.VERSION_NAME)
4142
.build()
@@ -85,7 +86,7 @@ class HttpSmsApiService(private val apiKey: String, private val baseURL: URI) {
8586
""".trimIndent()
8687

8788
val request: Request = Request.Builder()
88-
.url(baseURL.resolve("/v1/messages/receive").toURL())
89+
.url(resolveURL("/v1/messages/receive"))
8990
.post(body.toRequestBody(jsonMediaType))
9091
.header(apiKeyHeader, apiKey)
9192
.header(clientVersionHeader, BuildConfig.VERSION_NAME)
@@ -111,7 +112,7 @@ class HttpSmsApiService(private val apiKey: String, private val baseURL: URI) {
111112
""".trimIndent()
112113

113114
val request: Request = Request.Builder()
114-
.url(baseURL.resolve("/v1/heartbeats").toURL())
115+
.url(resolveURL("/v1/heartbeats"))
115116
.post(body.toRequestBody(jsonMediaType))
116117
.header(apiKeyHeader, apiKey)
117118
.header(clientVersionHeader, BuildConfig.VERSION_NAME)
@@ -147,7 +148,7 @@ class HttpSmsApiService(private val apiKey: String, private val baseURL: URI) {
147148
""".trimIndent()
148149

149150
val request: Request = Request.Builder()
150-
.url(baseURL.resolve("/v1/messages/${messageId}/events").toURL())
151+
.url(resolveURL("/v1/messages/${messageId}/events"))
151152
.post(body.toRequestBody(jsonMediaType))
152153
.header(apiKeyHeader, apiKey)
153154
.header(clientVersionHeader, BuildConfig.VERSION_NAME)
@@ -175,7 +176,7 @@ class HttpSmsApiService(private val apiKey: String, private val baseURL: URI) {
175176
""".trimIndent()
176177

177178
val request: Request = Request.Builder()
178-
.url(baseURL.resolve("/v1/phones").toURL())
179+
.url(resolveURL("/v1/phones"))
179180
.put(body.toRequestBody(jsonMediaType))
180181
.header(apiKeyHeader, apiKey)
181182
.header(clientVersionHeader, BuildConfig.VERSION_NAME)
@@ -197,7 +198,7 @@ class HttpSmsApiService(private val apiKey: String, private val baseURL: URI) {
197198

198199
fun validateApiKey(): Pair<String?, String?> {
199200
val request: Request = Request.Builder()
200-
.url(baseURL.resolve("/v1/users/me").toURL())
201+
.url(resolveURL("/v1/users/me"))
201202
.header(apiKeyHeader, apiKey)
202203
.header(clientVersionHeader, BuildConfig.VERSION_NAME)
203204
.get()
@@ -218,4 +219,8 @@ class HttpSmsApiService(private val apiKey: String, private val baseURL: URI) {
218219
return Pair(null, ex.message)
219220
}
220221
}
222+
223+
private fun resolveURL(path: String): URL {
224+
return baseURL.resolve(baseURL.path + path).toURL()
225+
}
221226
}

android/app/src/main/java/com/httpsms/LogzTree.kt

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,10 @@ import timber.log.Timber
1212
import java.time.ZoneOffset
1313
import java.time.ZonedDateTime
1414
import java.time.format.DateTimeFormatter
15-
import java.util.concurrent.ConcurrentLinkedQueue
15+
import io.sentry.Sentry
1616

1717
class LogzTree(val context: Context): Timber.DebugTree() {
1818
private val client = OkHttpClient()
19-
private val jsonMediaType = "application/json; charset=utf-8".toMediaType()
20-
private val queue: ConcurrentLinkedQueue<LogEntry> = ConcurrentLinkedQueue<LogEntry>()
2119

2220
override fun log(priority: Int, tag: String?, message: String, t: Throwable?) {
2321
val formatter: DateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'")
@@ -36,17 +34,8 @@ class LogzTree(val context: Context): Timber.DebugTree() {
3634
Settings.getUserID(context),
3735
t
3836
)
39-
queue.add(logEntry)
40-
if (queue.size < 100) {
41-
return
42-
}
43-
44-
val logEntries = queue.toArray()
45-
queue.clear()
46-
47-
val body = logEntries.joinToString(separator = "\n") { x -> Klaxon().toJsonString(x) }
48-
.toRequestBody("application/x-www-form-urlencoded".toMediaType())
4937

38+
val body = Klaxon().toJsonString(logEntry).toRequestBody("application/x-www-form-urlencoded".toMediaType())
5039
val request: Request = Request.Builder()
5140
.url("https://listener.logz.io:8071?token=cTCUVJoTDrPjaFcanAPRzIsYyThyrIDw&type=http-bulk")
5241
.post(body)
@@ -58,6 +47,7 @@ class LogzTree(val context: Context): Timber.DebugTree() {
5847
val response = client.newCall(request).execute()
5948
response.body?.close()
6049
} catch(ex: Exception) {
50+
Sentry.captureException(ex)
6151
}
6252
}.start()
6353
}

api/cmd/experiments/main.go

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,6 @@ import (
66
"log"
77
"os"
88
"sync"
9-
"time"
10-
11-
"github.com/NdoleStudio/httpsms/pkg/di"
12-
"github.com/NdoleStudio/httpsms/pkg/entities"
139

1410
"github.com/carlmjohnson/requests"
1511

@@ -22,22 +18,12 @@ func main() {
2218
log.Fatal("Error loading .env file")
2319
}
2420

25-
container := di.NewLiteContainer()
26-
cache := container.RistrettoCache()
27-
logger := container.Logger()
28-
29-
for i := 0; i < 100; i++ {
30-
result := cache.SetWithTTL(fmt.Sprintf("how are you %d", i), entities.AuthUser{
31-
ID: "dasfdfds",
32-
33-
}, 1, 2*time.Hour)
34-
logger.Info(fmt.Sprintf("cached [%t]", result))
35-
}
21+
loadTest()
3622
}
3723

3824
func loadTest() {
3925
wg := sync.WaitGroup{}
40-
for i := 0; i < 5; i++ {
26+
for i := 0; i < 1; i++ {
4127
wg.Add(1)
4228
go func(count int) {
4329
sendSMS(count)

0 commit comments

Comments
 (0)