Skip to content

Commit

Permalink
fix: fix dependency conflict for ObjectMapper in PushEndpoint (#3137)
Browse files Browse the repository at this point in the history
* fix: fix dependency conflict for PushEndpoint

Fixes #3136

* test
  • Loading branch information
Artur- authored and ZheSun88 committed Jan 10, 2025
1 parent 5d80e99 commit 3576207
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import java.util.Collections;
import java.util.List;

import com.fasterxml.jackson.databind.ObjectMapper;

import com.vaadin.hilla.EndpointProperties;
import org.atmosphere.client.TrackMessageSizeInterceptor;
import org.atmosphere.cpr.ApplicationConfig;
Expand All @@ -14,6 +16,7 @@
import org.atmosphere.interceptor.AtmosphereResourceLifecycleInterceptor;
import org.atmosphere.interceptor.SuspendTrackerInterceptor;
import org.atmosphere.util.SimpleBroadcaster;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.web.servlet.ServletContextInitializer;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
Expand Down Expand Up @@ -46,8 +49,10 @@ public PushConfigurer(EndpointProperties endpointProperties) {
}

@Bean
PushEndpoint pushEndpoint() {
return new PushEndpoint();
PushEndpoint pushEndpoint(
@Qualifier("hillaEndpointObjectMapper") ObjectMapper objectMapper,
PushMessageHandler pushMessageHandler) {
return new PushEndpoint(objectMapper, pushMessageHandler);
}

@Bean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import java.security.Principal;
import java.util.function.Consumer;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.atmosphere.cpr.AtmosphereRequest;
import org.atmosphere.cpr.AtmosphereResource;
import org.atmosphere.cpr.AtmosphereResourceEvent;
Expand All @@ -12,14 +14,11 @@
import org.atmosphere.util.IOUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.context.SecurityContextImpl;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

import com.vaadin.hilla.push.messages.fromclient.AbstractServerMessage;
import com.vaadin.hilla.push.messages.toclient.AbstractClientMessage;

Expand All @@ -28,11 +27,15 @@
*/
public class PushEndpoint extends AtmosphereHandlerAdapter {

@Autowired
private ObjectMapper objectMapper;
@Autowired
private PushMessageHandler pushMessageHandler;

PushEndpoint(ObjectMapper objectMapper,
PushMessageHandler pushMessageHandler) {
this.objectMapper = objectMapper;
this.pushMessageHandler = pushMessageHandler;
}

@Override
public void onRequest(AtmosphereResource resource) throws IOException {
String method = resource.getRequest().getMethod();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package com.vaadin.hilla.test.reactgrid;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Primary;

import com.vaadin.flow.component.page.AppShellConfigurator;
import com.vaadin.flow.theme.Theme;
Expand All @@ -13,4 +16,13 @@ public class Application implements AppShellConfigurator {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}

@Bean
@Primary
ObjectMapper myObjectMapper() {
// This is only to test that you can have a custom object mapper without
// causing problems for Hilla
return new ObjectMapper();
}

}

0 comments on commit 3576207

Please sign in to comment.