updateAddressPort(port, PORT);
if (standalone) {
TokenTestUtils.updateSTSPort((BindingProvider)port, STSPORT2);
}
TokenStore tokenStore = new MemoryTokenStore();
((BindingProvider)port).getRequestContext().put(
TokenStore.class.getName(), tokenStore
);
// Make a successful invocation
((BindingProvider)port).getRequestContext().put(
"ws-security.username", "alice"
);
doubleIt(port, 25);
// Change the STSClient so that it can no longer find the STS
BindingProvider p = (BindingProvider)port;
clearSTSClient(p);
// This invocation should be successful as the token is cached
doubleIt(port, 25);
((java.io.Closeable)port).close();
//
// Proxy no. 2
//
DoubleItPortType port2 =
service.getPort(portQName, DoubleItPortType.class);
updateAddressPort(port2, PORT);
if (standalone) {
TokenTestUtils.updateSTSPort((BindingProvider)port2, STSPORT2);
}
// Change the STSClient so that it can no longer find the STS
p = (BindingProvider)port2;
clearSTSClient(p);
// This should fail as the cache is not being used
try {
doubleIt(port2, 40);
fail("Failure expected as the token is not stored in the cache");
} catch (Exception ex) {
// expected
}
// Set the cache correctly
p.getRequestContext().put(TokenStore.class.getName(), tokenStore);
// Make another invocation - this should succeed as the token is cached
p.getRequestContext().put("ws-security.username", "alice");
doubleIt(port2, 40);
// Reset the cache - this invocation should fail
p.getRequestContext().put(TokenStore.class.getName(), new MemoryTokenStore());
try {
doubleIt(port2, 40);
fail("Failure expected as the cache is reset");
} catch (Exception ex) {
// expected