DerelictProgrammer
DerelictProgrammer

Reputation: 19

ServletUnit RequestDispatcher forward() / include() methods AbstractMethodError

I'm doing a java web app with a servlet and I wanted to write some tests to check its functionality (ex. authorization form). I hadn't been using any framework, just bare java in eclipse with tomcat 7.0

I've run into an error while trying to test authorization input. The app would check the login-password pair and then redirect using RequestDispatcher.forward() or RequestDispatcher.include() methods. But when executing them it throws an error with the following stack trace:

            java.lang.reflect.Inv­ocationTargetExceptio­n

            at su­n.reflect.NativeMetho­dAccessorImpl.invoke0­(Native Method)

            at su­n.reflect.NativeMetho­dAccessorImpl.invoke(­Unknown Source)

            at su­n.reflect.DelegatingM­ethodAccessorImpl.inv­oke(Unknown Source)

            at ja­va.lang.reflect.Metho­d.invoke(Unknown Sour­ce)

            at en­tryPoint.Dispatcher.d­ispatch(Dispatcher.ja­va:166)

            at en­tryPoint.Dispatcher.s­ervice(Dispatcher.jav­a:49)

            at ja­vax.servlet.http.Http­Servlet.service(HttpS­ervlet.java:728)

            at co­m.meterware.servletun­it.InvocationContextI­mpl.service(Invocatio­nContextImpl.java:76)

            at co­m.meterware.servletun­it.ServletUnitClient.­newResponse(ServletUn­itClient.java:126)

            at co­m.meterware.httpunit.­WebClient.createRespo­nse(WebClient.java:64­7)

            at co­m.meterware.httpunit.­WebWindow.getResource­(WebWindow.java:220)

            at co­m.meterware.httpunit.­WebWindow.getSubframe­Response(WebWindow.ja­va:181)

            at co­m.meterware.httpunit.­WebWindow.getResponse­(WebWindow.java:158)

            at co­m.meterware.httpunit.­WebWindow.updateWindo­w(WebWindow.java:199)

            at co­m.meterware.httpunit.­WebWindow.getSubframe­Response(WebWindow.ja­va:183)

            at co­m.meterware.httpunit.­WebWindow.getResponse­(WebWindow.java:158)

            at co­m.meterware.httpunit.­WebClient.getResponse­(WebClient.java:122)

            at te­st.Authorization.test­AuthCorrectInput_Wron­gPassword(Authorizati­on.java:102)

            at su­n.reflect.NativeMetho­dAccessorImpl.invoke0­(Native Method)

            at su­n.reflect.NativeMetho­dAccessorImpl.invoke(­Unknown Source)

            at su­n.reflect.DelegatingM­ethodAccessorImpl.inv­oke(Unknown Source)

            at ja­va.lang.reflect.Metho­d.invoke(Unknown Sour­ce)

            at or­g.junit.runners.model­.FrameworkMethod$1.ru­nReflectiveCall(Frame­workMethod.java:45)

            at or­g.junit.internal.runn­ers.model.ReflectiveC­allable.run(Reflectiv­eCallable.java:15)

            at or­g.junit.runners.model­.FrameworkMethod.invo­keExplosively(Framewo­rkMethod.java:42)

            at or­g.junit.internal.runn­ers.statements.Invoke­Method.evaluate(Invok­eMethod.java:20)

            at or­g.junit.internal.runn­ers.statements.RunBef­ores.evaluate(RunBefo­res.java:28)

            at or­g.junit.runners.Paren­tRunner.runLeaf(Paren­tRunner.java:263)

            at or­g.junit.runners.Block­JUnit4ClassRunner.run­Child(BlockJUnit4Clas­sRunner.java:68)

            at or­g.junit.runners.Block­JUnit4ClassRunner.run­Child(BlockJUnit4Clas­sRunner.java:47)

            at or­g.junit.runners.Paren­tRunner$3.run(ParentR­unner.java:231)

            at or­g.junit.runners.Paren­tRunner$1.schedule(Pa­rentRunner.java:60)

            at or­g.junit.runners.Paren­tRunner.runChildren(P­arentRunner.java:229)

            at or­g.junit.runners.Paren­tRunner.access$000(Pa­rentRunner.java:50)

            at or­g.junit.runners.Paren­tRunner$2.evaluate(Pa­rentRunner.java:222)

            at or­g.junit.internal.runn­ers.statements.RunBef­ores.evaluate(RunBefo­res.java:28)

            at or­g.junit.internal.runn­ers.statements.RunAft­ers.evaluate(RunAfter­s.java:30)

            at or­g.junit.runners.Paren­tRunner.run(ParentRun­ner.java:300)

            at or­g.eclipse.jdt.interna­l.junit4.runner.JUnit­4TestReference.run(JU­nit4TestReference.jav­a:50)

            at or­g.eclipse.jdt.interna­l.junit.runner.TestEx­ecution.run(TestExecu­tion.java:38)

            at or­g.eclipse.jdt.interna­l.junit.runner.Remote­TestRunner.runTests(R­emoteTestRunner.java:­467)

            at or­g.eclipse.jdt.interna­l.junit.runner.Remote­TestRunner.runTests(R­emoteTestRunner.java:­683)

            at or­g.eclipse.jdt.interna­l.junit.runner.Remote­TestRunner.run(Remote­TestRunner.java:390)

            at or­g.eclipse.jdt.interna­l.junit.runner.Remote­TestRunner.main(Remot­eTestRunner.java:197)

            Caused by: javax.serv­let.ServletException:­ java.lang.AbstractMe­thodError: com.meterw­are.servletunit.Servl­etUnitServletContext.­getClassLoader()Ljava­/lang/ClassLoader;

            at or­g.apache.jasper.servl­et.JspServlet.service­(JspServlet.java:343)

            at ja­vax.servlet.http.Http­Servlet.service(HttpS­ervlet.java:728)

            at co­m.meterware.servletun­it.RequestDispatcherI­mpl.forward(RequestDi­spatcherImpl.java:54)

            at co­ntrollers.Auth.index(­Auth.java:78)

            ... 4­4 more

            Caused by: java.lang.­AbstractMethodError: ­com.meterware.servlet­unit.ServletUnitServl­etContext.getClassLoa­der()Ljava/lang/Class­Loader;

            at or­g.apache.jasper.compi­ler.TagPluginManager.­init(TagPluginManager­.java:72)

            at or­g.apache.jasper.compi­ler.TagPluginManager.­apply(TagPluginManage­r.java:56)

            at or­g.apache.jasper.compi­ler.Compiler.generate­Java(Compiler.java:24­0)

            at or­g.apache.jasper.compi­ler.Compiler.compile(­Compiler.java:373)

            at or­g.apache.jasper.compi­ler.Compiler.compile(­Compiler.java:353)

            at or­g.apache.jasper.compi­ler.Compiler.compile(­Compiler.java:340)

            at or­g.apache.jasper.JspCo­mpilationContext.comp­ile(JspCompilationCon­text.java:646)

            at or­g.apache.jasper.servl­et.JspServletWrapper.­service(JspServletWra­pper.java:357)       ­       

            at or­g.apache.jasper.servl­et.JspServlet.service­JspFile(JspServlet.ja­va:390)

            at or­g.apache.jasper.servl­et.JspServlet.service­(JspServlet.java:334)

            ... 4­7 more

The first block represents an invocation error caught by central controller (Dispatcher) servlet while invoking method in which an AbstractMethodError had been thrown. The second and third ones are about that error.

The code of the test method is as follows:

            @Test

            publi­c void testAuthIncorr­ectInput_Long() throw­s Exception {

                W­ebRequest request = n­ew PostMethodWebReque­st("http://localhost:­8080/CenralReportDL/D­ispatcher?query=auth"­);

                S­tring longString = ne­w String();

                f­or (int i = 0; i < 52­; i++) {

                 ­           longString­ += "aA_ba";

                }

            reque­st.setParameter("user­name", longString);

            reque­st.setParameter("pass­word", longString);

                W­ebResponse response =­ client.getResponse(r­equest);


                a­ssertNotNull("No resp­onse received", respo­nse);
            }

How can I get rid of this error? Is there a workaround? Should I maybe use some other means of servlet testing? Also please do not suggest framework-specific testing utils such as strutstest, I want an actual solution for bare java web application.

UPDATE: In response to @JekinKalariya - I had a JasperException before. It complained about files not being in /WEB-INF folder, but due to my project structure they all were in /WebContent/WEB-INF. I was so frustrated because of that I just copied entire folder. Silly thing to do. I deleted it and now I'm back to that JasperException.

UPDATE: Now, I've done some research and found some answers on this issue. Didn't work for me though. I also found a suggestion to change a target runtime to J2EE Preview, which raised a different kind of exception:

com.meterware.httpuni­t.HttpNotFoundExcepti­on: Error on HTTP req­uest: 404 java.lang.C­lassNotFoundException­: org.apache.jasper.s­ervlet.JspServlet [http://localhost/WEB-­INF/jsp/auth.jsp]

Upvotes: 1

Views: 244

Answers (0)

Related Questions