FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Fixes COMETD-415 (Upgrade CometD to support Jackson 2). · JavaInCloud/cometd@a34d6e8 · GitHub

forked from cometd/cometd

Commit a34d6e8

Browse files
committed
Fixes COMETD-415 (Upgrade CometD to support Jackson 2).
Merged branch 'mrossi975_jackson2', from https://github.com/mrossi975/cometd/tree/branch1. See cometd#16.
2 parents ae345e4 + bac9b70 commit a34d6e8

19 files changed

Lines changed: 843 additions & 235 deletions

File tree

‎cometd-java/cometd-java-benchmark/cometd-java-benchmark-client/pom.xml‎

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,11 @@
2121
<executable>java</executable>
2222
<arguments>
2323
<argument>-showversion</argument>
24-
<argument>-Xmx2g</argument>
25-
<argument>-Xms2g</argument>
24+
<argument>-Xmx1g</argument>
25+
<argument>-Xms1g</argument>
26+
<!--
2627
<argument>-Xmn1g</argument>
28+
-->
2729
<argument>-XX:+PrintCommandLineFlags</argument>
2830
<argument>-XX:-UseSplitVerifier</argument>
2931
<argument>-XX:+PrintGCDateStamps</argument>
@@ -75,11 +77,7 @@
7577
<artifactId>jetty-jmx</artifactId>
7678
<version>${jetty-version}</version>
7779
</dependency>
78-
<dependency>
79-
<groupId>org.codehaus.jackson</groupId>
80-
<artifactId>jackson-mapper-asl</artifactId>
81-
<version>${jackson-version}</version>
82-
</dependency>
80+
8381
<dependency>
8482
<groupId>org.slf4j</groupId>
8583
<artifactId>slf4j-log4j12</artifactId>

‎cometd-java/cometd-java-benchmark/cometd-java-benchmark-client/src/main/java/org/cometd/benchmark/client/BayeuxLoadClient.java‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
import org.cometd.client.BayeuxClient;
5050
import org.cometd.client.transport.ClientTransport;
5151
import org.cometd.client.transport.LongPollingTransport;
52-
import org.cometd.common.JacksonJSONContextClient;
52+
import org.cometd.common.Jackson1JSONContextClient;
5353
import org.cometd.websocket.client.WebSocketTransport;
5454
import org.eclipse.jetty.client.HttpClient;
5555
import org.eclipse.jetty.jmx.MBeanContainer;
@@ -430,13 +430,13 @@ private ClientTransport newClientTransport(ClientTransportType clientTransportTy
430430
case LONG_POLLING:
431431
{
432432
Map<String, Object> options = new HashMap<>();
433-
options.put(ClientTransport.JSON_CONTEXT, new JacksonJSONContextClient());
433+
options.put(ClientTransport.JSON_CONTEXT, new Jackson1JSONContextClient());
434434
return new LongPollingTransport(options, httpClient);
435435
}
436436
case WEBSOCKET:
437437
{
438438
Map<String, Object> options = new HashMap<>();
439-
options.put(ClientTransport.JSON_CONTEXT, new JacksonJSONContextClient());
439+
options.put(ClientTransport.JSON_CONTEXT, new Jackson1JSONContextClient());
440440
options.put(WebSocketTransport.IDLE_TIMEOUT_OPTION, 35000);
441441
return new WebSocketTransport(options, webSocketClient, scheduler);
442442
}

‎cometd-java/cometd-java-benchmark/cometd-java-benchmark-server/pom.xml‎

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,16 +78,35 @@
7878
<artifactId>websocket-server</artifactId>
7979
<version>${jetty-version}</version>
8080
</dependency>
81-
<dependency>
81+
<dependency>
82+
<groupId>com.fasterxml.jackson.core</groupId>
83+
<artifactId>jackson-databind</artifactId>
84+
<version>${jackson2-version}</version>
85+
</dependency>
86+
87+
<dependency>
88+
<groupId>com.fasterxml.jackson.core</groupId>
89+
<artifactId>jackson-core</artifactId>
90+
<version>${jackson2-version}</version>
91+
</dependency>
92+
93+
<dependency>
8294
<groupId>org.codehaus.jackson</groupId>
8395
<artifactId>jackson-mapper-asl</artifactId>
84-
<version>${jackson-version}</version>
96+
<version>${jackson1-version}</version>
97+
</dependency>
98+
99+
<dependency>
100+
<groupId>org.slf4j</groupId>
101+
<artifactId>slf4j-simple</artifactId>
102+
<!-- Travis build failing if I use ${slf4j-version}, trying hard-coding version -->
103+
<version>1.7.5</version>
104+
<scope>runtime</scope>
85105
</dependency>
86106
<dependency>
87107
<groupId>org.slf4j</groupId>
88108
<artifactId>slf4j-log4j12</artifactId>
89109
<scope>runtime</scope>
90110
</dependency>
91111
</dependencies>
92-
93112
</project>

‎cometd-java/cometd-java-benchmark/cometd-java-benchmark-server/src/main/java/org/cometd/benchmark/server/BayeuxLoadServer.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
import org.cometd.server.AbstractService;
5555
import org.cometd.server.BayeuxServerImpl;
5656
import org.cometd.server.CometDServlet;
57-
import org.cometd.server.JacksonJSONContextServer;
57+
import org.cometd.server.Jackson2JSONContextServer;
5858
import org.cometd.websocket.server.WebSocketTransport;
5959
import org.eclipse.jetty.jmx.MBeanContainer;
6060
import org.eclipse.jetty.server.AbstractConnectionFactory;
@@ -206,7 +206,7 @@ public void run() throws Exception
206206
// Explicitly set the timeout value
207207
cometdServletHolder.setInitParameter(AbstractServerTransport.TIMEOUT_OPTION, String.valueOf(30000));
208208
// Use the faster JSON parser/generator
209-
cometdServletHolder.setInitParameter(BayeuxServerImpl.JSON_CONTEXT, JacksonJSONContextServer.class.getName());
209+
cometdServletHolder.setInitParameter(BayeuxServerImpl.JSON_CONTEXT, Jackson2JSONContextServer.class.getName());
210210
context.addServlet(cometdServletHolder, cometServletPath + "/*");
211211

212212
server.start();

‎cometd-java/cometd-java-client/pom.xml‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,13 +90,18 @@
9090
<version>${jetty-version}</version>
9191
<scope>test</scope>
9292
</dependency>
93-
<dependency>
93+
<dependency>
94+
<groupId>com.fasterxml.jackson.core</groupId>
95+
<artifactId>jackson-databind</artifactId>
96+
<version>${jackson2-version}</version>
97+
<scope>test</scope>
98+
</dependency>
99+
<dependency>
94100
<groupId>org.codehaus.jackson</groupId>
95101
<artifactId>jackson-mapper-asl</artifactId>
96-
<version>${jackson-version}</version>
102+
<version>${jackson1-version}</version>
97103
<scope>test</scope>
98104
</dependency>
99-
100105
</dependencies>
101106

102107
</project>

‎cometd-java/cometd-java-client/src/main/java/org/cometd/client/transport/ClientTransport.java‎

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,44 @@ protected ClientTransport(String name, Map<String, Object> options)
4545
super(name, options);
4646
}
4747

48-
public void init()
49-
{
50-
jsonContext = (JSONContext.Client)getOption(JSON_CONTEXT);
51-
if (jsonContext == null)
52-
jsonContext = new JettyJSONContextClient();
53-
}
48+
public void init()
49+
{
50+
Object option = null;
51+
try
52+
{
53+
option = getOption(JSON_CONTEXT);
54+
if (option == null)
55+
{
56+
jsonContext = new JettyJSONContextClient();
57+
}
58+
else
59+
{
60+
if (option instanceof String)
61+
{
62+
Class<?> jsonContextClass = Thread.currentThread().getContextClassLoader().loadClass((String) option);
63+
if (JSONContext.Client.class.isAssignableFrom(jsonContextClass))
64+
{
65+
jsonContext = (JSONContext.Client) jsonContextClass.newInstance();
66+
}
67+
else
68+
{
69+
throw new IllegalArgumentException("Invalid implementation of " + JSONContext.Client.class.getName() + " provided (" + option + ")");
70+
}
71+
}
72+
else if (option instanceof JSONContext.Client)
73+
{
74+
jsonContext = (JSONContext.Client) option;
75+
}
76+
else
77+
{
78+
throw new IllegalArgumentException("Invalid implementation of " + JSONContext.Client.class.getName() + " provided (" + option + ")");
79+
}
80+
}
81+
setOption(JSON_CONTEXT, jsonContext);
82+
} catch (Exception ex) {
83+
throw new IllegalArgumentException("Exception ["+ex+"] while trying to initialise "+this+" with JSON Context "+option, ex);
84+
}
85+
}
5486

5587
public boolean isDebugEnabled()
5688
{

‎cometd-java/cometd-java-client/src/test/java/org/cometd/client/BayeuxClientUsageTest.java‎

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package org.cometd.client;
1818

19+
import java.util.Arrays;
1920
import java.util.HashMap;
2021
import java.util.Map;
2122
import java.util.concurrent.TimeUnit;
@@ -26,15 +27,44 @@
2627
import org.cometd.bayeux.client.ClientSessionChannel;
2728
import org.cometd.client.transport.ClientTransport;
2829
import org.cometd.client.transport.LongPollingTransport;
29-
import org.cometd.common.JacksonJSONContextClient;
30+
import org.cometd.common.Jackson1JSONContextClient;
31+
import org.cometd.common.Jackson2JSONContextClient;
32+
import org.cometd.common.JettyJSONContextClient;
3033
import org.cometd.server.BayeuxServerImpl;
31-
import org.cometd.server.JacksonJSONContextServer;
34+
import org.cometd.server.Jackson1JSONContextServer;
35+
import org.cometd.server.Jackson2JSONContextServer;
36+
import org.cometd.server.JettyJSONContextServer;
3237
import org.eclipse.jetty.util.BlockingArrayQueue;
3338
import org.junit.Assert;
3439
import org.junit.Test;
40+
import org.junit.runner.RunWith;
41+
import org.junit.runners.Parameterized;
42+
import org.junit.runners.Parameterized.Parameters;
3543

44+
@RunWith(Parameterized.class)
3645
public class BayeuxClientUsageTest extends ClientServerTest
3746
{
47+
@Parameters(name= "{index}: JSON Context Server: {0} JSON Context Client: {1}")
48+
public static Iterable<Object[]> data()
49+
{
50+
return Arrays.asList(new Object[][]
51+
{
52+
{ Jackson2JSONContextServer.class, Jackson2JSONContextClient.class },
53+
{ Jackson1JSONContextServer.class, Jackson1JSONContextClient.class },
54+
{ JettyJSONContextServer.class, JettyJSONContextClient.class}
55+
}
56+
);
57+
}
58+
59+
private final String jacksonContextServerClassName;
60+
private final String jacksonContextClientClassName;
61+
62+
public BayeuxClientUsageTest(final Object jacksonContextServerClass, final Object jacksonContextClientClass)
63+
{
64+
this.jacksonContextServerClassName = ((Class<?>) jacksonContextServerClass).getName();
65+
this.jacksonContextClientClassName = ((Class<?>) jacksonContextClientClass).getName();
66+
}
67+
3868
@Test
3969
public void testClientWithSelectConnector() throws Exception
4070
{
@@ -46,11 +76,11 @@ public void testClientWithSelectConnector() throws Exception
4676
public void testClientWithJackson() throws Exception
4777
{
4878
Map<String, String> serverOptions = new HashMap<>();
49-
serverOptions.put(BayeuxServerImpl.JSON_CONTEXT, JacksonJSONContextServer.class.getName());
79+
serverOptions.put(BayeuxServerImpl.JSON_CONTEXT, jacksonContextServerClassName);
5080
startServer(serverOptions);
5181

5282
Map<String, Object> clientOptions = new HashMap<>();
53-
clientOptions.put(ClientTransport.JSON_CONTEXT, new JacksonJSONContextClient());
83+
clientOptions.put(ClientTransport.JSON_CONTEXT, jacksonContextClientClassName);
5484
BayeuxClient client = new BayeuxClient(cometdURL, new LongPollingTransport(clientOptions, httpClient));
5585

5686
testClient(client);

‎cometd-java/cometd-java-client/src/test/java/org/cometd/client/JacksonContextTest.java‎

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package org.cometd.client;
1818

1919
import java.lang.reflect.Field;
20+
import java.util.Arrays;
2021
import java.util.HashMap;
2122
import java.util.Map;
2223
import java.util.concurrent.CountDownLatch;
@@ -29,25 +30,51 @@
2930
import org.cometd.client.transport.ClientTransport;
3031
import org.cometd.client.transport.LongPollingTransport;
3132
import org.cometd.common.HashMapMessage;
32-
import org.cometd.common.JacksonJSONContextClient;
33+
import org.cometd.common.Jackson1JSONContextClient;
34+
import org.cometd.common.Jackson2JSONContextClient;
3335
import org.cometd.server.AbstractService;
3436
import org.cometd.server.BayeuxServerImpl;
35-
import org.cometd.server.JacksonJSONContextServer;
37+
import org.cometd.server.Jackson1JSONContextServer;
38+
import org.cometd.server.Jackson2JSONContextServer;
3639
import org.cometd.server.ServerMessageImpl;
3740
import org.junit.Assert;
3841
import org.junit.Test;
42+
import org.junit.runner.RunWith;
43+
import org.junit.runners.Parameterized;
44+
import org.junit.runners.Parameterized.Parameters;
3945

46+
@RunWith(Parameterized.class)
4047
public class JacksonContextTest extends ClientServerTest
4148
{
49+
@Parameters(name= "{index}: Jackson Context Server: {0} Jackson Context Client: {1}")
50+
public static Iterable<Object[]> data()
51+
{
52+
return Arrays.asList(new Object[][]
53+
{
54+
{ Jackson2JSONContextServer.class, Jackson2JSONContextClient.class },
55+
{ Jackson1JSONContextServer.class, Jackson1JSONContextClient.class },
56+
}
57+
);
58+
}
59+
60+
private final String jacksonContextServerClassName;
61+
private final String jacksonContextClientClassName;
62+
63+
public JacksonContextTest(final Object jacksonContextServerClass, final Object jacksonContextClientClass)
64+
{
65+
this.jacksonContextServerClassName = ((Class<?>) jacksonContextServerClass).getName();
66+
this.jacksonContextClientClassName = ((Class<?>) jacksonContextClientClass).getName();
67+
}
68+
4269
@Test
4370
public void testAllMessagesUseJackson() throws Exception
4471
{
4572
Map<String, String> serverParams = new HashMap<>();
46-
serverParams.put(BayeuxServerImpl.JSON_CONTEXT, JacksonJSONContextServer.class.getName());
73+
serverParams.put(BayeuxServerImpl.JSON_CONTEXT, jacksonContextServerClassName);
4774
startServer(serverParams);
4875

4976
Map<String, Object> clientParams = new HashMap<>();
50-
clientParams.put(ClientTransport.JSON_CONTEXT, new JacksonJSONContextClient());
77+
clientParams.put(ClientTransport.JSON_CONTEXT, jacksonContextClientClassName);
5178
final BayeuxClient client = new BayeuxClient(cometdURL, new LongPollingTransport(clientParams, httpClient));
5279
client.setDebugEnabled(debugTests());
5380

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL