Search in sources :

Example 16 with Protocol

use of io.fabric8.annotations.Protocol in project fabric8 by jboss-fuse.

the class Activator method stop.

/**
 * Performs cleanup:<br/>
 * * Unregister handler;<br/>
 * * Unregister managed service;<br/>
 * * Release bundle context.
 *
 * @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
 */
public void stop(final BundleContext bundleContext) {
    if (m_handlerReg != null) {
        m_handlerReg.unregister();
        m_handlerReg = null;
    }
    if (m_managedServiceReg != null) {
        m_managedServiceReg.unregister();
        m_managedServiceReg = null;
    }
    ServiceRegistration<MavenResolver> registration = m_resolverReg.getAndSet(null);
    if (registration != null) {
        registration.unregister();
    }
    MavenResolver resolver = m_resolver.getAndSet(null);
    if (resolver != null) {
        try {
            resolver.close();
        } catch (IOException e) {
        // Ignore
        }
    }
    m_bundleContext = null;
    LOG.debug("Handler for protocols " + PROTOCOL + " stopped");
}
Also used : MavenResolver(io.fabric8.maven.MavenResolver) IOException(java.io.IOException)

Example 17 with Protocol

use of io.fabric8.annotations.Protocol in project fabric8 by jboss-fuse.

the class DetectingGatewayTest method createGateway.

public DetectingGateway createGateway() {
    String loadBalancerType = LoadBalancers.STICKY_LOAD_BALANCER;
    int stickyLoadBalancerCacheSize = LoadBalancers.STICKY_LOAD_BALANCER_DEFAULT_CACHE_SIZE;
    LoadBalancer serviceLoadBalancer = LoadBalancers.createLoadBalancer(loadBalancerType, stickyLoadBalancerCacheSize);
    ArrayList<Protocol> protocols = new ArrayList<Protocol>();
    protocols.add(new StompProtocol());
    protocols.add(new MqttProtocol());
    protocols.add(new AmqpProtocol());
    protocols.add(new OpenwireProtocol());
    protocols.add(new HttpProtocol());
    protocols.add(new SslProtocol());
    DetectingGateway gateway = new DetectingGateway();
    gateway.setPort(0);
    gateway.setVertx(vertx);
    SslConfig sslConfig = new SslConfig(new File(basedir(), "src/test/resources/server.ks"), "password");
    sslConfig.setKeyPassword("password");
    gateway.setSslConfig(sslConfig);
    gateway.setServiceMap(serviceMap);
    gateway.setProtocols(protocols);
    gateway.setServiceLoadBalancer(serviceLoadBalancer);
    gateway.setDefaultVirtualHost("broker1");
    gateway.setConnectionTimeout(5000);
    gateway.init();
    gateways.add(gateway);
    return gateway;
}
Also used : SslProtocol(io.fabric8.gateway.handlers.detecting.protocol.ssl.SslProtocol) ArrayList(java.util.ArrayList) LoadBalancer(io.fabric8.gateway.loadbalancer.LoadBalancer) MqttProtocol(io.fabric8.gateway.handlers.detecting.protocol.mqtt.MqttProtocol) OpenwireProtocol(io.fabric8.gateway.handlers.detecting.protocol.openwire.OpenwireProtocol) SslConfig(io.fabric8.gateway.handlers.detecting.protocol.ssl.SslConfig) HttpProtocol(io.fabric8.gateway.handlers.detecting.protocol.http.HttpProtocol) StompProtocol(io.fabric8.gateway.handlers.detecting.protocol.stomp.StompProtocol) AmqpProtocol(io.fabric8.gateway.handlers.detecting.protocol.amqp.AmqpProtocol) MqttProtocol(io.fabric8.gateway.handlers.detecting.protocol.mqtt.MqttProtocol) SslProtocol(io.fabric8.gateway.handlers.detecting.protocol.ssl.SslProtocol) StompProtocol(io.fabric8.gateway.handlers.detecting.protocol.stomp.StompProtocol) AmqpProtocol(io.fabric8.gateway.handlers.detecting.protocol.amqp.AmqpProtocol) HttpProtocol(io.fabric8.gateway.handlers.detecting.protocol.http.HttpProtocol) OpenwireProtocol(io.fabric8.gateway.handlers.detecting.protocol.openwire.OpenwireProtocol) File(java.io.File)

Example 18 with Protocol

use of io.fabric8.annotations.Protocol in project fabric8 by jboss-fuse.

the class DetectingGatewayVirtualHostTest method createGateway.

public DetectingGateway createGateway() {
    String loadBalancerType = LoadBalancers.ROUND_ROBIN_LOAD_BALANCER;
    int stickyLoadBalancerCacheSize = LoadBalancers.STICKY_LOAD_BALANCER_DEFAULT_CACHE_SIZE;
    LoadBalancer serviceLoadBalancer = LoadBalancers.createLoadBalancer(loadBalancerType, stickyLoadBalancerCacheSize);
    ArrayList<Protocol> protocols = new ArrayList<Protocol>();
    protocols.add(new StompProtocol());
    protocols.add(new MqttProtocol());
    protocols.add(new AmqpProtocol());
    protocols.add(new OpenwireProtocol());
    protocols.add(new HttpProtocol());
    protocols.add(new SslProtocol());
    DetectingGateway gateway = new DetectingGateway();
    gateway.setPort(0);
    gateway.setVertx(vertx);
    SslConfig sslConfig = new SslConfig(new File(basedir(), "src/test/resources/server.ks"), "password");
    sslConfig.setKeyPassword("password");
    gateway.setSslConfig(sslConfig);
    gateway.setServiceMap(serviceMap);
    gateway.setProtocols(protocols);
    gateway.setServiceLoadBalancer(serviceLoadBalancer);
    gateway.setDefaultVirtualHost("broker");
    gateway.setConnectionTimeout(500000);
    gateway.init();
    gateways.add(gateway);
    return gateway;
}
Also used : SslProtocol(io.fabric8.gateway.handlers.detecting.protocol.ssl.SslProtocol) ArrayList(java.util.ArrayList) LoadBalancer(io.fabric8.gateway.loadbalancer.LoadBalancer) MqttProtocol(io.fabric8.gateway.handlers.detecting.protocol.mqtt.MqttProtocol) OpenwireProtocol(io.fabric8.gateway.handlers.detecting.protocol.openwire.OpenwireProtocol) SslConfig(io.fabric8.gateway.handlers.detecting.protocol.ssl.SslConfig) HttpProtocol(io.fabric8.gateway.handlers.detecting.protocol.http.HttpProtocol) StompProtocol(io.fabric8.gateway.handlers.detecting.protocol.stomp.StompProtocol) AmqpProtocol(io.fabric8.gateway.handlers.detecting.protocol.amqp.AmqpProtocol) MqttProtocol(io.fabric8.gateway.handlers.detecting.protocol.mqtt.MqttProtocol) SslProtocol(io.fabric8.gateway.handlers.detecting.protocol.ssl.SslProtocol) StompProtocol(io.fabric8.gateway.handlers.detecting.protocol.stomp.StompProtocol) AmqpProtocol(io.fabric8.gateway.handlers.detecting.protocol.amqp.AmqpProtocol) HttpProtocol(io.fabric8.gateway.handlers.detecting.protocol.http.HttpProtocol) OpenwireProtocol(io.fabric8.gateway.handlers.detecting.protocol.openwire.OpenwireProtocol) File(java.io.File)

Example 19 with Protocol

use of io.fabric8.annotations.Protocol in project fabric8 by jboss-fuse.

the class FabricDetectingGateway method createDetectingGateway.

protected DetectingGateway createDetectingGateway() {
    DetectingGateway gateway = new DetectingGateway();
    VertxService vertxService = getVertxService();
    LoadBalancer serviceLoadBalancer = LoadBalancers.createLoadBalancer(loadBalancerType, stickyLoadBalancerCacheSize);
    gateway.setVertx(vertxService.getVertx());
    gateway.setPort(port);
    gateway.setServiceMap(serviceMap);
    gateway.setShutdownTacker(shutdownTacker);
    gateway.setServiceLoadBalancer(serviceLoadBalancer);
    gateway.setDefaultVirtualHost(defaultVirtualHost);
    ArrayList<Protocol> protocols = new ArrayList<Protocol>();
    if (isStompEnabled()) {
        protocols.add(new StompProtocol());
    }
    if (isMqttEnabled()) {
        protocols.add(new MqttProtocol());
    }
    if (isAmqpEnabled()) {
        protocols.add(new AmqpProtocol());
    }
    if (isOpenWireEnabled()) {
        protocols.add(new OpenwireProtocol());
    }
    if (isHttpEnabled()) {
        protocols.add(new HttpProtocol());
    }
    if (isSslEnabled()) {
        SslConfig sslConfig = new SslConfig();
        if (Strings.isNotBlank(sslAlgorithm)) {
            sslConfig.setAlgorithm(sslAlgorithm);
        }
        if (Strings.isNotBlank(keyAlias)) {
            sslConfig.setKeyAlias(keyAlias);
        }
        if (Strings.isNotBlank(keyPassword)) {
            sslConfig.setKeyPassword(keyPassword);
        }
        if (Strings.isNotBlank(keyStorePassword)) {
            sslConfig.setKeyStorePassword(keyStorePassword);
        }
        if (keyStoreURL != null) {
            sslConfig.setKeyStoreURL(keyStoreURL);
        }
        if (Strings.isNotBlank(sslProtocol)) {
            sslConfig.setProtocol(sslProtocol);
        }
        if (Strings.isNotBlank(sslStoreType)) {
            sslConfig.setStoreType(sslStoreType);
        }
        if (Strings.isNotBlank(trustStorePassword)) {
            sslConfig.setTrustStorePassword(trustStorePassword);
        }
        if (trustStoreURL != null) {
            sslConfig.setTrustStoreURL(trustStoreURL);
        }
        if (Strings.isNotBlank(enabledCipherSuites)) {
            sslConfig.setEnabledCipherSuites(enabledCipherSuites);
        }
        if (Strings.isNotBlank(disabledCypherSuites)) {
            sslConfig.setDisabledCypherSuites(disabledCypherSuites);
        }
        gateway.setSslConfig(sslConfig);
        // validating configuration
        try {
            SSLContext sslContext = SSLContext.getInstance(sslConfig.getProtocol());
            sslContext.init(sslConfig.getKeyManagers(), sslConfig.getTrustManagers(), null);
        } catch (Exception e) {
            throw new ComponentException(e);
        }
        protocols.add(new SslProtocol());
    }
    if (protocols.isEmpty()) {
        return null;
    }
    gateway.setProtocols(protocols);
    return gateway;
}
Also used : DetectingGateway(io.fabric8.gateway.handlers.detecting.DetectingGateway) SslProtocol(io.fabric8.gateway.handlers.detecting.protocol.ssl.SslProtocol) VertxService(io.fabric8.gateway.fabric.support.vertx.VertxService) ArrayList(java.util.ArrayList) LoadBalancer(io.fabric8.gateway.loadbalancer.LoadBalancer) SSLContext(javax.net.ssl.SSLContext) MqttProtocol(io.fabric8.gateway.handlers.detecting.protocol.mqtt.MqttProtocol) OpenwireProtocol(io.fabric8.gateway.handlers.detecting.protocol.openwire.OpenwireProtocol) ComponentException(org.osgi.service.component.ComponentException) ShutdownException(io.fabric8.common.util.ShutdownTracker.ShutdownException) SslConfig(io.fabric8.gateway.handlers.detecting.protocol.ssl.SslConfig) HttpProtocol(io.fabric8.gateway.handlers.detecting.protocol.http.HttpProtocol) StompProtocol(io.fabric8.gateway.handlers.detecting.protocol.stomp.StompProtocol) AmqpProtocol(io.fabric8.gateway.handlers.detecting.protocol.amqp.AmqpProtocol) ComponentException(org.osgi.service.component.ComponentException) MqttProtocol(io.fabric8.gateway.handlers.detecting.protocol.mqtt.MqttProtocol) SslProtocol(io.fabric8.gateway.handlers.detecting.protocol.ssl.SslProtocol) StompProtocol(io.fabric8.gateway.handlers.detecting.protocol.stomp.StompProtocol) AmqpProtocol(io.fabric8.gateway.handlers.detecting.protocol.amqp.AmqpProtocol) HttpProtocol(io.fabric8.gateway.handlers.detecting.protocol.http.HttpProtocol) OpenwireProtocol(io.fabric8.gateway.handlers.detecting.protocol.openwire.OpenwireProtocol) Protocol(io.fabric8.gateway.handlers.detecting.Protocol)

Example 20 with Protocol

use of io.fabric8.annotations.Protocol in project fabric8 by jboss-fuse.

the class StompProtocol method snoopConnectionParameters.

@Override
public void snoopConnectionParameters(final SocketWrapper socket, Buffer received, final Handler<ConnectionParameters> handler) {
    StompProtocolDecoder h = new StompProtocolDecoder(this);
    h.errorHandler(new Handler<String>() {

        @Override
        public void handle(String error) {
            LOG.info("STOMP protocol decoding error: " + error);
            socket.close();
        }
    });
    h.codecHandler(new Handler<StompFrame>() {

        @Override
        public void handle(StompFrame event) {
            if (event.action().equals(CONNECT) || event.action().equals(STOMP)) {
                ConnectionParameters parameters = new ConnectionParameters();
                parameters.protocolVirtualHost = event.getHeaderAsString(HOST);
                parameters.protocolUser = event.getHeaderAsString(USERID);
                parameters.protocolClientId = event.getHeaderAsString(CLIENT_ID);
                handler.handle(parameters);
            } else {
                LOG.info("Expected a CONNECT or STOMP frame");
                socket.close();
            }
        }
    });
    socket.readStream().dataHandler(h);
    h.handle(received);
}
Also used : ConnectionParameters(io.fabric8.gateway.handlers.loadbalancer.ConnectionParameters)

Aggregations

ArrayList (java.util.ArrayList)9 Protocol (io.fabric8.annotations.Protocol)5 ConnectionParameters (io.fabric8.gateway.handlers.loadbalancer.ConnectionParameters)5 PortName (io.fabric8.annotations.PortName)4 ServiceName (io.fabric8.annotations.ServiceName)4 AmqpProtocol (io.fabric8.gateway.handlers.detecting.protocol.amqp.AmqpProtocol)4 HttpProtocol (io.fabric8.gateway.handlers.detecting.protocol.http.HttpProtocol)4 MqttProtocol (io.fabric8.gateway.handlers.detecting.protocol.mqtt.MqttProtocol)4 OpenwireProtocol (io.fabric8.gateway.handlers.detecting.protocol.openwire.OpenwireProtocol)4 SslConfig (io.fabric8.gateway.handlers.detecting.protocol.ssl.SslConfig)4 SslProtocol (io.fabric8.gateway.handlers.detecting.protocol.ssl.SslProtocol)4 StompProtocol (io.fabric8.gateway.handlers.detecting.protocol.stomp.StompProtocol)4 LoadBalancer (io.fabric8.gateway.loadbalancer.LoadBalancer)4 ServicePort (io.fabric8.kubernetes.api.model.ServicePort)4 File (java.io.File)4 IOException (java.io.IOException)4 URI (java.net.URI)4 List (java.util.List)4 External (io.fabric8.annotations.External)3 URISyntaxException (java.net.URISyntaxException)3