HTTP 500 error when accessing a custom servlet injected into Selenium grid

54 views
Skip to first unread message

Prvn

unread,
May 2, 2018, 10:04:32 AM5/2/18
to Selenium Users
I have a basic servlet that extends RegistryBasedServlet class. I did `mvn package` and made sure I am only using the packaged jar with dependencies. Then I started the selenium server with the following command


java -cp gridservlet-0.0.1-SNAPSHOT.jar:selenium-server-standalone-3.8.1.jar org.openqa.grid.selenium.GridLauncherV3 -role hub -port 8007 -maxSession 1 -newSessioaitTimeout 600000 -timeout 50 -servlets com.servlet.ClacServlet

But when I access http://localhost:8007/grid/admin/ClacServlet/ . I get the following exception

HTTP ERROR 500

Problem accessing /grid/admin/ClacServlet/. Reason:

    Server Error

Caused by:

javax.servlet.ServletException: com.servlet.ClacServlet-7dc222ae@5c7dbcc9==com.servlet.ClacServlet,jsp=null,order=-1,inst=false
	at org.seleniumhq.jetty9.servlet.ServletHolder.initServlet(ServletHolder.java:658)
	at org.seleniumhq.jetty9.servlet.ServletHolder.getServlet(ServletHolder.java:498)
	at org.seleniumhq.jetty9.servlet.ServletHolder.ensureInstance(ServletHolder.java:785)
	at org.seleniumhq.jetty9.servlet.ServletHolder.prepare(ServletHolder.java:770)
	at org.seleniumhq.jetty9.servlet.ServletHandler.doHandle(ServletHandler.java:530)
	at org.seleniumhq.jetty9.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:188)
	at org.seleniumhq.jetty9.server.session.SessionHandler.doHandle(SessionHandler.java:1595)
	at org.seleniumhq.jetty9.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:188)
	at org.seleniumhq.jetty9.server.handler.ContextHandler.doHandle(ContextHandler.java:1253)
	at org.seleniumhq.jetty9.server.handler.ScopedHandler.nextScope(ScopedHandler.java:168)
	at org.seleniumhq.jetty9.servlet.ServletHandler.doScope(ServletHandler.java:473)
	at org.seleniumhq.jetty9.server.session.SessionHandler.doScope(SessionHandler.java:1564)
	at org.seleniumhq.jetty9.server.handler.ScopedHandler.nextScope(ScopedHandler.java:166)
	at org.seleniumhq.jetty9.server.handler.ContextHandler.doScope(ContextHandler.java:1155)
	at org.seleniumhq.jetty9.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
	at org.seleniumhq.jetty9.server.handler.HandlerWrapper.handle(HandlerWrapper.java:132)
	at org.seleniumhq.jetty9.server.Server.handle(Server.java:561)
	at org.seleniumhq.jetty9.server.HttpChannel.handle(HttpChannel.java:334)
	at org.seleniumhq.jetty9.server.HttpConnection.onFillable(HttpConnection.java:251)
	at org.seleniumhq.jetty9.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:279)
	at org.seleniumhq.jetty9.io.FillInterest.fillable(FillInterest.java:104)
	at org.seleniumhq.jetty9.io.ChannelEndPoint$2.run(ChannelEndPoint.java:124)
	at org.seleniumhq.jetty9.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:679)
	at org.seleniumhq.jetty9.util.thread.QueuedThreadPool$2.run(QueuedThreadPool.java:597)
	at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.InstantiationException: com.servlet.ClacServlet
	at java.lang.Class.newInstance(Class.java:427)
	at org.seleniumhq.jetty9.server.handler.ContextHandler$Context.createInstance(ContextHandler.java:2535)
	at org.seleniumhq.jetty9.servlet.ServletContextHandler$Context.createServlet(ServletContextHandler.java:1326)
	at org.seleniumhq.jetty9.servlet.ServletHolder.newInstance(ServletHolder.java:1273)
	at org.seleniumhq.jetty9.servlet.ServletHolder.initServlet(ServletHolder.java:614)
	... 24 more
Caused by: java.lang.NoSuchMethodException: com.servlet.ClacServlet.<init>()
	at java.lang.Class.getConstructor0(Class.java:3082)
	at java.lang.Class.newInstance(Class.java:412)
	... 28 more

Caused by:

java.lang.InstantiationException: com.servlet.ClacServlet
	at java.lang.Class.newInstance(Class.java:427)
	at org.seleniumhq.jetty9.server.handler.ContextHandler$Context.createInstance(ContextHandler.java:2535)
	at org.seleniumhq.jetty9.servlet.ServletContextHandler$Context.createServlet(ServletContextHandler.java:1326)
	at org.seleniumhq.jetty9.servlet.ServletHolder.newInstance(ServletHolder.java:1273)
	at org.seleniumhq.jetty9.servlet.ServletHolder.initServlet(ServletHolder.java:614)
	at org.seleniumhq.jetty9.servlet.ServletHolder.getServlet(ServletHolder.java:498)
	at org.seleniumhq.jetty9.servlet.ServletHolder.ensureInstance(ServletHolder.java:785)
	at org.seleniumhq.jetty9.servlet.ServletHolder.prepare(ServletHolder.java:770)
	at org.seleniumhq.jetty9.servlet.ServletHandler.doHandle(ServletHandler.java:530)
	at org.seleniumhq.jetty9.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:188)
	at org.seleniumhq.jetty9.server.session.SessionHandler.doHandle(SessionHandler.java:1595)
	at org.seleniumhq.jetty9.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:188)
	at org.seleniumhq.jetty9.server.handler.ContextHandler.doHandle(ContextHandler.java:1253)
	at org.seleniumhq.jetty9.server.handler.ScopedHandler.nextScope(ScopedHandler.java:168)
	at org.seleniumhq.jetty9.servlet.ServletHandler.doScope(ServletHandler.java:473)
	at org.seleniumhq.jetty9.server.session.SessionHandler.doScope(SessionHandler.java:1564)
	at org.seleniumhq.jetty9.server.handler.ScopedHandler.nextScope(ScopedHandler.java:166)
	at org.seleniumhq.jetty9.server.handler.ContextHandler.doScope(ContextHandler.java:1155)
	at org.seleniumhq.jetty9.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
	at org.seleniumhq.jetty9.server.handler.HandlerWrapper.handle(HandlerWrapper.java:132)
	at org.seleniumhq.jetty9.server.Server.handle(Server.java:561)
	at org.seleniumhq.jetty9.server.HttpChannel.handle(HttpChannel.java:334)
	at org.seleniumhq.jetty9.server.HttpConnection.onFillable(HttpConnection.java:251)
	at org.seleniumhq.jetty9.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:279)
	at org.seleniumhq.jetty9.io.FillInterest.fillable(FillInterest.java:104)
	at org.seleniumhq.jetty9.io.ChannelEndPoint$2.run(ChannelEndPoint.java:124)
	at org.seleniumhq.jetty9.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:679)
	at org.seleniumhq.jetty9.util.thread.QueuedThreadPool$2.run(QueuedThreadPool.java:597)
	at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.NoSuchMethodException: com.servlet.ClacServlet.<init>()
	at java.lang.Class.getConstructor0(Class.java:3082)
	at java.lang.Class.newInstance(Class.java:412)
	... 28 more

Caused by:

java.lang.NoSuchMethodException: com.servlet.ClacServlet.<init>()
	at java.lang.Class.getConstructor0(Class.java:3082)
	at java.lang.Class.newInstance(Class.java:412)
	at org.seleniumhq.jetty9.server.handler.ContextHandler$Context.createInstance(ContextHandler.java:2535)
	at org.seleniumhq.jetty9.servlet.ServletContextHandler$Context.createServlet(ServletContextHandler.java:1326)
	at org.seleniumhq.jetty9.servlet.ServletHolder.newInstance(ServletHolder.java:1273)
	at org.seleniumhq.jetty9.servlet.ServletHolder.initServlet(ServletHolder.java:614)
	at org.seleniumhq.jetty9.servlet.ServletHolder.getServlet(ServletHolder.java:498)
	at org.seleniumhq.jetty9.servlet.ServletHolder.ensureInstance(ServletHolder.java:785)
	at org.seleniumhq.jetty9.servlet.ServletHolder.prepare(ServletHolder.java:770)
	at org.seleniumhq.jetty9.servlet.ServletHandler.doHandle(ServletHandler.java:530)
	at org.seleniumhq.jetty9.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:188)
	at org.seleniumhq.jetty9.server.session.SessionHandler.doHandle(SessionHandler.java:1595)
	at org.seleniumhq.jetty9.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:188)
	at org.seleniumhq.jetty9.server.handler.ContextHandler.doHandle(ContextHandler.java:1253)
	at org.seleniumhq.jetty9.server.handler.ScopedHandler.nextScope(ScopedHandler.java:168)
	at org.seleniumhq.jetty9.servlet.ServletHandler.doScope(ServletHandler.java:473)
	at org.seleniumhq.jetty9.server.session.SessionHandler.doScope(SessionHandler.java:1564)
	at org.seleniumhq.jetty9.server.handler.ScopedHandler.nextScope(ScopedHandler.java:166)
	at org.seleniumhq.jetty9.server.handler.ContextHandler.doScope(ContextHandler.java:1155)
	at org.seleniumhq.jetty9.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
	at org.seleniumhq.jetty9.server.handler.HandlerWrapper.handle(HandlerWrapper.java:132)
	at org.seleniumhq.jetty9.server.Server.handle(Server.java:561)
	at org.seleniumhq.jetty9.server.HttpChannel.handle(HttpChannel.java:334)
	at org.seleniumhq.jetty9.server.HttpConnection.onFillable(HttpConnection.java:251)
	at org.seleniumhq.jetty9.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:279)
	at org.seleniumhq.jetty9.io.FillInterest.fillable(FillInterest.java:104)
	at org.seleniumhq.jetty9.io.ChannelEndPoint$2.run(ChannelEndPoint.java:124)
	at org.seleniumhq.jetty9.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:679)
	at org.seleniumhq.jetty9.util.thread.QueuedThreadPool$2.run(QueuedThreadPool.java:597)
	at java.lang.Thread.run(Thread.java:745)

⇜Krishnan Mahadevan⇝

unread,
May 2, 2018, 10:06:54 AM5/2/18
to seleniu...@googlegroups.com
What does the constructor of your servlet look like ? 

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/622dea86-9585-437e-9689-0729f7903e4d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--

Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/

My Technical Scribbings @ http://rationaleemotions.wordpress.com/

Prvn

unread,
May 2, 2018, 10:08:16 AM5/2/18
to Selenium Users
Hello Krishnan,

public class ClacServlet extends RegistryBasedServlet {


    private static final long serialVersionUID = 4615464862476676155L;


    public ClacServlet(GridRegistry registry) {

        super(registry);

    }


    @Override

    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        doPost(req, resp);

    }


    @Override

    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        processServlet(req, resp);

    }

...

..

.....

⇜Krishnan Mahadevan⇝

unread,
May 2, 2018, 10:16:23 AM5/2/18
to seleniu...@googlegroups.com
Your constructor looks fine. The exception is talking about a missing method. Are you sure you aren't mixing up selenium versions ? If you built a jar of jars then you don't need to be referring to selenium jar in your class path. 



For more options, visit https://groups.google.com/d/optout.

Prvn

unread,
May 2, 2018, 10:31:18 AM5/2/18
to Selenium Users
I am using selenium server standalone jar 3.8.1 and in the servlet project I am using Maven dependency selenium-server 3.8.1

Yes I am building the servlet jar with selenium server and testNG as dependency. So are you saying in my java -cp command I dont have to specify selenium server jar?

⇜Krishnan Mahadevan⇝

unread,
May 2, 2018, 10:32:59 AM5/2/18
to seleniu...@googlegroups.com
Yes if you have an uber jar then you don't need to be including the selenium jar. Can you give it a whirl and post back your findings ?


For more options, visit https://groups.google.com/d/optout.

Prvn

unread,
May 2, 2018, 11:32:25 AM5/2/18
to Selenium Users
Ok. this is what I did

1. In my pom of the GridServlet there are two dependencies selenium-server and testng. selenium-server version is 3.8.1 (I also tried with 3.11.0)
2. Then I did mvn package
3. I see a jar with name gridservlet-0.0.1-SNAPSHOT-jar-with-dependencies.jar
4. Now I ran the command java -cp gridservlet-0.0.1-SNAPSHOT.jar org.openqa.grid.selenium.GridLauncherV3 -role hub -port 8007 -servlets com.servlet.ClacServlet
5. I see that the servlet was injected successfully. when the grid was started
6. Now In the browser I did http://localhost:8007/grid/admin/ClacServlet and still see HTTP error 500

Krishnan Mahadevan

unread,
May 2, 2018, 12:30:29 PM5/2/18
to seleniu...@googlegroups.com

Praveen,

 

I took a closer look at the codebase.

It looks like you would need to be adding a default constructor to your constructor and try again.

 

Even though the Selenium Grid basically has a 1 arg constructor for the RegistryBasedServlet class, the codebase doesn’t seem to be leveraging that constructor via reflection for instantiation of your servlet into the root servlet container.

 

Selenium grid seems to be trying to invoke the default constructor for instantiation and the registry is being added to the RegistryBasedServlet via an attribute in the servlet context.

 

I hope that adds clarity. My apologies for not calling this out earlier. Been a bit out of touch with the grid servlets

 

 

Thanks & Regards

Krishnan Mahadevan

 

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"

My Scribblings @ http://wakened-cognition.blogspot.com/

My Technical Scribbings @ http://rationaleemotions.wordpress.com/

Prvn

unread,
May 2, 2018, 1:27:50 PM5/2/18
to Selenium Users
Krishnan,

If I have a default no argument constructor then it says "Implicit super constructor RegistryBasedServlet() is undefined. Must explicitly invoke another constructor"

What do you mean by "adding a default constructor to your constructor "?

To unsubscribe from this group and stop receiving emails from it, send an email to selenium-users+unsubscribe@googlegroups.com.
To post to this group, send email to
selenium-users@googlegroups.com.


To view this discussion on the web visit

⇜Krishnan Mahadevan⇝

unread,
May 2, 2018, 1:42:27 PM5/2/18
to seleniu...@googlegroups.com
Add both the constructors. The no arg default constructor to facilitate instantiation and the 1 arg constructor to keep the parent class happy. 

You can have your default constructor call into the 1 arg constructor via a "this()" call. 

.


To view this discussion on the web visit

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Prvn

unread,
May 2, 2018, 1:49:44 PM5/2/18
to Selenium Users
I tried that earlier. Pls see the code below. But when I do this() it says "Recursive constructor invocation ClacServlet()"

public class ClacServlet extends RegistryBasedServlet {


    private static final long serialVersionUID = 4615464862476676155L;


    public ClacServlet(GridRegistry registry) {

        super(registry);

    }

    

    

    public ClacServlet() {

        this();

To unsubscribe from this group and stop receiving emails from it, send an email to selenium-users+unsubscribe@googlegroups.com.
To post to this group, send email to
selenium-users@googlegroups.com.


To view this discussion on the web visit

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/ffcb9f42-91a5-45f9-8127-c450447737f6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Krishnan Mahadevan

unread,
May 2, 2018, 1:52:34 PM5/2/18
to seleniu...@googlegroups.com

Praveen,

 

I meant something like below:

 

public class ClacServlet extends RegistryBasedServlet {

 

    private static final long serialVersionUID = 4615464862476676155L;

 

    public ClacServlet(GridRegistry registry) {

        super(registry);

    }

   

    public ClacServlet() {

        this(null);

To view this discussion on the web visit

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
selenium-user...@googlegroups.com.
To post to this group, send email to
seleniu...@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/selenium-users/ffcb9f42-91a5-45f9-8127-c450447737f6%40googlegroups.com.
For more options, visit
https://groups.google.com/d/optout.

--

Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @
http://wakened-cognition.blogspot.com/

My Technical Scribbings @ http://rationaleemotions.wordpress.com/

--

You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to


To post to this group, send email to

Prvn

unread,
May 2, 2018, 2:01:59 PM5/2/18
to Selenium Users
Thanks a lot. It worked :) 

To unsubscribe from this group and stop receiving emails from it, send an email to selenium-users+unsubscribe@googlegroups.com.
To post to this group, send email to
selenium-users@googlegroups.com.


To view this discussion on the web visit

Reply all
Reply to author
Forward
0 new messages