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());
}
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.");
}
});
}
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.");
}
});
}
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.");
}
});
}
Aggregations