Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 6 additions & 12 deletions core/src/main/java/io/confluent/rest/RestConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
import java.util.TreeMap;

public class RestConfig extends AbstractConfig {
protected static final ConfigDef config;

public static final String DEBUG_CONFIG = "debug";
protected static final String DEBUG_CONFIG_DOC =
"Boolean indicating whether extra debugging information is generated in some " +
Expand Down Expand Up @@ -58,8 +56,8 @@ public class RestConfig extends AbstractConfig {
"Name of the SLF4J logger to write the NCSA Common Log Format request log.";
protected static final String REQUEST_LOGGER_NAME_DEFAULT = "io.confluent.rest-utils.requests";

static {
config = new ConfigDef()
public static ConfigDef baseConfigDef() {
return new ConfigDef()
.define(DEBUG_CONFIG, Type.BOOLEAN,
DEBUG_CONFIG_DEFAULT, Importance.HIGH, DEBUG_CONFIG_DOC)
.define(PORT_CONFIG, Type.INT, PORT_CONFIG_DEFAULT, Importance.HIGH,
Expand All @@ -78,15 +76,11 @@ public class RestConfig extends AbstractConfig {
REQUEST_LOGGER_NAME_DOC);
}

public RestConfig() {
super(config, new TreeMap<Object,Object>());
}

public RestConfig(Map<?, ?> props) {
super(config, props);
public RestConfig(ConfigDef definition, Map<?, ?> originals) {
super(definition, originals);
}

public static void main(String[] args) {
System.out.println(config.toHtmlTable());
public RestConfig(ConfigDef definition) {
super(definition, new TreeMap<Object,Object>());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@
*/
public class ExceptionHandlingTest {

RestConfig config;
TestRestConfig config;
ExceptionApplication app;

@Before
public void setUp() throws Exception {
Properties props = new Properties();
props.setProperty("debug", "false");
config = new RestConfig(props);
config = new TestRestConfig(props);
app = new ExceptionApplication(config);
app.start();
}
Expand Down Expand Up @@ -91,14 +91,14 @@ public void testUnexpectedException() {
}

// Test app just has endpoints that trigger different types of exceptions.
private static class ExceptionApplication extends Application<RestConfig> {
private static class ExceptionApplication extends Application<TestRestConfig> {

ExceptionApplication(RestConfig props) {
ExceptionApplication(TestRestConfig props) {
super(props);
}

@Override
public void setupResources(Configurable<?> config, RestConfig appConfig) {
public void setupResources(Configurable<?> config, TestRestConfig appConfig) {
config.register(ExceptionResource.class);
}
}
Expand Down
12 changes: 5 additions & 7 deletions core/src/test/java/io/confluent/rest/ShutdownTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@

import org.junit.Test;

import java.io.IOException;
import java.net.ServerSocket;
import java.util.Properties;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.atomic.AtomicBoolean;
Expand All @@ -37,7 +35,7 @@ public class ShutdownTest {
public void testShutdownHook() throws Exception {
Properties props = new Properties();
props.put("shutdown.graceful.ms", "50");
ShutdownApplication app = new ShutdownApplication(new RestConfig(props));
ShutdownApplication app = new ShutdownApplication(new TestRestConfig(props));
app.start();

StopThread stop = new StopThread(app);
Expand All @@ -51,7 +49,7 @@ public void testShutdownHook() throws Exception {
public void testGracefulShutdown() throws Exception {
Properties props = new Properties();
props.put("shutdown.graceful.ms", "50");
final RestConfig config = new RestConfig(props);
final TestRestConfig config = new TestRestConfig(props);
ShutdownApplication app = new ShutdownApplication(config);
app.start();

Expand All @@ -69,11 +67,11 @@ public void testGracefulShutdown() throws Exception {
}


private static class ShutdownApplication extends Application<RestConfig> {
private static class ShutdownApplication extends Application<TestRestConfig> {
public AtomicBoolean shutdown = new AtomicBoolean(false);
public SlowResource resource = new SlowResource();

ShutdownApplication(RestConfig props) {
ShutdownApplication(TestRestConfig props) {
super(props);
}

Expand All @@ -83,7 +81,7 @@ public void onShutdown() {
}

@Override
public void setupResources(Configurable<?> config, RestConfig appConfig) {
public void setupResources(Configurable<?> config, TestRestConfig appConfig) {
config.register(resource);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class WebApplicationExceptionMapperTest {
public void setUp() {
Properties props = new Properties();
props.setProperty("debug", "false");
RestConfig config = new RestConfig(props);
RestConfig config = new TestRestConfig(props);
mapper = new WebApplicationExceptionMapper(config);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import java.util.Map;

import io.confluent.common.config.ConfigDef;
import io.confluent.common.config.ConfigDef.Importance;
import io.confluent.common.config.ConfigDef.Type;
import io.confluent.rest.RestConfig;
Expand All @@ -28,23 +29,26 @@
* implementations.
*/
public class HelloWorldRestConfig extends RestConfig {
private static ConfigDef config;

public static final String GREETING_CONFIG = "greeting";
private static final String GREETING_CONFIG_DOC = "Greeting template for responses.";
private static final String GREETING_CONFIG_DEFAULT = "Hello, %s!";

static {
config.define(GREETING_CONFIG,
Type.STRING,
GREETING_CONFIG_DEFAULT,
Importance.HIGH,
GREETING_CONFIG_DOC);
config = baseConfigDef()
.define(GREETING_CONFIG,
Type.STRING,
GREETING_CONFIG_DEFAULT,
Importance.HIGH,
GREETING_CONFIG_DOC);
}

public HelloWorldRestConfig() {
super();
super(config);
}

public HelloWorldRestConfig(Map<?, ?> props) {
super(props);
super(config, props);
}
}