org.apache.camel.spi.RestConfiguration Java Examples

The following examples show how to use org.apache.camel.spi.RestConfiguration. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CamelRestTest.java    From camel-spring-boot with Apache License 2.0 6 votes vote down vote up
@Override
public Consumer createApiConsumer(
    CamelContext camelContext,
    Processor processor,
    String contextPath,
    RestConfiguration configuration,
    Map<String, Object> parameters) throws Exception {

    // just use a seda endpoint for testing purpose
    String id = DefaultUuidGenerator.generateSanitizedId(contextPath);
    // remove leading dash as we add that ourselves
    if (id.startsWith("-")) {
        id = id.substring(1);
    }

    SedaEndpoint seda = camelContext.getEndpoint("seda:api:" + "-" + id, SedaEndpoint.class);
    return seda.createConsumer(processor);
}
 
Example #2
Source File: RestConfigurationCustomizer.java    From camel-quarkus with Apache License 2.0 5 votes vote down vote up
@Override
public void customize(CamelContext context) {
    RestConfiguration restConfiguration = new RestConfiguration();
    restConfiguration.setApiContextPath("/example");

    context.setRestConfiguration(restConfiguration);
}
 
Example #3
Source File: CamelRestTest.java    From camel-spring-boot with Apache License 2.0 5 votes vote down vote up
@Override
public Consumer createConsumer(
    CamelContext camelContext,
    Processor processor,
    String verb,
    String basePath,
    String uriTemplate,
    String consumes,
    String produces,
    RestConfiguration configuration,
    Map<String, Object> parameters) throws Exception {

    // just use a seda endpoint for testing purpose
    String id;
    if (uriTemplate != null) {
        id = DefaultUuidGenerator.generateSanitizedId(basePath + uriTemplate);
    } else {
        id = DefaultUuidGenerator.generateSanitizedId(basePath);
    }
    // remove leading dash as we add that ourselves
    if (id.startsWith("-")) {
        id = id.substring(1);
    }

    if (configuration.getConsumerProperties() != null) {
        String ref = (String) configuration.getConsumerProperties().get("dummy");
        if (ref != null) {
            dummy = CamelContextHelper.mandatoryLookup(camelContext, ref.substring(1));
        }
    }

    SedaEndpoint seda = camelContext.getEndpoint("seda:" + verb + "-" + id, SedaEndpoint.class);
    return seda.createConsumer(processor);
}
 
Example #4
Source File: IntegrationTest.java    From camel-k-runtime with Apache License 2.0 5 votes vote down vote up
@Test
public void testRestConfiguration() {
    configureRoutes(
        "classpath:routes-with-rest-configuration.js"
    );

    RestConfiguration conf = context.getRestConfiguration();

    assertThat(conf).isNotNull();
    assertThat(conf).hasFieldOrPropertyWithValue("component", "undertow");
    assertThat(conf).hasFieldOrPropertyWithValue("port", 1234);
}
 
Example #5
Source File: SyndesisRestSwaggerComponent.java    From syndesis with Apache License 2.0 5 votes vote down vote up
@Override
@SuppressWarnings("PMD.ExcessiveParameterList") // overriden method
public Producer createProducer(final CamelContext camelContext, final String host, final String verb, final String basePath, final String uriTemplate,
    final String queryParameters, final String consumes, final String produces, final RestConfiguration configuration, final Map<String, Object> parameters)
    throws Exception {

    final HttpProducer producer = (HttpProducer) super.createProducer(camelContext, host, verb, basePath, uriTemplate, queryParameters, consumes, produces,
        configuration, parameters);

    for (final Consumer<HttpProducer> customizer : CUSTOMIZERS) {
        customizer.accept(producer);
    }

    return producer;
}
 
Example #6
Source File: AbstractRestDslIntegrationTest.java    From wildfly-camel with Apache License 2.0 5 votes vote down vote up
@Test
public void testRestDslCorsEnabled() throws Exception {
    RestConfiguration restConfiguration = createRestConfiguration();
    restConfiguration.setEnableCORS(true);

    CamelContext camelctx = new DefaultCamelContext();
    camelctx.setRestConfiguration(restConfiguration);
    camelctx.addRoutes(new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            rest()
                .get("/test")
                    .route()
                        .setBody(constant("GET: /test"))
                    .endRest();
        }
    });

    camelctx.start();
    try {
        Map<String, String> headers = client.getResponse("test", "OPTIONS").getHeaders();
        for (String header : CORS_HEADERS) {
            Assert.assertTrue("Expected HTTP response header: " + header, headers.containsKey(header));
        }
    } finally {
        camelctx.close();
    }
}
 
Example #7
Source File: AbstractRestDslIntegrationTest.java    From wildfly-camel with Apache License 2.0 5 votes vote down vote up
@Test
public void testRestDslCorsDisabled() throws Exception {
    RestConfiguration restConfiguration = createRestConfiguration();
    restConfiguration.setEnableCORS(false);

    CamelContext camelctx = new DefaultCamelContext();
    camelctx.setRestConfiguration(createRestConfiguration());
    camelctx.addRoutes(new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            rest()
                .get("/test")
                    .route()
                        .setBody(constant("GET: /test"))
                    .endRest();
        }
    });

    camelctx.start();
    try {
        Map<String, String> headers = client.getResponse("test", "OPTIONS").getHeaders();
        for (String header : CORS_HEADERS) {
            Assert.assertFalse(headers.containsKey(header));
        }
    } finally {
        camelctx.close();
    }
}
 
Example #8
Source File: AbstractRestDslIntegrationTest.java    From wildfly-camel with Apache License 2.0 5 votes vote down vote up
private RestConfiguration createRestConfiguration(String contextPath) {
    RestConfiguration configuration = new RestConfiguration();
    configuration.setComponent(getComponentName());
    configuration.setHost("localhost");
    configuration.setPort(getPort());

    // camel-servlet always requires a context path
    if (getComponentName().equals("servlet")) {
        configuration.setContextPath(getDefaultContextPath());
    } else {
        configuration.setContextPath(contextPath);
    }

    return configuration;
}
 
Example #9
Source File: UndertowSecureRestDslIntegrationTest.java    From wildfly-camel with Apache License 2.0 5 votes vote down vote up
private RestConfiguration createRestConfiguration(String contextPath) {
    RestConfiguration configuration = new RestConfiguration();
    configuration.setComponent(UNDERTOW_COMPONENT);
    configuration.setHost(TestClient.HOST);
    configuration.setPort(TestClient.PORT);
    configuration.setContextPath(contextPath);
    return configuration;
}
 
Example #10
Source File: RestConfigurationDefinitionAutoConfiguration.java    From camel-spring-boot with Apache License 2.0 4 votes vote down vote up
@Lazy
@Bean(name = RestComponent.DEFAULT_REST_CONFIGURATION_ID)
@ConditionalOnClass(CamelContext.class)
@ConditionalOnMissingBean
public RestConfiguration configureRestConfigurationDefinition()
        throws Exception {
    Map<String, Object> properties = new HashMap<>();
    IntrospectionSupport.getProperties(config, properties, null, false);
    // These options is configured specially further below, so remove them first
    properties.remove("enableCors");
    properties.remove("apiProperty");
    properties.remove("componentProperty");
    properties.remove("consumerProperty");
    properties.remove("dataFormatProperty");
    properties.remove("endpointProperty");
    properties.remove("corsHeaders");
    
    RestConfiguration definition = new RestConfiguration();
    CamelPropertiesHelper.setCamelProperties(camelContext, definition, properties, true);
    
    // Workaround for spring-boot properties name as It would appear
    // as enable-c-o-r-s if left uppercase in Configuration
    definition.setEnableCORS(config.getEnableCors());
    
    if (config.getApiProperty() != null) {
        definition.setApiProperties(new HashMap<>(CollectionHelper.flattenKeysInMap(config.getApiProperty(), ".")));
    }
    if (config.getComponentProperty() != null) {
        definition.setComponentProperties(new HashMap<>(CollectionHelper.flattenKeysInMap(config.getComponentProperty(), ".")));
    }
    if (config.getConsumerProperty() != null) {
        definition.setConsumerProperties(new HashMap<>(CollectionHelper.flattenKeysInMap(config.getConsumerProperty(), ".")));
    }
    if (config.getDataFormatProperty() != null) {
        definition.setDataFormatProperties(new HashMap<>(CollectionHelper.flattenKeysInMap(config.getDataFormatProperty(), ".")));
    }
    if (config.getEndpointProperty() != null) {
        definition.setEndpointProperties(new HashMap<>(CollectionHelper.flattenKeysInMap(config.getEndpointProperty(), ".")));
    }
    if (config.getCorsHeaders() != null) {
        Map<String, Object> map = CollectionHelper.flattenKeysInMap(config.getCorsHeaders(), ".");
        Map<String, String> target = new HashMap<>();
        map.forEach((k, v) -> target.put(k, v.toString()));
        definition.setCorsHeaders(target);
    }
    return definition;
}
 
Example #11
Source File: AbstractRestDslIntegrationTest.java    From wildfly-camel with Apache License 2.0 4 votes vote down vote up
private RestConfiguration createRestConfiguration() {
    return createRestConfiguration(null);
}