Skip to content

Commit

Permalink
Merge pull request #1695 from xjusko/UNDERTOW-2501
Browse files Browse the repository at this point in the history
[UNDERTOW-2501] Review anonymous classes in Undertow io.undertow.websockets.jsr.test.dynamicupgrade
  • Loading branch information
baranowb authored Nov 25, 2024
2 parents 12512a9 + 098b13a commit 7603b9a
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,50 +41,61 @@ public class DoUpgradeServlet extends HttpServlet {

@Override
protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException {
((ServerWebSocketContainer)ContainerProvider.getWebSocketContainer()).doUpgrade(req, resp, new ServerEndpointConfig() {
@Override
public Class<?> getEndpointClass() {
if(req.getParameter("annotated") != null) {
return EchoEndpoint.class;
} else {
return EchoProgramaticEndpoint.class;
}
}
((ServerWebSocketContainer)ContainerProvider.getWebSocketContainer()).doUpgrade(req,
resp,
new UpgradeServerEndpointConfig(req),
Collections.singletonMap("foo", req.getPathInfo()));
}

@Override
public String getPath() {
return req.getPathInfo();
}
private static class UpgradeServerEndpointConfig implements ServerEndpointConfig {
private final HttpServletRequest req;

@Override
public List<String> getSubprotocols() {
return Collections.emptyList();
}
UpgradeServerEndpointConfig(HttpServletRequest req) {
this.req = req;
}

@Override
public List<Extension> getExtensions() {
return Collections.emptyList();
@Override
public Class<?> getEndpointClass() {
if(req.getParameter("annotated") != null) {
return EchoEndpoint.class;
} else {
return EchoProgramaticEndpoint.class;
}
}

@Override
public Configurator getConfigurator() {
return null;
}
@Override
public String getPath() {
return req.getPathInfo();
}

@Override
public List<Class<? extends Encoder>> getEncoders() {
return Collections.emptyList();
}
@Override
public List<String> getSubprotocols() {
return Collections.emptyList();
}

@Override
public List<Class<? extends Decoder>> getDecoders() {
return Collections.emptyList();
}
@Override
public List<Extension> getExtensions() {
return Collections.emptyList();
}

@Override
public Map<String, Object> getUserProperties() {
return Collections.emptyMap();
}
}, Collections.singletonMap("foo", req.getPathInfo()));
@Override
public Configurator getConfigurator() {
return null;
}

@Override
public List<Class<? extends Encoder>> getEncoders() {
return Collections.emptyList();
}

@Override
public List<Class<? extends Decoder>> getDecoders() {
return Collections.emptyList();
}

@Override
public Map<String, Object> getUserProperties() {
return Collections.emptyMap();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

import jakarta.websocket.Endpoint;
import jakarta.websocket.EndpointConfig;
import jakarta.websocket.MessageHandler;
import jakarta.websocket.Session;

/**
Expand All @@ -31,11 +30,6 @@ public class EchoProgramaticEndpoint extends Endpoint {
@Override
public void onOpen(final Session session, EndpointConfig config) {
final String foo = session.getPathParameters().get("foo");
session.addMessageHandler(String.class, new MessageHandler.Whole<String>() {
@Override
public void onMessage(String message) {
session.getAsyncRemote().sendText(foo + " " + message);
}
});
session.addMessageHandler(String.class, message -> session.getAsyncRemote().sendText(foo + " " + message));
}
}

0 comments on commit 7603b9a

Please sign in to comment.