use of com.predic8.wsdl.Service in project service-proxy by membrane.
the class XPathCBRInterceptorTest method testRouting.
@Test
public void testRouting() throws Exception {
exc = new Exchange(null);
Request res = new Request();
res.setBodyContent(getByteArrayData(getClass().getResourceAsStream("/customerFromBonn.xml")));
exc.setRequest(res);
XPathCBRInterceptor i = new XPathCBRInterceptor();
i.setCases(getRouteList("//CITY[text()='England']", "http://www.host.uk/service", "//CITY[text()='Bonn']", "http://www.host.de/service"));
i.handleRequest(exc);
Assert.assertEquals("http://www.host.de/service", exc.getDestinations().get(0));
}
use of com.predic8.wsdl.Service in project service-proxy by membrane.
the class XPathCBRInterceptorTest method testRoutingNSAware.
@Test
public void testRoutingNSAware() throws Exception {
exc = new Exchange(null);
Request res = new Request();
res.setBodyContent(getByteArrayData(getClass().getResourceAsStream("/customerFromBonnWithNS.xml")));
exc.setRequest(res);
XPathCBRInterceptor i = new XPathCBRInterceptor();
i.setCases(getRouteList("//pre:CITY[text()='England']", "http://www.host.uk/service", "//pre:CITY[text()='Bonn']", "http://www.host.de/service"));
i.setNamespaces(getNamespaceMap("pre", "http://predic8.de/customer/1"));
i.handleRequest(exc);
Assert.assertEquals("http://www.host.de/service", exc.getDestinations().get(0));
}
use of com.predic8.wsdl.Service in project service-proxy by membrane.
the class DynamicAdminPageInterceptor method handleServiceProxyStartRequest.
@Mapping("/admin/service-proxy/start/?(\\?.*)?")
public Response handleServiceProxyStartRequest(Map<String, String> params, String relativeRootPath) throws Exception {
if (readOnly)
return createReadOnlyErrorResponse();
Rule rule = RuleUtil.findRuleByIdentifier(router, params.get("name"));
Rule newRule = rule.clone();
router.getRuleManager().replaceRule(rule, newRule);
return respond(getServiceProxyPage(params, relativeRootPath));
}
use of com.predic8.wsdl.Service in project service-proxy by membrane.
the class DynamicAdminPageInterceptor method handleServiceProxySaveRequest.
@Mapping("/admin/service-proxy/save/?(\\?.*)?")
public Response handleServiceProxySaveRequest(Map<String, String> params, String relativeRootPath) throws Exception {
if (readOnly)
return createReadOnlyErrorResponse();
logAddFwdRuleParams(params);
Rule r = new ServiceProxy(new ServiceProxyKey("*", params.get("method"), ".*", getPortParam(params), null), params.get("targetHost"), getTargetPortParam(params));
r.setName(params.get("name"));
try {
router.getRuleManager().addProxyAndOpenPortIfNew(r);
} catch (PortOccupiedException e) {
return Response.internalServerError("The port could not be opened: Either it is occupied or Membrane does " + "not have enough privileges to do so.").build();
}
return respond(getServiceProxyPage(params, relativeRootPath));
}
use of com.predic8.wsdl.Service in project service-proxy by membrane.
the class AMStatisticsCollector method collectStatisticFrom.
private String collectStatisticFrom(Exchange exc, String apiKey) throws IOException {
StatisticCollector statistics = new StatisticCollector(false);
statistics.collectFrom(exc);
JsonGenerator gen = getAndResetJsonGenerator();
try {
gen.writeStartObject();
gen.writeObjectField("excId", exc.getId());
gen.writeObjectField("excTime", exc.getTime().toInstant().toString());
gen.writeObjectField("excApiKey", apiKey);
gen.writeObjectField("service", exc.getRule().getName());
gen.writeObjectField("uri", exc.getOriginalRequestUri());
gen.writeObjectField("method", exc.getRequest().getMethod());
gen.writeObjectField("excStatus", exc.getStatus().toString());
gen.writeObjectField("code", exc.getResponse().getStatusCode());
gen.writeObjectField("time", getInflightTime(exc));
gen.writeEndObject();
} catch (IOException e) {
e.printStackTrace();
}
return getStringFromJsonGenerator();
}
Aggregations