[ 
http://issues.apache.org/jira/browse/CACTUS-61?page=comments#action_12315389 ] 

Natalia Kowalczyk commented on CACTUS-61:
-----------------------------------------

IWorkaround: To prevent NullPointerException when processing a page that 
includes
JavaScript via src attribute, add following code at the beginning of the
endXXX() method before calling any HttpUnit methods that parse the
response:

    public void endXXX(WebResponse webResponse) {
        ServletUnitClient client = ServletUnitClient.newClient(
            new InvocationContextFactory() {

            public InvocationContext newInvocation(
                 ServletUnitClient client,
                    FrameSelector targetFrame, WebRequest request,
                    Dictionary clientHeaders, byte[] messageBody)
                    throws IOException, MalformedURLException {
                return new InvocationContextImpl(request);
            }

            public HttpSession getSession(String sessionId,
                         boolean create) {
                return null;
            }

        });

        try {
            webResponse = client.getResponse(
                             new InvocationContextImpl(webResponse));
        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (SAXException e) {
            e.printStackTrace();
        }
        
        // webResponse can be now queried
        
    }

    static class InvocationContextImpl implements InvocationContext {
        private WebResponse webResponse;

        public InvocationContextImpl(WebRequest webRequest)
                throws MalformedURLException, IOException {
            try {
                webResponse = new WebConversation().
                                      getResponse(webRequest);
            } catch (SAXException e) {
                e.printStackTrace();
                throw new IOException(e.getMessage());
            }
        }

        public InvocationContextImpl(WebResponse webResponse) {
            this.webResponse = webResponse;
        }

        public HttpServletRequest getRequest() {
            return null;
        }

        public HttpServletResponse getResponse() {
            return null;
        }

        public void service() throws ServletException, IOException {
        }

        public Servlet getServlet() throws ServletException {
            return null;
        }

        public WebResponse getServletResponse() throws IOException {
            return webResponse;
        }

        public FrameSelector getFrame() {
            return FrameSelector.TOP_FRAME;
        }

        public void pushIncludeRequest(RequestDispatcher rd,
                HttpServletRequest request,
                HttpServletResponse response)
                throws ServletException {
        }

        public void pushForwardRequest(RequestDispatcher rd,
                HttpServletRequest request,
                HttpServletResponse response)
                throws ServletException {
        }

        public void popRequest() {
        }

        public boolean isFilterActive() {
            return false;
        }

        public Filter getFilter() throws ServletException {
            return null;
        }

        public FilterChain getFilterChain() {
            return null;
        }

        public void pushFilter(ServletRequest request,
                ServletResponse response) {
        }

    }


> Cactus doesn't properly integrate w/HttpUnit. External Javascript generates 
> NullPointerException
> ------------------------------------------------------------------------------------------------
>
>          Key: CACTUS-61
>          URL: http://issues.apache.org/jira/browse/CACTUS-61
>      Project: Cactus
>         Type: Bug
>   Components: Framework
>     Versions: 1.5-rc1
>  Environment: Operating System: Windows NT/2K
> Platform: PC
>     Reporter: Evgeny Burya

>
> We've tried Cactus 1.4.1 and 1.5 Beta1.
> They both throw NullPointerException while trying to execute 
> com.meterware.httpunit.WebResponse.getFormWithID() in endXXX() method. The 
> problem is linked to Parsing of External JavaScript and Usage of window 
> object 
> (==null) in HttpUnit.
> This problem is really critical for us, So I'd like to get your quick 
> response.
> Pls find the exception stack trace below (for 1.5 Beta1):
> There was 1 error:
> 1) testXXX(com.blablabla.UserSyncPrefActionHandlerTest)
> java.lang.NullPointerException
>       at com.meterware.httpunit.ParsedHTML.getIncludedScript
> (ParsedHTML.java:305)
>       at com.meterware.httpunit.ParsedHTML.getScript(ParsedHTML.java:289)
>       at com.meterware.httpunit.ParsedHTML.interpretScriptElement
> (ParsedHTML.java:269)
>       at com.meterware.httpunit.ParsedHTML.access$600(ParsedHTML.java:37)
>       at com.meterware.httpunit.ParsedHTML$ScriptFactory.recordElement
> (ParsedHTML.java:404)
>       at com.meterware.httpunit.ParsedHTML$2.processElement
> (ParsedHTML.java:556)
>       at com.meterware.httpunit.NodeUtils$PreOrderTraversal.perform
> (NodeUtils.java:169)
>       at com.meterware.httpunit.ParsedHTML.loadElements(ParsedHTML.java:566)
>       at com.meterware.httpunit.ParsedHTML.getElementWithID
> (ParsedHTML.java:225)
>       at com.meterware.httpunit.ParsedHTML.getFormWithID(ParsedHTML.java:211)
>       at com.meterware.httpunit.WebResponse.getFormWithID
> (WebResponse.java:329)
>       at com.blablabla.UserSyncPrefActionHandlerTest.endActionUserSyncPrefEdit
> (UserSyncPrefActionHandlerTest.java:97)
>       at 
> org.apache.cactus.internal.client.WebClientTestCaseDelegate.callGenericEndMethod
> (WebClientTestCaseDelegate.java;org/apache/cactus/util/log/LogAspect.aj[1k]:189)
>       at 
> org.apache.cactus.internal.client.WebClientTestCaseDelegate.dispatch75_callEndMe
> thod(WebClientTestCaseDelegate.java;org/apache/cactus/util/log/LogAspect.aj
> [1k]:244)
>       at 
> org.apache.cactus.internal.client.WebClientTestCaseDelegate.around75_callEndMeth
> od(WebClientTestCaseDelegate.java;org/apache/cactus/util/log/LogAspect.aj
> [1k]:1240)
>       at 
> org.apache.cactus.internal.client.WebClientTestCaseDelegate.callEndMethod
> (WebClientTestCaseDelegate.java;org/apache/cactus/util/log/LogAspect.aj[1k]:240)
>       at 
> org.apache.cactus.internal.client.WebClientTestCaseDelegate.runGenericTest
> (WebClientTestCaseDelegate.java;org/apache/cactus/util/log/LogAspect.aj[1k]:285)
>       at org.apache.cactus.internal.client.WebClientTestCaseDelegate.runTest
> (WebClientTestCaseDelegate.java;org/apache/cactus/util/log/LogAspect.aj[1k]:258)
>       at org.apache.cactus.ServletTestCase.runTest(ServletTestCase.java:289)
>       at org.apache.cactus.ServletTestCase.runBare(ServletTestCase.java:251)
>       at com.intellij.rt.execution.junit.TextTestRunner.main
> (TextTestRunner.java:12)

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to