Search in sources :

Example 36 with ServiceProxyKey

use of com.predic8.membrane.core.rules.ServiceProxyKey in project service-proxy by membrane.

the class MethodTest method setUp.

@Before
public void setUp() throws Exception {
    Rule rule = new ServiceProxy(new ServiceProxyKey("localhost", "*", ".*", 4000), "oio.de", 80);
    router = new HttpRouter();
    router.getRuleManager().addProxyAndOpenPortIfNew(rule);
    router.init();
}
Also used : ServiceProxyKey(com.predic8.membrane.core.rules.ServiceProxyKey) ServiceProxy(com.predic8.membrane.core.rules.ServiceProxy) Rule(com.predic8.membrane.core.rules.Rule) HttpRouter(com.predic8.membrane.core.HttpRouter) Before(org.junit.Before)

Example 37 with ServiceProxyKey

use of com.predic8.membrane.core.rules.ServiceProxyKey in project service-proxy by membrane.

the class AbortExchangeTest method setup.

@Before
public void setup() throws Exception {
    router = new HttpRouter();
    LimitedMemoryExchangeStore es = new LimitedMemoryExchangeStore();
    router.setExchangeStore(es);
    router.getTransport().getInterceptors().add(2, new ExchangeStoreInterceptor(es));
    ServiceProxy sp2 = new ServiceProxy(new ServiceProxyKey("*", "*", ".*", 3031), "", -1);
    sp2.getInterceptors().add(new AbstractInterceptor() {

        @Override
        public Outcome handleRequest(Exchange exc) throws Exception {
            exc.getRequest().readBody();
            exc.setResponse(Response.ok("").body(new InputStream() {

                int l = 0;

                @Override
                public int read() throws IOException {
                    if (l >= 2000000)
                        return -1;
                    return 0;
                }
            }, true).build());
            return Outcome.RETURN;
        }
    });
    router.getRuleManager().addProxyAndOpenPortIfNew(sp2);
    router.init();
}
Also used : AbstractExchange(com.predic8.membrane.core.exchange.AbstractExchange) Exchange(com.predic8.membrane.core.exchange.Exchange) ServiceProxyKey(com.predic8.membrane.core.rules.ServiceProxyKey) ServiceProxy(com.predic8.membrane.core.rules.ServiceProxy) Outcome(com.predic8.membrane.core.interceptor.Outcome) InputStream(java.io.InputStream) AbstractInterceptor(com.predic8.membrane.core.interceptor.AbstractInterceptor) ExchangeStoreInterceptor(com.predic8.membrane.core.interceptor.ExchangeStoreInterceptor) HttpRouter(com.predic8.membrane.core.HttpRouter) IOException(java.io.IOException) Before(org.junit.Before)

Example 38 with ServiceProxyKey

use of com.predic8.membrane.core.rules.ServiceProxyKey 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);
}
Also used : ServiceProxyKey(com.predic8.membrane.core.rules.ServiceProxyKey) ServiceProxy(com.predic8.membrane.core.rules.ServiceProxy) ProxyRule(com.predic8.membrane.core.rules.ProxyRule) ProxyRuleKey(com.predic8.membrane.core.rules.ProxyRuleKey) Before(org.junit.Before)

Example 39 with ServiceProxyKey

use of com.predic8.membrane.core.rules.ServiceProxyKey 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)

Example 40 with ServiceProxyKey

use of com.predic8.membrane.core.rules.ServiceProxyKey in project service-proxy by membrane.

the class SOAPProxy method parseWSDL.

/**
 * @return error or null for success
 */
private void parseWSDL() throws Exception {
    WSDLParserContext ctx = new WSDLParserContext();
    ctx.setInput(ResolverMap.combine(router.getBaseLocation(), wsdl));
    try {
        WSDLParser wsdlParser = new WSDLParser();
        wsdlParser.setResourceResolver(resolverMap.toExternalResolver().toExternalResolver());
        Definitions definitions = wsdlParser.parse(ctx);
        List<Service> services = definitions.getServices();
        if (services.size() != 1)
            throw new IllegalArgumentException("There are " + services.size() + " services defined in the WSDL, but exactly 1 is required for soapProxy.");
        Service service = services.get(0);
        if (StringUtils.isEmpty(name))
            name = StringUtils.isEmpty(service.getName()) ? definitions.getName() : service.getName();
        List<Port> ports = service.getPorts();
        Port port = selectPort(ports, portName);
        String location = port.getAddress().getLocation();
        if (location == null)
            throw new IllegalArgumentException("In the WSDL, there is no @location defined on the port.");
        try {
            URL url = new URL(location);
            target.setHost(url.getHost());
            if (url.getPort() != -1)
                target.setPort(url.getPort());
            else
                target.setPort(url.getDefaultPort());
            if (key.getPath() == null) {
                key.setUsePathPattern(true);
                key.setPathRegExp(false);
                key.setPath(url.getPath());
            } else {
                String query = "";
                if (url.getQuery() != null) {
                    query = "?" + url.getQuery();
                }
                targetPath = url.getPath() + query;
            }
            if (location.startsWith("https")) {
                SSLParser sslOutboundParser = new SSLParser();
                target.setSslParser(sslOutboundParser);
            }
            ((ServiceProxyKey) key).setMethod("*");
        } catch (MalformedURLException e) {
            throw new IllegalArgumentException("WSDL endpoint location '" + location + "' is not an URL.", e);
        }
        return;
    } catch (Exception e) {
        Throwable f = e;
        while (f.getCause() != null && !(f instanceof ResourceRetrievalException)) f = f.getCause();
        if (f instanceof ResourceRetrievalException) {
            ResourceRetrievalException rre = (ResourceRetrievalException) f;
            if (rre.getStatus() >= 400)
                throw rre;
            Throwable cause = rre.getCause();
            if (cause != null) {
                if (cause instanceof UnknownHostException)
                    throw (UnknownHostException) cause;
                else if (cause instanceof ConnectException)
                    throw (ConnectException) cause;
            }
        }
        throw new IllegalArgumentException("Could not download the WSDL '" + wsdl + "'.", e);
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) UnknownHostException(java.net.UnknownHostException) Definitions(com.predic8.wsdl.Definitions) Port(com.predic8.wsdl.Port) Service(com.predic8.wsdl.Service) URL(java.net.URL) ResourceRetrievalException(com.predic8.membrane.core.resolver.ResourceRetrievalException) ConnectException(java.net.ConnectException) MalformedURLException(java.net.MalformedURLException) UnknownHostException(java.net.UnknownHostException) ResourceRetrievalException(com.predic8.membrane.core.resolver.ResourceRetrievalException) SSLParser(com.predic8.membrane.core.config.security.SSLParser) WSDLParser(com.predic8.wsdl.WSDLParser) WSDLParserContext(com.predic8.wsdl.WSDLParserContext) ConnectException(java.net.ConnectException)

Aggregations

ServiceProxyKey (com.predic8.membrane.core.rules.ServiceProxyKey)35 ServiceProxy (com.predic8.membrane.core.rules.ServiceProxy)34 HttpRouter (com.predic8.membrane.core.HttpRouter)24 Before (org.junit.Before)18 Rule (com.predic8.membrane.core.rules.Rule)14 Exchange (com.predic8.membrane.core.exchange.Exchange)12 AbstractInterceptor (com.predic8.membrane.core.interceptor.AbstractInterceptor)11 Outcome (com.predic8.membrane.core.interceptor.Outcome)11 IOException (java.io.IOException)8 LoadBalancingInterceptor (com.predic8.membrane.core.interceptor.balancer.LoadBalancingInterceptor)3 Mapping (com.predic8.membrane.core.interceptor.rewrite.RewriteInterceptor.Mapping)3 ProxyRule (com.predic8.membrane.core.rules.ProxyRule)3 SSLParser (com.predic8.membrane.core.config.security.SSLParser)2 MockInterceptor (com.predic8.membrane.core.interceptor.MockInterceptor)2 WebServerInterceptor (com.predic8.membrane.core.interceptor.server.WebServerInterceptor)2 ProxyRuleKey (com.predic8.membrane.core.rules.ProxyRuleKey)2 DummyWebServiceInterceptor (com.predic8.membrane.core.services.DummyWebServiceInterceptor)2 HttpClientConfiguration (com.predic8.membrane.core.transport.http.client.HttpClientConfiguration)2 ProxyConfiguration (com.predic8.membrane.core.transport.http.client.ProxyConfiguration)2 MalformedURLException (java.net.MalformedURLException)2