use of com.predic8.wsdl.Service in project service-proxy by membrane.
the class XMLValidationTest method test.
@Test
public void test() throws IOException, InterruptedException {
File baseDir = getExampleDir("validation" + File.separator + "xml");
Process2 sl = new Process2.Builder().in(baseDir).script("service-proxy").waitForMembrane().start();
try {
String url = "http://localhost:2000/";
postAndAssert(200, url, readFileToString(new File(baseDir, "year.xml")));
postAndAssert(400, url, readFileToString(new File(baseDir, "invalid-year.xml")));
} finally {
sl.killScript();
}
}
use of com.predic8.wsdl.Service in project service-proxy by membrane.
the class DynamicAdminPageInterceptor method handleServiceProxyShowRequest.
@Mapping("/admin/service-proxy/show/?(\\?.*)?")
public Response handleServiceProxyShowRequest(final Map<String, String> params, final String relativeRootPath) throws Exception {
final StringWriter writer = new StringWriter();
final AbstractServiceProxy rule = (AbstractServiceProxy) RuleUtil.findRuleByIdentifier(router, params.get("name"));
return respond(new AdminPageBuilder(writer, router, relativeRootPath, params, readOnly) {
@Override
protected int getSelectedTab() {
return TAB_ID_SERVICE_PROXIES;
}
@Override
protected String getTitle() {
return super.getTitle() + " " + rule.toString() + " ServiceProxy";
}
@Override
protected void createTabContent() throws Exception {
h1().text(rule.toString() + " ServiceProxy").end();
script().raw("$(function() {\r\n" + " $( \"#subtab\" ).tabs();\r\n" + " });").end();
div().id("subtab");
ul();
li().a().href("#tab1").text("Visualization").end(2);
li().a().href("#tab2").text("Statistics").end(2);
// li().a().href("#tab3").text("XML Configuration").end(2);
end();
div().id("tab1");
createServiceProxyVisualization(rule, relativeRootPath);
end();
div().id("tab2");
createStatusCodesTable(rule.getStatisticsByStatusCodes());
br();
createButton("View Messages", "calls", null, createQueryString("proxy", rule.toString()));
end();
end();
}
}.createPage());
}
use of com.predic8.wsdl.Service in project service-proxy by membrane.
the class ApiManagementConfiguration method parsePolicies.
private Map<String, Policy> parsePolicies(Map<String, Object> yaml) {
Map<String, Policy> result = new HashMap<String, Policy>();
Object policies = yaml.get("policies");
if (policies == null) {
log.warn("No policies in policy file");
return result;
}
List<Object> yamlPolicies = (List<Object>) policies;
for (Object yamlPolicyObj : yamlPolicies) {
if (yamlPolicyObj == null) {
continue;
}
LinkedHashMap<String, Object> yamlPolicy = (LinkedHashMap<String, Object>) yamlPolicyObj;
for (Object polObj : yamlPolicy.values()) {
if (polObj == null) {
continue;
}
LinkedHashMap<String, Object> yamlPolicyDef = (LinkedHashMap<String, Object>) polObj;
Policy policy = new Policy();
Object name = yamlPolicyDef.get("id");
if (name == null) {
log.warn("Policy object found, but no \"id\" field");
continue;
}
String policyName = (String) name;
policy.setName(policyName);
Object serviceProxiesObj = yamlPolicyDef.get("serviceProxy");
if (serviceProxiesObj == null) {
log.warn("Policy object found, but no service proxies specified ");
continue;
}
List<String> serviceProxyNames = (List<String>) serviceProxiesObj;
for (String sp : serviceProxyNames) {
policy.getServiceProxies().add(sp);
}
// Optionals like rateLimit/quota etc. follow
Object rateLimitObj = yamlPolicyDef.get("rateLimit");
if (rateLimitObj != null) {
LinkedHashMap<String, Object> rateLimitData = (LinkedHashMap<String, Object>) rateLimitObj;
RateLimit rateLimit = new RateLimit();
int requests = parseInteger(rateLimitData.get("requests"), RateLimit.REQUESTS_DEFAULT);
int interval = parseInteger(rateLimitData.get("interval"), RateLimit.INTERVAL_DEFAULT);
rateLimit.setRequests(requests);
rateLimit.setInterval(interval);
policy.setRateLimit(rateLimit);
}
Object quotaObj = yamlPolicyDef.get("quota");
if (quotaObj != null) {
LinkedHashMap<String, Object> quota = (LinkedHashMap<String, Object>) quotaObj;
Object quotaSizeObj = quota.get("size");
long quotaNumber = getQuotaNumber(quotaSizeObj);
int quotaInterval = parseInteger(quota.get("interval"), Quota.INTERVAL_DEFAULT);
Quota q = new Quota();
q.setSize(quotaNumber);
q.setInterval(quotaInterval);
policy.setQuota(q);
}
parseUnauthenticatedField(yamlPolicyDef, policy);
result.put(policyName, policy);
}
}
return result;
}
use of com.predic8.wsdl.Service in project service-proxy by membrane.
the class EtcdRegistryApiConfig method findAdminConsole.
private EtcdNodeInformation findAdminConsole() {
Object routerObj = context.getBean(Router.class);
if (routerObj == null)
throw new RuntimeException("Router not found, cannot publish admin console");
Router router = (Router) routerObj;
for (Rule r : router.getRuleManager().getRules()) {
if (!(r instanceof AbstractServiceProxy))
continue;
for (Interceptor i : r.getInterceptors()) {
if (i instanceof AdminConsoleInterceptor) {
String name = r.getName();
String host = ((ServiceProxy) r).getExternalHostname();
if (host == null)
host = getLocalHostname();
String port = Integer.toString(((AbstractServiceProxy) r).getPort());
EtcdNodeInformation node = new EtcdNodeInformation(null, null, host, port, name);
return node;
}
}
}
throw new RuntimeException("Admin console not found but is needed. Add a service proxy with an admin console.");
}
use of com.predic8.wsdl.Service in project service-proxy by membrane.
the class AdminPageBuilder method createStreamPumpsTable.
protected void createStreamPumpsTable() throws UnsupportedEncodingException {
table().attr("cellpadding", "0", "cellspacing", "0", "border", "0", "class", "display", "id", "stream-pumps-table");
thead();
tr();
createThs("Name", "Service Proxy", "Creation Time", "Active Time", "Transferred Bytes");
end();
end();
tbody();
for (StreamPump p : router.getStatistics().getStreamPumpStats().getStreamPumps()) {
tr().style("text-align: right;");
td().style("text-align:left;").text(p.getName()).end();
createTds(p.getServiceProxyName(), new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(p.getCreationTime()), // TODO: Pretty Print with library
(System.currentTimeMillis() - p.getCreationTime()) / 1000 + " seconds", "" + p.getTransferredBytes());
end();
}
end();
end();
}
Aggregations