Skip to content

Commit

Permalink
PAYARA-2582 … (#2520)
Browse files Browse the repository at this point in the history
* PAYARA-2582 change application to be a local variable to prevent classloader leak when validating resources

* payara-2582 Fixed messed up infinite loop
  • Loading branch information
smillidge authored and arjantijms committed Mar 27, 2018
1 parent b0d5376 commit 4ae5337
Showing 1 changed file with 23 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,6 @@ public class ResourceValidator implements EventListener, ResourceValidatorVisito

private DeploymentContext dc;

private Application application;

@Inject
private Events events;

Expand All @@ -130,7 +128,7 @@ public void postConstruct() {
public void event(Event event) {
if (event.is(Deployment.AFTER_APPLICATION_CLASSLOADER_CREATION)) {
dc = (DeploymentContext) event.hook();
application = dc.getModuleMetaData(Application.class);
Application application = dc.getModuleMetaData(Application.class);
DeployCommandParameters commandParams = dc.getCommandParameters(DeployCommandParameters.class);
target = commandParams.target;
if (System.getProperty("deployment.resource.validation", "true").equals("false")) {
Expand All @@ -142,7 +140,7 @@ public void event(Event event) {
}
AppResources appResources = new AppResources();
//Puts all resouces found in the application via annotation or xml into appResources
parseResources(appResources);
parseResources(application, appResources);

// Ensure we have a valid component invocation before triggering lookups
String componentId = null;
Expand All @@ -156,19 +154,19 @@ public void event(Event event) {
}
contextUtil.setInstanceComponentId(componentId);
try (Context ctx = contextUtil.pushContext()) {
validateResources(appResources);
validateResources(application, appResources);
}
}
}

/**
* Store all the resources before starting the validation.
*/
private void parseResources(AppResources appResources) {
parseResources(application, appResources);
private void parseResources(Application application, AppResources appResources) {
parseResourcesBd(application, appResources);
for (BundleDescriptor bd : application.getBundleDescriptors()) {
if (bd instanceof WebBundleDescriptor || bd instanceof ApplicationClientDescriptor) {
parseResources(bd, appResources);
parseResourcesBd(bd, appResources);
}
if (bd instanceof EjbBundleDescriptor) {
// Resources from Java files in the ejb.jar which are neither an EJB nor a managed bean are stored here.
Expand All @@ -183,7 +181,7 @@ private void parseResources(AppResources appResources) {
}
}

parseManagedBeans(appResources);
parseManagedBeans(application, appResources);

// Parse AppScoped resources
String appName = DOLUtils.getApplicationName(application);
Expand Down Expand Up @@ -350,15 +348,15 @@ private static String checkFullyQualifiedJndiName(String origJndiName, String fu
return returnValue;
}

private void parseManagedBeans(AppResources appResources) {
private void parseManagedBeans(Application application, AppResources appResources) {
for (BundleDescriptor bd : application.getBundleDescriptors()) {
for (ManagedBeanDescriptor managedBean : bd.getManagedBeans()) {
appResources.storeInNamespace(managedBean.getGlobalJndiName(), (JndiNameEnvironment) bd);
}
}
}

private void parseResources(BundleDescriptor bd, AppResources appResources) {
private void parseResourcesBd(BundleDescriptor bd, AppResources appResources) {
if (!(bd instanceof JndiNameEnvironment)) {
return;
}
Expand Down Expand Up @@ -502,7 +500,7 @@ else if (envProp.getMappedName().length() > 0) {
* Logic from EjbNamingReferenceManagerImpl.java - Here EJB references get
* resolved
*/
private void parseResources(EjbReferenceDescriptor ejbRef, JndiNameEnvironment env, AppResources appResources) {
private void parseResources(Application application, EjbReferenceDescriptor ejbRef, JndiNameEnvironment env, AppResources appResources) {
String name = getLogicalJNDIName(ejbRef.getName(), env);
// we only need to worry about those references which are not linked yet
if (ejbRef.getEjbDescriptor() != null) {
Expand Down Expand Up @@ -693,7 +691,7 @@ private String rawNameToLogicalJndiName(String rawName) {
*
* @return the converted name with java:global JNDI prefix.
*/
private String convertModuleOrAppJNDIName(String jndiName, JndiNameEnvironment env) {
private String convertModuleOrAppJNDIName(Application application, String jndiName, JndiNameEnvironment env) {
BundleDescriptor bd = null;
if (env instanceof EjbDescriptor) {
bd = ((EjbDescriptor) env).getEjbBundleDescriptor();
Expand Down Expand Up @@ -744,15 +742,15 @@ private String convertModuleOrAppJNDIName(String jndiName, JndiNameEnvironment e
/**
* Start of validation logic.
*/
private void validateResources(AppResources appResources) {
private void validateResources(Application application, AppResources appResources) {
for (AppResource resource : appResources.myResources) {
if (!resource.validate) {
continue;
}
if (resource.getType().equals("CFD") || resource.getType().equals("AODD")) {
validateRAName(resource);
validateRAName(application, resource);
} else {
validateJNDIRefs(resource, appResources.myNamespace);
validateJNDIRefs(application, resource, appResources.myNamespace);
}
}
// Validate the ra-names of app scoped resources
Expand All @@ -763,15 +761,15 @@ private void validateResources(AppResources appResources) {
return;
}
for (Map.Entry<String, String> entry : raNames) {
validateRAName(entry.getKey(), entry.getValue());
validateRAName(application, entry.getKey(), entry.getValue());
}
}

/**
* Validate the resource adapter names of @CFD, @AODD.
*/
private void validateRAName(AppResource resource) {
validateRAName(resource.getJndiName(), resource.getType());
private void validateRAName(Application application, AppResource resource) {
validateRAName(application, resource.getJndiName(), resource.getType());
}

/**
Expand All @@ -783,7 +781,7 @@ private void validateRAName(AppResource resource) {
*
* In case of null ra name, we fail the deployment.
*/
private void validateRAName(String raname, String type) {
private void validateRAName(Application application, String raname, String type) {
// No ra-name specified
if (raname == null || raname.length() == 0) {
deplLogger.log(Level.SEVERE, RESOURCE_REF_INVALID_RA,
Expand All @@ -804,14 +802,14 @@ private void validateRAName(String raname, String type) {
|| raname.equals("__cp_jdbc_ra") || raname.equals("__xa_jdbc_ra") || raname.equals("__dm_jdbc_ra")) {
return;
}
if (isEmbedded(raname)) {
if (isEmbedded(application, raname)) {
return;
}
} // Embedded RA
// In case the app name does not match, we fail the deployment
else if (raname.substring(0, poundIndex).equals(application.getAppName())) {
raname = raname.substring(poundIndex + 1);
if (isEmbedded(raname)) {
if (isEmbedded(application, raname)) {
return;
}
}
Expand All @@ -823,7 +821,7 @@ else if (raname.substring(0, poundIndex).equals(application.getAppName())) {
raname, type));
}

private boolean isEmbedded(String raname) {
private boolean isEmbedded(Application application, String raname) {
String ranameWithRAR = raname + ".rar";
// check for rar named this
for (BundleDescriptor bd : application.getBundleDescriptors(ConnectorDescriptor.class)) {
Expand All @@ -844,7 +842,7 @@ private boolean isEmbedded(String raname) {
*
* @param resource to be validated.
*/
private void validateJNDIRefs(AppResource resource, JNDINamespace namespace) {
private void validateJNDIRefs(Application application, AppResource resource, JNDINamespace namespace) {
// In case lookup is not present, check if another resource with the same name exists
if (!resource.hasLookup() && !namespace.find(resource.getName(), resource.getEnv())) {
deplLogger.log(Level.SEVERE, RESOURCE_REF_JNDI_LOOKUP_FAILED,
Expand All @@ -869,7 +867,7 @@ private void validateJNDIRefs(AppResource resource, JNDINamespace namespace) {
return;
}

String newName = convertModuleOrAppJNDIName(jndiName, resource.getEnv());
String newName = convertModuleOrAppJNDIName(application, jndiName, resource.getEnv());
if (namespace.find(newName, env)) {
return;
} else {
Expand Down

0 comments on commit 4ae5337

Please sign in to comment.