public void testCachePerProxySymmetric() throws Exception {
SpringBusFactory bf = new SpringBusFactory();
URL busFile = CachingTest.class.getResource("client/client.xml");
Bus bus = bf.createBus(busFile.toString());
SpringBusFactory.setDefaultBus(bus);
SpringBusFactory.setThreadDefaultBus(bus);
URL wsdl = CachingTest.class.getResource("DoubleItCache.wsdl");
Service service = Service.create(wsdl, SERVICE_QNAME);
QName portQName = new QName(NAMESPACE, "DoubleItCachePerProxySymmetricPort");
// First invocation
DoubleItPortType port =
service.getPort(portQName, DoubleItPortType.class);
updateAddressPort(port, PORT);
((BindingProvider)port).getRequestContext().put(
SecurityConstants.CACHE_IDENTIFIER, "proxy1"
);
((BindingProvider)port).getRequestContext().put(
SecurityConstants.CACHE_CONFIG_FILE, "client/per-proxy-cache.xml"
);
port.doubleIt(25);
Client client = ClientProxy.getClient(port);
TokenStore tokenStore =
(TokenStore)client.getEndpoint().getEndpointInfo().getProperty(
SecurityConstants.TOKEN_STORE_CACHE_INSTANCE
);
assertNotNull(tokenStore);
// We expect 1 token
assertEquals(tokenStore.getTokenIdentifiers().size(), 1);
// Second invocation
port = service.getPort(portQName, DoubleItPortType.class);
updateAddressPort(port, PORT);
((BindingProvider)port).getRequestContext().put(
SecurityConstants.CACHE_IDENTIFIER, "proxy2"
);
((BindingProvider)port).getRequestContext().put(
SecurityConstants.CACHE_CONFIG_FILE, "client/per-proxy-cache.xml"
);
port.doubleIt(35);
client = ClientProxy.getClient(port);
tokenStore =
(TokenStore)client.getEndpoint().getEndpointInfo().getProperty(
SecurityConstants.TOKEN_STORE_CACHE_INSTANCE
);
assertNotNull(tokenStore);
// We expect 1 token
assertEquals(tokenStore.getTokenIdentifiers().size(), 1);
((java.io.Closeable)port).close();
bus.shutdown(true);
}