Search in sources :

Example 1 with PortOccupiedException

use of com.predic8.membrane.core.transport.PortOccupiedException 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

AbstractServiceProxy (com.predic8.membrane.core.rules.AbstractServiceProxy)1 ProxyRule (com.predic8.membrane.core.rules.ProxyRule)1 Rule (com.predic8.membrane.core.rules.Rule)1 ServiceProxy (com.predic8.membrane.core.rules.ServiceProxy)1 ServiceProxyKey (com.predic8.membrane.core.rules.ServiceProxyKey)1 PortOccupiedException (com.predic8.membrane.core.transport.PortOccupiedException)1