refactor: use parseInt instead of ctor/new Integer
MODIFY
common/config/src/main/java/io/apiman/common/config/options/AbstractOptions.java
common/config/src/main/java/io/apiman/common/config/options/AbstractOptions.java
@@ -72,7 +72,7 @@ public abstract class AbstractOptions {
protected static int parseInt(Map<String, String> optionsMap, String key, int defaultValue) {
if (optionsMap.containsKey(key)) {
- return Integer.valueOf(optionsMap.get(key));
+ return Integer.parseInt(optionsMap.get(key));
}
return defaultValue;
}

MODIFY
gateway/engine/core/src/test/java/io/apiman/gateway/engine/impl/DefaultJdbcComponentTest.java
gateway/engine/core/src/test/java/io/apiman/gateway/engine/impl/DefaultJdbcComponentTest.java
@@ -203,7 +203,7 @@ public class DefaultJdbcComponentTest {
result.next();
Assert.assertEquals("ewittman", result.getString(1));
Assert.assertEquals("Eric Wittmann", result.getString(2));
- Assert.assertEquals(new Integer(17), result.getInteger(3));
+ Assert.assertEquals(Integer.valueOf(17), result.getInteger(3));
Assert.assertEquals(Boolean.TRUE, result.getBoolean(4));
Assert.assertFalse(result.hasNext());
}

MODIFY
gateway/engine/es/src/main/java/io/apiman/gateway/engine/es/EsMetrics.java
gateway/engine/es/src/main/java/io/apiman/gateway/engine/es/EsMetrics.java
@@ -73,14 +73,14 @@ public class EsMetrics extends AbstractEsComponent implements IMetrics {
int queueSize = DEFAULT_QUEUE_SIZE;
String queueSizeConfig = config.get("queue.size"); //$NON-NLS-1$
if (queueSizeConfig != null) {
- queueSize = new Integer(queueSizeConfig);
+ queueSize = Integer.parseInt(queueSizeConfig);
}
queue = new LinkedBlockingDeque<>(queueSize);
int batchSize = DEFAULT_BATCH_SIZE;
String batchSizeConfig = config.get("batch.size"); //$NON-NLS-1$
if (batchSizeConfig != null) {
- batchSize = new Integer(batchSizeConfig);
+ batchSize = Integer.parseInt(batchSizeConfig);
}
this.batchSize = batchSize;

MODIFY
gateway/engine/es/src/main/java/io/apiman/gateway/engine/es/PollCachingEsRegistry.java
gateway/engine/es/src/main/java/io/apiman/gateway/engine/es/PollCachingEsRegistry.java
@@ -48,8 +48,8 @@ public class PollCachingEsRegistry extends CachingEsRegistry {
private static final int DEFAULT_POLLING_INTERVAL = 10;
private static final int DEFAULT_STARTUP_DELAY = 30;
- private int pollIntervalMillis;
- private int startupDelayMillis;
+ private final int pollIntervalMillis;
+ private final int startupDelayMillis;
private boolean polling = false;
private String dataVersion = null;
@@ -67,13 +67,13 @@ public class PollCachingEsRegistry extends CachingEsRegistry {
String startupVal = config.get("cache-polling-startup-delay"); //$NON-NLS-1$
if (intervalVal != null) {
- pollIntervalMillis = new Integer(intervalVal) * 1000;
+ pollIntervalMillis = Integer.parseInt(intervalVal) * 1000;
} else {
pollIntervalMillis = DEFAULT_POLLING_INTERVAL * 1000;
}
if (startupVal != null) {
- startupDelayMillis = new Integer(startupVal) * 1000;
+ startupDelayMillis = Integer.parseInt(startupVal) * 1000;
} else {
startupDelayMillis = DEFAULT_STARTUP_DELAY * 1000;
}

MODIFY
gateway/engine/jdbc/src/main/java/io/apiman/gateway/engine/jdbc/JdbcMetrics.java
gateway/engine/jdbc/src/main/java/io/apiman/gateway/engine/jdbc/JdbcMetrics.java
@@ -61,7 +61,7 @@ public class JdbcMetrics extends AbstractJdbcComponent implements IMetrics {
int queueSize = DEFAULT_QUEUE_SIZE;
String queueSizeConfig = config.get("queue.size"); //$NON-NLS-1$
if (queueSizeConfig != null) {
- queueSize = Integer.valueOf(queueSizeConfig);
+ queueSize = Integer.parseInt(queueSizeConfig);
}
queue = new LinkedBlockingDeque<>(queueSize);
startConsumerThread();

MODIFY
gateway/engine/jdbc/src/main/java/io/apiman/gateway/engine/jdbc/PollCachingJdbcRegistry.java
gateway/engine/jdbc/src/main/java/io/apiman/gateway/engine/jdbc/PollCachingJdbcRegistry.java
*/
package io.apiman.gateway.engine.jdbc;
+import io.apiman.common.logging.ApimanLoggerFactory;
+import io.apiman.common.logging.IApimanLogger;
import io.apiman.gateway.engine.async.IAsyncResult;
import io.apiman.gateway.engine.async.IAsyncResultHandler;
import io.apiman.gateway.engine.beans.Api;
@@ -41,6 +43,8 @@ import org.apache.commons.dbutils.ResultSetHandler;
*/
public class PollCachingJdbcRegistry extends CachingJdbcRegistry {
+ private static final IApimanLogger LOGGER = ApimanLoggerFactory.getLogger(PollCachingJdbcRegistry.class);
+
private static final int DEFAULT_POLLING_INTERVAL = 10;
private static final int DEFAULT_STARTUP_DELAY = 30;
@@ -50,6 +54,7 @@ public class PollCachingJdbcRegistry extends CachingJdbcRegistry {
private boolean polling = false;
private long dataVersion = -1;
+
/**
* Constructor.
*/
@@ -60,13 +65,13 @@ public class PollCachingJdbcRegistry extends CachingJdbcRegistry {
String startupVal = config.get("cache-polling-startup-delay"); //$NON-NLS-1$
if (intervalVal != null) {
- pollIntervalMillis = new Integer(intervalVal) * 1000;
+ pollIntervalMillis = Integer.parseInt(intervalVal) * 1000;
} else {
pollIntervalMillis = DEFAULT_POLLING_INTERVAL * 1000;
}
if (startupVal != null) {
- startupDelayMillis = new Integer(startupVal) * 1000;
+ startupDelayMillis = Integer.parseInt(startupVal) * 1000;
} else {
startupDelayMillis = DEFAULT_STARTUP_DELAY * 1000;
}
@@ -74,9 +79,6 @@ public class PollCachingJdbcRegistry extends CachingJdbcRegistry {
startCacheInvalidator();
}
- /**
- * @see io.apiman.gateway.engine.CachingJdbcRegistry.CachingEsRegistry#publishApi(io.apiman.gateway.engine.beans.Api, io.apiman.gateway.engine.async.IAsyncResultHandler)
- */
@Override
public void publishApi(Api api, final IAsyncResultHandler<Void> handler) {
super.publishApi(api, new IAsyncResultHandler<Void>() {
@@ -90,9 +92,6 @@ public class PollCachingJdbcRegistry extends CachingJdbcRegistry {
});
}
- /**
- * @see io.apiman.gateway.engine.CachingJdbcRegistry.CachingEsRegistry#retireApi(io.apiman.gateway.engine.beans.Api, io.apiman.gateway.engine.async.IAsyncResultHandler)
- */
@Override
public void retireApi(Api api, final IAsyncResultHandler<Void> handler) {
super.retireApi(api, new IAsyncResultHandler<Void>() {
@@ -106,9 +105,6 @@ public class PollCachingJdbcRegistry extends CachingJdbcRegistry {
});
}
- /**
- * @see io.apiman.gateway.engine.CachingJdbcRegistry.CachingEsRegistry#registerClient(io.apiman.gateway.engine.beans.Client, io.apiman.gateway.engine.async.IAsyncResultHandler)
- */
@Override
public void registerClient(Client client, final IAsyncResultHandler<Void> handler) {
super.registerClient(client, new IAsyncResultHandler<Void>() {
@@ -125,9 +121,6 @@ public class PollCachingJdbcRegistry extends CachingJdbcRegistry {
});
}
- /**
- * @see io.apiman.gateway.engine.CachingJdbcRegistry.CachingEsRegistry#unregisterClient(io.apiman.gateway.engine.beans.Client, io.apiman.gateway.engine.async.IAsyncResultHandler)
- */
@Override
public void unregisterClient(Client client, final IAsyncResultHandler<Void> handler) {
super.unregisterClient(client, new IAsyncResultHandler<Void>() {
@@ -210,8 +203,7 @@ public class PollCachingJdbcRegistry extends CachingJdbcRegistry {
dataVersion = latestVersion;
}
} catch (SQLException e) {
- // TODO need to use the gateway logger to log this!
- e.printStackTrace();
+ LOGGER.error("SQL problem encountered while running latest version query: " + e.getMessage(), e);
}
if (invalidate) {
invalidateCache();

MODIFY
gateway/engine/policies/src/test/java/io/apiman/gateway/engine/policies/TransferQuotaPolicyTest.java
gateway/engine/policies/src/test/java/io/apiman/gateway/engine/policies/TransferQuotaPolicyTest.java
@@ -286,14 +286,13 @@ public class TransferQuotaPolicyTest extends ApimanPolicyTest {
int payloadSize = 20;
String payloadSizeHeader = request.getHeaders().get("X-Payload-Size");
if (payloadSizeHeader != null) {
- payloadSize = new Integer(payloadSizeHeader);
+ payloadSize = Integer.parseInt(payloadSizeHeader);
}
byte [] payloadData = new byte[payloadSize];
Arrays.fill(payloadData, (byte) 80);
String payload = new String(payloadData);
- PolicyTestBackEndApiResponse response = new PolicyTestBackEndApiResponse(apiResponse, payload);
- return response;
+ return new PolicyTestBackEndApiResponse(apiResponse, payload);
}
}

MODIFY
gateway/platforms/servlet/src/main/java/io/apiman/gateway/platforms/servlet/connectors/HttpApiConnection.java
gateway/platforms/servlet/src/main/java/io/apiman/gateway/platforms/servlet/connectors/HttpApiConnection.java
@@ -219,7 +219,7 @@ public class HttpApiConnection implements IApiConnection, IApiConnectionResponse
try {
Map<String, String> endpointProperties = this.api.getEndpointProperties();
if (endpointProperties.containsKey("timeouts.connect")) { //$NON-NLS-1$
- int connectTimeoutMs = new Integer(endpointProperties.get("timeouts.connect")); //$NON-NLS-1$
+ int connectTimeoutMs = Integer.parseInt(endpointProperties.get("timeouts.connect")); //$NON-NLS-1$
connection.setConnectTimeout(connectTimeoutMs);
}
} catch (Throwable t) {
@@ -235,7 +235,7 @@ public class HttpApiConnection implements IApiConnection, IApiConnectionResponse
try {
Map<String, String> endpointProperties = this.api.getEndpointProperties();
if (endpointProperties.containsKey("timeouts.read")) { //$NON-NLS-1$
- int connectTimeoutMs = new Integer(endpointProperties.get("timeouts.read")); //$NON-NLS-1$
+ int connectTimeoutMs = Integer.parseInt(endpointProperties.get("timeouts.read")); //$NON-NLS-1$
connection.setReadTimeout(connectTimeoutMs);
}
} catch (Throwable t) {

MODIFY
gateway/platforms/vertx3/vertx3/src/main/java/io/apiman/gateway/platforms/vertx3/common/config/VertxEngineConfig.java
gateway/platforms/vertx3/vertx3/src/main/java/io/apiman/gateway/platforms/vertx3/common/config/VertxEngineConfig.java
@@ -388,7 +388,7 @@ public class VertxEngineConfig implements IEngineConfig {
if (val instanceof Number) {
return (int) val;
} else if (val instanceof String) {
- return Integer.valueOf((String)val);
+ return Integer.parseInt((String)val);
}
throw new IllegalArgumentException("Expected integer, got " + obj.getClass().getName());
}
@@ -398,8 +398,7 @@ public class VertxEngineConfig implements IEngineConfig {
* @return a loaded class
*/
@SuppressWarnings("unchecked")
- protected <T> Class<? extends T> loadConfigClass(String className, Class<T> type, IPluginRegistry pluginRegistry, Class<? extends T> defaultClass) {
- String componentSpec = className;
+ protected <T> Class<? extends T> loadConfigClass(String componentSpec, Class<T> type, IPluginRegistry pluginRegistry, Class<? extends T> defaultClass) {
if (componentSpec == null) {
return defaultClass;
}
@@ -432,8 +431,8 @@ public class VertxEngineConfig implements IEngineConfig {
return (Class<T>) c;
}
} catch (ClassNotFoundException | InterruptedException | ExecutionException e) {
- e.printStackTrace();
- throw new IllegalStateException(Messages.getString("EngineConfig.FailedToLoadClass") + className);
+ logger.error("Failed to load class " + componentSpec, e);
+ throw new IllegalStateException(Messages.getString("EngineConfig.FailedToLoadClass") + componentSpec, e);
}
}

MODIFY
manager/api/gateway/src/main/java/io/apiman/manager/api/gateway/rest/GatewayClient.java
manager/api/gateway/src/main/java/io/apiman/manager/api/gateway/rest/GatewayClient.java
@@ -360,7 +360,7 @@ public class GatewayClient /*implements ISystemResource, IApiResource, IClientRe
} else {
String fileName = split[0];
String lineNum = split[1];
- elements.add(new StackTraceElement(className, methodName, fileName, new Integer(lineNum)));
+ elements.add(new StackTraceElement(className, methodName, fileName, Integer.parseInt(lineNum)));
}
}
}

MODIFY
manager/api/migrator/src/main/java/io/apiman/manager/api/migrator/VersionMigrators.java
manager/api/migrator/src/main/java/io/apiman/manager/api/migrator/VersionMigrators.java
@@ -90,9 +90,9 @@ public class VersionMigrators {
public VersionComponents(String version) {
@SuppressWarnings("nls")
String[] split = version.replace("-SNAPSHOT", "").split("\\.");
- major = new Integer(split[0]);
- minor = new Integer(split[1]);
- patch = new Integer(split[2]);
+ major = Integer.parseInt(split[0]);
+ minor = Integer.parseInt(split[1]);
+ patch = Integer.parseInt(split[2]);
}
/**

MODIFY
test/common/src/main/java/io/apiman/test/common/mock/EchoServlet.java
test/common/src/main/java/io/apiman/test/common/mock/EchoServlet.java
@@ -153,7 +153,7 @@ public class EchoServlet extends HttpServlet {
String acceptHeader = req.getHeader("Accept");
String errorCode = req.getHeader("X-Echo-ErrorCode");
if (errorCode != null) {
- int ec = new Integer(errorCode);
+ int ec = Integer.parseInt(errorCode);
String errorMsg = req.getHeader("X-Echo-ErrorMessage");
resp.sendError(ec, errorMsg);
return;

MODIFY
test/common/src/main/java/io/apiman/test/common/util/TestUtil.java
test/common/src/main/java/io/apiman/test/common/util/TestUtil.java
@@ -162,7 +162,7 @@ public class TestUtil {
// Response
// Expected Status Code
line = reader.readLine();
- rval.setExpectedStatusCode(new Integer(line.trim()));
+ rval.setExpectedStatusCode(Integer.parseInt(line.trim()));
// Expected Response Headers
line = reader.readLine();

MODIFY
test/policies/src/main/java/io/apiman/test/policies/EchoBackEndApi.java
test/policies/src/main/java/io/apiman/test/policies/EchoBackEndApi.java
@@ -59,7 +59,7 @@ public class EchoBackEndApi implements IPolicyTestBackEndApi {
String errorCode = request.getHeaders().get("X-Echo-ErrorCode");
if (errorCode != null) {
- int ec = new Integer(errorCode);
+ int ec = Integer.parseInt(errorCode);
String errorMsg = request.getHeaders().get("X-Echo-ErrorMessage");
apiResponse.setCode(ec);
apiResponse.setMessage(errorMsg);

refactor: use parseInt instead of ctor/new Integer