Skip to content

Commit

Permalink
Merge branch 'main' into serviceName
Browse files Browse the repository at this point in the history
  • Loading branch information
platosha authored Jan 14, 2025
2 parents 9a38a22 + 52484b9 commit 0638cb8
Show file tree
Hide file tree
Showing 102 changed files with 21,213 additions and 18,486 deletions.
5,459 changes: 3,665 additions & 1,794 deletions package-lock.json

Large diffs are not rendered by default.

22 changes: 11 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,46 +33,46 @@
"prettier": "$prettier"
},
"devDependencies": {
"@nx/js": "^20.2.2",
"@preact/signals-react-transform": "^0.5.0",
"@nx/js": "^20.3.1",
"@preact/signals-react-transform": "^0.5.1",
"@remcovaes/web-test-runner-vite-plugin": "^1.2.2",
"@types/karma": "^6.3.9",
"@types/node": "^22.10.2",
"@vaadin/react-components": "24.7.0-alpha2",
"@types/node": "^22.10.5",
"@vaadin/react-components": "24.7.0-alpha5",
"@vitejs/plugin-react": "^4.3.4",
"@web/test-runner": "^0.19.0",
"chai-dom": "^1.12.0",
"compare-versions": "^6.1.1",
"concurrently": "^9.1.0",
"concurrently": "^9.1.2",
"cssnano": "^7.0.6",
"esbuild": "^0.24.0",
"esbuild": "^0.24.2",
"eslint": "^8.56.0",
"eslint-config-vaadin": "1.0.0-alpha.18",
"eslint-plugin-mocha": "^10.3.0",
"eslint-plugin-prettier": "^5.1.3",
"eslint-plugin-tsdoc": "^0.2.17",
"glob": "^11.0.0",
"glob": "^11.0.1",
"karma": "^6.4.4",
"karma-chrome-launcher": "^3.2.0",
"karma-coverage": "^2.2.1",
"karma-mocha": "^2.0.1",
"karma-spec-reporter": "^0.0.36",
"karma-viewport": "^1.0.9",
"karma-vite": "^1.0.5",
"lint-staged": "^15.2.11",
"lint-staged": "^15.3.0",
"magic-string": "^0.30.17",
"meow": "^13.2.0",
"micromatch": "^4.0.8",
"mocha": "^11.0.1",
"nx": "^20.2.2",
"nx": "^20.3.1",
"postcss": "^8.4.49",
"prettier": "^3.4.2",
"react-dom": "^18.3.1",
"simple-git-hooks": "^2.11.1",
"sync-request": "^6.1.0",
"tsx": "^4.19.2",
"type-fest": "^4.30.2",
"typescript": "5.7.2",
"type-fest": "^4.32.0",
"typescript": "5.7.3",
"vite": "^5.4.11"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,7 @@ public void update() {
GeneratorProcessor generator = new GeneratorProcessor(
engineConfiguration);
generator.process();

try {
var openApiPath = engineConfiguration.getOpenAPIFile();
this.endpointController
.registerEndpoints(openApiPath.toUri().toURL());
} catch (IOException e) {
throw new RuntimeException(e);
}
this.endpointController.registerEndpoints();
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@

import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import java.net.URL;
import java.util.TreeMap;
import java.util.stream.Collectors;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.node.ObjectNode;
Expand Down Expand Up @@ -114,7 +114,7 @@ public EndpointController(ApplicationContext context,
* Initializes the controller by registering all endpoints found in the
* OpenApi definition or, as a fallback, in the Spring context.
*/
public void registerEndpoints(URL openApiResource) {
public void registerEndpoints() {
// Spring returns bean names in lower camel case, while Hilla names
// endpoints in upper camel case, so a case-insensitive map is used to
// ease searching
Expand All @@ -124,27 +124,16 @@ public void registerEndpoints(URL openApiResource) {
endpointBeans
.putAll(context.getBeansWithAnnotation(BrowserCallable.class));

if (endpointRegistry.isEmpty() && !endpointBeans.isEmpty()) {
LOGGER.debug("No endpoints found in openapi.json:"
+ " registering all endpoints found using the Spring context");
var currentEndpointNames = endpointBeans.values().stream()
.map(endpointRegistry::registerEndpoint)
.collect(Collectors.toSet());
// remove obsolete endpoints
endpointRegistry.getEndpoints().keySet()
.retainAll(currentEndpointNames);

endpointBeans.forEach((name, endpointBean) -> endpointRegistry
.registerEndpoint(endpointBean));
}

if (!endpointRegistry.isEmpty()) {
HillaStats.reportHasEndpoint();
}

// make sure that signalsHandler endpoint is always registered, but not
// counted as a regular endpoint in stats:
if (endpointRegistry.get(SIGNALS_HANDLER_BEAN_NAME) == null) {
var signalHandlerBean = endpointBeans
.get(SIGNALS_HANDLER_BEAN_NAME);
if (signalHandlerBean != null) {
endpointRegistry.registerEndpoint(signalHandlerBean);
}
}
endpointBeans.keySet().stream()
.filter(name -> !name.equals(SIGNALS_HANDLER_BEAN_NAME))
.findAny().ifPresent(name -> HillaStats.reportHasEndpoint());

// Temporary Hack
VaadinService vaadinService = VaadinService.getCurrent();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ private static ObjectMapper createDefaultEndpointMapper(
*/
@Bean
EndpointInvoker endpointInvoker(ApplicationContext applicationContext,
ObjectMapper hillaEndpointObjectMapper,
@Qualifier("hillaEndpointObjectMapper") ObjectMapper hillaEndpointObjectMapper,
ExplicitNullableTypeChecker explicitNullableTypeChecker,
ServletContext servletContext, EndpointRegistry endpointRegistry) {
return new EndpointInvoker(applicationContext,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,10 @@ private static String getEndpointNameForClass(Class<?> beanType) {
// BrowserCallable has no value so this works
return Optional.ofNullable(beanType.getAnnotation(Endpoint.class))
.map(Endpoint::value).filter(value -> !value.isEmpty())
.orElse(beanType.getSimpleName());
.orElse(beanType.getSimpleName()).toLowerCase(Locale.ENGLISH);
}

void registerEndpoint(Object endpointBean) {
String registerEndpoint(Object endpointBean) {
// Check the bean type instead of the implementation type in
// case of e.g. proxies
Class<?> beanType = ClassUtils.getUserClass(endpointBean.getClass());
Expand All @@ -129,10 +129,11 @@ void registerEndpoint(Object endpointBean) {
Method[] endpointPublicMethods = beanType.getMethods();
AccessibleObject.setAccessible(endpointPublicMethods, true);

vaadinEndpoints.put(endpointName.toLowerCase(Locale.ENGLISH),
vaadinEndpoints.put(endpointName,
new VaadinEndpointData(endpointBean, endpointPublicMethods));
LOGGER.debug("Registered endpoint '{}' with class '{}'", endpointName,
beanType);
return endpointName;
}

/**
Expand Down
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
Expand Up @@ -22,6 +22,8 @@
import com.vaadin.hilla.signals.Signal;
import com.vaadin.hilla.signals.core.registry.SecureSignalsRegistry;
import com.vaadin.hilla.signals.handler.SignalsHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

Expand All @@ -36,7 +38,7 @@ public class SignalsConfiguration {
private final EndpointInvoker endpointInvoker;

public SignalsConfiguration(EndpointInvoker endpointInvoker,
ObjectMapper hillaEndpointObjectMapper) {
@Qualifier("hillaEndpointObjectMapper") ObjectMapper hillaEndpointObjectMapper) {
this.endpointInvoker = endpointInvoker;
Signal.setMapper(hillaEndpointObjectMapper);
}
Expand All @@ -62,11 +64,11 @@ public SecureSignalsRegistry signalsRegistry() {
*
* @return SignalsHandler endpoint instance
*/
@ConditionalOnFeatureFlag("fullstackSignals")
@Bean
public SignalsHandler signalsHandler() {
public SignalsHandler signalsHandler(
@Autowired(required = false) SecureSignalsRegistry signalsRegistry) {
if (signalsHandler == null) {
signalsHandler = new SignalsHandler(signalsRegistry());
signalsHandler = new SignalsHandler(signalsRegistry);
}
return signalsHandler;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,19 @@
@BrowserCallable
public class SignalsHandler {

private static final String FEATURE_FLAG_ERROR_MESSAGE = """
%n
***********************************************************************************************************************
* The Hilla Fullstack Signals API is currently considered experimental and may change in the future. *
* To use it you need to explicitly enable it in Copilot, or by adding com.vaadin.experimental.fullstackSignals=true *
* to src/main/resources/vaadin-featureflags.properties. *
***********************************************************************************************************************
%n"""
.stripIndent();

private final SecureSignalsRegistry registry;

public SignalsHandler(SecureSignalsRegistry registry) {
public SignalsHandler(@Nullable SecureSignalsRegistry registry) {
this.registry = registry;
}

Expand All @@ -53,6 +63,10 @@ public SignalsHandler(SecureSignalsRegistry registry) {
public Flux<ObjectNode> subscribe(String providerEndpoint,
String providerMethod, String clientSignalId, ObjectNode body,
@Nullable String parentClientSignalId) {
if (registry == null) {
throw new IllegalStateException(
String.format(FEATURE_FLAG_ERROR_MESSAGE));
}
try {
if (parentClientSignalId != null) {
return subscribe(parentClientSignalId, clientSignalId);
Expand Down Expand Up @@ -96,6 +110,10 @@ private Flux<ObjectNode> subscribe(String parentClientSignalId,
public void update(String clientSignalId, ObjectNode event)
throws EndpointInvocationException.EndpointAccessDeniedException,
EndpointInvocationException.EndpointNotFoundException {
if (registry == null) {
throw new IllegalStateException(
String.format(FEATURE_FLAG_ERROR_MESSAGE));
}
var parentSignalId = ListStateEvent.extractParentSignalId(event);
if (parentSignalId != null) {
if (registry.get(parentSignalId) == null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,13 @@
package com.vaadin.hilla.startup;

import com.vaadin.flow.function.DeploymentConfiguration;
import com.vaadin.flow.server.ServiceInitEvent;
import com.vaadin.flow.server.VaadinServiceInitListener;
import com.vaadin.hilla.EndpointController;
import com.vaadin.hilla.engine.EngineConfiguration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import java.net.MalformedURLException;
import java.net.URL;

@Component
public class EndpointRegistryInitializer implements VaadinServiceInitListener {

private static final Logger LOGGER = LoggerFactory
.getLogger(EndpointRegistryInitializer.class);

private static final String OPEN_API_PROD_RESOURCE_PATH = '/'
+ EngineConfiguration.OPEN_API_PATH;

private final EndpointController endpointController;

public EndpointRegistryInitializer(EndpointController endpointController) {
Expand All @@ -29,28 +16,6 @@ public EndpointRegistryInitializer(EndpointController endpointController) {

@Override
public void serviceInit(ServiceInitEvent event) {
var deploymentConfig = event.getSource().getDeploymentConfiguration();
var openApiResource = getOpenApiAsResource(deploymentConfig);
endpointController.registerEndpoints(openApiResource);
}

private URL getOpenApiAsResource(DeploymentConfiguration deploymentConfig) {
if (deploymentConfig.isProductionMode()) {
return getClass().getResource(OPEN_API_PROD_RESOURCE_PATH);
}
var openApiPathInDevMode = deploymentConfig.getProjectFolder().toPath()
.resolve(deploymentConfig.getBuildFolder())
.resolve(EngineConfiguration.OPEN_API_PATH);
try {
return openApiPathInDevMode.toFile().exists()
? openApiPathInDevMode.toUri().toURL()
: null;
} catch (MalformedURLException e) {
LOGGER.debug(String.format(
"%s Mode: Path %s to resource %s seems to be malformed/could not be parsed. ",
deploymentConfig.getMode(), openApiPathInDevMode.toUri(),
EngineConfiguration.OPEN_API_PATH), e);
return null;
}
endpointController.registerEndpoints();
}
}
Loading

0 comments on commit 0638cb8

Please sign in to comment.