Skip to content

Commit

Permalink
Merge pull request #25 from aol/access_log_issue
Browse files Browse the repository at this point in the history
Fix for issue access log issue
  • Loading branch information
kewangie committed Jun 10, 2015
2 parents 674b66f + 72ef037 commit bb41978
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.aol.micro.server.events.ConfigureActiveJobsAspect;
import com.aol.micro.server.module.ConfigureEnviroment;
import com.aol.micro.server.rest.resources.ConfigureResources;
import com.aol.micro.server.servers.AccessLogConfig;
import com.aol.micro.server.spring.datasource.DataSourceBuilder;
import com.aol.micro.server.spring.datasource.JdbcConfig;
import com.aol.micro.server.spring.datasource.hibernate.DAOProvider;
Expand Down Expand Up @@ -36,7 +37,7 @@ public enum Classes {
* Codahale Metrics, Event tracking etc
*/
CORE_CLASSES(PropertyFileConfig.class, MiscellaneousConfig.class, AopConfig.class, CodahaleMetricsConfigurer.class,
ConfigureActiveJobsAspect.class, ScheduleAndAsyncConfig.class, ConfigureResources.class, ConfigureEnviroment.class),
ConfigureActiveJobsAspect.class, ScheduleAndAsyncConfig.class, ConfigureResources.class, ConfigureEnviroment.class, AccessLogConfig.class),
JDBC_CLASSES(JdbcConfig.class, DAOProvider.class, DataSourceBuilder.class, SQL.class, SpringDataConfig.class),
ROMA_ROW_MAPPER(RomaRowMapperConfig.class),
HIBERNATE_CLASSES(HibernateConfig.class, JdbcConfig.class, GenericHibernateService.class, DAOProvider.class, DataSourceBuilder.class, SQL.class),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.aol.micro.server.servers;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class AccessLogConfig {

@Value("${access.log.output:./logs}")
private String accessLogLocation;

@Bean
public AccessLogLocationBean accessLogLocationBean() {
return new AccessLogLocationBean(accessLogLocation);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public void run(CompletableFuture start, CompletableFuture end) {

WebappContext webappContext = new WebappContext("WebappContext", "");

new ServletContextListenerConfigurer(serverData, servletContextListenerData,servletRequestListenerData);
new ServletContextListenerConfigurer(serverData, servletContextListenerData, servletRequestListenerData);

addServlet(webappContext);

Expand Down Expand Up @@ -109,7 +109,7 @@ private void addAccessLog(HttpServer httpServer) {
try {
String accessLogLocation = serverData.getRootContext().getBean(AccessLogLocationBean.class).getAccessLogLocation();

accessLogLocation = accessLogLocation + replaceSlash(serverData.getModule().getContext()) + "-access.log";
accessLogLocation = accessLogLocation + "/" + replaceSlash(serverData.getModule().getContext()) + "-access.log";
final AccessLogBuilder builder = new AccessLogBuilder(accessLogLocation);

builder.rotatedDaily();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package com.aol.micro.server.spring;

import java.util.Optional;
import java.util.Properties;
import java.util.stream.Stream;

import javax.sql.DataSource;

Expand All @@ -16,14 +14,11 @@

import com.aol.micro.server.config.Config;
import com.aol.micro.server.config.ConfigAccessor;
import com.aol.micro.server.config.Microserver;
import com.aol.micro.server.servers.AccessLogLocationBean;
import com.aol.micro.server.spring.datasource.DataSourceBuilder;
import com.aol.micro.server.spring.datasource.JdbcConfig;
import com.aol.micro.server.spring.datasource.hibernate.DAOBuilder;
import com.aol.micro.server.spring.datasource.hibernate.DAOProvider;
import com.aol.micro.server.spring.datasource.hibernate.HibernateSessionBuilder;
import com.aol.micro.server.utility.UsefulStaticMethods;

class SpringApplicationConfigurator implements SpringBuilder {
private final Logger logger = LoggerFactory.getLogger(this.getClass());
Expand All @@ -35,14 +30,11 @@ public ConfigurableApplicationContext createSpringApp(Config config, Class... cl
rootContext.setAllowCircularReferences(config.isAllowCircularReferences());
rootContext.register(classes);


rootContext.scan(config.getBasePackages());
rootContext.refresh();
logger.debug("Configuring Additional Spring Beans");
ConfigurableListableBeanFactory beanFactory = ((ConfigurableApplicationContext) rootContext).getBeanFactory();

beanFactory.registerSingleton(AccessLogLocationBean.class.getCanonicalName(), createAccessLogLocationBean(rootContext));

config.getDataSources().keySet().stream().filter(it -> !new ConfigAccessor().get().getDefaultDataSourceName().equals(it)).forEach(name -> {
JdbcConfig jdbc = buildJdbcProperties(rootContext, name);
DataSource dataSource = buildDataSource(name, jdbc);
Expand Down Expand Up @@ -82,9 +74,4 @@ private JdbcConfig buildJdbcProperties(AnnotationConfigWebApplicationContext roo
return JdbcConfig.builder().properties((Properties) rootContext.getBean("propertyFactory")).name(name).build();
}

private AccessLogLocationBean createAccessLogLocationBean(AnnotationConfigWebApplicationContext rootContext) {
Properties props = (Properties) rootContext.getBean("propertyFactory");
String location = Optional.ofNullable((String) props.get("access.log.output")).orElse("./logs/");
return new AccessLogLocationBean(location);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package app.micro.server.servers;

import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;

import java.io.File;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import com.aol.micro.server.MicroserverApp;
import com.aol.micro.server.config.Config;
import com.google.common.collect.ImmutableMap;

public class AccessLogConfigTest {

MicroserverApp server;

File logFile;

@Before
public void startServer() {

logFile = new File(System.getProperty("user.home") + "/access-log-app-access.log");
logFile.delete();

assertThat(logFile.exists(), is(false));

server = new MicroserverApp(Config.instance().withProperties(ImmutableMap.of("access.log.output", "${user.home}")), () -> "access-log-app");
server.start();

}

@After
public void stopServer() {
server.stop();
}

@Test
public void runAppAndBasicTest() {

assertThat(logFile.exists(), is(true));

}
}

0 comments on commit bb41978

Please sign in to comment.