Search in sources :

Example 1 with CertificateValidator

use of org.eclipse.milo.opcua.stack.core.application.CertificateValidator in project wildfly-camel by wildfly-extras.

the class MiloIntegrationTest method testClientWrite.

@Test
public void testClientWrite() throws Exception {
    CamelContext camelctx = new DefaultCamelContext();
    camelctx.addRoutes(new RouteBuilder() {

        public void configure() throws Exception {
            from(MILO_SERVER_ITEM_1).to(MOCK_TEST_1);
            from(MILO_SERVER_ITEM_2).to(MOCK_TEST_2);
            from(DIRECT_START_1).to(resolve(MILO_CLIENT_ITEM_C1_1));
            from(DIRECT_START_2).to(resolve(MILO_CLIENT_ITEM_C1_2));
            from(DIRECT_START_3).to(resolve(MILO_CLIENT_ITEM_C2_1));
            from(DIRECT_START_4).to(resolve(MILO_CLIENT_ITEM_C2_2));
        }
    });
    OpcUaServerConfig serverConfig = OpcUaServerConfig.builder().setEndpointAddresses(Arrays.asList(new String[] { "localhost" })).setCertificateValidator(new CertificateValidator() {

        @Override
        public void validate(X509Certificate certificate) throws UaException {
        }

        @Override
        public void verifyTrustChain(List<X509Certificate> certificateChain) throws UaException {
        }
    }).setCertificateManager(new DefaultCertificateManager()).setUserTokenPolicies(singletonList(USER_TOKEN_POLICY_ANONYMOUS)).setIdentityValidator(AnonymousIdentityValidator.INSTANCE).build();
    MiloServerComponent server = new MiloServerComponent(serverConfig);
    server.setBindAddresses("localhost");
    server.setBindPort(serverPort);
    server.setEnableAnonymousAuthentication(true);
    camelctx.addComponent("milo-server", server);
    camelctx.start();
    try {
        MockEndpoint test1Endpoint = camelctx.getEndpoint(MOCK_TEST_1, MockEndpoint.class);
        MockEndpoint test2Endpoint = camelctx.getEndpoint(MOCK_TEST_2, MockEndpoint.class);
        // item 1
        test1Endpoint.setExpectedCount(2);
        testBody(test1Endpoint.message(0), assertGoodValue("Foo1"));
        testBody(test1Endpoint.message(1), assertGoodValue("Foo3"));
        // item 1
        test2Endpoint.setExpectedCount(2);
        testBody(test2Endpoint.message(0), assertGoodValue("Foo2"));
        testBody(test2Endpoint.message(1), assertGoodValue("Foo4"));
        ProducerTemplate producer1 = camelctx.createProducerTemplate();
        producer1.setDefaultEndpointUri(DIRECT_START_1);
        ProducerTemplate producer2 = camelctx.createProducerTemplate();
        producer2.setDefaultEndpointUri(DIRECT_START_2);
        ProducerTemplate producer3 = camelctx.createProducerTemplate();
        producer3.setDefaultEndpointUri(DIRECT_START_3);
        ProducerTemplate producer4 = camelctx.createProducerTemplate();
        producer4.setDefaultEndpointUri(DIRECT_START_4);
        // send
        sendValue(producer1, new Variant("Foo1"));
        sendValue(producer2, new Variant("Foo2"));
        sendValue(producer3, new Variant("Foo3"));
        sendValue(producer4, new Variant("Foo4"));
        MockEndpoint.assertIsSatisfied(camelctx);
    } finally {
        camelctx.stop();
    }
}
Also used : DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) CamelContext(org.apache.camel.CamelContext) ProducerTemplate(org.apache.camel.ProducerTemplate) RouteBuilder(org.apache.camel.builder.RouteBuilder) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) UaException(org.eclipse.milo.opcua.stack.core.UaException) OpcUaServerConfig(org.eclipse.milo.opcua.sdk.server.api.config.OpcUaServerConfig) CertificateValidator(org.eclipse.milo.opcua.stack.core.application.CertificateValidator) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) UaException(org.eclipse.milo.opcua.stack.core.UaException) X509Certificate(java.security.cert.X509Certificate) Variant(org.eclipse.milo.opcua.stack.core.types.builtin.Variant) MiloServerComponent(org.apache.camel.component.milo.server.MiloServerComponent) DefaultCertificateManager(org.eclipse.milo.opcua.stack.core.application.DefaultCertificateManager) Test(org.junit.Test)

Aggregations

X509Certificate (java.security.cert.X509Certificate)1 CamelContext (org.apache.camel.CamelContext)1 ProducerTemplate (org.apache.camel.ProducerTemplate)1 RouteBuilder (org.apache.camel.builder.RouteBuilder)1 MiloServerComponent (org.apache.camel.component.milo.server.MiloServerComponent)1 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)1 DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)1 OpcUaServerConfig (org.eclipse.milo.opcua.sdk.server.api.config.OpcUaServerConfig)1 UaException (org.eclipse.milo.opcua.stack.core.UaException)1 CertificateValidator (org.eclipse.milo.opcua.stack.core.application.CertificateValidator)1 DefaultCertificateManager (org.eclipse.milo.opcua.stack.core.application.DefaultCertificateManager)1 Variant (org.eclipse.milo.opcua.stack.core.types.builtin.Variant)1 Test (org.junit.Test)1