Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CC-3635 - Add config to specify location of static resources #992

Merged
merged 2 commits into from
Jan 14, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,8 @@ public class SchemaRegistryConfig extends RestConfig {
"schema.registry.resource.extension.class";
public static final String RESOURCE_EXTENSION_CONFIG =
"resource.extension.class";
public static final String RESOURCE_STATIC_LOCATIONS_CONFIG =
"resource.static.locations";
@Deprecated
public static final String SCHEMAREGISTRY_INTER_INSTANCE_PROTOCOL_CONFIG =
"schema.registry.inter.instance.protocol";
Expand Down Expand Up @@ -293,6 +295,9 @@ public class SchemaRegistryConfig extends RestConfig {
+ " like filters to Schema Registry. Typically used to add custom capability like logging, "
+ " security, etc. The schema.registry.resource.extension.class name is deprecated; "
+ "prefer using resource.extension.class instead.";
protected static final String RESOURCE_STATIC_LOCATIONS_DOC =
" A list of classpath resources containing static resources to serve using the default "
+ "servlet.";
protected static final String SCHEMAREGISTRY_INTER_INSTANCE_PROTOCOL_DOC =
"The protocol used while making calls between the instances of schema registry. The slave "
+ "to master node calls for writes and deletes will use the specified protocol. The default "
Expand Down Expand Up @@ -485,6 +490,9 @@ public static ConfigDef baseSchemaRegistryConfigDef() {
.define(RESOURCE_EXTENSION_CONFIG, ConfigDef.Type.LIST, "",
ConfigDef.Importance.LOW, SCHEMAREGISTRY_RESOURCE_EXTENSION_DOC
)
.define(RESOURCE_STATIC_LOCATIONS_CONFIG, ConfigDef.Type.LIST, "",
ConfigDef.Importance.LOW, RESOURCE_STATIC_LOCATIONS_DOC
)
.define(SCHEMAREGISTRY_INTER_INSTANCE_PROTOCOL_CONFIG, ConfigDef.Type.STRING, "",
ConfigDef.Importance.LOW, SCHEMAREGISTRY_INTER_INSTANCE_PROTOCOL_DOC)
.define(INTER_INSTANCE_PROTOCOL_CONFIG, ConfigDef.Type.STRING, HTTP,
Expand Down Expand Up @@ -651,6 +659,10 @@ public String definedResourceExtensionConfigName() {
return RESOURCE_EXTENSION_CONFIG;
}

public List<String> getStaticLocations() {
return getList(RESOURCE_STATIC_LOCATIONS_CONFIG);
}

/**
* Gets the inter.instance.protocol setting, handling the deprecated
* schema.registry.inter.instance.protocol setting.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

package io.confluent.kafka.schemaregistry.rest;

import org.eclipse.jetty.util.resource.Resource;
import org.eclipse.jetty.util.resource.ResourceCollection;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -95,6 +97,19 @@ public void setupResources(Configurable<?> config, SchemaRegistryConfig schemaRe
}
}

@Override
protected ResourceCollection getStaticResources() {
List<String> locations = config.getStaticLocations();
if (locations != null && !locations.isEmpty()) {
Resource[] resources = config.getStaticLocations().stream()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

locations.stream()?

.map(Resource::newClassPathResource)
.toArray(Resource[]::new);
return new ResourceCollection(resources);
} else {
return null;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this be super.getStaticResources() instead?

}
}

@Override
public void onShutdown() {

Expand Down