2

I'm starting Jetty from inside the Java program itself. I'm simply trying to get it to point at a cgi-folder that I've placed underneath the package directory (/src/package/cgi-bin)

The problem is that every time I start up the server, it complains "no CGI bin!". Where is the correct location to put your cgi-bin and point at it? This is what I have:

public static void main(String[] args) throws Exception {
    // The core Jetty server running on 8080
    Server server = new org.eclipse.jetty.server.Server(8080);

    // Setup CGI routing
    ServletContextHandler context2 = new ServletContextHandler(ServletContextHandler.SESSIONS);
    context2.setContextPath("/");
    context2.setInitParameter("commandPrefix", "perl");

    // Where does this point to? 
    context2.setInitParameter("cgibinResourceBase", "cgi-bin");
    server.setHandler(context2);

    // Add the CGI Servlet
    context2.addServlet(new ServletHolder(new Cgi()), "/cgi");

    server.start();
    server.join();
}

See Jetty setInitParameter is NOT initializing any parameter for the answer to this question.

Community
  • 1
  • 1
joslinm
  • 7,845
  • 6
  • 49
  • 72

3 Answers3

1

In looking at the code it appears that your setInitParameter was not set appropriately. You seem to be doing the right thing although we use XML to configure Jetty and I'm not familiar with doing it in code.

Have you tried to add the servlet before setting the handler? Is it possible that it is called init at the wrong time?

String tmp = getInitParameter("cgibinResourceBase");
if (tmp == null) {
    tmp = getInitParameter("resourceBase");
    if (tmp == null)
        tmp = getServletContext().getRealPath("/");
}

if (tmp == null) {
    Log.warn("CGI: no CGI bin !");
    throw new ServletException();
}

No much help but I'll leave this answer up until someone posts a better answer.

Gray
  • 115,027
  • 24
  • 293
  • 354
  • I guess this was the best we could do, but thanks though. It did help me in the right direction, but that method is actually called upon server.start(). I simply do not understand why setInitParameter isn't carrying the information over. – joslinm Jan 31 '12 at 02:02
  • 1
    the source has moved, it is now here: http://git.eclipse.org/c/jetty/org.eclipse.jetty.project.git/tree/jetty-servlets/src/main/java/org/eclipse/jetty/servlets/CGI.java – Janus Troelsen Jun 30 '13 at 14:41
1

Via Jetty setInitParameter is NOT initializing any parameter

The problem is that I was setting the parameter on the context, when I should have been setting it on the ServletHolder

Community
  • 1
  • 1
joslinm
  • 7,845
  • 6
  • 49
  • 72
0

It seems that you are not pointing to the correct location for your cgi-bin.

// Where does this point to? 
context2.setInitParameter("cgibinResourceBase", "cgi-bin");

The correct path should be relative to your WEB-INF directory, or as a fail-safe, the absolute path on your file-system.

In this case, you should use /src/package/cgi-bin, assuming that src is at the root of your file-system. If it is not, you can use something as the following:

// The second argument is the absolute path to your cgi-bin
context2.setInitParameter("cgibinResourceBase", "/usr/local/some-more-path/src/package/cgi-bin");
Abhishek
  • 192
  • 2
  • 8