Skip to content

Conversation

@finecut82
Copy link

fix(wikimedia-producer): pin okhttp-eventsource to 2.5.0, correct headers() API, add UA

Root cause

  • Project initially used okhttp-eventsource 4.x where EventHandler was removed; IDE auto-imported java.beans.EventHandler, causing unresolved symbols.
  • After downgrades, the code still called header(name, value) which does not exist in 2.x; 2.x expects a single OkHttp Headers via .headers(Headers).
  • Wikimedia SSE returned HTTP 403 because the request lacked a meaningful User-Agent.

Fix

  • Pin dependency to com.launchdarkly:okhttp-eventsource:2.5.0.
  • Use the 2.x package com.launchdarkly.eventsource.* (not java.beans.*, not the 3.x ...okhttp... package).
  • Build okhttp3.Headers and pass with .headers(headers) on EventSource.Builder.
  • Add a proper User-Agent header to avoid 403.
  • Minor: set .reconnectTime(Duration.ofSeconds(3)) and keep Kafka client at 3.7.0.

Testing

  • ./gradlew clean run streams events and forwards to Kafka topic wikimedia.recentchange.
  • curl -i -H "User-Agent: user-wiki-stream/1.0 (user@example.com)" \ https://stream.wikimedia.org/v2/stream/recentchange returns 200 and events.

fix(wikimedia-producer): pin okhttp-eventsource to 2.5.0, correct headers() API, add UA

**Root cause**
- Project initially used okhttp-eventsource 4.x where `EventHandler` was removed; IDE
  auto-imported `java.beans.EventHandler`, causing unresolved symbols.
- After downgrades, the code still called `header(name, value)` which does not exist in 2.x;
  2.x expects a single OkHttp `Headers` via `.headers(Headers)`.
- Wikimedia SSE returned HTTP 403 because the request lacked a meaningful `User-Agent`.

**Fix**
- Pin dependency to `com.launchdarkly:okhttp-eventsource:2.5.0`.
- Use the 2.x package `com.launchdarkly.eventsource.*` (not `java.beans.*`, not the 3.x `...okhttp...` package).
- Build `okhttp3.Headers` and pass with `.headers(headers)` on `EventSource.Builder`.
- Add a proper `User-Agent` header to avoid 403.
- Minor: set `.reconnectTime(Duration.ofSeconds(3))` and keep Kafka client at 3.7.0.

**Testing**
- `./gradlew clean run` streams events and forwards to Kafka topic `wikimedia.recentchange`.
- `curl -i -H "User-Agent: user-wiki-stream/1.0 (user@example.com)" \
  https://stream.wikimedia.org/v2/stream/recentchange` returns `200` and events.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant