CamelRoutesEndpoint { @WriteOperation public void doWriteAction(@Selector String id, @Selector WriteAction action, @Nullable TimeInfo timeInfo) { if (this.properties.isReadOnly()) { throw new IllegalArgumentException(String.format("Read only: write action %s is not allowed", action)); } switch (action) { case STOP: stopRoute( id, Optional.ofNullable(timeInfo).flatMap(ti -> Optional.ofNullable(ti.getTimeout())), Optional.of(TimeUnit.SECONDS), Optional.ofNullable(timeInfo).flatMap(ti -> Optional.ofNullable(ti.getAbortAfterTimeout()))); break; case START: startRoute(id); break; case RESET: resetRoute(id); break; case SUSPEND: suspendRoute(id, Optional.ofNullable(timeInfo).flatMap(ti -> Optional.ofNullable(ti.getTimeout())), Optional.of(TimeUnit.SECONDS)); break; case RESUME: resumeRoute(id); break; default: throw new IllegalArgumentException("Unsupported write action " + action); } } CamelRoutesEndpoint(CamelContext camelContext, CamelRoutesEndpointProperties properties); @ReadOperation List<RouteEndpointInfo> readRoutes(); @ReadOperation Object doReadAction(@Selector String id, @Selector ReadAction action); @WriteOperation void doWriteAction(@Selector String id, @Selector WriteAction action, @Nullable TimeInfo timeInfo);  }
@Test(expected = IllegalArgumentException.class) public void testWriteOperationReadOnly() throws Exception { TimeInfo timeInfo = new TimeInfo(); timeInfo.setAbortAfterTimeout(true); timeInfo.setTimeout(5L); endpoint.doWriteAction("foo-route", WriteAction.STOP, timeInfo); }