Search in sources :

Example 1 with ConnectorException

use of org.eclipse.californium.elements.exception.ConnectorException in project hono by eclipse.

the class TelemetryCoapIT method testUploadFailsForLargePayload.

/**
 * Verifies that the upload of a telemetry message containing a payload that
 * exceeds the CoAP adapter's configured max payload size fails with a 4.13
 * response code.
 *
 * @param ctx The test context.
 * @throws IOException if the CoAP request cannot be sent to the adapter.
 * @throws ConnectorException  if the CoAP request cannot be sent to the adapter.
 */
@Test
@Timeout(value = 10, timeUnit = TimeUnit.SECONDS)
public void testUploadFailsForLargePayload(final VertxTestContext ctx) throws ConnectorException, IOException {
    final Tenant tenant = new Tenant();
    helper.registry.addPskDeviceForTenant(tenantId, tenant, deviceId, SECRET).compose(ok -> {
        final CoapClient client = getCoapsClient(deviceId, tenantId, SECRET);
        final Request request = createCoapsRequest(Code.POST, Type.CON, getPostResource(), IntegrationTestSupport.getPayload(4096));
        final Promise<OptionSet> result = Promise.promise();
        client.advanced(getHandler(result, ResponseCode.REQUEST_ENTITY_TOO_LARGE), request);
        return result.future();
    }).onComplete(ctx.succeedingThenComplete());
}
Also used : X509Certificate(java.security.cert.X509Certificate) ResponseCode(org.eclipse.californium.core.coap.CoAP.ResponseCode) VertxTestContext(io.vertx.junit5.VertxTestContext) CoapClient(org.eclipse.californium.core.CoapClient) DownstreamMessage(org.eclipse.hono.application.client.DownstreamMessage) ConnectorException(org.eclipse.californium.elements.exception.ConnectorException) KeyLoader(org.eclipse.hono.config.KeyLoader) Tenant(org.eclipse.hono.service.management.tenant.Tenant) Timeout(io.vertx.junit5.Timeout) TelemetryConstants(org.eclipse.hono.util.TelemetryConstants) IntegrationTestSupport(org.eclipse.hono.tests.IntegrationTestSupport) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) Assumptions.assumeTrue(org.junit.jupiter.api.Assumptions.assumeTrue) Tenants(org.eclipse.hono.tests.Tenants) Type(org.eclipse.californium.core.coap.CoAP.Type) MessageContext(org.eclipse.hono.application.client.MessageContext) Promise(io.vertx.core.Promise) IOException(java.io.IOException) Truth.assertThat(com.google.common.truth.Truth.assertThat) VertxExtension(io.vertx.junit5.VertxExtension) Future(io.vertx.core.Future) StandardCharsets(java.nio.charset.StandardCharsets) TimeUnit(java.util.concurrent.TimeUnit) Test(org.junit.jupiter.api.Test) Code(org.eclipse.californium.core.coap.CoAP.Code) Request(org.eclipse.californium.core.coap.Request) MessageConsumer(org.eclipse.hono.application.client.MessageConsumer) OptionSet(org.eclipse.californium.core.coap.OptionSet) Handler(io.vertx.core.Handler) QoS(org.eclipse.hono.util.QoS) Promise(io.vertx.core.Promise) Tenant(org.eclipse.hono.service.management.tenant.Tenant) Request(org.eclipse.californium.core.coap.Request) CoapClient(org.eclipse.californium.core.CoapClient) Test(org.junit.jupiter.api.Test) Timeout(io.vertx.junit5.Timeout)

Example 2 with ConnectorException

use of org.eclipse.californium.elements.exception.ConnectorException in project thingsboard by thingsboard.

the class NoSecClient method test.

public void test() {
    executor.submit(() -> {
        try {
            while (!Thread.interrupted()) {
                CoapResponse response = null;
                try {
                    response = coapClient.get();
                } catch (ConnectorException | IOException e) {
                    System.err.println("Error occurred while sending request: " + e);
                    System.exit(-1);
                }
                if (response != null) {
                    System.out.println(response.getCode() + " - " + response.getCode().name());
                    System.out.println(response.getOptions());
                    System.out.println(response.getResponseText());
                    System.out.println();
                    System.out.println("ADVANCED:");
                    EndpointContext context = response.advanced().getSourceContext();
                    Principal identity = context.getPeerIdentity();
                    if (identity != null) {
                        System.out.println(context.getPeerIdentity());
                    } else {
                        System.out.println("anonymous");
                    }
                    System.out.println(context.get(DtlsEndpointContext.KEY_CIPHER));
                    System.out.println(Utils.prettyPrint(response));
                } else {
                    System.out.println("No response received.");
                }
                Thread.sleep(5000);
            }
        } catch (Exception e) {
            System.out.println("Error occurred while sending COAP requests.");
        }
    });
}
Also used : CoapResponse(org.eclipse.californium.core.CoapResponse) EndpointContext(org.eclipse.californium.elements.EndpointContext) DtlsEndpointContext(org.eclipse.californium.elements.DtlsEndpointContext) ConnectorException(org.eclipse.californium.elements.exception.ConnectorException) IOException(java.io.IOException) Principal(java.security.Principal) ConnectorException(org.eclipse.californium.elements.exception.ConnectorException) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException)

Example 3 with ConnectorException

use of org.eclipse.californium.elements.exception.ConnectorException in project thingsboard by thingsboard.

the class SecureClientNoAuth method test.

public void test() {
    executor.submit(() -> {
        try {
            while (!Thread.interrupted()) {
                CoapResponse response = null;
                try {
                    response = coapClient.get();
                } catch (ConnectorException | IOException e) {
                    System.err.println("Error occurred while sending request: " + e);
                    System.exit(-1);
                }
                if (response != null) {
                    System.out.println(response.getCode() + " - " + response.getCode().name());
                    System.out.println(response.getOptions());
                    System.out.println(response.getResponseText());
                    System.out.println();
                    System.out.println("ADVANCED:");
                    EndpointContext context = response.advanced().getSourceContext();
                    Principal identity = context.getPeerIdentity();
                    if (identity != null) {
                        System.out.println(context.getPeerIdentity());
                    } else {
                        System.out.println("anonymous");
                    }
                    System.out.println(context.get(DtlsEndpointContext.KEY_CIPHER));
                    System.out.println(Utils.prettyPrint(response));
                } else {
                    System.out.println("No response received.");
                }
                Thread.sleep(5000);
            }
        } catch (Exception e) {
            System.out.println("Error occurred while sending COAP requests.");
        }
    });
}
Also used : CoapResponse(org.eclipse.californium.core.CoapResponse) EndpointContext(org.eclipse.californium.elements.EndpointContext) DtlsEndpointContext(org.eclipse.californium.elements.DtlsEndpointContext) ConnectorException(org.eclipse.californium.elements.exception.ConnectorException) IOException(java.io.IOException) Principal(java.security.Principal) ConnectorException(org.eclipse.californium.elements.exception.ConnectorException) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) GeneralSecurityException(java.security.GeneralSecurityException)

Example 4 with ConnectorException

use of org.eclipse.californium.elements.exception.ConnectorException in project thingsboard by thingsboard.

the class SecureClientX509 method test.

public void test() {
    executor.submit(() -> {
        try {
            while (!Thread.interrupted()) {
                CoapResponse response = null;
                try {
                    response = coapClient.get();
                } catch (ConnectorException | IOException e) {
                    System.err.println("Error occurred while sending request: " + e);
                    System.exit(-1);
                }
                if (response != null) {
                    System.out.println(response.getCode() + " - " + response.getCode().name());
                    System.out.println(response.getOptions());
                    System.out.println(response.getResponseText());
                    System.out.println();
                    System.out.println("ADVANCED:");
                    EndpointContext context = response.advanced().getSourceContext();
                    Principal identity = context.getPeerIdentity();
                    if (identity != null) {
                        System.out.println(context.getPeerIdentity());
                    } else {
                        System.out.println("anonymous");
                    }
                    System.out.println(context.get(DtlsEndpointContext.KEY_CIPHER));
                    System.out.println(Utils.prettyPrint(response));
                } else {
                    System.out.println("No response received.");
                }
                Thread.sleep(5000);
            }
        } catch (Exception e) {
            System.out.println("Error occurred while sending COAP requests.");
        }
    });
}
Also used : CoapResponse(org.eclipse.californium.core.CoapResponse) EndpointContext(org.eclipse.californium.elements.EndpointContext) DtlsEndpointContext(org.eclipse.californium.elements.DtlsEndpointContext) ConnectorException(org.eclipse.californium.elements.exception.ConnectorException) IOException(java.io.IOException) Principal(java.security.Principal) ConnectorException(org.eclipse.californium.elements.exception.ConnectorException) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) GeneralSecurityException(java.security.GeneralSecurityException)

Aggregations

IOException (java.io.IOException)4 ConnectorException (org.eclipse.californium.elements.exception.ConnectorException)4 URISyntaxException (java.net.URISyntaxException)3 Principal (java.security.Principal)3 CoapResponse (org.eclipse.californium.core.CoapResponse)3 DtlsEndpointContext (org.eclipse.californium.elements.DtlsEndpointContext)3 EndpointContext (org.eclipse.californium.elements.EndpointContext)3 GeneralSecurityException (java.security.GeneralSecurityException)2 Truth.assertThat (com.google.common.truth.Truth.assertThat)1 Future (io.vertx.core.Future)1 Handler (io.vertx.core.Handler)1 Promise (io.vertx.core.Promise)1 Timeout (io.vertx.junit5.Timeout)1 VertxExtension (io.vertx.junit5.VertxExtension)1 VertxTestContext (io.vertx.junit5.VertxTestContext)1 StandardCharsets (java.nio.charset.StandardCharsets)1 X509Certificate (java.security.cert.X509Certificate)1 TimeUnit (java.util.concurrent.TimeUnit)1 CoapClient (org.eclipse.californium.core.CoapClient)1 Code (org.eclipse.californium.core.coap.CoAP.Code)1