use of com.predic8.membrane.core.rules.ServiceProxy in project service-proxy by membrane.
the class RuleManagerTest method setUp.
@Before
public void setUp() throws Exception {
manager = new RuleManager();
MockRouter router = new MockRouter();
manager.setRouter(router);
proxy3013 = new ProxyRule(new ProxyRuleKey(3013));
manager.addProxyAndOpenPortIfNew(proxy3013);
forwardBlz = new ServiceProxy(new ServiceProxyKey("localhost", "*", ".*", 3014), "thomas-bayer.com", 80);
forwardBlz.init(router);
forwardBlzPOST = new ServiceProxy(new ServiceProxyKey("localhost", "POST", ".*", 3015), "thomas-bayer.com", 80);
forwardBlzPOST.init(router);
manager.addProxyAndOpenPortIfNew(forwardBlz);
manager.addProxyAndOpenPortIfNew(forwardBlzPOST);
}
use of com.predic8.membrane.core.rules.ServiceProxy 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.membrane.core.rules.ServiceProxy in project service-proxy by membrane.
the class GroovyInterceptor method logGroovyException.
private void logGroovyException(Flow flow, Exception e) {
try {
ServiceProxy sp = getRule();
log.error("Exception in Groovy script in service proxy '" + sp.getName() + "' on port " + sp.getPort() + " with path " + (sp.getPath() != null ? sp.getPath().getValue() : "*"));
if (flow != null)
log.error("Flow: " + flow.name());
else
log.error("There is possibly a syntax error in the groovy script (compilation error)");
} catch (NoSuchElementException e2) {
// ignore - logging should not break anything
} finally {
e.printStackTrace();
}
}
use of com.predic8.membrane.core.rules.ServiceProxy in project service-proxy by membrane.
the class QuickstartRESTTest method doit.
@Test
public void doit() throws IOException, InterruptedException {
File baseDir = getExampleDir("quickstart-rest");
Process2 sl = new Process2.Builder().in(baseDir).script("service-proxy").waitForMembrane().start();
try {
String result = getAndAssert200("http://localhost:2000/restnames/name.groovy?name=Pia");
assertContains("Italy", result);
AssertUtils.closeConnections();
new ProxiesXmlUtil(new File(baseDir, "proxies.xml")).updateWith("<spring:beans xmlns=\"http://membrane-soa.org/proxies/1/\"\r\n" + " xmlns:spring=\"http://www.springframework.org/schema/beans\"\r\n" + " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\r\n" + " xsi:schemaLocation=\"http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd\r\n" + " http://membrane-soa.org/proxies/1/ http://membrane-soa.org/schemas/proxies-1.xsd\">\r\n" + "\r\n" + " <router>\r\n" + "\r\n" + " <serviceProxy name=\"names\" port=\"2000\">\r\n" + " <path isRegExp=\"true\">/(rest)?names.*</path>\r\n" + " <rewriter>\r\n" + " <map from=\"/names/(.*)\" to=\"/restnames/name\\.groovy\\?name=$1\" />\r\n" + " </rewriter>\r\n" + " <statisticsCSV file=\"log.csv\" />\r\n" + " <response>\r\n" + " <regExReplacer regex=\"\\s*,\\s*<\" replace=\"<\" />\r\n" + " <transform xslt=\"restnames.xsl\" />\r\n" + " </response>\r\n" + " <target host=\"thomas-bayer.com\" port=\"80\" />\r\n" + " </serviceProxy>\r\n" + " \r\n" + " <serviceProxy name=\"Console\" port=\"9000\">\r\n" + " <basicAuthentication>\r\n" + " <user name=\"alice\" password=\"membrane\" />\r\n" + " </basicAuthentication> \r\n" + " <adminConsole />\r\n" + " </serviceProxy> \r\n" + " </router>\r\n" + "</spring:beans>", sl);
result = getAndAssert200("http://localhost:2000/names/Pia");
assertContains("Italy, Spain", result);
assertContainsNot(",<", result);
String csvLog = FileUtils.readFileToString(new File(baseDir, "log.csv"));
assertContains("Pia", csvLog);
AssertUtils.setupHTTPAuthentication("localhost", 9000, "alice", "membrane");
result = getAndAssert200("http://localhost:9000/admin/");
assertContains("ServiceProxies", result);
} finally {
sl.killScript();
}
}
Aggregations