This is an automated email from the ASF dual-hosted git repository.
mridulpathak pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/ofbiz-framework.git
The following commit(s) were added to refs/heads/trunk by this push:
new 096d347281 Load the service definitions with a delegator when a
dispatch context has no dispatcher
096d347281 is described below
commit 096d347281f438e1e40097b03b725dc7ba467a04
Author: Mridul Pathak <[email protected]>
AuthorDate: Sat Oct 31 18:51:02 2026 +0530
Load the service definitions with a delegator when a dispatch context has
no dispatcher
A DispatchContext created without a dispatcher, as the label manager and
the artifact info pages do, read the service definitions in tasks that each
called getDelegator() on the null dispatcher, so every task failed and an empty
service map was cached for the entity model reader. After the caches were
cleared, this left every dispatcher using that reader unable to find any
service. Such a context now uses the first configured delegator whose entity
model reader matches its name, and r [...]
---
.../org/apache/ofbiz/service/DispatchContext.java | 31 ++++++++++++++++++++--
1 file changed, 29 insertions(+), 2 deletions(-)
diff --git
a/framework/service/src/main/java/org/apache/ofbiz/service/DispatchContext.java
b/framework/service/src/main/java/org/apache/ofbiz/service/DispatchContext.java
index 73938c89a0..01c4a2c8af 100644
---
a/framework/service/src/main/java/org/apache/ofbiz/service/DispatchContext.java
+++
b/framework/service/src/main/java/org/apache/ofbiz/service/DispatchContext.java
@@ -38,6 +38,7 @@ import org.apache.ofbiz.base.config.ResourceHandler;
import org.apache.ofbiz.base.util.Debug;
import org.apache.ofbiz.base.util.cache.UtilCache;
import org.apache.ofbiz.entity.Delegator;
+import org.apache.ofbiz.entity.DelegatorFactory;
import org.apache.ofbiz.entity.GenericEntityConfException;
import org.apache.ofbiz.entity.config.model.DelegatorElement;
import org.apache.ofbiz.entity.config.model.EntityConfig;
@@ -63,10 +64,13 @@ public class DispatchContext implements Serializable {
private final transient ClassLoader loader;
private final transient LocalDispatcher dispatcher;
private final String model;
+ // the delegator used when there is no dispatcher
+ private final transient Delegator modelDelegator;
/**
* Creates new DispatchContext as an immutable object.
- * The "dispatcher" argument can be null if the "name" argument matches
the name of a valid entity model reader.
+ * The "dispatcher" argument can be null if the "name" argument matches
the name of a valid entity model reader:
+ * the first configured delegator that uses this entity model reader is
then used.
* The thread safety of a DispatchContext object is a consequence of its
immutability.
* @param name The immutable name of the DispatchContext
* @param loader The immutable class loader
@@ -97,6 +101,7 @@ public class DispatchContext implements Serializable {
modelName = name;
}
this.model = modelName;
+ this.modelDelegator = dispatcher == null ?
getDelegatorForModel(modelName) : null;
getGlobalServiceMap();
}
@@ -129,7 +134,7 @@ public class DispatchContext implements Serializable {
* @return Delegator associated with this context
*/
public Delegator getDelegator() {
- return dispatcher.getDelegator();
+ return dispatcher != null ? dispatcher.getDelegator() : modelDelegator;
}
/**
@@ -228,6 +233,28 @@ public class DispatchContext implements Serializable {
return model.toWSDL(locationURI);
}
+ /**
+ * Gets the first configured delegator that uses the given entity model
reader.
+ * @param modelName the name of the entity model reader
+ * @return the delegator
+ * @throws IllegalArgumentException if no delegator uses this entity model
reader
+ */
+ private static Delegator getDelegatorForModel(String modelName) {
+ try {
+ for (DelegatorElement delegatorInfo :
EntityConfig.getInstance().getDelegatorList()) {
+ if (modelName.equals(delegatorInfo.getEntityModelReader())) {
+ Delegator delegator =
DelegatorFactory.getDelegator(delegatorInfo.getName());
+ if (delegator != null) {
+ return delegator;
+ }
+ }
+ }
+ } catch (GenericEntityConfException e) {
+ Debug.logWarning(e, "Exception thrown while getting delegator
config: ", MODULE);
+ }
+ throw new IllegalArgumentException("No delegator uses the entity model
reader [" + modelName + "]");
+ }
+
private Callable<Map<String, ModelService>>
createServiceReaderCallable(final ResourceHandler handler) {
return () -> ModelServiceReader.getModelServiceMap(handler,
DispatchContext.this.getDelegator());
}