Class JakartaEndpointComponents

java.lang.Object
io.micronaut.servlet.websocket.JakartaEndpointComponents

@Internal @Singleton public final class JakartaEndpointComponents extends Object
Instantiates the classes a @ServerEndpoint names in decoders, encoders and configurator.

A Jakarta container creates these with Class.newInstance(). Here a class is resolved through the first route that can produce it, and only the last one reflects:

  1. as a bean, when it is one;
  2. through its introspection, which the annotation processor generates for every class the endpoint names, when it has a no-argument constructor;
  3. reflectively, when micronaut-reflection is on the classpath and the type matches a micronaut.introspection.allow-reflection pattern, after which it is a bean whose constructor arguments are injected.
Since:
6.2.0
Author:
graemerocher
  • Constructor Details

    • JakartaEndpointComponents

      public JakartaEndpointComponents(io.micronaut.context.BeanContext beanContext, @Nullable ReflectiveBeanDefinitions reflective)
      Default constructor.
      Parameters:
      beanContext - The bean context
      reflective - The reflective route, present only with micronaut-reflection
  • Method Details

    • instantiate

      public <T> T instantiate(Class<T> type)
      Creates an instance of the component. A bean is created as its scope says; an introspected type is instantiated anew on every call.
      Type Parameters:
      T - The component type
      Parameters:
      type - The component type
      Returns:
      The instance
      Throws:
      io.micronaut.websocket.exceptions.WebSocketException - if no route can produce the type
    • encodedType

      public @Nullable Class<?> encodedType(Class<?> encoder)
      The type an encoder encodes: the type argument of the Encoder interface it implements.

      Read from the bean definition when the encoder is a bean, which the processors recorded at compilation time. Reading it from the class's generic signature is reflection, so that only happens with micronaut-reflection on the classpath. Otherwise the type is unknown and the encoder is offered every value, stepping aside for one it cannot encode; an encoder is therefore best declared as a bean.

      Parameters:
      encoder - The encoder class
      Returns:
      The encoded type, or null when it cannot be resolved
    • isReflectionAllowed

      public boolean isReflectionAllowed(Class<?> type)
      Whether the container itself may instantiate the type reflectively, which is what it does with the encoders of a ServerEndpointConfig.
      Parameters:
      type - The type
      Returns:
      true when the application has opted the type into reflection