Skip to content

Subscription not working when executing app within external webserver (e.g. OpenLiberty) #209

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

Closed
apae89 opened this issue Sep 30, 2019 · 1 comment
Milestone

Comments

@apae89
Copy link
Contributor

apae89 commented Sep 30, 2019

Hi,
We're facing an issue with Subscriptions when running our GraphQL Spring Boot app (embedded webserver deactivated) within an OpenLiberty webserver. When executing our app in context of the embedded Tomcat everything is working fine.
When executing within OpenLiberty there is a NullPointerException being thrown in class GraphQLWebsocketServlet in method onOpen()

public void onOpen(final Session session, EndpointConfig endpointConfig) {
        final WsSessionSubscriptions subscriptions = new WsSessionSubscriptions();
        final HandshakeRequest request = (HandshakeRequest)session.getUserProperties().get(HANDSHAKE_REQUEST_KEY);
        final SubscriptionProtocolHandler subscriptionProtocolHandler = (SubscriptionProtocolHandler)session.getUserProperties().get(PROTOCOL_HANDLER_REQUEST_KEY);
        synchronized(this.cacheLock) {
            if (this.isShuttingDown.get()) {
                throw new IllegalStateException("Server is shutting down!");
            }

            this.sessionSubscriptionCache.put(session, subscriptions);
        }

        log.debug("Session opened: {}, {}", session.getId(), endpointConfig);
        session.addMessageHandler(new Whole<String>() {
            public void onMessage(String text) {
                try {
                    subscriptionProtocolHandler.onMessage(request, session, subscriptions, text);
                } catch (Throwable var3) {
                    GraphQLWebsocketServlet.log.error("Error executing websocket query for session: {}", session.getId(), var3);
                    GraphQLWebsocketServlet.this.closeUnexpectedly(session, var3);
                }

            }
        });
    }

The NPE is being thrown when accessing subscriptionProtocolHandler within onMessage(). While debugging within OpenLiberty I found out that the userProperties Map of the session object used to create subscriptionProtocolHandler is empty. When executing within embedded Tomcat its contains instances of ApolloSubscriptionProtocolHandler and WsHandshakeRequest. Interestingly these objects are present in the userProperties Map of the endpointConfig (second argument).

Do I need some extra configuration when using Subscriptions within external webserver? Can anyone give me a solution to this?

Many thanks in advance,
Andreas

@apae89
Copy link
Contributor Author

apae89 commented Sep 30, 2019

I could already find out that the embedded Tomcat and OpenLiberty Session objects are implemented differently. The Tomcat implementation fills its userProperties with the content of the userProperties of the endpointConfig object while initializing the Session object (in constructor), whereas the OpenLiberty Session implementation doesn't, as you can see here.
In my opinion, it would make sense to adapt the GraphQLWebsocketServlet to use the userProperties of the endpointConfig object, since there is already an indirect usage and it would provide support for an additional WAS...?

apae89 pushed a commit to apae89/graphql-java-servlet that referenced this issue Oct 1, 2019
… of EndpointConfig, instead of retrieving them Session object.

The issue is described here: graphql-java-kickstart#209
@oliemansm oliemansm added this to the 9.0.0 milestone Nov 28, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants