You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by "Igor Vaynberg (JIRA)" <ji...@apache.org> on 2010/10/14 19:26:35 UTC

[jira] Resolved: (WICKET-2282) StringIndexOutOfBoundsException when using FormTester.submit() with form that redirects to "/" onSubmit()

     [ https://issues.apache.org/jira/browse/WICKET-2282?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Igor Vaynberg resolved WICKET-2282.
-----------------------------------

    Resolution: Invalid
      Assignee: Igor Vaynberg

the problem is that you are assuming that your application runs out of the root context, which in wicket tester it does not.

wicket tester uses application's name as the context and also as the servlet path, so your homepage is actually located on the 

/<context/<servlet path> url instead of just /

for your particular usecase the concrete url for homepage is

/WicketTester$DummyWebApplication/WicketTester$DummyWebApplication

if you want to redirect to the root of your application then you should use the "./" syntax instead of "/". the dot as the first char of url means make the rest context-relative.

so if you change your code to this:

getRequestCycle().setRequestTarget(new RedirectRequestTarget("./"));

it will work inside the test.

if you want to make your tests work out of the root context then you have to provide your own mockhttpservletrequest subclass with getcontet() and getservletpath() overridden.

> StringIndexOutOfBoundsException when using FormTester.submit() with form that redirects to "/" onSubmit()
> ---------------------------------------------------------------------------------------------------------
>
>                 Key: WICKET-2282
>                 URL: https://issues.apache.org/jira/browse/WICKET-2282
>             Project: Wicket
>          Issue Type: Bug
>          Components: wicket
>    Affects Versions: 1.4-RC1, 1.4-RC2, 1.4-RC3, 1.4-RC4
>            Reporter: Brad Fritz
>            Assignee: Igor Vaynberg
>            Priority: Minor
>         Attachments: demo-WICKET-2282.patch, external-redirect-during-form-submit.zip
>
>
> When testing a form that redirects to "/" in onSubmit() with FormTester, the test fails with:
>       INFO  - MockHttpServletRequest     - Redirecting to /WicketApplication/
>       ERROR - RequestCycle               - String index out of range: -17
>       java.lang.StringIndexOutOfBoundsException: String index out of range: -17
>           at java.lang.String.substring(String.java:1768)
>           at java.lang.String.substring(String.java:1735)
>           at org.apache.wicket.protocol.http.WicketFilter.getRelativePath(WicketFilter.java:575)
>           at org.apache.wicket.protocol.http.servlet.ServletWebRequest.getPath(ServletWebRequest.java:170)
>           at org.apache.wicket.protocol.http.request.WebRequestCodingStrategy.getRequestPath(WebRequestCodingStrategy.java:1042)
>           at org.apache.wicket.protocol.http.request.WebRequestCodingStrategy.decode(WebRequestCodingStrategy.java:202)
>           at org.apache.wicket.Request.getRequestParameters(Request.java:172)
>           at org.apache.wicket.RequestCycle.step(RequestCycle.java:1300)
>           at org.apache.wicket.RequestCycle.steps(RequestCycle.java:1418)
>           at org.apache.wicket.RequestCycle.request(RequestCycle.java:544)
>           at org.apache.wicket.protocol.http.MockWebApplication.postProcessRequestCycle(MockWebApplication.java:545)
>           at org.apache.wicket.protocol.http.MockWebApplication.processRequestCycle(MockWebApplication.java:517)
>           at org.apache.wicket.util.tester.FormTester.submit(FormTester.java:661)
>           at quickstart.TestHomePage.testRenderMyPage(TestHomePage.java:26)
>           [..]
> This bug is similar to WICKET-1864 and *might* have been a regression during the
> fix for WICKET-702.
> Quickstart project to reproduce the problem attached.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.