Skip to content

Commit

Permalink
Fix #706 Improve RuntimeCatalogConfig docs
Browse files Browse the repository at this point in the history
  • Loading branch information
ppalaga committed Apr 4, 2020
1 parent 935b6db commit fcbd110
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class CamelConfig {
public ServiceConfig service;

/**
* Build time configuration options for {@link RuntimeCatalogConfig}.
* Build time configuration options for {@link org.apache.camel.catalog.RuntimeCamelCatalog}.
*/
@ConfigItem
public RuntimeCatalogConfig runtimeCatalog;
Expand Down Expand Up @@ -290,41 +290,45 @@ public static class ReflectionConfig {
@ConfigGroup
public static class RuntimeCatalogConfig {
/**
* Used to control the resolution of components catalog info.
* If {@code true} the Runtime Camel Catalog embedded in the application will contain JSON schemas of Camel
* components available in the application; otherwise component JSON schemas will not be available in the
* Runtime Camel Catalog and any attempt to access those will result in a RuntimeException.
* <p>
* Note that when building native images, this flag determine if the json metadata files related to components
* discovered at build time have to be included in the final binary. In JVM mode there is no real benefit of
* setting this flag to {@code false} if not to make the behavior consistent with native mode.
* Setting this to {@code false} helps to reduce the size of the native image. In JVM mode, there is no real
* benefit of setting this flag to {@code false} except for making the behavior consistent with native mode.
*/
@ConfigItem(defaultValue = "true")
public boolean components;

/**
* Used to control the resolution of languages catalog info.
* If {@code true} the Runtime Camel Catalog embedded in the application will contain JSON schemas of Camel
* languages available in the application; otherwise language JSON schemas will not be available in the
* Runtime Camel Catalog and any attempt to access those will result in a RuntimeException.
* <p>
* Note that when building native images, this flag determine if the json metadata files related to languages
* discovered at build time have to be included in the final binary. In JVM mode there is no real benefit of
* setting this flag to {@code false} if not to make the behavior consistent with native mode.
* Setting this to {@code false} helps to reduce the size of the native image. In JVM mode, there is no real
* benefit of setting this flag to {@code false} except for making the behavior consistent with native mode.
*/
@ConfigItem(defaultValue = "true")
public boolean languages;

/**
* Used to control the resolution of dataformats catalog info.
* If {@code true} the Runtime Camel Catalog embedded in the application will contain JSON schemas of Camel
* data formats available in the application; otherwise data format JSON schemas will not be available in the
* Runtime Camel Catalog and any attempt to access those will result in a RuntimeException.
* <p>
* Note that when building native images, this flag determine if the json metadata files related to dataformats
* discovered at build time have to be included in the final binary. In JVM mode there is no real benefit of
* setting this flag to {@code false} if not to make the behavior consistent with native mode.
* Setting this to {@code false} helps to reduce the size of the native image. In JVM mode, there is no real
* benefit of setting this flag to {@code false} except for making the behavior consistent with native mode.
*/
@ConfigItem(defaultValue = "true")
public boolean dataformats;

/**
* Used to control the resolution of model catalog info.
* If {@code true} the Runtime Camel Catalog embedded in the application will contain JSON schemas of Camel
* EIP models available in the application; otherwise EIP model JSON schemas will not be available in the
* Runtime Camel Catalog and any attempt to access those will result in a RuntimeException.
* <p>
* Note that when building native images, this flag determine if the json metadata files related to models
* has to be included in the final binary. In JVM mode there is no real benefit of setting this flag to
* {@code false} if not to make the behavior consistent with native mode.
* Setting this to {@code false} helps to reduce the size of the native image. In JVM mode, there is no real
* benefit of setting this flag to {@code false} except for making the behavior consistent with native mode.
*/
@ConfigItem(defaultValue = "true")
public boolean models;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ public CamelRuntimeCatalog(CamelConfig.RuntimeCatalogConfig config) {
@Override
public String modelJSonSchema(String name) {
if (!config.models) {
return null;
throw new RuntimeException(
"Accessing model JSON schemas was disabled via quarkus.camel.runtime-catalog.models = false");
}

return super.modelJSonSchema(name);
Expand All @@ -37,7 +38,8 @@ public String modelJSonSchema(String name) {
@Override
public String componentJSonSchema(String name) {
if (!config.components) {
return null;
throw new RuntimeException(
"Accessing component JSON schemas was disabled via quarkus.camel.runtime-catalog.components = false");
}

return super.componentJSonSchema(name);
Expand All @@ -46,7 +48,8 @@ public String componentJSonSchema(String name) {
@Override
public String dataFormatJSonSchema(String name) {
if (!config.dataformats) {
return null;
throw new RuntimeException(
"Accessing data format JSON schemas was disabled via quarkus.camel.runtime-catalog.dataformats = false");
}

return super.dataFormatJSonSchema(name);
Expand All @@ -55,7 +58,8 @@ public String dataFormatJSonSchema(String name) {
@Override
public String languageJSonSchema(String name) {
if (!config.languages) {
return null;
throw new RuntimeException(
"Accessing language JSON schemas was disabled via quarkus.camel.runtime-catalog.languages = false");
}

return super.languageJSonSchema(name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,20 +136,30 @@ public boolean adaptToExtendedCamelContext() {
@Path("/catalog/{type}/{name}")
@GET
@Produces(MediaType.APPLICATION_JSON)
public String catalog(@PathParam("type") String type, @PathParam("name") String name) throws IOException {
public Response catalog(@PathParam("type") String type, @PathParam("name") String name) throws IOException {
final CamelRuntimeCatalog catalog = (CamelRuntimeCatalog) context.getExtension(RuntimeCamelCatalog.class);

switch (type) {
case "component":
return catalog.componentJSonSchema(name);
case "language":
return catalog.languageJSonSchema(name);
case "dataformat":
return catalog.dataFormatJSonSchema(name);
case "model":
return catalog.modelJSonSchema(name);
default:
throw new IllegalArgumentException("Unknown type " + type);
try {
final String schema;
switch (type) {
case "component":
schema = catalog.componentJSonSchema(name);
break;
case "language":
schema = catalog.languageJSonSchema(name);
break;
case "dataformat":
schema = catalog.dataFormatJSonSchema(name);
break;
case "model":
schema = catalog.modelJSonSchema(name);
break;
default:
throw new IllegalArgumentException("Unknown type " + type);
}
return Response.ok(schema).build();
} catch (Exception e) {
return Response.serverError().entity(e.getClass().getSimpleName() + ": " + e.getMessage()).build();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ public void testResolveLanguages() {
@Test
public void testCatalogComponent() throws IOException {
RestAssured.when().get("/test/catalog/component/timer").then().body(not(emptyOrNullString()));
RestAssured.when().get("/test/catalog/language/simple").then().body(emptyOrNullString());
RestAssured.when().get("/test/catalog/language/simple").then().statusCode(500).body(is(
"RuntimeException: Accessing language JSON schemas was disabled via quarkus.camel.runtime-catalog.languages = false"));
}

@Test
Expand Down

0 comments on commit fcbd110

Please sign in to comment.