Skip to content

Commit

Permalink
Added catch to make TransportException be returned to the caller
Browse files Browse the repository at this point in the history
Signed-off-by: Alberto Codutti <alberto.codutti@eurotech.com>
  • Loading branch information
Coduz committed Aug 2, 2023
1 parent c17e9e6 commit 6816868
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@
*******************************************************************************/
package org.eclipse.kapua.service.device.call;

import org.checkerframework.checker.nullness.qual.Nullable;
import org.eclipse.kapua.service.device.call.exception.DeviceCallSendException;
import org.eclipse.kapua.service.device.call.exception.DeviceCallTimeoutException;
import org.eclipse.kapua.service.device.call.message.DeviceMessage;
import org.eclipse.kapua.service.device.call.message.app.request.DeviceRequestMessage;
import org.eclipse.kapua.service.device.call.message.app.response.DeviceResponseMessage;
import org.eclipse.kapua.transport.exception.TransportException;

import org.checkerframework.checker.nullness.qual.Nullable;
import javax.validation.constraints.NotNull;

/**
Expand All @@ -42,7 +43,7 @@ public interface DeviceCall<RQ extends DeviceRequestMessage<?, ?>, RS extends De
* @throws DeviceCallSendException if sending the request produces any error.
* @since 1.0.0
*/
RS read(@NotNull RQ requestMessage, @Nullable Long timeout) throws DeviceCallTimeoutException, DeviceCallSendException;
RS read(@NotNull RQ requestMessage, @Nullable Long timeout) throws DeviceCallTimeoutException, DeviceCallSendException, TransportException;

/**
* Performs a 'create' request.
Expand All @@ -54,7 +55,7 @@ public interface DeviceCall<RQ extends DeviceRequestMessage<?, ?>, RS extends De
* @throws DeviceCallSendException if sending the request produces any error.
* @since 1.0.0
*/
RS create(@NotNull RQ requestMessage, @Nullable Long timeout) throws DeviceCallTimeoutException, DeviceCallSendException;
RS create(@NotNull RQ requestMessage, @Nullable Long timeout) throws DeviceCallTimeoutException, DeviceCallSendException, TransportException;

/**
* Performs a 'write' request.
Expand All @@ -66,7 +67,7 @@ public interface DeviceCall<RQ extends DeviceRequestMessage<?, ?>, RS extends De
* @throws DeviceCallSendException if sending the request produces any error.
* @since 1.0.0
*/
RS write(@NotNull RQ requestMessage, @Nullable Long timeout) throws DeviceCallTimeoutException, DeviceCallSendException;
RS write(@NotNull RQ requestMessage, @Nullable Long timeout) throws DeviceCallTimeoutException, DeviceCallSendException, TransportException;

/**
* Performs a 'delete' request.
Expand All @@ -78,7 +79,7 @@ public interface DeviceCall<RQ extends DeviceRequestMessage<?, ?>, RS extends De
* @throws DeviceCallSendException if sending the request produces any error.
* @since 1.0.0
*/
RS delete(@NotNull RQ requestMessage, @Nullable Long timeout) throws DeviceCallTimeoutException, DeviceCallSendException;
RS delete(@NotNull RQ requestMessage, @Nullable Long timeout) throws DeviceCallTimeoutException, DeviceCallSendException, TransportException;

/**
* Performs an 'execute' request.
Expand All @@ -90,7 +91,7 @@ public interface DeviceCall<RQ extends DeviceRequestMessage<?, ?>, RS extends De
* @throws DeviceCallSendException if sending the request produces any error.
* @since 1.0.0
*/
RS execute(@NotNull RQ requestMessage, @Nullable Long timeout) throws DeviceCallTimeoutException, DeviceCallSendException;
RS execute(@NotNull RQ requestMessage, @Nullable Long timeout) throws DeviceCallTimeoutException, DeviceCallSendException, TransportException;

/**
* Performs an 'options' request.
Expand All @@ -102,7 +103,7 @@ public interface DeviceCall<RQ extends DeviceRequestMessage<?, ?>, RS extends De
* @throws DeviceCallSendException if sending the request produces any error.
* @since 1.0.0
*/
RS options(@NotNull RQ requestMessage, @Nullable Long timeout) throws DeviceCallTimeoutException, DeviceCallSendException;
RS options(@NotNull RQ requestMessage, @Nullable Long timeout) throws DeviceCallTimeoutException, DeviceCallSendException, TransportException;

/**
* Performs a SUBMIT request.
Expand All @@ -115,7 +116,7 @@ public interface DeviceCall<RQ extends DeviceRequestMessage<?, ?>, RS extends De
* @throws DeviceCallSendException if sending the request produces any error.
* @since 1.3.0
*/
RS submit(@NotNull RQ requestMessage, @Nullable Long timeout) throws DeviceCallTimeoutException, DeviceCallSendException;
RS submit(@NotNull RQ requestMessage, @Nullable Long timeout) throws DeviceCallTimeoutException, DeviceCallSendException, TransportException;

/**
* Performs a CANCEL request.
Expand All @@ -128,7 +129,7 @@ public interface DeviceCall<RQ extends DeviceRequestMessage<?, ?>, RS extends De
* @throws DeviceCallSendException if sending the request produces any error.
* @since 1.3.0
*/
RS cancel(@NotNull RQ requestMessage, @Nullable Long timeout) throws DeviceCallTimeoutException, DeviceCallSendException;
RS cancel(@NotNull RQ requestMessage, @Nullable Long timeout) throws DeviceCallTimeoutException, DeviceCallSendException, TransportException;

/**
* Get the {@link DeviceMessage} type.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import org.eclipse.kapua.transport.TransportFacade;
import org.eclipse.kapua.transport.exception.TransportClientGetException;
import org.eclipse.kapua.transport.exception.TransportClientPoolExhaustedException;
import org.eclipse.kapua.transport.exception.TransportException;
import org.eclipse.kapua.transport.exception.TransportTimeoutException;
import org.eclipse.kapua.transport.message.TransportMessage;

Expand Down Expand Up @@ -69,49 +70,49 @@ public class KuraDeviceCallImpl implements DeviceCall<KuraRequestMessage, KuraRe

@Override
public KuraResponseMessage create(@NotNull KuraRequestMessage requestMessage, @Nullable Long timeout)
throws DeviceCallTimeoutException, DeviceCallSendException {
throws DeviceCallTimeoutException, DeviceCallSendException, TransportException {
return sendInternal(requestMessage, timeout);
}

@Override
public KuraResponseMessage read(@NotNull KuraRequestMessage requestMessage, @Nullable Long timeout)
throws DeviceCallTimeoutException, DeviceCallSendException {
throws DeviceCallTimeoutException, DeviceCallSendException, TransportException {
return sendInternal(requestMessage, timeout);
}

@Override
public KuraResponseMessage options(@NotNull KuraRequestMessage requestMessage, @Nullable Long timeout)
throws DeviceCallTimeoutException, DeviceCallSendException {
throws DeviceCallTimeoutException, DeviceCallSendException, TransportException {
return sendInternal(requestMessage, timeout);
}

@Override
public KuraResponseMessage delete(@NotNull KuraRequestMessage requestMessage, @Nullable Long timeout)
throws DeviceCallTimeoutException, DeviceCallSendException {
throws DeviceCallTimeoutException, DeviceCallSendException, TransportException {
return sendInternal(requestMessage, timeout);
}

@Override
public KuraResponseMessage execute(@NotNull KuraRequestMessage requestMessage, @Nullable Long timeout)
throws DeviceCallTimeoutException, DeviceCallSendException {
throws DeviceCallTimeoutException, DeviceCallSendException, TransportException {
return sendInternal(requestMessage, timeout);
}

@Override
public KuraResponseMessage write(@NotNull KuraRequestMessage requestMessage, @Nullable Long timeout)
throws DeviceCallTimeoutException, DeviceCallSendException {
throws DeviceCallTimeoutException, DeviceCallSendException, TransportException {
return sendInternal(requestMessage, timeout);
}

@Override
public KuraResponseMessage submit(KuraRequestMessage requestMessage, @Nullable Long timeout)
throws DeviceCallTimeoutException, DeviceCallSendException {
throws DeviceCallTimeoutException, DeviceCallSendException, TransportException {
return sendInternal(requestMessage, timeout);
}

@Override
public KuraResponseMessage cancel(KuraRequestMessage requestMessage, @Nullable Long timeout)
throws DeviceCallTimeoutException, DeviceCallSendException {
throws DeviceCallTimeoutException, DeviceCallSendException, TransportException {
return sendInternal(requestMessage, timeout);
}

Expand All @@ -134,7 +135,7 @@ public Class<KuraMessage> getBaseMessageClass() {
* @throws DeviceCallSendException if sending the request produces any error.
* @since 1.0.0
*/
protected KuraResponseMessage sendInternal(@NotNull KuraRequestMessage requestMessage, @Nullable Long timeout) throws DeviceCallTimeoutException, DeviceCallSendException {
protected KuraResponseMessage sendInternal(@NotNull KuraRequestMessage requestMessage, @Nullable Long timeout) throws DeviceCallTimeoutException, DeviceCallSendException, TransportException {

KuraResponseMessage response = null;
try {
Expand Down Expand Up @@ -178,6 +179,8 @@ protected KuraResponseMessage sendInternal(@NotNull KuraRequestMessage requestMe
}
} catch (TransportTimeoutException te) {
throw new DeviceCallTimeoutException(te, timeout);
} catch (TransportException te) {
throw te;
} catch (KapuaException se) {
throw new DeviceCallSendException(se, requestMessage);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import org.eclipse.kapua.service.device.registry.DeviceRegistryService;
import org.eclipse.kapua.service.device.registry.connection.DeviceConnectionStatus;
import org.eclipse.kapua.translator.Translator;
import org.eclipse.kapua.transport.exception.TransportException;

import java.util.Date;

Expand Down Expand Up @@ -111,7 +112,7 @@ public DeviceCallBuilder withTimeoutOrDefault(Long timeout) {
* @throws DeviceManagementSendException If sending the {@link KapuaRequestMessage} goes on error.
* @since 1.0.0
*/
public RS send() throws KapuaEntityNotFoundException, KapuaIllegalArgumentException, DeviceNotConnectedException, DeviceManagementTimeoutException, DeviceManagementSendException {
public RS send() throws KapuaEntityNotFoundException, KapuaIllegalArgumentException, DeviceNotConnectedException, DeviceManagementTimeoutException, DeviceManagementSendException, TransportException {

deviceCallPreChecks();

Expand Down Expand Up @@ -167,6 +168,8 @@ public RS send() throws KapuaEntityNotFoundException, KapuaIllegalArgumentExcept
return tClientToKapua.translate(responseMessage);
} catch (DeviceCallTimeoutException dcte) {
throw new DeviceManagementTimeoutException(dcte, timeout);
} catch (TransportException te) {
throw te;
} catch (Exception e) {
throw new DeviceManagementSendException(e, requestMessage);
}
Expand All @@ -181,7 +184,7 @@ public RS send() throws KapuaEntityNotFoundException, KapuaIllegalArgumentExcept
* @throws DeviceManagementSendException If sending the {@link KapuaRequestMessage} goes on error.
* @since 1.4.0
*/
public void sendAndForget() throws KapuaEntityNotFoundException, KapuaIllegalArgumentException, DeviceNotConnectedException, DeviceManagementTimeoutException, DeviceManagementSendException {
public void sendAndForget() throws KapuaEntityNotFoundException, KapuaIllegalArgumentException, DeviceNotConnectedException, DeviceManagementSendException, TransportException {

deviceCallPreChecks();

Expand Down Expand Up @@ -229,11 +232,18 @@ public void sendAndForget() throws KapuaEntityNotFoundException, KapuaIllegalArg
default:
throw new DeviceManagementRequestBadMethodException(requestMessage.getChannel().getMethod());
}
} catch (TransportException te) {
throw te;
} catch (Exception e) {
throw new DeviceManagementSendException(e, requestMessage);
}
}


//
// Private methods
//

private void deviceCallPreChecks() throws DeviceManagementSendException, KapuaEntityNotFoundException, DeviceNotConnectedException, KapuaIllegalNullArgumentException {
//
// Validate arguments
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import org.eclipse.kapua.service.device.registry.DeviceRegistryService;
import org.eclipse.kapua.service.device.registry.connection.DeviceConnectionStatus;
import org.eclipse.kapua.translator.Translator;
import org.eclipse.kapua.transport.exception.TransportException;

import org.checkerframework.checker.nullness.qual.Nullable;
import javax.validation.constraints.NotNull;
Expand Down Expand Up @@ -101,7 +102,7 @@ public DeviceCallExecutor(@NotNull RQ requestMessage, @Nullable Long timeout) {
* @throws DeviceManagementSendException If sending the {@link KapuaRequestMessage} goes on error.
* @since 1.0.0
*/
public RS send() throws KapuaEntityNotFoundException, DeviceNotConnectedException, DeviceManagementTimeoutException, DeviceManagementSendException {
public RS send() throws KapuaEntityNotFoundException, DeviceNotConnectedException, DeviceManagementTimeoutException, DeviceManagementSendException, TransportException {

//
// Check Device existence
Expand Down Expand Up @@ -173,6 +174,8 @@ public RS send() throws KapuaEntityNotFoundException, DeviceNotConnectedExceptio
return tClientToKapua.translate(responseMessage);
} catch (DeviceCallTimeoutException dcte) {
throw new DeviceManagementTimeoutException(dcte, timeout);
} catch (TransportException te) {
throw te;
} catch (Exception e) {
throw new DeviceManagementSendException(e, requestMessage);
}
Expand Down

0 comments on commit 6816868

Please sign in to comment.