Search in sources :

Example 41 with Rule

use of com.predic8.membrane.core.interceptor.HeaderFilterInterceptor.Rule in project service-proxy by membrane.

the class DynamicAdminPageInterceptor method handleProxySaveRequest.

@Mapping("/admin/proxy/save/?(\\?.*)?")
public Response handleProxySaveRequest(Map<String, String> params, String relativeRootPath) throws Exception {
    if (readOnly)
        return createReadOnlyErrorResponse();
    log.debug("adding proxy rule");
    log.debug("name: " + params.get("name"));
    log.debug("port: " + params.get("port"));
    Rule r = new ProxyRule(new ProxyRuleKey(Integer.parseInt(params.get("port")), null));
    r.setName(params.get("name"));
    router.getRuleManager().addProxyAndOpenPortIfNew(r);
    return respond(getProxyPage(params, relativeRootPath));
}
Also used : ProxyRule(com.predic8.membrane.core.rules.ProxyRule) ProxyRuleKey(com.predic8.membrane.core.rules.ProxyRuleKey) ProxyRule(com.predic8.membrane.core.rules.ProxyRule) Rule(com.predic8.membrane.core.rules.Rule)

Example 42 with Rule

use of com.predic8.membrane.core.interceptor.HeaderFilterInterceptor.Rule 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));
}
Also used : ProxyRule(com.predic8.membrane.core.rules.ProxyRule) Rule(com.predic8.membrane.core.rules.Rule)

Example 43 with Rule

use of com.predic8.membrane.core.interceptor.HeaderFilterInterceptor.Rule in project service-proxy by membrane.

the class DynamicAdminPageInterceptor method handlePruleShowRequest.

@Mapping("/admin/proxy/show/?(\\?.*)?")
public Response handlePruleShowRequest(final Map<String, String> params, String relativeRootPath) throws Exception {
    StringWriter writer = new StringWriter();
    final ProxyRule rule = (ProxyRule) RuleUtil.findRuleByIdentifier(router, params.get("name"));
    return respond(new AdminPageBuilder(writer, router, relativeRootPath, params, readOnly) {

        @Override
        protected int getSelectedTab() {
            return TAB_ID_PROXIES;
        }

        @Override
        protected String getTitle() {
            return super.getTitle() + " " + rule.toString() + " Proxy";
        }

        @Override
        protected void createTabContent() throws Exception {
            h1().text(rule.toString() + " Proxy").end();
            if (rule.getKey().getPort() != -1) {
                table();
                createTr("Listen Port", "" + rule.getKey().getPort());
                end();
            }
            h2().text("Status Codes").end();
            createStatusCodesTable(rule.getStatisticsByStatusCodes());
            h2().text("Interceptors").end();
            createInterceptorTable(rule.getInterceptors());
        }
    }.createPage());
}
Also used : StringWriter(java.io.StringWriter) ProxyRule(com.predic8.membrane.core.rules.ProxyRule)

Example 44 with Rule

use of com.predic8.membrane.core.interceptor.HeaderFilterInterceptor.Rule 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));
}
Also used : ServiceProxyKey(com.predic8.membrane.core.rules.ServiceProxyKey) ServiceProxy(com.predic8.membrane.core.rules.ServiceProxy) AbstractServiceProxy(com.predic8.membrane.core.rules.AbstractServiceProxy) PortOccupiedException(com.predic8.membrane.core.transport.PortOccupiedException) ProxyRule(com.predic8.membrane.core.rules.ProxyRule) Rule(com.predic8.membrane.core.rules.Rule)

Aggregations

Rule (com.predic8.membrane.core.rules.Rule)29 ServiceProxy (com.predic8.membrane.core.rules.ServiceProxy)15 ServiceProxyKey (com.predic8.membrane.core.rules.ServiceProxyKey)13 HttpRouter (com.predic8.membrane.core.HttpRouter)11 Before (org.junit.Before)8 IRuleChangeListener (com.predic8.membrane.core.model.IRuleChangeListener)6 ProxyRule (com.predic8.membrane.core.rules.ProxyRule)6 AbstractServiceProxy (com.predic8.membrane.core.rules.AbstractServiceProxy)5 Exchange (com.predic8.membrane.core.exchange.Exchange)3 IOException (java.io.IOException)3 Test (org.junit.Test)3 AbstractExchange (com.predic8.membrane.core.exchange.AbstractExchange)2 HeaderField (com.predic8.membrane.core.http.HeaderField)2 MockInterceptor (com.predic8.membrane.core.interceptor.MockInterceptor)2 Mapping (com.predic8.membrane.core.interceptor.rewrite.RewriteInterceptor.Mapping)2 IExchangesStoreListener (com.predic8.membrane.core.model.IExchangesStoreListener)2 NullRule (com.predic8.membrane.core.rules.NullRule)2 SOAPProxy (com.predic8.membrane.core.rules.SOAPProxy)2 StringWriter (java.io.StringWriter)2 CacheBuilder (com.google.common.cache.CacheBuilder)1