Skip to content

Commit

Permalink
Merge pull request #24544 from OndroMih/ondromih-initial-app-context
Browse files Browse the repository at this point in the history
Propagate JNDI context if none exists
  • Loading branch information
arjantijms authored Aug 22, 2023
2 parents c1dc4cf + eda7d95 commit 6d56eba
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,7 @@ public ContextHandle setup(ContextHandle contextHandle) {
ComponentInvocation invocation = invocationCtx.getInvocation();
final String appName = invocation == null ? null : invocation.getAppName();

if (!isApplicationEnabled(appName)) {
throw new IllegalStateException("Module " + appName + " is disabled");
}
verifyApplicationEnabled(appName);

final ClassLoader resetClassLoader;
if (invocationCtx.getContextClassLoader() != null) {
Expand All @@ -149,11 +147,21 @@ public ContextHandle setup(ContextHandle contextHandle) {
resetSecurityContext = SecurityContext.getCurrent();
SecurityContext.setCurrent(invocationCtx.getSecurityContext());
}
if (invocation != null) {
// Each invocation needs a ResourceTableKey that returns a unique hashCode for TransactionManager
invocation.setResourceTableKey(new PairKey(invocation.getInstance(), Thread.currentThread()));
invocationManager.preInvoke(invocation);

if (setup.isUnchanged(JNDI) || (!setup.isPropagated(JNDI) && !setup.isClear(JNDI))) {
ComponentInvocation currentInvocation = invocationManager.getCurrentInvocation();
if (currentInvocation != null) {
if (currentInvocation.getAppName() == null) {
currentInvocation.setAppName(invocation.getAppName());
}
invocation = currentInvocation;
}
}

// Each invocation needs a ResourceTableKey that returns a unique hashCode for TransactionManager
invocation.setResourceTableKey(new PairKey(invocation.getInstance(), Thread.currentThread()));
invocationManager.preInvoke(invocation);

// Ensure that there is no existing transaction in the current thread
if (transactionManager != null && setup.isClear(StandardContextType.WorkArea)) {
transactionManager.clearThreadTx();
Expand Down Expand Up @@ -235,29 +243,29 @@ private ComponentInvocation getSavedInvocation() {
return null;
}
if (setup.isClear(JNDI)) {
return new ComponentInvocation();
}
if (setup.isPropagated(JNDI)) {
return cloneComponentInvocation(currentInvocation);
return new ComponentInvocation(null, null, null, currentInvocation.getAppName(), null);
}
return null;
return cloneComponentInvocation(currentInvocation);
}


/**
* Check whether the application component submitting the task is still running.
* Throw IllegalStateException if not.
*/
private boolean isApplicationEnabled(String appId) {
private void verifyApplicationEnabled(String appId) {
if (appId == null) {
// we don't know the application name yet, it is starting.
return true;
IllegalStateException ex = new IllegalStateException("The appId is null");
LOG.log(Level.WARNING, "Context handle not in valid state. Do not run the task. " + ex.getMessage(), ex);
throw ex;
}
Application app = applications.getApplication(appId);
if (app != null) {
return deployment.isAppEnabled(app);
if (app != null && !deployment.isAppEnabled(app)) {
IllegalStateException ex = new IllegalStateException("Module " + appId + " is disabled");
LOG.log(Level.WARNING, "Context handle not in valid state. Do not run the task. " + ex.getMessage(), ex);
throw ex;
}
return false;
// if we know the application name but don't have an application yet, it is starting, and thus enabled
}


Expand Down
2 changes: 1 addition & 1 deletion appserver/tests/tck/concurrency/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
<dependency>
<groupId>org.jboss.arquillian</groupId>
<artifactId>arquillian-bom</artifactId>
<version>1.7.0.Alpha13</version>
<version>1.7.0.Final</version>
<type>pom</type>
<scope>import</scope>
</dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,10 @@ public String getAppName() {
return appName;
}

public void setAppName(String appName) {
this.appName = appName;
}

/**
* Returns the moduleName for the current invocation, equivalent to the value bound to java:module/ModuleName, without
* the cost of lookup. For invocations that are not on Jakarta EE components, returns null.
Expand Down

0 comments on commit 6d56eba

Please sign in to comment.