2

を使用してアプリケーションを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.RestConsumerFactoryGuice は 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か?

4

1 に答える 1

1

わかりました、ついにどこが間違っていたのかわかりました。

私は常に.component("servlet")and notを使用していたと思います.component("RestServlet")が、Camel は以前はこれを自動的にリンクしませんでした。

このセクションを次のように変更しました

restConfiguration()
            .bindingMode(RestBindingMode.json)
            .component("servlet")
            .dataFormatProperty("prettyPrint", "true")
            .endpointProperty("servletName", "RestServlet);

そして、サーブレットのマッピングを/*orに変更した展開は、内部request.getPathInfo()に戻ります。NB私は最初にcontextPathを設定し たため、セッションとCookieが台無しになったため、問題が発生しましたnullCamelHttpTransportServlet/rest/*

DeploymentInfo deploymentInfo = Servlets.deployment()
            .setClassLoader(classLoader)
            .setContextPath("/rest/")
            .setDeploymentName(DEPLOYMENT_NAME)
            .addServlet(
                    Servlets.servlet("RestServlet", CamelHttpTransportServlet.class)
                            .addMapping("/*")
                            .setLoadOnStartup(1)
            );
于 2015-10-04T14:55:25.003 に答える