refactor: use new Apiman logging framework everywhere
MODIFY
gateway/engine/core/src/main/java/io/apiman/gateway/engine/impl/DefaultPolicyErrorWriter.java
gateway/engine/core/src/main/java/io/apiman/gateway/engine/impl/DefaultPolicyErrorWriter.java
*/
package io.apiman.gateway.engine.impl;
-import io.apiman.common.logging.DefaultDelegateFactory;
+import io.apiman.common.logging.ApimanLoggerFactory;
import io.apiman.common.logging.IApimanLogger;
import io.apiman.gateway.engine.IApiClientResponse;
import io.apiman.gateway.engine.IPolicyErrorWriter;
@@ -24,7 +24,6 @@ import io.apiman.gateway.engine.beans.EngineErrorResponse;
import io.apiman.gateway.engine.beans.exceptions.IStatusCode;
import java.io.StringWriter;
-
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
@@ -38,7 +37,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
*/
public class DefaultPolicyErrorWriter implements IPolicyErrorWriter {
- private IApimanLogger logger = new DefaultDelegateFactory().createLogger(DefaultPolicyErrorWriter.class);
+ private static final IApimanLogger LOGGER = ApimanLoggerFactory.getLogger(DefaultPolicyErrorWriter.class);
private static final ObjectMapper mapper = new ObjectMapper();
private static JAXBContext jaxbContext;
@@ -67,7 +66,7 @@ public class DefaultPolicyErrorWriter implements IPolicyErrorWriter {
isXml = true;
}
String message = createErrorMessage(request, error);
- logger.error(message, error);
+ LOGGER.error(message, error);
response.setHeader("X-Gateway-Error", message);
int statusCode = 500;
@@ -86,7 +85,7 @@ public class DefaultPolicyErrorWriter implements IPolicyErrorWriter {
jaxbMarshaller.marshal(eer, sw);
response.write(sw.getBuffer());
} catch (Exception e) {
- logger.error(e);
+ LOGGER.error(e);
}
} else {
response.setHeader("Content-Type", "application/json");
@@ -95,7 +94,7 @@ public class DefaultPolicyErrorWriter implements IPolicyErrorWriter {
mapper.writer().writeValue(sw, eer);
response.write(sw.getBuffer());
} catch (Exception e) {
- logger.error(e);
+ LOGGER.error(e);
}
}
}

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
@@ -56,7 +56,7 @@ import static io.apiman.gateway.engine.storage.util.BackingStoreUtil.JSON_MAPPER
*/
public class EsMetrics extends AbstractEsComponent implements IMetrics {
- private static final IApimanLogger logger = ApimanLoggerFactory.getLogger(EsMetrics.class);
+ private static final IApimanLogger LOGGER = ApimanLoggerFactory.getLogger(EsMetrics.class);
private static final int DEFAULT_QUEUE_SIZE = 10000;
private static final int DEFAULT_BATCH_SIZE = 1000;
@@ -147,12 +147,12 @@ public class EsMetrics extends AbstractEsComponent implements IMetrics {
@Override
public void onFailure(Exception e) {
- logger.error("Failed to add metric(s) to ES", e); //$NON-NLS-1$
+ LOGGER.error("Failed to add metric(s) to ES", e); //$NON-NLS-1$
}
};
client.bulkAsync(request, RequestOptions.DEFAULT, listener);
} catch (InterruptedException | JsonProcessingException e) {
- logger.error("Failed to add metric(s) to ES", e); //$NON-NLS-1$
+ LOGGER.error("Failed to add metric(s) to ES", e); //$NON-NLS-1$
}
}

MODIFY
gateway/engine/es/src/main/java/io/apiman/gateway/engine/es/EsRegistry.java
gateway/engine/es/src/main/java/io/apiman/gateway/engine/es/EsRegistry.java
@@ -19,7 +19,7 @@ import io.apiman.common.es.util.AbstractEsComponent;
import io.apiman.common.es.util.EsConstants;
import io.apiman.common.es.util.EsUtils;
import io.apiman.common.es.util.builder.index.EsIndexProperties;
-import io.apiman.common.logging.DefaultDelegateFactory;
+import io.apiman.common.logging.ApimanLoggerFactory;
import io.apiman.common.logging.IApimanLogger;
import io.apiman.gateway.engine.IRegistry;
import io.apiman.gateway.engine.async.AsyncResultImpl;
@@ -75,7 +75,7 @@ import static io.apiman.gateway.engine.storage.util.BackingStoreUtil.JSON_MAPPER
*/
public class EsRegistry extends AbstractEsComponent implements IRegistry {
- private IApimanLogger logger = new DefaultDelegateFactory().createLogger(EsRegistry.class);
+ private final IApimanLogger LOGGER = ApimanLoggerFactory.getLogger(EsRegistry.class);
/**
* Constructor.
@@ -433,7 +433,7 @@ public class EsRegistry extends AbstractEsComponent implements IRegistry {
handler.handle(AsyncResultImpl.create(results));
}
catch (IOException e) {
- logger.error(e.getMessage(), e);
+ LOGGER.error(e.getMessage(), e);
}
}
@@ -461,7 +461,7 @@ public class EsRegistry extends AbstractEsComponent implements IRegistry {
handler.handle(AsyncResultImpl.create(results));
}
catch (IOException e) {
- logger.error(e.getMessage(), e);
+ LOGGER.error(e.getMessage(), e);
}
}
@@ -488,7 +488,7 @@ public class EsRegistry extends AbstractEsComponent implements IRegistry {
handler.handle(AsyncResultImpl.create(results));
}
catch (IOException e) {
- logger.error(e.getMessage(), e);
+ LOGGER.error(e.getMessage(), e);
}
}
@@ -544,7 +544,7 @@ public class EsRegistry extends AbstractEsComponent implements IRegistry {
handler.handle(AsyncResultImpl.create(results));
} catch (IOException e) {
- logger.error(e.getMessage(), e);
+ LOGGER.error(e.getMessage(), e);
}
}
@@ -601,7 +601,7 @@ public class EsRegistry extends AbstractEsComponent implements IRegistry {
handler.handle(AsyncResultImpl.create(results));
} catch (IOException e) {
- logger.error(e.getMessage(), e);
+ LOGGER.error(e.getMessage(), e);
}
}

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
@@ -18,21 +18,22 @@ package io.apiman.gateway.engine.es;
import io.apiman.common.es.util.EsConstants;
import io.apiman.common.es.util.builder.index.EsIndexProperties;
import io.apiman.common.es.util.builder.index.EsIndexUtils;
-import io.apiman.common.logging.DefaultDelegateFactory;
+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;
import io.apiman.gateway.engine.beans.Client;
+
+import java.io.IOException;
+import java.util.Map;
+
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.get.GetRequest;
import org.elasticsearch.action.get.GetResponse;
import org.elasticsearch.action.index.IndexRequest;
import org.elasticsearch.client.RequestOptions;
-import java.io.IOException;
-import java.util.Map;
-
/**
* Extends the {@link EsRegistry} to provide multi-node caching. This caching solution
* will work in a cluster, although it is a rather naive implementation. The approach
@@ -54,7 +55,7 @@ public class PollCachingEsRegistry extends CachingEsRegistry {
private boolean polling = false;
private String dataVersion = null;
- private IApimanLogger logger = new DefaultDelegateFactory().createLogger(PollCachingEsRegistry.class);
+ private IApimanLogger LOGGER = ApimanLoggerFactory.getLogger(PollCachingEsRegistry.class);
/**
* Constructor.
@@ -188,7 +189,7 @@ public class PollCachingEsRegistry extends CachingEsRegistry {
Thread.sleep(pollIntervalMillis);
checkCacheVersion();
} catch (Exception e) {
- logger.error(e.getMessage(), e);
+ LOGGER.error(e.getMessage(), e);
}
}

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
package io.apiman.gateway.platforms.servlet.connectors;
import io.apiman.common.config.options.BasicAuthOptions;
-import io.apiman.common.logging.DefaultDelegateFactory;
+import io.apiman.common.logging.ApimanLoggerFactory;
import io.apiman.common.logging.IApimanLogger;
import io.apiman.common.util.ApimanPathUtils;
import io.apiman.gateway.engine.IApiConnection;
@@ -40,38 +40,34 @@ import io.apiman.gateway.platforms.servlet.connectors.ssl.SSLSessionStrategy;
import java.io.IOException;
import java.io.InputStream;
-import java.io.InterruptedIOException;
import java.io.OutputStream;
-import java.net.ConnectException;
import java.net.HttpURLConnection;
-import java.net.NoRouteToHostException;
-import java.net.SocketTimeoutException;
import java.net.URL;
import java.net.URLEncoder;
-import java.net.UnknownHostException;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
-
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLSocketFactory;
+import com.squareup.okhttp.OkHttpClient;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.io.IOUtils;
-import com.squareup.okhttp.OkHttpClient;
-
/**
* Models a live connection to a back end API.
*
* @author eric.wittmann@redhat.com
*/
public class HttpApiConnection implements IApiConnection, IApiConnectionResponse {
- private ApiRequest request;
- private Api api;
- private RequiredAuthType requiredAuthType;
- private SSLSessionStrategy sslStrategy;
- private IAsyncResultHandler<IApiConnectionResponse> responseHandler;
+
+ private static final IApimanLogger LOGGER = ApimanLoggerFactory.getLogger(DefaultPolicyErrorWriter.class);
+
+ private final ApiRequest request;
+ private final Api api;
+ private final RequiredAuthType requiredAuthType;
+ private final SSLSessionStrategy sslStrategy;
+ private final IAsyncResultHandler<IApiConnectionResponse> responseHandler;
private boolean connected;
private HttpURLConnection connection;
@@ -81,14 +77,12 @@ public class HttpApiConnection implements IApiConnection, IApiConnectionResponse
private IAsyncHandler<Void> endHandler;
private ApiResponse response;
- final private OkHttpClient client;
- private boolean hasDataPolicy;
+ private final OkHttpClient client;
+ private final boolean hasDataPolicy;
private boolean isError = false;
- private IConnectorConfig connectorConfig;
-
- private IApimanLogger logger = new DefaultDelegateFactory().createLogger(DefaultPolicyErrorWriter.class);
+ private final IConnectorConfig connectorConfig;
/**
* Constructor.
@@ -405,7 +399,7 @@ public class HttpApiConnection implements IApiConnection, IApiConnectionResponse
private void handleConnectionError(Exception error) {
ConnectorException ce = ErrorHandler.handleConnectionError(error);
- logger.error(error.getMessage(), error);
+ LOGGER.error(error.getMessage(), error);
throw ce;
}
}

refactor: use new Apiman logging framework everywhere