Skip to content
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -463,15 +463,20 @@ class PageConnectionHolderFragment : Fragment(), CoroutineScope {

subscribeJob = scope.launch {
try {
val response = client.post("/rest/sitemaps/events/subscribe",
"{}", "application/json").asText()
val result = JSONObject(response.response)
val status = result.getString("status")
if (status != "CREATED") {
throw JSONException("Unexpected status $status")
val response = client.post("/rest/sitemaps/events/subscribe", "{}", "application/json")
val url = if (response.statusCode == 201) {
// OH 4: event stream URL is part of response headers
response.headers.get("Location")?.toHttpUrlOrNull()
} else {
// OH 2/3: event stream URL is part of response JSON body
val result = JSONObject(response.asText().response)
val status = result.getString("status")
if (status != "CREATED") {
throw JSONException("Unexpected status $status")
}
val headerObject = result.getJSONObject("context").getJSONObject("headers")
headerObject.getJSONArray("Location").getString(0).toHttpUrlOrNull()
}
val headerObject = result.getJSONObject("context").getJSONObject("headers")
val url = headerObject.getJSONArray("Location").getString(0).toHttpUrlOrNull()
if (url != null) {
val u = url.newBuilder()
.addQueryParameter("sitemap", sitemap)
Expand Down