/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 5017051 6360774
* @summary Tests CR 5017051 & 6360774
*/
/*
* Part 1:
* First request sent to the http server will not have an "Authorization" header set and
* the server will respond with a 401, but not until it has set a cookie in the response
* headers. The subsequent request ( comes from HttpURLConnection's authentication retry )
* will have the appropriate Authorization header and the servers context handler will be
* invoked. The test passes only if the client (HttpURLConnection) has sent the cookie
* in its second request that had been set via the first response from the server.
*
* Part 2:
* Preload the CookieManager with a cookie. Make a http request that requires authentication
* The cookie will be sent in the first request (without the Authorization header), the
* server will respond with a 401 (from MyBasicAuthFilter) and the client will add the
* appropriate Authorization header. This tests ensures that there is only one Cookie header
* in the request that actually makes it to the Http servers context handler.
*/
public class B5017051
{
{
new B5017051();
}
public B5017051()
{
try {
doClient();
} catch (IOException ioe) {
}
}
void doClient() {
try {
// Part 1
if (resp != 200)
throw new RuntimeException("Failed: Part 1, Response code is not 200");
// Part 2
// can use the global CookieHandler used for the first test as the URL's are different
// preload the CookieHandler with a cookie for our URL
// so that it will be sent during the first request
if (resp != 200)
throw new RuntimeException("Failed: Part 2, Response code is not 200");
} catch (IOException e) {
e.printStackTrace();
} catch (URISyntaxException ue) {
} finally {
}
}
/**
* Http Server
*/
// create HttpServer context for Part 1.
// CookieFilter needs to be executed before Authenticator.
// create HttpServer context for Part 2.
httpServer.start();
}
}
}
}
}
// there should only be one Cookie header
}
}
}
}
}
{
super(realm);
}
}
}
{
{
}
return new String("Filter for setting a cookie for requests without an \"Authorization\" header.");
}
}
}