org.springframework.web.socket.sockjs.frame.Jackson2SockJsMessageCodec Java Examples

The following examples show how to use org.springframework.web.socket.sockjs.frame.Jackson2SockJsMessageCodec. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TransportHandlingSockJsService.java    From spring-analysis-note with MIT License 6 votes vote down vote up
/**
 * Create a TransportHandlingSockJsService with given {@link TransportHandler handler} types.
 * @param scheduler a task scheduler for heart-beat messages and removing timed-out sessions;
 * the provided TaskScheduler should be declared as a Spring bean to ensure it gets
 * initialized at start-up and shuts down when the application stops
 * @param handlers one or more {@link TransportHandler} implementations to use
 */
public TransportHandlingSockJsService(TaskScheduler scheduler, Collection<TransportHandler> handlers) {
	super(scheduler);

	if (CollectionUtils.isEmpty(handlers)) {
		logger.warn("No transport handlers specified for TransportHandlingSockJsService");
	}
	else {
		for (TransportHandler handler : handlers) {
			handler.initialize(this);
			this.handlers.put(handler.getTransportType(), handler);
		}
	}

	if (jackson2Present) {
		this.messageCodec = new Jackson2SockJsMessageCodec();
	}
}
 
Example #2
Source File: RestTemplateXhrTransportTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void connectReceiveAndCloseWithStompFrame() throws Exception {
	StompHeaderAccessor accessor = StompHeaderAccessor.create(StompCommand.SEND);
	accessor.setDestination("/destination");
	MessageHeaders headers = accessor.getMessageHeaders();
	Message<byte[]> message = MessageBuilder.createMessage("body".getBytes(StandardCharsets.UTF_8), headers);
	byte[] bytes = new StompEncoder().encode(message);
	TextMessage textMessage = new TextMessage(bytes);
	SockJsFrame frame = SockJsFrame.messageFrame(new Jackson2SockJsMessageCodec(), textMessage.getPayload());

	String body = "o\n" + frame.getContent() + "\n" + "c[3000,\"Go away!\"]";
	ClientHttpResponse response = response(HttpStatus.OK, body);
	connect(response);

	verify(this.webSocketHandler).afterConnectionEstablished(any());
	verify(this.webSocketHandler).handleMessage(any(), eq(textMessage));
	verify(this.webSocketHandler).afterConnectionClosed(any(), eq(new CloseStatus(3000, "Go away!")));
	verifyNoMoreInteractions(this.webSocketHandler);
}
 
Example #3
Source File: TransportHandlingSockJsService.java    From java-technology-stack with MIT License 6 votes vote down vote up
/**
 * Create a TransportHandlingSockJsService with given {@link TransportHandler handler} types.
 * @param scheduler a task scheduler for heart-beat messages and removing timed-out sessions;
 * the provided TaskScheduler should be declared as a Spring bean to ensure it gets
 * initialized at start-up and shuts down when the application stops
 * @param handlers one or more {@link TransportHandler} implementations to use
 */
public TransportHandlingSockJsService(TaskScheduler scheduler, Collection<TransportHandler> handlers) {
	super(scheduler);

	if (CollectionUtils.isEmpty(handlers)) {
		logger.warn("No transport handlers specified for TransportHandlingSockJsService");
	}
	else {
		for (TransportHandler handler : handlers) {
			handler.initialize(this);
			this.handlers.put(handler.getTransportType(), handler);
		}
	}

	if (jackson2Present) {
		this.messageCodec = new Jackson2SockJsMessageCodec();
	}
}
 
Example #4
Source File: RestTemplateXhrTransportTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
public void connectReceiveAndCloseWithStompFrame() throws Exception {
	StompHeaderAccessor accessor = StompHeaderAccessor.create(StompCommand.SEND);
	accessor.setDestination("/destination");
	MessageHeaders headers = accessor.getMessageHeaders();
	Message<byte[]> message = MessageBuilder.createMessage("body".getBytes(StandardCharsets.UTF_8), headers);
	byte[] bytes = new StompEncoder().encode(message);
	TextMessage textMessage = new TextMessage(bytes);
	SockJsFrame frame = SockJsFrame.messageFrame(new Jackson2SockJsMessageCodec(), textMessage.getPayload());

	String body = "o\n" + frame.getContent() + "\n" + "c[3000,\"Go away!\"]";
	ClientHttpResponse response = response(HttpStatus.OK, body);
	connect(response);

	verify(this.webSocketHandler).afterConnectionEstablished(any());
	verify(this.webSocketHandler).handleMessage(any(), eq(textMessage));
	verify(this.webSocketHandler).afterConnectionClosed(any(), eq(new CloseStatus(3000, "Go away!")));
	verifyNoMoreInteractions(this.webSocketHandler);
}
 
Example #5
Source File: TransportHandlingSockJsService.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
/**
 * Create a TransportHandlingSockJsService with given {@link TransportHandler handler} types.
 * @param scheduler a task scheduler for heart-beat messages and removing timed-out sessions;
 * the provided TaskScheduler should be declared as a Spring bean to ensure it gets
 * initialized at start-up and shuts down when the application stops
 * @param handlers one or more {@link TransportHandler} implementations to use
 */
public TransportHandlingSockJsService(TaskScheduler scheduler, Collection<TransportHandler> handlers) {
	super(scheduler);

	if (CollectionUtils.isEmpty(handlers)) {
		logger.warn("No transport handlers specified for TransportHandlingSockJsService");
	}
	else {
		for (TransportHandler handler : handlers) {
			handler.initialize(this);
			this.handlers.put(handler.getTransportType(), handler);
		}
	}

	if (jackson2Present) {
		this.messageCodec = new Jackson2SockJsMessageCodec();
	}
}
 
Example #6
Source File: RestTemplateXhrTransportTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Test
public void connectReceiveAndCloseWithStompFrame() throws Exception {
	StompHeaderAccessor accessor = StompHeaderAccessor.create(StompCommand.SEND);
	accessor.setDestination("/destination");
	MessageHeaders headers = accessor.getMessageHeaders();
	Message<byte[]> message = MessageBuilder.createMessage("body".getBytes(Charset.forName("UTF-8")), headers);
	byte[] bytes = new StompEncoder().encode(message);
	TextMessage textMessage = new TextMessage(bytes);
	SockJsFrame frame = SockJsFrame.messageFrame(new Jackson2SockJsMessageCodec(), textMessage.getPayload());

	String body = "o\n" + frame.getContent() + "\n" + "c[3000,\"Go away!\"]";
	ClientHttpResponse response = response(HttpStatus.OK, body);
	connect(response);

	verify(this.webSocketHandler).afterConnectionEstablished(any());
	verify(this.webSocketHandler).handleMessage(any(), eq(textMessage));
	verify(this.webSocketHandler).afterConnectionClosed(any(), eq(new CloseStatus(3000, "Go away!")));
	verifyNoMoreInteractions(this.webSocketHandler);
}
 
Example #7
Source File: SockJsClient.java    From spring-analysis-note with MIT License 5 votes vote down vote up
/**
 * Create a {@code SockJsClient} with the given transports.
 * <p>If the list includes an {@link XhrTransport} (or more specifically an
 * implementation of {@link InfoReceiver}) the instance is used to initialize
 * the {@link #setInfoReceiver(InfoReceiver) infoReceiver} property, or
 * otherwise is defaulted to {@link RestTemplateXhrTransport}.
 * @param transports the (non-empty) list of transports to use
 */
public SockJsClient(List<Transport> transports) {
	Assert.notEmpty(transports, "No transports provided");
	this.transports = new ArrayList<>(transports);
	this.infoReceiver = initInfoReceiver(transports);
	if (jackson2Present) {
		this.messageCodec = new Jackson2SockJsMessageCodec();
	}
}
 
Example #8
Source File: SockJsClient.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * Create a {@code SockJsClient} with the given transports.
 * <p>If the list includes an {@link XhrTransport} (or more specifically an
 * implementation of {@link InfoReceiver}) the instance is used to initialize
 * the {@link #setInfoReceiver(InfoReceiver) infoReceiver} property, or
 * otherwise is defaulted to {@link RestTemplateXhrTransport}.
 * @param transports the (non-empty) list of transports to use
 */
public SockJsClient(List<Transport> transports) {
	Assert.notEmpty(transports, "No transports provided");
	this.transports = new ArrayList<>(transports);
	this.infoReceiver = initInfoReceiver(transports);
	if (jackson2Present) {
		this.messageCodec = new Jackson2SockJsMessageCodec();
	}
}
 
Example #9
Source File: SockJsClient.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * Create a {@code SockJsClient} with the given transports.
 * <p>If the list includes an {@link XhrTransport} (or more specifically an
 * implementation of {@link InfoReceiver}) the instance is used to initialize
 * the {@link #setInfoReceiver(InfoReceiver) infoReceiver} property, or
 * otherwise is defaulted to {@link RestTemplateXhrTransport}.
 * @param transports the (non-empty) list of transports to use
 */
public SockJsClient(List<Transport> transports) {
	Assert.notEmpty(transports, "No transports provided");
	this.transports = new ArrayList<Transport>(transports);
	this.infoReceiver = initInfoReceiver(transports);
	if (jackson2Present) {
		this.messageCodec = new Jackson2SockJsMessageCodec();
	}
}