AuthenticateStub authenticateStub = new AuthenticateStub();
ProxyServiceAdminStub proxyServiceAdminStub = new ProxyServiceAdminStub("https://" + FrameworkSettings.HOST_NAME + ":" + FrameworkSettings.HTTPS_PORT + "/services/ProxyServiceAdmin");
authenticateStub.authenticateAdminStub(proxyServiceAdminStub, sessionCookie);
ThrottleAdminServiceStub throttleAdminServiceStub = new ThrottleAdminServiceStub("https://" + FrameworkSettings.HOST_NAME + ":" + FrameworkSettings.HTTPS_PORT + "/services/ThrottleAdminService");
authenticateStub.authenticateAdminStub(throttleAdminServiceStub, sessionCookie);
proxyData = handler.getProxy(ThrottlleTest.class.getResource("/testdata/StockQuoteProxyTest.xml").getPath());
//Add proxy Service test
proxyServiceAdminStub.addProxy(proxyData);
log.info("Proxy service added");
ThrottlePolicy throttlePolicy = new ThrottlePolicy();
InternalData[] internalDatas = new InternalData[1];
InternalData data = new InternalData();
data.setMaxRequestCount(6);
data.setProhibitTimePeriod(10000);
data.setRange("other");
data.setAccessLevel(0);
data.setRangeType("IP");
data.setUnitTime(10000);
internalDatas[0] = data;
throttlePolicy.setInternalConfigs(internalDatas);
throttleAdminServiceStub.enableThrottling("StockQuoteProxyTest", throttlePolicy);
for (int i = 0; i <= 7; i++) {
StockQuoteClient stockQuoteClient = new StockQuoteClient();
if (FrameworkSettings.STRATOS.equalsIgnoreCase("false")) {
result = stockQuoteClient.stockQuoteClientforProxy("http://" + FrameworkSettings.HOST_NAME + ":" + FrameworkSettings.HTTP_PORT + "/services/StockQuoteProxyTest", null, "IBM");
}
else if (FrameworkSettings.STRATOS.equalsIgnoreCase("true")) {
System.out.println("http://" + FrameworkSettings.HOST_NAME + ":" + FrameworkSettings.HTTP_PORT + "/services/" + FrameworkSettings.TENANT_NAME + "/StockQuoteProxyTest");
result = stockQuoteClient.stockQuoteClientforProxy("http://" + FrameworkSettings.HOST_NAME + ":" + FrameworkSettings.HTTP_PORT + "/services/" + FrameworkSettings.TENANT_NAME + "/StockQuoteProxyTest", null, "IBM");
}
boolean isFound = result.getChildren().next().toString().contains("IBM");
System.out.println(result.toString());
if (!isFound) {
log.error("Required response not found");
Assert.fail("Required response not found");
}
Iterator iterator = result.getFirstElement().getChildrenWithName(new QName("http://services.samples/xsd", "name"));
while (iterator.hasNext()) {
OMElement element = (OMElement) iterator.next();
System.out.println("The response is received : " + element.getText());
Assert.assertEquals("IBM Company", element.getText());
}
throttleCounter++;
}
throttleAdminServiceStub.disableThrottling("StockQuoteProxyTest");
}
catch (Exception
e) {
log.fatal(e.toString());
}