Skip to content

Commit

Permalink
[JBWS-3739] Enforce jbossws-spi metadata immutability
Browse files Browse the repository at this point in the history
  • Loading branch information
asoldano authored and bstansberry committed May 12, 2014
1 parent 0a278b0 commit e32f27d
Show file tree
Hide file tree
Showing 18 changed files with 250 additions and 344 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentU
}

//extract SOAP-over-JMS 1.0 bindings
final JMSEndpointsMetaData endpointsMetaData = new JMSEndpointsMetaData();
List<JMSEndpointMetaData> list = new LinkedList<JMSEndpointMetaData>();
if (!map.isEmpty()) {

for (String wsdlLocation : map.keySet()) {
Expand All @@ -114,14 +114,7 @@ public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentU
ClassInfo webServiceClassInfo = (ClassInfo) ai.target();
String beanClassName = webServiceClassInfo.name().toString();
//service name ?
JMSEndpointMetaData endpointMetaData = new JMSEndpointMetaData(endpointsMetaData);
endpointMetaData.setEndpointName(port);
endpointMetaData.setName(beanClassName);
endpointMetaData.setImplementor(beanClassName);
//endpointMetaData.setName(name);
endpointMetaData.setSoapAddress(soapAddress);
endpointMetaData.setWsdlLocation(wsdlLocation);
endpointsMetaData.addEndpointMetaData(endpointMetaData);
list.add(new JMSEndpointMetaData(beanClassName, port, beanClassName, wsdlLocation, soapAddress));
}
}
} catch (Exception ignore) {
Expand All @@ -130,7 +123,7 @@ public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentU
}

}
unit.putAttachment(JMS_ENDPOINT_METADATA_KEY, endpointsMetaData);
unit.putAttachment(JMS_ENDPOINT_METADATA_KEY, new JMSEndpointsMetaData(list));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,14 @@
import org.jboss.as.webservices.util.ASHelper;
import org.jboss.as.webservices.util.WSServices;
import org.jboss.dmr.ModelNode;
import org.jboss.msc.inject.Injector;
import org.jboss.msc.service.ServiceBuilder;
import org.jboss.msc.service.ServiceController;
import org.jboss.msc.service.ServiceName;
import org.jboss.msc.service.ServiceTarget;
import org.jboss.msc.service.ServiceBuilder.DependencyType;
import org.jboss.wsf.spi.management.ServerConfig;
import org.jboss.wsf.spi.metadata.j2ee.serviceref.UnifiedHandlerChainMetaData;

/**
* @author <a href="mailto:alessio.soldano@jboss.com">Alessio Soldano</a>
Expand Down Expand Up @@ -77,7 +80,10 @@ protected void performRuntime(final OperationContext context, final ModelNode op
final ConfigService clientConfigService = new ConfigService(serverConfig, name, true);
final ServiceTarget target = context.getServiceTarget();
final ServiceBuilder<?> clientServiceBuilder = target.addService(serviceName, clientConfigService);

setDependency(context, clientServiceBuilder, clientConfigService.getPreHandlerChainsInjector(), serviceName, address, Constants.PRE_HANDLER_CHAIN);
final Injector<UnifiedHandlerChainMetaData> postInjector = clientConfigService.getPostHandlerChainsInjector();
setDependency(context, clientServiceBuilder, postInjector, serviceName, address, Constants.POST_HANDLER_CHAIN);
clientServiceBuilder.addDependency(DependencyType.OPTIONAL, ServiceName.JBOSS.append("xts").append("handlers"), UnifiedHandlerChainMetaData.class, postInjector);
ServiceController<?> controller = clientServiceBuilder.setInitialMode(ServiceController.Mode.ACTIVE).install();
if (newControllers != null) {
newControllers.add(controller);
Expand All @@ -86,4 +92,11 @@ protected void performRuntime(final OperationContext context, final ModelNode op
context.reloadRequired();
}
}

private void setDependency(final OperationContext context, final ServiceBuilder<?> builder, final Injector<UnifiedHandlerChainMetaData> injector,
final ServiceName serviceName, final PathAddress address, final String handlerChainType) {
for (ServiceName sn : PackageUtils.getServiceNameDependencies(context, serviceName, address, handlerChainType)) {
builder.addDependency(sn, UnifiedHandlerChainMetaData.class, injector);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,13 @@
import org.jboss.as.webservices.util.ASHelper;
import org.jboss.as.webservices.util.WSServices;
import org.jboss.dmr.ModelNode;
import org.jboss.msc.inject.Injector;
import org.jboss.msc.service.ServiceBuilder;
import org.jboss.msc.service.ServiceController;
import org.jboss.msc.service.ServiceName;
import org.jboss.msc.service.ServiceTarget;
import org.jboss.wsf.spi.management.ServerConfig;
import org.jboss.wsf.spi.metadata.j2ee.serviceref.UnifiedHandlerChainMetaData;

/**
* @author <a href="ema@redhat.com">Jim Ma</a>
Expand Down Expand Up @@ -81,6 +83,8 @@ protected void performRuntime(final OperationContext context, final ModelNode op

final ServiceTarget target = context.getServiceTarget();
final ServiceBuilder<?> clientServiceBuilder = target.addService(serviceName, endpointConfigService);
setDependency(context, clientServiceBuilder, endpointConfigService.getPreHandlerChainsInjector(), serviceName, address, Constants.PRE_HANDLER_CHAIN);
setDependency(context, clientServiceBuilder, endpointConfigService.getPostHandlerChainsInjector(), serviceName, address, Constants.POST_HANDLER_CHAIN);
ServiceController<?> controller = clientServiceBuilder.setInitialMode(ServiceController.Mode.ACTIVE).install();
if (newControllers != null) {
newControllers.add(controller);
Expand All @@ -89,4 +93,11 @@ protected void performRuntime(final OperationContext context, final ModelNode op
context.reloadRequired();
}
}

private void setDependency(final OperationContext context, final ServiceBuilder<?> builder, final Injector<UnifiedHandlerChainMetaData> injector,
final ServiceName serviceName, final PathAddress address, final String handlerChainType) {
for (ServiceName sn : PackageUtils.getServiceNameDependencies(context, serviceName, address, handlerChainType)) {
builder.addDependency(sn, UnifiedHandlerChainMetaData.class, injector);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* JBoss, Home of Professional Open Source.
* Copyright 2012, Red Hat, Inc., and individual contributors
* 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.
*
Expand Down Expand Up @@ -43,7 +43,6 @@
import org.jboss.msc.service.ServiceName;
import org.jboss.msc.service.ServiceRegistry;
import org.jboss.msc.service.ServiceTarget;
import org.jboss.wsf.spi.metadata.j2ee.serviceref.UnifiedHandlerChainMetaData;

/**
* @author <a href="mailto:alessio.soldano@jboss.com">Alessio Soldano</a>
Expand Down Expand Up @@ -73,6 +72,7 @@ protected void performRuntime(final OperationContext context, final ModelNode op
final PathElement confElem = address.getElement(address.size() - 3);
final String configType = confElem.getKey();
final String configName = confElem.getValue();
final String handlerChainType = address.getElement(address.size() - 2).getKey();
final String handlerChainId = address.getElement(address.size() - 2).getValue();
final String handlerName = address.getElement(address.size() - 1).getValue();
final String handlerClass = operation.require(CLASS).asString();
Expand All @@ -84,15 +84,13 @@ protected void performRuntime(final OperationContext context, final ModelNode op
if (registry.getService(configServiceName) == null) {
throw MESSAGES.missingConfig(configName);
}
final ServiceName handlerChainServiceName = getHandlerChainServiceName(configServiceName, handlerChainId);
final ServiceName handlerChainServiceName = getHandlerChainServiceName(configServiceName, handlerChainType, handlerChainId);
if (registry.getService(handlerChainServiceName) == null) {
String handlerChainType = address.getElement(address.size() - 2).getKey();
throw MESSAGES.missingHandlerChain(configName, handlerChainType, handlerChainId);
}
final ServiceName handlerServiceName = getHandlerServiceName(handlerChainServiceName, handlerName);

final ServiceBuilder<?> handlerServiceBuilder = target.addService(handlerServiceName, service);
handlerServiceBuilder.addDependency(handlerChainServiceName, UnifiedHandlerChainMetaData.class, service.getHandlerChain());
ServiceController<?> controller = handlerServiceBuilder.setInitialMode(ServiceController.Mode.ACTIVE).install();
if (newControllers != null) {
newControllers.add(controller);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP_ADDR;
import static org.jboss.as.webservices.WSMessages.MESSAGES;
import static org.jboss.as.webservices.dmr.Constants.HANDLER;
import static org.jboss.as.webservices.dmr.Constants.PROTOCOL_BINDINGS;
import static org.jboss.as.webservices.dmr.PackageUtils.getConfigServiceName;
import static org.jboss.as.webservices.dmr.PackageUtils.getHandlerChainServiceName;
Expand All @@ -37,11 +38,12 @@
import org.jboss.as.controller.ServiceVerificationHandler;
import org.jboss.as.webservices.service.HandlerChainService;
import org.jboss.dmr.ModelNode;
import org.jboss.msc.inject.Injector;
import org.jboss.msc.service.ServiceBuilder;
import org.jboss.msc.service.ServiceController;
import org.jboss.msc.service.ServiceName;
import org.jboss.msc.service.ServiceTarget;
import org.jboss.wsf.spi.metadata.config.AbstractCommonConfig;
import org.jboss.wsf.spi.metadata.j2ee.serviceref.UnifiedHandlerMetaData;

/**
* @author <a href="mailto:ropalka@redhat.com">Richard Opalka</a>
Expand Down Expand Up @@ -80,11 +82,14 @@ protected void performRuntime(final OperationContext context, final ModelNode op
throw MESSAGES.missingConfig(configName);
}

final ServiceName handlerChainServiceName = getHandlerChainServiceName(configServiceName, handlerChainId);
final HandlerChainService<AbstractCommonConfig> service = new HandlerChainService<AbstractCommonConfig>(handlerChainType, handlerChainId, protocolBindings);
final ServiceName handlerChainServiceName = getHandlerChainServiceName(configServiceName, handlerChainType, handlerChainId);
final HandlerChainService service = new HandlerChainService(handlerChainType, handlerChainId, protocolBindings);
final ServiceTarget target = context.getServiceTarget();
final ServiceBuilder<?> handlerChainServiceBuilder = target.addService(handlerChainServiceName, service);
handlerChainServiceBuilder.addDependency(configServiceName, AbstractCommonConfig.class, service.getAbstractCommonConfig());
final Injector<UnifiedHandlerMetaData> injector = service.getHandlersInjector();
for (ServiceName sn : PackageUtils.getServiceNameDependencies(context, handlerChainServiceName, address, HANDLER)) {
handlerChainServiceBuilder.addDependency(sn, UnifiedHandlerMetaData.class, injector);
}
ServiceController<?> controller = handlerChainServiceBuilder.setInitialMode(ServiceController.Mode.ACTIVE).install();
if (newControllers != null) {
newControllers.add(controller);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package org.jboss.as.webservices.dmr;

import java.util.List;

import org.jboss.msc.inject.InjectionException;
import org.jboss.msc.inject.Injector;
import org.jboss.msc.inject.RetainingInjector;
import org.jboss.msc.value.Value;

public final class ListInjector<T> extends RetainingInjector<T> implements Injector<T> {
private final List<T> list;

public ListInjector(final List<T> list) {
this.list = list;
}

/** {@inheritDoc} */
public void inject(final T value) throws InjectionException {
synchronized (list) {
list.add(value);
super.inject(value);
}
}

/** {@inheritDoc} */
public void uninject() {
synchronized (list) {
try {
final Value<T> storedValue = getStoredValue();
if (storedValue != null) list.remove(storedValue.getValue());
} finally {
super.uninject();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,15 @@

import static org.jboss.as.webservices.dmr.Constants.ENDPOINT_CONFIG;
import static org.jboss.as.webservices.dmr.Constants.HANDLER;
import static org.jboss.as.webservices.dmr.Constants.HANDLER_CHAIN;
import static org.jboss.as.webservices.dmr.Constants.PROPERTY;

import java.util.LinkedList;
import java.util.List;

import org.jboss.as.controller.OperationContext;
import org.jboss.as.controller.PathAddress;
import org.jboss.as.controller.registry.Resource;
import org.jboss.as.controller.registry.Resource.ResourceEntry;
import org.jboss.as.webservices.util.WSServices;
import org.jboss.msc.service.ServiceName;

Expand All @@ -52,12 +58,8 @@ static ServiceName getConfigServiceName(final String configType, final String co
return (ENDPOINT_CONFIG.equals(configType) ? getEndpointConfigServiceName(configName) : getClientConfigServiceName(configName));
}

static ServiceName getHandlerChainServiceName(final String configType, final String configName, final String handlerChainId) {
return getHandlerChainServiceName(getConfigServiceName(configType, configName), handlerChainId);
}

static ServiceName getHandlerChainServiceName(final ServiceName configServiceName, final String handlerChainId) {
return configServiceName.append(HANDLER_CHAIN).append(handlerChainId);
static ServiceName getHandlerChainServiceName(final ServiceName configServiceName, final String handlerChainType, final String handlerChainId) {
return configServiceName.append(handlerChainType).append(handlerChainId);
}

static ServiceName getHandlerServiceName(final ServiceName handlerChainServiceName, final String handlerName) {
Expand All @@ -68,4 +70,13 @@ static ServiceName getPropertyServiceName(final ServiceName configServiceName, f
return configServiceName.append(PROPERTY).append(propertyName);
}

static List<ServiceName> getServiceNameDependencies(final OperationContext context, final ServiceName baseServiceName, final PathAddress address, final String childType) {
final List<ServiceName> childrenServiceNames = new LinkedList<ServiceName>();
final Resource resource = context.readResourceFromRoot(address);
final ServiceName sn = baseServiceName.append(childType);
for (ResourceEntry re : resource.getChildren(childType)) {
childrenServiceNames.add(sn.append(re.getName()));
}
return childrenServiceNames;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -133,21 +133,6 @@ private static void readConfigServiceNames(List<ServiceName> serviceNames, Resou
ServiceName configServiceName = Constants.CLIENT_CONFIG.equals(configType) ? PackageUtils
.getClientConfigServiceName(re.getName()) : PackageUtils.getEndpointConfigServiceName(re.getName());
serviceNames.add(configServiceName);
readHandlerChainServiceNames(serviceNames, re, Constants.PRE_HANDLER_CHAIN, configServiceName);
readHandlerChainServiceNames(serviceNames, re, Constants.POST_HANDLER_CHAIN, configServiceName);
for (String propertyName : re.getChildrenNames(Constants.PROPERTY)) {
serviceNames.add(PackageUtils.getPropertyServiceName(configServiceName, propertyName));
}
}
}

private static void readHandlerChainServiceNames(List<ServiceName> serviceNames, Resource configResource, String chainType, ServiceName configServiceName) {
for (ResourceEntry re : configResource.getChildren(chainType)) {
ServiceName handlerChainServiceName = PackageUtils.getHandlerChainServiceName(configServiceName, re.getName());
serviceNames.add(handlerChainServiceName);
for (String handlerName : re.getChildrenNames(Constants.HANDLER)) {
serviceNames.add(PackageUtils.getHandlerServiceName(handlerChainServiceName, handlerName));
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@
*/
package org.jboss.as.webservices.service;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;

import org.jboss.as.webservices.dmr.ListInjector;
import org.jboss.msc.inject.Injector;
import org.jboss.msc.service.Service;
import org.jboss.msc.service.StartContext;
import org.jboss.msc.service.StartException;
Expand All @@ -29,6 +35,7 @@
import org.jboss.wsf.spi.metadata.config.AbstractCommonConfig;
import org.jboss.wsf.spi.metadata.config.ClientConfig;
import org.jboss.wsf.spi.metadata.config.EndpointConfig;
import org.jboss.wsf.spi.metadata.j2ee.serviceref.UnifiedHandlerChainMetaData;

/**
* A service for setting a ws client / endpoint config.
Expand All @@ -41,6 +48,8 @@ public final class ConfigService implements Service<AbstractCommonConfig> {
private final ServerConfig serverConfig;
private final String configName;
private final boolean client;
private final List<UnifiedHandlerChainMetaData> preHandlerChains = new ArrayList<UnifiedHandlerChainMetaData>(1);
private final List<UnifiedHandlerChainMetaData> postHandlerChains = new ArrayList<UnifiedHandlerChainMetaData>(1);
private volatile AbstractCommonConfig config;

public ConfigService(ServerConfig serverConfig, String configName, boolean client) {
Expand All @@ -59,11 +68,15 @@ public void start(final StartContext context) throws StartException {
if (client) {
ClientConfig clientConfig = new ClientConfig();
clientConfig.setConfigName(configName);
clientConfig.setPreHandlerChains(new CopyOnWriteArrayList<UnifiedHandlerChainMetaData>(preHandlerChains));
clientConfig.setPostHandlerChains(new CopyOnWriteArrayList<UnifiedHandlerChainMetaData>(postHandlerChains));
serverConfig.addClientConfig(clientConfig);
config = clientConfig;
} else {
EndpointConfig endpointConfig = new EndpointConfig();
endpointConfig.setConfigName(configName);
endpointConfig.setPreHandlerChains(new CopyOnWriteArrayList<UnifiedHandlerChainMetaData>(preHandlerChains));
endpointConfig.setPostHandlerChains(new CopyOnWriteArrayList<UnifiedHandlerChainMetaData>(postHandlerChains));
serverConfig.addEndpointConfig(endpointConfig);
config = endpointConfig;
}
Expand All @@ -77,4 +90,13 @@ public void stop(final StopContext context) {
serverConfig.getEndpointConfigs().remove(config);
}
}

public Injector<UnifiedHandlerChainMetaData> getPreHandlerChainsInjector() {
return new ListInjector<UnifiedHandlerChainMetaData>(preHandlerChains);
}

public Injector<UnifiedHandlerChainMetaData> getPostHandlerChainsInjector() {
return new ListInjector<UnifiedHandlerChainMetaData>(postHandlerChains);
}

}
Loading

0 comments on commit e32f27d

Please sign in to comment.