Skip to content

Commit

Permalink
Merge pull request #8317 from stuartwdouglas/WFLY-1438
Browse files Browse the repository at this point in the history
WFLY-1438 Add support for listing WebSocket ServerEndpoints in the CLI
  • Loading branch information
n1hility committed Oct 22, 2015
2 parents f19acde + 71454d8 commit 255f204
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 5 deletions.
@@ -0,0 +1,54 @@
/*
* JBoss, Home of Professional Open Source.
* Copyright 2013, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/

package org.wildfly.extension.undertow;

import org.jboss.as.controller.PathElement;
import org.jboss.as.controller.SimpleAttributeDefinition;
import org.jboss.as.controller.SimpleAttributeDefinitionBuilder;
import org.jboss.as.controller.SimpleResourceDefinition;
import org.jboss.as.controller.registry.ManagementResourceRegistration;
import org.jboss.dmr.ModelType;

/**
* @author Stuart Douglas
*/
public class DeploymentWebSocketDefinition extends SimpleResourceDefinition {
public static final DeploymentWebSocketDefinition INSTANCE = new DeploymentWebSocketDefinition();

static final SimpleAttributeDefinition PATH = new SimpleAttributeDefinitionBuilder("path", ModelType.STRING, false).setStorageRuntime().build();
static final SimpleAttributeDefinition ENDPOINT_CLASS = new SimpleAttributeDefinitionBuilder("endpoint-class", ModelType.STRING, false).setStorageRuntime().build();



private DeploymentWebSocketDefinition() {
super(PathElement.pathElement("websocket"),
UndertowExtension.getResolver("deployment.websocket"));
}

@Override
public void registerAttributes(ManagementResourceRegistration registration) {
registration.registerReadOnlyAttribute(PATH, null);
registration.registerReadOnlyAttribute(ENDPOINT_CLASS, null);

}
}
Expand Up @@ -100,7 +100,7 @@ public void initialize(ExtensionContext context) {

final ManagementResourceRegistration deployments = subsystem.registerDeploymentModel(DeploymentDefinition.INSTANCE);
deployments.registerSubModel(DeploymentServletDefinition.INSTANCE);

deployments.registerSubModel(DeploymentWebSocketDefinition.INSTANCE);
subsystem.registerXMLElementWriter(UndertowSubsystemParser_3_0.INSTANCE);
}

Expand Down
Expand Up @@ -24,18 +24,22 @@

import io.undertow.websockets.jsr.JsrWebSocketLogger;
import io.undertow.websockets.jsr.WebSocketDeploymentInfo;
import org.jboss.as.controller.PathElement;
import org.jboss.as.ee.utils.ClassLoadingUtils;
import org.jboss.as.server.deployment.Attachments;
import org.jboss.as.server.deployment.DeploymentPhaseContext;
import org.jboss.as.server.deployment.DeploymentResourceSupport;
import org.jboss.as.server.deployment.DeploymentUnit;
import org.jboss.as.server.deployment.DeploymentUnitProcessingException;
import org.jboss.as.server.deployment.DeploymentUnitProcessor;
import org.jboss.as.server.deployment.annotation.CompositeIndex;
import org.jboss.as.web.common.WarMetaData;
import org.jboss.dmr.ModelNode;
import org.jboss.jandex.AnnotationInstance;
import org.jboss.jandex.ClassInfo;
import org.jboss.jandex.DotName;
import org.jboss.modules.Module;
import org.wildfly.extension.undertow.UndertowExtension;
import org.wildfly.extension.undertow.logging.UndertowLogger;

import javax.websocket.ClientEndpoint;
Expand Down Expand Up @@ -156,7 +160,7 @@ public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentU

WebSocketDeploymentInfo webSocketDeploymentInfo = new WebSocketDeploymentInfo();

doDeployment(webSocketDeploymentInfo, annotatedEndpoints, config, endpoints);
doDeployment(deploymentUnit, webSocketDeploymentInfo, annotatedEndpoints, config, endpoints);

installWebsockets(phaseContext, webSocketDeploymentInfo);

Expand All @@ -171,7 +175,7 @@ private void installWebsockets(final DeploymentPhaseContext phaseContext, final
deploymentUnit.putAttachment(UndertowAttachments.WEB_SOCKET_DEPLOYMENT_INFO, webSocketDeploymentInfo);
}

private void doDeployment(final WebSocketDeploymentInfo container, final Set<Class<?>> annotatedEndpoints, final Set<Class<? extends ServerApplicationConfig>> serverApplicationConfigClasses, final Set<Class<? extends Endpoint>> endpoints) throws DeploymentUnitProcessingException {
private void doDeployment(DeploymentUnit deploymentUnit, final WebSocketDeploymentInfo container, final Set<Class<?>> annotatedEndpoints, final Set<Class<? extends ServerApplicationConfig>> serverApplicationConfigClasses, final Set<Class<? extends Endpoint>> endpoints) throws DeploymentUnitProcessingException {

Set<Class<? extends Endpoint>> allScannedEndpointImplementations = new HashSet<>(endpoints);
Set<Class<?>> allScannedAnnotatedEndpoints = new HashSet<>(annotatedEndpoints);
Expand Down Expand Up @@ -205,11 +209,33 @@ private void doDeployment(final WebSocketDeploymentInfo container, final Set<Cla

//annotated endpoints first
for (Class<?> endpoint : newAnnotatatedEndpoints) {
container.addEndpoint(endpoint);
if(endpoint != null ) {
container.addEndpoint(endpoint);
ServerEndpoint annotation = endpoint.getAnnotation(ServerEndpoint.class);
if (annotation != null) {
String path = annotation.value();
addManagementWebsocket(deploymentUnit, endpoint, path);
}
}
}

for (final ServerEndpointConfig endpoint : serverEndpointConfigurations) {
container.addEndpoint(endpoint);
if(endpoint != null) {
container.addEndpoint(endpoint);
addManagementWebsocket(deploymentUnit, endpoint.getEndpointClass(), endpoint.getPath());
}
}
}

void addManagementWebsocket(final DeploymentUnit unit, Class endpoint, String path) {
try {
final DeploymentResourceSupport deploymentResourceSupport = unit.getAttachment(Attachments.DEPLOYMENT_RESOURCE_SUPPORT);
//websockets don't have the concept of a name, however the path much be unique
final ModelNode node = deploymentResourceSupport.getDeploymentSubModel(UndertowExtension.SUBSYSTEM_NAME, PathElement.pathElement("websocket", path));
node.get("endpoint-class").set(endpoint.getName());
node.get("path").set(path);
} catch (Exception e) {
UndertowLogger.ROOT_LOGGER.failedToRegisterWebsocket(endpoint, path, e);
}
}

Expand Down
Expand Up @@ -328,4 +328,7 @@ public interface UndertowLogger extends BasicLogger {
@Message(id = 76, value = "Cannot remove resource of type %s")
IllegalArgumentException cannotRemoveResourceOfType(String type);

@LogMessage(level = ERROR)
@Message(id = 78, value = "Failed to register management view for websocket %s at %s")
void failedToRegisterWebsocket(Class endpoint, String path, @Cause Exception e);
}
Expand Up @@ -343,6 +343,10 @@ undertow.deployment.servlet.max-request-time=Maximal time for processing request
undertow.deployment.servlet.total-request-time=Total time spend in processing all requests
undertow.deployment.servlet.request-count=Number of all requests
undertow.deployment.servlet.mappings=Servlet mappings
undertow.deployment.websocket=Websocket
undertow.deployment.websocket.endpoint-class=The endpoint class
undertow.deployment.websocket.path=The path the endpoint is deployed to


undertow.filter.mod-cluster=A mod-cluster front end load balancer
undertow.handler.mod-cluster=A mod-cluster front end load balancer
Expand Down

0 comments on commit 255f204

Please sign in to comment.