small medium large xlarge

Generic-user-small
23 Apr 2015, 10:46
Mark Winspear (2 posts)

IDE: Intellij I have setup classes for AtmServer and AtmServlet On attempting to run from the CucumberRunner class (the one containing @RunWith and @CucumberOptions), I am getting the following exception - can anyone help please?:

`Error:(18, 28) java: no suitable constructor found for ServletHolder(nicebank.AtmServlet,java.lang.String)

constructor org.eclipse.jetty.servlet.ServletHolder.ServletHolder(java.lang.String,java.lang.Class<? extends javax.servlet.Servlet>) is not applicable

  (argument mismatch; nicebank.AtmServlet cannot be converted to java.lang.String)

constructor org.eclipse.jetty.servlet.ServletHolder.ServletHolder(java.lang.String,javax.servlet.Servlet) is not applicable

  (argument mismatch; nicebank.AtmServlet cannot be converted to java.lang.String)`

My classes appear the same as those in the source code for this chapter, see below:

AtmServer: `package nicebank;

import org.eclipse.jetty.server.Server; import org.eclipse.jetty.servlet.ServletContextHandler; import org.eclipse.jetty.servlet.ServletHolder;

public class AtmServer {

private final Server server;
public AtmServer(int port) {
    server = new Server(port);
    ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
    context.setContextPath("/");
    server.setHandler(context);

    context.addServlet(new ServletHolder(new AtmServlet(),"/"));
}


public void start() throws Exception {
    server.start();
    System.out.println("Listening on " + server.getURI());
}

public void stop() throws Exception {
    server.stop();
}

public static void main(String[] args) throws Exception {
    new AtmServer(9988).start();
} }`

AtmServlet: `package nicebank;

import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException;

public class AtmServlet extends HttpServlet{

protected void doGet (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    response.setContentType("text/html");
    response.setStatus(HttpServletResponse.SC_OK);
    response.getWriter().println("<html><head><title>Nice Bank ATM</title></head>" +
        "<body><h2>Welcome</h2></body></html>");
} }`
Generic-user-small
23 Apr 2015, 10:55
Mark Winspear (2 posts)

my fault - misplaced parentheses in AtmServer

‘context.addServlet(new ServletHolder(new AtmServlet(),”/”));’

should have been

‘context.addServlet(new ServletHolder(new AtmServlet()),”/”);’

You must be logged in to comment