[Httpunit-develop] Re: Redirects- still can't get it to work?
Brought to you by:
russgold
From: <nie...@dk...> - 2002-01-25 12:03:34
|
I still can't get it to work? I tried adding a simple test case to PseudoServerTest (copied from testRedirect): public void testRedirectDisabled() throws Exception { String resourceName =3D "something/redirected"; String resourceValue =3D "the undesired content"; String redirectName =3D "anOldOne"; PseudoServer ps =3D new PseudoServer(); int port =3D ps.getConnectedPort(); ps.setResource( resourceName, resourceValue ); ps.setResource( redirectName, "" ); ps.addResourceHeader( redirectName, "Location: http://localhost= :" + port + '/' + resourceName ); try { HttpUnitOptions.setAutoRedirect(false); WebConversation wc =3D new WebConversation(); WebRequest request =3D new GetMethodWebRequest ( "http://localhost:" + port + '/' + redirectName ); WebResponse response =3D wc.getResponse( request ); assertEquals( "Location header", "http://localhost:" + port= + '/' + resourceName, response.getHeaderField("Location")); } finally { ps.shutDown(); } } However, JUnit gives me the following error: testRedirectDisabled(com.meterware.httpunit.PseudoServerTest) com.meterware.httpunit.NoSuchFrameException: No frame named _top is currently active at com.meterware.httpunit.WebClient.getFrameContents(WebClient.java:91)= at com.meterware.httpunit.WebClient.getResponse(WebClient.java:67) at com.meterware.httpunit.PseudoServerTest.testRedirectDisabled(PseudoServ= erTest.java:205) at com.meterware.httpunit.HttpUnitSuite.main(HttpUnitSuite.java:33) Am I doing something wrong? Was this new functionality tested? I'm not quite sure about how the whole target/frame/state maintenance works, so= I'm not confident fixing this myself. BTW, isn't it rather dangerous to detect redirection just through the existence of a Location header? It is legal for non-redirect responses to have a Location header (e.g. = for 201 Created). You should probably change the code in WebClient line 214 from: } else if (!HttpUnitOptions.getAutoRedirect() || response.getHeaderFiel= d ( "Location" ) =3D=3D null) { to something like } else if (!HttpUnitOptions.getAutoRedirect() || (response.getResponseC= ode () < 300) || (response.getResponseCode() > 399)) { Niels Ull Harremo=EBs Principal Consultant PwC Consulting, Tuborg Boulevard 1, DK-2900 Hellerup, Denmark Tel +45 39 45 99 65, Mobile: +45 21 41 61 42, Fax +45 39 45 99 87 ---------------------------------------------------------------- The information transmitted is intended only for the person or entity t= o which it is addressed and may contain confidential and/or privileged material. Any review, retransmission, dissemination or other use of, o= r taking of any action in reliance upon, this information by persons or entities other than the intended recipient is prohibited. If you rece= ived this in error, please contact the sender and delete the material from a= ny computer.= |