org.apache.camel.component.olingo4.Olingo4Component Java Examples

The following examples show how to use org.apache.camel.component.olingo4.Olingo4Component. 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: Olingo4IntegrationTest.java    From wildfly-camel with Apache License 2.0 6 votes vote down vote up
private CamelContext createCamelContext() throws Exception {

        final CamelContext context = new DefaultCamelContext();

        Map<String, Object> options = new HashMap<String, Object>();
        options.put("serviceUri", getRealServiceUrl(TEST_SERVICE_BASE_URL));
        options.put("contentType", "application/json;charset=utf-8");

        final Olingo4Configuration configuration = new Olingo4Configuration();
        IntrospectionSupport.setProperties(configuration, options);

        // add OlingoComponent to Camel context
        final Olingo4Component component = new Olingo4Component(context);
        component.setConfiguration(configuration);
        context.addComponent("olingo4", component);

        return context;
    }
 
Example #2
Source File: Olingo4ComponentAutoConfiguration.java    From camel-spring-boot with Apache License 2.0 5 votes vote down vote up
@Lazy
@Bean(name = "olingo4-component")
@ConditionalOnMissingBean(Olingo4Component.class)
public Olingo4Component configureOlingo4Component() throws Exception {
    Olingo4Component component = new Olingo4Component();
    component.setCamelContext(camelContext);
    Map<String, Object> parameters = new HashMap<>();
    IntrospectionSupport.getProperties(configuration, parameters, null,
            false);
    CamelPropertiesHelper.setCamelProperties(camelContext, component,
            parameters, false);
    if (ObjectHelper.isNotEmpty(customizers)) {
        for (ComponentCustomizer<Olingo4Component> customizer : customizers) {
            boolean useCustomizer = (customizer instanceof HasId)
                    ? HierarchicalPropertiesEvaluator.evaluate(
                            applicationContext.getEnvironment(),
                            "camel.component.customizer",
                            "camel.component.olingo4.customizer",
                            ((HasId) customizer).getId())
                    : HierarchicalPropertiesEvaluator.evaluate(
                            applicationContext.getEnvironment(),
                            "camel.component.customizer",
                            "camel.component.olingo4.customizer");
            if (useCustomizer) {
                LOGGER.debug("Configure component {}, with customizer {}",
                        component, customizer);
                customizer.customize(component);
            }
        }
    }
    return component;
}
 
Example #3
Source File: ODataComponent.java    From syndesis with Apache License 2.0 4 votes vote down vote up
@Override
protected Optional<Component> createDelegateComponent(ComponentDefinition definition, Map<String, Object> options) {
    Olingo4AppEndpointConfiguration configuration = new Olingo4AppEndpointConfiguration();

    Map<String, String> httpHeaders = new HashMap<>();
    configuration.setHttpHeaders(httpHeaders);

    Methods method = ConnectorOptions.extractOptionAndMap(options, METHOD_NAME, Methods::getValueOf);
    if (ObjectHelper.isEmpty(method)) {
        throw new IllegalStateException("No method specified for odata component");
    }

    configuration.setMethodName(method.id());

    //
    // Ensure at least a blank map exists for this property
    //
    Map<String, String> endPointHttpHeaders = new HashMap<>();
    configuration.setEndpointHttpHeaders(endPointHttpHeaders);

    Map<String, Object> resolvedOptions = bundleOptions(options);
    HttpClientBuilder httpClientBuilder = ODataUtil.createHttpClientBuilder(resolvedOptions);
    configuration.setHttpClientBuilder(httpClientBuilder);

    HttpAsyncClientBuilder httpAsyncClientBuilder = ODataUtil.createHttpAsyncClientBuilder(resolvedOptions);
    configuration.setHttpAsyncClientBuilder(httpAsyncClientBuilder);

    if (getServiceUri() != null) {
        configuration.setServiceUri(getServiceUri());
    }

    configureResourcePath(configuration, options);

    if (Methods.READ.equals(method)) {
        //
        // Modify the query parameters into the expected map
        //
        Map<String, String> queryParams = new HashMap<>();
        if (getQueryParams() != null) {
            String queryString = getQueryParams();
            String[] clauses = queryString.split(AMPERSAND, -1);
            if (clauses.length >= 1) {
                for (String clause : clauses) {
                    String[] parts = clause.split(EQUALS, -1);
                    if (parts.length == 2) {
                        queryParams.put(parts[0], parts[1]);
                    } else if (parts.length < 2) {
                        queryParams.put(parts[0], EMPTY_STRING);
                    }
                    // A clause with more than 1 '=' would be invalid
                }
            }
        }

        configuration.setQueryParams(queryParams);
        configuration.setFilterAlreadySeen(isFilterAlreadySeen());
        configuration.setSplitResult(isSplitResult());
    }

    Olingo4Component component = new Olingo4Component(getCamelContext());
    component.setConfiguration(configuration);
    return Optional.of(component);
}
 
Example #4
Source File: BaseOlingo4Test.java    From syndesis with Apache License 2.0 4 votes vote down vote up
@Test
public void testExpectations() throws Exception {
    URI httpURI = URI.create(defaultTestServer.servicePlainUri() + FORWARD_SLASH + defaultTestServer.resourcePath());
    String camelURI = "olingo4://read/" + defaultTestServer.resourcePath();

    //
    // Create own main class to allow for setting the context
    //
    try (MyMain main = new MyMain()) {

        //
        // Get a context we can play with
        //
        CamelContext context = main.getCamelContext();

        //
        // Find the olingo4 component to configure
        //
        Olingo4Component component = (Olingo4Component) context.getComponent("olingo4");

        //
        // Create a configuration and apply the sevice url to
        // workaround the no serviceUri problem.
        //
        Olingo4AppEndpointConfiguration configuration = new Olingo4AppEndpointConfiguration();

        //
        // Override the ACCEPT header since it does not take account of the odata.metadata parameter
        //
        Map<String, String> httpHeaders = new HashMap<>();
        httpHeaders.put(HttpHeaders.ACCEPT, "application/json;odata.metadata=full,application/xml,*/*");
        configuration.setHttpHeaders(httpHeaders);

        configuration.setServiceUri(defaultTestServer.servicePlainUri());

        //
        // Apply empty values to these properties so they are
        // not violated as missing
        //
        configuration.setQueryParams(new HashMap<>());
        configuration.setEndpointHttpHeaders(new HashMap<>());

        //
        // Apply the configuration to the component
        //
        component.setConfiguration(configuration);

        //
        // Apply the component to the context
        //
        context.removeComponent("olingo4");
        context.addComponent("olingo4", component);

        //
        // Apply the route and run
        //
        main.addRoutesBuilder(new MyRouteBuilder(camelURI));

        ClientEntitySet olEntitySet = null;
        ODataRetrieveResponse<ClientEntitySet> response = null;
        ODataClient client = ODataClientFactory.getClient();
        try {
            response = client.getRetrieveRequestFactory().getEntitySetRequest(httpURI).execute();
            assertEquals(HttpStatus.SC_OK, response.getStatusCode());

            olEntitySet = response.getBody();
            assertNotNull(olEntitySet);
        } finally {
            if (response != null) {
                response.close();
            }
        }

        main.start();

        /*
         * Note:
         * Annoyingly, cannot put olEntitySet in the expected body of
         * the mock:result. Although an EntitySet is returned with all the
         * correct properties and values, some of the individual entity
         * attributes are slightly different, such as names being null
         * rather than Edm.null. These different attributes do not make
         * the results wrong enough to fail the test.
         */

        MockEndpoint result = context.getEndpoint("mock:result", MockEndpoint.class);
        result.setMinimumExpectedMessageCount(1);
        result.assertIsSatisfied();

        //
        // Split is true by default hence the return of a client entity rather than an entity set
        //
        Object body = result.getExchanges().get(0).getIn().getBody();
        assertTrue(body instanceof ClientEntity);
        ClientEntity cmEntity = (ClientEntity) body;

        ClientEntity olEntity = olEntitySet.getEntities().get(0);
        assertEquals(olEntity.getProperties(), cmEntity.getProperties());
    }
}