を使用してアプリケーションをUndertow
セットアップし、ResourceHandler
静的ファイル用にセットアップし、Servlet
残りのサービスを公開するために apache-camel によって使用されます。
アプリコンテナでSpringとservlet3.0を使用してこれを行いました。
クラス拡張でorg.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer
@Override
public void onStartup(ServletContext servletContext) throws ServletException
{
super.onStartup(servletContext);
ServletRegistration.Dynamic servlet = servletContext.addServlet("RestServlet", new CamelHttpTransportServlet());
servlet.setLoadOnStartup(1);
servlet.addMapping("/rest/*");
}
そしてキャメルルートで
restConfiguration()
.component("RestServlet")
.bindingMode(RestBindingMode.json)
.dataFormatProperty("prettyPrint", "true");
http://camel.apache.org/servlet.htmlで説明されている内容にかなり近い
しかし、Undertow でこれを組み込みとして行うと、org.apache.camel.NoSuchBeanException: No bean could be found in the registry for: RestServlet of type: org.apache.camel.spi.RestConsumerFactory
Guice は Undertow によって作成されたサーブレットを決して見つけられないと思います。CamelHttpTransportServlet を Guice Binding として手動で公開しようとしましたが、状況は変わらないようです。
ClassLoader classLoader = getClass().getClassLoader();
ResourceHandler staticHandler = new ResourceHandler(new ClassPathResourceManager(classLoader, STATIC_RESOURCE_ROOT))
.addWelcomeFiles(INDEX_HTML);
DeploymentInfo deploymentInfo = Servlets.deployment()
.setClassLoader(classLoader)
.setContextPath(ROOT_MAPPING)
.setDeploymentName(DEPLOYMENT_NAME)
.addServlet(
Servlets.servlet("RestServlet", CamelHttpTransportServlet.class)
.addMapping(REST_MAPPING)
.setLoadOnStartup(1)
);
DeploymentManager manager = Servlets.defaultContainer().addDeployment(deploymentInfo);
manager.deploy();
PathHandler path = Handlers.path()
.addPrefixPath(REST_MAPPING, manager.start())
.addPrefixPath(ROOT_MAPPING, staticHandler);
undertow = Undertow.builder()
.addHttpListener(port, LOCALHOST)
.setHandler(path)
.build();
undertow.start();
静的リソースは期待どおりに機能し、残りのサーブレットも実行されており、応答を取得しているようですが、CamelContext
起動しません。
ポートが使用されるため、キャメルでrestletなどを使用できないため、静的ファイルと残りに別のポートを使用する必要があります。Servlet
によって開始されたものをラクダに識別させる方法はありますUndertow
か?