use of com.predic8.wsdl.Port in project service-proxy by membrane.
the class ElasticSearchExchangeStore method getExchanges.
@Override
public AbstractExchange[] getExchanges(RuleKey ruleKey) {
int port = ruleKey.getPort();
try {
Exchange exc = new Request.Builder().post(getElasticSearchExchangesPath() + "_search").body("{\n" + " \"query\": {\n" + " \"bool\": {\n" + " \"must\": [\n" + " {\n" + " \"wildcard\": {\n" + " \"issuer\": \"" + documentPrefix + "\"\n" + " }\n" + " },\n" + " {\n" + " \"match\": {\n" + " \"rule.port\": \"" + port + "\"\n" + " }\n" + " }\n" + " ]\n" + " }\n" + " }\n" + "}").header("Content-Type", "application/json").buildExchange();
exc = client.call(exc);
List source = getSourceElementFromElasticSearchResponse(responseToMap(exc));
AbstractExchangeSnapshot[] snapshots = mapper.readValue(mapper.writeValueAsString(source), AbstractExchangeSnapshot[].class);
return Stream.of(snapshots).map(snapshot -> snapshot.toAbstractExchange()).collect(Collectors.toList()).toArray(new AbstractExchange[0]);
} catch (Exception e) {
e.printStackTrace();
return new AbstractExchange[0];
}
}
use of com.predic8.wsdl.Port in project service-proxy by membrane.
the class IndexInterceptor method getServiceInfo.
private ServiceInfo getServiceInfo(Exchange exc, AbstractServiceProxy sp) {
if (sp.getInterceptors().size() == 1 && sp.getInterceptors().get(0) instanceof IndexInterceptor)
return null;
ServiceProxyKey k = (ServiceProxyKey) sp.getKey();
ServiceInfo ri = new ServiceInfo();
ri.method = k.getMethod();
// NOTE: when running as servlet, we have no idea what the protocol was
ri.ssl = sp.getSslInboundContext() != null;
String protocol = ri.ssl ? "https" : "http";
String host = k.isHostWildcard() ? new HostColonPort(ri.ssl, exc.getRequest().getHeader().getHost()).host : fullfillRegexp(ServiceProxyKey.createHostPattern(k.getHost()));
if (host == null || host.length() == 0)
host = exc.getHandler().getLocalAddress().getHostAddress().toString();
int port = k.getPort();
if (port == -1 || !exc.getHandler().isMatchLocalPort())
port = exc.getHandler().getLocalPort();
String path;
if (!k.isUsePathPattern()) {
path = "/";
} else if (k.isPathRegExp()) {
path = fullfillRegexp(k.getPath());
} else {
path = "/" + StringUtils.removeStart(k.getPath(), "/");
}
if (!"".equals(exc.getHandler().getContextPath(exc))) {
path = StringUtils.removeEnd(exc.getHandler().getContextPath(exc), "/") + "/" + StringUtils.removeStart(path, "/");
}
ri.name = sp.getName();
if (path != null)
ri.url = protocol + "://" + host + ":" + port + path;
ri.host = k.isHostWildcard() ? "" : StringEscapeUtils.escapeHtml(k.getHost());
ri.port = k.getPort() == -1 ? "" : "" + k.getPort();
ri.path = k.isUsePathPattern() ? "<tt>" + StringEscapeUtils.escapeHtml(k.getPath()) + "</tt>" + (k.isPathRegExp() ? " (regex)" : "") : "";
return ri;
}
use of com.predic8.wsdl.Port in project service-proxy by membrane.
the class STOMPClient method handleRequest.
@Override
public Outcome handleRequest(Exchange exc) throws Exception {
String login = exc.getRequest().getHeader().getFirstValue("login");
String passcode = exc.getRequest().getHeader().getFirstValue("passcode");
String host = exc.getRequest().getHeader().getFirstValue("host");
String acceptVersion = exc.getRequest().getHeader().getFirstValue("accept-version");
boolean isStomp1_0 = login != null && passcode != null;
boolean isStomp1_1orAbove = host != null && acceptVersion != null;
if (isStomp1_0 || isStomp1_1orAbove) {
Connection c = connectionManager.getConnection(this.host, port, connectionConfiguration.getLocalAddr(), sslOutboundProvider, connectionConfiguration.getTimeout());
exc.getRequest().writeSTOMP(c.out);
HttpClient.setupConnectionForwarding(exc, c, "STOMP", getRouter().getStatistics().getStreamPumpStats());
} else {
exc.setResponse(Response.badRequest().build());
}
return Outcome.RETURN;
}
use of com.predic8.wsdl.Port in project service-proxy by membrane.
the class LoadBalancerMultiple4Test method test.
@Test
public void test() throws IOException, InterruptedException {
File base = getExampleDir("loadbalancer-multiple-4");
AssertUtils.replaceInFile(new File(base, "proxies.xml"), "8080", "3023");
AssertUtils.replaceInFile(new File(base, "proxies.xml"), "8081", "3024");
Process2 sl = new Process2.Builder().in(base).script("service-proxy").waitForMembrane().start();
try {
assertEquals(1, LoadBalancerUtil.getRespondingNode("http://localhost:3023/service"));
assertEquals(2, LoadBalancerUtil.getRespondingNode("http://localhost:3023/service"));
assertEquals(1, LoadBalancerUtil.getRespondingNode("http://localhost:3023/service"));
assertEquals(2, LoadBalancerUtil.getRespondingNode("http://localhost:3023/service"));
assertEquals(3, LoadBalancerUtil.getRespondingNode("http://localhost:3024/service"));
assertEquals(4, LoadBalancerUtil.getRespondingNode("http://localhost:3024/service"));
assertEquals(3, LoadBalancerUtil.getRespondingNode("http://localhost:3024/service"));
assertEquals(4, LoadBalancerUtil.getRespondingNode("http://localhost:3024/service"));
String status = getAndAssert200("http://localhost:9000/admin/clusters/show?balancer=balancer1&cluster=Default");
assertNodeStatus(status, "localhost", 4000, "UP");
assertNodeStatus(status, "localhost", 4001, "UP");
getAndAssert(204, "http://localhost:9010/clustermanager/down?balancer=balancer1&host=localhost&port=4001");
Thread.sleep(1000);
status = getAndAssert200("http://localhost:9000/admin/clusters/show?balancer=balancer1&cluster=Default");
assertNodeStatus(status, "localhost", 4000, "UP");
assertNodeStatus(status, "localhost", 4001, "DOWN");
assertEquals(1, LoadBalancerUtil.getRespondingNode("http://localhost:3023/service"));
assertEquals(1, LoadBalancerUtil.getRespondingNode("http://localhost:3023/service"));
} finally {
sl.killScript();
}
}
use of com.predic8.wsdl.Port in project service-proxy by membrane.
the class JSONSchemaValidationTest method test.
@Test
public void test() throws IOException, InterruptedException {
File baseDir = getExampleDir("validation" + File.separator + "json-schema");
Process2 sl = new Process2.Builder().in(baseDir).script("service-proxy").waitForMembrane().start();
try {
for (int port : new int[] { 2000, 2001 }) {
postAndAssert(200, "http://localhost:" + port + "/", readFileToString(new File(baseDir, "good" + port + ".json")));
postAndAssert(400, "http://localhost:" + port + "/", readFileToString(new File(baseDir, "bad" + port + ".json")));
}
} finally {
sl.killScript();
}
}
Aggregations