Search in sources :

Example 1 with UaStackClientConfig

use of org.eclipse.milo.opcua.stack.client.UaStackClientConfig in project milo by eclipse.

the class ClientServerTest method testClientTimeout.

@Test
public void testClientTimeout() throws Exception {
    EndpointDescription endpoint = endpoints[0];
    logger.info("SecurityPolicy={}, MessageSecurityMode={}", SecurityPolicy.fromUri(endpoint.getSecurityPolicyUri()), endpoint.getSecurityMode());
    UaStackClientConfig config = UaStackClientConfig.builder().setEndpoint(endpoint).setKeyPair(clientKeyPair).setCertificate(clientCertificate).build();
    UaStackClient client = UaStackClient.create(config);
    client.connect().get();
    server.addServiceHandler("/test", ReadRequest.TYPE_ID, service -> {
        // intentionally do nothing so the request can timeout
        logger.info("received {}; ignoring...", service.getRequest());
    });
    RequestHeader header = new RequestHeader(NodeId.NULL_VALUE, DateTime.now(), uint(0), uint(0), null, uint(1000), null);
    ReadRequest request = new ReadRequest(header, 0.0, TimestampsToReturn.Neither, new ReadValueId[] { new ReadValueId(NodeId.NULL_VALUE, AttributeId.Value.uid(), null, null) });
    try {
        client.sendRequest(request).get();
        fail("expected response to timeout");
    } catch (Throwable t) {
        StatusCode statusCode = UaException.extractStatusCode(t).orElse(StatusCode.BAD);
        assertEquals(statusCode.getValue(), StatusCodes.Bad_Timeout);
    }
}
Also used : ReadValueId(org.eclipse.milo.opcua.stack.core.types.structured.ReadValueId) UaStackClient(org.eclipse.milo.opcua.stack.client.UaStackClient) RequestHeader(org.eclipse.milo.opcua.stack.core.types.structured.RequestHeader) EndpointDescription(org.eclipse.milo.opcua.stack.core.types.structured.EndpointDescription) UaStackClientConfig(org.eclipse.milo.opcua.stack.client.UaStackClientConfig) StatusCode(org.eclipse.milo.opcua.stack.core.types.builtin.StatusCode) ReadRequest(org.eclipse.milo.opcua.stack.core.types.structured.ReadRequest) Test(org.testng.annotations.Test)

Example 2 with UaStackClientConfig

use of org.eclipse.milo.opcua.stack.client.UaStackClientConfig in project milo by eclipse.

the class UaStackClientConfigTest method testCopyAndModify.

@Test
public void testCopyAndModify() {
    UaStackClientConfig original = UaStackClientConfig.builder().setEndpoint(endpoint).setKeyPair(clientKeyPair).setCertificate(clientCertificate).setCertificateValidator(validator).setEncodingLimits(EncodingLimits.DEFAULT).setChannelLifetime(uint(1234)).setExecutor(Stack.sharedExecutor()).setEventLoop(Stack.sharedEventLoop()).setWheelTimer(Stack.sharedWheelTimer()).build();
    UaStackClientConfig copy = UaStackClientConfig.copy(original, builder -> builder.setKeyPair(null).setCertificate(null).setCertificateChain(null).setCertificateValidator(null).setEncodingLimits(null).setChannelLifetime(uint(0)).setAcknowledgeTimeout(uint(12345)));
    assertEquals(copy.getKeyPair(), Optional.empty());
    assertEquals(copy.getCertificate(), Optional.empty());
    assertEquals(copy.getCertificateChain(), Optional.empty());
    assertEquals(copy.getCertificateValidator(), null);
    assertEquals(copy.getEncodingLimits(), null);
    assertEquals(copy.getChannelLifetime(), uint(0));
    assertEquals(copy.getAcknowledgeTimeout(), uint(12345));
}
Also used : UaStackClientConfig(org.eclipse.milo.opcua.stack.client.UaStackClientConfig) Test(org.testng.annotations.Test)

Example 3 with UaStackClientConfig

use of org.eclipse.milo.opcua.stack.client.UaStackClientConfig 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)

Example 4 with UaStackClientConfig

use of org.eclipse.milo.opcua.stack.client.UaStackClientConfig in project milo by eclipse.

the class UaStackClientConfigTest method testCopy.

@Test
public void testCopy() {
    UaStackClientConfig original = UaStackClientConfig.builder().setEndpoint(endpoint).setKeyPair(clientKeyPair).setCertificate(clientCertificate).setCertificateChain(new X509Certificate[] { clientCertificate }).setCertificateValidator(validator).setEncodingLimits(EncodingLimits.DEFAULT).setChannelLifetime(uint(1234)).setExecutor(Stack.sharedExecutor()).setEventLoop(Stack.sharedEventLoop()).setWheelTimer(Stack.sharedWheelTimer()).setAcknowledgeTimeout(uint(12345)).build();
    UaStackClientConfig copy = UaStackClientConfig.copy(original).build();
    assertEquals(copy.getKeyPair(), original.getKeyPair());
    assertEquals(copy.getCertificate(), original.getCertificate());
    assertEquals(copy.getCertificateChain(), original.getCertificateChain());
    assertEquals(copy.getCertificateValidator(), original.getCertificateValidator());
    assertEquals(copy.getEncodingLimits(), original.getEncodingLimits());
    assertEquals(copy.getChannelLifetime(), original.getChannelLifetime());
    assertEquals(copy.getExecutor(), original.getExecutor());
    assertEquals(copy.getEventLoop(), original.getEventLoop());
    assertEquals(copy.getWheelTimer(), original.getWheelTimer());
    assertEquals(copy.getAcknowledgeTimeout(), original.getAcknowledgeTimeout());
}
Also used : UaStackClientConfig(org.eclipse.milo.opcua.stack.client.UaStackClientConfig) Test(org.testng.annotations.Test)

Aggregations

UaStackClientConfig (org.eclipse.milo.opcua.stack.client.UaStackClientConfig)4 Test (org.testng.annotations.Test)3 EndpointDescription (org.eclipse.milo.opcua.stack.core.types.structured.EndpointDescription)2 KeyPair (java.security.KeyPair)1 X509Certificate (java.security.cert.X509Certificate)1 LinkedHashSet (java.util.LinkedHashSet)1 UaStackClient (org.eclipse.milo.opcua.stack.client.UaStackClient)1 StatusCode (org.eclipse.milo.opcua.stack.core.types.builtin.StatusCode)1 Unsigned.uint (org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.Unsigned.uint)1 ReadRequest (org.eclipse.milo.opcua.stack.core.types.structured.ReadRequest)1 ReadValueId (org.eclipse.milo.opcua.stack.core.types.structured.ReadValueId)1 RequestHeader (org.eclipse.milo.opcua.stack.core.types.structured.RequestHeader)1 SelfSignedHttpsCertificateBuilder (org.eclipse.milo.opcua.stack.core.util.SelfSignedHttpsCertificateBuilder)1 EndpointConfiguration (org.eclipse.milo.opcua.stack.server.EndpointConfiguration)1 UaStackServer (org.eclipse.milo.opcua.stack.server.UaStackServer)1 UaStackServerConfig (org.eclipse.milo.opcua.stack.server.UaStackServerConfig)1 BeforeSuite (org.testng.annotations.BeforeSuite)1