Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* IronJacamar, a Java EE Connector Architecture implementation
* Copyright 2008-2020, 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.jca.deployers.common;
import org.jboss.jca.common.api.metadata.Defaults;
import org.jboss.jca.common.api.metadata.common.Credential;
import org.jboss.jca.common.api.metadata.common.FlushStrategy;
import org.jboss.jca.common.api.metadata.common.Recovery;
import org.jboss.jca.common.api.metadata.common.Security;
import org.jboss.jca.common.api.metadata.common.SecurityMetadata;
import org.jboss.jca.common.api.metadata.common.TimeOut;
import org.jboss.jca.common.api.metadata.common.TransactionSupportEnum;
import org.jboss.jca.common.api.metadata.common.Validation;
import org.jboss.jca.common.api.metadata.common.XaPool;
import org.jboss.jca.common.api.metadata.resourceadapter.Activation;
import org.jboss.jca.common.api.metadata.resourceadapter.ConnectionDefinition;
import org.jboss.jca.common.api.metadata.resourceadapter.WorkManagerSecurity;
import org.jboss.jca.common.api.metadata.spec.ConfigProperty;
import org.jboss.jca.common.api.metadata.spec.Connector;
import org.jboss.jca.common.api.metadata.spec.Connector.Version;
import org.jboss.jca.common.api.metadata.spec.MessageListener;
import org.jboss.jca.common.api.metadata.spec.XsdString;
import org.jboss.jca.common.metadata.spec.ConfigPropertyImpl;
import org.jboss.jca.core.api.bootstrap.CloneableBootstrapContext;
import org.jboss.jca.core.api.connectionmanager.ccm.CachedConnectionManager;
import org.jboss.jca.core.api.connectionmanager.pool.PoolConfiguration;
import org.jboss.jca.core.bootstrapcontext.BootstrapContextCoordinator;
import org.jboss.jca.core.connectionmanager.ConnectionManager;
import org.jboss.jca.core.connectionmanager.ConnectionManagerFactory;
import org.jboss.jca.core.connectionmanager.pool.api.PoolFactory;
import org.jboss.jca.core.connectionmanager.pool.api.PoolStrategy;
import org.jboss.jca.core.connectionmanager.pool.api.PrefillPool;
import org.jboss.jca.core.connectionmanager.pool.capacity.CapacityFactory;
import org.jboss.jca.core.connectionmanager.pool.mcp.ManagedConnectionPoolFactory;
import org.jboss.jca.core.recovery.DefaultRecoveryPlugin;
import org.jboss.jca.core.security.CallbackImpl;
import org.jboss.jca.core.spi.recovery.RecoveryPlugin;
import org.jboss.jca.core.spi.security.Callback;
import org.jboss.jca.core.spi.security.SubjectFactory;
import org.jboss.jca.core.spi.transaction.TransactionIntegration;
import org.jboss.jca.core.spi.transaction.XAResourceStatistics;
import org.jboss.jca.core.spi.transaction.recovery.XAResourceRecovery;
import org.jboss.jca.core.util.Injection;
import org.jboss.jca.deployers.DeployersBundle;
import org.jboss.jca.deployers.DeployersLogger;
import org.jboss.jca.validator.Failure;
import org.jboss.jca.validator.FailureHelper;
import org.jboss.jca.validator.Key;
import org.jboss.jca.validator.Severity;
import org.jboss.jca.validator.Validate;
import org.jboss.jca.validator.ValidateClass;
import org.jboss.jca.validator.ValidateObject;
import org.jboss.jca.validator.Validator;
import org.jboss.jca.validator.ValidatorException;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.Serializable;
import java.lang.reflect.Proxy;
import java.net.URL;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Enumeration;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import java.util.regex.Pattern;
import jakarta.resource.ResourceException;
import jakarta.resource.spi.ActivationSpec;
import jakarta.resource.spi.ManagedConnectionFactory;
import jakarta.resource.spi.ResourceAdapterAssociation;
import jakarta.resource.spi.TransactionSupport;
import jakarta.resource.spi.TransactionSupport.TransactionSupportLevel;
import jakarta.resource.spi.ValidatingManagedConnectionFactory;
import jakarta.resource.spi.security.PasswordCredential;
import jakarta.resource.spi.work.WorkContext;
import javax.security.auth.Subject;
import jakarta.transaction.TransactionManager;
import org.jboss.logging.Messages;
/**
* An abstract resource adapter deployer which contains common functionality
* for all resource adapter archive based deployers.
* @author Jesper Pedersen
*/
public abstract class AbstractResourceAdapterDeployer
{
/** The bundle */
private static DeployersBundle bundle = Messages.getBundle(DeployersBundle.class);
/** the logger **/
protected final DeployersLogger log;
/** boolean to set if validation is needed at class level or it should be considered already valid
* (IOW object put in repository at previous steps have been already validated at class level**/
protected final boolean validateClasses;
/** The configuration */
private Configuration configuration = null;
/**
* Create a new AbstractResourceAdapterDeployer.
*
* @param validateClasses validateClasses validateClasses boolean to express if this instance will
* apply validation on classes structure
*/
public AbstractResourceAdapterDeployer(boolean validateClasses)
{
super();
this.log = getLogger();
this.validateClasses = validateClasses;
}
/**
* Set the configuration
* @param value value value The value
*/
public void setConfiguration(Configuration value)
{
configuration = value;
}
/**
* Get the configuration
* @return The value
*/
public Configuration getConfiguration()
{
return configuration;
}
/**
* validate archive
*
* @param url url url of the archive
* @param archiveValidation archiveValidation archiveValidation classes and/or to validate.
* @param failures failures failures original list of failures
* @return The list of failures gotten with all new failures added. Null in case of no failures
* or if validation is not run according to {@link Configuration#getArchiveValidation()} Setting. It returns null
* also if the concrete implementation of this class set validateClasses instance variable to flase and the list of
* archiveValidation contains one or more instance of {@link ValidateClass} type
*/
public Set validateArchive(URL url, List archiveValidation, Set failures)
{
// Archive validation
if (!getConfiguration().getArchiveValidation())
{
return null;
}
for (Validate validate : archiveValidation)
{
if (!(validate instanceof ValidateObject) && !this.validateClasses)
return null;
}
Validator validator = new Validator();
List partialFailures = validator.validate(archiveValidation);
if (partialFailures != null)
{
if (failures == null)
{
failures = new HashSet();
}
failures.addAll(partialFailures);
}
return failures;
}
/**
* print Failures into Log files.
*
* @param urlFileName urlFileName urlFileName filename Of deployed rar
* @param validator validator validator validator instance used to run validation rules
* @param failures failures failures the list of Failures to be printed
* @param reportDirectory reportDirectory reportDirectory where to put various logs
* @param fhInput fhInput fhInput optional parameter. Normally used only for test or in case of
* FailureHelper already present in context
* @return the error Text
*
*/
public String printFailuresLog(String urlFileName, Validator validator, Collection failures,
File reportDirectory, FailureHelper... fhInput)
{
String errorText = "";
FailureHelper fh = null;
if (fhInput.length == 0)
fh = new FailureHelper(failures);
else
fh = fhInput[0];
if (failures != null && failures.size() > 0)
{
if (reportDirectory == null)
{
reportDirectory = getReportDirectory();
}
if (reportDirectory != null && reportDirectory.exists())
{
int lastSlashIndex = urlFileName.lastIndexOf("/");
int lastSepaIndex = urlFileName.lastIndexOf(File.separator);
int lastIndex = lastSlashIndex > lastSepaIndex ? lastSlashIndex : lastSepaIndex;
if (lastIndex != -1)
urlFileName = urlFileName.substring(lastIndex + 1);
urlFileName += ".log";
File report = new File(reportDirectory, urlFileName);
FileWriter fw = null;
BufferedWriter bw = null;
try
{
fw = new FileWriter(report);
bw = new BufferedWriter(fw, 8192);
bw.write(fh.asText(validator.getResourceBundle()));
bw.flush();
errorText = "Validation failures - see: " + report.getAbsolutePath();
}
catch (IOException ioe)
{
log.validationReportFailure(ioe.getMessage(), ioe);
}
finally
{
if (bw != null)
{
try
{
bw.close();
}
catch (IOException ignore)
{
// Ignore
}
}
if (fw != null)
{
try
{
fw.close();
}
catch (IOException ignore)
{
// Ignore
}
}
}
}
else
{
errorText = fh.asText(validator.getResourceBundle());
}
}
return errorText;
}
/**
* Cehck for failures at a certain level
* @param failures failures failures The failures
* @param severity severity severity The level
* @return True if a failure is found with the specified severity; otherwise false
*/
protected boolean hasFailuresLevel(Collection failures, int severity)
{
if (failures != null)
{
for (Failure failure : failures)
{
if (failure.getSeverity() == severity)
{
return true;
}
}
}
return false;
}
/**
* Start the resource adapter
* @param resourceAdapter The resource adapter
* @param bootstrapContextIdentifier The bootstrap context identifier
* @param bootstrapContextName The bootstrap context name; may be null
* @param cb The callback
* @throws DeployException DeployException Thrown if the resource adapter cant be started
*/
@SuppressWarnings("unchecked")
protected void startContext(jakarta.resource.spi.ResourceAdapter resourceAdapter,
String bootstrapContextIdentifier, String bootstrapContextName,
Callback cb)
throws DeployException
{
try
{
CloneableBootstrapContext cbc =
BootstrapContextCoordinator.getInstance().createBootstrapContext(bootstrapContextIdentifier,
bootstrapContextName);
cbc.setResourceAdapter(resourceAdapter);
if (cb != null)
setCallbackSecurity((org.jboss.jca.core.api.workmanager.WorkManager)cbc.getWorkManager(), cb);
resourceAdapter.start(cbc);
}
catch (Throwable t)
{
throw new DeployException(bundle.unableToStartResourceAdapter(resourceAdapter.getClass().getName()), t);
}
}
/**
* Sets the call back security info in this rar work manager before starting the resource adapter.
*
* @param workManager the work manager that will be used by the resource adapter
* @param cb the security callback
*/
protected void setCallbackSecurity(org.jboss.jca.core.api.workmanager.WorkManager workManager, Callback cb)
{
workManager.setCallbackSecurity(cb);
}
/**
* Associate resource adapter with ojects if they implement ResourceAdapterAssociation
* @param resourceAdapter resourceAdapter resourceAdapter The resource adapter
* @param object object object The of possible association object
* @throws DeployException DeployException Thrown if the resource adapter cant be started
*/
@SuppressWarnings("unchecked")
protected void associateResourceAdapter(jakarta.resource.spi.ResourceAdapter resourceAdapter, Object object)
throws DeployException
{
if (resourceAdapter != null && object != null)
{
if (object instanceof ResourceAdapterAssociation)
{
try
{
ResourceAdapterAssociation raa = (ResourceAdapterAssociation)object;
raa.setResourceAdapter(resourceAdapter);
}
catch (Throwable t)
{
throw new DeployException(bundle.unableToAssociate(object.getClass().getName()), t);
}
}
}
}
/**
* Return a list of ManagedConnectionFactory classes
* @param ra The metadata
* @return The classes
*/
private Set findManagedConnectionFactories(org.jboss.jca.common.api.metadata.spec.ResourceAdapter ra)
{
Set result = new HashSet(1);
if (ra != null)
{
if (ra.getOutboundResourceadapter() != null)
{
for (org.jboss.jca.common.api.metadata.spec.ConnectionDefinition cd :
ra.getOutboundResourceadapter().getConnectionDefinitions())
{
result.add(cd.getManagedConnectionFactoryClass().getValue());
}
}
}
return result;
}
/**
* Return a list of AdminObject classes
* @param ra The metadata
* @return The classes
*/
private Set resolveAdminObjects(org.jboss.jca.common.api.metadata.spec.ResourceAdapter ra)
{
Set result = new HashSet(1);
if (ra != null)
{
if (ra.getAdminObjects() != null)
{
for (org.jboss.jca.common.api.metadata.spec.AdminObject ao : ra.getAdminObjects())
{
result.add(ao.getAdminobjectClass().getValue());
}
}
}
return result;
}
/**
* Find the metadata for a managed connection factory
* @param clz The fully quilified class name for the managed connection factory
* @param mcfs The managed connection facotries
* @param defs The connection definitions
* @param cl The class loader
* @return The metadata; null if none could be found
* @exception DeployException Thrown in case of configuration error
*/
protected Set findConnectionDefinitions(String clz, Set mcfs,
List defs,
ClassLoader cl)
throws DeployException
{
Set result = null;
if (mcfs != null && defs != null)
{
// If there is only one we will return that
if (mcfs.size() == 1 && defs.size() == 1)
{
ConnectionDefinition cd = defs.get(0);
if (cd.getClassName() != null && !clz.equals(cd.getClassName()))
{
log.connectionDefinitionMismatch(cd.getClassName());
throw new DeployException(clz + " not a valid connection definition");
}
boolean add = true;
if (cd.getClassName() != null)
{
if (!verifyManagedConnectionFactory(cd.getClassName(), cl))
{
log.connectionDefinitionInvalid(cd.getClassName());
add = false;
}
}
if (add)
{
result = new HashSet(1);
result.add(cd);
return result;
}
}
// If there are multiple definitions the MCF class name is mandatory
if (clz == null)
throw new IllegalArgumentException(bundle.undefinedManagedConnectionFactory());
for (ConnectionDefinition cd : defs)
{
if (cd.getClassName() == null)
{
log.connectionDefinitionNull();
}
else
{
if (clz.equals(cd.getClassName()))
{
if (result == null)
result = new HashSet();
result.add(cd);
}
else
{
if (!verifyManagedConnectionFactory(cd.getClassName(), cl))
log.connectionDefinitionInvalid(cd.getClassName());
}
}
}
}
return result;
}
/**
* Verify the MCF definition
* @param clz The class name
* @param cl The class loader
* @return True if MCF, otherwise false
*/
private boolean verifyManagedConnectionFactory(String clz, ClassLoader cl)
{
if (clz != null)
{
try
{
Class> c = Class.forName(clz, true, cl);
if (ManagedConnectionFactory.class.isAssignableFrom(c))
return true;
}
catch (Throwable t)
{
// Nothing we can do
}
}
return false;
}
/**
* Verify a class definition
* @param clz The class name
* @param cl The class loader
* @return True if found, otherwise false
*/
private boolean verifyClass(String clz, ClassLoader cl)
{
if (clz != null)
{
try
{
Class> c = Class.forName(clz, true, cl);
return true;
}
catch (Throwable t)
{
// Nothing we can do
}
}
return false;
}
/**
* Verify that a class implements a certain interface
* @param interfaceClz The interface class name
* @param implClz The implementation class name
* @param cl The class loader
* @return True if correct, otherwise false
*/
private boolean verifyInstance(String interfaceClz, String implClz, ClassLoader cl)
{
if (interfaceClz != null && implClz != null)
{
try
{
Class> interfaceDef = Class.forName(interfaceClz, true, cl);
Class> implDef = Class.forName(implClz, true, cl);
return interfaceDef.isAssignableFrom(implDef);
}
catch (Throwable t)
{
// Nothing we can do
}
}
return false;
}
/**
* Find the metadata for an admin object
* @param clz The fully quilified class name for the admin object
* @param aos The admin object classes
* @param defs The admin object definitions
* @return The metadata; null if none could be found
* @exception DeployException Thrown in case of configuration error
*/
protected Set findAdminObjects(String clz,
Set aos,
List defs)
throws DeployException
{
Set result = null;
if (aos != null && defs != null)
{
// If there is only one we will return that
if (aos.size() == 1 && defs.size() == 1)
{
org.jboss.jca.common.api.metadata.resourceadapter.AdminObject cao = defs.get(0);
if (cao.getClassName() != null && !clz.equals(cao.getClassName()))
{
log.adminObjectMismatch(cao.getClassName());
throw new DeployException(clz + " not a valid admin object");
}
result = new HashSet(1);
result.add(cao);
return result;
}
// If there are multiple definitions the admin object class name is mandatory
if (clz == null)
throw new IllegalArgumentException(bundle.undefinedAdminObject());
for (org.jboss.jca.common.api.metadata.resourceadapter.AdminObject cao : defs)
{
if (cao.getClassName() == null)
{
log.adminObjectNull();
}
else
{
if (clz.equals(cao.getClassName()))
{
if (result == null)
result = new HashSet();
result.add(cao);
}
}
}
}
return result;
}
/**
* Create an instance of the pool configuration based on the input
* @param pp The pool parameters
* @param tp The timeout parameters
* @param vp The validation parameters
* @return The configuration
*/
protected PoolConfiguration createPoolConfiguration(org.jboss.jca.common.api.metadata.common.Pool pp,
TimeOut tp, Validation vp)
{
PoolConfiguration pc = new PoolConfiguration();
if (pp != null)
{
if (pp.getMinPoolSize() != null)
pc.setMinSize(pp.getMinPoolSize().intValue());
if (pp.getInitialPoolSize() != null)
pc.setInitialSize(pp.getInitialPoolSize().intValue());
if (pp.getMaxPoolSize() != null)
pc.setMaxSize(pp.getMaxPoolSize().intValue());
if (pp.isPrefill() != null)
pc.setPrefill(pp.isPrefill());
if (pp.isUseStrictMin() != null)
pc.setStrictMin(pp.isUseStrictMin());
if (pp.isFair() != null)
pc.setFair(pp.isFair());
}
if (tp != null)
{
if (tp.getBlockingTimeoutMillis() != null)
pc.setBlockingTimeout(tp.getBlockingTimeoutMillis().longValue());
if (tp.getIdleTimeoutMinutes() != null)
pc.setIdleTimeoutMinutes(tp.getIdleTimeoutMinutes().intValue());
}
if (vp != null)
{
if (vp.isValidateOnMatch() != null)
pc.setValidateOnMatch(vp.isValidateOnMatch().booleanValue());
if (vp.isBackgroundValidation() != null)
pc.setBackgroundValidation(vp.isBackgroundValidation().booleanValue());
if (vp.getBackgroundValidationMillis() != null)
pc.setBackgroundValidationMillis(vp.getBackgroundValidationMillis().intValue());
if (vp.isUseFastFail() != null)
pc.setUseFastFail(vp.isUseFastFail());
}
return pc;
}
/**
* Start
*/
public void start()
{
if (!checkConfigurationIsValid())
throw new IllegalStateException("Configuration not valid or not defined");
}
/**
* init the acrtivation spec
*
* @param cl cl
* @param cmd cmd
* @param resourceAdapter resourceAdapter
* @param archiveValidationObjects archiveValidationObjects
* @param beanValidationObjects beanValidationObjects
* @param failures falures to be updated during implemented operations
* @param url url
* @param activateDeployment activateDeployment
* @return failures updated after implemented operations
* @throws DeployException DeployException in case of error
*/
protected Set initActivationSpec(ClassLoader cl, Connector cmd,
jakarta.resource.spi.ResourceAdapter resourceAdapter,
List archiveValidationObjects,
List