0

PLEASE HELP!

I'm having an issue regarding configuration of Embedded Jetty to run 2 Jersey Servlets in 2 classes, package entry. It runs from the Eclipse, but once when exported as runnable jar file, I'm getting ERROR: 500, for the one run secondly. It is Maven project and the tool I'm using for creating runnable jar is <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-shade-plugin</artifactId>,

while the Server point is configured as below:

        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... ");

The Postman error I've got :

<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>

Reminder: It works fine in Eclipse, and no errors listed when running in console with java -jar command.

Frant
  • 5,382
  • 1
  • 16
  • 22
  • Try to register [this exception mapper](https://stackoverflow.com/a/33684719/2587435). See if there is any exception thrown that's not being handled. – Paul Samsotha Dec 09 '20 at 15:29

1 Answers1

0

I have solved the issue by changing configuration in my ServerPoint as below:

Instead of:

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... ");

I wrote:

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... ");

But now, I'm getting JCE cannot authenticate the provide BC. Tried this solution, but it didn't worked: bouncycastle error "JCE cannot authenticate the provider BC" with "jar-with-dependencies" Works fine when in Eclipse, but not when exported. Any idea?