Revision | 191c26cf7525b900b95cbfa175f986c0a7293e10 (tree) |
---|---|
Time | 2019-01-18 05:19:37 |
Author | sebastian_bugiu <sebastian_ <bugiu@head...> |
Commiter | sebastian_bugiu <sebastian_ |
Adding lobby support.
@@ -33,6 +33,8 @@ | ||
33 | 33 | c.add(FriendDataListBodyHandler.class); |
34 | 34 | c.add(LobbyBodyHandler.class); |
35 | 35 | c.add(LobbyListBodyHandler.class); |
36 | + c.add(LobbyInvitationBodyHandler.class); | |
37 | + c.add(LobbyInvitationListBodyHandler.class); | |
36 | 38 | classes = Collections.unmodifiableSet(c); |
37 | 39 | |
38 | 40 |
@@ -0,0 +1,49 @@ | ||
1 | +package Blackhole_Darksun_WebServer.Tables.MessageBodyHandlers; | |
2 | + | |
3 | +import Blackhole_Darksun_WebServer.Tables.Lobby; | |
4 | +import Blackhole_Darksun_WebServer.Tables.LobbyInvitation; | |
5 | + | |
6 | +import javax.ws.rs.Consumes; | |
7 | +import javax.ws.rs.Produces; | |
8 | +import javax.ws.rs.WebApplicationException; | |
9 | +import javax.ws.rs.core.MediaType; | |
10 | +import javax.ws.rs.core.MultivaluedMap; | |
11 | +import javax.ws.rs.ext.MessageBodyReader; | |
12 | +import javax.ws.rs.ext.MessageBodyWriter; | |
13 | +import javax.ws.rs.ext.Provider; | |
14 | +import java.io.IOException; | |
15 | +import java.io.InputStream; | |
16 | +import java.io.OutputStream; | |
17 | +import java.lang.annotation.Annotation; | |
18 | +import java.lang.reflect.Type; | |
19 | + | |
20 | +@Provider | |
21 | +@Produces("application/json") | |
22 | +@Consumes("application/json") | |
23 | +public class LobbyInvitationBodyHandler extends BodyHandler implements MessageBodyWriter<LobbyInvitation>, MessageBodyReader<LobbyInvitation> { | |
24 | + | |
25 | + @Override | |
26 | + public boolean isWriteable(Class<?> aClass, Type type, Annotation[] annotations, MediaType mediaType) { | |
27 | + return LobbyInvitation.class.isAssignableFrom(aClass); | |
28 | + } | |
29 | + | |
30 | + @Override | |
31 | + public long getSize(LobbyInvitation user, Class<?> aClass, Type type, Annotation[] annotations, MediaType mediaType) { | |
32 | + return -1; | |
33 | + } | |
34 | + | |
35 | + @Override | |
36 | + public void writeTo(LobbyInvitation user, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> multivaluedMap, OutputStream outputStream) throws IOException, WebApplicationException { | |
37 | + writeGson(user, type, genericType, outputStream); | |
38 | + } | |
39 | + | |
40 | + @Override | |
41 | + public boolean isReadable(Class<?> aClass, Type type, Annotation[] annotations, MediaType mediaType) { | |
42 | + return LobbyInvitation.class.isAssignableFrom(aClass); | |
43 | + } | |
44 | + | |
45 | + @Override | |
46 | + public LobbyInvitation readFrom(Class<LobbyInvitation> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> multivaluedMap, InputStream inputStream) throws IOException, WebApplicationException { | |
47 | + return (LobbyInvitation) readGson(type, genericType, inputStream); | |
48 | + } | |
49 | +} |
@@ -0,0 +1,49 @@ | ||
1 | +package Blackhole_Darksun_WebServer.Tables.MessageBodyHandlers; | |
2 | + | |
3 | +import Blackhole_Darksun_WebServer.Tables.LobbyInvitation; | |
4 | +import Blackhole_Darksun_WebServer.Tables.LobbyInvitationList; | |
5 | + | |
6 | +import javax.ws.rs.Consumes; | |
7 | +import javax.ws.rs.Produces; | |
8 | +import javax.ws.rs.WebApplicationException; | |
9 | +import javax.ws.rs.core.MediaType; | |
10 | +import javax.ws.rs.core.MultivaluedMap; | |
11 | +import javax.ws.rs.ext.MessageBodyReader; | |
12 | +import javax.ws.rs.ext.MessageBodyWriter; | |
13 | +import javax.ws.rs.ext.Provider; | |
14 | +import java.io.IOException; | |
15 | +import java.io.InputStream; | |
16 | +import java.io.OutputStream; | |
17 | +import java.lang.annotation.Annotation; | |
18 | +import java.lang.reflect.Type; | |
19 | + | |
20 | +@Provider | |
21 | +@Produces("application/json") | |
22 | +@Consumes("application/json") | |
23 | +public class LobbyInvitationListBodyHandler extends BodyHandler implements MessageBodyWriter<LobbyInvitationList>, MessageBodyReader<LobbyInvitationList> { | |
24 | + | |
25 | + @Override | |
26 | + public boolean isWriteable(Class<?> aClass, Type type, Annotation[] annotations, MediaType mediaType) { | |
27 | + return LobbyInvitationList.class.isAssignableFrom(aClass); | |
28 | + } | |
29 | + | |
30 | + @Override | |
31 | + public long getSize(LobbyInvitationList user, Class<?> aClass, Type type, Annotation[] annotations, MediaType mediaType) { | |
32 | + return -1; | |
33 | + } | |
34 | + | |
35 | + @Override | |
36 | + public void writeTo(LobbyInvitationList user, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> multivaluedMap, OutputStream outputStream) throws IOException, WebApplicationException { | |
37 | + writeGson(user, type, genericType, outputStream); | |
38 | + } | |
39 | + | |
40 | + @Override | |
41 | + public boolean isReadable(Class<?> aClass, Type type, Annotation[] annotations, MediaType mediaType) { | |
42 | + return LobbyInvitationList.class.isAssignableFrom(aClass); | |
43 | + } | |
44 | + | |
45 | + @Override | |
46 | + public LobbyInvitationList readFrom(Class<LobbyInvitationList> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> multivaluedMap, InputStream inputStream) throws IOException, WebApplicationException { | |
47 | + return (LobbyInvitationList) readGson(type, genericType, inputStream); | |
48 | + } | |
49 | +} |
@@ -30,16 +30,16 @@ | ||
30 | 30 | client.register(MapBodyHandler.class); |
31 | 31 | client.register(MapListBodyHandler.class); |
32 | 32 | client.register(StringBodyHandler.class); |
33 | - client.register(UserBodyHandler.class); | |
34 | 33 | client.register(UserFriendBodyHandler.class); |
35 | 34 | client.register(UserFriendListBodyHandler.class); |
36 | 35 | client.register(UserFriendInvitationBodyHandler.class); |
37 | 36 | client.register(UserFriendInvitationListBodyHandler.class); |
38 | - client.register(SessionListBodyHandler.class); | |
39 | 37 | client.register(FriendDataBodyHandler.class); |
40 | 38 | client.register(FriendDataListBodyHandler.class); |
41 | 39 | client.register(LobbyBodyHandler.class); |
42 | 40 | client.register(LobbyListBodyHandler.class); |
41 | + client.register(LobbyInvitationBodyHandler.class); | |
42 | + client.register(LobbyInvitationListBodyHandler.class); | |
43 | 43 | } |
44 | 44 | |
45 | 45 | static void printLongerTrace(Throwable t) { |
@@ -112,6 +112,11 @@ | ||
112 | 112 | |
113 | 113 | final Lobby createdLobby = createLobbyArr[0].readEntity(Lobby.class); |
114 | 114 | |
115 | + final Response getLobbyStatus = client.target(URI).path("get_lobby_status").path(userResponse0.getAuthToken()) | |
116 | + .request().post(Entity.entity(createdLobby, MediaType.APPLICATION_JSON_TYPE)); | |
117 | + Assert.assertEquals(getLobbyStatus.getStatusInfo().getStatusCode(), Response.Status.OK.getStatusCode()); | |
118 | + final LobbyInvitationList lobbyInvitationList = getLobbyStatus.readEntity(LobbyInvitationList.class); | |
119 | + | |
115 | 120 | // Now the other user must check for lobby invitations and join the lobby. |
116 | 121 | final Response getLobbyInvitations = client.target(URI).path("get_lobby_invitations").path(userResponse1.getAuthToken()).request().get(); |
117 | 122 | Assert.assertEquals(getLobbyInvitations.getStatusInfo().getStatusCode(), Response.Status.OK.getStatusCode()); |