Custom Proxy and Servlet for Selenium not working

129 views
Skip to first unread message

olanrewaju ısaac Elisha

unread,
Nov 11, 2014, 11:31:17 AM11/11/14
to seleniu...@googlegroups.com
Hello,

I have overridden  DefaultRemoteProxy to provide custom Proxy Functionality.

public class MyRemoteProxy extends DefaultRemoteProxy{
 
    public MyRemoteProxy(RegistrationRequest request, Registry registry) throws IOException {
    super(request, registry);
    preInit(); // purpose to send a request to the custom Servlet injected on the Node. 
    }
    
private  void preInit(){
 
           HttpClient client = new DefaultHttpClient();
           StringBuilder url = new StringBuilder();
           url.append("http://");
           url.append(getRemoteHost().getHost());
           url.append(":").append(getRemoteHost().getPort());
           url.append("/extra/");
           url.append(CloseAllBrowserServlet.class.getSimpleName());
           HttpPost post = new HttpPost(url.toString());
           try {
               client.execute(post);
           } catch (ClientProtocolException e) {
              // log.log(Level.SEVERE, e.getMessage(), e);
           } catch (IOException e) {
              // log.log(Level.SEVERE, e.getMessage(), e);
           }
          
  }
}

the object here is to send a post request to the injected Servlet on the node.

I use this Ant file to start the Node and passed both Proxy and Servlet as Argument parameter.

<java jar="${selenium.jar}" fork="yes" spawn="no" maxmemory="768m" failonerror="true">
<classpath>
<pathelement location="${selenium.jar}" />
<pathelement location="${jar.myproxy}" /> <!--jar containing Custom Proxy and Servlet -->
</classpath>
<arg line="-role node" />
<arg line="-port ${selenium.gridNode.nodePort}" />
<arg line="-hub http://${selenium.gridNode.hubHost}:${selenium.gridNode.hubPort}/grid/register"/>

<arg line="-servlets com.selenium.automation.test.CloseAllBrowserServlet" /> <!-Custom Servlet ->
<arg line="-proxy com.selenium.automation.test.MyRemoteProxy" /> <!-- Custom Proxy --> 
</java>

I have similar Ant file on the Hub and I supplied the Custom Proxy as argument to it.

The problem is, when i start the Node using this Ant script, i get error message: 
"Could not register the Node to the Hub"

Could anyone Show what i did wrong ? i followed the doc available on the Selenium website.

The custom Jar file was on the Class path of both Hub and Node.

Please help.

Thanks

Krishnan Mahadevan

unread,
Nov 11, 2014, 11:57:10 AM11/11/14
to Selenium Users

Your grid console should tell you what exception was raised when the registration request failed. Did u take a look at it ?

--
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/d040fc23-5611-40ad-bf41-a791809dd72e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

olanrewaju ısaac Elisha

unread,
Nov 12, 2014, 10:06:32 AM11/12/14
to seleniu...@googlegroups.com
the error message didn't include a particular a name Exception, otherwise i would have looked it up.
the message on the screen  is:  " couldn't register this node. Error sending the registration request..  

please see attached file for the screen shot.

Thanks.

--
You received this message because you are subscribed to a topic in the Google Groups "Selenium Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/selenium-users/ud0iuQBOP1w/unsubscribe.
To unsubscribe from this group and all its topics, send an email to selenium-user...@googlegroups.com.

To post to this group, send email to seleniu...@googlegroups.com.
seleniumNode_error.png

Krishnan Mahadevan

unread,
Nov 12, 2014, 12:17:07 PM11/12/14
to Selenium Users

I was asking about the hub console and not the node console. What does the terminal from where you started the hub say ?

olanrewaju ısaac Elisha

unread,
Nov 13, 2014, 10:15:07 AM11/13/14
to seleniu...@googlegroups.com
Thanks very much, i just pulled the log from the Hub and i notice a ClassNotFoundException, the Hub could not find the Custome Proxy.

Attached here it the is the error log.

Sincerely.


hub_log.png

Krishnan Mahadevan

unread,
Nov 13, 2014, 11:27:11 AM11/13/14
to Selenium Users

So am guessing you now know what to do don't you ?

If not then here's what you should be doing.

1. Copy the jar that has your proxy into the directory where your standalone selenium jar resides and then use java -cp to spawn the hub. (Or)
2. Build an uber jar that contains both the selenium jar and your proxy class and then use it to spawn the hub and the node.

olanrewaju ısaac Elisha

unread,
Nov 14, 2014, 10:08:17 AM11/14/14
to seleniu...@googlegroups.com
Thank you very much Krishnan, your step by step guidance is out this world, thanks for your kindness.

1) I performed the first step you listed above. my Custom Jar file is placed at the same directory where Selenium Jar is               located, and i provide the custom jar in Selenium classpath.
       The problem is that, i couldn't  use java -cp to spawn the Hub because  the existing setup uses ANT file.
        I  attached the Ant file and directory structure here.

2) I probably will resort to the second solution - "uber jar", i don't know how to create one yet but i will quickly look it up.

Thanks a lot for being this helpful.

Sincerely.


 

server_ant.png
server_dir.png
Reply all
Reply to author
Forward
0 new messages