use of org.jboss.modules.ModuleIdentifier in project wildfly by wildfly.
the class JaxrsIntegrationProcessor method deploy.
@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
if (!JaxrsDeploymentMarker.isJaxrsDeployment(deploymentUnit)) {
return;
}
if (!DeploymentTypeMarker.isType(DeploymentType.WAR, deploymentUnit)) {
return;
}
final DeploymentUnit parent = deploymentUnit.getParent() == null ? deploymentUnit : deploymentUnit.getParent();
final WarMetaData warMetaData = deploymentUnit.getAttachment(WarMetaData.ATTACHMENT_KEY);
final JBossWebMetaData webdata = warMetaData.getMergedJBossWebMetaData();
final ResteasyDeploymentData resteasy = deploymentUnit.getAttachment(JaxrsAttachments.RESTEASY_DEPLOYMENT_DATA);
if (resteasy == null)
return;
deploymentUnit.getDeploymentSubsystemModel(JaxrsExtension.SUBSYSTEM_NAME);
//remove the resteasy.scan parameter
//because it is not needed
final List<ParamValueMetaData> params = webdata.getContextParams();
boolean entityExpandEnabled = false;
if (params != null) {
Iterator<ParamValueMetaData> it = params.iterator();
while (it.hasNext()) {
final ParamValueMetaData param = it.next();
if (param.getParamName().equals(RESTEASY_SCAN)) {
it.remove();
} else if (param.getParamName().equals(RESTEASY_SCAN_RESOURCES)) {
it.remove();
} else if (param.getParamName().equals(RESTEASY_SCAN_PROVIDERS)) {
it.remove();
} else if (param.getParamName().equals(ResteasyContextParameters.RESTEASY_EXPAND_ENTITY_REFERENCES)) {
entityExpandEnabled = true;
}
}
}
//don't expand entity references by default
if (!entityExpandEnabled) {
setContextParameter(webdata, ResteasyContextParameters.RESTEASY_EXPAND_ENTITY_REFERENCES, "false");
}
final Map<ModuleIdentifier, ResteasyDeploymentData> attachmentMap = parent.getAttachment(JaxrsAttachments.ADDITIONAL_RESTEASY_DEPLOYMENT_DATA);
final List<ResteasyDeploymentData> additionalData = new ArrayList<ResteasyDeploymentData>();
final ModuleSpecification moduleSpec = deploymentUnit.getAttachment(Attachments.MODULE_SPECIFICATION);
if (moduleSpec != null && attachmentMap != null) {
final Set<ModuleIdentifier> identifiers = new HashSet<ModuleIdentifier>();
for (ModuleDependency dep : moduleSpec.getAllDependencies()) {
//make sure we don't double up
if (!identifiers.contains(dep.getIdentifier())) {
identifiers.add(dep.getIdentifier());
if (attachmentMap.containsKey(dep.getIdentifier())) {
additionalData.add(attachmentMap.get(dep.getIdentifier()));
}
}
}
resteasy.merge(additionalData);
}
if (!resteasy.getScannedResourceClasses().isEmpty()) {
StringBuffer buf = null;
for (String resource : resteasy.getScannedResourceClasses()) {
if (buf == null) {
buf = new StringBuffer();
buf.append(resource);
} else {
buf.append(",").append(resource);
}
}
String resources = buf.toString();
JAXRS_LOGGER.debugf("Adding JAX-RS resource classes: %s", resources);
setContextParameter(webdata, ResteasyContextParameters.RESTEASY_SCANNED_RESOURCES, resources);
}
if (!resteasy.getScannedProviderClasses().isEmpty()) {
StringBuffer buf = null;
for (String provider : resteasy.getScannedProviderClasses()) {
if (buf == null) {
buf = new StringBuffer();
buf.append(provider);
} else {
buf.append(",").append(provider);
}
}
String providers = buf.toString();
JAXRS_LOGGER.debugf("Adding JAX-RS provider classes: %s", providers);
setContextParameter(webdata, ResteasyContextParameters.RESTEASY_SCANNED_PROVIDERS, providers);
}
if (!resteasy.getScannedJndiComponentResources().isEmpty()) {
StringBuffer buf = null;
for (String resource : resteasy.getScannedJndiComponentResources()) {
if (buf == null) {
buf = new StringBuffer();
buf.append(resource);
} else {
buf.append(",").append(resource);
}
}
String providers = buf.toString();
JAXRS_LOGGER.debugf("Adding JAX-RS jndi component resource classes: %s", providers);
setContextParameter(webdata, ResteasyContextParameters.RESTEASY_SCANNED_JNDI_RESOURCES, providers);
}
if (!resteasy.isUnwrappedExceptionsParameterSet()) {
setContextParameter(webdata, ResteasyContextParameters.RESTEASY_UNWRAPPED_EXCEPTIONS, "javax.ejb.EJBException");
}
if (resteasy.hasBootClasses() || resteasy.isDispatcherCreated())
return;
// ignore any non-annotated Application class that doesn't have a servlet mapping
Set<Class<? extends Application>> applicationClassSet = new HashSet<>();
for (Class<? extends Application> clazz : resteasy.getScannedApplicationClasses()) {
if (clazz.isAnnotationPresent(ApplicationPath.class) || servletMappingsExist(webdata, clazz.getName())) {
applicationClassSet.add(clazz);
}
}
// add default servlet
if (applicationClassSet.size() == 0) {
JBossServletMetaData servlet = new JBossServletMetaData();
servlet.setName(JAX_RS_SERVLET_NAME);
servlet.setServletClass(HttpServlet30Dispatcher.class.getName());
servlet.setAsyncSupported(true);
addServlet(webdata, servlet);
setServletMappingPrefix(webdata, JAX_RS_SERVLET_NAME, servlet);
} else {
for (Class<? extends Application> applicationClass : applicationClassSet) {
String servletName = null;
servletName = applicationClass.getName();
JBossServletMetaData servlet = new JBossServletMetaData();
// must load on startup for services like JSAPI to work
servlet.setLoadOnStartup("" + 0);
servlet.setName(servletName);
servlet.setServletClass(HttpServlet30Dispatcher.class.getName());
servlet.setAsyncSupported(true);
setServletInitParam(servlet, SERVLET_INIT_PARAM, applicationClass.getName());
addServlet(webdata, servlet);
if (!servletMappingsExist(webdata, servletName)) {
try {
//no mappings, add our own
List<String> patterns = new ArrayList<String>();
//for some reason the spec requires this to be decoded
String pathValue = URLDecoder.decode(applicationClass.getAnnotation(ApplicationPath.class).value().trim(), "UTF-8");
if (!pathValue.startsWith("/")) {
pathValue = "/" + pathValue;
}
String prefix = pathValue;
if (pathValue.endsWith("/")) {
pathValue += "*";
} else {
pathValue += "/*";
}
patterns.add(pathValue);
setServletInitParam(servlet, "resteasy.servlet.mapping.prefix", prefix);
ServletMappingMetaData mapping = new ServletMappingMetaData();
mapping.setServletName(servletName);
mapping.setUrlPatterns(patterns);
if (webdata.getServletMappings() == null) {
webdata.setServletMappings(new ArrayList<ServletMappingMetaData>());
}
webdata.getServletMappings().add(mapping);
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
}
} else {
setServletMappingPrefix(webdata, servletName, servlet);
}
}
}
if (webdata.getServletMappings() == null || webdata.getServletMappings().isEmpty()) {
JAXRS_LOGGER.noServletDeclaration(deploymentUnit.getName());
}
}
use of org.jboss.modules.ModuleIdentifier in project wildfly by wildfly.
the class JSFDependencyProcessor method addJSFAPI.
private void addJSFAPI(String jsfVersion, ModuleSpecification moduleSpecification, ModuleLoader moduleLoader) throws DeploymentUnitProcessingException {
if (jsfVersion.equals(JsfVersionMarker.WAR_BUNDLES_JSF_IMPL))
return;
ModuleIdentifier jsfModule = moduleIdFactory.getApiModId(jsfVersion);
ModuleDependency jsfAPI = new ModuleDependency(moduleLoader, jsfModule, false, false, false, false);
moduleSpecification.addSystemDependency(jsfAPI);
}
use of org.jboss.modules.ModuleIdentifier in project wildfly by wildfly.
the class WSDependenciesProcessor method deploy.
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 (ModuleIdentifier api : JAVAEE_APIS) {
moduleSpec.addSystemDependency(new ModuleDependency(moduleLoader, api, false, false, true, false));
}
}
use of org.jboss.modules.ModuleIdentifier in project wildfly by wildfly.
the class ApplicationClientDependencyProcessor method deploy.
@Override
public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
final ModuleSpecification moduleSpecification = deploymentUnit.getAttachment(Attachments.MODULE_SPECIFICATION);
final ModuleLoader loader = deploymentUnit.getAttachment(Attachments.SERVICE_MODULE_LOADER);
moduleSpecification.addSystemDependency(new ModuleDependency(loader, CORBA_ID, false, true, true, false));
moduleSpecification.addSystemDependency(new ModuleDependency(loader, XNIO, false, true, true, false));
final Set<ModuleIdentifier> moduleIdentifiers = new HashSet<ModuleIdentifier>();
final DeploymentUnit top = deploymentUnit.getParent() == null ? deploymentUnit : deploymentUnit.getParent();
moduleIdentifiers.add(top.getAttachment(Attachments.MODULE_IDENTIFIER));
for (final DeploymentUnit module : top.getAttachmentList(Attachments.SUB_DEPLOYMENTS)) {
moduleIdentifiers.add(module.getAttachment(Attachments.MODULE_IDENTIFIER));
}
final ListIterator<ModuleDependency> iterator = moduleSpecification.getMutableUserDependencies().listIterator();
while (iterator.hasNext()) {
final ModuleDependency dep = iterator.next();
final ModuleIdentifier identifier = dep.getIdentifier();
if (identifier.getName().startsWith(ServiceModuleLoader.MODULE_PREFIX) && !identifier.getName().startsWith(ExtensionIndexService.MODULE_PREFIX)) {
if (!moduleIdentifiers.contains(identifier)) {
iterator.remove();
}
}
}
}
use of org.jboss.modules.ModuleIdentifier in project wildfly by wildfly.
the class JdbcDriverAdd method performRuntime.
protected void performRuntime(OperationContext context, ModelNode operation, ModelNode model) throws OperationFailedException {
final ModelNode address = operation.require(OP_ADDR);
final String driverName = PathAddress.pathAddress(address).getLastElement().getValue();
if (operation.get(DRIVER_NAME.getName()).isDefined() && !driverName.equals(operation.get(DRIVER_NAME.getName()).asString())) {
throw ConnectorLogger.ROOT_LOGGER.driverNameAndResourceNameNotEquals(operation.get(DRIVER_NAME.getName()).asString(), driverName);
}
String moduleName = DRIVER_MODULE_NAME.resolveModelAttribute(context, model).asString();
final Integer majorVersion = model.hasDefined(DRIVER_MAJOR_VERSION.getName()) ? DRIVER_MAJOR_VERSION.resolveModelAttribute(context, model).asInt() : null;
final Integer minorVersion = model.hasDefined(DRIVER_MINOR_VERSION.getName()) ? DRIVER_MINOR_VERSION.resolveModelAttribute(context, model).asInt() : null;
final String driverClassName = model.hasDefined(DRIVER_CLASS_NAME.getName()) ? DRIVER_CLASS_NAME.resolveModelAttribute(context, model).asString() : null;
final String dataSourceClassName = model.hasDefined(DRIVER_DATASOURCE_CLASS_NAME.getName()) ? DRIVER_DATASOURCE_CLASS_NAME.resolveModelAttribute(context, model).asString() : null;
final String xaDataSourceClassName = model.hasDefined(DRIVER_XA_DATASOURCE_CLASS_NAME.getName()) ? DRIVER_XA_DATASOURCE_CLASS_NAME.resolveModelAttribute(context, model).asString() : null;
final ServiceTarget target = context.getServiceTarget();
final ModuleIdentifier moduleId;
final Module module;
String slot = model.hasDefined(MODULE_SLOT.getName()) ? MODULE_SLOT.resolveModelAttribute(context, model).asString() : null;
try {
moduleId = ModuleIdentifier.create(moduleName, slot);
module = Module.getCallerModuleLoader().loadModule(moduleId);
} catch (ModuleLoadException e) {
throw new OperationFailedException(ConnectorLogger.ROOT_LOGGER.failedToLoadModuleDriver(moduleName), e);
}
if (driverClassName == null) {
final ServiceLoader<Driver> serviceLoader = module.loadService(Driver.class);
boolean driverLoaded = false;
if (serviceLoader != null) {
for (Driver driver : serviceLoader) {
startDriverServices(target, moduleId, driver, driverName, majorVersion, minorVersion, dataSourceClassName, xaDataSourceClassName);
driverLoaded = true;
// w/ explicit declaration of driver-class attribute
break;
}
}
if (!driverLoaded)
SUBSYSTEM_DATASOURCES_LOGGER.cannotFindDriverClassName(driverName);
} else {
try {
final Class<? extends Driver> driverClass = module.getClassLoader().loadClass(driverClassName).asSubclass(Driver.class);
final Constructor<? extends Driver> constructor = driverClass.getConstructor();
final Driver driver = constructor.newInstance();
startDriverServices(target, moduleId, driver, driverName, majorVersion, minorVersion, dataSourceClassName, xaDataSourceClassName);
} catch (Exception e) {
SUBSYSTEM_DATASOURCES_LOGGER.cannotInstantiateDriverClass(driverClassName, e);
throw new OperationFailedException(ConnectorLogger.ROOT_LOGGER.cannotInstantiateDriverClass(driverClassName));
}
}
}
Aggregations