Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
package io.syndesis.connector.odata;
import java.util.HashMap;
import org.apache.camel.CamelContext;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.olingo4.Olingo4AppEndpointConfiguration;
import org.apache.camel.component.olingo4.Olingo4Component;
import org.apache.camel.main.Main;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import io.syndesis.common.util.StringConstants;
import io.syndesis.connector.odata.server.ODataTestServer;
public class SimpleOlingo4Test implements StringConstants {
private static class MyRouteBuilder extends RouteBuilder {
@Override
public void configure() throws Exception {
from("olingo4://read/Products").to("log:foo");
}
}
private static class MyMain extends Main {
CamelContext context;
public void setCamelContext(CamelContext context) {
this.context = context;
}
@Override
protected CamelContext createContext() {
if (context == null) {
return super.createContext();
}
return context;
}
}
private ODataTestServer server;
@Before
public void setup() throws Exception {
server = new ODataTestServer();
server.start();
}
@After
public void tearDown() throws Exception {
server.stop();
}
@Test
public void test1() throws Exception {
//
// Create own main class to allow for setting the context
//
MyMain main = new MyMain();
//
// Get a context we can play with
//
CamelContext context = main.getOrCreateCamelContext();
//
// 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();
configuration.setServiceUri(server.serviceUrl());
//
// Apply empty values to these properties so they are
// not violated as missing
//
configuration.setQueryParams(new HashMap<>());
configuration.setEndpointHttpHeaders(new HashMap<>());
//
// Apply the configurtion to the component
//
component.setConfiguration(configuration);
//
// Apply the component to the context
//
context.removeComponent("olingo4");
context.addComponent("olingo4", component);
//
// Apply the context to main
//
main.setCamelContext(context);
//
// Apply the route and run
//
main.addRouteBuilder(new MyRouteBuilder());
main.run();
}
}
@phantomjinx

This comment has been minimized.

Copy link
Owner Author

commented Dec 13, 2018

Fails with a stacktrace:
org.apache.camel.FailedToCreateRouteException: Failed to create route route1: Route(route1)[[From[olingo4://read/Products]] -> [To[log:foo... because of Missing properties for /read, need one or more from [responseHandler, edm]
at org.apache.camel.impl.RouteService.warmUp(RouteService.java:147)
at org.apache.camel.impl.DefaultCamelContext.doWarmUpRoutes(DefaultCamelContext.java:3947)
at org.apache.camel.impl.DefaultCamelContext.safelyStartRouteServices(DefaultCamelContext.java:3854)
at org.apache.camel.impl.DefaultCamelContext.doStartOrResumeRoutes(DefaultCamelContext.java:3640)
at org.apache.camel.impl.DefaultCamelContext.doStartCamel(DefaultCamelContext.java:3492)
at org.apache.camel.impl.DefaultCamelContext.access$000(DefaultCamelContext.java:209)
at org.apache.camel.impl.DefaultCamelContext$2.call(DefaultCamelContext.java:3251)
at org.apache.camel.impl.DefaultCamelContext$2.call(DefaultCamelContext.java:3247)
at org.apache.camel.impl.DefaultCamelContext.doWithDefinedClassLoader(DefaultCamelContext.java:3270)
at org.apache.camel.impl.DefaultCamelContext.doStart(DefaultCamelContext.java:3247)
at org.apache.camel.support.ServiceSupport.start(ServiceSupport.java:61)
at org.apache.camel.impl.DefaultCamelContext.start(DefaultCamelContext.java:3163)
at org.apache.camel.main.Main.doStart(Main.java:139)
at org.apache.camel.support.ServiceSupport.start(ServiceSupport.java:61)
at org.apache.camel.main.MainSupport.run(MainSupport.java:170)
at io.syndesis.connector.odata.SimpleOlingo4Test.test1(SimpleOlingo4Test.java:122)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:538)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:760)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:460)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:206)
Caused by: java.lang.IllegalArgumentException: Missing properties for /read, need one or more from [responseHandler, edm]
at org.apache.camel.util.component.ApiConsumerHelper.findMethod(ApiConsumerHelper.java:61)
at org.apache.camel.util.component.AbstractApiConsumer.(AbstractApiConsumer.java:52)
at org.apache.camel.component.olingo4.Olingo4Consumer.(Olingo4Consumer.java:37)
at org.apache.camel.component.olingo4.Olingo4Endpoint.createConsumer(Olingo4Endpoint.java:91)
at org.apache.camel.impl.EventDrivenConsumerRoute.addServices(EventDrivenConsumerRoute.java:69)
at org.apache.camel.impl.DefaultRoute.onStartingServices(DefaultRoute.java:103)
at org.apache.camel.impl.RouteService.doWarmUp(RouteService.java:172)
at org.apache.camel.impl.RouteService.warmUp(RouteService.java:145)
... 40 more

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.