use of io.apiman.common.logging.IApimanLogger in project apiman-plugins by apiman.
the class LogHeadersPolicy method doApply.
/**
* @see io.apiman.gateway.engine.policies.AbstractMappedPolicy#doApply(io.apiman.gateway.engine.beans.ApiResponse, io.apiman.gateway.engine.policy.IPolicyContext, java.lang.Object, io.apiman.gateway.engine.policy.IPolicyChain)
*/
@Override
protected void doApply(ApiResponse response, IPolicyContext context, LogHeadersConfigBean config, IPolicyChain<ApiResponse> chain) {
IApimanLogger logger = context.getLogger(getClass());
if (config.getDirection() != LogHeadersDirectionType.request) {
// $NON-NLS-1$
String endpoint = context.getAttribute(ENDPOINT_ATTRIBUTE, "");
if (config.isLogStatusCode()) {
logger.info(String.format("Status code %d for %s", response.getCode(), endpoint));
}
if (config.isLogHeaders()) {
logHeaders(logger, response.getHeaders(), HttpDirection.RESPONSE, endpoint);
}
}
chain.doApply(response);
}
use of io.apiman.common.logging.IApimanLogger in project apiman by apiman.
the class StorageImportDispatcher method start.
/**
* Set an additional logger implementations.
*
* @see #start(String, IApimanLogger)
*/
public void start(String fileName, List<IApimanLogger> extraLoggers) {
ArrayList<IApimanLogger> delegates = new ArrayList<>(extraLoggers.size() + 1);
delegates.addAll(extraLoggers);
delegates.add(logger);
this.logger = new MultiLogger(delegates);
start(fileName);
}
use of io.apiman.common.logging.IApimanLogger in project apiman by apiman.
the class SystemResourceImpl method exportData.
/**
* @see ISystemResource#exportData()
*/
@Override
public Response exportData() {
final IApimanLogger exportLogger = ApimanLoggerFactory.getLogger(IExportWriter.class);
StreamingOutput stream = new StreamingOutput() {
@Override
public void write(OutputStream os) throws IOException, WebApplicationException {
IExportWriter writer = new JsonExportWriter(os, exportLogger);
exporter.init(writer);
exporter.export();
os.flush();
}
};
return Response.ok(stream, MediaType.APPLICATION_JSON).header("Content-Disposition", // $NON-NLS-1$ //$NON-NLS-2$
"attachment; filename=api-manager-export.json").build();
}
use of io.apiman.common.logging.IApimanLogger in project apiman by apiman.
the class SystemResourceImpl method importData.
/**
* @see ISystemResource#importData()
*/
@Override
public Response importData() throws NotAuthorizedException {
securityContext.checkAdminPermissions();
// First, stream the import data to a temporary file. We do this so
// that we can stream the import logging statements back to the HTTP
// response. We can't stream the inbound data into the importer
// *and* stream the importer's logging output back to the HTTP
// response at the same time due to the nature of HTTP.
File tempFile;
InputStream data;
try {
// $NON-NLS-1$ //$NON-NLS-2$
tempFile = File.createTempFile("apiman_import", ".json");
tempFile.deleteOnExit();
data = request.getInputStream();
FileUtils.copyInputStreamToFile(data, tempFile);
} catch (IOException e) {
throw new RuntimeException(e);
}
final File importFile = tempFile;
// Next, do the import and stream the import logging output back to
// the HTTP response output stream.
StreamingOutput stream = new StreamingOutput() {
@Override
public void write(final OutputStream output) throws IOException, WebApplicationException {
final PrintWriter writer = new PrintWriter(output);
IApimanLogger logger = new IApimanLogger() {
@Override
public void warn(String message) {
// $NON-NLS-1$
writer.println("WARN: " + message);
writer.flush();
}
@Override
public void warn(String message, Object... args) {
warn(MessageFormat.format(message, args));
}
@Override
public void trace(String message) {
// $NON-NLS-1$
writer.println("TRACE: " + message);
writer.flush();
}
@Override
public void trace(String message, Object... args) {
trace(MessageFormat.format(message, args));
}
@Override
public void info(String message) {
// $NON-NLS-1$
writer.println("INFO: " + message);
writer.flush();
}
@Override
public void info(String message, Object... args) {
info(MessageFormat.format(message, args));
}
@Override
public void error(String message, Throwable error) {
// $NON-NLS-1$
writer.println("ERROR: " + message);
error.printStackTrace(writer);
writer.flush();
}
@Override
public void error(Throwable error) {
// $NON-NLS-1$
writer.println("ERROR: " + error.getMessage());
error.printStackTrace(writer);
writer.flush();
}
@Override
public void error(Throwable error, String message, Object... args) {
error(MessageFormat.format(message, args), error);
}
@Override
public void debug(String message) {
// $NON-NLS-1$
writer.println("DEBUG: " + message);
writer.flush();
}
@Override
public void debug(String message, Object... args) {
debug(MessageFormat.format(message, args));
}
};
// which can mess with our CDI interceptors.
try {
storage.beginTx();
importExportService.fullImport(importFile, logger);
storage.commitTx();
} catch (Exception e) {
logger.error(e);
storage.rollbackTx();
throw new IOException(e);
} finally {
writer.flush();
writer.close();
output.close();
}
}
};
return Response.ok(stream).build();
}
use of io.apiman.common.logging.IApimanLogger in project apiman-plugins by apiman.
the class LogHeadersPolicy method doApply.
/**
* @see io.apiman.gateway.engine.policies.AbstractMappedPolicy#doApply(io.apiman.gateway.engine.beans.ApiRequest, io.apiman.gateway.engine.policy.IPolicyContext, java.lang.Object, io.apiman.gateway.engine.policy.IPolicyChain)
*/
@Override
protected void doApply(ApiRequest request, IPolicyContext context, LogHeadersConfigBean config, IPolicyChain<ApiRequest> chain) {
IApimanLogger logger = context.getLogger(getClass());
String endpoint = request.getApi().getEndpoint();
context.setAttribute(ENDPOINT_ATTRIBUTE, endpoint);
if (config.isLogHeaders() && config.getDirection() != LogHeadersDirectionType.response) {
logHeaders(logger, request.getHeaders(), HttpDirection.REQUEST, endpoint);
}
chain.doApply(request);
}
Aggregations