Skip to content

Commit

Permalink
Resolves eclipse-ee4j#694
Browse files Browse the repository at this point in the history
  • Loading branch information
dansiviter committed Apr 5, 2020
1 parent 7fe9fea commit f23cf37
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
Expand Down Expand Up @@ -528,7 +529,8 @@ public void run() {
} else if ((((Class<?>) o).getAnnotation(ClientEndpoint.class) != null)) {
endpoint = AnnotatedEndpoint
.fromClass((Class) o, componentProvider, false, incomingBufferSize, collector,
EndpointEventListener.NO_OP);
EndpointEventListener.NO_OP,
new ArrayList<>(getInstalledExtensions()));
config = (ClientEndpointConfig) ((AnnotatedEndpoint) endpoint).getEndpointConfig();
} else {
collector.addException(new DeploymentException(String.format(
Expand All @@ -539,7 +541,8 @@ public void run() {
}
} else {
endpoint = AnnotatedEndpoint
.fromInstance(o, componentProvider, false, incomingBufferSize, collector);
.fromInstance(o, componentProvider, false, incomingBufferSize, collector,
new ArrayList<>(getInstalledExtensions()));
config = (ClientEndpointConfig) ((AnnotatedEndpoint) endpoint).getEndpointConfig();
}

Expand Down Expand Up @@ -754,7 +757,6 @@ public void setDefaultMaxTextMessageBufferSize(int i) {
@Override
public Set<Extension> getInstalledExtensions() {
if (webSocketContainer == null) {
// TODO
return Collections.emptySet();
} else {
return webSocketContainer.getInstalledExtensions();
Expand Down
24 changes: 15 additions & 9 deletions core/src/main/java/org/glassfish/tyrus/core/AnnotatedEndpoint.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import javax.websocket.Encoder;
import javax.websocket.Endpoint;
import javax.websocket.EndpointConfig;
import javax.websocket.Extension;
import javax.websocket.MessageHandler;
import javax.websocket.OnClose;
import javax.websocket.OnError;
Expand Down Expand Up @@ -87,13 +88,15 @@ public class AnnotatedEndpoint extends Endpoint {
* @param incomingBufferSize size limit of the incoming buffer.
* @param collector error collector.
* @param endpointEventListener listener of monitored endpoint events.
* @param extensions installled extentions.
* @return new instance.
*/
public static AnnotatedEndpoint fromClass(Class<?> annotatedClass, ComponentProviderService componentProvider,
boolean isServerEndpoint, int incomingBufferSize, ErrorCollector
collector, EndpointEventListener endpointEventListener) {
boolean isServerEndpoint, int incomingBufferSize,
ErrorCollector collector, EndpointEventListener endpointEventListener,
List<Extension> extensions) {
return new AnnotatedEndpoint(annotatedClass, null, componentProvider, isServerEndpoint, incomingBufferSize,
collector, endpointEventListener);
collector, endpointEventListener, extensions);
}

/**
Expand All @@ -104,19 +107,20 @@ public static AnnotatedEndpoint fromClass(Class<?> annotatedClass, ComponentProv
* @param isServerEndpoint {@code true} iff annotated endpoint is deployed on server side.
* @param incomingBufferSize size limit of the incoming buffer
* @param collector error collector.
* @param extensions installled extentions.
* @return new instance.
*/
public static AnnotatedEndpoint fromInstance(
Object annotatedInstance, ComponentProviderService componentProvider, boolean isServerEndpoint,
int incomingBufferSize, ErrorCollector collector) {
int incomingBufferSize, ErrorCollector collector, List<Extension> extensions) {
return new AnnotatedEndpoint(annotatedInstance.getClass(), annotatedInstance, componentProvider,
isServerEndpoint, incomingBufferSize, collector, EndpointEventListener.NO_OP);
isServerEndpoint, incomingBufferSize, collector, EndpointEventListener.NO_OP, extensions);
}

private AnnotatedEndpoint(Class<?> annotatedClass, Object instance, ComponentProviderService componentProvider,
Boolean isServerEndpoint, int incomingBufferSize, ErrorCollector collector,
EndpointEventListener endpointEventListener) {
this.configuration = createEndpointConfig(annotatedClass, isServerEndpoint, collector);
EndpointEventListener endpointEventListener, List<Extension> extensions) {
this.configuration = createEndpointConfig(annotatedClass, isServerEndpoint, collector, extensions);
this.annotatedInstance = instance;
this.annotatedClass = annotatedClass;
this.endpointEventListener = endpointEventListener;
Expand Down Expand Up @@ -264,8 +268,8 @@ public <T> Object getEndpointInstance(Class<T> endpointClass) throws Instantiati
this.onCloseParameters = onCloseParameters;
}

private EndpointConfig createEndpointConfig(Class<?> annotatedClass, boolean isServerEndpoint, ErrorCollector
collector) {
private EndpointConfig createEndpointConfig(Class<?> annotatedClass, boolean isServerEndpoint,
ErrorCollector collector, List<Extension> extensions) {
if (isServerEndpoint) {
final ServerEndpoint wseAnnotation = annotatedClass.getAnnotation(ServerEndpoint.class);

Expand Down Expand Up @@ -294,6 +298,7 @@ private EndpointConfig createEndpointConfig(Class<?> annotatedClass, boolean isS
.create(annotatedClass, wseAnnotation.value())
.encoders(encoderClasses)
.decoders(decoderClasses)
.extensions(extensions)
.subprotocols(Arrays.asList(subProtocols));
if (!wseAnnotation.configurator().equals(ServerEndpointConfig.Configurator.class)) {
builder = builder.configurator(ReflectionHelper.getInstance(wseAnnotation.configurator(),
Expand All @@ -307,6 +312,7 @@ private EndpointConfig createEndpointConfig(Class<?> annotatedClass, boolean isS
.create(annotatedClass, wseAnnotation.value())
.encoders(encoderClasses)
.decoders(decoderClasses)
.extensions(extensions)
.subprotocols(Arrays.asList(subProtocols));
if (!wseAnnotation.configurator().equals(ServerEndpointConfig.Configurator.class)) {
builder = builder.configurator(ReflectionHelper.getInstance(wseAnnotation.configurator(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public TyrusServerEndpointConfig build() {
);
}

private Builder(Class endpointClass, String path) {
private Builder(Class<?> endpointClass, String path) {
if (endpointClass == null) {
throw new IllegalArgumentException("endpointClass cannot be null");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package org.glassfish.tyrus.core;

import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
Expand Down Expand Up @@ -591,7 +592,7 @@ public void register(Class<?> endpointClass, String contextPath) throws Deployme
EndpointEventListenerWrapper endpointEventListenerWrapper = new EndpointEventListenerWrapper();
AnnotatedEndpoint endpoint = AnnotatedEndpoint
.fromClass(endpointClass, componentProviderService, true, incomingBufferSize, collector,
endpointEventListenerWrapper);
endpointEventListenerWrapper, new ArrayList<>(webSocketContainer.getInstalledExtensions()));
EndpointConfig config = endpoint.getEndpointConfig();

TyrusEndpointWrapper endpointWrapper =
Expand Down Expand Up @@ -644,7 +645,7 @@ public void register(ServerEndpointConfig serverConfig, String contextPath) thro

final AnnotatedEndpoint endpoint = AnnotatedEndpoint
.fromClass(endpointClass, componentProviderService, true, incomingBufferSize, collector,
endpointEventListenerWrapper);
endpointEventListenerWrapper, new ArrayList<>(webSocketContainer.getInstalledExtensions()));
final EndpointConfig config = endpoint.getEndpointConfig();

endpointWrapper = new TyrusEndpointWrapper(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -317,9 +317,6 @@ public void setDefaultMaxTextMessageBufferSize(int max) {

@Override
public Set<Extension> getInstalledExtensions() {
// TODO
// return Collections.unmodifiableSet(new HashSet<String>(configuration.parseExtensionsHeader()));

return Collections.emptySet();
}

Expand Down

0 comments on commit f23cf37

Please sign in to comment.