title: Trying to customize 404 error page from Camel Jetty
body: <p>I'm working on an osgi package with Apache Camel and Jetty and trying to customize the 404 error page but can't find a way</p>
  <p>Reading on the internet indicates that it has to be done using an Error Handler.</p>
  <p>I am trying to add the errorHandler as follows:</p>
  <pre><code>JettyHttpComponent9 jetty = getContext().getComponent(&quot;jetty&quot;, JettyHttpComponent9.class);
  ErrorPageErrorHandler errorPageErrorHandler = new ErrorPageErrorHandler();
  errorPageErrorHandler.addErrorPage(404,&quot;http://localhost:8081/getActualDate&quot;);
  jetty.setErrorHandler(errorPageErrorHandler);
  </code></pre>
  <p>But when I load the bundle in Karaf it shows me the following error:</p>
  <pre><code>java.lang.IllegalStateException: STARTED
      at org.eclipse.jetty.server.handler.AbstractHandler.setServer(AbstractHandler.java:126) ~[?:?]
      at org.eclipse.jetty.server.Server.doStart(Server.java:342) ~[?:?]
      at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:72) ~[?:?]
      at org.apache.camel.component.jetty.JettyHttpComponent.connect(JettyHttpComponent.java:337) ~[?:?]
      at org.apache.camel.http.common.HttpCommonEndpoint.connect(HttpCommonEndpoint.java:186) ~[?:?]
      at org.apache.camel.http.common.HttpConsumer.doStart(HttpConsumer.java:58) ~[?:?]
      at org.apache.camel.component.jetty.JettyHttpConsumer.doStart(JettyHttpConsumer.java:31) ~[?:?]
      at org.apache.camel.support.service.BaseService.start(BaseService.java:119) ~[!/:3.14.3]
      at org.apache.camel.support.service.ServiceHelper.startService(ServiceHelper.java:113) ~[!/:3.14.3]
      at org.apache.camel.impl.engine.AbstractCamelContext.startService(AbstractCamelContext.java:3598) ~[!/:3.14.3]
      at org.apache.camel.impl.engine.InternalRouteStartupManager.doStartOrResumeRouteConsumers(InternalRouteStartupManager.java:401) ~[!/:3.14.3]
      at org.apache.camel.impl.engine.InternalRouteStartupManager.doStartRouteConsumers(InternalRouteStartupManager.java:319) ~[!/:3.14.3]
      at org.apache.camel.impl.engine.InternalRouteStartupManager.safelyStartRouteServices(InternalRouteStartupManager.java:213) ~[!/:3.14.3]
      at org.apache.camel.impl.engine.InternalRouteStartupManager.doStartOrResumeRoutes(InternalRouteStartupManager.java:147) ~[!/:3.14.3]
      at org.apache.camel.impl.engine.AbstractCamelContext.doStartCamel(AbstractCamelContext.java:3300) ~[!/:3.14.3]
      at org.apache.camel.impl.engine.AbstractCamelContext.doStartContext(AbstractCamelContext.java:2952) ~[!/:3.14.3]
      at org.apache.camel.impl.engine.AbstractCamelContext.doStart(AbstractCamelContext.java:2903) ~[!/:3.14.3]
      at org.apache.camel.support.service.BaseService.start(BaseService.java:119) ~[!/:3.14.3]
      at org.apache.camel.impl.engine.AbstractCamelContext.start(AbstractCamelContext.java:2587) ~[!/:3.14.3]
      at org.apache.camel.impl.DefaultCamelContext.start(DefaultCamelContext.java:253) ~[!/:3.14.3]
      at org.apache.camel.blueprint.BlueprintCamelContext.start(BlueprintCamelContext.java:241) ~[!/:3.14.3]
      at org.apache.camel.blueprint.BlueprintCamelContext.maybeStart(BlueprintCamelContext.java:283) ~[!/:3.14.3]
      at org.apache.camel.blueprint.BlueprintCamelContext.blueprintEvent(BlueprintCamelContext.java:188) [!/:3.14.3]
      at org.apache.aries.blueprint.container.BlueprintEventDispatcher$3.call(BlueprintEventDispatcher.java:190) [!/:1.10.2]
      at org.apache.aries.blueprint.container.BlueprintEventDispatcher$3.call(BlueprintEventDispatcher.java:188) [!/:1.10.2]
      at java.util.concurrent.FutureTask.run(FutureTask.java:266) [?:1.8.0_302]
      at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [?:1.8.0_302]
      at java.util.concurrent.FutureTask.run(FutureTask.java:266) [?:1.8.0_302]
      at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [?:1.8.0_302]
      at java.util.concurrent.FutureTask.run(FutureTask.java:266) [?:1.8.0_302]
      at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180) [?:1.8.0_302]
      at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293) [?:1.8.0_302]
      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [?:1.8.0_302]
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [?:1.8.0_302]
      at java.lang.Thread.run(Thread.java:748) [?:1.8.0_302]
  </code></pre>
  <p>From what I understand the error says that since the component is already started it could not load the handler, but I don't know how to load it before it starts.</p>
  <p>I am currently using Camel 3.14.3 with Karaf 4.2.8</p>
  <p>Any help is appreciated</p>
  <p><strong>Edit:</strong>
  Currently I load the data to build the routes from the database as follows:</p>
  <pre><code>configManager.getRoutes().forEach((apiBasePath, route) -&gt; {
  
              Predicate requiresAudit = PredicateBuilder.constant(route.getRequiresAudit());
              Predicate requiresAuthorization = PredicateBuilder.constant(route.getRequiresAuthorization());
  
              from(createInternalEndPoint(route)).routeId(route.getApiBasePath())
                  
                  .setHeader(Exchange.HTTP_PATH,simple(route.getApiBasePath())) 
                  .bean(gateway, &quot;checkRoute&quot;)
                  .setHeader(Exchange.HTTP_PATH,simple(&quot;&quot;)) //Esto se hace para que no de error la ruta en TO
  
                  .choice()
                      ...
                  .end()
  
                  .choice()
                      ..
                  .end()
  
                  .circuitBreaker().resilience4jConfiguration(Resilience4JConfig.getConfig())
                      .to(createExternalEndPoint(route))
                      .onFallback()
                          .process(getShortCircuitedProcess())
                      .end()
                  .end()
          });
  </code></pre>
  <p>In pom.xml I only have this dependency related to jetty:</p>
  <pre><code>&lt;dependency&gt;
     &lt;groupId&gt;org.apache.camel&lt;/groupId&gt;
     &lt;artifactId&gt;camel-jetty&lt;/artifactId&gt;
  &lt;/dependency&gt;
  </code></pre>
  <p>I try to set the error handler before creating the routes (All in the same class that extends RouteBuilder).</p>