You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by mb...@apache.org on 2017/10/07 14:30:13 UTC
svn commit: r1811431 -
/ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/
Author: mbrohl
Date: Sat Oct 7 14:30:13 2017
New Revision: 1811431
URL: http://svn.apache.org/viewvc?rev=1811431&view=rev
Log:
Improved: Fixing defects reported by FindBugs, package
org.apache.ofbiz.service.
(OFBIZ-9638)
Thanks Dennis Balkir for reporting and providing the patch.
Modified:
ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/DispatchContext.java
ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/GenericAbstractDispatcher.java
ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/GenericDispatcherFactory.java
ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/ModelParam.java
ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/ModelPermGroup.java
ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/ModelPermission.java
ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/ModelService.java
ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/ModelServiceReader.java
ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/RunningService.java
ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/ServiceDispatcher.java
ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/ServiceSynchronization.java
ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/ServiceUtil.java
ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/ServiceXaWrapper.java
Modified: ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/DispatchContext.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/DispatchContext.java?rev=1811431&r1=1811430&r2=1811431&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/DispatchContext.java (original)
+++ ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/DispatchContext.java Sat Oct 7 14:30:13 2017
@@ -183,19 +183,18 @@ public class DispatchContext implements
if (model == null) {
throw new GenericServiceException("Model service is null! Should never happen.");
- } else {
- switch (modeInt) {
- case 2:
- newContext = model.makeValid(context, ModelService.OUT_PARAM, true, null);
- break;
- case 1:
- newContext = model.makeValid(context, ModelService.IN_PARAM, true, null);
- break;
- default:
- throw new GenericServiceException("Invalid mode, should be either IN or OUT");
- }
- return newContext;
}
+ switch (modeInt) {
+ case 1:
+ newContext = model.makeValid(context, ModelService.IN_PARAM, true, null);
+ break;
+ case 2:
+ newContext = model.makeValid(context, ModelService.OUT_PARAM, true, null);
+ break;
+ default:
+ throw new GenericServiceException("Invalid mode, should be either IN or OUT");
+ }
+ return newContext;
}
/**
@@ -206,11 +205,9 @@ public class DispatchContext implements
public ModelService getModelService(String serviceName) throws GenericServiceException {
Map<String, ModelService> serviceMap = getGlobalServiceMap();
ModelService retVal = null;
- if (serviceMap != null) {
- retVal = serviceMap.get(serviceName);
- if (retVal != null && !retVal.inheritedParameters()) {
- retVal.interfaceUpdate(this);
- }
+ retVal = serviceMap.get(serviceName);
+ if (retVal != null && !retVal.inheritedParameters()) {
+ retVal.interfaceUpdate(this);
}
if (retVal == null) {
throw new GenericServiceException("Cannot locate service by name (" + serviceName + ")");
@@ -219,7 +216,7 @@ public class DispatchContext implements
}
public Set<String> getAllServiceNames() {
- Set<String> serviceNames = new TreeSet<String>();
+ Set<String> serviceNames = new TreeSet<>();
Map<String, ModelService> globalServices = modelServiceMapByModel.get(this.model);
if (globalServices != null) {
@@ -244,9 +241,9 @@ public class DispatchContext implements
private Map<String, ModelService> getGlobalServiceMap() {
Map<String, ModelService> serviceMap = modelServiceMapByModel.get(this.model);
if (serviceMap == null) {
- serviceMap = new HashMap<String, ModelService>();
+ serviceMap = new HashMap<>();
- List<Future<Map<String, ModelService>>> futures = new LinkedList<Future<Map<String, ModelService>>>();
+ List<Future<Map<String, ModelService>>> futures = new LinkedList<>();
List<GlobalServices> globalServicesList = null;
try {
globalServicesList = ServiceConfigUtil.getServiceEngine().getGlobalServices();
@@ -270,11 +267,9 @@ public class DispatchContext implements
}
}
- if (serviceMap != null) {
- Map<String, ModelService> cachedServiceMap = modelServiceMapByModel.putIfAbsentAndGet(this.model, serviceMap);
- if (cachedServiceMap == serviceMap) { // same object: this means that the object created by this thread was actually added to the cache
- ServiceEcaUtil.reloadConfig();
- }
+ Map<String, ModelService> cachedServiceMap = modelServiceMapByModel.putIfAbsentAndGet(this.model, serviceMap);
+ if (cachedServiceMap == serviceMap) { // same object: this means that the object created by this thread was actually added to the cache
+ ServiceEcaUtil.reloadConfig();
}
}
return serviceMap;
Modified: ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/GenericAbstractDispatcher.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/GenericAbstractDispatcher.java?rev=1811431&r1=1811430&r2=1811431&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/GenericAbstractDispatcher.java (original)
+++ ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/GenericAbstractDispatcher.java Sat Oct 7 14:30:13 2017
@@ -83,6 +83,8 @@ public abstract class GenericAbstractDis
} catch (JobManagerException jme) {
throw new GenericServiceException(jme.getMessage(), jme);
}
+ } catch (RuntimeException e) {
+ throw e;
} catch (Exception e) {
String errMsg = "General error while scheduling job";
Debug.logError(e, errMsg, module);
Modified: ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/GenericDispatcherFactory.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/GenericDispatcherFactory.java?rev=1811431&r1=1811430&r2=1811431&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/GenericDispatcherFactory.java (original)
+++ ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/GenericDispatcherFactory.java Sat Oct 7 14:30:13 2017
@@ -29,7 +29,7 @@ import org.apache.ofbiz.entity.Delegator
*/
public class GenericDispatcherFactory implements LocalDispatcherFactory {
- protected static boolean ecasDisabled = false;
+ private static boolean ecasDisabled = false;
@Override
public LocalDispatcher createLocalDispatcher(String name, Delegator delegator) {
@@ -46,7 +46,7 @@ public class GenericDispatcherFactory im
}
// The default LocalDispatcher implementation.
- private class GenericDispatcher extends GenericAbstractDispatcher {
+ private static class GenericDispatcher extends GenericAbstractDispatcher {
private GenericDispatcher(String name, Delegator delegator) {
ClassLoader loader;
Modified: ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/ModelParam.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/ModelParam.java?rev=1811431&r1=1811430&r2=1811431&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/ModelParam.java (original)
+++ ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/ModelParam.java Sat Oct 7 14:30:13 2017
@@ -128,9 +128,8 @@ public class ModelParam implements Seria
public String getPrimaryFailMessage(Locale locale) {
if (UtilValidate.isNotEmpty(validators)) {
return validators.get(0).getFailMessage(locale);
- } else {
- return null;
}
+ return null;
}
public String getShortDisplayDescription() {
@@ -209,6 +208,13 @@ public class ModelParam implements Seria
return model.name.equals(this.name);
}
+ public boolean equals(Object obj) {
+ if (!(obj instanceof ModelParam)) {
+ return false;
+ }
+ return equals((ModelParam) obj);
+ }
+
@Override
public String toString() {
StringBuilder buf = new StringBuilder();
@@ -313,10 +319,9 @@ public class ModelParam implements Seria
public String getFailMessage(Locale locale) {
if (failMessage != null) {
return this.failMessage;
- } else {
- if (failResource != null && failProperty != null) {
- return UtilProperties.getMessage(failResource, failProperty, locale);
- }
+ }
+ if (failResource != null && failProperty != null) {
+ return UtilProperties.getMessage(failResource, failProperty, locale);
}
return null;
}
Modified: ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/ModelPermGroup.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/ModelPermGroup.java?rev=1811431&r1=1811430&r2=1811431&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/ModelPermGroup.java (original)
+++ ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/ModelPermGroup.java Sat Oct 7 14:30:13 2017
@@ -36,7 +36,7 @@ public class ModelPermGroup implements S
public static final String PERM_JOIN_AND = "AND";
public static final String PERM_JOIN_OR = "OR";
- public List<ModelPermission> permissions = new LinkedList<ModelPermission>();
+ public List<ModelPermission> permissions = new LinkedList<>();
public String joinType;
public boolean evalPermissions(DispatchContext dctx, Map<String, ? extends Object> context) {
@@ -52,8 +52,7 @@ public class ModelPermGroup implements S
}
}
return foundOne;
- } else {
- return true;
}
+ return true;
}
}
Modified: ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/ModelPermission.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/ModelPermission.java?rev=1811431&r1=1811430&r2=1811431&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/ModelPermission.java (original)
+++ ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/ModelPermission.java Sat Oct 7 14:30:13 2017
@@ -126,10 +126,6 @@ public class ModelPermission implements
Debug.logError(e, "Failed to get ModelService: " + e.toString(), module);
return false;
}
- if (permission == null) {
- Debug.logError("No ModelService found with the name [" + permissionServiceName + "]", module);
- return false;
- }
permission.auth = true;
Map<String, Object> ctx = permission.makeValid(context, ModelService.IN_PARAM);
if (UtilValidate.isNotEmpty(action)) {
@@ -147,7 +143,7 @@ public class ModelPermission implements
resp = dispatcher.runSync(permission.name, ctx, 300, true);
failMessage = (String) resp.get("failMessage");
} catch (GenericServiceException e) {
- Debug.logError(failMessage + e.getMessage(), module);
+ Debug.logError(null + e.getMessage(), module);
return false;
}
if (ServiceUtil.isError(resp) || ServiceUtil.isFailure(resp)) {
Modified: ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/ModelService.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/ModelService.java?rev=1811431&r1=1811430&r2=1811431&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/ModelService.java (original)
+++ ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/ModelService.java Sat Oct 7 14:30:13 2017
@@ -31,6 +31,7 @@ import java.util.LinkedList;
import java.util.List;
import java.util.Locale;
import java.util.Map;
+import java.util.NoSuchElementException;
import java.util.Set;
import java.util.TimeZone;
import java.util.TreeSet;
@@ -84,7 +85,7 @@ import com.ibm.wsdl.extensions.soap.SOAP
@SuppressWarnings("serial")
public class ModelService extends AbstractMap<String, Object> implements Serializable {
private static final Field[] MODEL_SERVICE_FIELDS;
- private static final Map<String, Field> MODEL_SERVICE_FIELD_MAP = new LinkedHashMap<String, Field>();
+ private static final Map<String, Field> MODEL_SERVICE_FIELD_MAP = new LinkedHashMap<>();
static {
MODEL_SERVICE_FIELDS = ModelService.class.getFields();
for (Field field: MODEL_SERVICE_FIELDS) {
@@ -184,16 +185,16 @@ public class ModelService extends Abstra
public boolean hideResultInLog;
/** Set of services this service implements */
- public Set<ModelServiceIface> implServices = new LinkedHashSet<ModelServiceIface>();
+ public Set<ModelServiceIface> implServices = new LinkedHashSet<>();
/** Set of override parameters */
- public Set<ModelParam> overrideParameters = new LinkedHashSet<ModelParam>();
+ public Set<ModelParam> overrideParameters = new LinkedHashSet<>();
/** List of permission groups for service invocation */
- public List<ModelPermGroup> permissionGroups = new LinkedList<ModelPermGroup>();
+ public List<ModelPermGroup> permissionGroups = new LinkedList<>();
/** List of email-notifications for this service */
- public List<ModelNotification> notifications = new LinkedList<ModelNotification>();
+ public List<ModelNotification> notifications = new LinkedList<>();
/** Internal Service Group */
public GroupModel internalGroup = null;
@@ -204,10 +205,10 @@ public class ModelService extends Abstra
public String deprecatedReason = null;
/** Context Information, a Map of parameters used by the service, contains ModelParam objects */
- protected Map<String, ModelParam> contextInfo = new LinkedHashMap<String, ModelParam>();
+ protected Map<String, ModelParam> contextInfo = new LinkedHashMap<>();
/** Context Information, a List of parameters used by the service, contains ModelParam objects */
- protected List<ModelParam> contextParamList = new LinkedList<ModelParam>();
+ protected List<ModelParam> contextParamList = new LinkedList<>();
/** Flag to say if we have pulled in our addition parameters from our implemented service(s) */
protected boolean inheritedParameters = false;
@@ -331,6 +332,9 @@ public class ModelService extends Abstra
}
public Map.Entry<String, Object> next() {
+ if (!hasNext()) {
+ throw new NoSuchElementException();
+ }
return new ModelServiceMapEntry(MODEL_SERVICE_FIELDS[i++]);
}
@@ -384,7 +388,7 @@ public class ModelService extends Abstra
* Test if we have already inherited our interface parameters
* @return boolean
*/
- public boolean inheritedParameters() {
+ public synchronized boolean inheritedParameters() {
return this.inheritedParameters;
}
@@ -431,7 +435,7 @@ public class ModelService extends Abstra
}
public Set<String> getAllParamNames() {
- Set<String> nameList = new TreeSet<String>();
+ Set<String> nameList = new TreeSet<>();
for (ModelParam p: this.contextParamList) {
nameList.add(p.name);
}
@@ -439,7 +443,7 @@ public class ModelService extends Abstra
}
public Set<String> getInParamNames() {
- Set<String> nameList = new TreeSet<String>();
+ Set<String> nameList = new TreeSet<>();
for (ModelParam p: this.contextParamList) {
// don't include OUT parameters in this list, only IN and INOUT
if (p.isIn()) nameList.add(p.name);
@@ -460,7 +464,7 @@ public class ModelService extends Abstra
}
public Set<String> getOutParamNames() {
- Set<String> nameList = new TreeSet<String>();
+ Set<String> nameList = new TreeSet<>();
for (ModelParam p: this.contextParamList) {
// don't include IN parameters in this list, only OUT and INOUT
if (p.isOut()) nameList.add(p.name);
@@ -482,14 +486,12 @@ public class ModelService extends Abstra
public void updateDefaultValues(Map<String, Object> context, String mode) {
List<ModelParam> params = this.getModelParamList();
- if (params != null) {
- for (ModelParam param: params) {
- if (IN_OUT_PARAM.equals(param.mode) || mode.equals(param.mode)) {
- Object defaultValueObj = param.getDefaultValue();
- if (defaultValueObj != null && context.get(param.name) == null) {
- context.put(param.name, defaultValueObj);
- Debug.logInfo("Set default value [" + defaultValueObj + "] for parameter [" + param.name + "]", module);
- }
+ for (ModelParam param: params) {
+ if (IN_OUT_PARAM.equals(param.mode) || mode.equals(param.mode)) {
+ Object defaultValueObj = param.getDefaultValue();
+ if (defaultValueObj != null && context.get(param.name) == null) {
+ context.put(param.name, defaultValueObj);
+ Debug.logInfo("Set default value [" + defaultValueObj + "] for parameter [" + param.name + "]", module);
}
}
}
@@ -502,8 +504,8 @@ public class ModelService extends Abstra
* @param locale the actual locale to use
*/
public void validate(Map<String, Object> context, String mode, Locale locale) throws ServiceValidationException {
- Map<String, String> requiredInfo = new HashMap<String, String>();
- Map<String, String> optionalInfo = new HashMap<String, String>();
+ Map<String, String> requiredInfo = new HashMap<>();
+ Map<String, String> optionalInfo = new HashMap<>();
boolean verboseOn = Debug.verboseOn();
if (verboseOn) Debug.logVerbose("[ModelService.validate] : {" + this.name + "} : Validating context - " + context, module);
@@ -529,14 +531,14 @@ public class ModelService extends Abstra
}
// get the test values
- Map<String, Object> requiredTest = new HashMap<String, Object>();
- Map<String, Object> optionalTest = new HashMap<String, Object>();
+ Map<String, Object> requiredTest = new HashMap<>();
+ Map<String, Object> optionalTest = new HashMap<>();
- if (context == null) context = new HashMap<String, Object>();
+ if (context == null) context = new HashMap<>();
requiredTest.putAll(context);
- List<String> requiredButNull = new LinkedList<String>();
- List<String> keyList = new LinkedList<String>();
+ List<String> requiredButNull = new LinkedList<>();
+ List<String> keyList = new LinkedList<>();
keyList.addAll(requiredTest.keySet());
for (String key: keyList) {
Object value = requiredTest.get(key);
@@ -551,7 +553,7 @@ public class ModelService extends Abstra
// check for requiredButNull fields and return an error since null values are not allowed for required fields
if (requiredButNull.size() > 0) {
- List<String> missingMsg = new LinkedList<String>();
+ List<String> missingMsg = new LinkedList<>();
for (String missingKey: requiredButNull) {
String message = this.getParam(missingKey).getPrimaryFailMessage(locale);
if (message == null) {
@@ -590,7 +592,7 @@ public class ModelService extends Abstra
// required and type validation complete, do allow-html validation
if (IN_PARAM.equals(mode)) {
- List<String> errorMessageList = new LinkedList<String>();
+ List<String> errorMessageList = new LinkedList<>();
for (ModelParam modelParam : this.contextInfo.values()) {
// the param is a String, allow-html is not any, and we are looking at an IN parameter during input parameter validation
if (context.get(modelParam.name) != null && ("String".equals(modelParam.type) || "java.lang.String".equals(modelParam.type))
@@ -640,10 +642,10 @@ public class ModelService extends Abstra
if (info.size() == 0 && test.size() == 0) return;
// This is to see if the test set contains all from the info set (reverse)
if (reverse && !testSet.containsAll(keySet)) {
- Set<String> missing = new TreeSet<String>(keySet);
+ Set<String> missing = new TreeSet<>(keySet);
missing.removeAll(testSet);
- List<String> missingMsgs = new LinkedList<String>();
+ List<String> missingMsgs = new LinkedList<>();
for (String key: missing) {
String msg = model.getParam(key).getPrimaryFailMessage(locale);
if (msg == null) {
@@ -653,17 +655,17 @@ public class ModelService extends Abstra
missingMsgs.add(msg);
}
- List<String> missingCopy = new LinkedList<String>();
+ List<String> missingCopy = new LinkedList<>();
missingCopy.addAll(missing);
throw new ServiceValidationException(missingMsgs, model, missingCopy, null, mode);
}
// This is to see if the info set contains all from the test set
if (!keySet.containsAll(testSet)) {
- Set<String> extra = new TreeSet<String>(testSet);
+ Set<String> extra = new TreeSet<>(testSet);
extra.removeAll(keySet);
- List<String> extraMsgs = new LinkedList<String>();
+ List<String> extraMsgs = new LinkedList<>();
for (String key: extra) {
ModelParam param = model.getParam(key);
String msg = null;
@@ -676,13 +678,13 @@ public class ModelService extends Abstra
extraMsgs.add(msg);
}
- List<String> extraCopy = new LinkedList<String>();
+ List<String> extraCopy = new LinkedList<>();
extraCopy.addAll(extra);
throw new ServiceValidationException(extraMsgs, model, null, extraCopy, mode);
}
// * Validate types next
- List<String> typeFailMsgs = new LinkedList<String>();
+ List<String> typeFailMsgs = new LinkedList<>();
for (String key: testSet) {
ModelParam param = model.getParam(key);
@@ -803,7 +805,7 @@ public class ModelService extends Abstra
* @return List of parameter names
*/
public List<String> getParameterNames(String mode, boolean optional, boolean internal) {
- List<String> names = new LinkedList<String>();
+ List<String> names = new LinkedList<>();
if (!IN_PARAM.equals(mode) && !OUT_PARAM.equals(mode) && !IN_OUT_PARAM.equals(mode)) {
return names;
@@ -871,7 +873,7 @@ public class ModelService extends Abstra
* @param locale Locale to use to do some type conversion
*/
public Map<String, Object> makeValid(Map<String, ? extends Object> source, String mode, boolean includeInternal, List<Object> errorMessages, TimeZone timeZone, Locale locale) {
- Map<String, Object> target = new HashMap<String, Object>();
+ Map<String, Object> target = new HashMap<>();
if (source == null) {
return target;
@@ -947,7 +949,7 @@ public class ModelService extends Abstra
}
private Map<String, Object> makePrefixMap(Map<String, ? extends Object> source, ModelParam param) {
- Map<String, Object> paramMap = new HashMap<String, Object>();
+ Map<String, Object> paramMap = new HashMap<>();
for (Map.Entry<String, ? extends Object> entry: source.entrySet()) {
String key = entry.getKey();
if (key.startsWith(param.stringMapPrefix)) {
@@ -959,7 +961,7 @@ public class ModelService extends Abstra
}
private List<Object> makeSuffixList(Map<String, ? extends Object> source, ModelParam param) {
- List<Object> paramList = new LinkedList<Object>();
+ List<Object> paramList = new LinkedList<>();
for (Map.Entry<String, ? extends Object> entry: source.entrySet()) {
String key = entry.getKey();
if (key.endsWith(param.stringListSuffix)) {
@@ -993,51 +995,42 @@ public class ModelService extends Abstra
result.put("failMessage", e.getMessage());
return result;
}
- if (permission != null) {
- Map<String, Object> ctx = permission.makeValid(context, IN_PARAM);
- if (UtilValidate.isNotEmpty(this.permissionMainAction)) {
- ctx.put("mainAction", this.permissionMainAction);
- }
- if (UtilValidate.isNotEmpty(this.permissionResourceDesc)) {
- ctx.put("resourceDescription", this.permissionResourceDesc);
- } else if (thisService != null) {
- ctx.put("resourceDescription", thisService.name);
- }
+ Map<String, Object> ctx = permission.makeValid(context, IN_PARAM);
+ if (UtilValidate.isNotEmpty(this.permissionMainAction)) {
+ ctx.put("mainAction", this.permissionMainAction);
+ }
+ if (UtilValidate.isNotEmpty(this.permissionResourceDesc)) {
+ ctx.put("resourceDescription", this.permissionResourceDesc);
+ }
+ ctx.put("resourceDescription", thisService.name);
- LocalDispatcher dispatcher = dctx.getDispatcher();
- Map<String, Object> resp;
- try {
- resp = dispatcher.runSync(permission.name, ctx, 300, true);
- } catch (GenericServiceException e) {
- Debug.logError(e, module);
- Map<String, Object> result = ServiceUtil.returnSuccess();
- result.put("hasPermission", Boolean.FALSE);
- result.put("failMessage", e.getMessage());
- return result;
- }
- if (ServiceUtil.isError(resp) || ServiceUtil.isFailure(resp)) {
- Map<String, Object> result = ServiceUtil.returnSuccess();
- result.put("hasPermission", Boolean.FALSE);
- String failMessage = (String) resp.get("failMessage");
- if (UtilValidate.isEmpty(failMessage)) {
- failMessage = ServiceUtil.getErrorMessage(resp);
- }
- result.put("failMessage", failMessage);
- return result;
- }
- return resp;
- } else {
+ LocalDispatcher dispatcher = dctx.getDispatcher();
+ Map<String, Object> resp;
+ try {
+ resp = dispatcher.runSync(permission.name, ctx, 300, true);
+ } catch (GenericServiceException e) {
+ Debug.logError(e, module);
Map<String, Object> result = ServiceUtil.returnSuccess();
result.put("hasPermission", Boolean.FALSE);
- result.put("failMessage", "No ModelService found with the name [" + this.permissionServiceName + "]");
+ result.put("failMessage", e.getMessage());
return result;
}
- } else {
- Map<String, Object> result = ServiceUtil.returnSuccess();
- result.put("hasPermission", Boolean.FALSE);
- result.put("failMessage", "No ModelService found; no service name specified!");
- return result;
+ if (ServiceUtil.isError(resp) || ServiceUtil.isFailure(resp)) {
+ Map<String, Object> result = ServiceUtil.returnSuccess();
+ result.put("hasPermission", Boolean.FALSE);
+ String failMessage = (String) resp.get("failMessage");
+ if (UtilValidate.isEmpty(failMessage)) {
+ failMessage = ServiceUtil.getErrorMessage(resp);
+ }
+ result.put("failMessage", failMessage);
+ return result;
+ }
+ return resp;
}
+ Map<String, Object> result = ServiceUtil.returnSuccess();
+ result.put("hasPermission", Boolean.FALSE);
+ result.put("failMessage", "No ModelService found; no service name specified!");
+ return result;
}
/**
@@ -1072,7 +1065,7 @@ public class ModelService extends Abstra
* @return A list of required IN parameters in the order which they were defined.
*/
public List<Object> getInParameterSequence(Map<String, ? extends Object> source) {
- List<Object> target = new LinkedList<Object>();
+ List<Object> target = new LinkedList<>();
if (source == null) {
return target;
}
@@ -1096,7 +1089,7 @@ public class ModelService extends Abstra
* the service was created.
*/
public List<ModelParam> getModelParamList() {
- List<ModelParam> newList = new LinkedList<ModelParam>();
+ List<ModelParam> newList = new LinkedList<>();
newList.addAll(this.contextParamList);
return newList;
}
@@ -1106,7 +1099,7 @@ public class ModelService extends Abstra
* the service was created.
*/
public List<ModelParam> getInModelParamList() {
- List<ModelParam> inList = new LinkedList<ModelParam>();
+ List<ModelParam> inList = new LinkedList<>();
for (ModelParam modelParam: this.contextParamList) {
// don't include OUT parameters in this list, only IN and INOUT
if (OUT_PARAM.equals(modelParam.mode)) continue;
@@ -1264,78 +1257,74 @@ public class ModelService extends Abstra
// set the IN parameters
Input input = def.createInput();
Set<String> inParam = this.getInParamNames();
- if (inParam != null) {
- Message inMessage = def.createMessage();
- inMessage.setQName(new QName(TNS, this.name + "Request"));
- inMessage.setUndefined(false);
- Part parametersPart = def.createPart();
- parametersPart.setName("map-Map");
- parametersPart.setTypeName(new QName(TNS, "map-Map"));
- inMessage.addPart(parametersPart);
- Element documentation = document.createElement("wsdl:documentation");
- for (String paramName: inParam) {
- ModelParam param = this.getParam(paramName);
- if (!param.internal) {
- Part part = param.getWSDLPart(def);
- Element attribute = document.createElement("attribute");
- attribute.setAttribute("name", paramName);
- attribute.setAttribute("type", part.getTypeName().getLocalPart());
- attribute.setAttribute("namespace", part.getTypeName().getNamespaceURI());
- attribute.setAttribute("java-class", param.type);
- attribute.setAttribute("optional", Boolean.toString(param.optional));
- documentation.appendChild(attribute);
- }
- }
- Element usernameAttr = document.createElement("attribute");
- usernameAttr.setAttribute("name", "login.username");
- usernameAttr.setAttribute("type", "std-String");
- usernameAttr.setAttribute("namespace", TNS);
- usernameAttr.setAttribute("java-class", String.class.getName());
- usernameAttr.setAttribute("optional", Boolean.toString(!this.auth));
- documentation.appendChild(usernameAttr);
-
- Element passwordAttr = document.createElement("attribute");
- passwordAttr.setAttribute("name", "login.password");
- passwordAttr.setAttribute("type", "std-String");
- passwordAttr.setAttribute("namespace", TNS);
- passwordAttr.setAttribute("java-class", String.class.getName());
- passwordAttr.setAttribute("optional", Boolean.toString(!this.auth));
- documentation.appendChild(passwordAttr);
-
- parametersPart.setDocumentationElement(documentation);
- def.addMessage(inMessage);
- input.setMessage(inMessage);
- }
+ Message inMessage = def.createMessage();
+ inMessage.setQName(new QName(TNS, this.name + "Request"));
+ inMessage.setUndefined(false);
+ Part parametersPart = def.createPart();
+ parametersPart.setName("map-Map");
+ parametersPart.setTypeName(new QName(TNS, "map-Map"));
+ inMessage.addPart(parametersPart);
+ Element documentation = document.createElement("wsdl:documentation");
+ for (String paramName : inParam) {
+ ModelParam param = this.getParam(paramName);
+ if (!param.internal) {
+ Part part = param.getWSDLPart(def);
+ Element attribute = document.createElement("attribute");
+ attribute.setAttribute("name", paramName);
+ attribute.setAttribute("type", part.getTypeName().getLocalPart());
+ attribute.setAttribute("namespace", part.getTypeName().getNamespaceURI());
+ attribute.setAttribute("java-class", param.type);
+ attribute.setAttribute("optional", Boolean.toString(param.optional));
+ documentation.appendChild(attribute);
+ }
+ }
+ Element usernameAttr = document.createElement("attribute");
+ usernameAttr.setAttribute("name", "login.username");
+ usernameAttr.setAttribute("type", "std-String");
+ usernameAttr.setAttribute("namespace", TNS);
+ usernameAttr.setAttribute("java-class", String.class.getName());
+ usernameAttr.setAttribute("optional", Boolean.toString(!this.auth));
+ documentation.appendChild(usernameAttr);
+
+ Element passwordAttr = document.createElement("attribute");
+ passwordAttr.setAttribute("name", "login.password");
+ passwordAttr.setAttribute("type", "std-String");
+ passwordAttr.setAttribute("namespace", TNS);
+ passwordAttr.setAttribute("java-class", String.class.getName());
+ passwordAttr.setAttribute("optional", Boolean.toString(!this.auth));
+ documentation.appendChild(passwordAttr);
+
+ parametersPart.setDocumentationElement(documentation);
+ def.addMessage(inMessage);
+ input.setMessage(inMessage);
// set the OUT parameters
Output output = def.createOutput();
Set<String> outParam = this.getOutParamNames();
- if (outParam != null) {
- Message outMessage = def.createMessage();
- outMessage.setQName(new QName(TNS, this.name + "Response"));
- outMessage.setUndefined(false);
- Part resultsPart = def.createPart();
- resultsPart.setName("map-Map");
- resultsPart.setTypeName(new QName(TNS, "map-Map"));
- outMessage.addPart(resultsPart);
- Element documentation = document.createElement("wsdl:documentation");
- for (String paramName: outParam) {
- ModelParam param = this.getParam(paramName);
- if (!param.internal) {
- Part part = param.getWSDLPart(def);
- Element attribute = document.createElement("attribute");
- attribute.setAttribute("name", paramName);
- attribute.setAttribute("type", part.getTypeName().getLocalPart());
- attribute.setAttribute("namespace", part.getTypeName().getNamespaceURI());
- attribute.setAttribute("java-class", param.type);
- attribute.setAttribute("optional", Boolean.toString(param.optional));
- documentation.appendChild(attribute);
- }
- }
- resultsPart.setDocumentationElement(documentation);
- def.addMessage(outMessage);
- output.setMessage(outMessage);
- }
+ Message outMessage = def.createMessage();
+ outMessage.setQName(new QName(TNS, this.name + "Response"));
+ outMessage.setUndefined(false);
+ Part resultsPart = def.createPart();
+ resultsPart.setName("map-Map");
+ resultsPart.setTypeName(new QName(TNS, "map-Map"));
+ outMessage.addPart(resultsPart);
+ documentation = document.createElement("wsdl:documentation");
+ for (String paramName : outParam) {
+ ModelParam param = this.getParam(paramName);
+ if (!param.internal) {
+ Part part = param.getWSDLPart(def);
+ Element attribute = document.createElement("attribute");
+ attribute.setAttribute("name", paramName);
+ attribute.setAttribute("type", part.getTypeName().getLocalPart());
+ attribute.setAttribute("namespace", part.getTypeName().getNamespaceURI());
+ attribute.setAttribute("java-class", param.type);
+ attribute.setAttribute("optional", Boolean.toString(param.optional));
+ documentation.appendChild(attribute);
+ }
+ }
+ resultsPart.setDocumentationElement(documentation);
+ def.addMessage(outMessage);
+ output.setMessage(outMessage);
// set port type
Operation operation = def.createOperation();
Modified: ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/ModelServiceReader.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/ModelServiceReader.java?rev=1811431&r1=1811430&r2=1811431&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/ModelServiceReader.java (original)
+++ ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/ModelServiceReader.java Sat Oct 7 14:30:13 2017
@@ -107,10 +107,7 @@ public class ModelServiceReader implemen
}
}
- Map<String, ModelService> modelServices = new HashMap<String, ModelService>();
- if (this.isFromURL) {// utilTimer.timerString("Before getDocumentElement in file " + readerURL);
- } else {// utilTimer.timerString("Before getDocumentElement in " + handler);
- }
+ Map<String, ModelService> modelServices = new HashMap<>();
Element docElement = document.getDocumentElement();
if (docElement == null) {
@@ -151,27 +148,21 @@ public class ModelServiceReader implemen
ModelService service = createModelService(curServiceElement, resourceLocation);
// utilTimer.timerString(" After createModelService -- " + i + " --");
- if (service != null) {
- modelServices.put(serviceName, service);
- // utilTimer.timerString(" After modelServices.put -- " + i + " --");
- /*
- int reqIn = service.getParameterNames(ModelService.IN_PARAM, false).size();
- int optIn = service.getParameterNames(ModelService.IN_PARAM, true).size() - reqIn;
- int reqOut = service.getParameterNames(ModelService.OUT_PARAM, false).size();
- int optOut = service.getParameterNames(ModelService.OUT_PARAM, true).size() - reqOut;
-
- if (Debug.verboseOn()) {
- String msg = "-- getModelService: # " + i + " Loaded service: " + serviceName +
- " (IN) " + reqIn + "/" + optIn + " (OUT) " + reqOut + "/" + optOut;
-
- Debug.logVerbose(msg, module);
- }
- */
- } else {
- Debug.logWarning(
- "-- -- SERVICE ERROR:getModelService: Could not create service for serviceName: " +
- serviceName, module);
+ modelServices.put(serviceName, service);
+ // utilTimer.timerString(" After modelServices.put -- " + i + " --");
+ /*
+ int reqIn = service.getParameterNames(ModelService.IN_PARAM, false).size();
+ int optIn = service.getParameterNames(ModelService.IN_PARAM, true).size() - reqIn;
+ int reqOut = service.getParameterNames(ModelService.OUT_PARAM, false).size();
+ int optOut = service.getParameterNames(ModelService.OUT_PARAM, true).size() - reqOut;
+
+ if (Debug.verboseOn()) {
+ String msg = "-- getModelService: # " + i + " Loaded service: " + serviceName +
+ " (IN) " + reqIn + "/" + optIn + " (OUT) " + reqOut + "/" + optOut;
+
+ Debug.logVerbose(msg, module);
}
+ */
}
} while ((curChild = curChild.getNextSibling()) != null);
@@ -273,7 +264,7 @@ public class ModelServiceReader implemen
service.nameSpace = getCDATADef(serviceElement, "namespace");
// construct the context
- service.contextInfo = new HashMap<String, ModelParam>();
+ service.contextInfo = new HashMap<>();
this.createNotification(serviceElement, service);
this.createPermission(serviceElement, service);
this.createPermGroups(serviceElement, service);
@@ -441,52 +432,50 @@ public class ModelServiceReader implemen
}
if (delegator != null && entityName != null) {
- Map<String, ModelParam> modelParamMap = new LinkedHashMap<String, ModelParam>();
+ Map<String, ModelParam> modelParamMap = new LinkedHashMap<>();
try {
ModelEntity entity = delegator.getModelEntity(entityName);
if (entity == null) {
throw new GeneralException("Could not find entity with name [" + entityName + "]");
}
Iterator<ModelField> fieldsIter = entity.getFieldsIterator();
- if (fieldsIter != null) {
- while (fieldsIter.hasNext()) {
- ModelField field = fieldsIter.next();
- if ((!field.getIsAutoCreatedInternal()) && ((field.getIsPk() && includePk) || (!field.getIsPk() && includeNonPk))) {
- ModelFieldType fieldType = delegator.getEntityFieldType(entity, field.getType());
- if (fieldType == null) {
- throw new GeneralException("Null field type from delegator for entity [" + entityName + "]");
- }
- ModelParam param = new ModelParam();
- param.entityName = entityName;
- param.fieldName = field.getName();
- param.name = field.getName();
- param.type = fieldType.getJavaType();
- // this is a special case where we use something different in the service layer than we do in the entity/data layer
- if ("java.sql.Blob".equals(param.type)) {
- param.type = "java.nio.ByteBuffer";
- }
- param.mode = UtilXml.checkEmpty(autoElement.getAttribute("mode")).intern();
- param.optional = "true".equalsIgnoreCase(autoElement.getAttribute("optional")); // default to true
- param.formDisplay = !"false".equalsIgnoreCase(autoElement.getAttribute("form-display")); // default to false
- param.allowHtml = UtilXml.checkEmpty(autoElement.getAttribute("allow-html"), "none").intern(); // default to none
- modelParamMap.put(field.getName(), param);
+ while (fieldsIter.hasNext()) {
+ ModelField field = fieldsIter.next();
+ if ((!field.getIsAutoCreatedInternal()) && ((field.getIsPk() && includePk) || (!field.getIsPk() && includeNonPk))) {
+ ModelFieldType fieldType = delegator.getEntityFieldType(entity, field.getType());
+ if (fieldType == null) {
+ throw new GeneralException("Null field type from delegator for entity [" + entityName + "]");
}
- }
-
- // get the excludes list; and remove those from the map
- List<? extends Element> excludes = UtilXml.childElementList(autoElement, "exclude");
- if (excludes != null) {
- for (Element exclude: excludes) {
- modelParamMap.remove(UtilXml.checkEmpty(exclude.getAttribute("field-name")));
+ ModelParam param = new ModelParam();
+ param.entityName = entityName;
+ param.fieldName = field.getName();
+ param.name = field.getName();
+ param.type = fieldType.getJavaType();
+ // this is a special case where we use something different in the service layer than we do in the entity/data layer
+ if ("java.sql.Blob".equals(param.type)) {
+ param.type = "java.nio.ByteBuffer";
}
+ param.mode = UtilXml.checkEmpty(autoElement.getAttribute("mode")).intern();
+ param.optional = "true".equalsIgnoreCase(autoElement.getAttribute("optional")); // default to true
+ param.formDisplay = !"false".equalsIgnoreCase(autoElement.getAttribute("form-display")); // default to false
+ param.allowHtml = UtilXml.checkEmpty(autoElement.getAttribute("allow-html"), "none").intern(); // default to none
+ modelParamMap.put(field.getName(), param);
}
+ }
- // now add in all the remaining params
- for (ModelParam thisParam: modelParamMap.values()) {
- //Debug.logInfo("Adding Param to " + service.name + ": " + thisParam.name + " [" + thisParam.mode + "] " + thisParam.type + " (" + thisParam.optional + ")", module);
- service.addParam(thisParam);
+ // get the excludes list; and remove those from the map
+ List<? extends Element> excludes = UtilXml.childElementList(autoElement, "exclude");
+ if (excludes != null) {
+ for (Element exclude : excludes) {
+ modelParamMap.remove(UtilXml.checkEmpty(exclude.getAttribute("field-name")));
}
}
+
+ // now add in all the remaining params
+ for (ModelParam thisParam : modelParamMap.values()) {
+ //Debug.logInfo("Adding Param to " + service.name + ": " + thisParam.name + " [" + thisParam.mode + "] " + thisParam.type + " (" + thisParam.optional + ")", module);
+ service.addParam(thisParam);
+ }
} catch (GenericEntityException e) {
Debug.logError(e, "Problem loading auto-attributes [" + entityName + "] for " + service.name, module);
} catch (GeneralException e) {
@@ -709,7 +698,7 @@ public class ModelServiceReader implemen
List<? extends Element> validateElements = UtilXml.childElementList(attribute, "type-validate");
if (UtilValidate.isNotEmpty(validateElements)) {
// always clear out old ones; never append
- param.validators = new LinkedList<ModelParamValidator>();
+ param.validators = new LinkedList<>();
Element validate = validateElements.get(0);
String methodName = validate.getAttribute("method").intern();
Modified: ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/RunningService.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/RunningService.java?rev=1811431&r1=1811430&r2=1811431&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/RunningService.java (original)
+++ ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/RunningService.java Sat Oct 7 14:30:13 2017
@@ -56,11 +56,11 @@ public class RunningService {
}
public Timestamp getStartStamp() {
- return this.startStamp;
+ return (Timestamp) this.startStamp.clone();
}
public Timestamp getEndStamp() {
- return this.endStamp;
+ return (Timestamp) this.endStamp.clone();
}
public void setEndStamp() {
@@ -77,4 +77,8 @@ public class RunningService {
}
return false;
}
+
+ public int hashCode() {
+ return System.identityHashCode(this);
+ }
}
Modified: ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/ServiceDispatcher.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/ServiceDispatcher.java?rev=1811431&r1=1811430&r2=1811431&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/ServiceDispatcher.java (original)
+++ ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/ServiceDispatcher.java Sat Oct 7 14:30:13 2017
@@ -70,18 +70,18 @@ public class ServiceDispatcher {
public static final int LOCK_RETRIES = 3;
protected static final Map<RunningService, ServiceDispatcher> runLog = new ConcurrentLinkedHashMap.Builder<RunningService, ServiceDispatcher>().maximumWeightedCapacity(lruLogSize).build();
- protected static ConcurrentHashMap<String, ServiceDispatcher> dispatchers = new ConcurrentHashMap<String, ServiceDispatcher>();
+ private static ConcurrentHashMap<String, ServiceDispatcher> dispatchers = new ConcurrentHashMap<>();
// FIXME: These fields are not thread-safe. They are modified by EntityDataLoadContainer.
// We need a better design - like have this class query EntityDataLoadContainer if data is being loaded.
- protected static boolean enableJM = true;
- protected static boolean enableJMS = UtilProperties.getPropertyAsBoolean("service", "enableJMS", true);
- protected static boolean enableSvcs = true;
+ private static boolean enableJM = true;
+ private static boolean enableJMS = UtilProperties.getPropertyAsBoolean("service", "enableJMS", true);
+ private static boolean enableSvcs = true;
protected Delegator delegator = null;
protected GenericEngineFactory factory = null;
protected Security security = null;
- protected Map<String, DispatchContext> localContext = new HashMap<String, DispatchContext>();
- protected Map<String, List<GenericServiceCallback>> callbacks = new HashMap<String, List<GenericServiceCallback>>();
+ protected Map<String, DispatchContext> localContext = new HashMap<>();
+ protected Map<String, List<GenericServiceCallback>> callbacks = new HashMap<>();
protected JobManager jm = null;
protected JmsListenerFactory jlf = null;
@@ -98,10 +98,8 @@ public class ServiceDispatcher {
} catch (SecurityConfigurationException e) {
Debug.logError(e, "[ServiceDispatcher.init] : No instance of security implementation found.", module);
}
- }
// clean up the service semaphores of same instance
- if (delegator != null) {
try {
int rn = delegator.removeByAnd("ServiceSemaphore", "lockedByInstanceId", JobManager.instanceId);
if (rn > 0) {
@@ -111,18 +109,22 @@ public class ServiceDispatcher {
Debug.logError(e, module);
}
}
-
+
// job manager needs to always be running, but the poller thread does not
- try {
- Delegator origDelegator = this.delegator;
- if (!this.delegator.getOriginalDelegatorName().equals(this.delegator.getDelegatorName())) {
- origDelegator = DelegatorFactory.getDelegator(this.delegator.getOriginalDelegatorName());
- }
- this.jm = JobManager.getInstance(origDelegator, enableJM);
- } catch (GeneralRuntimeException e) {
- Debug.logWarning(e.getMessage(), module);
+ if (this.delegator != null) {
+ try {
+ Delegator origDelegator = this.delegator;
+ if (!this.delegator.getOriginalDelegatorName().equals(this.delegator.getDelegatorName())) {
+ origDelegator = DelegatorFactory.getDelegator(this.delegator.getOriginalDelegatorName());
+ }
+ this.jm = JobManager.getInstance(origDelegator, enableJM);
+ }
+ catch (GeneralRuntimeException e) {
+ Debug.logWarning(e.getMessage(), module);
+ }
+ } else {
+ Debug.logError("[ServiceDispatcher.init] : Delegator parameter was null and caused an exception.", module);
}
-
// make sure we haven't disabled these features from running
if (enableJMS) {
this.jlf = JmsListenerFactory.getInstance(delegator);
@@ -203,7 +205,7 @@ public class ServiceDispatcher {
public synchronized void registerCallback(String serviceName, GenericServiceCallback cb) {
List<GenericServiceCallback> callBackList = callbacks.get(serviceName);
if (callBackList == null) {
- callBackList = new LinkedList<GenericServiceCallback>();
+ callBackList = new LinkedList<>();
}
callBackList.add(cb);
callbacks.put(serviceName, callBackList);
@@ -253,7 +255,7 @@ public class ServiceDispatcher {
*/
public Map<String, Object> runSync(String localName, ModelService modelService, Map<String, ? extends Object> params, boolean validateOut) throws ServiceAuthException, ServiceValidationException, GenericServiceException {
long serviceStartTime = System.currentTimeMillis();
- Map<String, Object> result = new HashMap<String, Object>();
+ Map<String, Object> result = new HashMap<>();
ServiceSemaphore lock = null;
Map<String, List<ServiceEcaRule>> eventMap = null;
Map<String, Object> ecaContext = null;
@@ -276,7 +278,7 @@ public class ServiceDispatcher {
"/" + modelService.invoke + "] (" + modelService.engineName + ")", module);
}
- Map<String, Object> context = new HashMap<String, Object>();
+ Map<String, Object> context = new HashMap<>();
if (params != null) {
context.putAll(params);
}
@@ -423,7 +425,7 @@ public class ServiceDispatcher {
// NOTE DEJ20070908 are there other things we need to check? I don't think so because these will
//be Entity Engine errors that will be caught and come back in an error message... IFF the
//service is written to not ignore it of course!
- if (errMsg != null && errMsg.toUpperCase().indexOf("DEADLOCK") >= 0) {
+ if (errMsg != null && errMsg.toUpperCase(Locale.getDefault()).indexOf("DEADLOCK") >= 0) {
// it's a deadlock! retry...
String retryMsg = "RETRYING SERVICE [" + modelService.name + "]: Deadlock error found in message [" + errMsg + "]; retry [" + (LOCK_RETRIES - lockRetriesRemaining) + "] of [" + LOCK_RETRIES + "]";
@@ -451,7 +453,7 @@ public class ServiceDispatcher {
needsLockRetry = true;
// reset state variables
- result = new HashMap<String, Object>();
+ result = new HashMap<>();
isFailure = false;
isError = false;
@@ -461,8 +463,8 @@ public class ServiceDispatcher {
// look for lock wait timeout error, retry in a different way by running after the parent transaction finishes, ie attach to parent tx
// - Derby 10.2.2.0 lock wait timeout string: "A lock could not be obtained within the time requested"
// - MySQL ? lock wait timeout string: "Lock wait timeout exceeded; try restarting transaction"
- if (errMsg != null && (errMsg.indexOf("A lock could not be obtained within the time requested") >= 0 ||
- errMsg.indexOf("Lock wait timeout exceeded") >= 0)) {
+ if (errMsg.indexOf("A lock could not be obtained within the time requested") >= 0 ||
+ errMsg.indexOf("Lock wait timeout exceeded") >= 0) {
// TODO: add to run after parent tx
}
}
@@ -470,7 +472,7 @@ public class ServiceDispatcher {
} while (needsLockRetry && lockRetriesRemaining > 0);
// create a new context with the results to pass to ECA services; necessary because caller may reuse this context
- ecaContext = new HashMap<String, Object>();
+ ecaContext = new HashMap<>();
ecaContext.putAll(context);
// copy all results: don't worry parameters that aren't allowed won't be passed to the ECA services
ecaContext.putAll(result);
@@ -629,12 +631,12 @@ public class ServiceDispatcher {
"] (" + service.engineName + ")", module);
}
- Map<String, Object> context = new HashMap<String, Object>();
+ Map<String, Object> context = new HashMap<>();
if (params != null) {
context.putAll(params);
}
// setup the result map
- Map<String, Object> result = new HashMap<String, Object>();
+ Map<String, Object> result = new HashMap<>();
boolean isFailure = false;
boolean isError = false;
Modified: ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/ServiceSynchronization.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/ServiceSynchronization.java?rev=1811431&r1=1811430&r2=1811431&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/ServiceSynchronization.java (original)
+++ ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/ServiceSynchronization.java Sat Oct 7 14:30:13 2017
@@ -47,21 +47,17 @@ public class ServiceSynchronization impl
public static final String MODULE = ServiceSynchronization.class.getName();
- private static Map<Transaction, ServiceSynchronization> syncingleton = new WeakHashMap<Transaction, ServiceSynchronization>();
- private List<ServiceExecution> services = new ArrayList<ServiceExecution>();
+ private static Map<Transaction, ServiceSynchronization> syncingleton = new WeakHashMap<>();
+ private List<ServiceExecution> services = new ArrayList<>();
public static void registerCommitService(DispatchContext dctx, String serviceName, String runAsUser, Map<String, ? extends Object> context, boolean async, boolean persist) throws GenericServiceException {
ServiceSynchronization sync = ServiceSynchronization.getInstance();
- if (sync != null) {
- sync.services.add(new ServiceExecution(dctx, serviceName, runAsUser, context, async, persist, false));
- }
+ sync.services.add(new ServiceExecution(dctx, serviceName, runAsUser, context, async, persist, false));
}
public static void registerRollbackService(DispatchContext dctx, String serviceName, String runAsUser, Map<String, ? extends Object> context, boolean async, boolean persist) throws GenericServiceException {
ServiceSynchronization sync = ServiceSynchronization.getInstance();
- if (sync != null) {
- sync.services.add(new ServiceExecution(dctx, serviceName, runAsUser, context, async, persist, true));
- }
+ sync.services.add(new ServiceExecution(dctx, serviceName, runAsUser, context, async, persist, true));
}
protected static ServiceSynchronization getInstance() throws GenericServiceException {
@@ -141,7 +137,7 @@ public class ServiceSynchronization impl
if (model.validate) {
thisContext = model.makeValid(context, ModelService.IN_PARAM);
} else {
- thisContext = new HashMap<String, Object>();
+ thisContext = new HashMap<>();
thisContext.putAll(context);
}
Modified: ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/ServiceUtil.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/ServiceUtil.java?rev=1811431&r1=1811430&r2=1811431&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/ServiceUtil.java (original)
+++ ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/ServiceUtil.java Sat Oct 7 14:30:13 2017
@@ -118,18 +118,18 @@ public final class ServiceUtil {
}
public static Map<String, Object> returnProblem(String returnType, String errorMessage, List<? extends Object> errorMessageList, Map<String, ? extends Object> errorMessageMap, Map<String, ? extends Object> nestedResult) {
- Map<String, Object> result = new HashMap<String, Object>();
+ Map<String, Object> result = new HashMap<>();
result.put(ModelService.RESPONSE_MESSAGE, returnType);
if (errorMessage != null) {
result.put(ModelService.ERROR_MESSAGE, errorMessage);
}
- List<Object> errorList = new LinkedList<Object>();
+ List<Object> errorList = new LinkedList<>();
if (errorMessageList != null) {
errorList.addAll(errorMessageList);
}
- Map<String, Object> errorMap = new HashMap<String, Object>();
+ Map<String, Object> errorMap = new HashMap<>();
if (errorMessageMap != null) {
errorMap.putAll(errorMessageMap);
}
@@ -177,7 +177,7 @@ public final class ServiceUtil {
* and what type of message that is should be determined by the RESPONSE_MESSAGE (and there's another annoyance, it should be RESPONSE_CODE)
*/
public static Map<String, Object> returnMessage(String code, String message) {
- Map<String, Object> result = new HashMap<String, Object>();
+ Map<String, Object> result = new HashMap<>();
if (code != null) result.put(ModelService.RESPONSE_MESSAGE, code);
if (message != null) result.put(ModelService.SUCCESS_MESSAGE, message);
return result;
@@ -294,9 +294,8 @@ public final class ServiceUtil {
strBuf.append(outMsg.toString());
if (errorSuffix != null) strBuf.append(errorSuffix);
return strBuf.toString();
- } else {
- return null;
}
+ return null;
}
public static String makeSuccessMessage(Map<String, ? extends Object> result, String msgPrefix, String msgSuffix, String successPrefix, String successSuffix) {
@@ -321,9 +320,8 @@ public final class ServiceUtil {
strBuf.append(outMsg.toString());
if (successSuffix != null) strBuf.append(successSuffix);
return strBuf.toString();
- } else {
- return null;
}
+ return null;
}
public static String makeMessageList(List<? extends Object> msgList, String msgPrefix, String msgSuffix) {
@@ -476,7 +474,7 @@ public final class ServiceUtil {
// Now JobSandbox data is cleaned up. Now process Runtime data and remove the whole data in single shot that is of no need.
boolean beganTx3 = false;
GenericValue runtimeData = null;
- List<GenericValue> runtimeDataToDelete = new LinkedList<GenericValue>();
+ List<GenericValue> runtimeDataToDelete = new LinkedList<>();
long jobsandBoxCount = 0;
try {
// begin this transaction
@@ -554,16 +552,15 @@ public final class ServiceUtil {
return ServiceUtil.returnError(errMsg);
}
- Timestamp cancelDate = job.getTimestamp("cancelDateTime");
- if (cancelDate != null) {
+ if (job != null) {
+ Timestamp cancelDate = job.getTimestamp("cancelDateTime");
Map<String, Object> result = ServiceUtil.returnSuccess();
result.put("cancelDateTime", cancelDate);
result.put("statusId", "SERVICE_PENDING"); // To more easily see current pending jobs and possibly cancel some others
return result;
- } else {
- String errMsg = UtilProperties.getMessage(ServiceUtil.resource, "serviceUtil.unable_to_cancel_job", locale) + " : " + job;
- return ServiceUtil.returnError(errMsg);
}
+ String errMsg = UtilProperties.getMessage(ServiceUtil.resource, "serviceUtil.unable_to_cancel_job", locale) + " : " + null;
+ return ServiceUtil.returnError(errMsg);
}
public static Map<String, Object> cancelJobRetries(DispatchContext dctx, Map<String, ? extends Object> context) {
@@ -592,13 +589,11 @@ public final class ServiceUtil {
return ServiceUtil.returnError(errMsg);
}
- Timestamp cancelDate = job.getTimestamp("cancelDateTime");
- if (cancelDate != null) {
+ if (job != null) {
return ServiceUtil.returnSuccess();
- } else {
- String errMsg = UtilProperties.getMessage(ServiceUtil.resource, "serviceUtil.unable_to_cancel_job_retries", locale) + " : " + job;
- return ServiceUtil.returnError(errMsg);
}
+ String errMsg = UtilProperties.getMessage(ServiceUtil.resource, "serviceUtil.unable_to_cancel_job_retries", locale) + " : " + null;
+ return ServiceUtil.returnError(errMsg);
}
public static Map<String, Object> genericDateCondition(DispatchContext dctx, Map<String, ? extends Object> context) {
@@ -640,10 +635,11 @@ public final class ServiceUtil {
}
public static <T extends Object> Map<String, Object> makeContext(T... args) {
- if (args != null) {
- for (int i = 0; i < args.length; i += 2) {
- if (!(args[i] instanceof String)) throw new IllegalArgumentException("Arg(" + i + "), value(" + args[i] + ") is not a string.");
- }
+ if (args == null) {
+ throw new IllegalArgumentException("args is null in makeContext, this would throw a NullPointerExcption.");
+ }
+ for (int i = 0; i < args.length; i += 2) {
+ if (!(args[i] instanceof String)) throw new IllegalArgumentException("Arg(" + i + "), value(" + args[i] + ") is not a string.");
}
return UtilGenerics.checkMap(UtilMisc.toMap(args));
}
@@ -705,7 +701,7 @@ public final class ServiceUtil {
*/
public static Map<String, Object> setServiceFields(LocalDispatcher dispatcher, String serviceName, Map<String, Object> fromMap, GenericValue userLogin,
TimeZone timeZone, Locale locale) throws GeneralServiceException {
- Map<String, Object> outMap = new HashMap<String, Object>();
+ Map<String, Object> outMap = new HashMap<>();
ModelService modelService = null;
try {
Modified: ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/ServiceXaWrapper.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/ServiceXaWrapper.java?rev=1811431&r1=1811430&r2=1811431&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/ServiceXaWrapper.java (original)
+++ ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/ServiceXaWrapper.java Sat Oct 7 14:30:13 2017
@@ -262,6 +262,8 @@ public class ServiceXaWrapper extends Ge
case TYPE_COMMIT:
msgPrefix = "[Commit] ";
break;
+ default:
+ Debug.logWarning("There was another type instead of [Commit] or [Rollback] in runService: " + type, module);
}
// if a service exists; run it
@@ -295,7 +297,7 @@ public class ServiceXaWrapper extends Ge
if (model.validate) {
thisContext = model.makeValid(context, ModelService.IN_PARAM);
} else {
- thisContext = new HashMap<String, Object>();
+ thisContext = new HashMap<>();
thisContext.putAll(context);
}