Skip to content

Commit bebf6be

Browse files
committed
Add 1st draft of Java ServerEventsClient
1 parent e37e9f9 commit bebf6be

16 files changed

+913
-2
lines changed

src/AndroidClient/client/src/main/java/net/servicestack/client/JsonServiceClient.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,19 @@ public class JsonServiceClient implements ServiceClient {
4646
Gson gson;
4747

4848
public JsonServiceClient(String baseUrl) {
49-
this.baseUrl = baseUrl.endsWith("/") ? baseUrl : baseUrl + "/";
50-
this.replyUrl = this.baseUrl + "json/reply/";
49+
setBaseUrl(baseUrl);
5150

5251
//Automatically populate response cookies
5352
if (CookieHandler.getDefault() == null){
5453
CookieHandler.setDefault(new CookieManager());
5554
}
5655
}
5756

57+
public void setBaseUrl(String baseUrl) {
58+
this.baseUrl = baseUrl.endsWith("/") ? baseUrl : baseUrl + "/";
59+
this.replyUrl = this.baseUrl + "json/reply/";
60+
}
61+
5862
public void setTimeout(int timeoutMs) {
5963
this.timeoutMs = timeoutMs;
6064
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package net.servicestack.client.sse;
2+
3+
/**
4+
* Created by mythz on 2/10/2017.
5+
*/
6+
7+
public interface ExceptionCallback {
8+
void execute(Exception ex);
9+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package net.servicestack.client.sse;
2+
3+
import java.net.HttpURLConnection;
4+
5+
/**
6+
* Created by mythz on 2/10/2017.
7+
*/
8+
9+
public interface HttpRequestFilter {
10+
void execute(HttpURLConnection req);
11+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package net.servicestack.client.sse;
2+
3+
import java.net.HttpURLConnection;
4+
5+
/**
6+
* Created by mythz on 2/10/2017.
7+
*/
8+
9+
public interface HttpResponseFilter {
10+
void execute(HttpURLConnection req);
11+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package net.servicestack.client.sse;
2+
3+
/**
4+
* Created by mythz on 2/10/2017.
5+
*/
6+
7+
public interface ServerEventCallback {
8+
void execute(ServerEventsClient client, ServerEventMessage e);
9+
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
package net.servicestack.client.sse;
2+
3+
import com.google.gson.JsonObject;
4+
5+
import net.servicestack.client.JsonUtils;
6+
import net.servicestack.client.Utils;
7+
8+
/**
9+
* Created by mythz on 2/10/2017.
10+
*/
11+
12+
public class ServerEventCommand extends ServerEventMessage {
13+
private String userId;
14+
private String displayName;
15+
private String profileUrl;
16+
private boolean isAuthenticated;
17+
private String[] channels;
18+
19+
public String getUserId() {
20+
return userId;
21+
}
22+
23+
public void setUserId(String userId) {
24+
this.userId = userId;
25+
}
26+
27+
public String getDisplayName() {
28+
return displayName;
29+
}
30+
31+
public void setDisplayName(String displayName) {
32+
this.displayName = displayName;
33+
}
34+
35+
public String getProfileUrl() {
36+
return profileUrl;
37+
}
38+
39+
public void setProfileUrl(String profileUrl) {
40+
this.profileUrl = profileUrl;
41+
}
42+
43+
public boolean isAuthenticated() {
44+
return isAuthenticated;
45+
}
46+
47+
public void setAuthenticated(boolean authenticated) {
48+
isAuthenticated = authenticated;
49+
}
50+
51+
public String[] getChannels() {
52+
return channels;
53+
}
54+
55+
public void setChannels(String[] channels) {
56+
this.channels = channels;
57+
}
58+
59+
@Override
60+
protected void populate(JsonObject obj) {
61+
super.populate(obj);
62+
63+
this.userId = JsonUtils.asString(obj, "userId");
64+
this.displayName = JsonUtils.asString(obj, "displayName");
65+
this.isAuthenticated = "true".equals(JsonUtils.asString(obj, "isAuthenticated"));
66+
this.profileUrl = JsonUtils.asString(obj, "profileUrl");
67+
68+
String channels = JsonUtils.asString(obj, "channels");
69+
if (!Utils.isNullOrEmpty(channels))
70+
this.channels = channels.split(",");
71+
}
72+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package net.servicestack.client.sse;
2+
3+
/**
4+
* Created by mythz on 2/10/2017.
5+
*/
6+
7+
public class ServerEventConnect extends ServerEventCommand {
8+
private String id;
9+
private String unRegisterUrl;
10+
private String heartbeatUrl;
11+
private long heartbeatIntervalMs;
12+
private long idleTimeoutMs;
13+
14+
public String getId() {
15+
return id;
16+
}
17+
18+
public void setId(String id) {
19+
this.id = id;
20+
}
21+
22+
public String getUnRegisterUrl() {
23+
return unRegisterUrl;
24+
}
25+
26+
public void setUnRegisterUrl(String unRegisterUrl) {
27+
this.unRegisterUrl = unRegisterUrl;
28+
}
29+
30+
public String getHeartbeatUrl() {
31+
return heartbeatUrl;
32+
}
33+
34+
public void setHeartbeatUrl(String heartbeatUrl) {
35+
this.heartbeatUrl = heartbeatUrl;
36+
}
37+
38+
public long getHeartbeatIntervalMs() {
39+
return heartbeatIntervalMs;
40+
}
41+
42+
public void setHeartbeatIntervalMs(long heartbeatIntervalMs) {
43+
this.heartbeatIntervalMs = heartbeatIntervalMs;
44+
}
45+
46+
public long getIdleTimeoutMs() {
47+
return idleTimeoutMs;
48+
}
49+
50+
public void setIdleTimeoutMs(long idleTimeoutMs) {
51+
this.idleTimeoutMs = idleTimeoutMs;
52+
}
53+
54+
@Override
55+
public String toString() {
56+
return "(" + this.getClass().getSimpleName() +
57+
"\n id: " + id +
58+
"\n unRegisterUrl: " + unRegisterUrl +
59+
"\n heartbeatUrl: " + heartbeatUrl +
60+
"\n heartbeatIntervalMs: " + heartbeatIntervalMs +
61+
"\n idleTimeoutMs: " + idleTimeoutMs + "\n)";
62+
}
63+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package net.servicestack.client.sse;
2+
3+
/**
4+
* Created by mythz on 2/10/2017.
5+
*/
6+
7+
public interface ServerEventConnectCallback {
8+
void execute(ServerEventConnect e);
9+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package net.servicestack.client.sse;
2+
3+
/**
4+
* Created by mythz on 2/10/2017.
5+
*/
6+
public class ServerEventHeartbeat extends ServerEventCommand {
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package net.servicestack.client.sse;
2+
3+
/**
4+
* Created by mythz on 2/10/2017.
5+
*/
6+
public class ServerEventJoin extends ServerEventCommand {
7+
}

0 commit comments

Comments
 (0)