【问题标题】:Embedded Jetty + 2 Jersey Servlets: unable to load bothEmbedded Jetty + 2 Jersey Servlet:无法同时加载
【发布时间】:2020-12-14 18:16:34
【问题描述】:

请帮忙!

我在配置 Embedded Jetty 以在 2 个类中运行 2 个 Jersey Servlet 时遇到问题,包条目。它从 Eclipse 运行,但是一旦导出为可运行的 jar 文件,我得到 ERROR: 500,第二次运行。 它是 Maven 项目,我用来创建可运行 jar 的工具是 <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-shade-plugin</artifactId>

Server 点配置如下:

        ServletContextHandler context = new ServletContextHandler(ServletContextHandler.NO_SESSIONS);
        context.setContextPath("/");
        HttpConfiguration https = new HttpConfiguration();
        https.addCustomizer(new SecureRequestCustomizer());
        ServerConnector connector = new ServerConnector(jettyServer);
        connector.setPort(10001);
        jettyServer.setConnectors(new Connector[] { connector });

        jettyServer.setHandler(context);

        ServletHolder jerseyServletEntry = context.addServlet(org.glassfish.jersey.servlet.ServletContainer.class,
                "/entry/*");
        jerseyServletEntry.setInitOrder(0);
        jerseyServletEntry.setInitParameter("jersey.config.server.provider.classnames",
                EntryPoint.class.getCanonicalName());
        EntryPoint.logger.info("Server is starting up... ");

        ServletHolder jerseyServletNoEntry = context.addServlet(org.glassfish.jersey.servlet.ServletContainer.class,
                "/noentry/*");
        jerseyServletNoEntry.setInitOrder(1);
        jerseyServletNoEntry.setInitParameter("jersey.config.server.provider.classnames",
                NoEntryPoint.class.getCanonicalName());
        NoEntryPoint.logger.info("Server is starting up... ");

我遇到的邮递员错误:

<head>
    <meta http-equiv="Content-Type" content="text/html;charset=ISO-8859-1" />
    <title>Error 500 </title>
</head>

<body>
    <h2>HTTP ERROR: 500</h2>
    <p>Problem accessing /entry/input//7858/768434. Reason:
        <pre>    Request failed.</pre>
    </p>
    <hr /><i><small>Powered by Jetty://</small></i>
</body>

提醒:在 Eclipse 中运行良好,在控制台中使用 java -jar 命令运行时不会出现错误。

【问题讨论】:

标签: jersey jetty


【解决方案1】:

我已经通过更改我的 ServerPoint 中的配置解决了这个问题,如下所示:

代替:

ServletHolder jerseyServletEntry = context.addServlet(org.glassfish.jersey.servlet.ServletContainer.class,
                "/entry/*");
        jerseyServletEntry.setInitOrder(0);
        jerseyServletEntry.setInitParameter("jersey.config.server.provider.classnames",
                EntryPoint.class.getCanonicalName());
        EntryPoint.logger.info("Server is starting up... ");

        ServletHolder jerseyServletNoEntry = context.addServlet(org.glassfish.jersey.servlet.ServletContainer.class,
                "/noentry/*");
        jerseyServletNoEntry.setInitOrder(1);
        jerseyServletNoEntry.setInitParameter("jersey.config.server.provider.classnames",
                NoEntryPoint.class.getCanonicalName());
        NoEntryPoint.logger.info("Server is starting up... ");

我写道:

ServletHolder jerseyServletEntry = context.addServlet(org.glassfish.jersey.servlet.ServletContainer.class,
                "/api/*");
        jerseyServletEntry.setInitOrder(0);
        jerseyServletEntry.setInitParameter("jersey.config.server.provider.classnames",
                "entry.EntryPoint, entry.NoEntryPoint"); //upload both Jersey servlets
        ServerPoint.logger.info("Server is starting up... ");

但是现在,我发现 JCE 无法验证提供的 BC。尝试了这个解决方案,但没有奏效:bouncycastle error "JCE cannot authenticate the provider BC" with "jar-with-dependencies" 在 Eclipse 中工作正常,但在导出时不行。有什么想法吗?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-10-03
    • 1970-01-01
    • 2012-12-15
    • 2014-10-29
    • 2013-11-02
    • 2019-11-08
    • 1970-01-01
    相关资源
    最近更新 更多