List of usage examples for com.fasterxml.jackson.databind MappingJsonFactory MappingJsonFactory
public MappingJsonFactory(ObjectMapper paramObjectMapper)
From source file:ch.rasc.wampspring.demo.client.CallClient.java
public static void main(String[] args) throws InterruptedException { WebSocketClient webSocketClient = new StandardWebSocketClient(); JsonFactory jsonFactory = new MappingJsonFactory(new ObjectMapper()); CountDownLatch latch = new CountDownLatch(1_000_000); TestTextWebSocketHandler handler = new TestTextWebSocketHandler(jsonFactory, latch); Long[] start = new Long[1]; ListenableFuture<WebSocketSession> future = webSocketClient.doHandshake(handler, "ws://localhost:8080/wamp"); future.addCallback(wss -> {/* www . j av a2 s. c om*/ start[0] = System.currentTimeMillis(); for (int i = 0; i < 1_000_000; i++) { CallMessage callMessage = new CallMessage(UUID.randomUUID().toString(), "testService.sum", i, i + 1); try { wss.sendMessage(new TextMessage(callMessage.toJson(jsonFactory))); } catch (Exception e) { System.out.println("ERROR SENDING CALLMESSAGE" + e); latch.countDown(); } } }, t -> { System.out.println("DO HANDSHAKE ERROR: " + t); System.exit(1); }); if (!latch.await(3, TimeUnit.MINUTES)) { System.out.println("SOMETHING WENT WRONG"); } System.out.println((System.currentTimeMillis() - start[0]) / 1000 + " seconds"); System.out.println("SUCCESS: " + handler.getSuccess()); System.out.println("ERROR : " + handler.getError()); }
From source file:ch.rasc.wampspring.demo.client.Publisher.java
public static void main(String[] args) throws InterruptedException { WebSocketClient webSocketClient = new StandardWebSocketClient(); final JsonFactory jsonFactory = new MappingJsonFactory(new ObjectMapper()); final CountDownLatch welcomeLatch = new CountDownLatch(1); final CountDownLatch latch = new CountDownLatch(1_000_000); TextWebSocketHandler handler = new TextWebSocketHandler() { @Override/* ww w. j a v a2 s. c o m*/ protected void handleTextMessage(WebSocketSession session, TextMessage message) throws Exception { WampMessage wampMessage = WampMessage.fromJson(jsonFactory, message.getPayload()); if (wampMessage instanceof WelcomeMessage) { latch.countDown(); } } }; Long[] start = new Long[1]; ListenableFuture<WebSocketSession> future = webSocketClient.doHandshake(handler, "ws://localhost:8080/wamp"); future.addCallback(wss -> { // Waiting for WELCOME message try { welcomeLatch.await(5, TimeUnit.SECONDS); start[0] = System.currentTimeMillis(); for (int i = 0; i < 1_000_000; i++) { PublishMessage publishMessage = new PublishMessage("/test/myqueue", i); try { wss.sendMessage(new TextMessage(publishMessage.toJson(jsonFactory))); } catch (Exception e) { System.out.println("ERROR SENDING PUBLISH_MESSAGE" + e); } latch.countDown(); } } catch (Exception e1) { System.out.println("SENDING PUBLISH MESSAGES: " + e1); } }, t -> { System.out.println("DO HANDSHAKE ERROR: " + t); System.exit(1); }); if (!latch.await(3, TimeUnit.MINUTES)) { System.out.println("SOMETHING WENT WRONG"); } System.out.println((System.currentTimeMillis() - start[0]) / 1000 + " seconds"); }
From source file:ch.rasc.wampspring.demo.client.CallClientSockJs.java
public static void main(String[] args) throws InterruptedException { List<Transport> transports = new ArrayList<>(2); transports.add(new WebSocketTransport(new StandardWebSocketClient())); transports.add(new RestTemplateXhrTransport()); WebSocketClient webSocketClient = new SockJsClient(transports); JsonFactory jsonFactory = new MappingJsonFactory(new ObjectMapper()); CountDownLatch latch = new CountDownLatch(10_000); TestTextWebSocketHandler handler = new TestTextWebSocketHandler(jsonFactory, latch); Long[] start = new Long[1]; ListenableFuture<WebSocketSession> future = webSocketClient.doHandshake(handler, "ws://localhost:8080/wampOverSockJS"); future.addCallback(wss -> {//ww w . j av a 2s . com start[0] = System.currentTimeMillis(); for (int i = 0; i < 10_000; i++) { CallMessage callMessage = new CallMessage(UUID.randomUUID().toString(), "testService.sum", i, i + 1); try { wss.sendMessage(new TextMessage(callMessage.toJson(jsonFactory))); } catch (Exception e) { System.out.println("ERROR SENDING CALLMESSAGE" + e); latch.countDown(); } } }, t -> { System.out.println("DO HANDSHAKE ERROR: " + t); System.exit(1); }); if (!latch.await(3, TimeUnit.MINUTES)) { System.out.println("SOMETHING WENT WRONG"); } System.out.println((System.currentTimeMillis() - start[0]) / 1000 + " seconds"); System.out.println("SUCCESS: " + handler.getSuccess()); System.out.println("ERROR : " + handler.getError()); }
From source file:ch.rasc.wampspring.config.DefaultWampConfiguration.java
@Bean public HandlerMapping wampWebSocketHandlerMapping() { WebSocketHandler handler = subProtocolWebSocketHandler(); handler = decorateWebSocketHandler(handler); WebMvcWampEndpointRegistry registry = new WebMvcWampEndpointRegistry(handler, getTransportRegistration(), messageBrokerSockJsTaskScheduler(), new MappingJsonFactory(lookupObjectMapper())); List<HandshakeInterceptor> handshakeInterceptors = new ArrayList<>(); addHandshakeInterceptors(handshakeInterceptors); registry.addHandshakeInterceptors(handshakeInterceptors); registerWampEndpoints(registry);//from w w w . j a v a 2 s. com return registry.getHandlerMapping(); }