Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to remap context roots and ports for web-sockets #5643

Closed
lscoughlin opened this issue Dec 12, 2022 · 0 comments
Closed

How to remap context roots and ports for web-sockets #5643

lscoughlin opened this issue Dec 12, 2022 · 0 comments
Assignees
Labels
4.x Version 4.x enhancement New feature or request P3 websocket WebSocket in Helidon

Comments

@lscoughlin
Copy link

lscoughlin commented Dec 12, 2022

Environment Details

  • Helidon Version: 3.0.2
  • Helidon MP
  • JDK version: Java(TM) SE Runtime Environment (build 18.0.2.1+1-1)
  • OS: MacOS 12+, OL7+
  • Docker version (if applicable): 19.03.11-ol

Problem Description

I have a URL Pattern for my services

https://[customer].example.com/[deployment]/[component]/api
https://[customer].example.com/[deployment]/[component]/ui

Such that a “real” customer it might look like:

https://payer18.example.com/dev1/claims/api
https://payer18.example.com/dev1/claims/ui

https://payer18.example.com/dev2/claims/api
https://payer18.example.com/dev2/claims/ui
https://payer18.example.com/dev2/policies/api
https://payer18.example.com/dev2/policies/ui

I use @RoutingPath and @RoutingName extensively in my application to map the jax-rs applications context roots and contexts because I do the good 12-factor thing and put my admin services and metrics on a separate port, but now I have a web socket use case, where I have a private socket that ingests and processes information that is consumed externally by my end users, so I need to be able to re-map it's context route to match the patterns, as well as be able to bind them to different ports.

Then set up my ServerApplicationConfigs like so:

import java.util.Collections;
import java.util.Set;

import com.example.PublisherWebsocket;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.websocket.Endpoint;
import jakarta.websocket.server.ServerApplicationConfig;
import jakarta.websocket.server.ServerEndpointConfig;

@ApplicationScoped
public class PublisherWebsocketApplication implements ServerApplicationConfig {
    @Override
    public Set<ServerEndpointConfig> getEndpointConfigs(Set<Class<? extends Endpoint>> set) {
        return Collections.emptySet();
    }

    @Override
    public Set<Class<?>> getAnnotatedEndpointClasses(Set<Class<?>> set) {
        return Set.of(PublisherWebsocket.class);
    }
}

and like so:

package fsgbu.ohi.saas.applogs.jaxrs;

import java.util.Collections;
import java.util.Set;

import com.example.ReceiverWebsocket;
import io.helidon.microprofile.server.RoutingName;
import io.helidon.microprofile.server.RoutingPath;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.websocket.Endpoint;
import jakarta.websocket.server.ServerApplicationConfig;
import jakarta.websocket.server.ServerEndpointConfig;

@ApplicationScoped
@RoutingPath("/inbound")
@RoutingName("inbound")
public class ReceiverSocketApplication implements ServerApplicationConfig {
    @Override
    public Set<ServerEndpointConfig> getEndpointConfigs(Set<Class<? extends Endpoint>> set) {
        return Collections.emptySet();
    }

    @Override
    public Set<Class<?>> getAnnotatedEndpointClasses(Set<Class<?>> set) {
        return Set.of(ReceiverWebsocket.class);
    }
}

And set up my application yaml like so:

server:
  port: 8080
  host: 0.0.0.0
  sockets:
    - name: inbound
      port: 8090

fsgbu.ohi.saas.applogs.jaxrs.ReceiverSocketApplication:
  routing-name:
    name: "inbound"
    required: true
  routing-path:
    path: "/inbound"

and all it ever spits out is this fancy exception:

Exception in thread "main" java.lang.ExceptionInInitializerError
	at io.helidon.microprofile.cdi.ContainerInstanceHolder.fromBuildTimeInitializer(ContainerInstanceHolder.java:65)
	at io.helidon.microprofile.cdi.ContainerInstanceHolder.lambda$get$1(ContainerInstanceHolder.java:56)
	at io.helidon.microprofile.cdi.ContainerInstanceHolder.access(ContainerInstanceHolder.java:91)
	at io.helidon.microprofile.cdi.ContainerInstanceHolder.get(ContainerInstanceHolder.java:53)
	at io.helidon.microprofile.cdi.HelidonContainer.instance(HelidonContainer.java:48)
	at io.helidon.microprofile.server.Server$Builder.build(Server.java:190)
	at fsgbu.ohi.saas.applogs.cli.ServeCommand.run(ServeCommand.java:20)
	at picocli.CommandLine.executeUserObject(CommandLine.java:2026)
	at picocli.CommandLine.access$1500(CommandLine.java:148)
	at picocli.CommandLine$RunLast.executeUserObjectOfLastSubcommandWithSameParent(CommandLine.java:2461)
	at picocli.CommandLine$RunLast.handle(CommandLine.java:2453)
	at picocli.CommandLine$RunLast.handle(CommandLine.java:2415)
	at picocli.CommandLine$AbstractParseResultHandler.execute(CommandLine.java:2273)
	at picocli.CommandLine$RunLast.execute(CommandLine.java:2417)
	at picocli.CommandLine.execute(CommandLine.java:2170)
	at fsgbu.ohi.saas.applogs.AppLogsMain.main(AppLogsMain.java:20)
	at fsgbu.ohi.saas.applogs.MainDemo.main(MainDemo.java:44)
Caused by: org.jboss.weld.exceptions.DefinitionException: Exception List with 1 exceptions:
Exception 0 :
java.lang.IllegalStateException: At most one subclass of ServerApplicationConfig is permitted
	at io.helidon.microprofile.tyrus.WebSocketApplication$Builder.applicationClass(WebSocketApplication.java:123)
	at io.helidon.microprofile.tyrus.WebSocketCdiExtension.applicationClass(WebSocketCdiExtension.java:83)
	at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)
	at java.base/java.lang.reflect.Method.invoke(Method.java:577)
	at org.jboss.weld.injection.StaticMethodInjectionPoint.invoke(StaticMethodInjectionPoint.java:95)
	at org.jboss.weld.injection.StaticMethodInjectionPoint.invoke(StaticMethodInjectionPoint.java:85)
	at org.jboss.weld.injection.MethodInvocationStrategy$SimpleMethodInvocationStrategy.invoke(MethodInvocationStrategy.java:168)
	at org.jboss.weld.event.ObserverMethodImpl.sendEvent(ObserverMethodImpl.java:330)
	at org.jboss.weld.event.ExtensionObserverMethodImpl.sendEvent(ExtensionObserverMethodImpl.java:123)
	at org.jboss.weld.event.ObserverMethodImpl.sendEvent(ObserverMethodImpl.java:308)
	at org.jboss.weld.event.ObserverMethodImpl.notify(ObserverMethodImpl.java:286)
	at org.jboss.weld.bootstrap.events.ContainerLifecycleEvents.fireProcessAnnotatedType(ContainerLifecycleEvents.java:207)

There should be a way to accomplish the desired configuration of having endpoints listening on different ports in a single component.

Steps to reproduce

  1. Do The above
  2. Enjoy the exception
@tomas-langer tomas-langer added the websocket WebSocket in Helidon label Dec 12, 2022
@m0mus m0mus added enhancement New feature or request P3 labels Dec 22, 2022
@github-actions github-actions bot added the 4.x Version 4.x label Jan 11, 2023
spericas added a commit to spericas/helidon that referenced this issue Jan 30, 2023
… to be registered on different ports. Due to a restriction in Tyrus, you cannot share the same path even if registered on different ports, so this is a restriction on this enhancement. WebSocket unit tests re-structured to use @HelidonTest. For more info see issue helidon-io#5643 and WebSocketEndpointAppTest.
spericas added a commit that referenced this issue Jan 30, 2023
…ent ports (#6004)

* Port to Nima of enhancement to allow different WebSocket applications to be registered on different ports. Due to a restriction in Tyrus, you cannot share the same path even if registered on different ports, so this is a restriction on this enhancement. WebSocket unit tests re-structured to use @HelidonTest. For more info see issue #5643 and WebSocketEndpointAppTest.

* Updated docs describing enhancement to bind Websocket applications on different ports.

* Copyright year changed to 2023.

* Removed old comment.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
4.x Version 4.x enhancement New feature or request P3 websocket WebSocket in Helidon
Projects
Archived in project
Development

No branches or pull requests

4 participants