use of javax.websocket.Session in project javaee7-samples by javaee-samples.
the class MyEndpointTest method testEndpointByteArray.
/**
* The basic test method for the class {
*
* @MyEndpointByteArray }
*
* @throws DeploymentException
* @throws IOException
* @throws URISyntaxException
*/
@Test
public void testEndpointByteArray() throws DeploymentException, IOException, URISyntaxException, InterruptedException {
MyEndpointClient.latch = new CountDownLatch(1);
Session session = connectToServer("bytearray");
assertNotNull(session);
assertTrue(MyEndpointClient.latch.await(2, TimeUnit.SECONDS));
assertNotNull(MyEndpointClient.response);
assertArrayEquals(RESPONSE.getBytes(), MyEndpointClient.response);
}
use of javax.websocket.Session in project javaee7-samples by javaee-samples.
the class MyClientTest method testEndpoint.
@Test
public void testEndpoint() throws URISyntaxException, DeploymentException, IOException, InterruptedException {
String JSON = "{\"apple\":\"red\",\"banana\":\"yellow\"}";
Session session = connectToServer(MyClient.class);
assertNotNull(session);
assertTrue(MyClient.latch.await(2, TimeUnit.SECONDS));
assertEquals(JSON, MyClient.response.toString());
}
use of javax.websocket.Session in project javaee7-samples by javaee-samples.
the class EncoderEndpointTest method testEndpointEmptyJSONObject.
@Test
public void testEndpointEmptyJSONObject() throws URISyntaxException, DeploymentException, IOException, InterruptedException {
String JSON = "{\"apple\":\"red\",\"banana\":\"yellow\"}";
Session session = connectToServer(MyEndpointClientJSONObject.class);
assertNotNull(session);
assertTrue(MyEndpointClientJSONObject.latch.await(2, TimeUnit.SECONDS));
assertEquals(JSON, MyEndpointClientJSONObject.response);
}
use of javax.websocket.Session in project javaee7-samples by javaee-samples.
the class EncoderEndpointTest method testEndpointEmptyJSONArray.
@Test
public void testEndpointEmptyJSONArray() throws URISyntaxException, DeploymentException, IOException, InterruptedException {
final Session session = connectToServer(MyEndpointClientEmptyJSONArray.class);
assertNotNull(session);
assertTrue(MyEndpointClientEmptyJSONArray.latch.await(2, TimeUnit.SECONDS));
assertEquals("{}", MyEndpointClientEmptyJSONArray.response);
}
use of javax.websocket.Session in project pinot by linkedin.
the class MeetupRsvpStream method run.
public void run() {
try {
final ClientEndpointConfig cec = ClientEndpointConfig.Builder.create().build();
final KafkaJSONMessageDecoder decoder = new KafkaJSONMessageDecoder();
decoder.init(null, schema, null);
client = ClientManager.createClient();
client.connectToServer(new Endpoint() {
@Override
public void onOpen(Session session, EndpointConfig config) {
try {
session.addMessageHandler(new MessageHandler.Whole<String>() {
@Override
public void onMessage(String message) {
try {
JSONObject messageJSON = new JSONObject(message);
JSONObject extracted = new JSONObject();
if (messageJSON.has("venue")) {
JSONObject venue = messageJSON.getJSONObject("venue");
extracted.put("venue_name", venue.getString("venue_name"));
}
if (messageJSON.has("event")) {
JSONObject event = messageJSON.getJSONObject("event");
extracted.put("event_name", event.getString("event_name"));
extracted.put("event_id", event.getString("event_id"));
extracted.put("event_time", event.getLong("time"));
}
if (messageJSON.has("group")) {
JSONObject group = messageJSON.getJSONObject("group");
extracted.put("group_city", group.getString("group_city"));
extracted.put("group_country", group.getString("group_country"));
extracted.put("group_id", group.getLong("group_id"));
extracted.put("group_name", group.getString("group_name"));
}
extracted.put("mtime", messageJSON.getLong("mtime"));
extracted.put("rsvp_count", 1);
if (keepPublishing) {
KeyedMessage<String, byte[]> data = new KeyedMessage<String, byte[]>("meetupRSVPEvents", extracted.toString().getBytes("UTF-8"));
producer.send(data);
}
} catch (Exception e) {
//LOGGER.error("error processing raw event ", e);
}
}
});
session.getBasicRemote().sendText("");
} catch (IOException e) {
//LOGGER.error("found an event where data did not have all the fields, don't care about for quickstart");
}
}
}, cec, new URI("ws://stream.meetup.com/2/rsvps"));
} catch (Exception e) {
//e.printStackTrace();
}
}
Aggregations