repo
stringlengths
1
191
file
stringlengths
23
351
code
stringlengths
0
5.32M
file_length
int64
0
5.32M
avg_line_length
float64
0
2.9k
max_line_length
int64
0
288k
extension_type
stringclasses
1 value
null
wildfly-main/webservices/server-integration/src/main/java/org/jboss/as/webservices/dmr/WSSubsystemAdd.java
/* * JBoss, Home of Professional Open Source. * Copyright 2012, 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.jboss.as.webservices.dmr; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.SUBSYSTEM; import static org.jboss.as.webservices.dmr.Constants.WSDL_HOST; import static org.jboss.as.webservices.dmr.Constants.WSDL_PATH_REWRITE_RULE; import static org.jboss.as.webservices.dmr.Constants.WSDL_PORT; import static org.jboss.as.webservices.dmr.Constants.WSDL_SECURE_PORT; import static org.jboss.as.webservices.dmr.Constants.WSDL_URI_SCHEME; import java.net.UnknownHostException; import java.util.ArrayList; import java.util.List; import org.jboss.as.controller.AbstractBoottimeAddStepHandler; import org.jboss.as.controller.AttributeDefinition; import org.jboss.as.controller.OperationContext; import org.jboss.as.controller.OperationFailedException; import org.jboss.as.controller.PathAddress; import org.jboss.as.controller.PathElement; import org.jboss.as.controller.ProcessType; import org.jboss.as.controller.registry.Resource; import org.jboss.as.jmx.JMXExtension; import org.jboss.as.server.AbstractDeploymentChainStep; import org.jboss.as.server.DeploymentProcessorTarget; import org.jboss.as.web.host.CommonWebServer; import org.jboss.as.webservices.config.ServerConfigFactoryImpl; import org.jboss.as.webservices.config.ServerConfigImpl; import org.jboss.as.webservices.logging.WSLogger; import org.jboss.as.webservices.service.ServerConfigService; import org.jboss.as.webservices.service.XTSClientIntegrationService; import org.jboss.as.webservices.util.ModuleClassLoaderProvider; import org.jboss.dmr.ModelNode; import org.jboss.msc.service.ServiceName; import org.jboss.msc.service.ServiceTarget; /** * @author <a href="mailto:[email protected]">Alessio Soldano</a> * @author <a href="mailto:[email protected]">Darran Lofthouse</a> * @author <a href="mailto:[email protected]">Richard Opalka</a> */ class WSSubsystemAdd extends AbstractBoottimeAddStepHandler { static final WSSubsystemAdd INSTANCE = new WSSubsystemAdd(); @Override protected void populateModel(final ModelNode operation, final ModelNode model) throws OperationFailedException { Attributes.STATISTICS_ENABLED.validateAndSet(operation, model); for (AttributeDefinition attr : Attributes.SUBSYSTEM_ATTRIBUTES) { attr.validateAndSet(operation, model); } } protected void performBoottime(OperationContext context, ModelNode operation, ModelNode model) throws OperationFailedException { WSLogger.ROOT_LOGGER.activatingWebservicesExtension(); ModuleClassLoaderProvider.register(); final boolean appclient = context.getProcessType() == ProcessType.APPLICATION_CLIENT; context.addStep(new AbstractDeploymentChainStep() { protected void execute(DeploymentProcessorTarget processorTarget) { // add the DUP for dealing with WS deployments WSDeploymentActivator.activate(processorTarget, appclient); } }, OperationContext.Stage.RUNTIME); ServiceTarget serviceTarget = context.getServiceTarget(); final boolean jmxAvailable = isJMXSubsystemAvailable(context); if (appclient && model.hasDefined(WSDL_HOST)) { ServerConfigImpl serverConfig = createServerConfig(model, true, context); ServerConfigFactoryImpl.setConfig(serverConfig); ServerConfigService.install(serviceTarget, serverConfig, getServerConfigDependencies(context, appclient), jmxAvailable, false); } if (!appclient) { ServerConfigImpl serverConfig = createServerConfig(model, false, context); ServerConfigFactoryImpl.setConfig(serverConfig); ServerConfigService.install(serviceTarget, serverConfig, getServerConfigDependencies(context, appclient), jmxAvailable, true); } XTSClientIntegrationService.install(serviceTarget); } private static ServerConfigImpl createServerConfig(ModelNode configuration, boolean appclient, OperationContext context) throws OperationFailedException { final ServerConfigImpl config = ServerConfigImpl.newInstance(); try { ModelNode wsdlHost = Attributes.WSDL_HOST.resolveModelAttribute(context, configuration); config.setWebServiceHost(wsdlHost.isDefined() ? wsdlHost.asString() : null); } catch (UnknownHostException e) { throw new RuntimeException(e); } if (!appclient) { config.setModifySOAPAddress(Attributes.MODIFY_WSDL_ADDRESS.resolveModelAttribute(context, configuration).asBoolean()); config.setStatisticsEnabled(Attributes.STATISTICS_ENABLED.resolveModelAttribute(context, configuration).asBoolean()); } if (configuration.hasDefined(WSDL_PORT)) { config.setWebServicePort(Attributes.WSDL_PORT.resolveModelAttribute(context, configuration).asInt()); } if (configuration.hasDefined(WSDL_SECURE_PORT)) { config.setWebServiceSecurePort(Attributes.WSDL_SECURE_PORT.resolveModelAttribute(context, configuration).asInt()); } if (configuration.hasDefined(WSDL_URI_SCHEME)) { config.setWebServiceUriScheme(Attributes.WSDL_URI_SCHEME.resolveModelAttribute(context, configuration).asString()); } if (configuration.hasDefined(WSDL_PATH_REWRITE_RULE)) { config.setWebServicePathRewriteRule(Attributes.WSDL_PATH_REWRITE_RULE.resolveModelAttribute(context, configuration).asString()); } return config; } /** * Process the model to figure out the name of the services the server config service has to depend on * */ private static List<ServiceName> getServerConfigDependencies(OperationContext context, boolean appclient) { final List<ServiceName> serviceNames = new ArrayList<ServiceName>(); final Resource subsystemResource = context.readResourceFromRoot(PathAddress.pathAddress(WSExtension.SUBSYSTEM_PATH), false); readConfigServiceNames(serviceNames, subsystemResource, Constants.CLIENT_CONFIG); readConfigServiceNames(serviceNames, subsystemResource, Constants.ENDPOINT_CONFIG); if (!appclient) { serviceNames.add(CommonWebServer.SERVICE_NAME); } return serviceNames; } private static void readConfigServiceNames(List<ServiceName> serviceNames, Resource subsystemResource, String configType) { for (String name : subsystemResource.getChildrenNames(configType)) { ServiceName configServiceName = Constants.CLIENT_CONFIG.equals(configType) ? PackageUtils .getClientConfigServiceName(name) : PackageUtils.getEndpointConfigServiceName(name); serviceNames.add(configServiceName); } } private static boolean isJMXSubsystemAvailable(final OperationContext context) { Resource root = context.readResourceFromRoot(PathAddress.pathAddress(PathAddress.EMPTY_ADDRESS), false); return root.hasChild(PathElement.pathElement(SUBSYSTEM, JMXExtension.SUBSYSTEM_NAME)); } }
8,104
51.290323
158
java
null
wildfly-main/webservices/server-integration/src/main/java/org/jboss/as/webservices/dmr/PropertyAdd.java
/* * JBoss, Home of Professional Open Source. * Copyright 2012, 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.jboss.as.webservices.dmr; import static org.jboss.as.webservices.dmr.PackageUtils.getConfigServiceName; import static org.jboss.as.webservices.dmr.PackageUtils.getPropertyServiceName; import org.jboss.as.controller.AbstractAddStepHandler; import org.jboss.as.controller.OperationContext; import org.jboss.as.controller.OperationFailedException; import org.jboss.as.controller.PathAddress; import org.jboss.as.controller.PathElement; import org.jboss.as.controller.registry.Resource; import org.jboss.as.webservices.logging.WSLogger; import org.jboss.as.webservices.service.PropertyService; import org.jboss.dmr.ModelNode; import org.jboss.msc.service.ServiceBuilder; import org.jboss.msc.service.ServiceName; import org.jboss.msc.service.ServiceTarget; import java.util.function.Consumer; /** * @author <a href="mailto:[email protected]">Alessio Soldano</a> * @author <a href="mailto:[email protected]">Richard Opalka</a> */ final class PropertyAdd extends AbstractAddStepHandler { static final PropertyAdd INSTANCE = new PropertyAdd(); private PropertyAdd() { // forbidden instantiation } @Override protected void rollbackRuntime(OperationContext context, ModelNode operation, Resource resource) { super.rollbackRuntime(context, operation, resource); if (!context.isBooting()) { context.revertReloadRequired(); } } @Override protected void performRuntime(final OperationContext context, final ModelNode operation, final ModelNode model) throws OperationFailedException { //modify the runtime if we're booting, otherwise set reload required and leave the runtime unchanged if (context.isBooting()) { final PathAddress address = context.getCurrentAddress(); final String propertyName = context.getCurrentAddressValue(); final PathElement confElem = address.getElement(address.size() - 2); final String configType = confElem.getKey(); final String configName = confElem.getValue(); final String propertyValue = Attributes.VALUE.resolveModelAttribute(context, model).asStringOrNull(); final ServiceTarget target = context.getServiceTarget(); final ServiceName configServiceName = getConfigServiceName(configType, configName); if (context.getServiceRegistry(false).getService(configServiceName) == null) { throw WSLogger.ROOT_LOGGER.missingConfig(configName); } final ServiceName propertyServiceName = getPropertyServiceName(configServiceName, propertyName); final ServiceBuilder<?> propertyServiceBuilder = target.addService(propertyServiceName); final Consumer<PropertyService> propertyServiceConsumer = propertyServiceBuilder.provides(propertyServiceName); propertyServiceBuilder.setInstance(new PropertyService(propertyName, propertyValue, propertyServiceConsumer)); propertyServiceBuilder.install(); } else { context.reloadRequired(); } } @Override protected void populateModel(final ModelNode operation, final ModelNode model) throws OperationFailedException { Attributes.VALUE.validateAndSet(operation,model); } }
4,313
45.891304
149
java
null
wildfly-main/webservices/server-integration/src/main/java/org/jboss/as/webservices/dmr/Attributes.java
/* * * JBoss, Home of Professional Open Source. * Copyright 2012, Red Hat Middleware LLC, 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.jboss.as.webservices.dmr; import org.jboss.as.controller.SimpleAttributeDefinition; import org.jboss.as.controller.SimpleAttributeDefinitionBuilder; import org.jboss.as.controller.operations.validation.EnumValidator; import org.jboss.as.controller.operations.validation.IntRangeValidator; import org.jboss.dmr.ModelNode; import org.jboss.dmr.ModelType; /** * @author <a href="mailto:[email protected]">Tomaz Cerar</a> (c) 2012 Red Hat Inc. * @author <a href="mailto:[email protected]">Alessio Soldano</a> * @author <a href="mailto:[email protected]">Jim Ma</a> */ interface Attributes { SimpleAttributeDefinition WSDL_HOST = new SimpleAttributeDefinitionBuilder(Constants.WSDL_HOST, ModelType.STRING) .setRequired(false) .setMinSize(1) .setAllowExpression(true) .setValidator(new AddressValidator(true, true)) .build(); SimpleAttributeDefinition WSDL_PORT = new SimpleAttributeDefinitionBuilder(Constants.WSDL_PORT, ModelType.INT) .setRequired(false) .setMinSize(1) .setValidator(new IntRangeValidator(1, true, true)) .setAllowExpression(true) .build(); SimpleAttributeDefinition WSDL_SECURE_PORT = new SimpleAttributeDefinitionBuilder(Constants.WSDL_SECURE_PORT, ModelType.INT) .setRequired(false) .setMinSize(1) .setValidator(new IntRangeValidator(1, true, true)) .setAllowExpression(true) .build(); SimpleAttributeDefinition WSDL_URI_SCHEME = new SimpleAttributeDefinitionBuilder(Constants.WSDL_URI_SCHEME, ModelType.STRING) .setRequired(false) .setMinSize(1) .setValidator(EnumValidator.create(WsdlUriSchema.class)) .setAllowExpression(true) .build(); enum WsdlUriSchema {http, https} SimpleAttributeDefinition MODIFY_WSDL_ADDRESS = new SimpleAttributeDefinitionBuilder(Constants.MODIFY_WSDL_ADDRESS, ModelType.BOOLEAN) .setRequired(false) .setDefaultValue(ModelNode.TRUE) .setAllowExpression(true) .build(); SimpleAttributeDefinition WSDL_PATH_REWRITE_RULE = new SimpleAttributeDefinitionBuilder(Constants.WSDL_PATH_REWRITE_RULE, ModelType.STRING) .setRequired(false) .setAllowExpression(false) .build(); SimpleAttributeDefinition STATISTICS_ENABLED = new SimpleAttributeDefinitionBuilder(Constants.STATISTICS_ENABLED, ModelType.BOOLEAN) .setRequired(false) .setDefaultValue(ModelNode.FALSE) .setAllowExpression(true) .build(); SimpleAttributeDefinition[] SUBSYSTEM_ATTRIBUTES = {MODIFY_WSDL_ADDRESS, WSDL_HOST, WSDL_PORT, WSDL_SECURE_PORT, WSDL_URI_SCHEME, WSDL_PATH_REWRITE_RULE}; SimpleAttributeDefinition VALUE = new SimpleAttributeDefinitionBuilder(Constants.VALUE, ModelType.STRING) .setRequired(false) .setAllowExpression(true) .build(); SimpleAttributeDefinition CLASS = new SimpleAttributeDefinitionBuilder(Constants.CLASS, ModelType.STRING) .setRequired(true) .build(); SimpleAttributeDefinition PROTOCOL_BINDINGS = new SimpleAttributeDefinitionBuilder(Constants.PROTOCOL_BINDINGS, ModelType.STRING) .setRequired(false) .setAllowExpression(true) .build(); }
4,483
43.39604
158
java
null
wildfly-main/webservices/server-integration/src/main/java/org/jboss/as/webservices/dmr/HandlerAdd.java
/* * 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.jboss.as.webservices.dmr; import static org.jboss.as.webservices.dmr.PackageUtils.getConfigServiceName; import static org.jboss.as.webservices.dmr.PackageUtils.getHandlerChainServiceName; import static org.jboss.as.webservices.dmr.PackageUtils.getHandlerServiceName; import java.util.concurrent.atomic.AtomicInteger; import java.util.function.Consumer; import org.jboss.as.controller.AbstractAddStepHandler; import org.jboss.as.controller.OperationContext; import org.jboss.as.controller.OperationFailedException; import org.jboss.as.controller.PathAddress; import org.jboss.as.controller.PathElement; import org.jboss.as.controller.registry.Resource; import org.jboss.as.webservices.logging.WSLogger; import org.jboss.as.webservices.service.HandlerService; import org.jboss.dmr.ModelNode; import org.jboss.msc.service.ServiceBuilder; 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.UnifiedHandlerMetaData; /** * @author <a href="mailto:[email protected]">Alessio Soldano</a> * @author <a href="mailto:[email protected]">Richard Opalka</a> */ final class HandlerAdd extends AbstractAddStepHandler { static final HandlerAdd INSTANCE = new HandlerAdd(); static final AtomicInteger counter = new AtomicInteger(0); private HandlerAdd() { // forbidden instantiation } @Override protected void rollbackRuntime(OperationContext context, ModelNode operation, Resource resource) { super.rollbackRuntime(context, operation, resource); if (!context.isBooting()) { context.revertReloadRequired(); } } @Override protected void performRuntime(final OperationContext context, final ModelNode operation, final ModelNode model) throws OperationFailedException { // modify the runtime if we're booting, otherwise set reload required and leave the runtime unchanged if (context.isBooting()) { final PathAddress address = context.getCurrentAddress(); 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 = Attributes.CLASS.resolveModelAttribute(context, model).asString(); final ServiceTarget target = context.getServiceTarget(); final ServiceName configServiceName = getConfigServiceName(configType, configName); final ServiceRegistry registry = context.getServiceRegistry(false); if (registry.getService(configServiceName) == null) { throw WSLogger.ROOT_LOGGER.missingConfig(configName); } final ServiceName handlerChainServiceName = getHandlerChainServiceName(configServiceName, handlerChainType, handlerChainId); if (registry.getService(handlerChainServiceName) == null) { throw WSLogger.ROOT_LOGGER.missingHandlerChain(configName, handlerChainType, handlerChainId); } final ServiceName handlerServiceName = getHandlerServiceName(handlerChainServiceName, handlerName); final ServiceBuilder<?> handlerServiceBuilder = target.addService(handlerServiceName); final Consumer<UnifiedHandlerMetaData> handlerConsumer = handlerServiceBuilder.provides(handlerServiceName); handlerServiceBuilder.setInstance(new HandlerService(handlerName, handlerClass, counter.incrementAndGet(), handlerConsumer)); handlerServiceBuilder.install(); } else { context.reloadRequired(); } } @Override protected void populateModel(final ModelNode operation, final ModelNode model) throws OperationFailedException { Attributes.CLASS.validateAndSet(operation, model); } }
5,222
48.742857
149
java
null
wildfly-main/webservices/server-integration/src/main/java/org/jboss/as/webservices/dmr/WSSubsystem11Reader.java
/* * JBoss, Home of Professional Open Source. * Copyright 2012, 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.jboss.as.webservices.dmr; import static javax.xml.stream.XMLStreamConstants.END_ELEMENT; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP_ADDR; import static org.jboss.as.controller.parsing.ParseUtils.requireNoAttributes; import static org.jboss.as.controller.parsing.ParseUtils.requireNoNamespaceAttribute; import static org.jboss.as.controller.parsing.ParseUtils.unexpectedAttribute; import static org.jboss.as.controller.parsing.ParseUtils.unexpectedElement; import static org.jboss.as.webservices.dmr.Constants.CLIENT_CONFIG; 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.POST_HANDLER_CHAIN; import static org.jboss.as.webservices.dmr.Constants.PRE_HANDLER_CHAIN; import static org.jboss.as.webservices.dmr.Constants.PROPERTY; import java.util.ArrayList; import java.util.EnumSet; import java.util.LinkedList; import java.util.List; import javax.xml.stream.XMLStreamException; import org.jboss.as.controller.PathAddress; import org.jboss.as.controller.operations.common.Util; import org.jboss.as.controller.parsing.ParseUtils; import org.jboss.dmr.ModelNode; import org.jboss.staxmapper.XMLElementReader; import org.jboss.staxmapper.XMLExtendedStreamReader; /** * @author <a href="mailto:[email protected]">Richard Opalka</a> * @author <a href="mailto:[email protected]">Alessio Soldano</a> * @author <a href="mailto:[email protected]">Jim Ma</a> */ class WSSubsystem11Reader implements XMLElementReader<List<ModelNode>> { WSSubsystem11Reader() { } @Override public void readElement(final XMLExtendedStreamReader reader, final List<ModelNode> list) throws XMLStreamException { final PathAddress address = PathAddress.pathAddress(WSExtension.SUBSYSTEM_PATH); final ModelNode subsystem = Util.createAddOperation(address); list.add(subsystem); readAttributes(reader, subsystem); // elements final EnumSet<Element> encountered = EnumSet.noneOf(Element.class); while (reader.hasNext() && reader.nextTag() != END_ELEMENT) { final Element element = Element.forName(reader.getLocalName()); switch (element) { case MODIFY_WSDL_ADDRESS: { if (!encountered.add(element)) { throw unexpectedElement(reader); } final String value = parseElementNoAttributes(reader); Attributes.MODIFY_WSDL_ADDRESS.parseAndSetParameter(value, subsystem, reader); break; } case WSDL_HOST: { if (!encountered.add(element)) { throw unexpectedElement(reader); } final String value = parseElementNoAttributes(reader); Attributes.WSDL_HOST.parseAndSetParameter(value, subsystem, reader); break; } case WSDL_PORT: { if (!encountered.add(element)) { throw unexpectedElement(reader); } final String value = parseElementNoAttributes(reader); Attributes.WSDL_PORT.parseAndSetParameter(value, subsystem, reader); break; } case WSDL_SECURE_PORT: { if (!encountered.add(element)) { throw unexpectedElement(reader); } final String value = parseElementNoAttributes(reader); Attributes.WSDL_SECURE_PORT.parseAndSetParameter(value, subsystem, reader); break; } case ENDPOINT_CONFIG: { List<ModelNode> configs = readConfig(reader, address, false); list.addAll(configs); break; } default: { handleUnknownElement(reader, address, element, list, encountered); } } } //TODO:check required element } protected void handleUnknownElement(final XMLExtendedStreamReader reader, final PathAddress parentAddress, Element element, List<ModelNode> list, EnumSet<Element> encountered) throws XMLStreamException { throw unexpectedElement(reader); } protected void readAttributes(final XMLExtendedStreamReader reader, final ModelNode operation) throws XMLStreamException { requireNoAttributes(reader); } protected String parseElementNoAttributes(final XMLExtendedStreamReader reader) throws XMLStreamException { // no attributes requireNoAttributes(reader); return reader.getElementText().trim(); } protected List<ModelNode> readConfig(final XMLExtendedStreamReader reader, final PathAddress parentAddress, final boolean client) throws XMLStreamException { final List<ModelNode> configs = new ArrayList<ModelNode>(); String configName = null; final int count = reader.getAttributeCount(); for (int i = 0; i < count; i++) { requireNoNamespaceAttribute(reader, i); final String value = reader.getAttributeValue(i); final Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i)); switch (attribute) { case NAME: configName = value; break; default: throw unexpectedAttribute(reader, i); } } final PathAddress address = parentAddress.append(client ? CLIENT_CONFIG : ENDPOINT_CONFIG, configName); final ModelNode node = Util.createAddOperation(address); configs.add(node); final EnumSet<Element> encountered = EnumSet.noneOf(Element.class); while (reader.nextTag() != END_ELEMENT) { final Element element = Element.forName(reader.getLocalName()); if (element != Element.PRE_HANDLER_CHAIN && element != Element.POST_HANDLER_CHAIN && element != Element.PROPERTY && !encountered.add(element)) { throw unexpectedElement(reader); } switch (element) { case PRE_HANDLER_CHAIN: { parseHandlerChain(reader, configs, true, address); break; } case POST_HANDLER_CHAIN: { parseHandlerChain(reader, configs, false, address); break; } case PROPERTY: { final ModelNode operation = parseProperty(reader, address); configs.add(operation); break; } default: { throw unexpectedElement(reader); } } } return configs; } private ModelNode parseProperty(final XMLExtendedStreamReader reader, PathAddress parentAddress) throws XMLStreamException { final ModelNode operation = Util.createAddOperation(null); String propertyName = null; final int count = reader.getAttributeCount(); for (int i = 0; i < count; i++) { requireNoNamespaceAttribute(reader, i); final String value = reader.getAttributeValue(i); final Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i)); switch (attribute) { case NAME: propertyName = value; break; case VALUE: Attributes.VALUE.parseAndSetParameter(value, operation, reader); break; default: throw unexpectedAttribute(reader, i); } } ParseUtils.requireNoContent(reader); operation.get(OP_ADDR).set(parentAddress.append(PROPERTY, propertyName).toModelNode()); return operation; } private void parseHandlerChain(final XMLExtendedStreamReader reader, final List<ModelNode> operationList, final boolean isPreHandlerChain, PathAddress parentAddress) throws XMLStreamException { final ModelNode operation = Util.createAddOperation(); String handlerChainId = null; final int count = reader.getAttributeCount(); for (int i = 0; i < count; i++) { requireNoNamespaceAttribute(reader, i); final String value = reader.getAttributeValue(i); final Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i)); switch (attribute) { case NAME: handlerChainId = value; break; case PROTOCOL_BINDINGS: Attributes.PROTOCOL_BINDINGS.parseAndSetParameter(value, operation, reader); break; default: throw unexpectedAttribute(reader, i); } } final String handlerChainType = isPreHandlerChain ? PRE_HANDLER_CHAIN : POST_HANDLER_CHAIN; PathAddress address = parentAddress.append(handlerChainType, handlerChainId); operation.get(OP_ADDR).set(address.toModelNode()); final EnumSet<Element> encountered = EnumSet.noneOf(Element.class); final List<ModelNode> addHandlerOperations = new LinkedList<ModelNode>(); while (reader.nextTag() != END_ELEMENT) { final Element element = Element.forName(reader.getLocalName()); if (element != Element.HANDLER && !encountered.add(element)) { throw unexpectedElement(reader); } switch (element) { case HANDLER: { parseHandler(reader, addHandlerOperations, address); break; } default: { throw unexpectedElement(reader); } } } operationList.add(operation); operationList.addAll(addHandlerOperations); } private void parseHandler(final XMLExtendedStreamReader reader, final List<ModelNode> operations, PathAddress parentAddress) throws XMLStreamException { String handlerName = null; final ModelNode operation = Util.createAddOperation(); final int count = reader.getAttributeCount(); for (int i = 0; i < count; i++) { requireNoNamespaceAttribute(reader, i); final String value = reader.getAttributeValue(i); final Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i)); switch (attribute) { case NAME: handlerName = value; break; case CLASS: Attributes.CLASS.parseAndSetParameter(value, operation, reader); break; default: throw unexpectedAttribute(reader, i); } } ParseUtils.requireNoContent(reader); operation.get(OP_ADDR).set(parentAddress.append(HANDLER, handlerName).toModelNode()); operations.add(operation); } }
12,356
43.934545
207
java
null
wildfly-main/webservices/server-integration/src/main/java/org/jboss/as/webservices/dmr/WSExtension.java
/* * JBoss, Home of Professional Open Source. * Copyright 2012, 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.jboss.as.webservices.dmr; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.SUBSYSTEM; import static org.jboss.as.webservices.dmr.Constants.CLIENT_CONFIG; import static org.jboss.as.webservices.dmr.Constants.ENDPOINT; 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.POST_HANDLER_CHAIN; import static org.jboss.as.webservices.dmr.Constants.PRE_HANDLER_CHAIN; import static org.jboss.as.webservices.dmr.Constants.PROPERTY; import static org.jboss.as.webservices.dmr.Constants.WSDL_URI_SCHEME; import org.jboss.as.controller.AttributeDefinition; import org.jboss.as.controller.Extension; import org.jboss.as.controller.ExtensionContext; import org.jboss.as.controller.ModelVersion; import org.jboss.as.controller.PathElement; import org.jboss.as.controller.ReloadRequiredRemoveStepHandler; import org.jboss.as.controller.ReloadRequiredWriteAttributeHandler; import org.jboss.as.controller.ResourceBuilder; import org.jboss.as.controller.ResourceDefinition; import org.jboss.as.controller.SimpleAttributeDefinitionBuilder; import org.jboss.as.controller.SubsystemRegistration; import org.jboss.as.controller.descriptions.StandardResourceDescriptionResolver; import org.jboss.as.controller.parsing.ExtensionParsingContext; import org.jboss.as.controller.registry.ManagementResourceRegistration; import org.jboss.dmr.ModelType; /** * The webservices extension. * * @author [email protected] * @author <a href="mailto:[email protected]">Darran Lofthouse</a> * @author <a href="mailto:[email protected]">Richard Opalka</a> * @author <a href="[email protected]">Jim Ma</a> */ public final class WSExtension implements Extension { static final PathElement ENDPOINT_PATH = PathElement.pathElement(ENDPOINT); static final PathElement CLIENT_CONFIG_PATH = PathElement.pathElement(CLIENT_CONFIG); static final PathElement WSDL_URI_SCHEME_PATH = PathElement.pathElement(WSDL_URI_SCHEME); static final PathElement ENDPOINT_CONFIG_PATH = PathElement.pathElement(ENDPOINT_CONFIG); private static final PathElement PROPERTY_PATH = PathElement.pathElement(PROPERTY); static final PathElement PRE_HANDLER_CHAIN_PATH = PathElement.pathElement(PRE_HANDLER_CHAIN); static final PathElement POST_HANDLER_CHAIN_PATH = PathElement.pathElement(POST_HANDLER_CHAIN); static final PathElement HANDLER_PATH = PathElement.pathElement(HANDLER); public static final String SUBSYSTEM_NAME = "webservices"; static final PathElement SUBSYSTEM_PATH = PathElement.pathElement(SUBSYSTEM, SUBSYSTEM_NAME); private static final String RESOURCE_NAME = WSExtension.class.getPackage().getName() + ".LocalDescriptions"; static final ModelVersion CURRENT_MODEL_VERSION = ModelVersion.create(3, 0, 0); static final ModelVersion MODEL_VERSION_2_0 = ModelVersion.create(2, 0, 0); static final ModelVersion MODEL_VERSION_1_2 = ModelVersion.create(1, 2, 0); // attributes on the endpoint element static final AttributeDefinition ENDPOINT_WSDL = new SimpleAttributeDefinitionBuilder( Constants.ENDPOINT_WSDL, ModelType.STRING, false) .setStorageRuntime() .build(); static final AttributeDefinition ENDPOINT_CLASS = new SimpleAttributeDefinitionBuilder( Constants.ENDPOINT_CLASS, ModelType.STRING, false) .setStorageRuntime() .build(); static final AttributeDefinition ENDPOINT_CONTEXT = new SimpleAttributeDefinitionBuilder( Constants.ENDPOINT_CONTEXT, ModelType.STRING, false) .setStorageRuntime() .build(); static final AttributeDefinition ENDPOINT_TYPE = new SimpleAttributeDefinitionBuilder( Constants.ENDPOINT_TYPE, ModelType.STRING, true) .setStorageRuntime() .build(); static final AttributeDefinition ENDPOINT_NAME = new SimpleAttributeDefinitionBuilder( Constants.ENDPOINT_NAME, ModelType.STRING, false) .setStorageRuntime() .build(); static StandardResourceDescriptionResolver getResourceDescriptionResolver(final String... keyPrefix) { StringBuilder prefix = new StringBuilder(SUBSYSTEM_NAME); for (String kp : keyPrefix) { prefix.append('.').append(kp); } return new StandardResourceDescriptionResolver(prefix.toString(), RESOURCE_NAME, WSExtension.class.getClassLoader(), true, false); } @Override public void initialize(final ExtensionContext context) { final boolean registerRuntimeOnly = context.isRuntimeOnlyRegistrationValid(); final SubsystemRegistration subsystem = context.registerSubsystem(SUBSYSTEM_NAME, CURRENT_MODEL_VERSION); subsystem.registerXMLElementWriter(new WSSubsystemWriter()); // ws subsystem ResourceBuilder propertyResource = ResourceBuilder.Factory.create(PROPERTY_PATH, getResourceDescriptionResolver(Constants.PROPERTY)) .setAddOperation(PropertyAdd.INSTANCE) .setRemoveOperation(ReloadRequiredRemoveStepHandler.INSTANCE) .addReadWriteAttribute(Attributes.VALUE, null, new ReloadRequiredWriteAttributeHandler(Attributes.VALUE)); ResourceBuilder handlerBuilder = ResourceBuilder.Factory.create(HANDLER_PATH, getResourceDescriptionResolver(HANDLER)) .setAddOperation(HandlerAdd.INSTANCE) .setRemoveOperation(ReloadRequiredRemoveStepHandler.INSTANCE) .addReadWriteAttribute(Attributes.CLASS, null, new ReloadRequiredWriteAttributeHandler(Attributes.CLASS)); ResourceBuilder preHandler = ResourceBuilder.Factory.create(PRE_HANDLER_CHAIN_PATH, getResourceDescriptionResolver(Constants.PRE_HANDLER_CHAIN)) .setAddOperation(HandlerChainAdd.INSTANCE) .setRemoveOperation(ReloadRequiredRemoveStepHandler.INSTANCE) .addReadWriteAttribute(Attributes.PROTOCOL_BINDINGS, null, new ReloadRequiredWriteAttributeHandler(Attributes.PROTOCOL_BINDINGS)) .pushChild(handlerBuilder).pop(); ResourceBuilder postHandler = ResourceBuilder.Factory.create(POST_HANDLER_CHAIN_PATH, getResourceDescriptionResolver(Constants.POST_HANDLER_CHAIN)) .setAddOperation(HandlerChainAdd.INSTANCE) .setRemoveOperation(ReloadRequiredRemoveStepHandler.INSTANCE) .addReadWriteAttribute(Attributes.PROTOCOL_BINDINGS, null, new ReloadRequiredWriteAttributeHandler(Attributes.PROTOCOL_BINDINGS)) .pushChild(handlerBuilder).pop(); ResourceDefinition epConfigsDef = ResourceBuilder.Factory.create(ENDPOINT_CONFIG_PATH, getResourceDescriptionResolver(ENDPOINT_CONFIG)) .setAddOperation(EndpointConfigAdd.INSTANCE) .setRemoveOperation(ReloadRequiredRemoveStepHandler.INSTANCE) .pushChild(propertyResource).pop() .pushChild(preHandler).pop() .pushChild(postHandler).pop() .build(); ResourceDefinition clConfigsDef = ResourceBuilder.Factory.create(CLIENT_CONFIG_PATH, getResourceDescriptionResolver(CLIENT_CONFIG)) .setAddOperation(ClientConfigAdd.INSTANCE) .setRemoveOperation(ReloadRequiredRemoveStepHandler.INSTANCE) .pushChild(propertyResource).pop() .pushChild(preHandler).pop() .pushChild(postHandler).pop() .build(); ResourceDefinition subsystemResource = ResourceBuilder.Factory.createSubsystemRoot(SUBSYSTEM_PATH, getResourceDescriptionResolver(), WSSubsystemAdd.INSTANCE, WSSubsystemRemove.INSTANCE) .addReadWriteAttribute(Attributes.WSDL_HOST, null, new WSServerConfigAttributeHandler(Attributes.WSDL_HOST)) .addReadWriteAttribute(Attributes.WSDL_PORT, null, new WSServerConfigAttributeHandler(Attributes.WSDL_PORT)) .addReadWriteAttribute(Attributes.WSDL_SECURE_PORT, null, new WSServerConfigAttributeHandler(Attributes.WSDL_SECURE_PORT)) .addReadWriteAttribute(Attributes.WSDL_URI_SCHEME, null, new WSServerConfigAttributeHandler(Attributes.WSDL_URI_SCHEME)) .addReadWriteAttribute(Attributes.WSDL_PATH_REWRITE_RULE, null, new WSServerConfigAttributeHandler(Attributes.WSDL_PATH_REWRITE_RULE)) .addReadWriteAttribute(Attributes.MODIFY_WSDL_ADDRESS, null, new WSServerConfigAttributeHandler(Attributes.MODIFY_WSDL_ADDRESS)) .addReadWriteAttribute(Attributes.STATISTICS_ENABLED, null, new WSServerConfigAttributeHandler(Attributes.STATISTICS_ENABLED)) .build(); ManagementResourceRegistration subsystemRegistration = subsystem.registerSubsystemModel(subsystemResource); subsystemRegistration.registerSubModel(epConfigsDef); subsystemRegistration.registerSubModel(clConfigsDef); if (registerRuntimeOnly) { subsystem.registerDeploymentModel(ResourceBuilder.Factory.create(SUBSYSTEM_PATH, getResourceDescriptionResolver("deployment")) .noFeature() .setRuntime() .pushChild(ENDPOINT_PATH) .addMetrics(WSEndpointMetrics.INSTANCE, WSEndpointMetrics.ATTRIBUTES) .addReadOnlyAttribute(ENDPOINT_CLASS) .addReadOnlyAttribute(ENDPOINT_CONTEXT) .addReadOnlyAttribute(ENDPOINT_NAME) .addReadOnlyAttribute(ENDPOINT_TYPE) .addReadOnlyAttribute(ENDPOINT_WSDL) .build()); } } @Override public void initializeParsers(final ExtensionParsingContext context) { context.setSubsystemXmlMapping(SUBSYSTEM_NAME, Namespace.WEBSERVICES_1_0.getUriString(), WSSubsystemLegacyReader::new); context.setSubsystemXmlMapping(SUBSYSTEM_NAME, Namespace.WEBSERVICES_1_1.getUriString(), WSSubsystem11Reader::new); context.setSubsystemXmlMapping(SUBSYSTEM_NAME, Namespace.WEBSERVICES_1_2.getUriString(), WSSubSystem12Reader::new); context.setSubsystemXmlMapping(SUBSYSTEM_NAME, Namespace.WEBSERVICES_2_0.getUriString(), WSSubSystem20Reader::new); } }
11,341
59.010582
193
java
null
wildfly-main/webservices/server-integration/src/main/java/org/jboss/as/webservices/dmr/WSSubsystemRemove.java
/* * JBoss, Home of Professional Open Source. * Copyright 2011, Red Hat Middleware LLC, 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.jboss.as.webservices.dmr; import org.jboss.as.controller.OperationContext; import org.jboss.as.controller.OperationFailedException; import org.jboss.as.controller.ReloadRequiredRemoveStepHandler; import org.jboss.dmr.ModelNode; /** * * @author <a href="[email protected]">Kabir Khan</a> */ class WSSubsystemRemove extends ReloadRequiredRemoveStepHandler { static final WSSubsystemRemove INSTANCE = new WSSubsystemRemove(); private WSSubsystemRemove() { } @Override protected void performRuntime(OperationContext context, ModelNode operation, ModelNode model) throws OperationFailedException { super.performRuntime(context, operation, model); } @Override protected void recoverServices(OperationContext context, ModelNode operation, ModelNode model) throws OperationFailedException { super.recoverServices(context, operation, model); } }
1,938
36.288462
131
java
null
wildfly-main/webservices/server-integration/src/main/java/org/jboss/as/webservices/dmr/WSSubSystem12Reader.java
/* * JBoss, Home of Professional Open Source. * Copyright 2014, 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.jboss.as.webservices.dmr; import java.util.EnumSet; import java.util.List; import javax.xml.stream.XMLStreamException; import org.jboss.as.controller.PathAddress; import org.jboss.dmr.ModelNode; import org.jboss.staxmapper.XMLExtendedStreamReader; /** * @author <a href="mailto:[email protected]">Jim Ma</a> */ class WSSubSystem12Reader extends WSSubsystem11Reader { WSSubSystem12Reader() { } @Override protected void handleUnknownElement(final XMLExtendedStreamReader reader, final PathAddress parentAddress, final Element element, List<ModelNode> list, EnumSet<Element> encountered) throws XMLStreamException { switch (element) { case CLIENT_CONFIG: { List<ModelNode> configs = readConfig(reader, parentAddress, true); list.addAll(configs); break; } default: { super.handleUnknownElement(reader, parentAddress, element, list, encountered); } } } }
2,037
36.740741
213
java
null
wildfly-main/webservices/server-integration/src/main/java/org/jboss/as/webservices/dmr/AddressValidator.java
/* * JBoss, Home of Professional Open Source * Copyright 2013 Red Hat Inc. and/or its affiliates and other contributors * as indicated by the @authors tag. All rights reserved. * See the copyright.txt in the distribution for a * full listing of individual contributors. * * This copyrighted material is made available to anyone wishing to use, * modify, copy, or redistribute it subject to the terms and conditions * of the GNU Lesser General Public License, v. 2.1. * This program is distributed in the hope that it will be useful, but WITHOUT A * 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, * v.2.1 along with this distribution; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * MA 02110-1301, USA. */ package org.jboss.as.webservices.dmr; import org.jboss.as.controller.OperationFailedException; import org.jboss.as.controller.operations.validation.ModelTypeValidator; import org.jboss.dmr.ModelNode; import org.jboss.dmr.ModelType; import org.jboss.ws.common.Messages; import org.jboss.ws.common.utils.AddressUtils; /** * Validates addresses using the JBossWS common address utilities * * @author <a href="mailto:[email protected]">Alessio Soldano</a> */ public class AddressValidator extends ModelTypeValidator { public AddressValidator(final boolean nullable, final boolean allowExpressions) { super(ModelType.STRING, nullable, allowExpressions, true); } /** * {@inheritDoc} */ @Override public void validateParameter(String parameterName, ModelNode value) throws OperationFailedException { super.validateParameter(parameterName, value); if (value.isDefined() && value.getType() != ModelType.EXPRESSION) { String address = value.asString(); if (address.startsWith("[") && address.endsWith("]")) { address = address.substring(1, address.length() - 1); } if (!AddressUtils.isValidAddress(address)) { throw new OperationFailedException(Messages.MESSAGES.invalidAddressProvided(address)); } } } }
2,336
39.293103
106
java
null
wildfly-main/webservices/server-integration/src/main/java/org/jboss/as/webservices/dmr/WSSubsystemWriter.java
/* * JBoss, Home of Professional Open Source. * Copyright 2012, 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.jboss.as.webservices.dmr; import static org.jboss.as.webservices.dmr.Constants.CLIENT_CONFIG; 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.NAME; import static org.jboss.as.webservices.dmr.Constants.POST_HANDLER_CHAIN; import static org.jboss.as.webservices.dmr.Constants.PRE_HANDLER_CHAIN; import static org.jboss.as.webservices.dmr.Constants.PROPERTY; import static org.jboss.as.webservices.dmr.Constants.PROTOCOL_BINDINGS; import javax.xml.stream.XMLStreamException; import org.jboss.as.controller.SimpleAttributeDefinition; import org.jboss.as.controller.persistence.SubsystemMarshallingContext; import org.jboss.dmr.ModelNode; import org.jboss.staxmapper.XMLElementWriter; import org.jboss.staxmapper.XMLExtendedStreamWriter; /** * @author <a href="mailto:[email protected]">Richard Opalka</a> * @author <a href="mailto:[email protected]">Alessio Soldano</a> */ final class WSSubsystemWriter implements XMLElementWriter<SubsystemMarshallingContext> { WSSubsystemWriter() { } @Override public void writeContent(final XMLExtendedStreamWriter writer, final SubsystemMarshallingContext context) throws XMLStreamException { // write ws subsystem start element context.startSubsystemElement(Namespace.CURRENT.getUriString(), false); ModelNode subsystem = context.getModelNode(); if (Attributes.STATISTICS_ENABLED.isMarshallable(subsystem)) { Attributes.STATISTICS_ENABLED.marshallAsAttribute(subsystem, writer); } for (SimpleAttributeDefinition attr : Attributes.SUBSYSTEM_ATTRIBUTES) { attr.getMarshaller().marshallAsElement(attr, subsystem, true, writer); } if (subsystem.hasDefined(ENDPOINT_CONFIG)) { // write endpoint-config elements final ModelNode endpointConfigs = subsystem.get(ENDPOINT_CONFIG); writeConfigs(ENDPOINT_CONFIG, writer, endpointConfigs); } if (subsystem.hasDefined(CLIENT_CONFIG)) { // write client-config elements final ModelNode clientConfigs = subsystem.get(CLIENT_CONFIG); writeConfigs(CLIENT_CONFIG, writer, clientConfigs); } // write ws subsystem end element writer.writeEndElement(); } private static void writeConfigs(final String elementName, final XMLExtendedStreamWriter writer, final ModelNode configs) throws XMLStreamException { ModelNode config = null; for (final String configName : configs.keys()) { config = configs.get(configName); // start config element writer.writeStartElement(elementName); writer.writeAttribute(Constants.NAME, configName); // write pre-handler-chain elements if (config.hasDefined(Constants.PRE_HANDLER_CHAIN)) { final ModelNode handlerChains = config.get(Constants.PRE_HANDLER_CHAIN); writeHandlerChains(writer, handlerChains, true); } // write post-handler-chain elements if (config.hasDefined(Constants.POST_HANDLER_CHAIN)) { final ModelNode handlerChains = config.get(Constants.POST_HANDLER_CHAIN); writeHandlerChains(writer, handlerChains, false); } // write property elements if (config.hasDefined(Constants.PROPERTY)) { final ModelNode properties = config.get(PROPERTY); writeProperties(writer, properties); } // close endpoint-config element writer.writeEndElement(); } } private static void writeProperties(final XMLExtendedStreamWriter writer, final ModelNode properties) throws XMLStreamException { ModelNode property; // write property elements for (final String propertyName : properties.keys()) { property = properties.get(propertyName); writer.writeStartElement(PROPERTY); writer.writeAttribute(NAME, propertyName); Attributes.VALUE.marshallAsAttribute(property, false, writer); writer.writeEndElement(); } } private static void writeHandlerChains(final XMLExtendedStreamWriter writer, final ModelNode handlerChains, final boolean isPre) throws XMLStreamException { ModelNode handlerChain = null; ModelNode handler = null; for (final String handlerChainName : handlerChains.keys()) { handlerChain = handlerChains.get(handlerChainName); // start either pre-handler-chain or post-handler-chain element writer.writeStartElement(isPre ? PRE_HANDLER_CHAIN : POST_HANDLER_CHAIN); writer.writeAttribute(NAME, handlerChainName); if (handlerChain.hasDefined(PROTOCOL_BINDINGS)) { final String protocolBinding = handlerChain.get(PROTOCOL_BINDINGS).asString(); writer.writeAttribute(PROTOCOL_BINDINGS, protocolBinding); } // write handler elements if (handlerChain.hasDefined(HANDLER)) { for (final String handlerName : handlerChain.require(HANDLER).keys()) { handler = handlerChain.get(HANDLER).get(handlerName); writer.writeStartElement(HANDLER); writer.writeAttribute(NAME, handlerName); Attributes.CLASS.marshallAsAttribute(handler, writer); writer.writeEndElement(); } } // end either pre-handler-chain or post-handler-chain element writer.writeEndElement(); } } }
6,800
46.229167
160
java
null
wildfly-main/webservices/server-integration/src/main/java/org/jboss/as/webservices/dmr/Attribute.java
/* * JBoss, Home of Professional Open Source. * Copyright 2012, 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.jboss.as.webservices.dmr; import java.util.HashMap; import java.util.Map; /** * @author <a href="mailto:[email protected]">Richard Opalka</a> * @author <a href="mailto:[email protected]">Jim Ma</a> */ enum Attribute { UNKNOWN(null), ID(Constants.ID), NAME(Constants.NAME), VALUE(Constants.VALUE), CLASS(Constants.CLASS), PROTOCOL_BINDINGS(Constants.PROTOCOL_BINDINGS), STATISTICS_ENABLED(Constants.STATISTICS_ENABLED), ; private final String name; Attribute(final String name) { this.name = name; } /** * Get the local name of this attribute. * * @return the local name */ public String getLocalName() { return name; } private static final Map<String, Attribute> MAP; static { final Map<String, Attribute> map = new HashMap<String, Attribute>(); for (Attribute element : values()) { final String name = element.getLocalName(); if (name != null) map.put(name, element); } MAP = map; } public static Attribute forName(String localName) { final Attribute element = MAP.get(localName); return element == null ? UNKNOWN : element; } @Override public String toString() { return getLocalName(); } }
2,359
28.5
76
java
null
wildfly-main/webservices/server-integration/src/main/java/org/jboss/as/webservices/dmr/WSSubsystemLegacyReader.java
/* * JBoss, Home of Professional Open Source. * Copyright 2012, 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.jboss.as.webservices.dmr; import static javax.xml.stream.XMLStreamConstants.END_ELEMENT; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.ADD; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP_ADDR; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.SUBSYSTEM; import static org.jboss.as.controller.parsing.ParseUtils.requireNoAttributes; import static org.jboss.as.controller.parsing.ParseUtils.requireNoNamespaceAttribute; import static org.jboss.as.controller.parsing.ParseUtils.unexpectedAttribute; import static org.jboss.as.controller.parsing.ParseUtils.unexpectedElement; import static org.jboss.as.webservices.dmr.Constants.CLASS; 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.MODIFY_WSDL_ADDRESS; import static org.jboss.as.webservices.dmr.Constants.POST_HANDLER_CHAIN; import static org.jboss.as.webservices.dmr.Constants.PRE_HANDLER_CHAIN; import static org.jboss.as.webservices.dmr.Constants.PROPERTY; import static org.jboss.as.webservices.dmr.Constants.VALUE; import static org.jboss.as.webservices.dmr.Constants.WSDL_HOST; import static org.jboss.as.webservices.dmr.Constants.WSDL_PORT; import static org.jboss.as.webservices.dmr.Constants.WSDL_SECURE_PORT; import java.util.ArrayList; import java.util.EnumSet; import java.util.LinkedList; import java.util.List; import javax.xml.stream.XMLStreamException; import org.jboss.dmr.ModelNode; import org.jboss.staxmapper.XMLElementReader; import org.jboss.staxmapper.XMLExtendedStreamReader; /** * @author [email protected] * @author <a href="mailto:[email protected]">Jim Ma</a> */ final class WSSubsystemLegacyReader implements XMLElementReader<List<ModelNode>> { WSSubsystemLegacyReader() { } @Override public void readElement(final XMLExtendedStreamReader reader, final List<ModelNode> list) throws XMLStreamException { // no attributes requireNoAttributes(reader); final ModelNode subsystem = new ModelNode(); subsystem.get(OP).set(ADD); subsystem.get(OP_ADDR).add(SUBSYSTEM, WSExtension.SUBSYSTEM_NAME); final List<ModelNode> endpointConfigs = new ArrayList<ModelNode>(); // elements final EnumSet<Element> encountered = EnumSet.noneOf(Element.class); while (reader.hasNext() && reader.nextTag() != END_ELEMENT) { switch (Namespace.forUri(reader.getNamespaceURI())) { case WEBSERVICES_1_0: { final Element element = Element.forName(reader.getLocalName()); if (element != Element.ENDPOINT_CONFIG && !encountered.add(element)) { throw unexpectedElement(reader); } switch (element) { case MODIFY_WSDL_ADDRESS: { boolean b = Boolean.parseBoolean(parseElementNoAttributes(reader)); subsystem.get(MODIFY_WSDL_ADDRESS).set(b); break; } case WSDL_HOST: { subsystem.get(WSDL_HOST).set(parseElementNoAttributes(reader)); break; } case WSDL_PORT: { int port = Integer.valueOf(parseElementNoAttributes(reader)); subsystem.get(WSDL_PORT).set(port); break; } case WSDL_SECURE_PORT: { int port = Integer.valueOf(parseElementNoAttributes(reader)); subsystem.get(WSDL_SECURE_PORT).set(port); break; } case ENDPOINT_CONFIG: { readEndpointConfig(reader, subsystem.get(OP_ADDR), endpointConfigs); break; } default: { throw unexpectedElement(reader); } } break; } } } list.add(subsystem); list.addAll(endpointConfigs); } private String parseElementNoAttributes(final XMLExtendedStreamReader reader) throws XMLStreamException { // no attributes requireNoAttributes(reader); return reader.getElementText().trim(); } private void readEndpointConfig(final XMLExtendedStreamReader reader, final ModelNode address, final List<ModelNode> operationList) throws XMLStreamException { String configName = null; final EnumSet<Element> encountered = EnumSet.noneOf(Element.class); while (reader.nextTag() != END_ELEMENT) { final Element element = Element.forName(reader.getLocalName()); if (element != Element.PROPERTY && !encountered.add(element)) { throw unexpectedElement(reader); } switch (element) { case CONFIG_NAME: { configName = parseElementNoAttributes(reader); final ModelNode node = new ModelNode(); node.get(OP).set(ADD); node.get(OP_ADDR).set(address).add(ENDPOINT_CONFIG, configName); operationList.add(node); break; } case PRE_HANDLER_CHAINS: { parseHandlerChains(reader, configName, operationList, true); break; } case POST_HANDLER_CHAINS: { parseHandlerChains(reader, configName, operationList, false); break; } case PROPERTY : { final ModelNode operation = parseProperty(reader, configName); operationList.add(operation); break; } default: { throw unexpectedElement(reader); } } } } private ModelNode parseProperty(final XMLExtendedStreamReader reader, final String configName) throws XMLStreamException { String propertyName = null; String propertyValue = null; final EnumSet<Element> encountered = EnumSet.noneOf(Element.class); while (reader.nextTag() != END_ELEMENT) { final Element element = Element.forName(reader.getLocalName()); if (!encountered.add(element)) { throw unexpectedElement(reader); } switch (element) { case PROPERTY_NAME: { propertyName = parseElementNoAttributes(reader); break; } case PROPERTY_VALUE : { propertyValue = parseElementNoAttributes(reader); break; } default: { throw unexpectedElement(reader); } } } final ModelNode operation = new ModelNode(); operation.get(OP).set(ADD); operation.get(OP_ADDR).add(SUBSYSTEM, WSExtension.SUBSYSTEM_NAME).add(ENDPOINT_CONFIG, configName).add(PROPERTY, propertyName); if (propertyValue != null) { operation.get(VALUE).set(propertyValue); } return operation; } private ModelNode parseHandlerChains(final XMLExtendedStreamReader reader, final String configName, final List<ModelNode> operationList, final boolean isPreHandlerChain) throws XMLStreamException { ModelNode chainsNode = new ModelNode(); final EnumSet<Element> encountered = EnumSet.noneOf(Element.class); while (reader.nextTag() != END_ELEMENT) { final Element element = Element.forName(reader.getLocalName()); if (element != Element.HANDLER_CHAIN && !encountered.add(element)) { throw unexpectedElement(reader); } switch (element) { case HANDLER_CHAIN: { parseHandlerChain(reader, configName, operationList, isPreHandlerChain); break; } default: { throw unexpectedElement(reader); } } } return chainsNode; } private void parseHandlerChain(final XMLExtendedStreamReader reader, final String configName, final List<ModelNode> operationList, final boolean isPreHandlerChain) throws XMLStreamException { String handlerChainId = null; final EnumSet<Element> encountered = EnumSet.noneOf(Element.class); final int count = reader.getAttributeCount(); for (int i = 0; i < count; i++) { requireNoNamespaceAttribute(reader, i); final String value = reader.getAttributeValue(i); final Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i)); switch (attribute) { case ID: handlerChainId = value; break; default: throw unexpectedAttribute(reader, i); } } if (handlerChainId == null) { handlerChainId = "auto-generated-" + System.currentTimeMillis(); } String protocolBindings = null; final List<ModelNode> addHandlerOperations = new LinkedList<ModelNode>(); while (reader.nextTag() != END_ELEMENT) { final Element element = Element.forName(reader.getLocalName()); if (element != Element.HANDLER && !encountered.add(element)) { throw unexpectedElement(reader); } switch (element) { case PROTOCOL_BINDINGS: { protocolBindings = parseElementNoAttributes(reader); break; } case HANDLER: { parseHandler(reader, configName, handlerChainId, isPreHandlerChain, addHandlerOperations); break; } default: { throw unexpectedElement(reader); } } } final ModelNode operation = new ModelNode(); final String handlerChainType = isPreHandlerChain ? PRE_HANDLER_CHAIN : POST_HANDLER_CHAIN; operation.get(OP).set(ADD); operation.get(OP_ADDR).add(SUBSYSTEM, WSExtension.SUBSYSTEM_NAME).add(ENDPOINT_CONFIG, configName).add(handlerChainType, handlerChainId); if (protocolBindings != null) { operation.get(Constants.PROTOCOL_BINDINGS).set(protocolBindings); } operationList.add(operation); operationList.addAll(addHandlerOperations); } private void parseHandler(final XMLExtendedStreamReader reader, final String configName, final String handlerChainId, final boolean isPreHandlerChain, final List<ModelNode> operations) throws XMLStreamException { String handlerName = null; String handlerClass = null; final EnumSet<Element> encountered = EnumSet.noneOf(Element.class); while (reader.nextTag() != END_ELEMENT) { final Element element = Element.forName(reader.getLocalName()); if (!encountered.add(element)) { throw unexpectedElement(reader); } switch (element) { case HANDLER_NAME: { handlerName = parseElementNoAttributes(reader); break; } case HANDLER_CLASS: { handlerClass = parseElementNoAttributes(reader); break; } default: { throw unexpectedElement(reader); } } } final ModelNode operation = new ModelNode(); final String handlerChainType = isPreHandlerChain ? PRE_HANDLER_CHAIN : POST_HANDLER_CHAIN; operation.get(OP).set(ADD); operation.get(OP_ADDR).add(SUBSYSTEM, WSExtension.SUBSYSTEM_NAME).add(ENDPOINT_CONFIG, configName).add(handlerChainType, handlerChainId).add(HANDLER, handlerName); operation.get(CLASS).set(handlerClass); operations.add(operation); } }
13,600
43.159091
216
java
null
wildfly-main/webservices/server-integration/src/main/java/org/jboss/as/webservices/dmr/WSSubSystem20Reader.java
/* * JBoss, Home of Professional Open Source. * Copyright 2014, 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.jboss.as.webservices.dmr; import static org.jboss.as.controller.parsing.ParseUtils.requireNoNamespaceAttribute; import static org.jboss.as.controller.parsing.ParseUtils.unexpectedAttribute; import static org.jboss.as.controller.parsing.ParseUtils.unexpectedElement; import java.util.EnumSet; import java.util.List; import javax.xml.stream.XMLStreamException; import org.jboss.as.controller.PathAddress; import org.jboss.dmr.ModelNode; import org.jboss.staxmapper.XMLExtendedStreamReader; /** * @author <a href="mailto:[email protected]">Jim Ma</a> */ class WSSubSystem20Reader extends WSSubSystem12Reader { WSSubSystem20Reader() { } @Override protected void readAttributes(final XMLExtendedStreamReader reader, final ModelNode operation) throws XMLStreamException { final int count = reader.getAttributeCount(); for (int i = 0; i < count; i++) { requireNoNamespaceAttribute(reader, i); final String value = reader.getAttributeValue(i); final Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i)); switch (attribute) { case STATISTICS_ENABLED: { Attributes.STATISTICS_ENABLED.parseAndSetParameter(value, operation, reader); break; } default: throw unexpectedAttribute(reader, i); } } } @Override protected void handleUnknownElement(final XMLExtendedStreamReader reader, final PathAddress parentAddress, final Element element, List<ModelNode> list, EnumSet<Element> encountered) throws XMLStreamException { //get the root ws subsystem add operation ModelNode operation = list.get(0); switch (element) { case WSDL_URI_SCHEME: { if (!encountered.add(element)) { throw unexpectedElement(reader); } final String value = parseElementNoAttributes(reader); Attributes.WSDL_URI_SCHEME.parseAndSetParameter(value, operation, reader); break; } case WSDL_PATH_REWRITE_RULE: { final String value = parseElementNoAttributes(reader); Attributes.WSDL_PATH_REWRITE_RULE.parseAndSetParameter(value, operation, reader); break; } default: { super.handleUnknownElement(reader, parentAddress, element, list, encountered); } } } }
3,559
40.395349
213
java
null
wildfly-main/webservices/server-integration/src/main/java/org/jboss/as/webservices/dmr/WSServerConfigAttributeHandler.java
/* * 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.jboss.as.webservices.dmr; import static org.jboss.as.webservices.dmr.Constants.MODIFY_WSDL_ADDRESS; import static org.jboss.as.webservices.dmr.Constants.STATISTICS_ENABLED; import static org.jboss.as.webservices.dmr.Constants.WSDL_HOST; import static org.jboss.as.webservices.dmr.Constants.WSDL_PORT; import static org.jboss.as.webservices.dmr.Constants.WSDL_SECURE_PORT; import static org.jboss.as.webservices.dmr.Constants.WSDL_PATH_REWRITE_RULE; import static org.jboss.as.webservices.dmr.Constants.WSDL_URI_SCHEME; import java.net.UnknownHostException; import org.jboss.as.controller.AbstractWriteAttributeHandler; import org.jboss.as.controller.AttributeDefinition; import org.jboss.as.controller.OperationContext; import org.jboss.as.controller.OperationFailedException; import org.jboss.as.webservices.config.DisabledOperationException; import org.jboss.as.webservices.config.ServerConfigFactoryImpl; import org.jboss.as.webservices.config.ServerConfigImpl; import org.jboss.dmr.ModelNode; /** * An AbstractWriteAttributeHandler extension for updating basic WS server config attributes * * @author <a href="mailto:[email protected]">Alessio Soldano</a> * @author <a href="mailto:[email protected]">Jim Ma</a> */ final class WSServerConfigAttributeHandler extends AbstractWriteAttributeHandler<WSServerConfigAttributeHandler.RollbackInfo> { public WSServerConfigAttributeHandler(final AttributeDefinition... definitions) { super(definitions); } @Override protected boolean applyUpdateToRuntime(OperationContext context, ModelNode operation, String attributeName, ModelNode resolvedValue, ModelNode currentValue, HandbackHolder<WSServerConfigAttributeHandler.RollbackInfo> handbackHolder) throws OperationFailedException { //if the server is booting or the required value is the current one, //we do not need to do anything and reload is not required if (isSameValue(context, resolvedValue, currentValue, attributeName) || context.isBooting()) { return false; } final String value = resolvedValue.isDefined() ? resolvedValue.asString() : null; boolean done = updateServerConfig(attributeName, value, false); handbackHolder.setHandback(new RollbackInfo(done)); return !done; //reload required if runtime has not been updated } private boolean isSameValue(OperationContext context, ModelNode resolvedValue, ModelNode currentValue, String attributeName) throws OperationFailedException { if (resolvedValue.equals(getAttributeDefinition(attributeName).resolveValue(context, currentValue))) { return true; } if (!currentValue.isDefined()) { return resolvedValue.equals(getAttributeDefinition(attributeName).getDefaultValue()); } return false; } @Override protected void revertUpdateToRuntime(OperationContext context, ModelNode operation, String attributeName, ModelNode valueToRestore, ModelNode valueToRevert, WSServerConfigAttributeHandler.RollbackInfo handback) throws OperationFailedException { if (handback != null && handback.isRuntimeUpdated()) { //nothing to do if the runtime was not updated final String value = valueToRestore.isDefined() ? valueToRestore.asString() : null; try { updateServerConfig(attributeName, value, true); } catch (DisabledOperationException e) { //revert rejected by WS stack throw new OperationFailedException(e); } } } /** * Returns true if the update operation succeeds in modifying the runtime, false otherwise. * * @param attributeName * @param value * @return * @throws OperationFailedException * @throws DisabledOperationException */ private boolean updateServerConfig(String attributeName, String value, boolean isRevert) throws OperationFailedException, DisabledOperationException { final ServerConfigImpl config = (ServerConfigImpl) ServerConfigFactoryImpl.getConfig(); try { if (MODIFY_WSDL_ADDRESS.equals(attributeName)) { final boolean modifyWSDLAddress = value != null && Boolean.parseBoolean(value); config.setModifySOAPAddress(modifyWSDLAddress, isRevert); } else if (WSDL_HOST.equals(attributeName)) { final String host = value != null ? value : null; try { config.setWebServiceHost(host, isRevert); } catch (final UnknownHostException e) { throw new OperationFailedException(e.getMessage(), e); } } else if (WSDL_PORT.equals(attributeName)) { final int port = value != null ? Integer.parseInt(value) : -1; config.setWebServicePort(port, isRevert); } else if (WSDL_SECURE_PORT.equals(attributeName)) { final int securePort = value != null ? Integer.parseInt(value) : -1; config.setWebServiceSecurePort(securePort, isRevert); } else if (WSDL_PATH_REWRITE_RULE.equals(attributeName)) { final String path = value != null ? value : null; config.setWebServicePathRewriteRule(path, isRevert); } else if (WSDL_URI_SCHEME.equals(attributeName)) { if (value == null || value.equals("http") || value.equals("https")) { config.setWebServiceUriScheme(value, isRevert); } else { throw new IllegalArgumentException(attributeName + " = " + value); } } else if (STATISTICS_ENABLED.equals(attributeName)) { final boolean enabled = value != null ? Boolean.parseBoolean(value) : false; config.setStatisticsEnabled(enabled); } else { throw new IllegalArgumentException(attributeName); } } catch (DisabledOperationException doe) { // the WS stack rejected the runtime update if (!isRevert) { return false; } else { throw doe; } } return true; } static class RollbackInfo { private final boolean runtimeUpdated; public RollbackInfo(boolean runtimeUpdated) { this.runtimeUpdated = runtimeUpdated; } public boolean isRuntimeUpdated() { return this.runtimeUpdated; } } }
7,607
46.55
154
java
null
wildfly-main/webservices/server-integration/src/main/java/org/jboss/as/webservices/dmr/Namespace.java
/* * JBoss, Home of Professional Open Source * Copyright 2010, Red Hat Inc., and individual contributors as indicated * by the @authors tag. See the copyright.txt 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.jboss.as.webservices.dmr; import java.util.HashMap; import java.util.Map; /** * @author [email protected] * @author <a href="mailto:[email protected]">Richard Opalka</a> * @author <a href="mailto:[email protected]">Jim Ma</a> */ enum Namespace { // must be first UNKNOWN(null), WEBSERVICES_1_0("urn:jboss:domain:webservices:1.0"), WEBSERVICES_1_1("urn:jboss:domain:webservices:1.1"), WEBSERVICES_1_2("urn:jboss:domain:webservices:1.2"), WEBSERVICES_2_0("urn:jboss:domain:webservices:2.0"), JAVAEE("http://java.sun.com/xml/ns/javaee"), JAVAEE_7_0("http://xmlns.jcp.org/xml/ns/javaee"), JAXWSCONFIG("urn:jboss:jbossws-jaxws-config:4.0"); /** * The current namespace version. */ static final Namespace CURRENT = WEBSERVICES_2_0; private final String name; private Namespace(final String name) { this.name = name; } private static final Map<String, Namespace> MAP; static { final Map<String, Namespace> map = new HashMap<String, Namespace>(); for (final Namespace namespace : values()) { final String name = namespace.getUriString(); if (name != null) map.put(name, namespace); } MAP = map; } static Namespace forUri(final String uri) { final Namespace element = MAP.get(uri); return element == null ? UNKNOWN : element; } /** * Get the URI of this namespace. * * @return the URI */ String getUriString() { return name; } }
2,598
28.202247
76
java
null
wildfly-main/webservices/server-integration/src/main/java/org/jboss/as/webservices/dmr/HandlerChainAdd.java
/* * JBoss, Home of Professional Open Source. * Copyright 2012, 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.jboss.as.webservices.dmr; import static org.jboss.as.webservices.dmr.Constants.HANDLER; import static org.jboss.as.webservices.dmr.PackageUtils.getConfigServiceName; import static org.jboss.as.webservices.dmr.PackageUtils.getHandlerChainServiceName; import java.util.ArrayList; import java.util.List; import java.util.function.Consumer; import java.util.function.Supplier; import org.jboss.as.controller.AbstractAddStepHandler; import org.jboss.as.controller.OperationContext; import org.jboss.as.controller.OperationFailedException; import org.jboss.as.controller.PathAddress; import org.jboss.as.controller.PathElement; import org.jboss.as.controller.registry.Resource; import org.jboss.as.webservices.logging.WSLogger; import org.jboss.as.webservices.service.HandlerChainService; import org.jboss.dmr.ModelNode; import org.jboss.msc.service.ServiceBuilder; import org.jboss.msc.service.ServiceName; import org.jboss.msc.service.ServiceTarget; import org.jboss.wsf.spi.metadata.j2ee.serviceref.UnifiedHandlerChainMetaData; import org.jboss.wsf.spi.metadata.j2ee.serviceref.UnifiedHandlerMetaData; /** * @author <a href="mailto:[email protected]">Richard Opalka</a> * @author <a href="mailto:[email protected]">Alessio Soldano</a> */ final class HandlerChainAdd extends AbstractAddStepHandler { static final HandlerChainAdd INSTANCE = new HandlerChainAdd(); private HandlerChainAdd() { // forbidden instantiation } @Override protected void rollbackRuntime(OperationContext context, ModelNode operation, Resource resource) { super.rollbackRuntime(context, operation, resource); if (!context.isBooting()) { context.revertReloadRequired(); } } @Override protected void performRuntime(final OperationContext context, final ModelNode operation, final ModelNode model) throws OperationFailedException { //modify the runtime if we're booting, otherwise set reload required and leave the runtime unchanged if (context.isBooting()) { final String protocolBindings = Attributes.PROTOCOL_BINDINGS.resolveModelAttribute(context, model).asStringOrNull(); final PathAddress address = context.getCurrentAddress(); final PathElement confElem = address.getElement(address.size() - 2); final String configType = confElem.getKey(); final String configName = confElem.getValue(); final String handlerChainType = address.getElement(address.size() - 1).getKey(); final String handlerChainId = address.getElement(address.size() - 1).getValue(); final ServiceName configServiceName = getConfigServiceName(configType, configName); if (context.getServiceRegistry(false).getService(configServiceName) == null) { throw WSLogger.ROOT_LOGGER.missingConfig(configName); } final ServiceName handlerChainServiceName = getHandlerChainServiceName(configServiceName, handlerChainType, handlerChainId); final ServiceTarget target = context.getServiceTarget(); final ServiceBuilder<?> handlerChainServiceBuilder = target.addService(handlerChainServiceName); final Consumer<UnifiedHandlerChainMetaData> handlerChainConsumer = handlerChainServiceBuilder.provides(handlerChainServiceName); final List<Supplier<UnifiedHandlerMetaData>> handlerSuppliers = new ArrayList<>(); for (final ServiceName sn : PackageUtils.getServiceNameDependencies(context, handlerChainServiceName, address, HANDLER)) { handlerSuppliers.add(handlerChainServiceBuilder.requires(sn)); } handlerChainServiceBuilder.setInstance(new HandlerChainService(handlerChainType, handlerChainId, protocolBindings, handlerChainConsumer, handlerSuppliers)); handlerChainServiceBuilder.install(); } else { context.reloadRequired(); } } @Override protected void populateModel(final ModelNode operation, final ModelNode model) throws OperationFailedException { Attributes.PROTOCOL_BINDINGS.validateAndSet(operation, model); } }
5,207
48.6
168
java
null
wildfly-main/webservices/server-integration/src/main/java/org/jboss/as/webservices/parser/WSDeploymentAspectParser.java
/* * JBoss, Home of Professional Open Source. * Copyright 2011, Red Hat Middleware LLC, 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.jboss.as.webservices.parser; import static javax.xml.stream.XMLStreamConstants.END_ELEMENT; import static javax.xml.stream.XMLStreamConstants.START_ELEMENT; import static org.jboss.wsf.spi.util.StAXUtils.match; import java.io.InputStream; import java.lang.reflect.Method; import java.util.LinkedList; import java.util.List; import java.util.Map; import javax.xml.stream.XMLStreamConstants; import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamReader; import jakarta.xml.ws.WebServiceException; import org.jboss.as.webservices.logging.WSLogger; import org.jboss.ws.common.JavaUtils; import org.jboss.wsf.spi.deployment.DeploymentAspect; import org.jboss.wsf.spi.util.StAXUtils; import org.wildfly.security.manager.WildFlySecurityManager; /** * A parser for WS deployment aspects * * @author [email protected] * @since 18-Jan-2011 * */ public class WSDeploymentAspectParser { private static final String NS = "urn:jboss:ws:deployment:aspects:1.0"; private static final String DEPLOYMENT_ASPECTS = "deploymentAspects"; private static final String DEPLOYMENT_ASPECT = "deploymentAspect"; private static final String CLASS = "class"; private static final String PRIORITY = "priority"; private static final String PROPERTY = "property"; private static final String NAME = "name"; private static final String MAP = "map"; private static final String KEY_CLASS = "keyClass"; private static final String VALUE_CLASS = "valueClass"; private static final String ENTRY = "entry"; private static final String KEY = "key"; private static final String VALUE = "value"; private static final String LIST = "list"; private static final String ELEMENT_CLASS = "elementClass"; public static List<DeploymentAspect> parse(InputStream is, ClassLoader loader) { try { XMLStreamReader xmlr = StAXUtils.createXMLStreamReader(is); return parse(xmlr, loader); } catch (Exception e) { throw new WebServiceException(e); } } public static List<DeploymentAspect> parse(XMLStreamReader reader, ClassLoader loader) throws XMLStreamException { int iterate; try { iterate = reader.nextTag(); } catch (XMLStreamException e) { // skip non-tag elements iterate = reader.nextTag(); } List<DeploymentAspect> deploymentAspects = null; switch (iterate) { case END_ELEMENT: { // we're done break; } case START_ELEMENT: { if (match(reader, NS, DEPLOYMENT_ASPECTS)) { deploymentAspects = parseDeploymentAspects(reader, loader); } else { throw WSLogger.ROOT_LOGGER.unexpectedElement(reader.getLocalName()); } } } return deploymentAspects; } private static List<DeploymentAspect> parseDeploymentAspects(XMLStreamReader reader, ClassLoader loader) throws XMLStreamException { List<DeploymentAspect> deploymentAspects = new LinkedList<DeploymentAspect>(); while (reader.hasNext()) { switch (reader.nextTag()) { case XMLStreamConstants.END_ELEMENT: { if (match(reader, NS, DEPLOYMENT_ASPECTS)) { return deploymentAspects; } else { throw WSLogger.ROOT_LOGGER.unexpectedEndTag(reader.getLocalName()); } } case XMLStreamConstants.START_ELEMENT: { if (match(reader, NS, DEPLOYMENT_ASPECT)) { deploymentAspects.add(parseDeploymentAspect(reader, loader)); } else { throw WSLogger.ROOT_LOGGER.unexpectedElement(reader.getLocalName()); } } } } throw WSLogger.ROOT_LOGGER.unexpectedEndOfDocument(); } private static DeploymentAspect parseDeploymentAspect(XMLStreamReader reader, ClassLoader loader) throws XMLStreamException { String deploymentAspectClass = reader.getAttributeValue(null, CLASS); if (deploymentAspectClass == null) { throw WSLogger.ROOT_LOGGER.missingDeploymentAspectClassAttribute(); } DeploymentAspect deploymentAspect = null; try { @SuppressWarnings("unchecked") Class<? extends DeploymentAspect> clazz = (Class<? extends DeploymentAspect>) Class.forName(deploymentAspectClass, true, loader); ClassLoader orig = WildFlySecurityManager.getCurrentContextClassLoaderPrivileged(); try { WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(loader); deploymentAspect = clazz.newInstance(); } finally { WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(orig); } } catch (Exception e) { throw WSLogger.ROOT_LOGGER.cannotInstantiateDeploymentAspect(e, deploymentAspectClass); } String priority = reader.getAttributeValue(null, PRIORITY); if (priority != null) { deploymentAspect.setRelativeOrder(Integer.parseInt(priority.trim())); } while (reader.hasNext()) { switch (reader.nextTag()) { case XMLStreamConstants.END_ELEMENT: { if (match(reader, NS, DEPLOYMENT_ASPECT)) { return deploymentAspect; } else { throw WSLogger.ROOT_LOGGER.unexpectedEndTag(reader.getLocalName()); } } case XMLStreamConstants.START_ELEMENT: { if (match(reader, NS, PROPERTY)) { parseProperty(reader, deploymentAspect, loader); } else { throw WSLogger.ROOT_LOGGER.unexpectedElement(reader.getLocalName()); } } } } throw WSLogger.ROOT_LOGGER.unexpectedEndOfDocument(); } @SuppressWarnings("rawtypes") private static void parseProperty(XMLStreamReader reader, DeploymentAspect deploymentAspect, ClassLoader loader) throws XMLStreamException { Class<? extends DeploymentAspect> deploymentAspectClass = deploymentAspect.getClass(); String propName = reader.getAttributeValue(null, NAME); if (propName == null) { throw WSLogger.ROOT_LOGGER.missingPropertyNameAttribute(deploymentAspect); } String propClass = reader.getAttributeValue(null, CLASS); if (propClass == null) { throw WSLogger.ROOT_LOGGER.missingPropertyClassAttribute(deploymentAspect); } else { try { if (isSupportedPropertyClass(propClass)) { Method m = selectMethod(deploymentAspectClass, propName, propClass); m.invoke(deploymentAspect, parseSimpleValue(reader, propClass)); return; } } catch (Exception e) { throw new IllegalStateException(e); } } while (reader.hasNext()) { switch (reader.nextTag()) { case XMLStreamConstants.END_ELEMENT: { if (match(reader, NS, PROPERTY)) { return; } else { throw WSLogger.ROOT_LOGGER.unexpectedEndTag(reader.getLocalName()); } } case XMLStreamConstants.START_ELEMENT: { if (match(reader, NS, MAP)) { try { Method m = selectMethod(deploymentAspectClass, propName, propClass); Map map = parseMapProperty(reader, propClass, reader.getAttributeValue(null, KEY_CLASS), reader.getAttributeValue(null, VALUE_CLASS), loader); m.invoke(deploymentAspect, map); } catch (Exception e) { throw new IllegalStateException(e); } } else if (match(reader, NS, LIST)) { try { Method m = selectMethod(deploymentAspectClass, propName, propClass); List list = parseListProperty(reader, propClass, reader.getAttributeValue(null, ELEMENT_CLASS)); m.invoke(deploymentAspect, list); } catch (Exception e) { throw new IllegalStateException(e); } } else { throw WSLogger.ROOT_LOGGER.unexpectedElement(reader.getLocalName()); } } } } throw WSLogger.ROOT_LOGGER.unexpectedEndOfDocument(); } private static Method selectMethod(Class<?> deploymentAspectClass, String propName, String propClass) throws ClassNotFoundException { //TODO improve this (better support for primitives, edge cases, etc.) Method[] methods = deploymentAspectClass.getMethods(); for (Method m : methods) { if (m.getName().equals("set" + JavaUtils.capitalize(propName))) { Class<?>[] pars = m.getParameterTypes(); if (pars.length == 1 && (propClass.equals(pars[0].getName()) || (pars[0].isAssignableFrom(Class.forName(propClass))))) { return m; } } } return null; } private static boolean isSupportedPropertyClass(String propClass) { return (String.class.getName().equals(propClass) || Boolean.class.getName().equals(propClass) || Integer.class .getName().equals(propClass) || JavaUtils.isPrimitive(propClass)); } private static Object parseSimpleValue(XMLStreamReader reader, String propClass) throws XMLStreamException { if (String.class.getName().equals(propClass)) { return StAXUtils.elementAsString(reader); } else if (Boolean.class.getName().equals(propClass)) { return StAXUtils.elementAsBoolean(reader); } else if (Integer.class.getName().equals(propClass)) { return StAXUtils.elementAsInt(reader); } else if (boolean.class.getName().equals(propClass)) { return StAXUtils.elementAsBoolean(reader); } else { throw WSLogger.ROOT_LOGGER.unsupportedPropertyClass(propClass); } } @SuppressWarnings({ "rawtypes", "unchecked" }) private static List parseListProperty(XMLStreamReader reader, String propClass, String elementClass) throws XMLStreamException { List list = null; try { list = (List) Class.forName(propClass).newInstance(); } catch (Exception e) { throw WSLogger.ROOT_LOGGER.cannotInstantiateList(e, propClass); } while (reader.hasNext()) { switch (reader.nextTag()) { case XMLStreamConstants.END_ELEMENT: { if (match(reader, NS, LIST)) { return list; } else { throw WSLogger.ROOT_LOGGER.unexpectedEndTag(reader.getLocalName()); } } case XMLStreamConstants.START_ELEMENT: { if (match(reader, NS, VALUE)) { list.add(parseSimpleValue(reader, elementClass)); } else { throw WSLogger.ROOT_LOGGER.unexpectedElement(reader.getLocalName()); } } } } throw WSLogger.ROOT_LOGGER.unexpectedEndOfDocument(); } @SuppressWarnings("rawtypes") private static Map parseMapProperty(XMLStreamReader reader, String propClass, String keyClass, String valueClass, ClassLoader loader) throws XMLStreamException { Map map = null; try { map = (Map) Class.forName(propClass, true, loader).newInstance(); } catch (Exception e) { throw WSLogger.ROOT_LOGGER.cannotInstantiateMap(e, propClass); } while (reader.hasNext()) { switch (reader.nextTag()) { case XMLStreamConstants.END_ELEMENT: { if (match(reader, NS, MAP)) { return map; } else { throw WSLogger.ROOT_LOGGER.unexpectedEndTag(reader.getLocalName()); } } case XMLStreamConstants.START_ELEMENT: { if (match(reader, NS, ENTRY)) { parseMapEntry(reader, map, keyClass, valueClass); } else { throw WSLogger.ROOT_LOGGER.unexpectedElement(reader.getLocalName()); } } } } throw WSLogger.ROOT_LOGGER.unexpectedEndOfDocument(); } @SuppressWarnings({ "rawtypes", "unchecked" }) private static void parseMapEntry(XMLStreamReader reader, Map map, String keyClass, String valueClass) throws XMLStreamException { boolean keyStartDone = false, valueStartDone = false; Object key = null; Object value = null; while (reader.hasNext()) { switch (reader.nextTag()) { case XMLStreamConstants.END_ELEMENT: { if (match(reader, NS, ENTRY) && keyStartDone && valueStartDone) { map.put(key, value); return; } else { throw WSLogger.ROOT_LOGGER.unexpectedEndTag(reader.getLocalName()); } } case XMLStreamConstants.START_ELEMENT: { if (match(reader, NS, KEY)) { keyStartDone = true; key = parseSimpleValue(reader, keyClass); } else if (match(reader, NS, VALUE)) { valueStartDone = true; value = parseSimpleValue(reader, valueClass); } else { throw WSLogger.ROOT_LOGGER.unexpectedElement(reader.getLocalName()); } } } } throw WSLogger.ROOT_LOGGER.unexpectedEndOfDocument(); } }
15,665
43.254237
144
java
null
wildfly-main/webservices/server-integration/src/main/java/org/jboss/as/webservices/deployers/WebServiceAnnotationProcessor.java
/* * JBoss, Home of Professional Open Source * Copyright 2014, Red Hat Inc., and individual contributors as indicated * by the @authors tag. See the copyright.txt 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.jboss.as.webservices.deployers; import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Map; import org.jboss.as.ee.component.Attachments; import org.jboss.as.ee.component.EEModuleClassDescription; import org.jboss.as.ee.component.EEModuleDescription; import org.jboss.as.ee.metadata.ClassAnnotationInformation; import org.jboss.as.ee.metadata.ClassAnnotationInformationFactory; import org.jboss.as.server.deployment.DeploymentPhaseContext; 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.metadata.property.PropertyReplacers; /** * @author <a href="mailto:[email protected]">Jim Ma</a> */ public class WebServiceAnnotationProcessor implements DeploymentUnitProcessor { @SuppressWarnings("rawtypes") final List<ClassAnnotationInformationFactory> factories; public WebServiceAnnotationProcessor() { @SuppressWarnings("rawtypes") List<ClassAnnotationInformationFactory> factories = new ArrayList<ClassAnnotationInformationFactory>(); factories.add(new WebServiceAnnotationInformationFactory()); factories.add(new WebServiceProviderAnnotationInformationFactory()); factories.add(new WebContextAnnotationInformationFactory()); this.factories = Collections.unmodifiableList(factories); } @SuppressWarnings({ "unchecked", "rawtypes" }) public final void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException { final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit(); final EEModuleDescription eeModuleDescription = deploymentUnit.getAttachment(Attachments.EE_MODULE_DESCRIPTION); final CompositeIndex index = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.COMPOSITE_ANNOTATION_INDEX); if (index == null || eeModuleDescription == null) { return; } for (final ClassAnnotationInformationFactory factory : factories) { final Map<String, ClassAnnotationInformation<?, ?>> data = factory.createAnnotationInformation(index, PropertyReplacers.noop()); for (Map.Entry<String, ClassAnnotationInformation<?, ?>> entry : data.entrySet()) { EEModuleClassDescription clazz = eeModuleDescription.addOrGetLocalClassDescription(entry.getKey()); clazz.addAnnotationInformation(entry.getValue()); } } } }
3,667
47.906667
140
java
null
wildfly-main/webservices/server-integration/src/main/java/org/jboss/as/webservices/deployers/WSClassVerificationProcessor.java
/* * 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.jboss.as.webservices.deployers; import static org.jboss.as.webservices.util.DotNames.WEB_SERVICE_ANNOTATION; import static org.jboss.as.webservices.util.DotNames.WEB_SERVICE_PROVIDER_ANNOTATION; import static org.jboss.as.webservices.util.WSAttachmentKeys.JAXWS_ENDPOINTS_KEY; import java.util.HashSet; import java.util.Set; import jakarta.jws.WebService; import org.jboss.as.server.deployment.Attachments; import org.jboss.as.server.deployment.DeploymentPhaseContext; 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.server.deployment.module.ModuleDependency; import org.jboss.as.server.deployment.module.ModuleSpecification; import org.jboss.as.server.deployment.reflect.DeploymentReflectionIndex; import org.jboss.as.webservices.logging.WSLogger; import org.jboss.as.webservices.metadata.model.AbstractEndpoint; import org.jboss.as.webservices.metadata.model.JAXWSDeployment; import org.jboss.as.webservices.verification.JwsWebServiceEndpointVerifier; import org.jboss.jandex.AnnotationInstance; import org.jboss.jandex.AnnotationTarget; import org.jboss.jandex.ClassInfo; import org.jboss.jandex.DotName; import org.jboss.modules.Module; /** * @author sfcoy * @author <a href="mailto:[email protected]">Alessio Soldano</a> * */ public class WSClassVerificationProcessor implements DeploymentUnitProcessor { private static final Set<String> cxfExportingModules = new HashSet<>(); static { cxfExportingModules.add("org.apache.cxf"); cxfExportingModules.add("org.apache.cxf.impl"); cxfExportingModules.add("org.jboss.ws.cxf.jbossws-cxf-client"); } @Override public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException { final DeploymentUnit unit = phaseContext.getDeploymentUnit(); final JAXWSDeployment wsDeployment = unit.getAttachment(JAXWS_ENDPOINTS_KEY); if (wsDeployment != null) { final Module module = unit.getAttachment(Attachments.MODULE); final DeploymentReflectionIndex deploymentReflectionIndex = unit .getAttachment(org.jboss.as.server.deployment.Attachments.REFLECTION_INDEX); final ClassLoader moduleClassLoader = module.getClassLoader(); for (AbstractEndpoint pojoEndpoint : wsDeployment.getPojoEndpoints()) { verifyEndpoint(pojoEndpoint, moduleClassLoader, deploymentReflectionIndex); } for (AbstractEndpoint ejbEndpoint : wsDeployment.getEjbEndpoints()) { verifyEndpoint(ejbEndpoint, moduleClassLoader, deploymentReflectionIndex); } verifyApacheCXFModuleDependencyRequirement(unit); } } private void verifyEndpoint(final AbstractEndpoint pojoEndpoint, final ClassLoader moduleClassLoader, final DeploymentReflectionIndex deploymentReflectionIndex) throws DeploymentUnitProcessingException { if (WSLogger.ROOT_LOGGER.isTraceEnabled()) { WSLogger.ROOT_LOGGER.tracef("Verifying web service endpoint class %s", pojoEndpoint.getClassName()); } try { final Class<?> endpointClass = moduleClassLoader.loadClass(pojoEndpoint.getClassName()); final WebService webServiceAnnotation = endpointClass.getAnnotation(WebService.class); if (webServiceAnnotation != null) { verifyJwsEndpoint(endpointClass, webServiceAnnotation, moduleClassLoader, deploymentReflectionIndex); } // otherwise it's probably a jakarta.xml.ws.Provider implementation } catch (ClassNotFoundException e) { throw WSLogger.ROOT_LOGGER.endpointClassNotFound(pojoEndpoint.getClassName()); } } void verifyJwsEndpoint(final Class<?> endpointClass, final WebService webServiceAnnotation, final ClassLoader moduleClassLoader, final DeploymentReflectionIndex deploymentReflectionIndex) throws DeploymentUnitProcessingException { final String endpointInterfaceClassName = webServiceAnnotation.endpointInterface(); try { final Class<?> endpointInterfaceClass = endpointInterfaceClassName.length() > 0 ? moduleClassLoader .loadClass(endpointInterfaceClassName) : null; final JwsWebServiceEndpointVerifier wsEndpointVerifier = new JwsWebServiceEndpointVerifier( endpointClass, endpointInterfaceClass, deploymentReflectionIndex); wsEndpointVerifier.verify(); if (wsEndpointVerifier.failed()) { wsEndpointVerifier.logFailures(); throw WSLogger.ROOT_LOGGER.jwsWebServiceClassVerificationFailed(endpointClass); } } catch (ClassNotFoundException e) { throw WSLogger.ROOT_LOGGER.declaredEndpointInterfaceClassNotFound(endpointInterfaceClassName, endpointClass); } } private void verifyApacheCXFModuleDependencyRequirement(DeploymentUnit unit) { if (!hasCxfModuleDependency(unit)) { //notify user if he clearly forgot the CXF module dependency final CompositeIndex index = unit.getAttachment(Attachments.COMPOSITE_ANNOTATION_INDEX); final DotName[] dotNames = {WEB_SERVICE_ANNOTATION, WEB_SERVICE_PROVIDER_ANNOTATION}; for (final DotName dotName : dotNames) { for (AnnotationInstance ai : index.getAnnotations(dotName)) { AnnotationTarget at = ai.target(); if (at instanceof ClassInfo) { final ClassInfo clazz = (ClassInfo)ai.target(); for (DotName dn : clazz.annotationsMap().keySet()) { if (dn.toString().startsWith("org.apache.cxf")) { WSLogger.ROOT_LOGGER.missingModuleDependency(dn.toString(), clazz.name().toString(), "org.apache.cxf"); } } } } } } } static boolean hasCxfModuleDependency(DeploymentUnit unit) { final ModuleSpecification moduleSpec = unit.getAttachment(Attachments.MODULE_SPECIFICATION); for (ModuleDependency dep : moduleSpec.getUserDependencies()) { final String id = dep.getIdentifier().getName(); if (cxfExportingModules.contains(id)) { return true; } } return hasExportedCxfModuleDependency(unit.getParent()) || hasSiblingCxfModuleDependency(unit); } private static boolean hasExportedCxfModuleDependency(DeploymentUnit unit) { if (unit != null) { final ModuleSpecification moduleSpec = unit.getAttachment(Attachments.MODULE_SPECIFICATION); for (ModuleDependency dep : moduleSpec.getUserDependencies()) { final String id = dep.getIdentifier().getName(); if (cxfExportingModules.contains(id) && dep.isExport()) { return true; } } } return false; } private static boolean hasSiblingCxfModuleDependency(DeploymentUnit unit) { if (unit.getParent() == null) { return false; } final ModuleSpecification rootModuleSpec = unit.getParent().getAttachment(Attachments.MODULE_SPECIFICATION); // if ear-subdeployments-isolated is false, we can also look at siblings exported dependencies if (!rootModuleSpec.isSubDeploymentModulesIsolated()) { for (DeploymentUnit siblingUnit : unit.getParent().getAttachment(Attachments.SUB_DEPLOYMENTS)) { // look only at JAR dependencies, WARs are always isolated if (siblingUnit.getName().endsWith(".jar") && !siblingUnit.equals(unit) && hasExportedCxfModuleDependency(siblingUnit)) { return true; } } } return false; } }
9,210
49.059783
150
java
null
wildfly-main/webservices/server-integration/src/main/java/org/jboss/as/webservices/deployers/WebContextAnnotationInformationFactory.java
package org.jboss.as.webservices.deployers; import org.jboss.ws.api.annotation.WebContext; import org.jboss.as.ee.metadata.ClassAnnotationInformationFactory; import org.jboss.jandex.AnnotationInstance; import org.jboss.jandex.AnnotationValue; import org.jboss.metadata.property.PropertyReplacer; /** * User: rsearls * Date: 7/17/14 */ public class WebContextAnnotationInformationFactory extends ClassAnnotationInformationFactory<WebContext, WebContextAnnotationInfo> { protected WebContextAnnotationInformationFactory() { super(org.jboss.ws.api.annotation.WebContext.class, null); } @Override protected WebContextAnnotationInfo fromAnnotation(final AnnotationInstance annotationInstance, final PropertyReplacer propertyReplacer) { String authMethodValue = asString(annotationInstance, "authMethod"); String contextRootValue = asString(annotationInstance, "contextRoot"); boolean secureWSDLAccessValue = asBoolean(annotationInstance, "secureWSDLAccessValue"); String transportGuaranteeValue = asString(annotationInstance, "transportGuarantee"); String urlPatternValue = asString(annotationInstance, "urlPattern"); String virtualHostValue = asString(annotationInstance, "virtualHost"); return new WebContextAnnotationInfo(authMethodValue, contextRootValue, secureWSDLAccessValue, transportGuaranteeValue, urlPatternValue, virtualHostValue); } private String asString(final AnnotationInstance annotation, String property) { AnnotationValue value = annotation.value(property); return value == null ? "" : value.asString(); } private boolean asBoolean(final AnnotationInstance annotation, String property) { AnnotationValue value = annotation.value(property); return value == null ? false : Boolean.getBoolean(value.asString()); } }
1,888
41.931818
141
java
null
wildfly-main/webservices/server-integration/src/main/java/org/jboss/as/webservices/deployers/JBossWebservicesDescriptorDeploymentProcessor.java
/* * JBoss, Home of Professional Open Source * Copyright 2011, Red Hat Inc., and individual contributors as indicated * by the @authors tag. See the copyright.txt 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.jboss.as.webservices.deployers; import java.io.IOException; import java.net.URL; import org.jboss.as.ee.structure.JBossDescriptorPropertyReplacement; import org.jboss.as.server.deployment.Attachments; import org.jboss.as.server.deployment.DeploymentPhaseContext; 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.module.ResourceRoot; import org.jboss.as.webservices.logging.WSLogger; import org.jboss.as.webservices.metadata.JBossWebservicesPropertyReplaceFactory; import org.jboss.as.webservices.util.WSAttachmentKeys; import org.jboss.vfs.VirtualFile; import org.jboss.wsf.spi.metadata.webservices.JBossWebservicesMetaData; /** * DUP for parsing jboss-webservices.xml * * @author <a href="mailto:[email protected]">Richard Opalka</a> */ public final class JBossWebservicesDescriptorDeploymentProcessor implements DeploymentUnitProcessor { public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException { final DeploymentUnit unit = phaseContext.getDeploymentUnit(); final ResourceRoot deploymentRoot = unit.getAttachment(Attachments.DEPLOYMENT_ROOT); final URL jbossWebservicesDescriptorURL = getJBossWebServicesDescriptorURL(deploymentRoot); if (jbossWebservicesDescriptorURL != null) { final JBossWebservicesPropertyReplaceFactory webservicesFactory = new JBossWebservicesPropertyReplaceFactory( jbossWebservicesDescriptorURL, JBossDescriptorPropertyReplacement.propertyReplacer(unit)); final JBossWebservicesMetaData jbossWebservicesMD = webservicesFactory.load(jbossWebservicesDescriptorURL); unit.putAttachment(WSAttachmentKeys.JBOSS_WEBSERVICES_METADATA_KEY, jbossWebservicesMD); } } private URL getJBossWebServicesDescriptorURL(final ResourceRoot deploymentRoot) throws DeploymentUnitProcessingException { VirtualFile jwsdd = deploymentRoot.getRoot().getChild("WEB-INF/jboss-webservices.xml"); if (!jwsdd.exists()) { jwsdd = deploymentRoot.getRoot().getChild("META-INF/jboss-webservices.xml"); } try { return jwsdd.exists() ? jwsdd.toURL() : null; } catch (IOException e) { throw WSLogger.ROOT_LOGGER.cannotGetURLForDescriptor(e, jwsdd.getPathName()); } } }
3,523
45.986667
126
java
null
wildfly-main/webservices/server-integration/src/main/java/org/jboss/as/webservices/deployers/GracefulShutdownIntegrationProcessor.java
/* * JBoss, Home of Professional Open Source. * Copyright 2016, 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.jboss.as.webservices.deployers; import static org.jboss.as.webservices.util.WSAttachmentKeys.JAXWS_ENDPOINTS_KEY; import org.jboss.as.server.deployment.AttachmentKey; import org.jboss.as.server.deployment.DeploymentPhaseContext; 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.webservices.metadata.model.JAXWSDeployment; import org.wildfly.extension.undertow.deployment.UndertowAttachments; import io.undertow.predicate.Predicate; /** * DUP for telling Undertow to let WS deal with blocking requests to * serve XTS requirements. * * @author <a href="mailto:[email protected]">Alessio Soldano</a> */ public class GracefulShutdownIntegrationProcessor implements DeploymentUnitProcessor { private static final AttachmentKey<Predicate> ATTACHMENT_KEY = AttachmentKey.create(Predicate.class); @Override public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException { final DeploymentUnit unit = phaseContext.getDeploymentUnit(); final JAXWSDeployment wsDeployment = unit.getAttachment(JAXWS_ENDPOINTS_KEY); if (wsDeployment != null) { Predicate predicate = new AllowWSRequestPredicate(); unit.putAttachment(ATTACHMENT_KEY, predicate); unit.addToAttachmentList(UndertowAttachments.ALLOW_REQUEST_WHEN_SUSPENDED, predicate); } } @Override public void undeploy(DeploymentUnit deploymentUnit) { Predicate predicate = deploymentUnit.removeAttachment(ATTACHMENT_KEY); if (predicate != null) { deploymentUnit.getAttachmentList(UndertowAttachments.ALLOW_REQUEST_WHEN_SUSPENDED).remove(predicate); } } }
2,874
42.560606
113
java
null
wildfly-main/webservices/server-integration/src/main/java/org/jboss/as/webservices/deployers/WebservicesDescriptorDeploymentProcessor.java
/* * JBoss, Home of Professional Open Source * Copyright 2011, Red Hat Inc., and individual contributors as indicated * by the @authors tag. See the copyright.txt 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.jboss.as.webservices.deployers; import java.io.IOException; import java.net.URL; import org.jboss.as.ee.structure.JBossDescriptorPropertyReplacement; import org.jboss.as.server.deployment.Attachments; import org.jboss.as.server.deployment.DeploymentPhaseContext; 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.module.ResourceRoot; import org.jboss.as.webservices.logging.WSLogger; import org.jboss.as.webservices.metadata.WebservicesPropertyReplaceFactory; import org.jboss.as.webservices.util.WSAttachmentKeys; import org.jboss.vfs.VirtualFile; import org.jboss.wsf.spi.metadata.webservices.WebserviceDescriptionMetaData; import org.jboss.wsf.spi.metadata.webservices.WebservicesMetaData; /** * DUP for parsing webservices.xml * * @author [email protected] * @author <a href="mailto:[email protected]">Richard Opalka</a> */ public final class WebservicesDescriptorDeploymentProcessor implements DeploymentUnitProcessor { public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException { final DeploymentUnit unit = phaseContext.getDeploymentUnit(); final ResourceRoot deploymentRoot = unit.getAttachment(Attachments.DEPLOYMENT_ROOT); final URL webservicesDescriptorURL = getWebServicesDescriptorURL(deploymentRoot); if (webservicesDescriptorURL != null) { final WebservicesPropertyReplaceFactory webservicesFactory = new WebservicesPropertyReplaceFactory( webservicesDescriptorURL, JBossDescriptorPropertyReplacement.propertyReplacer(unit)); final WebservicesMetaData webservicesMD = webservicesFactory.load(webservicesDescriptorURL); unit.putAttachment(WSAttachmentKeys.WEBSERVICES_METADATA_KEY, webservicesMD); if (hasJaxRpcMapping(webservicesMD)) { throw WSLogger.ROOT_LOGGER.jaxRpcNotSupported(); } } } private URL getWebServicesDescriptorURL(final ResourceRoot deploymentRoot) throws DeploymentUnitProcessingException { VirtualFile wsdd = deploymentRoot.getRoot().getChild("WEB-INF/webservices.xml"); if (!wsdd.exists()) { wsdd = deploymentRoot.getRoot().getChild("META-INF/webservices.xml"); } try { return wsdd.exists() ? wsdd.toURL() : null; } catch (IOException e) { throw WSLogger.ROOT_LOGGER.cannotGetURLForDescriptor(e, wsdd.getPathName()); } } private boolean hasJaxRpcMapping(WebservicesMetaData webservicesMD) { for (WebserviceDescriptionMetaData wsdmd : webservicesMD.getWebserviceDescriptions()) { if (wsdmd.getJaxrpcMappingFile() != null) { return true; } } return false; } }
3,975
43.674157
121
java
null
wildfly-main/webservices/server-integration/src/main/java/org/jboss/as/webservices/deployers/AbstractIntegrationProcessorJAXWS.java
/* * JBoss, Home of Professional Open Source. * Copyright 2011, 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.jboss.as.webservices.deployers; import static org.jboss.as.ee.component.Attachments.EE_MODULE_DESCRIPTION; import static org.jboss.as.webservices.util.ASHelper.getRequiredAttachment; import static org.jboss.as.webservices.util.DotNames.SINGLETON_ANNOTATION; import static org.jboss.as.webservices.util.DotNames.STATELESS_ANNOTATION; import org.jboss.as.ee.component.ComponentConfiguration; import org.jboss.as.ee.component.ComponentDescription; import org.jboss.as.ee.component.EEModuleDescription; import org.jboss.as.ee.component.ViewConfiguration; import org.jboss.as.ee.component.ViewConfigurator; import org.jboss.as.ee.component.ViewDescription; import org.jboss.as.ee.component.interceptors.InterceptorOrder; import org.jboss.as.ee.structure.DeploymentType; import org.jboss.as.ee.structure.DeploymentTypeMarker; import org.jboss.as.server.deployment.Attachments; import org.jboss.as.server.deployment.DeploymentPhaseContext; 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.webservices.injection.WSComponentDescription; import org.jboss.as.webservices.service.EndpointService; import org.jboss.invocation.AccessCheckingInterceptor; import org.jboss.jandex.ClassInfo; import org.jboss.msc.service.ServiceName; /** * @author <a href="mailto:[email protected]">Richard Opalka</a> * @author <a href="mailto:[email protected]">Alessio Soldano</a> * @author <a href="mailto:[email protected]">Jim Ma</a> */ public abstract class AbstractIntegrationProcessorJAXWS implements DeploymentUnitProcessor { protected AbstractIntegrationProcessorJAXWS() { } @Override public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException { final DeploymentUnit unit = phaseContext.getDeploymentUnit(); if (DeploymentTypeMarker.isType(DeploymentType.EAR, unit)) { return; } final CompositeIndex index = unit.getAttachment(Attachments.COMPOSITE_ANNOTATION_INDEX); if (index == null) { return; } final EEModuleDescription eeModuleDescription = unit.getAttachment(org.jboss.as.ee.component.Attachments.EE_MODULE_DESCRIPTION); processAnnotation(unit, eeModuleDescription); } protected abstract void processAnnotation(final DeploymentUnit unit, final EEModuleDescription eeModuleDescription) throws DeploymentUnitProcessingException; static ComponentDescription createComponentDescription(final DeploymentUnit unit, final String componentName, final String componentClassName, final String dependsOnEndpointClassName) { final EEModuleDescription moduleDescription = getRequiredAttachment(unit, EE_MODULE_DESCRIPTION); // JBoss WEB processors may install fake components for WS endpoints - removing them forcibly moduleDescription.removeComponent(componentName, componentClassName); // register WS component ComponentDescription componentDescription = new WSComponentDescription(componentName, componentClassName, moduleDescription, unit.getServiceName()); moduleDescription.addComponent(componentDescription); // register WS dependency final ServiceName endpointServiceName = EndpointService.getServiceName(unit, dependsOnEndpointClassName); componentDescription.addDependency(endpointServiceName); return componentDescription; } static ServiceName registerView(final ComponentDescription componentDescription, final String componentClassName) { final ViewDescription pojoView = new ViewDescription(componentDescription, componentClassName); componentDescription.getViews().add(pojoView); pojoView.getConfigurators().add(new ViewConfigurator() { @Override public void configure(DeploymentPhaseContext context, ComponentConfiguration componentConfiguration, ViewDescription description, ViewConfiguration configuration) throws DeploymentUnitProcessingException { configuration.addViewInterceptor(AccessCheckingInterceptor.getFactory(), InterceptorOrder.View.CHECKING_INTERCEPTOR); // add WS POJO component instance associating interceptor configuration.addViewInterceptor(WSComponentInstanceAssociationInterceptor.FACTORY, InterceptorOrder.View.ASSOCIATING_INTERCEPTOR); } }); return pojoView.getServiceName(); } static boolean isEjb3(final ClassInfo clazz) { return clazz.annotationsMap().containsKey(STATELESS_ANNOTATION) || clazz.annotationsMap().containsKey(SINGLETON_ANNOTATION); } }
5,840
52.1
217
java
null
wildfly-main/webservices/server-integration/src/main/java/org/jboss/as/webservices/deployers/WSIntegrationProcessorJAXWS_EJB.java
/* * JBoss, Home of Professional Open Source. * Copyright 2011, Red Hat Middleware LLC, 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.jboss.as.webservices.deployers; import static org.jboss.as.ee.component.Attachments.EE_MODULE_DESCRIPTION; import static org.jboss.as.webservices.util.ASHelper.getJaxwsDeployment; import static org.jboss.as.webservices.util.ASHelper.getRequiredAttachment; import static org.jboss.as.webservices.util.DotNames.DECLARE_ROLES_ANNOTATION; import static org.jboss.as.webservices.util.DotNames.PERMIT_ALL_ANNOTATION; import static org.jboss.as.webservices.util.DotNames.ROLES_ALLOWED_ANNOTATION; import static org.jboss.as.webservices.util.DotNames.WEB_CONTEXT_ANNOTATION; import java.util.Collections; import java.util.HashSet; import java.util.LinkedList; import java.util.List; import java.util.Set; import jakarta.jws.WebService; import jakarta.xml.ws.WebServiceProvider; import org.jboss.as.ee.component.ComponentDescription; import org.jboss.as.ee.component.EEModuleClassDescription; import org.jboss.as.ee.component.EEModuleDescription; import org.jboss.as.ee.metadata.ClassAnnotationInformation; import org.jboss.as.ejb3.component.EJBViewDescription; import org.jboss.as.ejb3.component.session.SessionBeanComponentDescription; import org.jboss.as.ejb3.deployment.EjbDeploymentAttachmentKeys; import org.jboss.as.server.deployment.DeploymentPhaseContext; 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.webservices.metadata.model.EJBEndpoint; import org.jboss.as.webservices.metadata.model.JAXWSDeployment; import org.jboss.jandex.AnnotationInstance; import org.jboss.jandex.AnnotationTarget; import org.jboss.jandex.AnnotationValue; import org.jboss.jandex.ClassInfo; import org.jboss.metadata.ejb.spec.EjbJarMetaData; import org.jboss.metadata.javaee.spec.SecurityRoleMetaData; import org.jboss.metadata.javaee.spec.SecurityRolesMetaData; import org.jboss.msc.service.ServiceName; /** * @author <a href="mailto:[email protected]">Richard Opalka</a> * @author <a href="mailto:[email protected]">Jim Ma</a> * */ public final class WSIntegrationProcessorJAXWS_EJB implements DeploymentUnitProcessor { @Override public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException { final DeploymentUnit unit = phaseContext.getDeploymentUnit(); processAnnotation(unit, WebService.class); processAnnotation(unit, WebServiceProvider.class); } @SuppressWarnings("rawtypes") private static void processAnnotation(final DeploymentUnit unit, final Class annotationType) { final EEModuleDescription moduleDescription = getRequiredAttachment(unit, EE_MODULE_DESCRIPTION); final JAXWSDeployment jaxwsDeployment = getJaxwsDeployment(unit); for (EEModuleClassDescription description : moduleDescription.getClassDescriptions()) { @SuppressWarnings("unchecked") ClassAnnotationInformation classAnnotationInfo = description.getAnnotationInformation(annotationType); if (classAnnotationInfo != null && !classAnnotationInfo.getClassLevelAnnotations().isEmpty()) { Object obj = classAnnotationInfo.getClassLevelAnnotations().get(0); AnnotationTarget target = null; if (obj instanceof WebServiceAnnotationInfo) { target = ((WebServiceAnnotationInfo)obj).getTarget(); } else if (obj instanceof WebServiceProviderAnnotationInfo) { target = ((WebServiceProviderAnnotationInfo)obj).getTarget(); } else { return; } final ClassInfo webServiceClassInfo = (ClassInfo) target; final String webServiceClassName = webServiceClassInfo.name().toString(); final List<ComponentDescription> componentDescriptions = moduleDescription.getComponentsByClassName(webServiceClassName); final List<SessionBeanComponentDescription> sessionBeans = getSessionBeans(componentDescriptions); final Set<String> securityRoles = getDeclaredSecurityRoles(unit, webServiceClassInfo); // TODO: assembly processed for each endpoint! final WebContextAnnotationWrapper webCtx = getWebContextWrapper(webServiceClassInfo); final String authMethod = webCtx.getAuthMethod(); final boolean isSecureWsdlAccess = webCtx.isSecureWsdlAccess(); final String transportGuarantee = webCtx.getTransportGuarantee(); final String realmName = webCtx.getRealmName(); for (final SessionBeanComponentDescription sessionBean : sessionBeans) { if (sessionBean.isStateless() || sessionBean.isSingleton()) { final EJBViewDescription ejbViewDescription = sessionBean.addWebserviceEndpointView(); final ServiceName ejbViewName = ejbViewDescription.getServiceName(); jaxwsDeployment.addEndpoint(new EJBEndpoint(sessionBean, ejbViewName, securityRoles, authMethod, realmName, isSecureWsdlAccess, transportGuarantee)); } } } } } private static WebContextAnnotationWrapper getWebContextWrapper(final ClassInfo webServiceClassInfo) { if (!webServiceClassInfo.annotationsMap().containsKey(WEB_CONTEXT_ANNOTATION)) return new WebContextAnnotationWrapper(null); final AnnotationInstance webContextAnnotation = webServiceClassInfo.annotationsMap().get(WEB_CONTEXT_ANNOTATION).get(0); return new WebContextAnnotationWrapper(webContextAnnotation); } private static List<SessionBeanComponentDescription> getSessionBeans(final List<ComponentDescription> componentDescriptions) { final List<SessionBeanComponentDescription> sessionBeans = new LinkedList<SessionBeanComponentDescription>(); for (final ComponentDescription componentDescription : componentDescriptions) { if (componentDescription instanceof SessionBeanComponentDescription) { sessionBeans.add((SessionBeanComponentDescription) componentDescription); } } return sessionBeans; } private static Set<String> getDeclaredSecurityRoles(final DeploymentUnit unit, final ClassInfo webServiceClassInfo) { final Set<String> securityRoles = new HashSet<String>(); // process assembly-descriptor DD section final EjbJarMetaData ejbJarMD = unit.getAttachment(EjbDeploymentAttachmentKeys.EJB_JAR_METADATA); if (ejbJarMD != null && ejbJarMD.getAssemblyDescriptor() != null) { final List<SecurityRoleMetaData> securityRoleMetaDatas = ejbJarMD.getAssemblyDescriptor().getAny(SecurityRoleMetaData.class); if (securityRoleMetaDatas != null) { for (final SecurityRoleMetaData securityRoleMetaData : securityRoleMetaDatas) { securityRoles.add(securityRoleMetaData.getRoleName()); } } final SecurityRolesMetaData securityRolesMD = ejbJarMD.getAssemblyDescriptor().getSecurityRoles(); if (securityRolesMD != null && !securityRolesMD.isEmpty()) { for (final SecurityRoleMetaData securityRoleMD : securityRolesMD) { securityRoles.add(securityRoleMD.getRoleName()); } } } // process @RolesAllowed annotation if (webServiceClassInfo.annotationsMap().containsKey(ROLES_ALLOWED_ANNOTATION)) { final List<AnnotationInstance> allowedRoles = webServiceClassInfo.annotationsMap().get(ROLES_ALLOWED_ANNOTATION); for (final AnnotationInstance allowedRole : allowedRoles) { if (allowedRole.target().equals(webServiceClassInfo)) { for (final String roleName : allowedRole.value().asStringArray()) { securityRoles.add(roleName); } } } } // process @DeclareRoles annotation if (webServiceClassInfo.annotationsMap().containsKey(DECLARE_ROLES_ANNOTATION)) { final List<AnnotationInstance> declareRoles = webServiceClassInfo.annotationsMap().get(DECLARE_ROLES_ANNOTATION); for (final AnnotationInstance declareRole : declareRoles) { if (declareRole.target().equals(webServiceClassInfo)) { for (final String roleName : declareRole.value().asStringArray()) { securityRoles.add(roleName); } } } } // process @PermitAll annotation if (webServiceClassInfo.annotationsMap().containsKey(PERMIT_ALL_ANNOTATION)) { for (AnnotationInstance permitAll : webServiceClassInfo.annotationsMap().get(PERMIT_ALL_ANNOTATION)) { if (permitAll.target().equals(webServiceClassInfo)) { securityRoles.add("*"); break; } } } //if there is no class level security annotation, it will delegate to Jakarta Enterprise Beans's security check if (securityRoles.isEmpty()) { securityRoles.add("*"); } return Collections.unmodifiableSet(securityRoles); } private static final class WebContextAnnotationWrapper { private final String authMethod; private final String transportGuarantee; private final boolean secureWsdlAccess; private final String realmName; WebContextAnnotationWrapper(final AnnotationInstance annotation) { authMethod = stringValueOrNull(annotation, "authMethod"); transportGuarantee = stringValueOrNull(annotation, "transportGuarantee"); realmName = stringValueOrNull(annotation, "realmName"); secureWsdlAccess = booleanValue(annotation, "secureWSDLAccess"); } String getAuthMethod() { return authMethod; } String getTransportGuarantee() { return transportGuarantee; } boolean isSecureWsdlAccess() { return secureWsdlAccess; } String getRealmName() { return realmName; } private String stringValueOrNull(final AnnotationInstance annotation, final String attribute) { if (annotation == null) return null; final AnnotationValue value = annotation.value(attribute); return value != null ? value.asString() : null; } private boolean booleanValue(final AnnotationInstance annotation, final String attribute) { if (annotation == null) return false; final AnnotationValue value = annotation.value(attribute); return value != null ? value.asBoolean() : false; } } }
11,947
49.842553
173
java
null
wildfly-main/webservices/server-integration/src/main/java/org/jboss/as/webservices/deployers/WebServiceAnnotationInformationFactory.java
/* * JBoss, Home of Professional Open Source * Copyright 2014, Red Hat Inc., and individual contributors as indicated * by the @authors tag. See the copyright.txt 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.jboss.as.webservices.deployers; import jakarta.jws.WebService; import org.jboss.as.ee.metadata.ClassAnnotationInformationFactory; import org.jboss.jandex.AnnotationInstance; import org.jboss.jandex.AnnotationValue; import org.jboss.metadata.property.PropertyReplacer; /** * @author <a href="mailto:[email protected]">Jim Ma</a> */ public class WebServiceAnnotationInformationFactory extends ClassAnnotationInformationFactory<WebService, WebServiceAnnotationInfo> { protected WebServiceAnnotationInformationFactory() { super(jakarta.jws.WebService.class, null); } @Override protected WebServiceAnnotationInfo fromAnnotation(final AnnotationInstance annotationInstance, final PropertyReplacer propertyReplacer) { String nameValue = asString(annotationInstance, "name"); String targetNamespacValue = asString(annotationInstance, "targetNamespace"); String serviceNameValue = asString(annotationInstance, "serviceName"); String portNameValue = asString(annotationInstance, "portName"); String wsdlLocationValue = asString(annotationInstance, "wsdlLocation"); String endpointInterfaceValue = asString(annotationInstance, "endpointInterface"); return new WebServiceAnnotationInfo(endpointInterfaceValue, nameValue, portNameValue, serviceNameValue, targetNamespacValue, wsdlLocationValue, annotationInstance.target()); } private String asString(final AnnotationInstance annotation, String property) { AnnotationValue value = annotation.value(property); return value == null ? "" : value.asString(); } }
2,661
44.896552
141
java
null
wildfly-main/webservices/server-integration/src/main/java/org/jboss/as/webservices/deployers/AspectDeploymentProcessor.java
/* * JBoss, Home of Professional Open Source. * Copyright 2014, Red Hat Middleware LLC, 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.jboss.as.webservices.deployers; import org.jboss.as.server.deployment.DeploymentPhaseContext; 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.webservices.logging.WSLogger; import org.jboss.as.webservices.util.ASHelper; import org.jboss.as.webservices.util.WSAttachmentKeys; import org.jboss.msc.service.ServiceTarget; import org.jboss.wsf.spi.classloading.ClassLoaderProvider; import org.jboss.wsf.spi.deployment.Deployment; import org.jboss.wsf.spi.deployment.DeploymentAspect; import org.wildfly.security.manager.WildFlySecurityManager; /** * Adaptor of DeploymentAspect to DeploymentUnitProcessor * * @author <a href="mailto:[email protected]">Alessio Soldano</a> * @author <a href="mailto:[email protected]">Richard Opalka</a> */ public final class AspectDeploymentProcessor implements DeploymentUnitProcessor { private Class<? extends DeploymentAspect> clazz; private String aspectClass; private DeploymentAspect aspect; public AspectDeploymentProcessor(final Class<? extends DeploymentAspect> aspectClass) { this.clazz = aspectClass; } public AspectDeploymentProcessor(final String aspectClass) { this.aspectClass = aspectClass; } public AspectDeploymentProcessor(final DeploymentAspect aspect) { this.aspect = aspect; this.clazz = aspect.getClass(); } @Override public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException { final DeploymentUnit unit = phaseContext.getDeploymentUnit(); if (isWebServiceDeployment(unit)) { ensureAspectInitialized(); final Deployment dep = ASHelper.getRequiredAttachment(unit, WSAttachmentKeys.DEPLOYMENT_KEY); WSLogger.ROOT_LOGGER.tracef("%s start: %s", aspect, unit.getName()); ClassLoader origClassLoader = WildFlySecurityManager.getCurrentContextClassLoaderPrivileged(); try { WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(aspect.getLoader()); dep.addAttachment(ServiceTarget.class, phaseContext.getServiceTarget()); aspect.start(dep); dep.removeAttachment(ServiceTarget.class); } finally { WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(origClassLoader); } } } @Override public void undeploy(final DeploymentUnit unit) { if (isWebServiceDeployment(unit)) { final Deployment dep = ASHelper.getRequiredAttachment(unit, WSAttachmentKeys.DEPLOYMENT_KEY); WSLogger.ROOT_LOGGER.tracef("%s stop: %s", aspect, unit.getName()); ClassLoader origClassLoader = WildFlySecurityManager.getCurrentContextClassLoaderPrivileged(); try { WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(aspect.getLoader()); aspect.stop(dep); } finally { WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(origClassLoader); } } } @SuppressWarnings("unchecked") private void ensureAspectInitialized() throws DeploymentUnitProcessingException { if (aspect == null) { try { if (clazz == null) { clazz = (Class<? extends DeploymentAspect>) ClassLoaderProvider.getDefaultProvider() .getServerIntegrationClassLoader().loadClass(aspectClass); } aspect = clazz.newInstance(); } catch (Exception e) { throw new DeploymentUnitProcessingException(e); } } } private static boolean isWebServiceDeployment(final DeploymentUnit unit) { return unit.getAttachment(WSAttachmentKeys.DEPLOYMENT_KEY) != null; } }
5,039
42.448276
108
java
null
wildfly-main/webservices/server-integration/src/main/java/org/jboss/as/webservices/deployers/WSIntegrationProcessorJAXWS_JMS.java
/* * JBoss, Home of Professional Open Source. * Copyright 2011, Red Hat Middleware LLC, 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.jboss.as.webservices.deployers; import static org.jboss.as.server.deployment.Attachments.DEPLOYMENT_ROOT; import static org.jboss.as.server.deployment.Attachments.RESOURCE_ROOTS; import static org.jboss.as.webservices.util.ASHelper.getAnnotations; import static org.jboss.as.webservices.util.DotNames.WEB_SERVICE_ANNOTATION; import static org.jboss.as.webservices.util.WSAttachmentKeys.JMS_ENDPOINT_METADATA_KEY; import java.net.URL; import java.util.HashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; import javax.xml.namespace.QName; import org.jboss.as.ee.structure.DeploymentType; import org.jboss.as.ee.structure.DeploymentTypeMarker; import org.jboss.as.server.deployment.AttachmentList; import org.jboss.as.server.deployment.DeploymentPhaseContext; 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.module.ResourceRoot; import org.jboss.as.webservices.logging.WSLogger; import org.jboss.jandex.AnnotationInstance; import org.jboss.jandex.AnnotationValue; import org.jboss.jandex.ClassInfo; import org.jboss.vfs.VirtualFile; import org.jboss.ws.common.deployment.SOAPAddressWSDLParser; import org.jboss.wsf.spi.metadata.jms.JMSEndpointMetaData; import org.jboss.wsf.spi.metadata.jms.JMSEndpointsMetaData; /** * DUP for detecting Jakarta Messaging WS endpoints * * @author <a href="mailto:[email protected]">Alessio Soldano</a> */ public final class WSIntegrationProcessorJAXWS_JMS implements DeploymentUnitProcessor { private static final String WSDL_LOCATION = "wsdlLocation"; private static final String PORT_NAME = "portName"; private static final String SERVICE_NAME = "serviceName"; private static final String TARGET_NAMESPACE = "targetNamespace"; @Override public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException { final DeploymentUnit unit = phaseContext.getDeploymentUnit(); if (DeploymentTypeMarker.isType(DeploymentType.EAR, unit)) { return; } final List<AnnotationInstance> webServiceAnnotations = getAnnotations(unit, WEB_SERVICE_ANNOTATION); // TODO: how about @WebServiceProvider JMS based endpoints? //group @WebService annotations in the deployment by wsdl contract location Map<String, List<AnnotationInstance>> map = new HashMap<String, List<AnnotationInstance>>(); for (AnnotationInstance webServiceAnnotation : webServiceAnnotations) { final AnnotationValue wsdlLocation = webServiceAnnotation.value(WSDL_LOCATION); final AnnotationValue port = webServiceAnnotation.value(PORT_NAME); final AnnotationValue service = webServiceAnnotation.value(SERVICE_NAME); //support for contract-first development only: pick-up @WebService annotations referencing a provided wsdl contract only if (wsdlLocation != null && port != null && service != null) { String key = wsdlLocation.asString(); List<AnnotationInstance> annotations = map.get(key); if (annotations == null) { annotations = new LinkedList<AnnotationInstance>(); map.put(key, annotations); } annotations.add(webServiceAnnotation); } } //extract SOAP-over-JMS 1.0 bindings List<JMSEndpointMetaData> list = new LinkedList<JMSEndpointMetaData>(); if (!map.isEmpty()) { for (String wsdlLocation : map.keySet()) { try { final ResourceRoot resourceRoot = getWsdlResourceRoot(unit, wsdlLocation); if (resourceRoot == null) continue; final VirtualFile wsdlLocationFile = resourceRoot.getRoot().getChild(wsdlLocation); final URL url = wsdlLocationFile.toURL(); SOAPAddressWSDLParser parser = new SOAPAddressWSDLParser(url); for (AnnotationInstance ai : map.get(wsdlLocation)) { String port = ai.value(PORT_NAME).asString(); String service = ai.value(SERVICE_NAME).asString(); AnnotationValue targetNS = ai.value(TARGET_NAMESPACE); String tns = targetNS != null ? targetNS.asString() : null; QName serviceName = new QName(tns, service); QName portName = new QName(tns, port); String soapAddress = parser.filterSoapAddress(serviceName, portName, SOAPAddressWSDLParser.SOAP_OVER_JMS_NS); if (soapAddress != null) { ClassInfo webServiceClassInfo = (ClassInfo) ai.target(); String beanClassName = webServiceClassInfo.name().toString(); //service name ? list.add(new JMSEndpointMetaData(beanClassName, port, beanClassName, wsdlLocation, soapAddress)); } } } catch (Exception ignore) { WSLogger.ROOT_LOGGER.cannotReadWsdl(wsdlLocation); } } } unit.putAttachment(JMS_ENDPOINT_METADATA_KEY, new JMSEndpointsMetaData(list)); } private static ResourceRoot getWsdlResourceRoot(final DeploymentUnit unit, final String wsdlPath) { final AttachmentList<ResourceRoot> resourceRoots = new AttachmentList<ResourceRoot>(ResourceRoot.class); final ResourceRoot root = unit.getAttachment(DEPLOYMENT_ROOT); resourceRoots.add(root); final AttachmentList<ResourceRoot> otherResourceRoots = unit.getAttachment(RESOURCE_ROOTS); if (otherResourceRoots != null) { resourceRoots.addAll(otherResourceRoots); } for (final ResourceRoot resourceRoot : resourceRoots) { VirtualFile file = resourceRoot.getRoot().getChild(wsdlPath); if (file.exists()) return resourceRoot; } return null; } }
7,270
49.144828
133
java
null
wildfly-main/webservices/server-integration/src/main/java/org/jboss/as/webservices/deployers/WebServiceContextResourceProcessor.java
/* * JBoss, Home of Professional Open Source. * Copyright 2011, 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.jboss.as.webservices.deployers; import jakarta.xml.ws.WebServiceContext; import org.jboss.as.ee.component.InjectionSource; import org.jboss.as.ee.component.deployers.EEResourceReferenceProcessor; import org.jboss.as.server.deployment.DeploymentUnitProcessingException; import org.jboss.as.webservices.injection.WebServiceContextInjectionSource; /** * Processes {@link jakarta.annotation.Resource @Resource} and {@link jakarta.annotation.Resources @Resources} annotations * for a {@link WebServiceContext} type resource * <p/> * * @author Jaikiran Pai */ public final class WebServiceContextResourceProcessor implements EEResourceReferenceProcessor { @Override public String getResourceReferenceType() { return WebServiceContext.class.getName(); } @Override public InjectionSource getResourceReferenceBindingSource() throws DeploymentUnitProcessingException { return new WebServiceContextInjectionSource(); } }
1,998
37.442308
122
java
null
wildfly-main/webservices/server-integration/src/main/java/org/jboss/as/webservices/deployers/UnifiedServiceRefDeploymentAspect.java
/* * JBoss, Home of Professional Open Source * Copyright 2011, Red Hat Inc., and individual contributors as indicated * by the @authors tag. See the copyright.txt 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.jboss.as.webservices.deployers; import static org.jboss.ws.common.integration.WSHelper.getRequiredAttachment; import java.util.Map; import javax.xml.namespace.QName; import org.jboss.as.server.deployment.DeploymentUnit; import org.jboss.as.webservices.util.ASHelper; import org.jboss.as.webservices.webserviceref.WSRefRegistry; import org.jboss.ws.common.integration.AbstractDeploymentAspect; import org.jboss.wsf.spi.deployment.Deployment; import org.jboss.wsf.spi.metadata.j2ee.serviceref.UnifiedServiceRefMetaData; /** * DeploymentAspect to set deployed ServiceName and address map in unifiedServiceRefMetaData * @author <a href="mailto:[email protected]">Jim Ma</a> */ public class UnifiedServiceRefDeploymentAspect extends AbstractDeploymentAspect { @Override public void start(final Deployment dep) { final DeploymentUnit unit = getRequiredAttachment(dep, DeploymentUnit.class); WSRefRegistry wsRefRegistry = ASHelper.getWSRefRegistry(unit); Object obj = dep.getProperty("ServiceAddressMap"); if(obj != null) { @SuppressWarnings("unchecked") Map<QName, String> deployedPortsAddress = (Map<QName, String>)obj; for (UnifiedServiceRefMetaData metaData : wsRefRegistry.getUnifiedServiceRefMetaDatas()) { metaData.addDeployedServiceAddresses(deployedPortsAddress); } } } }
2,424
42.303571
102
java
null
wildfly-main/webservices/server-integration/src/main/java/org/jboss/as/webservices/deployers/WSEndpointConfigMapping.java
/* * JBoss, Home of Professional Open Source. * Copyright 2015, 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.jboss.as.webservices.deployers; import static org.wildfly.common.Assert.checkNotNullParam; import java.util.HashMap; import java.util.Map; import org.jboss.wsf.spi.metadata.config.EndpointConfig; /** * Defines mapping of endpoints and their config. * * @author <a href="mailto:[email protected]">Alessio Soldano</a> */ public final class WSEndpointConfigMapping { private final Map<String, EndpointConfig> endpointConfigMap = new HashMap<String, EndpointConfig>(); /** * Registers endpoint and its config. * * @param endpointClass WS endpoint * @param config Config with endpoint */ public void registerEndpointConfig(final String endpointClass, final EndpointConfig config) { checkNotNullParam("endpointClass", endpointClass); checkNotNullParam("config", config); endpointConfigMap.put(endpointClass, config); } /** * Returns config associated with WS endpoint. * * @param endpointClass to get associated config * @return associated config */ public EndpointConfig getConfig(final String endpointClass) { return endpointConfigMap.get(endpointClass); } public boolean isEmpty() { return endpointConfigMap.size() == 0; } }
2,306
32.434783
104
java
null
wildfly-main/webservices/server-integration/src/main/java/org/jboss/as/webservices/deployers/AllowWSRequestPredicate.java
/* * JBoss, Home of Professional Open Source. * Copyright 2016, 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.jboss.as.webservices.deployers; import org.jboss.wsf.spi.deployment.WSFServlet; import io.undertow.predicate.Predicate; import io.undertow.server.HttpServerExchange; import io.undertow.servlet.handlers.ServletRequestContext; public class AllowWSRequestPredicate implements Predicate { @Override public boolean resolve(HttpServerExchange exchange) { ServletRequestContext src = exchange.getAttachment(ServletRequestContext.ATTACHMENT_KEY); return src.getCurrentServlet().getManagedServlet().getServletInfo().getServletClass().equals(WSFServlet.class); } }
1,623
40.641026
119
java
null
wildfly-main/webservices/server-integration/src/main/java/org/jboss/as/webservices/deployers/EndpointRecordProcessorDeploymentAspect.java
/* * JBoss, Home of Professional Open Source. * Copyright 2006, Red Hat Middleware LLC, 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.jboss.as.webservices.deployers; import java.util.Collections; import java.util.Iterator; import java.util.LinkedList; import java.util.List; import java.util.ServiceLoader; import java.util.Vector; import org.jboss.ws.api.monitoring.RecordProcessor; import org.jboss.ws.api.monitoring.RecordProcessorFactory; import org.jboss.ws.common.integration.AbstractDeploymentAspect; import org.jboss.wsf.spi.deployment.Deployment; import org.jboss.wsf.spi.deployment.Endpoint; /** * An aspect that sets the record processors for each endpoint. * * @author [email protected] * @author <a href="mailto:[email protected]">Richard Opalka</a> */ public final class EndpointRecordProcessorDeploymentAspect extends AbstractDeploymentAspect { private List<RecordProcessor> processors = new LinkedList<RecordProcessor>(); public EndpointRecordProcessorDeploymentAspect() { ServiceLoader<RecordProcessorFactory> loader = ServiceLoader.load(RecordProcessorFactory.class); Iterator<RecordProcessorFactory> iterator = loader.iterator(); while (iterator.hasNext()) { RecordProcessorFactory factory = iterator.next(); processors.addAll(factory.newRecordProcessors()); } } @Override public void start(final Deployment dep) { final int size = processors.size(); for (final Endpoint ep : dep.getService().getEndpoints()) { List<RecordProcessor> processorList = new Vector<RecordProcessor>(size); for (RecordProcessor pr : processors) { try { RecordProcessor clone = (RecordProcessor) pr.clone(); processorList.add(clone); } catch (final CloneNotSupportedException ex) { throw new RuntimeException(ex); } } ep.setRecordProcessors(processorList); } } public void stop(final Deployment dep) { for (final Endpoint ep : dep.getService().getEndpoints()) { ep.setRecordProcessors(Collections.<RecordProcessor>emptyList()); } } }
3,157
38.475
104
java
null
wildfly-main/webservices/server-integration/src/main/java/org/jboss/as/webservices/deployers/WSLibraryFilterProcessor.java
/* * 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.jboss.as.webservices.deployers; import static org.jboss.as.server.deployment.Attachments.ANNOTATION_INDEX; import static org.jboss.as.server.deployment.Attachments.RESOURCE_ROOTS; import static org.jboss.as.webservices.util.ASHelper.hasClassesFromPackage; import static org.jboss.as.webservices.util.ASHelper.isJaxwsEndpoint; import static org.jboss.as.webservices.util.DotNames.WEB_SERVICE_ANNOTATION; import static org.jboss.as.webservices.util.DotNames.WEB_SERVICE_PROVIDER_ANNOTATION; import java.util.List; import org.jboss.as.ee.structure.DeploymentType; import org.jboss.as.ee.structure.DeploymentTypeMarker; import org.jboss.as.server.deployment.AttachmentList; import org.jboss.as.server.deployment.Attachments; import org.jboss.as.server.deployment.DeploymentPhaseContext; 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.server.deployment.module.ResourceRoot; import org.jboss.as.webservices.logging.WSLogger; import org.jboss.jandex.AnnotationInstance; import org.jboss.jandex.AnnotationTarget; import org.jboss.jandex.ClassInfo; import org.jboss.jandex.DotName; /** * @author <a href="mailto:[email protected]">Alessio Soldano</a> */ public class WSLibraryFilterProcessor implements DeploymentUnitProcessor { @Override public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException { final DeploymentUnit unit = phaseContext.getDeploymentUnit(); if (DeploymentTypeMarker.isType(DeploymentType.EAR, unit)) { return; } final CompositeIndex index = unit.getAttachment(Attachments.COMPOSITE_ANNOTATION_INDEX); if (index != null) { //perform checks on included libraries only if there're actually WS endpoints in the deployment if (hasWSEndpoints(index)) { AttachmentList<ResourceRoot> resourceRoots = unit.getAttachment(RESOURCE_ROOTS); if (resourceRoots != null) { for (ResourceRoot root : resourceRoots) { if (root.getRoot().getChild("META-INF/services/javax.xml.datatype.DatatypeFactory").exists() || root.getRoot().getChild("META-INF/services/javax.xml.parsers.DocumentBuilderFactory").exists() || root.getRoot().getChild("META-INF/services/javax.xml.parsers.SAXParserFactory").exists() || root.getRoot().getChild("META-INF/services/javax.xml.validation.SchemaFactory").exists()) { WSLogger.ROOT_LOGGER.warningLibraryInDeployment("JAXP Implementation", root.getRootName()); } if (hasClassesFromPackage(root.getAttachment(ANNOTATION_INDEX), "org.apache.cxf")) { throw WSLogger.ROOT_LOGGER.invalidLibraryInDeployment("Apache CXF", root.getRootName()); } } } } } else { WSLogger.ROOT_LOGGER.tracef("Skipping WS annotation processing since no composite annotation index found in unit: %s", unit.getName()); } } private boolean hasWSEndpoints(final CompositeIndex index) { final DotName[] dotNames = {WEB_SERVICE_ANNOTATION, WEB_SERVICE_PROVIDER_ANNOTATION}; for (final DotName dotName : dotNames) { final List<AnnotationInstance> wsAnnotations = index.getAnnotations(dotName); if (!wsAnnotations.isEmpty()) { for (final AnnotationInstance wsAnnotation : wsAnnotations) { final AnnotationTarget target = wsAnnotation.target(); if (target instanceof ClassInfo) { final ClassInfo classInfo = (ClassInfo) target; if (isJaxwsEndpoint(classInfo, index)) { return true; } } } } } return false; } }
5,250
49.490385
147
java
null
wildfly-main/webservices/server-integration/src/main/java/org/jboss/as/webservices/deployers/WSServiceDependenciesProcessor.java
/* * JBoss, Home of Professional Open Source * Copyright 2011, Red Hat Inc., and individual contributors as indicated * by the @authors tag. See the copyright.txt 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.jboss.as.webservices.deployers; import org.jboss.as.server.deployment.DeploymentPhaseContext; import org.jboss.as.server.deployment.DeploymentUnitProcessingException; import org.jboss.as.server.deployment.DeploymentUnitProcessor; import org.jboss.as.webservices.util.WSAttachmentKeys; import org.jboss.as.webservices.util.WSServices; /** * A DUP that sets the service dependencies to be satisfied before installing any deployments * * @author <a href="mailto:[email protected]">Alessio Soldano</a> */ public final class WSServiceDependenciesProcessor implements DeploymentUnitProcessor { public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException { phaseContext.addDependency(WSServices.CONFIG_SERVICE, WSAttachmentKeys.SERVER_CONFIG_KEY); } }
1,841
43.926829
102
java
null
wildfly-main/webservices/server-integration/src/main/java/org/jboss/as/webservices/deployers/WebServicesContextJndiSetupProcessor.java
/* * JBoss, Home of Professional Open Source. * Copyright 2012, 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.jboss.as.webservices.deployers; import org.jboss.as.ee.component.Attachments; import org.jboss.as.ee.component.deployers.EEResourceReferenceProcessorRegistry; import org.jboss.as.server.deployment.DeploymentPhaseContext; import org.jboss.as.server.deployment.DeploymentUnit; import org.jboss.as.server.deployment.DeploymentUnitProcessingException; import org.jboss.as.server.deployment.DeploymentUnitProcessor; /** * @author Stuart Douglas */ public class WebServicesContextJndiSetupProcessor implements DeploymentUnitProcessor { @Override public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException { final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit(); final EEResourceReferenceProcessorRegistry registry = deploymentUnit.getAttachment(Attachments.RESOURCE_REFERENCE_PROCESSOR_REGISTRY); if (registry != null) { // Add an EEResourceReferenceProcessor which handles @Resource references of type WebServiceContext. registry.registerResourceReferenceProcessor(new WebServiceContextResourceProcessor()); } } }
2,179
46.391304
142
java
null
wildfly-main/webservices/server-integration/src/main/java/org/jboss/as/webservices/deployers/TCCLDeploymentProcessor.java
/* * JBoss, Home of Professional Open Source * Copyright 2011, Red Hat Inc., and individual contributors as indicated * by the @authors tag. See the copyright.txt 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.jboss.as.webservices.deployers; import org.jboss.as.server.deployment.DeploymentPhaseContext; import org.jboss.as.server.deployment.DeploymentUnit; import org.jboss.as.server.deployment.DeploymentUnitProcessingException; import org.jboss.as.server.deployment.DeploymentUnitProcessor; import org.jboss.wsf.spi.classloading.ClassLoaderProvider; import org.wildfly.security.manager.WildFlySecurityManager; /** * A DUP that sets the context classloader * * @author [email protected] * @since 14-Jan-2011 */ public abstract class TCCLDeploymentProcessor implements DeploymentUnitProcessor { @Override public final void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException { ClassLoader origClassLoader = WildFlySecurityManager.getCurrentContextClassLoaderPrivileged(); try { WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(ClassLoaderProvider.getDefaultProvider().getServerIntegrationClassLoader()); internalDeploy(phaseContext); } finally { WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(origClassLoader); } } @Override public final void undeploy(final DeploymentUnit context) { ClassLoader origClassLoader = WildFlySecurityManager.getCurrentContextClassLoaderPrivileged(); try { WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(ClassLoaderProvider.getDefaultProvider().getServerIntegrationClassLoader()); internalUndeploy(context); } finally { WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(origClassLoader); } } public abstract void internalDeploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException; public abstract void internalUndeploy(final DeploymentUnit context); }
2,900
43.630769
150
java
null
wildfly-main/webservices/server-integration/src/main/java/org/jboss/as/webservices/deployers/WSComponentInstanceAssociationInterceptor.java
/* * JBoss, Home of Professional Open Source. * Copyright 2012, 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.jboss.as.webservices.deployers; import org.jboss.as.ee.component.BasicComponentInstance; import org.jboss.as.ee.component.Component; import org.jboss.as.ee.component.ComponentInstance; import org.jboss.as.naming.ManagedReference; import org.jboss.as.webservices.injection.WSComponent; import org.jboss.invocation.ImmediateInterceptorFactory; import org.jboss.invocation.Interceptor; import org.jboss.invocation.InterceptorContext; import org.jboss.invocation.InterceptorFactory; /** * Associates component instance for a POJO WS bean during invocation. * * @author <a href="mailto:[email protected]">Richard Opalka</a> */ final class WSComponentInstanceAssociationInterceptor implements Interceptor { public static final InterceptorFactory FACTORY = new ImmediateInterceptorFactory(new WSComponentInstanceAssociationInterceptor()); private WSComponentInstanceAssociationInterceptor() {} @Override public Object processInvocation(final InterceptorContext interceptorContext) throws Exception { final WSComponent wsComponent = (WSComponent)interceptorContext.getPrivateData(Component.class); BasicComponentInstance pojoComponentInstance = null; if (interceptorContext.getPrivateData(ManagedReference.class) != null) { ManagedReference reference = interceptorContext.getPrivateData(ManagedReference.class); pojoComponentInstance = (BasicComponentInstance)wsComponent.createInstance(reference.getInstance()); } else { pojoComponentInstance = wsComponent.getComponentInstance(); } interceptorContext.putPrivateData(ComponentInstance.class, pojoComponentInstance); return interceptorContext.proceed(); } }
2,754
45.694915
134
java
null
wildfly-main/webservices/server-integration/src/main/java/org/jboss/as/webservices/deployers/WSIntegrationProcessorJAXWS_HANDLER.java
/* * JBoss, Home of Professional Open Source. * Copyright 2015, 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.jboss.as.webservices.deployers; import static org.jboss.as.server.deployment.Attachments.DEPLOYMENT_ROOT; import static org.jboss.as.webservices.util.ASHelper.getJaxwsEjbs; import static org.jboss.as.webservices.util.ASHelper.getJaxwsPojos; import static org.jboss.as.webservices.util.ASHelper.getOptionalAttachment; import static org.jboss.as.webservices.util.ASHelper.isJaxwsEndpoint; import static org.jboss.as.webservices.util.WSAttachmentKeys.WS_ENDPOINT_HANDLERS_MAPPING_KEY; import java.util.Set; import jakarta.jws.WebService; import jakarta.xml.ws.WebServiceProvider; import org.jboss.as.ee.component.ComponentDescription; import org.jboss.as.ee.component.DeploymentDescriptorEnvironment; import org.jboss.as.ee.component.EEModuleClassDescription; import org.jboss.as.ee.component.EEModuleDescription; import org.jboss.as.ee.metadata.ClassAnnotationInformation; import org.jboss.as.ee.structure.DeploymentType; import org.jboss.as.ee.structure.DeploymentTypeMarker; import org.jboss.as.server.deployment.Attachments; import org.jboss.as.server.deployment.DeploymentUnit; import org.jboss.as.server.deployment.DeploymentUnitProcessingException; import org.jboss.as.server.deployment.annotation.CompositeIndex; import org.jboss.as.webservices.injection.WSEndpointHandlersMapping; import org.jboss.as.webservices.metadata.model.EJBEndpoint; import org.jboss.as.webservices.metadata.model.POJOEndpoint; import org.jboss.as.webservices.util.ASHelper; import org.jboss.as.webservices.util.WSAttachmentKeys; import org.jboss.jandex.ClassInfo; import org.jboss.metadata.web.jboss.JBossWebMetaData; import org.jboss.msc.service.ServiceName; import org.jboss.vfs.VirtualFile; import org.jboss.wsf.spi.metadata.config.EndpointConfig; import org.jboss.wsf.spi.metadata.webservices.JBossWebservicesMetaData; /** * @author <a href="mailto:[email protected]">Richard Opalka</a> * @author <a href="mailto:[email protected]">Jim Ma</a> * @author <a href="mailto:[email protected]">Alessio Soldano</a> */ public final class WSIntegrationProcessorJAXWS_HANDLER extends AbstractIntegrationProcessorJAXWS { public WSIntegrationProcessorJAXWS_HANDLER() { } @Override protected void processAnnotation(final DeploymentUnit unit, final EEModuleDescription moduleDescription) throws DeploymentUnitProcessingException { final WSEndpointHandlersMapping mapping = getOptionalAttachment(unit, WS_ENDPOINT_HANDLERS_MAPPING_KEY); final VirtualFile root = unit.getAttachment(DEPLOYMENT_ROOT).getRoot(); final JBossWebservicesMetaData jbossWebservicesMD = unit.getAttachment(WSAttachmentKeys.JBOSS_WEBSERVICES_METADATA_KEY); final CompositeIndex index = unit.getAttachment(Attachments.COMPOSITE_ANNOTATION_INDEX); final boolean war = DeploymentTypeMarker.isType(DeploymentType.WAR, unit); final JBossWebMetaData jwmd = ASHelper.getJBossWebMetaData(unit); for (EEModuleClassDescription classDescription : moduleDescription.getClassDescriptions()) { ClassInfo classInfo = null; ClassAnnotationInformation<WebService, WebServiceAnnotationInfo> annotationInfo = classDescription .getAnnotationInformation(WebService.class); if (annotationInfo != null) { classInfo = (ClassInfo) annotationInfo.getClassLevelAnnotations().get(0).getTarget(); } final ClassAnnotationInformation<WebServiceProvider, WebServiceProviderAnnotationInfo> providreInfo = classDescription .getAnnotationInformation(WebServiceProvider.class); if (providreInfo != null) { classInfo = (ClassInfo) providreInfo.getClassLevelAnnotations().get(0).getTarget(); } if (classInfo != null && isJaxwsEndpoint(classInfo, index, false)) { final String endpointClassName = classInfo.name().toString(); final ConfigResolver configResolver = new ConfigResolver(classInfo, jbossWebservicesMD, jwmd, root, war); final EndpointConfig config = configResolver.resolveEndpointConfig(); if (config != null) { registerConfigMapping(endpointClassName, config, unit); } final Set<String> handlers = getHandlers(endpointClassName, config, configResolver, mapping); if (!handlers.isEmpty()) { if (isEjb3(classInfo)) { for (final EJBEndpoint ejbEndpoint : getJaxwsEjbs(unit)) { if (endpointClassName.equals(ejbEndpoint.getClassName())) { for (final String handlerClassName : handlers) { final String ejbEndpointName = ejbEndpoint.getName(); final String handlerName = ejbEndpointName + "-" + handlerClassName; final ComponentDescription jaxwsHandlerDescription = createComponentDescription(unit, handlerName, handlerClassName, ejbEndpointName); propagateNamingContext(jaxwsHandlerDescription, ejbEndpoint); } } } } else { for (final POJOEndpoint pojoEndpoint : getJaxwsPojos(unit)) { if (endpointClassName.equals(pojoEndpoint.getClassName())) { for (final String handlerClassName : handlers) { final String pojoEndpointName = pojoEndpoint.getName(); final String handlerName = pojoEndpointName + "-" + handlerClassName; createComponentDescription(unit, handlerName, handlerClassName, pojoEndpointName); } } } } } } } } //TODO this could be moved to a separate DeploymentUnitProcessor operating on endpoints (together with the rest of the config resolution mechanism) private void registerConfigMapping(String endpointClassName, EndpointConfig config, DeploymentUnit unit) { WSEndpointConfigMapping mapping = unit.getAttachment(WSAttachmentKeys.WS_ENDPOINT_CONFIG_MAPPING_KEY); if (mapping == null) { mapping = new WSEndpointConfigMapping(); unit.putAttachment(WSAttachmentKeys.WS_ENDPOINT_CONFIG_MAPPING_KEY, mapping); } mapping.registerEndpointConfig(endpointClassName, config); } private Set<String> getHandlers(String endpointClassName, EndpointConfig config, ConfigResolver resolver, WSEndpointHandlersMapping mapping) { Set<String> handlers = resolver.getAllHandlers(config); //handlers from the resolved endpoint configuration if (mapping != null) { Set<String> hch = mapping.getHandlers(endpointClassName); // handlers from @HandlerChain if (hch != null) { handlers.addAll(hch); } } return handlers; } private static void propagateNamingContext(final ComponentDescription jaxwsHandlerDescription, final EJBEndpoint ejbEndpoint) { final ServiceName ejbContextServiceName = ejbEndpoint.getContextServiceName(); final DeploymentDescriptorEnvironment ejbEnv = ejbEndpoint.getDeploymentDescriptorEnvironment(); // configure Jakarta XML Web Services Enterprise Beans 3 handler to be able to see Enterprise Beans 3 environment jaxwsHandlerDescription.setContextServiceName(ejbContextServiceName); jaxwsHandlerDescription.setDeploymentDescriptorEnvironment(ejbEnv); jaxwsHandlerDescription.addDependency(ejbContextServiceName); } }
8,926
55.144654
151
java
null
wildfly-main/webservices/server-integration/src/main/java/org/jboss/as/webservices/deployers/WebServiceProviderAnnotationInformationFactory.java
/* * JBoss, Home of Professional Open Source * Copyright 2014, Red Hat Inc., and individual contributors as indicated * by the @authors tag. See the copyright.txt 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.jboss.as.webservices.deployers; import jakarta.xml.ws.WebServiceProvider; import org.jboss.as.ee.metadata.ClassAnnotationInformationFactory; import org.jboss.jandex.AnnotationInstance; import org.jboss.jandex.AnnotationValue; import org.jboss.metadata.property.PropertyReplacer; /** * @author <a href="mailto:[email protected]">Jim Ma</a> */ public class WebServiceProviderAnnotationInformationFactory extends ClassAnnotationInformationFactory<WebServiceProvider, WebServiceProviderAnnotationInfo> { protected WebServiceProviderAnnotationInformationFactory() { super(WebServiceProvider.class, null); } @Override protected WebServiceProviderAnnotationInfo fromAnnotation(final AnnotationInstance annotationInstance, final PropertyReplacer propertyReplacer) { String targetNamespacValue = asString(annotationInstance, "targetNamespace"); String serviceNameValue = asString(annotationInstance, "serviceName"); String portNameValue = asString(annotationInstance, "portName"); String wsdlLocationValue = asString(annotationInstance, "wsdlLocation"); return new WebServiceProviderAnnotationInfo(portNameValue, serviceNameValue, targetNamespacValue, wsdlLocationValue, annotationInstance.target()); } private String asString(final AnnotationInstance annotation, String property) { AnnotationValue value = annotation.value(property); return value == null ? "" : value.asString(); } }
2,525
44.107143
149
java
null
wildfly-main/webservices/server-integration/src/main/java/org/jboss/as/webservices/deployers/WebServiceAnnotationInfo.java
/* * JBoss, Home of Professional Open Source * Copyright 2014, Red Hat Inc., and individual contributors as indicated * by the @authors tag. See the copyright.txt 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.jboss.as.webservices.deployers; import org.jboss.jandex.AnnotationTarget; /** * @author <a href="mailto:[email protected]">Jim Ma</a> */ public class WebServiceAnnotationInfo { private final String wsdlLocation; private final String endpointInterface; private final String portName; private final String serviceName; private final String name; private final String targetNamespace; private final AnnotationTarget target; public WebServiceAnnotationInfo(final String endpointInterface, final String name, final String portName, final String servicename, final String targetNamespace, final String wsdlLocation, final AnnotationTarget target) { this.wsdlLocation = wsdlLocation; this.endpointInterface = endpointInterface; this.portName = portName; this.serviceName = servicename; this.name = name; this.targetNamespace = targetNamespace; this.target = target; } public String getTargetNamespace() { return targetNamespace; } public String getName() { return name; } public String getServiceName() { return serviceName; } public String getPortName() { return portName; } public String getEndpointInterface() { return endpointInterface; } public String getWsdlLocation() { return wsdlLocation; } public AnnotationTarget getTarget() { return target; } }
2,498
29.108434
225
java
null
wildfly-main/webservices/server-integration/src/main/java/org/jboss/as/webservices/deployers/ConfigResolver.java
/* * JBoss, Home of Professional Open Source. * Copyright 2015, 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.jboss.as.webservices.deployers; import java.io.IOException; import java.lang.annotation.Annotation; import java.net.MalformedURLException; import java.net.URL; import java.util.List; import org.jboss.jandex.AnnotationInstance; import org.jboss.jandex.AnnotationValue; import org.jboss.jandex.ClassInfo; import org.jboss.jandex.DotName; import org.jboss.metadata.javaee.spec.ParamValueMetaData; import org.jboss.metadata.web.jboss.JBossWebMetaData; import org.jboss.vfs.VirtualFile; import org.jboss.ws.api.annotation.EndpointConfig; import org.jboss.ws.common.configuration.AbstractCommonConfigResolver; import org.jboss.ws.common.integration.WSConstants; import org.jboss.wsf.spi.metadata.webservices.JBossWebservicesMetaData; public class ConfigResolver extends AbstractCommonConfigResolver { private final ClassInfo epClassInfo; private final String className; private final String annotationConfigName; private final String annotationConfigFile; private final String descriptorConfigName; private final String descriptorConfigFile; private final VirtualFile root; private final boolean isWar; public ConfigResolver(ClassInfo epClassInfo, JBossWebservicesMetaData jwmd, JBossWebMetaData jbwebmd, VirtualFile root, boolean isWar) { this.epClassInfo = epClassInfo; this.className = epClassInfo.name().toString(); List<AnnotationInstance> annotations = epClassInfo.annotationsMap().get( DotName.createSimple(EndpointConfig.class.getName())); if (annotations != null && !annotations.isEmpty()) { AnnotationInstance ann = annotations.get(0); AnnotationValue av = ann.value("configName"); this.annotationConfigName = av != null ? av.asString() : null; av = ann.value("configFile"); this.annotationConfigFile = av != null ? av.asString() : null; } else { this.annotationConfigName = null; this.annotationConfigFile = null; } String f = null; String n = null; if (jbwebmd != null && jbwebmd.getContextParams() != null) { for (ParamValueMetaData pvmd : jbwebmd.getContextParams()) { if (WSConstants.JBOSSWS_CONFIG_NAME.equals(pvmd.getParamName())) { n = pvmd.getParamValue(); } if (WSConstants.JBOSSWS_CONFIG_FILE.equals(pvmd.getParamName())) { f = pvmd.getParamValue(); } } } this.descriptorConfigFile = f != null ? f : (jwmd != null ? jwmd.getConfigFile() : null); this.descriptorConfigName = n != null ? n : (jwmd != null ? jwmd.getConfigName() : null); this.root = root; this.isWar = isWar; } @Override protected String getEndpointClassName() { return className; } @Override protected <T extends Annotation> boolean isEndpointClassAnnotated(Class<T> annotation) { return epClassInfo.annotationsMap().containsKey(DotName.createSimple(annotation.getName())); } @Override protected String getEndpointConfigNameFromAnnotation() { return annotationConfigName; } @Override protected String getEndpointConfigFileFromAnnotation() { return annotationConfigFile; } @Override protected String getEndpointConfigNameOverride() { return descriptorConfigName; } @Override protected String getEndpointConfigFileOverride() { return descriptorConfigFile; } @Override protected URL getConfigFile(String configFileName) throws IOException { return root.getChild(configFileName).asFileURL(); } @Override protected URL getDefaultConfigFile(String defaultConfigFileName) { URL url = null; if (isWar) { url = asFileURL(root.getChild("/WEB-INF/classes/" + defaultConfigFileName)); } if (url == null) { url = asFileURL(root.getChild("/" + defaultConfigFileName)); } return url; } private URL asFileURL(VirtualFile vf) { URL url = null; if (vf != null && vf.exists()) { try { url = vf.asFileURL(); } catch (MalformedURLException e) { // ignore } } return url; } }
5,396
36.22069
140
java
null
wildfly-main/webservices/server-integration/src/main/java/org/jboss/as/webservices/deployers/WSModelDeploymentProcessor.java
/* * JBoss, Home of Professional Open Source. * Copyright 2011, Red Hat Middleware LLC, 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.jboss.as.webservices.deployers; import org.jboss.as.server.deployment.DeploymentPhaseContext; import org.jboss.as.server.deployment.DeploymentUnit; import org.jboss.as.server.deployment.DeploymentUnitProcessor; import org.jboss.as.webservices.config.ServerConfigFactoryImpl; import org.jboss.as.webservices.config.ServerConfigImpl; import org.jboss.as.webservices.deployers.deployment.WSDeploymentBuilder; import org.jboss.as.webservices.util.WSAttachmentKeys; /** * This deployer initializes JBossWS deployment meta data. * * @author <a href="mailto:[email protected]">Richard Opalka</a> * @author <a href="mailto:[email protected]">Alessio Soldano</a> */ public final class WSModelDeploymentProcessor extends TCCLDeploymentProcessor implements DeploymentUnitProcessor { @Override public void internalDeploy(final DeploymentPhaseContext phaseContext) { final DeploymentUnit unit = phaseContext.getDeploymentUnit(); WSDeploymentBuilder.getInstance().build(unit); if (isWebServiceDeployment(unit)) { //note, this check works only after the WSDeploymentBuilder above has run ServerConfigImpl config = (ServerConfigImpl)ServerConfigFactoryImpl.getConfig(); config.incrementWSDeploymentCount(); } } @Override public void internalUndeploy(final DeploymentUnit context) { if (isWebServiceDeployment(context)) { ServerConfigImpl config = (ServerConfigImpl)ServerConfigFactoryImpl.getConfig(); config.decrementWSDeploymentCount(); } // Cleans up reference established by AbstractDeploymentModelBuilder#propagateAttachments context.removeAttachment(WSAttachmentKeys.DEPLOYMENT_KEY); } private static boolean isWebServiceDeployment(final DeploymentUnit unit) { return unit.getAttachment(WSAttachmentKeys.DEPLOYMENT_KEY) != null; } }
2,940
43.560606
117
java
null
wildfly-main/webservices/server-integration/src/main/java/org/jboss/as/webservices/deployers/WSIntegrationProcessorJAXWS_POJO.java
/* * JBoss, Home of Professional Open Source. * Copyright 2011, 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.jboss.as.webservices.deployers; import static org.jboss.as.webservices.util.ASHelper.getEndpointClassName; import static org.jboss.as.webservices.util.ASHelper.getEndpointName; import static org.jboss.as.webservices.util.ASHelper.getJBossWebMetaData; import static org.jboss.as.webservices.util.ASHelper.getJaxwsDeployment; import static org.jboss.as.webservices.util.ASHelper.getJBossWebserviceMetaDataPortComponent; import static org.jboss.as.webservices.util.ASHelper.getRequiredAttachment; import static org.jboss.as.webservices.util.ASHelper.isJaxwsEndpoint; import static org.jboss.as.webservices.util.ASHelper.getWebserviceMetadataEJBEndpoint; import static org.jboss.as.webservices.util.WSAttachmentKeys.JMS_ENDPOINT_METADATA_KEY; import static org.jboss.as.webservices.util.WebMetaDataHelper.getServlets; import java.util.HashMap; import java.util.HashSet; import java.util.Map; import java.util.Set; import jakarta.jws.WebService; import jakarta.xml.ws.WebServiceProvider; import org.jboss.as.ee.component.ComponentDescription; import org.jboss.as.ee.component.EEModuleClassDescription; import org.jboss.as.ee.component.EEModuleDescription; import org.jboss.as.ee.metadata.ClassAnnotationInformation; import org.jboss.as.ee.structure.DeploymentType; import org.jboss.as.ee.structure.DeploymentTypeMarker; import org.jboss.as.server.deployment.Attachments; import org.jboss.as.server.deployment.DeploymentUnit; import org.jboss.as.server.deployment.DeploymentUnitProcessingException; import org.jboss.as.server.deployment.annotation.CompositeIndex; import org.jboss.as.webservices.metadata.model.EJBEndpoint; import org.jboss.as.webservices.metadata.model.JAXWSDeployment; import org.jboss.as.webservices.metadata.model.POJOEndpoint; import org.jboss.jandex.ClassInfo; import org.jboss.metadata.web.jboss.JBossWebMetaData; import org.jboss.metadata.web.spec.ServletMappingMetaData; import org.jboss.metadata.web.spec.ServletMetaData; import org.jboss.msc.service.ServiceName; import org.jboss.ws.api.annotation.WebContext; import org.jboss.wsf.spi.metadata.jms.JMSEndpointMetaData; import org.jboss.wsf.spi.metadata.jms.JMSEndpointsMetaData; import org.jboss.ws.common.utils.UrlPatternUtils; /** * @author <a href="mailto:[email protected]">Richard Opalka</a> * @author <a href="mailto:[email protected]">Alessio Soldano</a> * @author <a href="mailto:[email protected]">Jim Ma</a> */ public class WSIntegrationProcessorJAXWS_POJO extends AbstractIntegrationProcessorJAXWS { public WSIntegrationProcessorJAXWS_POJO() { } // @Override protected void processAnnotation(final DeploymentUnit unit, final EEModuleDescription moduleDescription) throws DeploymentUnitProcessingException { if (!DeploymentTypeMarker.isType(DeploymentType.WAR, unit)) { return; } final Map<String, EEModuleClassDescription> classDescriptionMap = new HashMap<String, org.jboss.as.ee.component.EEModuleClassDescription>(); final CompositeIndex index = unit.getAttachment(Attachments.COMPOSITE_ANNOTATION_INDEX); for (EEModuleClassDescription classDescritpion : moduleDescription.getClassDescriptions()) { if (isJaxwsEndpoint(classDescritpion, index) && !exclude(unit, classDescritpion)) { classDescriptionMap.put(classDescritpion.getClassName(), classDescritpion); } } final JBossWebMetaData jbossWebMD = getJBossWebMetaData(unit); final JAXWSDeployment jaxwsDeployment = getJaxwsDeployment(unit); if (jbossWebMD != null) { final Set<String> matchedEps = new HashSet<String>(); for (final ServletMetaData servletMD : getServlets(jbossWebMD)) { final String endpointClassName = getEndpointClassName(servletMD); final String endpointName = getEndpointName(servletMD); if (classDescriptionMap.containsKey(endpointClassName) || matchedEps.contains(endpointClassName)) { // creating component description for POJO endpoint final ComponentDescription pojoComponent = createComponentDescription(unit, endpointName, endpointClassName, endpointName); final ServiceName pojoViewName = registerView(pojoComponent, endpointClassName); final String urlPattern = getUrlPattern(endpointName, unit); jaxwsDeployment.addEndpoint(new POJOEndpoint(endpointName, endpointClassName, pojoViewName, urlPattern)); classDescriptionMap.remove(endpointClassName); matchedEps.add(endpointClassName); } else { if (unit.getParent() != null && DeploymentTypeMarker.isType(DeploymentType.EAR, unit.getParent())) { final EEModuleDescription eeModuleDescription = unit.getParent().getAttachment( org.jboss.as.ee.component.Attachments.EE_MODULE_DESCRIPTION); final CompositeIndex parentIndex = unit.getParent().getAttachment( Attachments.COMPOSITE_ANNOTATION_INDEX); for (EEModuleClassDescription classDescription : eeModuleDescription.getClassDescriptions()) { if (classDescription.getClassName().equals(endpointClassName) && isJaxwsEndpoint(classDescription, parentIndex)) { final ComponentDescription pojoComponent = createComponentDescription(unit, endpointName, endpointClassName, endpointName); final ServiceName pojoViewName = registerView(pojoComponent, endpointClassName); final String urlPattern = getUrlPattern(endpointName, unit); jaxwsDeployment.addEndpoint(new POJOEndpoint(endpointName, endpointClassName, pojoViewName, urlPattern)); } } } } } } for (EEModuleClassDescription classDescription : classDescriptionMap.values()) { ClassInfo classInfo = null; String serviceName = null; String urlPattern = null; // #1 Override serviceName with the explicit urlPattern from port-component/port-component-uri in jboss-webservices.xml EJBEndpoint ejbEndpoint = getWebserviceMetadataEJBEndpoint(jaxwsDeployment, classDescription.getClassName()); if (ejbEndpoint != null) { urlPattern = UrlPatternUtils.getUrlPatternByPortComponentURI( getJBossWebserviceMetaDataPortComponent(unit, ejbEndpoint.getName())); } // #2 Override serviceName with @WebContext.urlPattern if (urlPattern == null) { final ClassAnnotationInformation<WebContext, WebContextAnnotationInfo> annotationWebContext = classDescription.getAnnotationInformation(WebContext.class); if (annotationWebContext != null) { WebContextAnnotationInfo wsInfo = annotationWebContext.getClassLevelAnnotations().get(0); if (wsInfo != null && wsInfo.getUrlPattern().length() > 0) { urlPattern = wsInfo.getUrlPattern(); } } } // #3 use serviceName declared in a class annotation if (urlPattern == null) { final ClassAnnotationInformation<WebService, WebServiceAnnotationInfo> annotationInfo = classDescription .getAnnotationInformation(WebService.class); if (annotationInfo != null) { WebServiceAnnotationInfo wsInfo = annotationInfo.getClassLevelAnnotations().get(0); serviceName = wsInfo.getServiceName(); classInfo = (ClassInfo)wsInfo.getTarget(); urlPattern = UrlPatternUtils.getUrlPattern(classInfo.name().local(), serviceName); if (jaxwsDeployment.contains(urlPattern)){ urlPattern = UrlPatternUtils.getUrlPattern(classInfo.name().local(), serviceName, wsInfo.getName()); } } final ClassAnnotationInformation<WebServiceProvider, WebServiceProviderAnnotationInfo> annotationProviderInfo = classDescription .getAnnotationInformation(WebServiceProvider.class); if (annotationProviderInfo != null) { WebServiceProviderAnnotationInfo wsInfo = annotationProviderInfo.getClassLevelAnnotations().get(0); serviceName = wsInfo.getServiceName(); classInfo = (ClassInfo)wsInfo.getTarget(); } } if (classInfo != null) { final String endpointClassName = classDescription.getClassName(); final ComponentDescription pojoComponent = createComponentDescription(unit, endpointClassName, endpointClassName, endpointClassName); final ServiceName pojoViewName = registerView(pojoComponent, endpointClassName); if (urlPattern == null) { urlPattern = UrlPatternUtils.getUrlPattern(classInfo.name().local(), serviceName); } // register POJO endpoint jaxwsDeployment.addEndpoint(new POJOEndpoint(endpointClassName, pojoViewName, UrlPatternUtils.getUrlPattern(urlPattern))); } } } private boolean exclude(final DeploymentUnit unit, final EEModuleClassDescription classDescription) { //exclude if it's Enterprise Beans 3 and Jakarta Messaging endpoint ClassInfo classInfo = null; ClassAnnotationInformation<WebService, WebServiceAnnotationInfo> annotationInfo = classDescription .getAnnotationInformation(WebService.class); if (annotationInfo != null) { classInfo = (ClassInfo) annotationInfo.getClassLevelAnnotations().get(0).getTarget(); } else { ClassAnnotationInformation<WebServiceProvider, WebServiceProviderAnnotationInfo> providreInfo = classDescription .getAnnotationInformation(WebServiceProvider.class); classInfo = (ClassInfo) providreInfo.getClassLevelAnnotations().get(0).getTarget(); } if (isEjb3(classInfo) || isJmsEndpoint(unit, classInfo)) { return true; } return false; } private static String getUrlPattern(final String servletName, final DeploymentUnit unit) { final JBossWebMetaData jbossWebMD = getJBossWebMetaData(unit); for (final ServletMappingMetaData servletMappingMD : jbossWebMD.getServletMappings()) { if (servletName.equals(servletMappingMD.getServletName())) { return servletMappingMD.getUrlPatterns().get(0); } } throw new IllegalStateException(); } private static boolean isJmsEndpoint(final DeploymentUnit unit, final ClassInfo classInfo) { final String endpointClassName = classInfo.name().toString(); final JMSEndpointsMetaData jmsEndpointsMD = getRequiredAttachment(unit, JMS_ENDPOINT_METADATA_KEY); for (final JMSEndpointMetaData endpoint : jmsEndpointsMD.getEndpointsMetaData()) { if (endpointClassName.equals(endpoint.getImplementor())) { return true; } } return false; } }
12,669
53.612069
148
java
null
wildfly-main/webservices/server-integration/src/main/java/org/jboss/as/webservices/deployers/WSDependenciesProcessor.java
/* * JBoss, Home of Professional Open Source * Copyright 2014, Red Hat Inc., and individual contributors as indicated * by the @authors tag. See the copyright.txt 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.jboss.as.webservices.deployers; import org.jboss.as.server.deployment.Attachments; import org.jboss.as.server.deployment.DeploymentPhaseContext; 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.module.ModuleDependency; import org.jboss.as.server.deployment.module.ModuleSpecification; import org.jboss.modules.Module; import org.jboss.modules.ModuleLoader; import org.jboss.wsf.spi.deployment.Endpoint; /** * A DUP that sets the WS dependencies * * @author <a href="mailto:[email protected]">Alessio Soldano</a> * @author <a href="mailto:[email protected]">Richard Opalka</a> */ public final class WSDependenciesProcessor implements DeploymentUnitProcessor { public static final String JBOSSWS_API = "org.jboss.ws.api"; public static final String JBOSSWS_SPI = "org.jboss.ws.spi"; public static final String[] JAVAEE_APIS = { "jakarta.xml.ws.api", "jakarta.xml.soap.api" }; public static final String XERCES_IMPL = "org.apache.xerces"; private final boolean addJBossWSDependencies; public WSDependenciesProcessor(boolean addJBossWSDependencies) { this.addJBossWSDependencies = addJBossWSDependencies; } public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException { final DeploymentUnit unit = phaseContext.getDeploymentUnit(); final ModuleLoader moduleLoader = Module.getBootModuleLoader(); final ModuleSpecification moduleSpec = unit.getAttachment(Attachments.MODULE_SPECIFICATION); if (addJBossWSDependencies) { moduleSpec.addSystemDependency(new ModuleDependency(moduleLoader, JBOSSWS_API, false, true, true, false)); moduleSpec.addSystemDependency(new ModuleDependency(moduleLoader, JBOSSWS_SPI, false, true, true, false)); } for(String api : JAVAEE_APIS) { moduleSpec.addSystemDependency(new ModuleDependency(moduleLoader, api, false, false, true, false)); } //After jboss modules 2.0, the xerces module is not added and this is required for jaxb 2.3.x(EE8) to pass the TCK //But this is not needed for jaxb 3.x in WildFly Preview(EE10) if (Endpoint.class.getPackage().getImplementationVersion().startsWith("3")) { moduleSpec.addSystemDependency(new ModuleDependency(moduleLoader, XERCES_IMPL, true, false, true, false)); } } }
3,606
46.460526
122
java
null
wildfly-main/webservices/server-integration/src/main/java/org/jboss/as/webservices/deployers/EndpointServiceDeploymentAspect.java
/* * JBoss, Home of Professional Open Source * Copyright 2013, Red Hat Inc., and individual contributors as indicated * by the @authors tag. See the copyright.txt 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.jboss.as.webservices.deployers; import static org.jboss.ws.common.integration.WSHelper.getOptionalAttachment; import static org.jboss.ws.common.integration.WSHelper.getRequiredAttachment; import org.jboss.as.server.deployment.DeploymentUnit; import org.jboss.as.webservices.service.EndpointService; import org.jboss.msc.service.ServiceTarget; import org.jboss.ws.common.integration.AbstractDeploymentAspect; import org.jboss.wsf.spi.deployment.Deployment; import org.jboss.wsf.spi.deployment.Endpoint; /** * Creates Endpoint Service instance when starting the Endpoint * * @author [email protected] * @author <a href="mailto:[email protected]">Richard Opalka</a> * @author <a href="mailto:[email protected]">Jim Ma</a> */ public final class EndpointServiceDeploymentAspect extends AbstractDeploymentAspect implements Cloneable { private boolean stopServices = false; @Override public void start(final Deployment dep) { final ServiceTarget target = getOptionalAttachment(dep, ServiceTarget.class); final DeploymentUnit unit = getRequiredAttachment(dep, DeploymentUnit.class); for (final Endpoint ep : dep.getService().getEndpoints()) { EndpointService.install(target, ep, unit); } } @Override public void stop(Deployment dep) { for (final Endpoint ep : dep.getService().getEndpoints()) { if (ep.getLifecycleHandler() != null) { ep.getLifecycleHandler().stop(ep); } if (stopServices) { final DeploymentUnit unit = getRequiredAttachment(dep, DeploymentUnit.class); EndpointService.uninstall(ep, unit); } } } public void setStopServices(boolean stopServices) { this.stopServices = stopServices; } public Object clone() { EndpointServiceDeploymentAspect clone = new EndpointServiceDeploymentAspect(); clone.setLast(isLast()); clone.setProvides(getProvides()); clone.setRelativeOrder(getRelativeOrder()); clone.setRequires(getRequires()); clone.setStopServices(stopServices); return clone; } }
3,200
38.518519
106
java
null
wildfly-main/webservices/server-integration/src/main/java/org/jboss/as/webservices/deployers/WebServiceProviderAnnotationInfo.java
/* * JBoss, Home of Professional Open Source * Copyright 2014, Red Hat Inc., and individual contributors as indicated * by the @authors tag. See the copyright.txt 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.jboss.as.webservices.deployers; import org.jboss.jandex.AnnotationTarget; /** * @author <a href="mailto:[email protected]">Jim Ma</a> */ public class WebServiceProviderAnnotationInfo { private final String wsdlLocation; private final String portName; private final String serviceName; private final String targetNamespace; private final AnnotationTarget target; public WebServiceProviderAnnotationInfo(final String portName, final String serviceName, final String targetNamespace, final String wsdlLocation, final AnnotationTarget target) { this.wsdlLocation = wsdlLocation; this.portName = portName; this.serviceName = serviceName; this.targetNamespace = targetNamespace; this.target = target; } public String getTargetNamespace() { return targetNamespace; } public String getServiceName() { return serviceName; } public String getPortName() { return portName; } public String getWsdlLocation() { return wsdlLocation; } public AnnotationTarget getTarget() { return target; } }
2,169
29.138889
182
java
null
wildfly-main/webservices/server-integration/src/main/java/org/jboss/as/webservices/deployers/WebContextAnnotationInfo.java
package org.jboss.as.webservices.deployers; /** * User: rsearls * Date: 7/17/14 */ public class WebContextAnnotationInfo { private final String authMethod; private final String contextRoot; private final boolean secureWSDLAccess; private final String transportGuarantee; private final String urlPattern; private final String virtualHost; public WebContextAnnotationInfo(final String authMethod, final String contextRoot, final boolean secureWSDLAccess, final String transportGuarantee, final String urlPattern, final String virtualHost) { this.authMethod = authMethod; this.contextRoot = contextRoot; this.secureWSDLAccess = secureWSDLAccess; this.transportGuarantee = transportGuarantee; this.urlPattern = urlPattern; this.virtualHost = virtualHost; } public String getAuthMethod() { return authMethod; } public String getContextRoot() { return contextRoot; } public boolean isSecureWSDLAccess() { return secureWSDLAccess; } public String getTransportGuarantee() { return transportGuarantee; } public String getUrlPattern() { return urlPattern; } public String getVirtualHost() { return virtualHost; } }
1,295
24.411765
204
java
null
wildfly-main/webservices/server-integration/src/main/java/org/jboss/as/webservices/deployers/deployment/DeploymentModelBuilderJAXWS_EJB.java
/* * JBoss, Home of Professional Open Source. * Copyright 2014, Red Hat Middleware LLC, 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.jboss.as.webservices.deployers.deployment; import static org.jboss.as.webservices.metadata.model.AbstractEndpoint.COMPONENT_VIEW_NAME; import static org.jboss.as.webservices.util.ASHelper.getJaxwsEjbs; import static org.jboss.wsf.spi.deployment.EndpointType.JAXWS_EJB3; import org.jboss.as.server.deployment.DeploymentUnit; import org.jboss.as.webservices.deployers.WSEndpointConfigMapping; import org.jboss.as.webservices.logging.WSLogger; import org.jboss.as.webservices.metadata.model.EJBEndpoint; import org.jboss.as.webservices.util.WSAttachmentKeys; import org.jboss.msc.service.ServiceName; import org.jboss.wsf.spi.deployment.Deployment; import org.jboss.wsf.spi.deployment.Endpoint; /** * Creates new JAXWS Enterprise Beans 3 deployment. * * @author <a href="mailto:[email protected]">Richard Opalka</a> */ final class DeploymentModelBuilderJAXWS_EJB extends AbstractDeploymentModelBuilder { DeploymentModelBuilderJAXWS_EJB() { super(JAXWS_EJB3); } @Override protected void build(final Deployment dep, final DeploymentUnit unit) { WSLogger.ROOT_LOGGER.trace("Creating JAXWS EJB endpoints meta data model"); WSEndpointConfigMapping ecm = unit.getAttachment(WSAttachmentKeys.WS_ENDPOINT_CONFIG_MAPPING_KEY); for (final EJBEndpoint ejbEndpoint : getJaxwsEjbs(unit)) { final String ejbEndpointName = ejbEndpoint.getName(); WSLogger.ROOT_LOGGER.tracef("EJB name: %s", ejbEndpointName); final String ejbEndpointClassName = ejbEndpoint.getClassName(); WSLogger.ROOT_LOGGER.tracef("EJB class: %s", ejbEndpointClassName); final Endpoint ep = newHttpEndpoint(ejbEndpointClassName, ejbEndpointName, dep); final ServiceName componentViewName = ejbEndpoint.getComponentViewName(); if (componentViewName != null) { ep.setProperty(COMPONENT_VIEW_NAME, componentViewName); } ep.setEndpointConfig(ecm.getConfig(ejbEndpointClassName)); markWeldDeployment(unit, ep); } } }
3,114
44.808824
106
java
null
wildfly-main/webservices/server-integration/src/main/java/org/jboss/as/webservices/deployers/deployment/AbstractDeploymentModelBuilder.java
/* * JBoss, Home of Professional Open Source. * Copyright 2014, Red Hat Middleware LLC, 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.jboss.as.webservices.deployers.deployment; import static org.jboss.as.webservices.metadata.model.AbstractEndpoint.WELD_DEPLOYMENT; import static org.jboss.as.webservices.util.ASHelper.getJBossWebMetaData; import static org.jboss.as.webservices.util.ASHelper.getOptionalAttachment; import static org.jboss.as.webservices.util.WSAttachmentKeys.CLASSLOADER_KEY; import static org.jboss.as.webservices.util.WSAttachmentKeys.DEPLOYMENT_KEY; import static org.jboss.as.webservices.util.WSAttachmentKeys.JAXWS_ENDPOINTS_KEY; import static org.jboss.as.webservices.util.WSAttachmentKeys.JBOSS_WEBSERVICES_METADATA_KEY; import static org.jboss.as.webservices.util.WSAttachmentKeys.REJECTION_RULE_KEY; import static org.jboss.as.webservices.util.WSAttachmentKeys.WEBSERVICES_METADATA_KEY; import org.jboss.as.controller.capability.CapabilityServiceSupport; import org.jboss.as.ejb3.deployment.EjbDeploymentAttachmentKeys; import org.jboss.as.server.deployment.Attachments; import org.jboss.as.server.deployment.DeploymentUnit; import org.jboss.as.server.deployment.module.ResourceRoot; import org.jboss.as.webservices.logging.WSLogger; import org.jboss.as.webservices.metadata.model.JAXWSDeployment; import org.jboss.as.webservices.util.VirtualFileAdaptor; import org.jboss.as.weld.WeldCapability; import org.jboss.metadata.ejb.spec.EjbJarMetaData; import org.jboss.metadata.web.jboss.JBossWebMetaData; import org.jboss.modules.Module; import org.jboss.vfs.VirtualFile; import org.jboss.ws.common.ResourceLoaderAdapter; import org.jboss.wsf.spi.SPIProvider; import org.jboss.wsf.spi.SPIProviderResolver; import org.jboss.wsf.spi.deployment.AnnotationsInfo; import org.jboss.wsf.spi.deployment.ArchiveDeployment; import org.jboss.wsf.spi.deployment.Deployment; import org.jboss.wsf.spi.deployment.DeploymentModelFactory; import org.jboss.wsf.spi.deployment.Endpoint; import org.jboss.wsf.spi.deployment.EndpointType; import org.jboss.wsf.spi.deployment.UnifiedVirtualFile; import org.jboss.wsf.spi.invocation.RejectionRule; import org.jboss.wsf.spi.metadata.webservices.JBossWebservicesMetaData; import org.jboss.wsf.spi.metadata.webservices.WebservicesMetaData; import static org.jboss.as.weld.Capabilities.WELD_CAPABILITY_NAME; /** * Base class for all deployment model builders. * * @author <a href="mailto:[email protected]">Alessio Soldano</a> * @author <a href="mailto:[email protected]">Richard Opalka</a> */ abstract class AbstractDeploymentModelBuilder implements DeploymentModelBuilder { /** Deployment model factory. */ private final DeploymentModelFactory deploymentModelFactory; /** Endpoint type this builder creates. */ private final EndpointType endpointType; /** * Constructor. */ protected AbstractDeploymentModelBuilder(final EndpointType endpointType) { // deployment factory final ClassLoader cl = AbstractDeploymentModelBuilder.class.getClassLoader(); final SPIProvider spiProvider = SPIProviderResolver.getInstance(cl).getProvider(); this.deploymentModelFactory = spiProvider.getSPI(DeploymentModelFactory.class, cl); this.endpointType = endpointType; } /** * @see org.jboss.webservices.integration.deployers.deployment.DeploymentModelBuilder#newDeploymentModel(DeploymentUnit) * * @param unit deployment unit */ public final void newDeploymentModel(final DeploymentUnit unit) { final ArchiveDeployment dep; if (unit.hasAttachment(DEPLOYMENT_KEY)) { dep = (ArchiveDeployment) unit.getAttachment(DEPLOYMENT_KEY); } else { dep = newDeployment(unit); propagateAttachments(unit, dep); } this.build(dep, unit); } private void propagateAttachments(final DeploymentUnit unit, final ArchiveDeployment dep) { dep.addAttachment(DeploymentUnit.class, unit); unit.putAttachment(DEPLOYMENT_KEY, dep); final JBossWebMetaData webMD = getJBossWebMetaData(unit); dep.addAttachment(JBossWebMetaData.class, webMD); final WebservicesMetaData webservicesMD = getOptionalAttachment(unit, WEBSERVICES_METADATA_KEY); dep.addAttachment(WebservicesMetaData.class, webservicesMD); JBossWebservicesMetaData jbossWebservicesMD = getOptionalAttachment(unit, JBOSS_WEBSERVICES_METADATA_KEY); if (unit.getParent() != null) { jbossWebservicesMD = JBossWebservicesMetaData.merge( getOptionalAttachment(unit.getParent(), JBOSS_WEBSERVICES_METADATA_KEY), jbossWebservicesMD); } dep.addAttachment(JBossWebservicesMetaData.class, jbossWebservicesMD); final JAXWSDeployment jaxwsDeployment = getOptionalAttachment(unit, JAXWS_ENDPOINTS_KEY); dep.addAttachment(JAXWSDeployment.class, jaxwsDeployment); final EjbJarMetaData ejbJarMD = getOptionalAttachment(unit, EjbDeploymentAttachmentKeys.EJB_JAR_METADATA); dep.addAttachment(EjbJarMetaData.class, ejbJarMD); final RejectionRule rr = getOptionalAttachment(unit, REJECTION_RULE_KEY); if (rr != null) { dep.addAttachment(RejectionRule.class, rr); } } /** * Template method for subclasses to implement. * * @param dep webservice deployment * @param unit deployment unit */ protected abstract void build(Deployment dep, DeploymentUnit unit); /** * Creates new Http Web Service endpoint. * * @param endpointClass endpoint class name * @param endpointName endpoint name * @param dep deployment * @return WS endpoint */ protected final Endpoint newHttpEndpoint(final String endpointClass, final String endpointName, final Deployment dep) { if (endpointName == null) throw WSLogger.ROOT_LOGGER.nullEndpointName(); if (endpointClass == null) throw WSLogger.ROOT_LOGGER.nullEndpointClass(); final Endpoint endpoint = this.deploymentModelFactory.newHttpEndpoint(endpointClass); endpoint.setShortName(endpointName); endpoint.setType(endpointType); dep.getService().addEndpoint(endpoint); return endpoint; } /** * Creates new Jakarta Messaging Web Service endpoint. * * @param endpointClass endpoint class name * @param endpointName endpoint name * @param dep deployment * @return WS endpoint */ protected final Endpoint newJMSEndpoint(final String endpointClass, final String endpointName, final String soapAddress, final Deployment dep) { if (endpointName == null) throw WSLogger.ROOT_LOGGER.nullEndpointName(); if (endpointClass == null) throw WSLogger.ROOT_LOGGER.nullEndpointClass(); final Endpoint endpoint = deploymentModelFactory.newJMSEndpoint(endpointClass); endpoint.setAddress(soapAddress); endpoint.setShortName(endpointName); endpoint.setType(endpointType); dep.getService().addEndpoint(endpoint); return endpoint; } protected void markWeldDeployment(DeploymentUnit unit, Endpoint ep) { final CapabilityServiceSupport support = unit.getAttachment(Attachments.CAPABILITY_SERVICE_SUPPORT); if (support.hasCapability(WELD_CAPABILITY_NAME)) { final WeldCapability weldCapabiltiy = support.getOptionalCapabilityRuntimeAPI(WELD_CAPABILITY_NAME, WeldCapability.class).get(); if (weldCapabiltiy.isWeldDeployment(unit)) { ep.setProperty(WELD_DEPLOYMENT, true); } } } /** * Creates new Web Service deployment. * * @param unit deployment unit * @return archive deployment */ private ArchiveDeployment newDeployment(final DeploymentUnit unit) { WSLogger.ROOT_LOGGER.tracef("Creating new unified WS deployment model for %s", unit); final ResourceRoot deploymentRoot = unit.getAttachment(Attachments.DEPLOYMENT_ROOT); final VirtualFile root = deploymentRoot != null ? deploymentRoot.getRoot() : null; final ClassLoader classLoader; final Module module = unit.getAttachment(Attachments.MODULE); if (module == null) { classLoader = unit.getAttachment(CLASSLOADER_KEY); if (classLoader == null) { throw WSLogger.ROOT_LOGGER.classLoaderResolutionFailed(unit); } } else { classLoader = module.getClassLoader(); } ArchiveDeployment parentDep = null; if (unit.getParent() != null) { final Module parentModule = unit.getParent().getAttachment(Attachments.MODULE); if (parentModule == null) { throw WSLogger.ROOT_LOGGER.classLoaderResolutionFailed(deploymentRoot); } WSLogger.ROOT_LOGGER.tracef("Creating new unified WS deployment model for %s", unit.getParent()); parentDep = this.newDeployment(null, unit.getParent().getName(), parentModule.getClassLoader(), null); } final UnifiedVirtualFile uvf = root != null ? new VirtualFileAdaptor(root) : new ResourceLoaderAdapter(classLoader); final ArchiveDeployment dep = this.newDeployment(parentDep, unit.getName(), classLoader, uvf); //add an AnnotationInfo attachment that uses composite jandex index dep.addAttachment(AnnotationsInfo.class, new JandexAnnotationsInfo(unit)); return dep; } private ArchiveDeployment newDeployment(final ArchiveDeployment parent, final String name, final ClassLoader loader, final UnifiedVirtualFile rootFile) { if (parent != null) { return (ArchiveDeployment) this.deploymentModelFactory.newDeployment(parent, name, loader, rootFile); } else { return (ArchiveDeployment) this.deploymentModelFactory.newDeployment(name, loader, rootFile); } } }
10,902
43.868313
157
java
null
wildfly-main/webservices/server-integration/src/main/java/org/jboss/as/webservices/deployers/deployment/DeploymentModelBuilderJAXWS_POJO.java
/* * JBoss, Home of Professional Open Source. * Copyright 2014, Red Hat Middleware LLC, 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.jboss.as.webservices.deployers.deployment; import static org.jboss.as.webservices.metadata.model.AbstractEndpoint.COMPONENT_VIEW_NAME; import static org.jboss.as.webservices.util.ASHelper.getJaxwsPojos; import static org.jboss.wsf.spi.deployment.EndpointType.JAXWS_JSE; import org.jboss.as.server.deployment.DeploymentUnit; import org.jboss.as.webservices.deployers.WSEndpointConfigMapping; import org.jboss.as.webservices.logging.WSLogger; import org.jboss.as.webservices.metadata.model.POJOEndpoint; import org.jboss.as.webservices.util.WSAttachmentKeys; import org.jboss.msc.service.ServiceName; import org.jboss.wsf.spi.deployment.Deployment; import org.jboss.wsf.spi.deployment.Endpoint; /** * Creates new JAXWS POJO deployment. * * @author <a href="mailto:[email protected]">Richard Opalka</a> */ final class DeploymentModelBuilderJAXWS_POJO extends AbstractDeploymentModelBuilder { DeploymentModelBuilderJAXWS_POJO() { super(JAXWS_JSE); } @Override protected void build(final Deployment dep, final DeploymentUnit unit) { WSLogger.ROOT_LOGGER.trace("Creating JAXWS POJO endpoints meta data model"); WSEndpointConfigMapping ecm = unit.getAttachment(WSAttachmentKeys.WS_ENDPOINT_CONFIG_MAPPING_KEY); for (final POJOEndpoint pojoEndpoint : getJaxwsPojos(unit)) { final String pojoEndpointName = pojoEndpoint.getName(); WSLogger.ROOT_LOGGER.tracef("POJO name: %s", pojoEndpointName); final String pojoEndpointClassName = pojoEndpoint.getClassName(); WSLogger.ROOT_LOGGER.tracef("POJO class: %s", pojoEndpointClassName); final Endpoint ep = newHttpEndpoint(pojoEndpointClassName, pojoEndpointName, dep); final ServiceName componentViewName = pojoEndpoint.getComponentViewName(); if (componentViewName != null) { ep.setProperty(COMPONENT_VIEW_NAME, componentViewName); } if (ecm != null) { ep.setEndpointConfig(ecm.getConfig(pojoEndpointClassName)); markWeldDeployment(unit, ep); } } } }
3,171
44.314286
106
java
null
wildfly-main/webservices/server-integration/src/main/java/org/jboss/as/webservices/deployers/deployment/DeploymentModelBuilderJAXWS_JMS.java
/* * JBoss, Home of Professional Open Source. * Copyright 2014, Red Hat Middleware LLC, 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.jboss.as.webservices.deployers.deployment; import static org.jboss.as.webservices.util.ASHelper.getOptionalAttachment; import static org.jboss.as.webservices.util.WSAttachmentKeys.JMS_ENDPOINT_METADATA_KEY; import static org.jboss.wsf.spi.deployment.EndpointType.JAXWS_JSE; import org.jboss.as.server.deployment.DeploymentUnit; import org.jboss.as.webservices.logging.WSLogger; import org.jboss.wsf.spi.deployment.Deployment; import org.jboss.wsf.spi.deployment.Endpoint; import org.jboss.wsf.spi.metadata.jms.JMSEndpointMetaData; import org.jboss.wsf.spi.metadata.jms.JMSEndpointsMetaData; /** * Creates new JAXWS Jakarta Messaging deployment. * * @author <a href="mailto:[email protected]">Richard Opalka</a> */ final class DeploymentModelBuilderJAXWS_JMS extends AbstractDeploymentModelBuilder { DeploymentModelBuilderJAXWS_JMS() { super(JAXWS_JSE); } @Override protected void build(final Deployment dep, final DeploymentUnit unit) { // propagate final JMSEndpointsMetaData jmsEndpointsMD = getOptionalAttachment(unit, JMS_ENDPOINT_METADATA_KEY); dep.addAttachment(JMSEndpointsMetaData.class, jmsEndpointsMD); WSLogger.ROOT_LOGGER.trace("Creating JAXWS Jakarta Messaging endpoints meta data model"); for (final JMSEndpointMetaData jmsEndpoint : jmsEndpointsMD.getEndpointsMetaData()) { final String jmsEndpointName = jmsEndpoint.getName(); WSLogger.ROOT_LOGGER.tracef("Jakarta Messaging name: %s", jmsEndpointName); final String jmsEndpointClassName = jmsEndpoint.getImplementor(); WSLogger.ROOT_LOGGER.tracef("Jakarta Messaging class: %s", jmsEndpointClassName); final String jmsEndpointAddress = jmsEndpoint.getSoapAddress(); WSLogger.ROOT_LOGGER.tracef("Jakarta Messaging address: %s", jmsEndpointAddress); Endpoint ep =newJMSEndpoint(jmsEndpointClassName, jmsEndpointName, jmsEndpointAddress, dep); markWeldDeployment(unit, ep); } } }
3,070
45.530303
107
java
null
wildfly-main/webservices/server-integration/src/main/java/org/jboss/as/webservices/deployers/deployment/DeploymentAspectsProvider.java
/* * JBoss, Home of Professional Open Source. * Copyright 2010, 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.jboss.as.webservices.deployers.deployment; import java.io.IOException; import java.io.InputStream; import java.net.URL; import java.util.Collections; import java.util.Enumeration; import java.util.LinkedList; import java.util.List; import org.jboss.as.webservices.logging.WSLogger; import org.jboss.as.webservices.parser.WSDeploymentAspectParser; import org.jboss.ws.common.sort.DeploymentAspectSorter; import org.jboss.wsf.spi.classloading.ClassLoaderProvider; import org.jboss.wsf.spi.deployment.DeploymentAspect; /** * Provides the configured WS deployment aspects * * @author [email protected] */ public class DeploymentAspectsProvider { private static List<DeploymentAspect> aspects = null; public static synchronized List<DeploymentAspect> getSortedDeploymentAspects() { if (aspects == null) { final List<DeploymentAspect> deploymentAspects = new LinkedList<DeploymentAspect>(); final ClassLoaderProvider provider = ClassLoaderProvider.getDefaultProvider(); final ClassLoader cl = provider.getServerIntegrationClassLoader(); deploymentAspects.addAll(getDeploymentAspects(cl, "/META-INF/stack-agnostic-deployment-aspects.xml")); deploymentAspects.addAll(getDeploymentAspects(cl, "/META-INF/stack-specific-deployment-aspects.xml")); aspects = DeploymentAspectSorter.getInstance().sort(deploymentAspects); } return aspects; } private static List<DeploymentAspect> getDeploymentAspects(final ClassLoader cl, final String resourcePath) { try { Enumeration<URL> urls = DeploymentAspectsProvider.class.getClassLoader().getResources(resourcePath); if (urls != null && urls.hasMoreElements()) { URL url = urls.nextElement(); InputStream is = null; try { is = url.openStream(); return WSDeploymentAspectParser.parse(is, cl); } finally { if (is != null) { try { is.close(); } catch (Exception e) { // ignore } } } } else { WSLogger.ROOT_LOGGER.cannotLoadDeploymentAspectsDefinitionFile(resourcePath); return Collections.emptyList(); } } catch (IOException e) { throw WSLogger.ROOT_LOGGER.cannotLoadDeploymentAspectsDefinitionFile(e, resourcePath); } } }
3,634
40.781609
114
java
null
wildfly-main/webservices/server-integration/src/main/java/org/jboss/as/webservices/deployers/deployment/WSDeploymentBuilder.java
/* * JBoss, Home of Professional Open Source. * Copyright 2011, Red Hat Middleware LLC, 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.jboss.as.webservices.deployers.deployment; import static org.jboss.as.webservices.util.ASHelper.getJaxwsEjbs; import static org.jboss.as.webservices.util.ASHelper.getJaxwsPojos; import static org.jboss.as.webservices.util.ASHelper.getOptionalAttachment; import static org.jboss.as.webservices.util.WSAttachmentKeys.JMS_ENDPOINT_METADATA_KEY; import org.jboss.as.server.deployment.DeploymentUnit; import org.jboss.as.webservices.logging.WSLogger; import org.jboss.wsf.spi.metadata.jms.JMSEndpointsMetaData; /** * JBossWS deployment model builder. * * @author <a href="mailto:[email protected]">Richard Opalka</a> * @author <a href="mailto:[email protected]">Alessio Soldano</a> */ public final class WSDeploymentBuilder { private static final WSDeploymentBuilder SINGLETON = new WSDeploymentBuilder(); private static final DeploymentModelBuilder JAXWS_JSE = new DeploymentModelBuilderJAXWS_POJO(); private static final DeploymentModelBuilder JAXWS_EJB = new DeploymentModelBuilderJAXWS_EJB(); private static final DeploymentModelBuilder JAXWS_JMS = new DeploymentModelBuilderJAXWS_JMS(); private WSDeploymentBuilder() { super(); } public static WSDeploymentBuilder getInstance() { return WSDeploymentBuilder.SINGLETON; } public void build(final DeploymentUnit unit) { if (isJaxwsPojoDeployment(unit)) { WSLogger.ROOT_LOGGER.trace("Detected JAXWS POJO deployment"); JAXWS_JSE.newDeploymentModel(unit); } if (isJaxwsJmsDeployment(unit)) { WSLogger.ROOT_LOGGER.trace("Detected JAXWS JMS deployment"); JAXWS_JMS.newDeploymentModel(unit); } if (isJaxwsEjbDeployment(unit)) { WSLogger.ROOT_LOGGER.trace("Detected JAXWS EJB deployment"); JAXWS_EJB.newDeploymentModel(unit); } } private static boolean isJaxwsPojoDeployment(final DeploymentUnit unit) { return !getJaxwsPojos(unit).isEmpty(); } private static boolean isJaxwsEjbDeployment(final DeploymentUnit unit) { return !getJaxwsEjbs(unit).isEmpty(); } private static boolean isJaxwsJmsDeployment(final DeploymentUnit unit) { final JMSEndpointsMetaData jmsEndpointsMD = getOptionalAttachment(unit, JMS_ENDPOINT_METADATA_KEY); if (jmsEndpointsMD != null) { return !jmsEndpointsMD.getEndpointsMetaData().isEmpty(); } return false; } }
3,507
39.790698
107
java
null
wildfly-main/webservices/server-integration/src/main/java/org/jboss/as/webservices/deployers/deployment/DeploymentModelBuilder.java
/* * JBoss, Home of Professional Open Source. * Copyright 2011, Red Hat Middleware LLC, 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.jboss.as.webservices.deployers.deployment; import org.jboss.as.server.deployment.DeploymentUnit; /** * Deployment builder interface. * * @author <a href="mailto:[email protected]">Richard Opalka</a> */ interface DeploymentModelBuilder { /** * Creates Web Service deployment model and associates it with deployment. * * @param unit deployment unit */ void newDeploymentModel(DeploymentUnit unit); }
1,477
36.897436
78
java
null
wildfly-main/webservices/server-integration/src/main/java/org/jboss/as/webservices/deployers/deployment/JandexAnnotationsInfo.java
/* * JBoss, Home of Professional Open Source. * Copyright 2014, Red Hat Middleware LLC, 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.jboss.as.webservices.deployers.deployment; import static org.jboss.as.server.deployment.Attachments.ANNOTATION_INDEX; import static org.wildfly.common.Assert.checkNotNullParam; import java.util.List; import org.jboss.as.server.deployment.DeploymentUnit; import org.jboss.as.server.deployment.module.ResourceRoot; import org.jboss.as.webservices.util.ASHelper; import org.jboss.jandex.AnnotationInstance; import org.jboss.jandex.DotName; import org.jboss.jandex.Index; import org.jboss.wsf.spi.deployment.AnnotationsInfo; /** * A Jandex based implementation of org.jboss.wsf.spi.deployment.AnnotationsInfo * * @author <a href="mailto:[email protected]">Alessio Soldano</a> */ public final class JandexAnnotationsInfo implements AnnotationsInfo { private final List<ResourceRoot> resourceRoots; public JandexAnnotationsInfo(DeploymentUnit unit) { resourceRoots = ASHelper.getResourceRoots(unit); } @Override public boolean hasAnnotatedClasses(String... annotation) { checkNotNullParam("annotation", annotation); if (resourceRoots != null) { Index index = null; for (ResourceRoot resourceRoot : resourceRoots) { index = resourceRoot.getAttachment(ANNOTATION_INDEX); if (index != null) { for (String ann : annotation) { List<AnnotationInstance> list = index.getAnnotations(DotName.createSimple(ann)); if (list != null && !list.isEmpty()) { return true; } } } } } return false; } }
2,728
37.985714
104
java
null
wildfly-main/webservices/server-integration/src/main/java/org/jboss/as/webservices/metadata/PublishLocationAdapterImpl.java
/* * JBoss, Home of Professional Open Source. * Copyright 2011, Red Hat Middleware LLC, 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.jboss.as.webservices.metadata; import org.jboss.wsf.spi.metadata.j2ee.PublishLocationAdapter; import org.jboss.wsf.spi.metadata.webservices.JBossWebserviceDescriptionMetaData; /** * Publish location adapter implementation. * * @author <a href="mailto:[email protected]">Richard Opalka</a> * @author <a href="mailto:[email protected]">Thomas Diesler</a> */ final class PublishLocationAdapterImpl implements PublishLocationAdapter { private final JBossWebserviceDescriptionMetaData[] wsDescriptionsMD; PublishLocationAdapterImpl(final JBossWebserviceDescriptionMetaData[] wsDescriptionsMD) { this.wsDescriptionsMD = wsDescriptionsMD; } public String getWsdlPublishLocationByName(final String endpointName) { if (wsDescriptionsMD != null) { for (final JBossWebserviceDescriptionMetaData wsDescriptionMD : wsDescriptionsMD) { if (endpointName.equals(wsDescriptionMD.getWebserviceDescriptionName())) return wsDescriptionMD.getWsdlPublishLocation(); } } return null; } }
2,136
39.320755
95
java
null
wildfly-main/webservices/server-integration/src/main/java/org/jboss/as/webservices/metadata/AbstractMetaDataBuilderPOJO.java
/* * JBoss, Home of Professional Open Source. * Copyright 2014, Red Hat Middleware LLC, 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.jboss.as.webservices.metadata; import static org.jboss.as.webservices.util.ASHelper.getContextRoot; import java.util.HashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; import org.jboss.as.server.deployment.DeploymentUnit; import org.jboss.as.webservices.logging.WSLogger; import org.jboss.as.webservices.metadata.model.POJOEndpoint; import org.jboss.as.webservices.util.WebMetaDataHelper; import org.jboss.metadata.javaee.spec.ParamValueMetaData; import org.jboss.metadata.web.jboss.JBossServletsMetaData; import org.jboss.metadata.web.jboss.JBossWebMetaData; import org.jboss.metadata.web.spec.SecurityConstraintMetaData; import org.jboss.metadata.web.spec.ServletMappingMetaData; import org.jboss.metadata.web.spec.WebResourceCollectionMetaData; import org.jboss.ws.common.integration.WSConstants; import org.jboss.ws.common.integration.WSHelper; import org.jboss.wsf.spi.deployment.Deployment; import org.jboss.wsf.spi.metadata.j2ee.JSEArchiveMetaData; import org.jboss.wsf.spi.metadata.j2ee.JSESecurityMetaData; import org.jboss.wsf.spi.metadata.j2ee.PublishLocationAdapter; import org.jboss.wsf.spi.metadata.webservices.JBossWebservicesMetaData; /** * Builds container independent meta data from WEB container meta data. * * @author <a href="mailto:[email protected]">Richard Opalka</a> * @author <a href="mailto:[email protected]">Thomas Diesler</a> * @author <a href="mailto:[email protected]">Alessio Soldano</a> */ abstract class AbstractMetaDataBuilderPOJO { AbstractMetaDataBuilderPOJO() { super(); } /** * Builds universal JSE meta data model that is AS agnostic. * * @param dep webservice deployment * @return universal JSE meta data model */ JSEArchiveMetaData create(final Deployment dep) { if (WSLogger.ROOT_LOGGER.isTraceEnabled()) { WSLogger.ROOT_LOGGER.tracef("Creating JBoss agnostic meta data for POJO webservice deployment: %s", dep.getSimpleName()); } final JBossWebMetaData jbossWebMD = WSHelper.getRequiredAttachment(dep, JBossWebMetaData.class); final DeploymentUnit unit = WSHelper.getRequiredAttachment(dep, DeploymentUnit.class); final List<POJOEndpoint> pojoEndpoints = getPojoEndpoints(unit); final JSEArchiveMetaData.Builder builder = new JSEArchiveMetaData.Builder(); // set context root final String contextRoot = getContextRoot(dep, jbossWebMD); builder.setContextRoot(contextRoot); WSLogger.ROOT_LOGGER.tracef("Setting context root: %s", contextRoot); // set servlet url patterns mappings final Map<String, String> servletMappings = getServletUrlPatternsMappings(jbossWebMD, pojoEndpoints); builder.setServletMappings(servletMappings); // set servlet class names mappings final Map<String, String> servletClassNamesMappings = getServletClassMappings(jbossWebMD, pojoEndpoints); builder.setServletClassNames(servletClassNamesMappings); // set security domain final String securityDomain = jbossWebMD.getSecurityDomain(); builder.setSecurityDomain(securityDomain); // set wsdl location resolver final JBossWebservicesMetaData jbossWebservicesMD = WSHelper.getOptionalAttachment(dep, JBossWebservicesMetaData.class); if (jbossWebservicesMD != null) { final PublishLocationAdapter resolver = new PublishLocationAdapterImpl(jbossWebservicesMD.getWebserviceDescriptions()); builder.setPublishLocationAdapter(resolver); } // set security meta data final List<JSESecurityMetaData> jseSecurityMDs = getSecurityMetaData(jbossWebMD.getSecurityConstraints()); builder.setSecurityMetaData(jseSecurityMDs); // set config name and file setConfigNameAndFile(builder, jbossWebMD, jbossWebservicesMD); return builder.build(); } protected abstract List<POJOEndpoint> getPojoEndpoints(final DeploymentUnit unit); /** * Sets config name and config file. * * @param builder universal JSE meta data model builder * @param jbossWebMD jboss web meta data */ private void setConfigNameAndFile(final JSEArchiveMetaData.Builder builder, final JBossWebMetaData jbossWebMD, final JBossWebservicesMetaData jbossWebservicesMD) { if (jbossWebservicesMD != null && jbossWebservicesMD.getConfigName() != null) { final String configName = jbossWebservicesMD.getConfigName(); builder.setConfigName(configName); WSLogger.ROOT_LOGGER.tracef("Setting config name: %s", configName); final String configFile = jbossWebservicesMD.getConfigFile(); builder.setConfigFile(configFile); WSLogger.ROOT_LOGGER.tracef("Setting config file: %s", configFile); // ensure higher priority against web.xml context parameters return; } final List<ParamValueMetaData> contextParams = jbossWebMD.getContextParams(); if (contextParams != null) { for (final ParamValueMetaData contextParam : contextParams) { if (WSConstants.JBOSSWS_CONFIG_NAME.equals(contextParam.getParamName())) { final String configName = contextParam.getParamValue(); builder.setConfigName(configName); WSLogger.ROOT_LOGGER.tracef("Setting config name: %s", configName); } if (WSConstants.JBOSSWS_CONFIG_FILE.equals(contextParam.getParamName())) { final String configFile = contextParam.getParamValue(); builder.setConfigFile(configFile); WSLogger.ROOT_LOGGER.tracef("Setting config file: %s", configFile); } } } } /** * Builds security meta data. * * @param securityConstraintsMD security constraints meta data * @return universal JSE security meta data model */ private List<JSESecurityMetaData> getSecurityMetaData(final List<SecurityConstraintMetaData> securityConstraintsMD) { final List<JSESecurityMetaData> jseSecurityMDs = new LinkedList<JSESecurityMetaData>(); if (securityConstraintsMD != null) { for (final SecurityConstraintMetaData securityConstraintMD : securityConstraintsMD) { final JSESecurityMetaData.Builder jseSecurityMDBuilder = new JSESecurityMetaData.Builder(); // transport guarantee jseSecurityMDBuilder.setTransportGuarantee(securityConstraintMD.getTransportGuarantee().name()); // web resources for (final WebResourceCollectionMetaData webResourceMD : securityConstraintMD.getResourceCollections()) { jseSecurityMDBuilder.addWebResource(webResourceMD.getName(), webResourceMD.getUrlPatterns()); } jseSecurityMDs.add(jseSecurityMDBuilder.build()); } } return jseSecurityMDs; } /** * Returns servlet name to url pattern mappings. * * @param jbossWebMD jboss web meta data * @return servlet name to url pattern mappings */ private Map<String, String> getServletUrlPatternsMappings(final JBossWebMetaData jbossWebMD, final List<POJOEndpoint> pojoEndpoints) { final Map<String, String> mappings = new HashMap<String, String>(); final List<ServletMappingMetaData> servletMappings = WebMetaDataHelper.getServletMappings(jbossWebMD); for (final POJOEndpoint pojoEndpoint : pojoEndpoints) { mappings.put(pojoEndpoint.getName(), pojoEndpoint.getUrlPattern()); if (!pojoEndpoint.isDeclared()) { final String endpointName = pojoEndpoint.getName(); final List<String> urlPatterns = WebMetaDataHelper.getUrlPatterns(pojoEndpoint.getUrlPattern()); WebMetaDataHelper.newServletMapping(endpointName, urlPatterns, servletMappings); } } return mappings; } /** * Returns servlet name to servlet class mappings. * * @param jbossWebMD jboss web meta data * @return servlet name to servlet mappings */ private Map<String, String> getServletClassMappings(final JBossWebMetaData jbossWebMD, final List<POJOEndpoint> pojoEndpoints) { final Map<String, String> mappings = new HashMap<String, String>(); final JBossServletsMetaData servlets = WebMetaDataHelper.getServlets(jbossWebMD); for (final POJOEndpoint pojoEndpoint : pojoEndpoints) { final String pojoName = pojoEndpoint.getName(); final String pojoClassName = pojoEndpoint.getClassName(); mappings.put(pojoName, pojoClassName); if (!pojoEndpoint.isDeclared()) { final String endpointName = pojoEndpoint.getName(); final String endpointClassName = pojoEndpoint.getClassName(); WebMetaDataHelper.newServlet(endpointName, endpointClassName, servlets); } } return mappings; } }
10,195
44.315556
167
java
null
wildfly-main/webservices/server-integration/src/main/java/org/jboss/as/webservices/metadata/WebservicesPropertyReplaceFactory.java
/* * JBoss, Home of Professional Open Source. * Copyright 2013, Red Hat Middleware LLC, 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.jboss.as.webservices.metadata; import static org.jboss.wsf.spi.util.StAXUtils.elementAsString; import java.net.URL; import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamReader; import org.jboss.metadata.property.PropertyReplacer; import org.jboss.wsf.spi.metadata.webservices.WebservicesFactory; /** * @author <a href="mailto:[email protected]">Jim Ma</a> */ public class WebservicesPropertyReplaceFactory extends WebservicesFactory { private PropertyReplacer replacer; public WebservicesPropertyReplaceFactory(final URL descriptorURL, final PropertyReplacer propertyReplacer) { super(descriptorURL); replacer = propertyReplacer; } @Override public String getElementText(XMLStreamReader reader) throws XMLStreamException { String res = elementAsString(reader); if (res != null && replacer != null) { res = replacer.replaceProperties(res); } return res; } }
2,018
34.421053
112
java
null
wildfly-main/webservices/server-integration/src/main/java/org/jboss/as/webservices/metadata/MetaDataBuilderJAXWS_POJO.java
/* * JBoss, Home of Professional Open Source. * Copyright 2011, 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.jboss.as.webservices.metadata; import static org.jboss.as.webservices.util.ASHelper.getJaxwsPojos; import java.util.List; import org.jboss.as.server.deployment.DeploymentUnit; import org.jboss.as.webservices.metadata.model.POJOEndpoint; /** * @author <a href="mailto:[email protected]">Richard Opalka</a> */ final class MetaDataBuilderJAXWS_POJO extends AbstractMetaDataBuilderPOJO { @Override protected List<POJOEndpoint> getPojoEndpoints(final DeploymentUnit unit) { return getJaxwsPojos(unit); } }
1,566
35.44186
78
java
null
wildfly-main/webservices/server-integration/src/main/java/org/jboss/as/webservices/metadata/JBossWebservicesPropertyReplaceFactory.java
/* * JBoss, Home of Professional Open Source. * Copyright 2013, Red Hat Middleware LLC, 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.jboss.as.webservices.metadata; import static org.jboss.wsf.spi.util.StAXUtils.elementAsString; import java.net.URL; import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamReader; import org.jboss.metadata.property.PropertyReplacer; import org.jboss.wsf.spi.metadata.webservices.JBossWebservicesFactory; /** * @author <a href="mailto:[email protected]">Jim Ma</a> */ public class JBossWebservicesPropertyReplaceFactory extends JBossWebservicesFactory { private PropertyReplacer replacer; public JBossWebservicesPropertyReplaceFactory(final URL descriptorURL, final PropertyReplacer propertyReplacer) { super(descriptorURL); replacer = propertyReplacer; } @Override public String getElementText(XMLStreamReader reader) throws XMLStreamException { String res = elementAsString(reader); if (res != null && replacer != null) { res = replacer.replaceProperties(res); } return res; } }
2,038
34.77193
117
java
null
wildfly-main/webservices/server-integration/src/main/java/org/jboss/as/webservices/metadata/ContainerMetaDataDeploymentAspect.java
/* * JBoss, Home of Professional Open Source. * Copyright 2011, Red Hat Middleware LLC, 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.jboss.as.webservices.metadata; import org.jboss.as.webservices.logging.WSLogger; import org.jboss.metadata.web.jboss.JBossWebMetaData; import org.jboss.ws.common.integration.AbstractDeploymentAspect; import org.jboss.ws.common.integration.WSHelper; import org.jboss.wsf.spi.deployment.Deployment; import org.jboss.wsf.spi.metadata.j2ee.EJBArchiveMetaData; import org.jboss.wsf.spi.metadata.j2ee.JSEArchiveMetaData; /** * An aspect that builds container independent meta data. * * @author <a href="mailto:[email protected]">Richard Opalka</a> */ public final class ContainerMetaDataDeploymentAspect extends AbstractDeploymentAspect { private final MetaDataBuilderJAXWS_POJO jaxwsPojoMDBuilder = new MetaDataBuilderJAXWS_POJO(); private final MetaDataBuilderJAXWS_EJB jaxwsEjbMDBuilder = new MetaDataBuilderJAXWS_EJB(); @Override public void start(final Deployment dep) { if (WSHelper.isJaxwsJseDeployment(dep) && WSHelper.hasAttachment(dep, JBossWebMetaData.class)) { if (WSLogger.ROOT_LOGGER.isTraceEnabled()) { WSLogger.ROOT_LOGGER.tracef("Creating JBoss agnostic JAXWS POJO meta data for deployment: %s", dep.getSimpleName()); } final JSEArchiveMetaData jseMetaData = jaxwsPojoMDBuilder.create(dep); dep.addAttachment(JSEArchiveMetaData.class, jseMetaData); } if (WSHelper.isJaxwsEjbDeployment(dep)) { if (WSLogger.ROOT_LOGGER.isTraceEnabled()) { WSLogger.ROOT_LOGGER.tracef("Creating JBoss agnostic JAXWS EJB meta data for deployment: %s", dep.getSimpleName()); } final EJBArchiveMetaData ejbMetaData = jaxwsEjbMDBuilder.create(dep); dep.addAttachment(EJBArchiveMetaData.class, ejbMetaData); } } }
2,876
43.953125
131
java
null
wildfly-main/webservices/server-integration/src/main/java/org/jboss/as/webservices/metadata/AbstractMetaDataBuilderEJB.java
/* * JBoss, Home of Professional Open Source. * Copyright 2014, Red Hat Middleware LLC, 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.jboss.as.webservices.metadata; import java.util.List; import org.jboss.as.webservices.logging.WSLogger; import org.jboss.as.webservices.metadata.model.EJBEndpoint; import org.jboss.ws.common.integration.WSHelper; import org.jboss.wsf.spi.deployment.Deployment; import org.jboss.wsf.spi.metadata.j2ee.EJBArchiveMetaData; import org.jboss.wsf.spi.metadata.j2ee.EJBMetaData; import org.jboss.wsf.spi.metadata.j2ee.EJBSecurityMetaData; import org.jboss.wsf.spi.metadata.j2ee.PublishLocationAdapter; import org.jboss.wsf.spi.metadata.j2ee.SLSBMetaData; import org.jboss.wsf.spi.metadata.webservices.JBossPortComponentMetaData; import org.jboss.wsf.spi.metadata.webservices.JBossWebserviceDescriptionMetaData; import org.jboss.wsf.spi.metadata.webservices.JBossWebservicesMetaData; /** * @author <a href="mailto:[email protected]">Richard Opalka</a> */ abstract class AbstractMetaDataBuilderEJB { /** * Builds universal Jakarta Enterprise Beans meta data model that is AS agnostic. * * @param dep * webservice deployment * @return universal Jakarta Enterprise Beans meta data model */ final EJBArchiveMetaData create(final Deployment dep) { if (WSLogger.ROOT_LOGGER.isTraceEnabled()) { WSLogger.ROOT_LOGGER.tracef("Building JBoss agnostic meta data for Jakarta Enterprise Beans webservice deployment: %s", dep.getSimpleName()); } final EJBArchiveMetaData.Builder ejbArchiveMDBuilder = new EJBArchiveMetaData.Builder(); this.buildEnterpriseBeansMetaData(dep, ejbArchiveMDBuilder); this.buildWebservicesMetaData(dep, ejbArchiveMDBuilder); return ejbArchiveMDBuilder.build(); } /** * Template method for build enterprise beans meta data. * * @param dep * webservice deployment * @param ejbMetaData * universal Jakarta Enterprise Beans meta data model */ protected abstract void buildEnterpriseBeansMetaData(Deployment dep, EJBArchiveMetaData.Builder ejbMetaDataBuilder); /** * Builds webservices meta data. This methods sets: * <ul> * <li>context root</li> * <li>wsdl location resolver</li> * <li>config name</li> * <li>config file</li> * </ul> * * @param dep webservice deployment * @param ejbArchiveMD universal Jakarta Enterprise Beans meta data model */ private void buildWebservicesMetaData(final Deployment dep, final EJBArchiveMetaData.Builder ejbArchiveMDBuilder) { final JBossWebservicesMetaData webservicesMD = WSHelper.getOptionalAttachment(dep, JBossWebservicesMetaData.class); if (webservicesMD == null) return; // set context root final String contextRoot = webservicesMD.getContextRoot(); ejbArchiveMDBuilder.setWebServiceContextRoot(contextRoot); WSLogger.ROOT_LOGGER.tracef("Setting context root: %s", contextRoot); // set config name final String configName = webservicesMD.getConfigName(); ejbArchiveMDBuilder.setConfigName(configName); WSLogger.ROOT_LOGGER.tracef("Setting config name: %s", configName); // set config file final String configFile = webservicesMD.getConfigFile(); ejbArchiveMDBuilder.setConfigFile(configFile); WSLogger.ROOT_LOGGER.tracef("Setting config file: %s", configFile); // set wsdl location resolver final JBossWebserviceDescriptionMetaData[] wsDescriptionsMD = webservicesMD.getWebserviceDescriptions(); final PublishLocationAdapter resolver = new PublishLocationAdapterImpl(wsDescriptionsMD); ejbArchiveMDBuilder.setPublishLocationAdapter(resolver); } protected JBossPortComponentMetaData getPortComponent(final String ejbName, final JBossWebservicesMetaData jbossWebservicesMD) { if (jbossWebservicesMD == null) return null; for (final JBossPortComponentMetaData jbossPortComponentMD : jbossWebservicesMD.getPortComponents()) { if (ejbName.equals(jbossPortComponentMD.getEjbName())) return jbossPortComponentMD; } return null; } /** * Builds JBoss agnostic Jakarta Enterprise Beans meta data. * * @param wsEjbsMD * jboss agnostic Jakarta Enterprise Beans meta data */ protected void buildEnterpriseBeanMetaData(final List<EJBMetaData> wsEjbsMD, final EJBEndpoint ejbEndpoint, final JBossWebservicesMetaData jbossWebservicesMD) { final SLSBMetaData.Builder wsEjbMDBuilder = new SLSBMetaData.Builder(); // set Jakarta Enterprise Beans name and class wsEjbMDBuilder.setEjbName(ejbEndpoint.getName()); wsEjbMDBuilder.setEjbClass(ejbEndpoint.getClassName()); final JBossPortComponentMetaData portComponentMD = getPortComponent(ejbEndpoint.getName(), jbossWebservicesMD); if (portComponentMD != null) { // set port component meta data wsEjbMDBuilder.setPortComponentName(portComponentMD.getPortComponentName()); wsEjbMDBuilder.setPortComponentURI(portComponentMD.getPortComponentURI()); } // set security meta data // auth method final String authMethod = getAuthMethod(ejbEndpoint, portComponentMD); // transport guarantee final String transportGuarantee = getTransportGuarantee(ejbEndpoint, portComponentMD); // secure wsdl access final boolean secureWsdlAccess = isSecureWsdlAccess(ejbEndpoint, portComponentMD); final String realmName = getRealmName(ejbEndpoint, portComponentMD); // propagate wsEjbMDBuilder.setSecurityMetaData(new EJBSecurityMetaData(authMethod, realmName, transportGuarantee, secureWsdlAccess)); wsEjbsMD.add(wsEjbMDBuilder.build()); } private static String getAuthMethod(final EJBEndpoint ejbEndpoint, final JBossPortComponentMetaData portComponentMD) { if (ejbEndpoint.getAuthMethod() != null) return ejbEndpoint.getAuthMethod(); return portComponentMD != null ? portComponentMD.getAuthMethod() : null; } private static String getTransportGuarantee(final EJBEndpoint ejbEndpoint, final JBossPortComponentMetaData portComponentMD) { if (portComponentMD != null && portComponentMD.getTransportGuarantee() != null) return portComponentMD.getTransportGuarantee(); return ejbEndpoint != null ? ejbEndpoint.getTransportGuarantee() : null; } private static boolean isSecureWsdlAccess(final EJBEndpoint ejbEndpoint, final JBossPortComponentMetaData portComponentMD) { if (ejbEndpoint.isSecureWsdlAccess()) return true; return (portComponentMD != null && portComponentMD.getSecureWSDLAccess() != null) ? portComponentMD.getSecureWSDLAccess() : false; } private static String getRealmName(final EJBEndpoint ejbEndpoint, final JBossPortComponentMetaData portComponentMD) { if (ejbEndpoint.getRealmName() != null) return ejbEndpoint.getRealmName(); return portComponentMD != null ? portComponentMD.getRealmName() : null; } }
8,101
45.034091
164
java
null
wildfly-main/webservices/server-integration/src/main/java/org/jboss/as/webservices/metadata/MetaDataBuilderJAXWS_EJB.java
/* * JBoss, Home of Professional Open Source. * Copyright 2014, Red Hat Middleware LLC, 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.jboss.as.webservices.metadata; import static org.jboss.as.webservices.util.ASHelper.getContextRoot; import java.util.LinkedList; import java.util.List; import org.jboss.as.webservices.metadata.model.EJBEndpoint; import org.jboss.as.webservices.metadata.model.JAXWSDeployment; import org.jboss.metadata.web.jboss.JBossWebMetaData; import org.jboss.ws.common.integration.WSHelper; import org.jboss.wsf.spi.deployment.Deployment; import org.jboss.wsf.spi.metadata.j2ee.EJBArchiveMetaData; import org.jboss.wsf.spi.metadata.j2ee.EJBMetaData; import org.jboss.wsf.spi.metadata.j2ee.JSEArchiveMetaData; import org.jboss.wsf.spi.metadata.webservices.JBossWebservicesMetaData; /** * @author <a href="mailto:[email protected]">Richard Opalka</a> */ final class MetaDataBuilderJAXWS_EJB extends AbstractMetaDataBuilderEJB { @Override protected void buildEnterpriseBeansMetaData(final Deployment dep, final EJBArchiveMetaData.Builder ejbArchiveMDBuilder) { if (!WSHelper.isJaxwsJseDeployment(dep)) { // [AS7-1605] support final JBossWebMetaData jbossWebMD = WSHelper.getOptionalAttachment(dep, JBossWebMetaData.class); final String contextRoot = getContextRoot(dep, jbossWebMD); if (contextRoot != null) { final JSEArchiveMetaData.Builder jseArchiveMDBuilder = new JSEArchiveMetaData.Builder(); jseArchiveMDBuilder.setContextRoot(contextRoot); dep.addAttachment(JSEArchiveMetaData.class, jseArchiveMDBuilder.build()); } } final JAXWSDeployment jaxwsDeployment = WSHelper.getRequiredAttachment(dep, JAXWSDeployment.class); final List<EJBMetaData> wsEjbsMD = new LinkedList<EJBMetaData>(); final JBossWebservicesMetaData jbossWebservicesMD = WSHelper.getOptionalAttachment(dep, JBossWebservicesMetaData.class); for (final EJBEndpoint jbossEjbMD : jaxwsDeployment.getEjbEndpoints()) { buildEnterpriseBeanMetaData(wsEjbsMD, jbossEjbMD, jbossWebservicesMD); } ejbArchiveMDBuilder.setEnterpriseBeans(wsEjbsMD); } }
3,138
45.161765
128
java
null
wildfly-main/webservices/server-integration/src/main/java/org/jboss/as/webservices/metadata/model/AbstractDeployment.java
/* * JBoss, Home of Professional Open Source. * Copyright 2006, Red Hat Middleware LLC, 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.jboss.as.webservices.metadata.model; import java.util.Collections; import java.util.HashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; import org.jboss.as.webservices.logging.WSLogger; /** * @author <a href="[email protected]">Richard Opalka</a> */ abstract class AbstractDeployment { private final List<EJBEndpoint> ejbEndpoints = new LinkedList<EJBEndpoint>(); private final List<EJBEndpoint> unmodifiableEjbEndpoints = Collections.unmodifiableList(ejbEndpoints); private final List<POJOEndpoint> pojoEndpoints = new LinkedList<POJOEndpoint>(); private final List<POJOEndpoint> unmodifiablePojoEndpoints = Collections.unmodifiableList(pojoEndpoints); private final Map<String, String> urlPatternToClassMapping = new HashMap<String, String>(); public List<EJBEndpoint> getEjbEndpoints() { return unmodifiableEjbEndpoints; } public List<POJOEndpoint> getPojoEndpoints() { return unmodifiablePojoEndpoints; } public void addEndpoint(final EJBEndpoint ep) { ejbEndpoints.add(ep); } public void addEndpoint(final POJOEndpoint ep) { final String urlPattern = ep.getUrlPattern(); final String className = ep.getClassName(); if (urlPatternToClassMapping.keySet().contains((urlPattern))) { final String clazz = urlPatternToClassMapping.get(urlPattern); throw WSLogger.ROOT_LOGGER.sameUrlPatternRequested(clazz, urlPattern, ep.getClassName()); } else { urlPatternToClassMapping.put(urlPattern, className); pojoEndpoints.add(ep); } } public boolean contains(String urlPattern) { return urlPatternToClassMapping.keySet().contains((urlPattern)); } }
2,807
38.549296
109
java
null
wildfly-main/webservices/server-integration/src/main/java/org/jboss/as/webservices/metadata/model/POJOEndpoint.java
/* * JBoss, Home of Professional Open Source. * Copyright 2006, Red Hat Middleware LLC, 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.jboss.as.webservices.metadata.model; import org.jboss.msc.service.ServiceName; /** * @author <a href="mailto:[email protected]">Richard Opalka</a> */ public final class POJOEndpoint extends AbstractEndpoint { private final String urlPattern; private final boolean isDeclared; public POJOEndpoint(final String name, final String className, final ServiceName viewName, final String urlPattern) { this(name, className, viewName, urlPattern, true); } public POJOEndpoint(final String className, final ServiceName viewName, final String urlPattern) { this(className, className, viewName, urlPattern, false); } public POJOEndpoint(final String name, final String className, final ServiceName viewName, final String urlPattern, boolean isDeclared) { super(name, className, viewName); this.urlPattern = urlPattern; this.isDeclared = isDeclared; } public String getUrlPattern() { return urlPattern; } public boolean isDeclared() { return isDeclared; } }
2,105
35.947368
141
java
null
wildfly-main/webservices/server-integration/src/main/java/org/jboss/as/webservices/metadata/model/EJBEndpoint.java
/* * JBoss, Home of Professional Open Source. * Copyright 2006, Red Hat Middleware LLC, 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.jboss.as.webservices.metadata.model; import java.util.Set; import org.jboss.as.ee.component.DeploymentDescriptorEnvironment; import org.jboss.as.ejb3.component.session.SessionBeanComponentDescription; import org.jboss.as.ejb3.security.service.EJBViewMethodSecurityAttributesService; import org.jboss.msc.service.ServiceName; /** * @author <a href="mailto:[email protected]">Richard Opalka</a> */ public final class EJBEndpoint extends AbstractEndpoint { private final SessionBeanComponentDescription ejbMD; private final Set<String> declaredSecurityRoles; private final String authMethod; private final boolean secureWsdlAccess; private final String transportGuarantee; private final String realmName; public EJBEndpoint(final SessionBeanComponentDescription ejbMD, final ServiceName viewName, final Set<String> declaredSecurityRoles, final String authMethod, final String realmName, final boolean secureWsdlAccess, final String transportGuarantee) { super(ejbMD.getComponentName(), ejbMD.getComponentClassName(), viewName); this.ejbMD = ejbMD; this.declaredSecurityRoles = declaredSecurityRoles; this.authMethod = authMethod; this.realmName = realmName; this.secureWsdlAccess = secureWsdlAccess; this.transportGuarantee = transportGuarantee; } public ServiceName getContextServiceName() { return ejbMD.getContextServiceName(); } public DeploymentDescriptorEnvironment getDeploymentDescriptorEnvironment() { return ejbMD.getDeploymentDescriptorEnvironment(); } public String getSecurityDomain() { return ejbMD.getResolvedSecurityDomain(); } public Set<String> getDeclaredSecurityRoles() { return declaredSecurityRoles; } public String getAuthMethod() { return authMethod; } public boolean isSecureWsdlAccess() { return secureWsdlAccess; } public String getTransportGuarantee() { return transportGuarantee; } public String getRealmName() { return realmName; } public ServiceName getEJBViewMethodSecurityAttributesService() { return EJBViewMethodSecurityAttributesService.getServiceName(ejbMD.getApplicationName(), ejbMD.getModuleName(), ejbMD.getEJBName(), getClassName()); } }
3,329
36
251
java
null
wildfly-main/webservices/server-integration/src/main/java/org/jboss/as/webservices/metadata/model/JAXWSDeployment.java
/* * JBoss, Home of Professional Open Source. * Copyright 2006, Red Hat Middleware LLC, 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.jboss.as.webservices.metadata.model; /** * @author <a href="[email protected]">Richard Opalka</a> */ public final class JAXWSDeployment extends AbstractDeployment {}
1,214
42.392857
70
java
null
wildfly-main/webservices/server-integration/src/main/java/org/jboss/as/webservices/metadata/model/AbstractEndpoint.java
/* * JBoss, Home of Professional Open Source. * Copyright 2006, Red Hat Middleware LLC, 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.jboss.as.webservices.metadata.model; import org.jboss.msc.service.ServiceName; /** * @author <a href="[email protected]">Richard Opalka</a> */ public abstract class AbstractEndpoint { public static final String COMPONENT_VIEW_NAME = AbstractEndpoint.class.getPackage().getName() + "ComponentViewName"; public static final String WELD_DEPLOYMENT = AbstractEndpoint.class.getPackage().getName() + ".WeldDeployment"; private final String name; private final String className; private final ServiceName viewName; protected AbstractEndpoint(final String name, final String className, final ServiceName viewName) { this.name = name; this.className = className; this.viewName = viewName; } public final String getName() { return name; } public final String getClassName() { return className; } public ServiceName getComponentViewName() { return viewName; } }
2,007
34.857143
121
java
null
wildfly-main/ee/src/test/java/org/jboss/as/ee/subsystem/EeSubsystemTestCase.java
/* * JBoss, Home of Professional Open Source. * Copyright 2011, Red Hat Middleware LLC, 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.jboss.as.ee.subsystem; import java.io.IOException; import org.jboss.as.subsystem.test.AbstractSubsystemBaseTest; import org.jboss.as.subsystem.test.AdditionalInitialization; /** * @author <a href="[email protected]">Kabir Khan</a> * @author Eduardo Martins */ public class EeSubsystemTestCase extends AbstractSubsystemBaseTest { public EeSubsystemTestCase() { super(EeExtension.SUBSYSTEM_NAME, new EeExtension()); } @Override protected String getSubsystemXml() throws IOException { return readResource("subsystem.xml"); } @Override protected String getSubsystemXsdPath() throws Exception { return "schema/jboss-as-ee_6_0.xsd"; } @Override protected AdditionalInitialization createAdditionalInitialization() { return AdditionalInitialization.withCapabilities(EeCapabilities.PATH_MANAGER_CAPABILITY); } }
1,916
34.5
97
java
null
wildfly-main/ee/src/test/java/org/jboss/as/ee/subsystem/EeLegacySubsystemTestCase.java
/* * * JBoss, Home of Professional Open Source. * Copyright 2015, 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.jboss.as.ee.subsystem; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.EXTENSION; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.SUBSYSTEM; import static org.jboss.as.ee.subsystem.GlobalModulesDefinition.ANNOTATIONS; import static org.jboss.as.ee.subsystem.GlobalModulesDefinition.META_INF; import static org.jboss.as.ee.subsystem.GlobalModulesDefinition.NAME; import static org.jboss.as.ee.subsystem.GlobalModulesDefinition.SERVICES; import static org.jboss.as.ee.subsystem.GlobalModulesDefinition.SLOT; import static org.jboss.as.ee.subsystem.GlobalModulesDefinition.GLOBAL_MODULES; import static org.jboss.as.ee.subsystem.EESubsystemModel.ANNOTATION_PROPERTY_REPLACEMENT; import static org.jboss.as.ee.subsystem.EESubsystemModel.EAR_SUBDEPLOYMENTS_ISOLATED; import static org.jboss.as.ee.subsystem.EESubsystemModel.JBOSS_DESCRIPTOR_PROPERTY_REPLACEMENT; import static org.jboss.as.ee.subsystem.EESubsystemModel.SPEC_DESCRIPTOR_PROPERTY_REPLACEMENT; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import java.io.File; import java.io.IOException; import java.nio.file.FileVisitResult; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.nio.file.SimpleFileVisitor; import java.nio.file.attribute.BasicFileAttributes; import java.util.ArrayList; import java.util.List; import java.util.regex.Pattern; import org.jboss.as.controller.OperationDefinition; import org.jboss.as.controller.PathElement; import org.jboss.as.controller.ReloadRequiredAddStepHandler; import org.jboss.as.controller.ReloadRequiredRemoveStepHandler; import org.jboss.as.controller.RunningMode; import org.jboss.as.controller.SimpleAttributeDefinitionBuilder; import org.jboss.as.controller.SimpleOperationDefinitionBuilder; import org.jboss.as.controller.SimpleResourceDefinition; import org.jboss.as.controller.capability.registry.RuntimeCapabilityRegistry; import org.jboss.as.controller.descriptions.NonResolvingResourceDescriptionResolver; import org.jboss.as.controller.extension.ExtensionRegistry; import org.jboss.as.controller.registry.ManagementResourceRegistration; import org.jboss.as.controller.registry.Resource; import org.jboss.as.subsystem.test.AbstractSubsystemBaseTest; import org.jboss.as.subsystem.test.AdditionalInitialization; import org.jboss.as.subsystem.test.KernelServices; import org.jboss.dmr.ModelNode; import org.jboss.dmr.ModelType; import org.junit.Assert; import org.junit.Test; import org.wildfly.security.manager.WildFlySecurityManager; /** * @author <a href="[email protected]">Richard Opalka</a> */ public class EeLegacySubsystemTestCase extends AbstractSubsystemBaseTest { public EeLegacySubsystemTestCase() { super(EeExtension.SUBSYSTEM_NAME, new EeExtension()); } @Test public void testLegacyConfigurations() throws Exception { // Get a list of all the logging_x_x.xml files final Pattern pattern = Pattern.compile("(subsystem)_\\d+_\\d+\\.xml"); // Using the CP as that's the standardSubsystemTest will use to find the config file final String cp = WildFlySecurityManager.getPropertyPrivileged("java.class.path", "."); final String[] entries = cp.split(Pattern.quote(File.pathSeparator)); final List<String> configs = new ArrayList<>(); for (String entry : entries) { final Path path = Paths.get(entry); if (Files.isDirectory(path)) { Files.walkFileTree(path, new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(final Path file, final BasicFileAttributes attrs) throws IOException { final String name = file.getFileName().toString(); if (pattern.matcher(name).matches()) { configs.add(name); } return FileVisitResult.CONTINUE; } }); } } // The paths shouldn't be empty Assert.assertFalse("No configs were found", configs.isEmpty()); for (String configId : configs) { // Run the standard subsystem test, but don't compare the XML as it should never match standardSubsystemTest(configId, false); } } @Test public void testSubsystem() throws Exception { KernelServices services = standardSubsystemTest("subsystem_1_2.xml", false); ModelNode model = services.readWholeModel(); ModelNode subsystem = model.require(SUBSYSTEM).require(EeExtension.SUBSYSTEM_NAME); ModelNode globalModules = subsystem.require(GLOBAL_MODULES); assertEquals("org.jboss.logging", globalModules.require(0).require(NAME).asString()); assertEquals("main", globalModules.require(0).require(SLOT).asString()); assertEquals("org.apache.logging.log4j.api", globalModules.require(1).require(NAME).asString()); assertTrue(globalModules.require(1).require(ANNOTATIONS).asBoolean()); assertTrue(globalModules.require(1).require(META_INF).asBoolean()); assertFalse(globalModules.require(1).require(SERVICES).asBoolean()); assertFalse(subsystem.require(ANNOTATION_PROPERTY_REPLACEMENT).asBoolean()); assertTrue(subsystem.require(EAR_SUBDEPLOYMENTS_ISOLATED).asBoolean()); assertTrue(subsystem.require(JBOSS_DESCRIPTOR_PROPERTY_REPLACEMENT).asBoolean()); assertFalse(subsystem.require(SPEC_DESCRIPTOR_PROPERTY_REPLACEMENT).asBoolean()); } @Override protected String getSubsystemXml() throws IOException { return readResource("subsystem_1_2.xml"); } @Override protected String getSubsystemXml(String resource) throws IOException { return readResource(resource); } @Override protected void compare(ModelNode node1, ModelNode node2) { node1.remove(EXTENSION); node2.remove(EXTENSION); node1.get(SUBSYSTEM).remove("bean-validation"); node2.get(SUBSYSTEM).remove("bean-validation"); super.compare(node1, node2); } boolean extensionAdded = false; @Override protected AdditionalInitialization createAdditionalInitialization() { return new AdditionalInitialization() { @Override protected RunningMode getRunningMode() { return RunningMode.ADMIN_ONLY; } @Override protected void initializeExtraSubystemsAndModel(ExtensionRegistry extensionRegistry, Resource rootResource, ManagementResourceRegistration rootRegistration, RuntimeCapabilityRegistry capabilityRegistry) { if (!extensionAdded) { //extensionAdded = true; //bean validation depends on EE, so we can't use the real subsystem here final OperationDefinition removeExtension = new SimpleOperationDefinitionBuilder("remove", NonResolvingResourceDescriptionResolver.INSTANCE) .build(); final OperationDefinition addExtension = new SimpleOperationDefinitionBuilder("add", NonResolvingResourceDescriptionResolver.INSTANCE) .addParameter(new SimpleAttributeDefinitionBuilder("module", ModelType.STRING).setRequired(true).build()) .build(); PathElement bvExtension = PathElement.pathElement(EXTENSION, "org.wildfly.extension.bean-validation"); ManagementResourceRegistration extensionRegistration = rootRegistration.registerSubModel(new SimpleResourceDefinition(bvExtension, NonResolvingResourceDescriptionResolver.INSTANCE)); extensionRegistration.registerReadOnlyAttribute(new SimpleAttributeDefinitionBuilder("module", ModelType.STRING).setRequired(true).build(), null); extensionRegistration.registerOperationHandler(removeExtension, ReloadRequiredRemoveStepHandler.INSTANCE); extensionRegistration.registerOperationHandler(addExtension, new ReloadRequiredAddStepHandler( new SimpleAttributeDefinitionBuilder("module", ModelType.STRING).setRequired(true).build())); final OperationDefinition removeSubsystem = new SimpleOperationDefinitionBuilder("remove", NonResolvingResourceDescriptionResolver.INSTANCE) .build(); final OperationDefinition addSubsystem = new SimpleOperationDefinitionBuilder("add", NonResolvingResourceDescriptionResolver.INSTANCE) .build(); PathElement bvSubsystem = PathElement.pathElement(SUBSYSTEM, "bean-validation"); ManagementResourceRegistration subsystemRegistration = rootRegistration.registerSubModel(new SimpleResourceDefinition(bvSubsystem, NonResolvingResourceDescriptionResolver.INSTANCE)); subsystemRegistration.registerOperationHandler(removeSubsystem, ReloadRequiredRemoveStepHandler.INSTANCE); subsystemRegistration.registerOperationHandler(addSubsystem, new ReloadRequiredAddStepHandler()); } } }; } }
10,436
49.42029
216
java
null
wildfly-main/ee/src/test/java/org/jboss/as/ee/subsystem/EeOperationsTestCase.java
/* * Copyright 2015 Red Hat, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.jboss.as.ee.subsystem; import java.io.IOException; import org.jboss.as.controller.RunningMode; import org.jboss.as.controller.client.helpers.ClientConstants; import org.jboss.as.controller.client.helpers.Operations; import org.jboss.as.controller.client.helpers.Operations.CompositeOperationBuilder; import org.jboss.as.subsystem.test.AbstractSubsystemBaseTest; import org.jboss.as.subsystem.test.AdditionalInitialization; import org.jboss.as.subsystem.test.ControllerInitializer; import org.jboss.as.subsystem.test.KernelServices; import org.jboss.dmr.ModelNode; import org.junit.Assert; import org.junit.Test; import org.wildfly.common.cpu.ProcessorInfo; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; /** * @author <a href="mailto:[email protected]">James R. Perkins</a> */ public class EeOperationsTestCase extends AbstractSubsystemBaseTest { public EeOperationsTestCase() { super(EeExtension.SUBSYSTEM_NAME, new EeExtension()); } @Override protected void standardSubsystemTest(final String configId) throws Exception { // do nothing as this is not a subsystem parsing test } @Override protected String getSubsystemXml() throws IOException { return readResource("simple-subsystem.xml"); } @Test public void testManagedExecutorFailureOperations() throws Exception { // Boot the container final KernelServices kernelServices = createKernelServicesBuilder(createAdditionalInitialization()).setSubsystemXml(getSubsystemXml()).build(); // Default address final ModelNode address = Operations.createAddress(ClientConstants.SUBSYSTEM, EeExtension.SUBSYSTEM_NAME, "managed-executor-service", "default"); // Create a composite operation that should fail; note that if the queue-length is undefined, 0 or Integer.MAX_VALUE the // core-threads must be greater than 0 ModelNode op = Operations.createWriteAttributeOperation(address, "core-threads", 0); ModelNode result = kernelServices.executeOperation(op); Assert.assertFalse(Operations.isSuccessfulOutcome(result)); op = CompositeOperationBuilder.create() .addStep(Operations.createWriteAttributeOperation(address, "queue-length", Integer.MAX_VALUE)) .addStep(Operations.createWriteAttributeOperation(address, "core-threads", 0)) .build().getOperation(); result = kernelServices.executeOperation(op); Assert.assertFalse(Operations.isSuccessfulOutcome(result)); op = CompositeOperationBuilder.create() .addStep(Operations.createWriteAttributeOperation(address, "queue-length", 0)) .addStep(Operations.createWriteAttributeOperation(address, "core-threads", 0)) .build().getOperation(); result = kernelServices.executeOperation(op); Assert.assertFalse(Operations.isSuccessfulOutcome(result)); // The max-threads must be greater than or equal to the core-threads op = CompositeOperationBuilder.create() .addStep(Operations.createWriteAttributeOperation(address, "core-threads", 4)) .addStep(Operations.createWriteAttributeOperation(address, "max-threads", 1)) .build().getOperation(); result = kernelServices.executeOperation(op); Assert.assertFalse(Operations.isSuccessfulOutcome(result)); // Test a failure at the runtime-stage op = CompositeOperationBuilder.create() .addStep(Operations.createWriteAttributeOperation(address, "queue-length", "${test.queue-length:10}")) .addStep(Operations.createWriteAttributeOperation(address, "core-threads", "${test.core-threads:500}")) .build().getOperation(); result = kernelServices.executeOperation(op); Assert.assertFalse(Operations.isSuccessfulOutcome(result)); // The max-threads must be greater than or equal to the core-threads final int calculatedMaxThreads = (ProcessorInfo.availableProcessors() * 2); op = CompositeOperationBuilder.create() .addStep(Operations.createWriteAttributeOperation(address, "core-threads", calculatedMaxThreads)) .addStep(Operations.createWriteAttributeOperation(address, "max-threads", calculatedMaxThreads - 1)) .build().getOperation(); result = kernelServices.executeOperation(op); Assert.assertFalse(Operations.isSuccessfulOutcome(result)); } @Test public void testManagedExecutorOperations() throws Exception { // Boot the container final KernelServices kernelServices = createKernelServicesBuilder(createAdditionalInitialization()).setSubsystemXml(getSubsystemXml()).build(); // Default address final ModelNode address = Operations.createAddress(ClientConstants.SUBSYSTEM, EeExtension.SUBSYSTEM_NAME, "managed-executor-service", "default"); ModelNode op = CompositeOperationBuilder.create() .addStep(Operations.createWriteAttributeOperation(address, "queue-length", Integer.MAX_VALUE)) .addStep(Operations.createWriteAttributeOperation(address, "core-threads", 5)) .build().getOperation(); executeForSuccess(kernelServices, op); op = CompositeOperationBuilder.create() .addStep(Operations.createWriteAttributeOperation(address, "max-threads", 5)) .addStep(Operations.createWriteAttributeOperation(address, "queue-length", 10)) .addStep(Operations.createWriteAttributeOperation(address, "core-threads", 0)) .build().getOperation(); executeForSuccess(kernelServices, op); // The max-threads must be greater than or equal to the core-threads op = CompositeOperationBuilder.create() .addStep(Operations.createWriteAttributeOperation(address, "core-threads", 4)) .addStep(Operations.createWriteAttributeOperation(address, "max-threads", 4)) .build().getOperation(); executeForSuccess(kernelServices, op); } @Test public void testAddExistingGlobalModule() throws Exception { // Boot the container final KernelServices kernelServices = createKernelServicesBuilder(createAdditionalInitialization()).setSubsystemXml(getSubsystemXml()).build(); final ModelNode address = Operations.createAddress(ClientConstants.SUBSYSTEM, EeExtension.SUBSYSTEM_NAME); addModule(kernelServices, address, moduleNode("test.module.one", null)); addModule(kernelServices, address, moduleNode("test.module.one", null)); ModelNode res = executeForSuccess(kernelServices, Operations.createReadAttributeOperation(address, GlobalModulesDefinition.GLOBAL_MODULES)); assertEquals(1, res.get(ClientConstants.RESULT).asList().size()); } @Test public void testAddUniqueGlobalModule() throws Exception { // Boot the container final KernelServices kernelServices = createKernelServicesBuilder(createAdditionalInitialization()).setSubsystemXml(getSubsystemXml()).build(); final ModelNode address = Operations.createAddress(ClientConstants.SUBSYSTEM, EeExtension.SUBSYSTEM_NAME); addModule(kernelServices, address, moduleNode("test.module.one", null)); addModule(kernelServices, address, moduleNode("test.module.two", null)); ModelNode res = executeForSuccess(kernelServices, Operations.createReadAttributeOperation(address, GlobalModulesDefinition.GLOBAL_MODULES)); assertEquals(2, res.get(ClientConstants.RESULT).asList().size()); } @Test public void testAddExistingGlobalModuleWithDifferentSlot() throws Exception { // Boot the container final KernelServices kernelServices = createKernelServicesBuilder(createAdditionalInitialization()).setSubsystemXml(getSubsystemXml()).build(); final ModelNode address = Operations.createAddress(ClientConstants.SUBSYSTEM, EeExtension.SUBSYSTEM_NAME); addModule(kernelServices, address, moduleNode("test.module.one", "main")); addModule(kernelServices, address, moduleNode("test.module.one", "foo")); ModelNode res = executeForSuccess(kernelServices, Operations.createReadAttributeOperation(address, GlobalModulesDefinition.GLOBAL_MODULES)); assertEquals(2, res.get(ClientConstants.RESULT).asList().size()); } @Test public void testAddExistingGlobalModuleWithMetaInf() throws Exception { // Boot the container final KernelServices kernelServices = createKernelServicesBuilder(createAdditionalInitialization()).setSubsystemXml(getSubsystemXml()).build(); final ModelNode address = Operations.createAddress(ClientConstants.SUBSYSTEM, EeExtension.SUBSYSTEM_NAME); ModelNode module = moduleNode("test.module.one", "main"); addModule(kernelServices, address, module); module.get(GlobalModulesDefinition.META_INF).set(true); addModule(kernelServices, address, module); ModelNode res = executeForSuccess(kernelServices, Operations.createReadAttributeOperation(address, GlobalModulesDefinition.GLOBAL_MODULES)); assertEquals(1, res.get(ClientConstants.RESULT).asList().size()); ModelNode actualModule = res.get(ClientConstants.RESULT).asList().get(0); assertTrue(actualModule.get(GlobalModulesDefinition.META_INF).asBoolean()); } private void addModule(KernelServices kernelServices, ModelNode address, ModelNode module) { executeForSuccess(kernelServices, listAddOp(address, module)); } private ModelNode moduleNode(String moduleName, String slotName) { ModelNode module = new ModelNode(); module.get(ClientConstants.NAME).set(moduleName); if (slotName != null) { module.get(GlobalModulesDefinition.SLOT).set(slotName); } return module; } private ModelNode listAddOp(ModelNode address, ModelNode list) { ModelNode op = Operations.createOperation("list-add", address); op.get(ClientConstants.NAME).set(GlobalModulesDefinition.GLOBAL_MODULES); op.get(ClientConstants.VALUE).set(list); return op; } private ModelNode executeForSuccess(final KernelServices kernelServices, final ModelNode op) { final ModelNode result = kernelServices.executeOperation(op); if (!Operations.isSuccessfulOutcome(result)) { Assert.fail(Operations.getFailureDescription(result).asString()); } return result; } @Override protected AdditionalInitialization createAdditionalInitialization() { return new AdditionalInitialization() { @Override protected RunningMode getRunningMode() { return RunningMode.NORMAL; } @Override protected ControllerInitializer createControllerInitializer() { return new EeInitializer(); } }; } class EeInitializer extends ControllerInitializer { public EeInitializer() { addSystemProperty("test.queue-length", "0"); addSystemProperty("test.core-threads", "0"); } } }
11,931
44.892308
153
java
null
wildfly-main/ee/src/test/java/org/jboss/as/ee/component/EEModuleDescriptionUnitTestCase.java
package org.jboss.as.ee.component; import org.jboss.msc.service.ServiceName; import org.junit.Test; import static org.junit.Assert.assertThrows; import static org.junit.Assert.assertTrue; public class EEModuleDescriptionUnitTestCase { @Test public void testAddExistingComponent() { EEModuleDescription eeModuleDescription = new EEModuleDescription("appName", "module1", "ear1", false); ComponentDescription description1 = new ComponentDescription("comp1", "org.test.comp1", eeModuleDescription, ServiceName.of("name")); ComponentDescription description2 = new ComponentDescription("comp1", "org.test.comp2", eeModuleDescription, ServiceName.of("name")); eeModuleDescription.addComponent(description1); Exception exception = assertThrows(RuntimeException.class, () -> { eeModuleDescription.addComponent(description2); }); String actualMessage = exception.getMessage(); assertTrue(actualMessage.contains("WFLYEE0040")); assertTrue(actualMessage.contains("comp1")); assertTrue(actualMessage.contains("org.test.comp2")); assertTrue(actualMessage.contains("org.test.comp1")); assertTrue(exception instanceof IllegalArgumentException); } }
1,375
33.4
95
java
null
wildfly-main/ee/src/main/java/org/jboss/as/ee/security/SecurityActions.java
/* * JBoss, Home of Professional Open Source. * Copyright 2010, 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.jboss.as.ee.security; import static java.security.AccessController.doPrivileged; import java.security.PrivilegedAction; import org.jboss.modules.Module; import org.jboss.modules.ModuleClassLoader; import org.jboss.modules.ModuleIdentifier; import org.jboss.modules.ModuleLoadException; import org.jboss.modules.ModuleLoader; import org.wildfly.security.manager.WildFlySecurityManager; import org.wildfly.security.manager.action.GetModuleClassLoaderAction; /** * Privileged blocks for this package * * @author <a href="mailto:[email protected]">Marcus Moyses</a> * @author Anil Saldhana * @author <a href="mailto:[email protected]">Darran Lofthouse</a> */ class SecurityActions { static ModuleClassLoader getModuleClassLoader(final String moduleSpec) throws ModuleLoadException { ModuleLoader loader = Module.getCallerModuleLoader(); final Module module = loader.loadModule(ModuleIdentifier.fromString(moduleSpec)); GetModuleClassLoaderAction action = new GetModuleClassLoaderAction(module); return WildFlySecurityManager.isChecking() ? doPrivileged(action) : action.run(); } static ClassLoader setThreadContextClassLoader(ClassLoader toSet) { return classLoaderActions().setThreadContextClassLoader(toSet); } private static ClassLoaderActions classLoaderActions() { return WildFlySecurityManager.isChecking() ? ClassLoaderActions.PRIVILEGED : ClassLoaderActions.NON_PRIVILEGED; } private interface ClassLoaderActions { ClassLoader setThreadContextClassLoader(ClassLoader toSet); ClassLoaderActions NON_PRIVILEGED = new ClassLoaderActions() { @Override public ClassLoader setThreadContextClassLoader(ClassLoader toSet) { Thread currentThread = Thread.currentThread(); ClassLoader previous = currentThread.getContextClassLoader(); currentThread.setContextClassLoader(toSet); return previous; } }; ClassLoaderActions PRIVILEGED = new ClassLoaderActions() { @Override public ClassLoader setThreadContextClassLoader(final ClassLoader toSet) { return doPrivileged(new PrivilegedAction<ClassLoader>() { @Override public ClassLoader run() { return NON_PRIVILEGED.setThreadContextClassLoader(toSet); } }); } }; } }
3,545
37.543478
119
java
null
wildfly-main/ee/src/main/java/org/jboss/as/ee/security/EarJaccService.java
/* * JBoss, Home of Professional Open Source. * Copyright 2011, 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.jboss.as.ee.security; import jakarta.security.jacc.PolicyConfiguration; import jakarta.security.jacc.PolicyContextException; import org.jboss.metadata.ear.spec.EarMetaData; /** * A service that creates JACC permissions for an ear deployment * * @author <a href="mailto:[email protected]">Marcus Moyses</a> * @author [email protected] * @author [email protected] */ public class EarJaccService extends JaccService<EarMetaData> { public EarJaccService(String contextId, EarMetaData metaData, Boolean standalone) { super(contextId, metaData, standalone); } /** {@inheritDoc} */ @Override public void createPermissions(EarMetaData metaData, PolicyConfiguration policyConfiguration) throws PolicyContextException { // nothing to do } }
1,830
35.62
128
java
null
wildfly-main/ee/src/main/java/org/jboss/as/ee/security/AbstractSecurityDeployer.java
/* * JBoss, Home of Professional Open Source. * Copyright 2011, 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.jboss.as.ee.security; import org.jboss.as.server.deployment.AttachmentKey; import org.jboss.as.server.deployment.DeploymentUnit; /** * A helper class for security deployment processors * * @author Marcus Moyses * @author Anil Saldhana */ public abstract class AbstractSecurityDeployer<T> { public JaccService<T> deploy(DeploymentUnit deploymentUnit) { // build the Jakarta Authorization context id. String contextId = deploymentUnit.getName(); if (deploymentUnit.getParent() != null) { contextId = deploymentUnit.getParent().getName() + "!" + contextId; } return deploy(deploymentUnit, contextId); } public JaccService<T> deploy(DeploymentUnit deploymentUnit, String jaccContextId) { T metaData = deploymentUnit.getAttachment(getMetaDataType()); Boolean standalone = Boolean.FALSE; // check if it is top level if (deploymentUnit.getParent() == null) { standalone = Boolean.TRUE; } return createService(jaccContextId, metaData, standalone); } public void undeploy(DeploymentUnit deploymentUnit) { } /** * Creates the appropriate service for metaData T * @param contextId * @param metaData * @param standalone * @return */ protected abstract JaccService<T> createService(String contextId, T metaData, Boolean standalone); /** * Return the type of metadata * * @return */ protected abstract AttachmentKey<T> getMetaDataType(); }
2,578
32.934211
102
java
null
wildfly-main/ee/src/main/java/org/jboss/as/ee/security/JaccEarDeploymentProcessor.java
/* * JBoss, Home of Professional Open Source. * Copyright 2011, 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.jboss.as.ee.security; import jakarta.security.jacc.PolicyConfiguration; import org.jboss.as.controller.capability.CapabilityServiceSupport; import org.jboss.as.ee.structure.DeploymentType; import org.jboss.as.ee.structure.DeploymentTypeMarker; import org.jboss.as.server.deployment.Attachments; import org.jboss.as.server.deployment.DeploymentPhaseContext; import org.jboss.as.server.deployment.DeploymentUnit; import org.jboss.as.server.deployment.DeploymentUnitProcessingException; import org.jboss.as.server.deployment.DeploymentUnitProcessor; import org.jboss.msc.service.ServiceBuilder; import org.jboss.msc.service.ServiceController.Mode; import org.jboss.msc.service.ServiceName; import org.jboss.msc.service.ServiceTarget; /** * A {@code DeploymentUnitProcessor} for Jakarta Authorization policies. * * @author <a href="mailto:[email protected]">Marcus Moyses</a> */ public class JaccEarDeploymentProcessor implements DeploymentUnitProcessor { private final String jaccCapabilityName; public JaccEarDeploymentProcessor(final String jaccCapabilityName) { this.jaccCapabilityName = jaccCapabilityName; } /** * {@inheritDoc} */ @Override public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException { final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit(); AbstractSecurityDeployer<?> deployer = null; if (DeploymentTypeMarker.isType(DeploymentType.EAR, deploymentUnit)) { deployer = new EarSecurityDeployer(); JaccService<?> service = deployer.deploy(deploymentUnit); if (service != null) { final ServiceName jaccServiceName = deploymentUnit.getServiceName().append(JaccService.SERVICE_NAME); final ServiceTarget serviceTarget = phaseContext.getServiceTarget(); ServiceBuilder<?> builder = serviceTarget.addService(jaccServiceName, service); if (deploymentUnit.getParent() != null) { // add dependency to parent policy final DeploymentUnit parentDU = deploymentUnit.getParent(); builder.addDependency(parentDU.getServiceName().append(JaccService.SERVICE_NAME), PolicyConfiguration.class, service.getParentPolicyInjector()); } CapabilityServiceSupport capabilitySupport = deploymentUnit.getAttachment(Attachments.CAPABILITY_SERVICE_SUPPORT); builder.requires(capabilitySupport.getCapabilityServiceName(jaccCapabilityName)); builder.setInitialMode(Mode.ACTIVE).install(); } } } /** * {@inheritDoc} */ @Override public void undeploy(DeploymentUnit context) { AbstractSecurityDeployer<?> deployer = null; if (DeploymentTypeMarker.isType(DeploymentType.EAR, context)) { deployer = new EarSecurityDeployer(); deployer.undeploy(context); } } }
4,060
42.666667
130
java
null
wildfly-main/ee/src/main/java/org/jboss/as/ee/security/EarSecurityDeployer.java
/* * JBoss, Home of Professional Open Source. * Copyright 2011, 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.jboss.as.ee.security; import org.jboss.as.ee.structure.Attachments; import org.jboss.as.server.deployment.AttachmentKey; import org.jboss.metadata.ear.spec.EarMetaData; /** * Handles ear deployments * * @author <a href="mailto:[email protected]">Marcus Moyses</a> */ public class EarSecurityDeployer extends AbstractSecurityDeployer<EarMetaData> { /** * {@inheritDoc} */ @Override protected JaccService<EarMetaData> createService(String contextId, EarMetaData metaData, Boolean standalone) { return new EarJaccService(contextId, metaData, standalone); } /** * {@inheritDoc} */ @Override protected AttachmentKey<EarMetaData> getMetaDataType() { return Attachments.EAR_METADATA; } }
1,795
32.886792
114
java
null
wildfly-main/ee/src/main/java/org/jboss/as/ee/security/JaccService.java
/* * JBoss, Home of Professional Open Source. * Copyright 2011, 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.jboss.as.ee.security; import static org.jboss.as.ee.logging.EeLogger.ROOT_LOGGER; import static org.wildfly.common.Assert.checkNotNullParam; import java.security.Policy; import jakarta.security.jacc.PolicyConfiguration; import jakarta.security.jacc.PolicyConfigurationFactory; import jakarta.security.jacc.PolicyContextException; import org.jboss.modules.ModuleLoadException; import org.jboss.msc.inject.Injector; import org.jboss.msc.service.Service; import org.jboss.msc.service.ServiceName; import org.jboss.msc.service.StartContext; import org.jboss.msc.service.StartException; import org.jboss.msc.service.StopContext; import org.jboss.msc.value.InjectedValue; import org.wildfly.security.manager.WildFlySecurityManager; /** * A service for Jakarta Authorization policies * * @author <a href="mailto:[email protected]">Marcus Moyses</a> */ public abstract class JaccService<T> implements Service<PolicyConfiguration> { private static final String JACC_MODULE = "org.jboss.as.security.jacc-module"; public static final ServiceName SERVICE_NAME = ServiceName.of("jacc"); private final String contextId; private final T metaData; private final Boolean standalone; private volatile PolicyConfiguration policyConfiguration; private final InjectedValue<PolicyConfiguration> parentPolicy = new InjectedValue<PolicyConfiguration>(); public JaccService(final String contextId, T metaData, Boolean standalone) { checkNotNullParam(contextId, contextId); this.contextId = contextId; this.metaData = metaData; this.standalone = standalone; } /** {@inheritDoc} */ @Override public PolicyConfiguration getValue() throws IllegalStateException, IllegalArgumentException { return policyConfiguration; } /** {@inheritDoc} */ @Override public void start(StartContext context) throws StartException { try { PolicyConfigurationFactory pcf = getPolicyConfigurationFactory(); synchronized (pcf) { // synchronize on the factory policyConfiguration = pcf.getPolicyConfiguration(contextId, false); if (metaData != null) { createPermissions(metaData, policyConfiguration); } else { ROOT_LOGGER.debugf("Cannot create permissions with 'null' metaData for id=%s", contextId); } if (!standalone) { PolicyConfiguration parent = parentPolicy.getValue(); if (parent != null) { parent = pcf.getPolicyConfiguration(parent.getContextID(), false); parent.linkConfiguration(policyConfiguration); policyConfiguration.commit(); parent.commit(); } else { ROOT_LOGGER.debugf("Could not retrieve parent policy for policy %s", contextId); } } else { policyConfiguration.commit(); } // Allow the policy to incorporate the policy configs Policy.getPolicy().refresh(); } } catch (Exception e) { throw ROOT_LOGGER.unableToStartException("JaccService", e); } } private PolicyConfigurationFactory getPolicyConfigurationFactory() throws ModuleLoadException, ClassNotFoundException, PolicyContextException { String module = WildFlySecurityManager.getPropertyPrivileged(JACC_MODULE, null); final ClassLoader originalClassLoader; final ClassLoader jaccClassLoader; if (module != null) { jaccClassLoader = SecurityActions.getModuleClassLoader(module); originalClassLoader = SecurityActions.setThreadContextClassLoader(jaccClassLoader); } else { jaccClassLoader = null; originalClassLoader = null; } try { return PolicyConfigurationFactory.getPolicyConfigurationFactory(); } finally { if (originalClassLoader != null) { SecurityActions.setThreadContextClassLoader(originalClassLoader); } } } /** {@inheritDoc} */ @Override public void stop(StopContext context) { try { PolicyConfigurationFactory pcf = PolicyConfigurationFactory.getPolicyConfigurationFactory(); synchronized (pcf) { // synchronize on the factory policyConfiguration = pcf.getPolicyConfiguration(contextId, false); policyConfiguration.delete(); } } catch (Exception e) { ROOT_LOGGER.errorDeletingJACCPolicy(e); } policyConfiguration = null; } /** * Target {@code Injector} * * @return target */ public Injector<PolicyConfiguration> getParentPolicyInjector() { return parentPolicy; } /** * Create JACC permissions for the deployment * * @param metaData * @param policyConfiguration * @throws PolicyContextException */ public abstract void createPermissions(T metaData, PolicyConfiguration policyConfiguration) throws PolicyContextException; }
6,287
36.879518
147
java
null
wildfly-main/ee/src/main/java/org/jboss/as/ee/concurrent/ConcurrentContextInterceptor.java
/* * 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.jboss.as.ee.concurrent; import org.jboss.invocation.Interceptor; import org.jboss.invocation.InterceptorContext; /** * The interceptor responsible for managing the current {@link org.jboss.as.ee.concurrent.ConcurrentContext}. * * @author Eduardo Martins */ public class ConcurrentContextInterceptor implements Interceptor { private final ConcurrentContext concurrentContext; public ConcurrentContextInterceptor(ConcurrentContext concurrentContext) { this.concurrentContext = concurrentContext; } @Override public Object processInvocation(InterceptorContext context) throws Exception { ConcurrentContext.pushCurrent(concurrentContext); try { return context.proceed(); } finally { ConcurrentContext.popCurrent(); } } }
1,850
35.294118
109
java
null
wildfly-main/ee/src/main/java/org/jboss/as/ee/concurrent/ManagedExecutorWithHungThreads.java
/* * JBoss, Home of Professional Open Source. * Copyright 2020 Red Hat, Inc., and individual contributors * as indicated by the @author tags. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.jboss.as.ee.concurrent; import org.glassfish.enterprise.concurrent.AbstractManagedThread; import org.jboss.as.ee.logging.EeLogger; import java.util.Collection; /** * A managed executor with support for hung threads. * @author emmartins */ public interface ManagedExecutorWithHungThreads { /** * * @return the executor's name */ String getName(); /** * Attempts to terminate the executor's hung tasks, by cancelling such tasks. * @return the number of hung tasks cancelled */ default void terminateHungTasks() { final String executorName = getClass().getSimpleName() + ":" + getName(); EeLogger.ROOT_LOGGER.debugf("Cancelling %s hung tasks...", executorName); final Collection<AbstractManagedThread> hungThreads = getHungThreads(); if (hungThreads != null) { for (AbstractManagedThread t : hungThreads) { final String taskIdentityName = t.getTaskIdentityName(); try { if (t instanceof ManagedThreadFactoryImpl.ManagedThread) { if (((ManagedThreadFactoryImpl.ManagedThread)t).cancelTask()) { EeLogger.ROOT_LOGGER.hungTaskCancelled(executorName, taskIdentityName); } else { EeLogger.ROOT_LOGGER.hungTaskNotCancelled(executorName, taskIdentityName); } } } catch (Throwable throwable) { EeLogger.ROOT_LOGGER.huntTaskTerminationFailure(throwable, executorName, taskIdentityName); } } } } /** * * @return the executor's hung threads */ Collection<AbstractManagedThread> getHungThreads(); }
2,500
35.246377
111
java
null
wildfly-main/ee/src/main/java/org/jboss/as/ee/concurrent/ManagedExecutorServiceImpl.java
/* * JBoss, Home of Professional Open Source. * Copyright 2014, 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 * 2110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.ee.concurrent; import org.glassfish.enterprise.concurrent.ContextServiceImpl; import org.glassfish.enterprise.concurrent.ManagedThreadFactoryImpl; import org.wildfly.extension.requestcontroller.ControlPoint; import java.util.concurrent.BlockingQueue; import java.util.concurrent.Callable; import java.util.concurrent.Future; import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.TimeUnit; import static org.jboss.as.ee.concurrent.ControlPointUtils.doWrap; import static org.jboss.as.ee.concurrent.SecurityIdentityUtils.doIdentityWrap; /** * @author Stuart Douglas * @author emmartins */ public class ManagedExecutorServiceImpl extends org.glassfish.enterprise.concurrent.ManagedExecutorServiceImpl implements ManagedExecutorWithHungThreads { private final ControlPoint controlPoint; private final ManagedExecutorRuntimeStats runtimeStats; public ManagedExecutorServiceImpl(String name, ManagedThreadFactoryImpl managedThreadFactory, long hungTaskThreshold, boolean longRunningTasks, int corePoolSize, int maxPoolSize, long keepAliveTime, TimeUnit keepAliveTimeUnit, long threadLifeTime, ContextServiceImpl contextService, RejectPolicy rejectPolicy, BlockingQueue<Runnable> queue, ControlPoint controlPoint) { super(name, managedThreadFactory, hungTaskThreshold, longRunningTasks, corePoolSize, maxPoolSize, keepAliveTime, keepAliveTimeUnit, threadLifeTime, contextService, rejectPolicy, queue); this.controlPoint = controlPoint; this.runtimeStats = new ManagedExecutorRuntimeStatsImpl(this); } public ManagedExecutorServiceImpl(String name, ManagedThreadFactoryImpl managedThreadFactory, long hungTaskThreshold, boolean longRunningTasks, int corePoolSize, int maxPoolSize, long keepAliveTime, TimeUnit keepAliveTimeUnit, long threadLifeTime, int queueCapacity, ContextServiceImpl contextService, RejectPolicy rejectPolicy, ControlPoint controlPoint) { super(name, managedThreadFactory, hungTaskThreshold, longRunningTasks, corePoolSize, maxPoolSize, keepAliveTime, keepAliveTimeUnit, threadLifeTime, queueCapacity, contextService, rejectPolicy); this.controlPoint = controlPoint; this.runtimeStats = new ManagedExecutorRuntimeStatsImpl(this); } @Override public <T> Future<T> submit(Callable<T> task) { final Callable<T> callable = doWrap(task, controlPoint); try { return super.submit(doIdentityWrap(callable)); } catch (Exception e) { controlPoint.requestComplete(); throw e; } } @Override public <T> Future<T> submit(Runnable task, T result) { final Runnable runnable = doWrap(task, controlPoint); try { return super.submit(doIdentityWrap(runnable), result); } catch (Exception e) { controlPoint.requestComplete(); throw e; } } @Override public Future<?> submit(Runnable task) { final Runnable runnable = doWrap(task, controlPoint); try { return super.submit(doIdentityWrap(runnable)); } catch (Exception e) { controlPoint.requestComplete(); throw e; } } @Override public void execute(Runnable command) { final Runnable runnable = doWrap(command, controlPoint); try { super.execute(doIdentityWrap(runnable)); } catch (Exception e) { controlPoint.requestComplete(); throw e; } } @Override protected ThreadPoolExecutor getThreadPoolExecutor() { return (ThreadPoolExecutor) super.getThreadPoolExecutor(); } /** * * @return the executor's runtime stats */ public ManagedExecutorRuntimeStats getRuntimeStats() { return runtimeStats; } }
4,864
40.939655
373
java
null
wildfly-main/ee/src/main/java/org/jboss/as/ee/concurrent/ContextServiceImpl.java
/* * JBoss, Home of Professional Open Source. * Copyright 2015, 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 * 2110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.ee.concurrent; import org.glassfish.enterprise.concurrent.spi.ContextSetupProvider; import org.wildfly.security.manager.WildFlySecurityManager; import java.lang.reflect.Proxy; import java.security.AccessController; import java.security.PrivilegedAction; import java.util.Map; import static org.jboss.as.ee.logging.EeLogger.ROOT_LOGGER; import static org.wildfly.common.Assert.checkArrayBounds; import static org.wildfly.common.Assert.checkNotNullParam; /** * An extension of Jakarta EE RI {@link org.glassfish.enterprise.concurrent.ContextServiceImpl}, which properly supports a security manager. * @author Eduardo Martins */ public class ContextServiceImpl extends org.glassfish.enterprise.concurrent.ContextServiceImpl { private final ContextServiceTypesConfiguration contextServiceTypesConfiguration; /** * * @param name * @param contextSetupProvider */ public ContextServiceImpl(String name, ContextSetupProvider contextSetupProvider, ContextServiceTypesConfiguration contextServiceTypesConfiguration) { super(name, contextSetupProvider, null); this.contextServiceTypesConfiguration = contextServiceTypesConfiguration; } private <T> T internalCreateContextualProxy(T instance, Map<String, String> executionProperties, Class<T> intf) { checkNotNullParam("instance", instance); checkNotNullParam("intf", intf); IdentityAwareProxyInvocationHandler handler = new IdentityAwareProxyInvocationHandler(this, instance, executionProperties); Object proxy = Proxy.newProxyInstance(instance.getClass().getClassLoader(), new Class[]{intf}, handler); return intf.cast(proxy); } @Override public <T> T createContextualProxy(final T instance, final Map<String, String> executionProperties, final Class<T> intf) { if (WildFlySecurityManager.isChecking()) { return AccessController.doPrivileged(new PrivilegedAction<T>() { @Override public T run() { return internalCreateContextualProxy(instance, executionProperties, intf); } }); } else { return internalCreateContextualProxy(instance, executionProperties, intf); } } private Object internalCreateContextualProxy(Object instance, Map<String, String> executionProperties, Class<?>... interfaces) { checkNotNullParam("instance", instance); checkArrayBounds(checkNotNullParam("interfaces", interfaces), 0, 1); Class<? extends Object> instanceClass = instance.getClass(); for (Class<? extends Object> thisInterface : interfaces) { if (!thisInterface.isAssignableFrom(instanceClass)) { throw ROOT_LOGGER.classDoesNotImplementAllInterfaces(); } } IdentityAwareProxyInvocationHandler handler = new IdentityAwareProxyInvocationHandler(this, instance, executionProperties); Object proxy = Proxy.newProxyInstance(instance.getClass().getClassLoader(), interfaces, handler); return proxy; } @Override public Object createContextualProxy(final Object instance, final Map<String, String> executionProperties, final Class<?>... interfaces) { if (WildFlySecurityManager.isChecking()) { return AccessController.doPrivileged(new PrivilegedAction<Object>() { @Override public Object run() { return internalCreateContextualProxy(instance, executionProperties, interfaces); } }); } else { return internalCreateContextualProxy(instance, executionProperties, interfaces); } } public ContextServiceTypesConfiguration getContextServiceTypesConfiguration() { return contextServiceTypesConfiguration; } // TODO *FOLLOW UP* revisit RI impl of the async methods, which quality seems to have issues (e.g. each method uses a new Managed Executor instance...) }
5,054
43.342105
155
java
null
wildfly-main/ee/src/main/java/org/jboss/as/ee/concurrent/ControlPointUtils.java
/* * JBoss, Home of Professional Open Source. * Copyright 2014, 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 * 2110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.ee.concurrent; import org.jboss.as.ee.logging.EeLogger; import org.wildfly.extension.requestcontroller.ControlPoint; import org.wildfly.extension.requestcontroller.RunResult; import jakarta.enterprise.concurrent.ManagedExecutorService; import jakarta.enterprise.concurrent.ManagedTask; import jakarta.enterprise.concurrent.ManagedTaskListener; import java.util.Map; import java.util.concurrent.Callable; import java.util.concurrent.Future; import java.util.concurrent.RejectedExecutionException; import static org.jboss.as.ee.logging.EeLogger.ROOT_LOGGER; /** * Class that manages the control point for executor services * * @author Stuart Douglas */ public class ControlPointUtils { public static Runnable doWrap(Runnable runnable, ControlPoint controlPoint) { if (controlPoint == null || runnable == null) { return runnable; } final RunResult result; try { result = controlPoint.forceBeginRequest(); } catch (Exception e) { throw new RejectedExecutionException(e); } if (result == RunResult.REJECTED) { throw ROOT_LOGGER.rejectedDueToMaxRequests(); } try { final ControlledRunnable controlledRunnable = new ControlledRunnable(runnable, controlPoint); return runnable instanceof ManagedTask ? new ControlledManagedRunnable(controlledRunnable, (ManagedTask) runnable) : controlledRunnable; } catch (Exception e) { controlPoint.requestComplete(); throw new RejectedExecutionException(e); } } public static <T> Callable<T> doWrap(Callable<T> callable, ControlPoint controlPoint) { if (controlPoint == null || callable == null) { return callable; } final RunResult result; try { result = controlPoint.forceBeginRequest(); } catch (Exception e) { throw new RejectedExecutionException(e); } if (result == RunResult.REJECTED) { throw ROOT_LOGGER.rejectedDueToMaxRequests(); } try { final ControlledCallable<T> controlledCallable = new ControlledCallable<>(callable, controlPoint); return callable instanceof ManagedTask ? new ControlledManagedCallable<>(controlledCallable, (ManagedTask) callable) : controlledCallable; } catch (Exception e) { controlPoint.requestComplete(); throw new RejectedExecutionException(e); } } public static Runnable doScheduledWrap(Runnable runnable, ControlPoint controlPoint) { if (controlPoint == null || runnable == null) { return runnable; } else { final ControlledScheduledRunnable controlledScheduledRunnable = new ControlledScheduledRunnable(runnable, controlPoint); return runnable instanceof ManagedTask ? new ControlledManagedRunnable(controlledScheduledRunnable, (ManagedTask) runnable) : controlledScheduledRunnable; } } public static <T> Callable<T> doScheduledWrap(Callable<T> callable, ControlPoint controlPoint) { if (controlPoint == null || callable == null) { return callable; } else { final ControlledScheduledCallable<T> controlledScheduledCallable = new ControlledScheduledCallable<>(callable, controlPoint); return callable instanceof ManagedTask ? new ControlledManagedCallable<>(controlledScheduledCallable, (ManagedTask) callable) : controlledScheduledCallable; } } /** * Runnable that wraps a runnable to allow server suspend/resume to work correctly. * */ static class ControlledRunnable implements Runnable { private final Runnable runnable; private final ControlPoint controlPoint; ControlledRunnable(Runnable runnable, ControlPoint controlPoint) { this.runnable = runnable; this.controlPoint = controlPoint; } @Override public void run() { try { runnable.run(); } finally { controlPoint.requestComplete(); } } } /** * Runnable that wraps a callable to allow server suspend/resume to work correctly. * */ static class ControlledCallable<T> implements Callable<T> { private final Callable<T> callable; private final ControlPoint controlPoint; ControlledCallable(Callable<T> callable, ControlPoint controlPoint) { this.callable = callable; this.controlPoint = controlPoint; } @Override public T call() throws Exception { try { return callable.call(); } finally { controlPoint.requestComplete(); } } } /** * Runnable that wraps a runnable to be scheduled, which allows server suspend/resume to work correctly. * */ static class ControlledScheduledRunnable implements Runnable { private final Runnable runnable; private final ControlPoint controlPoint; ControlledScheduledRunnable(Runnable runnable, ControlPoint controlPoint) { this.runnable = runnable; this.controlPoint = controlPoint; } @Override public void run() { if (controlPoint == null) { runnable.run(); } else { RuntimeException runnableException = null; try { if (controlPoint.beginRequest() == RunResult.RUN) { try { runnable.run(); } catch (RuntimeException e) { runnableException = e; throw e; } finally { controlPoint.requestComplete(); } } else { throw EeLogger.ROOT_LOGGER.cannotRunScheduledTask(runnable); } } catch (RuntimeException re) { // WFLY-13043 if (runnableException == null) { EeLogger.ROOT_LOGGER.failedToRunTask(runnable,re); return; } else { throw EeLogger.ROOT_LOGGER.failureWhileRunningTask(runnable, re); } } } } } /** * Runnable that wraps a callable to be scheduled, which allows server suspend/resume to work correctly. * */ static class ControlledScheduledCallable<T> implements Callable<T> { private final Callable<T> callable; private final ControlPoint controlPoint; ControlledScheduledCallable(Callable<T> callable, ControlPoint controlPoint) { this.callable = callable; this.controlPoint = controlPoint; } @Override public T call() throws Exception { if (controlPoint == null) { return callable.call(); } else { try { if (controlPoint.beginRequest() == RunResult.RUN) { try { return callable.call(); } finally { controlPoint.requestComplete(); } } else { throw EeLogger.ROOT_LOGGER.cannotRunScheduledTask(callable); } } catch (Exception e) { throw EeLogger.ROOT_LOGGER.failureWhileRunningTask(callable, e); } } } } /** * A managed controlled task. */ static class ControlledManagedTask implements ManagedTask { private final ManagedTask managedTask; private final ControlledManagedTaskListener managedTaskListenerWrapper; ControlledManagedTask(ManagedTask managedTask) { this.managedTask = managedTask; this.managedTaskListenerWrapper = managedTask.getManagedTaskListener() != null ? new ControlledManagedTaskListener(managedTask.getManagedTaskListener()) : null; } @Override public Map<String, String> getExecutionProperties() { return managedTask.getExecutionProperties(); } @Override public ManagedTaskListener getManagedTaskListener() { return managedTaskListenerWrapper; } } /** * A managed controlled task which is a runnable. * */ static class ControlledManagedRunnable extends ControlledManagedTask implements Runnable { private final Runnable controlledTask; ControlledManagedRunnable(Runnable controlledTask, ManagedTask managedTask) { super(managedTask); this.controlledTask = controlledTask; } @Override public void run() { controlledTask.run(); } } /** * A managed controlled task which is a callable. * */ static class ControlledManagedCallable<T> extends ControlledManagedTask implements Callable<T> { private final Callable<T> controlledTask; ControlledManagedCallable(Callable<T> controlledTask, ManagedTask managedTask) { super(managedTask); this.controlledTask = controlledTask; } @Override public T call() throws Exception { return controlledTask.call(); } } /** * A managed task listener for managed controlled tasks. */ static class ControlledManagedTaskListener implements ManagedTaskListener { private final ManagedTaskListener managedTaskListener; ControlledManagedTaskListener(ManagedTaskListener managedTaskListener) { this.managedTaskListener = managedTaskListener; } @Override public void taskAborted(Future<?> future, ManagedExecutorService executor, Object task, Throwable exception) { managedTaskListener.taskAborted(future, executor, ((ControlledManagedTask)task).managedTask, exception); } @Override public void taskDone(Future<?> future, ManagedExecutorService executor, Object task, Throwable exception) { managedTaskListener.taskDone(future, executor, ((ControlledManagedTask) task).managedTask, exception); } @Override public void taskStarting(Future<?> future, ManagedExecutorService executor, Object task) { managedTaskListener.taskStarting(future, executor, ((ControlledManagedTask) task).managedTask); } @Override public void taskSubmitted(Future<?> future, ManagedExecutorService executor, Object task) { managedTaskListener.taskSubmitted(future, executor, ((ControlledManagedTask) task).managedTask); } } }
12,037
35.259036
172
java
null
wildfly-main/ee/src/main/java/org/jboss/as/ee/concurrent/DefaultContextSetupProviderImpl.java
/* * 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.jboss.as.ee.concurrent; import org.glassfish.enterprise.concurrent.spi.ContextSetupProvider; import org.jboss.as.ee.concurrent.handle.ResetContextHandle; import org.jboss.as.ee.concurrent.handle.SetupContextHandle; import org.jboss.as.ee.logging.EeLogger; import org.jboss.as.ee.concurrent.handle.NullContextHandle; import jakarta.enterprise.concurrent.ContextService; import java.util.Map; /** * The default context setup provider. delegates context saving/setting/resetting to the context handle factory provided by the current concurrent context. * * @author Eduardo Martins */ public class DefaultContextSetupProviderImpl implements ContextSetupProvider { @Override public org.glassfish.enterprise.concurrent.spi.ContextHandle saveContext(ContextService contextService) { return saveContext(contextService, null); } @Override public org.glassfish.enterprise.concurrent.spi.ContextHandle saveContext(ContextService contextService, Map<String, String> contextObjectProperties) { final ConcurrentContext concurrentContext = ConcurrentContext.current(); if (concurrentContext != null) { return concurrentContext.saveContext(contextService, contextObjectProperties); } else { EeLogger.ROOT_LOGGER.debug("ee concurrency context not found in invocation context"); return new NullContextHandle(); } } @Override public org.glassfish.enterprise.concurrent.spi.ContextHandle setup(org.glassfish.enterprise.concurrent.spi.ContextHandle contextHandle) throws IllegalStateException { return ((SetupContextHandle) contextHandle).setup(); } @Override public void reset(org.glassfish.enterprise.concurrent.spi.ContextHandle contextHandle) { ((ResetContextHandle) contextHandle).reset(); } }
2,865
42.424242
170
java
null
wildfly-main/ee/src/main/java/org/jboss/as/ee/concurrent/TransactionSetupProviderImpl.java
/* * JBoss, Home of Professional Open Source. * Copyright 2014, 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.jboss.as.ee.concurrent; import org.glassfish.enterprise.concurrent.spi.TransactionHandle; import org.glassfish.enterprise.concurrent.spi.TransactionSetupProvider; import org.jboss.as.ee.logging.EeLogger; import org.wildfly.transaction.client.ContextTransactionManager; import jakarta.enterprise.concurrent.ManagedTask; import jakarta.transaction.Transaction; import jakarta.transaction.TransactionManager; /** * The transaction setup provider handles transaction suspend/resume. * * @author Eduardo Martins */ public class TransactionSetupProviderImpl implements TransactionSetupProvider { private final transient TransactionManager transactionManager; /** */ public TransactionSetupProviderImpl() { this.transactionManager = ContextTransactionManager.getInstance(); } @Override public TransactionHandle beforeProxyMethod(String transactionExecutionProperty) { Transaction transaction = null; if (!ManagedTask.USE_TRANSACTION_OF_EXECUTION_THREAD.equals(transactionExecutionProperty)) { try { transaction = transactionManager.suspend(); } catch (Throwable e) { EeLogger.ROOT_LOGGER.debug("failed to suspend transaction",e); } } return new TransactionHandleImpl(transaction); } @Override public void afterProxyMethod(TransactionHandle transactionHandle, String transactionExecutionProperty) { final Transaction transaction = ((TransactionHandleImpl) transactionHandle).getTransaction(); if (transaction != null) { try { transactionManager.resume(transaction); } catch (Throwable e) { EeLogger.ROOT_LOGGER.debug("failed to resume transaction",e); } } } private static class TransactionHandleImpl implements TransactionHandle { private final Transaction transaction; private TransactionHandleImpl(Transaction transaction) { this.transaction = transaction; } public Transaction getTransaction() { return transaction; } } }
3,185
36.046512
108
java
null
wildfly-main/ee/src/main/java/org/jboss/as/ee/concurrent/ManagedThreadFactoryImpl.java
/* * JBoss, Home of Professional Open Source. * Copyright 2017, 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 * 2110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.ee.concurrent; import org.glassfish.enterprise.concurrent.AbstractManagedThread; import org.glassfish.enterprise.concurrent.ContextServiceImpl; import org.glassfish.enterprise.concurrent.internal.ManagedFutureTask; import org.glassfish.enterprise.concurrent.spi.ContextHandle; import org.wildfly.security.auth.server.SecurityIdentity; import org.wildfly.security.manager.WildFlySecurityManager; import jakarta.enterprise.concurrent.ManagedThreadFactory; import java.security.AccessControlContext; import java.security.AccessController; import java.security.PrivilegedAction; /** * {@link ManagedThreadFactory} implementation ensuring {@link SecurityIdentity} propagation into new threads. * @author <a href="mailto:[email protected]">Jan Kalina</a> * @author emmartins */ public class ManagedThreadFactoryImpl extends org.glassfish.enterprise.concurrent.ManagedThreadFactoryImpl { /** * the priority set on new threads */ private final int priority; /** * the factory's ACC */ private final AccessControlContext accessControlContext; public ManagedThreadFactoryImpl(String name, ContextServiceImpl contextService, int priority) { super(name, contextService, priority); this.priority = priority; this.accessControlContext = AccessController.getContext(); } /** * * @return the priority set on new threads */ public int getPriority() { return priority; } protected AbstractManagedThread createThread(Runnable r, final ContextHandle contextHandleForSetup) { if (contextHandleForSetup != null) { // app thread, do identity wrap r = SecurityIdentityUtils.doIdentityWrap(r); } // use the factory's acc as privileged, otherwise the new thread inherits current thread's acc final AbstractManagedThread t = AccessController.doPrivileged(new CreateThreadAction(r, contextHandleForSetup), accessControlContext); // reset thread classloader to prevent leaks if (!WildFlySecurityManager.isChecking()) { t.setContextClassLoader(null); } else { AccessController.doPrivileged((PrivilegedAction<Void>) () -> { t.setContextClassLoader(null); return null; }); } return t; } @Override public void taskStarting(Thread t, ManagedFutureTask task) { super.taskStarting(t, task); if (t instanceof ManagedThread) { ((ManagedThread)t).task = task; } } @Override public void taskDone(Thread t) { super.taskDone(t); if (t instanceof ManagedThread) { ((ManagedThread)t).task = null; } } private final class CreateThreadAction implements PrivilegedAction<AbstractManagedThread> { private final Runnable r; private final ContextHandle contextHandleForSetup; private CreateThreadAction(Runnable r, ContextHandle contextHandleForSetup) { this.r = r; this.contextHandleForSetup = contextHandleForSetup; } @Override public AbstractManagedThread run() { return new ManagedThread(r, contextHandleForSetup); } } /** * Managed thread extension, to allow canceling the task running in the thread. * @author emmartins */ public class ManagedThread extends org.glassfish.enterprise.concurrent.ManagedThreadFactoryImpl.ManagedThread { volatile ManagedFutureTask task = null; /** * * @param target * @param contextHandleForSetup */ public ManagedThread(Runnable target, ContextHandle contextHandleForSetup) { super(target, contextHandleForSetup); } /** * Cancel the task running in the thread. * @return */ boolean cancelTask() { final ManagedFutureTask task = this.task; if (task != null) { return task.cancel(true); } return false; } } }
5,151
34.531034
142
java
null
wildfly-main/ee/src/main/java/org/jboss/as/ee/concurrent/ContextServiceTypesConfiguration.java
/* * JBoss, Home of Professional Open Source. * Copyright 2022 Red Hat, Inc., and individual contributors * as indicated by the @author tags. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.jboss.as.ee.concurrent; import jakarta.enterprise.concurrent.ContextServiceDefinition; import org.jboss.as.ee.logging.EeLogger; import java.io.Serializable; import java.util.Collections; import java.util.HashSet; import java.util.Objects; import java.util.Set; /** * The configuration for a Context Service, which indicates if a context type should be cleared, propagated or unchanged. * @author emmartins */ public class ContextServiceTypesConfiguration implements Serializable { public static final ContextServiceTypesConfiguration DEFAULT = new ContextServiceTypesConfiguration(null, null, null); private static final long serialVersionUID = -8818025042707301480L; private final Set<String> cleared; private final Set<String> propagated; private final Set<String> unchanged; /** * * @param cleared * @param propagated * @param unchanged */ private ContextServiceTypesConfiguration(Set<String> cleared, Set<String> propagated, Set<String> unchanged) { if (cleared == null || cleared.isEmpty()) { // spec default for cleared includes only Transaction this.cleared = Set.of(ContextServiceDefinition.TRANSACTION); } else { this.cleared = Collections.unmodifiableSet(cleared); } if (propagated == null || propagated.isEmpty()) { // spec default for propagation includes all remaining, i.e. not in "cleared" and not in "unchanged" this.propagated = Set.of(ContextServiceDefinition.ALL_REMAINING); } else { this.propagated = Collections.unmodifiableSet(propagated); } if (unchanged == null || unchanged.isEmpty()) { // spec default for unchanged includes none, which is represented by a single empty element this.unchanged = Set.of(""); } else { this.unchanged = Collections.unmodifiableSet(unchanged); } } /** * * @param contextType * @return true if the specified contextType should be cleared, false otherwise */ public boolean isCleared(String contextType) { return isTypeIncluded(contextType, cleared, propagated, unchanged); } /** * * @param contextType * @return true if the specified contextType should be propagated, false otherwise */ public boolean isPropagated(String contextType) { return isTypeIncluded(contextType, propagated, cleared, unchanged); } /** * * @param contextType * @return true if the specified contextType should be unchanged, false otherwise */ public boolean isUnchanged(String contextType) { return isTypeIncluded(contextType, unchanged, cleared, propagated); } /** * Checks if a contextType is included in a set of contextTypes. * @param contextType * @param contextTypes * @param otherContextTypes1 * @param otherContextTypes2 * @return true if contextType is in contextTypes, or if contextTypes contains ContextServiceDefinition.ALL_REMAINING and contextType not in otherContextTypes1 and contextType not in otherContextTypes2; false otherwise */ private boolean isTypeIncluded(String contextType, Set<String> contextTypes, Set<String> otherContextTypes1, Set<String> otherContextTypes2) { Objects.requireNonNull(contextType); if (contextTypes.contains(contextType)) { return true; } if (contextTypes.contains(ContextServiceDefinition.ALL_REMAINING)) { return !otherContextTypes1.contains(contextType) && !otherContextTypes2.contains(contextType); } return false; } /** * The builder class. */ public static class Builder { private Set<String> cleared; private Set<String> propagated; private Set<String> unchanged; /** * * @param cleared * @return */ public Builder setCleared(Set<String> cleared) { this.cleared = cleared; return this; } /** * * @param cleared * @return */ public Builder setCleared(String[] cleared) { if (cleared == null || cleared.length == 0) { this.cleared = null; } else { this.cleared = new HashSet<>(); Collections.addAll(this.cleared, cleared); } return this; } /** * * @param propagated * @return */ public Builder setPropagated(Set<String> propagated) { this.propagated = propagated; return this; } /** * * @param propagated * @return */ public Builder setPropagated(String[] propagated) { if (propagated == null || propagated.length == 0) { this.propagated = null; } else { this.propagated = new HashSet<>(); Collections.addAll(this.propagated, propagated); } return this; } /** * * @param unchanged * @return */ public Builder setUnchanged(Set<String> unchanged) { this.unchanged = unchanged; return this; } /** * * @param unchanged * @return */ public Builder setUnchanged(String[] unchanged) { if (unchanged == null || unchanged.length == 0) { this.unchanged = null; } else { this.unchanged = new HashSet<>(); Collections.addAll(this.unchanged, unchanged); } return this; } /** * @return a new ContextServiceTypesConfiguration instance with the set values of cleared, propagated and unchanged * @throws IllegalStateException if there are multiple usages of ContextServiceDefinition.ALL_REMAINING currently set */ public ContextServiceTypesConfiguration build() throws IllegalStateException { // validate there are not multiple ContextServiceDefinition.ALL_REMAINING int remainingCount = 0; if (cleared != null && cleared.contains(ContextServiceDefinition.ALL_REMAINING)) { remainingCount++; } if (propagated == null || propagated.isEmpty() || propagated.contains(ContextServiceDefinition.ALL_REMAINING)) { remainingCount++; } if (unchanged != null && unchanged.contains(ContextServiceDefinition.ALL_REMAINING)) { remainingCount++; } if (remainingCount > 1) { throw EeLogger.ROOT_LOGGER.multipleUsesOfAllRemaining(); } if ((cleared == null || cleared.isEmpty()) && (propagated == null || propagated.isEmpty()) && (unchanged == null || unchanged.isEmpty())) { return DEFAULT; } else { return new ContextServiceTypesConfiguration(cleared, propagated, unchanged); } } } }
7,921
34.053097
222
java
null
wildfly-main/ee/src/main/java/org/jboss/as/ee/concurrent/ManagedExecutorRuntimeStats.java
/* * JBoss, Home of Professional Open Source. * Copyright 2019 Red Hat, Inc., and individual contributors * as indicated by the @author tags. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.jboss.as.ee.concurrent; /** * Runtime stats from an executor. * @author emmartins */ public interface ManagedExecutorRuntimeStats { /** * * @return the approximate number of threads that are actively executing tasks */ int getActiveThreadsCount(); /** * * @return the approximate total number of tasks that have completed execution */ long getCompletedTaskCount(); /** * * @return the number of executor threads that are hung */ int getHungThreadsCount(); /** * * @return the largest number of executor threads */ int getMaxThreadsCount(); /** * * @return the current size of the executor's task queue */ int getQueueSize(); /** * * @return the approximate total number of tasks that have ever been submitted for execution */ long getTaskCount(); /** * * @return the current number of executor threads */ int getThreadsCount(); }
1,721
24.323529
96
java
null
wildfly-main/ee/src/main/java/org/jboss/as/ee/concurrent/ConcurrentContextSetupAction.java
/* * 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.jboss.as.ee.concurrent; import org.jboss.as.server.deployment.SetupAction; import org.jboss.msc.service.ServiceName; import java.util.Collections; import java.util.Map; import java.util.Set; /** * @author Eduardo Martins */ public class ConcurrentContextSetupAction implements SetupAction { private final ConcurrentContext concurrentContext; public ConcurrentContextSetupAction(ConcurrentContext concurrentContext) { this.concurrentContext = concurrentContext; } @Override public void setup(Map<String, Object> properties) { ConcurrentContext.pushCurrent(concurrentContext); } @Override public void teardown(Map<String, Object> properties) { ConcurrentContext.popCurrent(); } @Override public int priority() { return 100; } @Override public Set<ServiceName> dependencies() { return Collections.emptySet(); } public ConcurrentContext getConcurrentContext() { return concurrentContext; } }
2,050
30.553846
78
java
null
wildfly-main/ee/src/main/java/org/jboss/as/ee/concurrent/ServiceTransactionSetupProvider.java
/* * JBoss, Home of Professional Open Source. * Copyright 2015, 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.jboss.as.ee.concurrent; import org.glassfish.enterprise.concurrent.spi.TransactionHandle; import org.glassfish.enterprise.concurrent.spi.TransactionSetupProvider; import org.jboss.as.ee.logging.EeLogger; import org.jboss.as.server.CurrentServiceContainer; import org.jboss.msc.service.ServiceContainer; import org.jboss.msc.service.ServiceController; import org.jboss.msc.service.ServiceName; import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.security.AccessController; /** * A wrapper for a {@link org.glassfish.enterprise.concurrent.spi.TransactionSetupProvider} stored in a service, allowing deserialization through MSC. * @author emmartins */ public class ServiceTransactionSetupProvider implements TransactionSetupProvider { private transient TransactionSetupProvider transactionSetupProvider; private final ServiceName serviceName; /** * * @param transactionSetupProvider the provider to wrap * @param serviceName the name of the service where the provider may be retrieved */ public ServiceTransactionSetupProvider(TransactionSetupProvider transactionSetupProvider, ServiceName serviceName) { this.transactionSetupProvider = transactionSetupProvider; this.serviceName = serviceName; } @Override public TransactionHandle beforeProxyMethod(String transactionExecutionProperty) { return transactionSetupProvider.beforeProxyMethod(transactionExecutionProperty); } @Override public void afterProxyMethod(TransactionHandle handle, String transactionExecutionProperty) { transactionSetupProvider.afterProxyMethod(handle, transactionExecutionProperty); } private void writeObject(ObjectOutputStream out) throws IOException { out.defaultWriteObject(); } private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException { in.defaultReadObject(); // resolve from msc final ServiceContainer currentServiceContainer = System.getSecurityManager() == null ? CurrentServiceContainer.getServiceContainer() : AccessController.doPrivileged(CurrentServiceContainer.GET_ACTION); final ServiceController<?> serviceController = currentServiceContainer.getService(serviceName); if (serviceController == null) { throw EeLogger.ROOT_LOGGER.transactionSetupProviderServiceNotInstalled(); } transactionSetupProvider = (TransactionSetupProvider) serviceController.getValue(); } }
3,576
43.160494
209
java
null
wildfly-main/ee/src/main/java/org/jboss/as/ee/concurrent/ManagedScheduledExecutorServiceImpl.java
/* * JBoss, Home of Professional Open Source. * Copyright 2014, 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.jboss.as.ee.concurrent; import org.glassfish.enterprise.concurrent.ContextServiceImpl; import org.wildfly.extension.requestcontroller.ControlPoint; import jakarta.enterprise.concurrent.LastExecution; import jakarta.enterprise.concurrent.Trigger; import java.util.Date; import java.util.concurrent.Callable; import java.util.concurrent.Future; import java.util.concurrent.ScheduledFuture; import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.TimeUnit; import static org.jboss.as.ee.concurrent.ControlPointUtils.doScheduledWrap; import static org.jboss.as.ee.concurrent.ControlPointUtils.doWrap; import static org.jboss.as.ee.concurrent.SecurityIdentityUtils.doIdentityWrap; /** * WildFly's extension of {@link org.glassfish.enterprise.concurrent.ManagedScheduledExecutorServiceImpl}. * * @author Eduardo Martins */ public class ManagedScheduledExecutorServiceImpl extends org.glassfish.enterprise.concurrent.ManagedScheduledExecutorServiceImpl implements ManagedExecutorWithHungThreads { private final ControlPoint controlPoint; private final ManagedExecutorRuntimeStats runtimeStats; public ManagedScheduledExecutorServiceImpl(String name, ManagedThreadFactoryImpl managedThreadFactory, long hungTaskThreshold, boolean longRunningTasks, int corePoolSize, long keepAliveTime, TimeUnit keepAliveTimeUnit, long threadLifeTime, ContextServiceImpl contextService, RejectPolicy rejectPolicy, ControlPoint controlPoint) { super(name, managedThreadFactory, hungTaskThreshold, longRunningTasks, corePoolSize, keepAliveTime, keepAliveTimeUnit, threadLifeTime, contextService, rejectPolicy); this.controlPoint = controlPoint; this.runtimeStats = new ManagedExecutorRuntimeStatsImpl(this); } @Override public void execute(Runnable command) { super.execute(doIdentityWrap(doWrap(command, controlPoint))); } @Override public Future<?> submit(Runnable task) { return super.submit(doIdentityWrap(doWrap(task, controlPoint))); } @Override public <T> Future<T> submit(Runnable task, T result) { return super.submit(doIdentityWrap(doWrap(task, controlPoint)), result); } @Override public <T> Future<T> submit(Callable<T> task) { return super.submit(doIdentityWrap(doWrap(task, controlPoint))); } @Override public ScheduledFuture<?> schedule(Runnable command, Trigger trigger) { final CancellableTrigger ctrigger = new CancellableTrigger(trigger); ctrigger.future = super.schedule(doIdentityWrap(doScheduledWrap(command, controlPoint)), ctrigger); return ctrigger.future; } @Override public <V> ScheduledFuture<V> schedule(Callable<V> callable, Trigger trigger) { final CancellableTrigger ctrigger = new CancellableTrigger(trigger); ctrigger.future = super.schedule(doIdentityWrap(doScheduledWrap(callable, controlPoint)), ctrigger); return ctrigger.future; } @Override public ScheduledFuture<?> schedule(Runnable command, long delay, TimeUnit unit) { return super.schedule(doIdentityWrap(doScheduledWrap(command, controlPoint)), delay, unit); } @Override public <V> ScheduledFuture<V> schedule(Callable<V> callable, long delay, TimeUnit unit) { return super.schedule(doIdentityWrap(doScheduledWrap(callable, controlPoint)), delay, unit); } @Override public ScheduledFuture<?> scheduleAtFixedRate(Runnable command, long initialDelay, long period, TimeUnit unit) { return super.scheduleAtFixedRate(doIdentityWrap(doScheduledWrap(command, controlPoint)), initialDelay, period, unit); } @Override public ScheduledFuture<?> scheduleWithFixedDelay(Runnable command, long initialDelay, long delay, TimeUnit unit) { return super.scheduleWithFixedDelay(doIdentityWrap(doScheduledWrap(command, controlPoint)), initialDelay, delay, unit); } @Override protected ThreadPoolExecutor getThreadPoolExecutor() { return (ThreadPoolExecutor) super.getThreadPoolExecutor(); } /** * * @return the executor's runtime stats */ public ManagedExecutorRuntimeStats getRuntimeStats() { return runtimeStats; } /** * A {@link jakarta.enterprise.concurrent.Trigger} wrapper that stops scheduling if the related {@link java.util.concurrent.ScheduledFuture} is cancelled. */ private static class CancellableTrigger implements Trigger { private final Trigger trigger; private ScheduledFuture future; CancellableTrigger(Trigger trigger) { this.trigger = trigger; } @Override public Date getNextRunTime(LastExecution lastExecution, Date taskScheduledTime) { Date nextRunTime = trigger.getNextRunTime(lastExecution, taskScheduledTime); final ScheduledFuture future = this.future; if (future != null && future.isCancelled()) { nextRunTime = null; } return nextRunTime; } @Override public boolean skipRun(LastExecution lastExecution, Date date) { return trigger.skipRun(lastExecution, date); } } }
6,254
40.7
334
java
null
wildfly-main/ee/src/main/java/org/jboss/as/ee/concurrent/ConcurrentContext.java
/* * 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.jboss.as.ee.concurrent; import jakarta.enterprise.concurrent.ContextService; import jakarta.enterprise.concurrent.ContextServiceDefinition; import org.jboss.as.ee.concurrent.handle.ContextHandleFactory; import org.jboss.as.ee.concurrent.handle.EE10ContextHandleFactory; import org.jboss.as.ee.concurrent.handle.ResetContextHandle; import org.jboss.as.ee.concurrent.handle.SetupContextHandle; import org.jboss.as.ee.logging.EeLogger; import org.jboss.as.server.CurrentServiceContainer; import org.jboss.modules.Module; import org.jboss.modules.ModuleIdentifier; import org.jboss.msc.service.ServiceContainer; import org.jboss.msc.service.ServiceController; import org.jboss.msc.service.ServiceName; import org.wildfly.common.function.ThreadLocalStack; import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.security.AccessController; import java.security.PrivilegedAction; import java.util.ArrayList; import java.util.Comparator; import java.util.HashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.SortedSet; import java.util.TreeSet; import static java.lang.Thread.currentThread; /** * Manages context handle factories, it is used by EE Context Services to save the invocation context. * * @author Eduardo Martins */ public class ConcurrentContext { /** * the name of the factory used by the chained context handles */ public static final String CONTEXT_HANDLE_FACTORY_NAME = "CONCURRENT_CONTEXT"; /** * a thread local stack with the contexts pushed */ private static final ThreadLocalStack<ConcurrentContext> current = new ThreadLocalStack<ConcurrentContext>(); /** * Sets the specified context as the current one, in the current thread. * * @param context The current context */ public static void pushCurrent(final ConcurrentContext context) { current.push(context); } /** * Pops the current context in the current thread. * * @return */ public static ConcurrentContext popCurrent() { return current.pop(); } /** * Retrieves the current context in the current thread. * * @return */ public static ConcurrentContext current() { return current.peek(); } private final Map<String, ContextHandleFactory> factoryMap = new HashMap<>(); private List<ContextHandleFactory> factoryOrderedList; private volatile ServiceName serviceName; /** * * @param serviceName */ public void setServiceName(ServiceName serviceName) { this.serviceName = serviceName; } /** * Adds a new factory. * @param factory */ public synchronized void addFactory(ContextHandleFactory factory) { final String factoryName = factory.getName(); if(factoryMap.containsKey(factoryName)) { throw EeLogger.ROOT_LOGGER.factoryAlreadyExists(this, factoryName); } factoryMap.put(factoryName, factory); final Comparator<ContextHandleFactory> comparator = new Comparator<ContextHandleFactory>() { @Override public int compare(ContextHandleFactory o1, ContextHandleFactory o2) { return Integer.compare(o1.getChainPriority(),o2.getChainPriority()); } }; SortedSet<ContextHandleFactory> sortedSet = new TreeSet<>(comparator); sortedSet.addAll(factoryMap.values()); // TODO *FOLLOW UP* now that we have factories coming from deployments, rework the ordering approach to no use treeset, which does not supports factories with same priority (the order param) factoryOrderedList = new ArrayList<>(sortedSet); } /** * Saves the current invocation context on a chained context handle. * @param contextService * @param contextObjectProperties * @return */ public SetupContextHandle saveContext(ContextService contextService, Map<String, String> contextObjectProperties) { final ContextServiceTypesConfiguration contextServiceTypesConfiguration = ((ContextServiceImpl)contextService).getContextServiceTypesConfiguration(); final List<SetupContextHandle> handles = new ArrayList<>(factoryOrderedList.size()); for (ContextHandleFactory factory : factoryOrderedList) { // TODO *FOLLOW UP* migrate all factories on other subsystems to use the new EE10ContextHandleFactory API, and once all done replace the legacy ContextHandleFactory API with the new one, no need to keep both if (factory instanceof EE10ContextHandleFactory) { final EE10ContextHandleFactory ee10ContextHandleFactory = (EE10ContextHandleFactory) factory; final String contextType = ee10ContextHandleFactory.getContextType(); final SetupContextHandle setupContextHandle; if (contextServiceTypesConfiguration.isCleared(contextType)) { setupContextHandle = ee10ContextHandleFactory.clearedContext(contextService, contextObjectProperties); } else if (contextServiceTypesConfiguration.isPropagated(contextType)) { setupContextHandle = ee10ContextHandleFactory.propagatedContext(contextService, contextObjectProperties); } else if (contextServiceTypesConfiguration.isUnchanged(contextType)) { setupContextHandle = ee10ContextHandleFactory.unchangedContext(contextService, contextObjectProperties); } else { setupContextHandle = null; } if (setupContextHandle != null) { handles.add(setupContextHandle); } } else { if (contextServiceTypesConfiguration.isPropagated(ContextServiceDefinition.APPLICATION)) { handles.add(factory.saveContext(contextService, contextObjectProperties)); } } } return new ChainedSetupContextHandle(this, handles); } /** * A setup context handle that is a chain of other setup context handles */ private static class ChainedSetupContextHandle implements SetupContextHandle { private static final long serialVersionUID = 3609876437062603461L; private transient ConcurrentContext concurrentContext; private transient List<SetupContextHandle> setupHandles; private ChainedSetupContextHandle(ConcurrentContext concurrentContext, List<SetupContextHandle> setupHandles) { this.concurrentContext = concurrentContext; this.setupHandles = setupHandles; } @Override public ResetContextHandle setup() throws IllegalStateException { final LinkedList<ResetContextHandle> resetHandles = new LinkedList<>(); final ResetContextHandle resetContextHandle = new ChainedResetContextHandle(resetHandles); try { ConcurrentContext.pushCurrent(concurrentContext); for (SetupContextHandle handle : setupHandles) { resetHandles.addFirst(handle.setup()); } } catch (Error | RuntimeException e) { resetContextHandle.reset(); throw e; } return resetContextHandle; } @Override public String getFactoryName() { return CONTEXT_HANDLE_FACTORY_NAME; } private void writeObject(ObjectOutputStream out) throws IOException { out.defaultWriteObject(); // write the concurrent context service name out.writeObject(concurrentContext.serviceName); // write the number of setup handles out.write(setupHandles.size()); // write each handle ContextHandleFactory factory = null; String factoryName = null; for(SetupContextHandle handle : setupHandles) { factoryName = handle.getFactoryName(); factory = concurrentContext.factoryMap.get(factoryName); if(factory == null) { throw EeLogger.ROOT_LOGGER.factoryNotFound(concurrentContext, factoryName); } out.writeUTF(factoryName); factory.writeSetupContextHandle(handle, out); } } private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException { // switch to EE module classloader, otherwise, due to serialization, deployments would need to have dependencies to other internal modules final Module module; try { module = Module.getBootModuleLoader().loadModule(ModuleIdentifier.create("org.jboss.as.ee")); } catch (Throwable e) { throw new IOException(e); } final SecurityManager sm = System.getSecurityManager(); final ClassLoader classLoader; if (sm == null) { classLoader = currentThread().getContextClassLoader(); } else { classLoader = AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() { @Override public ClassLoader run() { return currentThread().getContextClassLoader(); } }); } if (sm == null) { currentThread().setContextClassLoader(module.getClassLoader()); } else { AccessController.doPrivileged(new PrivilegedAction<Object>() { @Override public Object run() { currentThread().setContextClassLoader(module.getClassLoader()); return null; } }); } try { in.defaultReadObject(); // restore concurrent context from msc final ServiceName serviceName = (ServiceName) in.readObject(); final ServiceController<?> serviceController = currentServiceContainer().getService(serviceName); if(serviceController == null) { throw EeLogger.ROOT_LOGGER.concurrentContextServiceNotInstalled(serviceName); } concurrentContext = (ConcurrentContext) serviceController.getValue(); // read setup handles setupHandles = new ArrayList<>(); ContextHandleFactory factory = null; String factoryName = null; for(int i = in.read(); i > 0; i--) { factoryName = in.readUTF(); factory = concurrentContext.factoryMap.get(factoryName); if(factory == null) { throw EeLogger.ROOT_LOGGER.factoryNotFound(concurrentContext, factoryName); } setupHandles.add(factory.readSetupContextHandle(in)); } } finally { if (sm == null) { currentThread().setContextClassLoader(classLoader); } else { AccessController.doPrivileged(new PrivilegedAction<Object>() { @Override public Object run() { currentThread().setContextClassLoader(classLoader); return null; } }); } } } } /** * A reset context handle that is a chain of other reset context handles */ private static class ChainedResetContextHandle implements ResetContextHandle { private static final long serialVersionUID = 8329909590327062062L; private transient List<ResetContextHandle> resetHandles; private ChainedResetContextHandle(List<ResetContextHandle> resetHandles) { this.resetHandles = resetHandles; } @Override public void reset() { if(resetHandles != null) { for (ResetContextHandle handle : resetHandles) { try { handle.reset(); } catch (Throwable e) { EeLogger.ROOT_LOGGER.debug("failed to reset handle",e); } } resetHandles = null; ConcurrentContext.popCurrent(); } } @Override public String getFactoryName() { return CONTEXT_HANDLE_FACTORY_NAME; } } private static ServiceContainer currentServiceContainer() { if(System.getSecurityManager() == null) { return CurrentServiceContainer.getServiceContainer(); } return AccessController.doPrivileged(CurrentServiceContainer.GET_ACTION); } }
14,017
40.844776
219
java
null
wildfly-main/ee/src/main/java/org/jboss/as/ee/concurrent/IdentityAwareProxyInvocationHandler.java
/* * JBoss, Home of Professional Open Source. * Copyright 2017 Red Hat, Inc., and individual contributors * as indicated by the @author tags. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.jboss.as.ee.concurrent; import java.lang.reflect.Method; import java.security.PrivilegedActionException; import java.security.PrivilegedExceptionAction; import java.util.Map; import org.glassfish.enterprise.concurrent.ContextServiceImpl; import org.glassfish.enterprise.concurrent.internal.ContextProxyInvocationHandler; import org.wildfly.security.auth.server.SecurityDomain; import org.wildfly.security.auth.server.SecurityIdentity; /** * A {@link SecurityIdentity} aware {@link ContextProxyInvocationHandler}. * * @author <a href="mailto:[email protected]">Darran Lofthouse</a> */ class IdentityAwareProxyInvocationHandler extends ContextProxyInvocationHandler { private final transient SecurityIdentity securityIdentity; /** * @param contextService * @param proxiedObject * @param executionProperties */ IdentityAwareProxyInvocationHandler(ContextServiceImpl contextService, Object proxiedObject, Map<String, String> executionProperties) { super(contextService, proxiedObject, executionProperties); SecurityDomain securityDomain = SecurityDomain.getCurrent(); securityIdentity = securityDomain != null ? securityDomain.getCurrentSecurityIdentity() : null; } @Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { if (securityIdentity != null) { try { return securityIdentity.runAs((PrivilegedExceptionAction<Object>) (() -> { try { return super.invoke(proxy, method, args); } catch (Throwable e) { throw new WrapperException(e); } })); } catch (PrivilegedActionException e) { Throwable cause = e.getCause(); throw cause instanceof WrapperException ? cause.getCause() : cause; } } else { return super.invoke(proxy, method, args); } } private static class WrapperException extends Exception { /** * @param cause */ WrapperException(Throwable cause) { super(cause); } } }
2,933
34.349398
139
java
null
wildfly-main/ee/src/main/java/org/jboss/as/ee/concurrent/SecurityIdentityUtils.java
/* * JBoss, Home of Professional Open Source. * Copyright 2017 Red Hat, Inc., and individual contributors * as indicated by the @author tags. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.jboss.as.ee.concurrent; import java.security.AccessController; import java.security.PrivilegedAction; import java.util.Map; import java.util.concurrent.Callable; import java.util.concurrent.Future; import jakarta.enterprise.concurrent.ManagedExecutorService; import jakarta.enterprise.concurrent.ManagedTask; import jakarta.enterprise.concurrent.ManagedTaskListener; import org.wildfly.security.auth.server.SecurityDomain; import org.wildfly.security.auth.server.SecurityIdentity; /** * Utilities for capturing the current SecurityIdentity and wrapping tasks. * * @author <a href="mailto:[email protected]">Darran Lofthouse</a> */ class SecurityIdentityUtils { private SecurityIdentityUtils() { } static <T> Callable<T> doIdentityWrap(final Callable<T> callable) { if(callable == null) { return null; } final SecurityIdentity securityIdentity = getSecurityIdentity(); if(securityIdentity == null) { return callable; } Callable<T> securedCallable = () -> securityIdentity.runAs(callable); return callable instanceof ManagedTask ? new SecuredManagedCallable<T>(securedCallable, (ManagedTask) callable) : securedCallable; } static Runnable doIdentityWrap(final Runnable runnable) { if(runnable == null) { return null; } final SecurityIdentity securityIdentity = getSecurityIdentity(); if(securityIdentity == null) { return runnable; } Runnable securedRunnable = () -> securityIdentity.runAs(runnable); return runnable instanceof ManagedTask ? new SecuredManagedRunnable(securedRunnable, (ManagedTask) runnable) : securedRunnable; } private static SecurityIdentity getSecurityIdentity() { final SecurityManager sm = System.getSecurityManager(); final SecurityDomain securityDomain; if (sm != null) { securityDomain = AccessController.doPrivileged((PrivilegedAction<SecurityDomain>) () -> SecurityDomain.getCurrent()); } else { securityDomain = SecurityDomain.getCurrent(); } return securityDomain != null ? securityDomain.getCurrentSecurityIdentity() : null; } /** * A managed Secured task. */ static class SecuredManagedTask implements ManagedTask { private final ManagedTask managedTask; private final SecurityIdentityUtils.SecuredManagedTaskListener managedTaskListenerWrapper; SecuredManagedTask(ManagedTask managedTask) { this.managedTask = managedTask; this.managedTaskListenerWrapper = managedTask.getManagedTaskListener() != null ? new SecurityIdentityUtils.SecuredManagedTaskListener(managedTask.getManagedTaskListener()) : null; } @Override public Map<String, String> getExecutionProperties() { return managedTask.getExecutionProperties(); } @Override public ManagedTaskListener getManagedTaskListener() { return managedTaskListenerWrapper; } } /** * A managed Secured task which is a runnable. * */ static class SecuredManagedRunnable extends SecurityIdentityUtils.SecuredManagedTask implements Runnable { private final Runnable runnable; SecuredManagedRunnable(Runnable SecuredTask, ManagedTask managedTask) { super(managedTask); this.runnable = SecuredTask; } @Override public void run() { runnable.run(); } } /** * A managed Secured task which is a callable. * */ static class SecuredManagedCallable<T> extends SecurityIdentityUtils.SecuredManagedTask implements Callable<T> { private final Callable<T> runnable; SecuredManagedCallable(Callable<T> SecuredTask, ManagedTask managedTask) { super(managedTask); this.runnable = SecuredTask; } @Override public T call() throws Exception { return runnable.call(); } } /** * A managed task listener for managed Secured tasks. */ static class SecuredManagedTaskListener implements ManagedTaskListener { private final ManagedTaskListener managedTaskListener; SecuredManagedTaskListener(ManagedTaskListener managedTaskListener) { this.managedTaskListener = managedTaskListener; } @Override public void taskAborted(Future<?> future, ManagedExecutorService executor, Object task, Throwable exception) { managedTaskListener.taskAborted(future, executor, ((SecurityIdentityUtils.SecuredManagedTask)task).managedTask, exception); } @Override public void taskDone(Future<?> future, ManagedExecutorService executor, Object task, Throwable exception) { managedTaskListener.taskDone(future, executor, ((SecurityIdentityUtils.SecuredManagedTask) task).managedTask, exception); } @Override public void taskStarting(Future<?> future, ManagedExecutorService executor, Object task) { managedTaskListener.taskStarting(future, executor, ((SecurityIdentityUtils.SecuredManagedTask) task).managedTask); } @Override public void taskSubmitted(Future<?> future, ManagedExecutorService executor, Object task) { managedTaskListener.taskSubmitted(future, executor, ((SecurityIdentityUtils.SecuredManagedTask) task).managedTask); } } }
6,259
35.395349
191
java
null
wildfly-main/ee/src/main/java/org/jboss/as/ee/concurrent/ManagedExecutorRuntimeStatsImpl.java
/* * JBoss, Home of Professional Open Source. * Copyright 2019 Red Hat, Inc., and individual contributors * as indicated by the @author tags. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.jboss.as.ee.concurrent; import org.glassfish.enterprise.concurrent.AbstractManagedExecutorService; import java.util.Collection; import java.util.concurrent.ThreadPoolExecutor; /** * Executor runtime stats obtained from a thread pool executor. * @author emmartins */ class ManagedExecutorRuntimeStatsImpl implements ManagedExecutorRuntimeStats { private final AbstractManagedExecutorService abstractManagedExecutorService; private final ThreadPoolExecutor threadPoolExecutor; ManagedExecutorRuntimeStatsImpl(ManagedExecutorServiceImpl executorService) { this.abstractManagedExecutorService = executorService; this.threadPoolExecutor = executorService.getThreadPoolExecutor(); } ManagedExecutorRuntimeStatsImpl(ManagedScheduledExecutorServiceImpl executorService) { this.abstractManagedExecutorService = executorService; this.threadPoolExecutor = executorService.getThreadPoolExecutor(); } @Override public int getThreadsCount() { return threadPoolExecutor.getPoolSize(); } @Override public int getActiveThreadsCount() { return threadPoolExecutor.getActiveCount(); } @Override public int getMaxThreadsCount() { return threadPoolExecutor.getLargestPoolSize(); } @Override public int getHungThreadsCount() { final Collection hungThreads = abstractManagedExecutorService.getHungThreads(); return hungThreads != null ? hungThreads.size() : 0; } @Override public long getTaskCount() { return threadPoolExecutor.getTaskCount(); } @Override public long getCompletedTaskCount() { return threadPoolExecutor.getCompletedTaskCount(); } @Override public int getQueueSize() { return threadPoolExecutor.getQueue().size(); } }
2,549
30.875
90
java
null
wildfly-main/ee/src/main/java/org/jboss/as/ee/concurrent/service/EEConcurrentAbstractService.java
/* * 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.jboss.as.ee.concurrent.service; import org.jboss.as.naming.ImmediateManagedReferenceFactory; import org.jboss.as.naming.ServiceBasedNamingStore; import org.jboss.as.naming.deployment.ContextNames; import org.jboss.as.naming.service.BinderService; import org.jboss.msc.service.Service; import org.jboss.msc.service.StartContext; import org.jboss.msc.service.StartException; import org.jboss.msc.service.StopContext; /** * Abstract service responsible for managing the lifecyle of EE Concurrent managed resources. * * @author Eduardo Martins */ abstract class EEConcurrentAbstractService<T> implements Service<T> { private final String jndiName; /** * * @param jndiName */ EEConcurrentAbstractService(String jndiName) { this.jndiName = jndiName; } public void start(final StartContext context) throws StartException { startValue(context); // every ee concurrent resource is bound to jndi, so EE components may reference it. bindValueToJndi(context); } /** * Starts the service's value. * @param context * @throws StartException */ abstract void startValue(final StartContext context) throws StartException; private void bindValueToJndi(final StartContext context) { final ContextNames.BindInfo bindInfo = ContextNames.bindInfoFor(jndiName); final BinderService binderService = new BinderService(bindInfo.getBindName()); binderService.getManagedObjectInjector().inject(new ImmediateManagedReferenceFactory(getValue())); context.getChildTarget().addService(bindInfo.getBinderServiceName(),binderService) .addDependency(bindInfo.getParentContextServiceName(), ServiceBasedNamingStore.class, binderService.getNamingStoreInjector()) .install(); } public void stop(final StopContext context) { stopValue(context); } /** * Stops the service's value. * @param context */ abstract void stopValue(final StopContext context); }
3,075
35.619048
141
java
null
wildfly-main/ee/src/main/java/org/jboss/as/ee/concurrent/service/DelegatingSupplier.java
/* * JBoss, Home of Professional Open Source. * Copyright 2023, 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.jboss.as.ee.concurrent.service; import java.util.function.Supplier; /** * A supplier which delegates to other supplier if it is configured. * @param <T> the type of objects that may be supplied by this supplier. * * @author <a href="mailto:[email protected]">Richard Opalka</a> */ public final class DelegatingSupplier<T> implements Supplier<T> { private volatile Supplier<T> delegate; /** * Gets delegating supplier value or <code>null</code> if supplier is not configured. * * @return delegating supplier value */ @Override public T get() { final Supplier<T> delegate = this.delegate; return delegate != null ? delegate.get() : null; } /** * Sets supplier to delegate to. * * @param delegate supplier to delegate to */ public void set(final Supplier<T> delegate) { this.delegate = delegate; } }
1,941
32.482759
89
java
null
wildfly-main/ee/src/main/java/org/jboss/as/ee/concurrent/service/ConcurrentServiceNames.java
/* * 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.jboss.as.ee.concurrent.service; import org.jboss.as.ee.subsystem.ContextServiceResourceDefinition; import org.jboss.as.ee.subsystem.ManagedExecutorServiceResourceDefinition; import org.jboss.as.ee.subsystem.ManagedScheduledExecutorServiceResourceDefinition; import org.jboss.as.ee.subsystem.ManagedThreadFactoryResourceDefinition; import org.jboss.msc.service.ServiceName; /** * MSC service names for EE's concurrent resources. * * @author Eduardo Martins */ public class ConcurrentServiceNames { private ConcurrentServiceNames() { } public static final ServiceName BASE_SERVICE_NAME = ServiceName.JBOSS.append("concurrent", "ee"); private static final ServiceName CONTEXT_BASE_SERVICE_NAME = BASE_SERVICE_NAME.append("context"); public static final ServiceName CONCURRENT_CONTEXT_BASE_SERVICE_NAME = CONTEXT_BASE_SERVICE_NAME.append("config"); public static final ServiceName HUNG_TASK_PERIODIC_TERMINATION_SERVICE_NAME = BASE_SERVICE_NAME.append("hung-task-periodic-termination"); /** * * @param name * @return * @deprecated Use "org.wildfly.ee.concurrent.context.service" dynamic capability's service name instead. */ @Deprecated public static ServiceName getContextServiceServiceName(String name) { return ContextServiceResourceDefinition.CAPABILITY.getCapabilityServiceName(name); } /** * * @param name * @return * @deprecated Use "org.wildfly.ee.concurrent.thread-factory" dynamic capability's service name instead. */ @Deprecated public static ServiceName getManagedThreadFactoryServiceName(String name) { return ManagedThreadFactoryResourceDefinition.CAPABILITY.getCapabilityServiceName(name); } /** * * @param name * @return * @deprecated Use "org.wildfly.ee.concurrent.executor" dynamic capability's service name instead. */ @Deprecated public static ServiceName getManagedExecutorServiceServiceName(String name) { return ManagedExecutorServiceResourceDefinition.CAPABILITY.getCapabilityServiceName(name); } /** * * @param name * @return * @deprecated Use "org.wildfly.ee.concurrent.scheduled-executor" dynamic capability's service name instead. */ @Deprecated public static ServiceName getManagedScheduledExecutorServiceServiceName(String name) { return ManagedScheduledExecutorServiceResourceDefinition.CAPABILITY.getCapabilityServiceName(name); } public static ServiceName getConcurrentContextServiceName(String app, String module, String component) { final ServiceName moduleServiceName = CONCURRENT_CONTEXT_BASE_SERVICE_NAME.append(app).append(module); if(component == null) { return moduleServiceName; } else { return moduleServiceName.append(component); } } }
3,913
37.372549
141
java
null
wildfly-main/ee/src/main/java/org/jboss/as/ee/concurrent/service/ManagedThreadFactoryService.java
/* * JBoss, Home of Professional Open Source. * Copyright 2010, 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.jboss.as.ee.concurrent.service; import java.util.function.Consumer; import java.util.function.Supplier; import org.glassfish.enterprise.concurrent.ContextServiceImpl; import org.jboss.as.ee.concurrent.ManagedThreadFactoryImpl; import org.jboss.as.ee.logging.EeLogger; import org.jboss.msc.service.StartContext; import org.jboss.msc.service.StartException; import org.jboss.msc.service.StopContext; /** * @author Eduardo Martins */ public class ManagedThreadFactoryService extends EEConcurrentAbstractService<ManagedThreadFactoryImpl> { private volatile ManagedThreadFactoryImpl managedThreadFactory; private final Consumer<ManagedThreadFactoryImpl> consumer; private final String name; private final DelegatingSupplier<ContextServiceImpl> contextServiceSupplier = new DelegatingSupplier<>(); private final int priority; /** * @param name * @param jndiName * @param priority * @see org.jboss.as.ee.concurrent.ManagedThreadFactoryImpl#ManagedThreadFactoryImpl(String, org.glassfish.enterprise.concurrent.ContextServiceImpl, int) */ public ManagedThreadFactoryService(final Consumer<ManagedThreadFactoryImpl> consumer, final Supplier<ContextServiceImpl> ctxServiceSupplier, String name, String jndiName, int priority) { super(jndiName); this.consumer = consumer; this.name = name; this.contextServiceSupplier.set(ctxServiceSupplier); this.priority = priority; } @Override void startValue(StartContext context) throws StartException { final String threadFactoryName = "EE-ManagedThreadFactory-"+name; consumer.accept(managedThreadFactory = new ManagedThreadFactoryImpl(threadFactoryName, contextServiceSupplier.get(), priority)); } @Override void stopValue(StopContext context) { managedThreadFactory.stop(); consumer.accept(managedThreadFactory = null); } public ManagedThreadFactoryImpl getValue() throws IllegalStateException { if (this.managedThreadFactory == null) { throw EeLogger.ROOT_LOGGER.concurrentServiceValueUninitialized(); } return managedThreadFactory; } public DelegatingSupplier<ContextServiceImpl> getContextServiceSupplier() { return contextServiceSupplier; } }
3,338
39.228916
190
java