4

I want to login https://pacer.login.uscourts.gov/csologin/login.jsf. i have used html unit for submitting a login form. here is my code:

public void submittingForm() throws Exception {
    final WebClient webClient = new WebClient();

    // Get the first page
    final HtmlPage page1 = webClient.getPage("https://pacer.login.uscourts.gov/csologin/login.jsf");

    // Get the form that we are dealing with and within that form, 
    // find the submit button and the field that we want to change.
    final HtmlForm form = page1.getFormByName("login");

   // final HtmlSubmitButton button = form.getButtonByName("login:j_idt184");
    final HtmlTextInput textField = form.getInputByName("login:loginName");
    final HtmlTextInput textField1 = form.getInputByName("login:password");
    // Change the value of the text field
    textField.setValueAttribute("XXX");
textField1.setValueAttribute("XXX");
    // Now submit the form by clicking the button and get back the second page.
    final HtmlPage page2 = form.getButtonByName("login:j_idt184").click();
System.out.println(page2.asText());
    webClient.closeAllWindows();
}

But it coutinue showing same error:

Exception in thread "main" java.lang.IllegalAccessError: class com.gargoylesoftware.htmlunit.javascript.regexp.HtmlUnitRegExpProxy$FixedSubString cannot access its superclass net.sourceforge.htmlunit.corejs.javascript.regexp.SubString
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:791)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
    at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
    at com.gargoylesoftware.htmlunit.javascript.HtmlUnitContextFactory.makeContext(HtmlUnitContextFactory.java:227)
    at net.sourceforge.htmlunit.corejs.javascript.Context.enter(Context.java:439)
    at net.sourceforge.htmlunit.corejs.javascript.Context.call(Context.java:535)
    at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.call(ContextFactory.java:538)
    at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.initialize(JavaScriptEngine.java:157)
    at com.gargoylesoftware.htmlunit.WebClient.initialize(WebClient.java:1141)
    at com.gargoylesoftware.htmlunit.WebWindowImpl.setEnclosedPage(WebWindowImpl.java:109)
    at com.gargoylesoftware.htmlunit.html.HTMLParser.parse(HTMLParser.java:200)
    at com.gargoylesoftware.htmlunit.html.HTMLParser.parseHtml(HTMLParser.java:179)
    at com.gargoylesoftware.htmlunit.DefaultPageCreator.createHtmlPage(DefaultPageCreator.java:221)
    at com.gargoylesoftware.htmlunit.DefaultPageCreator.createPage(DefaultPageCreator.java:106)
    at com.gargoylesoftware.htmlunit.WebClient.loadWebResponseInto(WebClient.java:433)
    at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:311)
    at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:373)
    at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:358)
    at htmlunit.HtmlUnit.submittingForm(HtmlUnit.java:63)
    at htmlunit.HtmlUnit.main(HtmlUnit.java:28)
Java Result: 1

how to overcome above error and successfull login to above url.i am using following jar in my code: htmlunit2.9jar,commons-code.jar,etc. which jar need to avoid above error.

please provide your suggestion.

thanks

atul

Atul Thakre
  • 502
  • 3
  • 8
  • 24
  • Can you verify your classpath? Sounds like you have duplicate JARs on the classpath, with different versions? – blagerweij Dec 16 '14 at 07:25

1 Answers1

1

The HtmlUnit installation I have on my system includes both htmlunit-2.15.jar (let's call this the "main" JAR) and htmlunit-core-js-2.15.jar (let's call this the "corejs" JAR). Looking inside the two JARs, I can see that the main JAR has com.gargoylesoftware.htmlunit.javascript.regexp.*, while the corejs JAR has net.sourceforge.htmlunit.corejs.javascript.regexp.*:

> for i in htmlunit-2.15.jar htmlunit-core-js-2.15.jar; do echo "===== $i ====="; unzip -l $i| grep regexp; done;
===== htmlunit-2.15.jar =====
        0  06-02-2014 19:53   com/gargoylesoftware/htmlunit/javascript/regexp/
      768  06-02-2014 19:53   com/gargoylesoftware/htmlunit/javascript/regexp/HtmlUnitRegExpProxy$FixedSubString.class
     1846  06-02-2014 19:53   com/gargoylesoftware/htmlunit/javascript/regexp/HtmlUnitRegExpProxy$RegExpData.class
    11530  06-02-2014 19:53   com/gargoylesoftware/htmlunit/javascript/regexp/HtmlUnitRegExpProxy.class
     1549  06-02-2014 19:53   com/gargoylesoftware/htmlunit/javascript/regexp/RegExpJsToJavaConverter$Tape.class
     3777  06-02-2014 19:53   com/gargoylesoftware/htmlunit/javascript/regexp/RegExpJsToJavaConverter.class
===== htmlunit-core-js-2.15.jar =====
        0  05-30-2014 10:28   net/sourceforge/htmlunit/corejs/javascript/regexp/
      944  05-30-2014 10:28   net/sourceforge/htmlunit/corejs/javascript/regexp/CompilerState.class
      712  05-30-2014 10:28   net/sourceforge/htmlunit/corejs/javascript/regexp/GlobData.class
    42350  05-30-2014 10:28   net/sourceforge/htmlunit/corejs/javascript/regexp/NativeRegExp.class
     6850  05-30-2014 10:28   net/sourceforge/htmlunit/corejs/javascript/regexp/NativeRegExpCtor.class
     1077  05-30-2014 10:28   net/sourceforge/htmlunit/corejs/javascript/regexp/REBackTrackData.class
      700  05-30-2014 10:28   net/sourceforge/htmlunit/corejs/javascript/regexp/RECharSet.class
      819  05-30-2014 10:28   net/sourceforge/htmlunit/corejs/javascript/regexp/RECompiled.class
     1245  05-30-2014 10:28   net/sourceforge/htmlunit/corejs/javascript/regexp/REGlobalData.class
      687  05-30-2014 10:28   net/sourceforge/htmlunit/corejs/javascript/regexp/RENode.class
      918  05-30-2014 10:28   net/sourceforge/htmlunit/corejs/javascript/regexp/REProgState.class
    14443  05-30-2014 10:28   net/sourceforge/htmlunit/corejs/javascript/regexp/RegExpImpl.class
     1072  05-30-2014 10:28   net/sourceforge/htmlunit/corejs/javascript/regexp/SubString.class

So I suspect that you are successfully including the main JAR in your $CLASSPATH, but not the corejs JAR. Thus, to solve the problem, you have to find the corejs JAR and include it in your $CLASSPATH.

Normally, once installed, these two JARs will live in the same directory. So, if this is the case for you, it will probably be easier for you to use the wildcard syntax in the $CLASSPATH to get both of them in one shot.

bgoldst
  • 34,190
  • 6
  • 38
  • 64