Java Code Examples for org.apache.camel.spi.RestConfiguration#setEnableCORS()
The following examples show how to use
org.apache.camel.spi.RestConfiguration#setEnableCORS() .
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: AbstractRestDslIntegrationTest.java From wildfly-camel with Apache License 2.0 | 5 votes |
@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 2
Source File: AbstractRestDslIntegrationTest.java From wildfly-camel with Apache License 2.0 | 5 votes |
@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 3
Source File: RestConfigurationDefinitionAutoConfiguration.java From camel-spring-boot with Apache License 2.0 | 4 votes |
@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; }