Search in sources :

Example 1 with UaStackServer

use of org.eclipse.milo.opcua.stack.server.UaStackServer in project milo by eclipse.

the class ServerChannelManager method bootstrap.

private static CompletableFuture<Channel> bootstrap(UaStackServer stackServer, InetSocketAddress bindAddress, TransportProfile transportProfile) {
    ChannelInitializer<SocketChannel> initializer;
    if (transportProfile == TransportProfile.TCP_UASC_UABINARY) {
        initializer = new OpcServerTcpChannelInitializer(stackServer);
    } else {
        initializer = new OpcServerHttpChannelInitializer(stackServer);
    }
    ServerBootstrap bootstrap = new ServerBootstrap();
    bootstrap.group(Stack.sharedEventLoop()).handler(new LoggingHandler(ServerChannelManager.class)).channel(NioServerSocketChannel.class).childOption(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT).childOption(ChannelOption.TCP_NODELAY, true).childHandler(initializer);
    CompletableFuture<Channel> channelFuture = new CompletableFuture<>();
    bootstrap.bind(bindAddress).addListener((ChannelFutureListener) future -> {
        if (future.isSuccess()) {
            Channel channel = future.channel();
            channelFuture.complete(channel);
        } else {
            channelFuture.completeExceptionally(future.cause());
        }
    });
    return channelFuture;
}
Also used : ChannelOption(io.netty.channel.ChannelOption) LoggingHandler(io.netty.handler.logging.LoggingHandler) Multiset(com.google.common.collect.Multiset) LoggerFactory(org.slf4j.LoggerFactory) CompletableFuture(java.util.concurrent.CompletableFuture) EndpointConfiguration(org.eclipse.milo.opcua.stack.server.EndpointConfiguration) Stack(org.eclipse.milo.opcua.stack.core.Stack) Unit(org.eclipse.milo.opcua.stack.core.util.Unit) Map(java.util.Map) ChannelFutureListener(io.netty.channel.ChannelFutureListener) UaStackServer(org.eclipse.milo.opcua.stack.server.UaStackServer) SocketChannel(io.netty.channel.socket.SocketChannel) TransportProfile(org.eclipse.milo.opcua.stack.core.transport.TransportProfile) Logger(org.slf4j.Logger) ChannelInitializer(io.netty.channel.ChannelInitializer) NioServerSocketChannel(io.netty.channel.socket.nio.NioServerSocketChannel) PooledByteBufAllocator(io.netty.buffer.PooledByteBufAllocator) InetSocketAddress(java.net.InetSocketAddress) Maps(com.google.common.collect.Maps) OpcServerHttpChannelInitializer(org.eclipse.milo.opcua.stack.server.transport.http.OpcServerHttpChannelInitializer) Channel(io.netty.channel.Channel) AsyncSemaphore(org.eclipse.milo.opcua.stack.core.util.AsyncSemaphore) ConcurrentHashMultiset(com.google.common.collect.ConcurrentHashMultiset) OpcServerTcpChannelInitializer(org.eclipse.milo.opcua.stack.server.transport.tcp.OpcServerTcpChannelInitializer) ServerBootstrap(io.netty.bootstrap.ServerBootstrap) SocketChannel(io.netty.channel.socket.SocketChannel) NioServerSocketChannel(io.netty.channel.socket.nio.NioServerSocketChannel) LoggingHandler(io.netty.handler.logging.LoggingHandler) CompletableFuture(java.util.concurrent.CompletableFuture) NioServerSocketChannel(io.netty.channel.socket.nio.NioServerSocketChannel) SocketChannel(io.netty.channel.socket.SocketChannel) NioServerSocketChannel(io.netty.channel.socket.nio.NioServerSocketChannel) Channel(io.netty.channel.Channel) OpcServerHttpChannelInitializer(org.eclipse.milo.opcua.stack.server.transport.http.OpcServerHttpChannelInitializer) OpcServerTcpChannelInitializer(org.eclipse.milo.opcua.stack.server.transport.tcp.OpcServerTcpChannelInitializer) ServerBootstrap(io.netty.bootstrap.ServerBootstrap)

Example 2 with UaStackServer

use of org.eclipse.milo.opcua.stack.server.UaStackServer in project milo by eclipse.

the class ClientServerTest method setUpClientServer.

@BeforeSuite
public void setUpClientServer() throws Exception {
    super.setUp();
    UaStackServerConfig config = UaStackServerConfig.builder().setCertificateManager(serverCertificateManager).setCertificateValidator(serverCertificateValidator).setEndpoints(createEndpointConfigurations(serverCertificate)).build();
    server = new UaStackServer(config);
    setReadRequestHandler(new Variant(42));
    server.startup().get();
    endpoints = DiscoveryClient.getEndpoints("opc.tcp://localhost:12685/test").get().toArray(new EndpointDescription[0]);
}
Also used : Variant(org.eclipse.milo.opcua.stack.core.types.builtin.Variant) UaStackServerConfig(org.eclipse.milo.opcua.stack.server.UaStackServerConfig) EndpointDescription(org.eclipse.milo.opcua.stack.core.types.structured.EndpointDescription) UaStackServer(org.eclipse.milo.opcua.stack.server.UaStackServer) BeforeSuite(org.testng.annotations.BeforeSuite)

Example 3 with UaStackServer

use of org.eclipse.milo.opcua.stack.server.UaStackServer in project milo by eclipse.

the class StackIntegrationTest method setUpClientServer.

@BeforeSuite
public void setUpClientServer() throws Exception {
    super.setUp();
    int tcpBindPort = getTcpBindPort();
    int httpsBindPort = getHttpsBindPort();
    KeyPair httpsKeyPair = SelfSignedCertificateGenerator.generateRsaKeyPair(2048);
    X509Certificate httpsCertificate = new SelfSignedHttpsCertificateBuilder(httpsKeyPair).setCommonName("localhost").build();
    List<String> bindAddresses = newArrayList();
    bindAddresses.add("localhost");
    List<String> hostnames = newArrayList();
    hostnames.add("localhost");
    Set<EndpointConfiguration> endpointConfigurations = new LinkedHashSet<>();
    for (String bindAddress : bindAddresses) {
        for (String hostname : hostnames) {
            EndpointConfiguration.Builder base = EndpointConfiguration.newBuilder().setBindAddress(bindAddress).setHostname(hostname).setPath("/test").setCertificate(serverCertificate).addTokenPolicies(USER_TOKEN_POLICY_ANONYMOUS);
            // TCP Transport Endpoints
            endpointConfigurations.add(base.copy().setBindPort(tcpBindPort).setSecurityPolicy(SecurityPolicy.None).setSecurityMode(MessageSecurityMode.None).setTransportProfile(TransportProfile.TCP_UASC_UABINARY).build());
            endpointConfigurations.add(base.copy().setBindPort(tcpBindPort).setSecurityPolicy(SecurityPolicy.Basic256Sha256).setSecurityMode(MessageSecurityMode.SignAndEncrypt).setTransportProfile(TransportProfile.TCP_UASC_UABINARY).build());
            // HTTPS Transport Endpoints
            endpointConfigurations.add(base.copy().setBindPort(httpsBindPort).setSecurityPolicy(SecurityPolicy.None).setSecurityMode(MessageSecurityMode.None).setTransportProfile(TransportProfile.HTTPS_UABINARY).build());
            endpointConfigurations.add(base.copy().setBindPort(httpsBindPort).setSecurityPolicy(SecurityPolicy.Basic256Sha256).setSecurityMode(MessageSecurityMode.SignAndEncrypt).setTransportProfile(TransportProfile.HTTPS_UABINARY).build());
        }
    }
    UaStackServerConfig serverConfig = configureServer(UaStackServerConfig.builder().setEndpoints(endpointConfigurations).setCertificateManager(serverCertificateManager).setCertificateValidator(serverCertificateValidator).setHttpsKeyPair(httpsKeyPair).setHttpsCertificate(httpsCertificate)).build();
    stackServer = new UaStackServer(serverConfig);
    stackServer.startup().get();
    String discoveryUrl = getDiscoveryUrl();
    EndpointDescription endpoint = selectEndpoint(DiscoveryClient.getEndpoints(discoveryUrl).thenApply(endpoints -> {
        endpoints.forEach(e -> logger.info("discovered endpoint: {}", e.getEndpointUrl()));
        return endpoints;
    }).get());
    UaStackClientConfig clientConfig = configureClient(UaStackClientConfig.builder().setEndpoint(endpoint).setKeyPair(clientKeyPair).setCertificate(clientCertificate).setRequestTimeout(uint(5000))).build();
    stackClient = UaStackClient.create(clientConfig);
    stackClient.connect().get();
}
Also used : LinkedHashSet(java.util.LinkedHashSet) KeyPair(java.security.KeyPair) UaStackServerConfig(org.eclipse.milo.opcua.stack.server.UaStackServerConfig) EndpointDescription(org.eclipse.milo.opcua.stack.core.types.structured.EndpointDescription) UaStackClientConfig(org.eclipse.milo.opcua.stack.client.UaStackClientConfig) Unsigned.uint(org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.Unsigned.uint) X509Certificate(java.security.cert.X509Certificate) SelfSignedHttpsCertificateBuilder(org.eclipse.milo.opcua.stack.core.util.SelfSignedHttpsCertificateBuilder) EndpointConfiguration(org.eclipse.milo.opcua.stack.server.EndpointConfiguration) UaStackServer(org.eclipse.milo.opcua.stack.server.UaStackServer) BeforeSuite(org.testng.annotations.BeforeSuite)

Aggregations

UaStackServer (org.eclipse.milo.opcua.stack.server.UaStackServer)3 EndpointDescription (org.eclipse.milo.opcua.stack.core.types.structured.EndpointDescription)2 EndpointConfiguration (org.eclipse.milo.opcua.stack.server.EndpointConfiguration)2 UaStackServerConfig (org.eclipse.milo.opcua.stack.server.UaStackServerConfig)2 BeforeSuite (org.testng.annotations.BeforeSuite)2 ConcurrentHashMultiset (com.google.common.collect.ConcurrentHashMultiset)1 Maps (com.google.common.collect.Maps)1 Multiset (com.google.common.collect.Multiset)1 ServerBootstrap (io.netty.bootstrap.ServerBootstrap)1 PooledByteBufAllocator (io.netty.buffer.PooledByteBufAllocator)1 Channel (io.netty.channel.Channel)1 ChannelFutureListener (io.netty.channel.ChannelFutureListener)1 ChannelInitializer (io.netty.channel.ChannelInitializer)1 ChannelOption (io.netty.channel.ChannelOption)1 SocketChannel (io.netty.channel.socket.SocketChannel)1 NioServerSocketChannel (io.netty.channel.socket.nio.NioServerSocketChannel)1 LoggingHandler (io.netty.handler.logging.LoggingHandler)1 InetSocketAddress (java.net.InetSocketAddress)1 KeyPair (java.security.KeyPair)1 X509Certificate (java.security.cert.X509Certificate)1