Search in sources :

Example 26 with TransportException

use of com.microsoft.azure.sdk.iot.device.exceptions.TransportException in project azure-iot-sdk-java by Azure.

the class AmqpsExceptionTranslator method convertFromAmqpException.

static TransportException convertFromAmqpException(ErrorCondition error) {
    if (error == null) {
        TransportException t = new TransportException("An unknown transport exception occurred");
        t.setRetryable(true);
        return t;
    }
    String exceptionCode = error.getCondition() != null ? error.getCondition().toString() : "unknown";
    String description = error.getDescription();
    switch(exceptionCode) {
        case AmqpLinkCreationConflict.errorCode:
            return new AmqpLinkCreationConflict(description);
        case AmqpConnectionForcedException.errorCode:
            return new AmqpConnectionForcedException(description);
        case AmqpConnectionRedirectException.errorCode:
            return new AmqpConnectionRedirectException(description);
        case AmqpDecodeErrorException.errorCode:
            return new AmqpDecodeErrorException(description);
        case AmqpLinkDetachForcedException.errorCode:
            return new AmqpLinkDetachForcedException(description);
        case AmqpSessionErrantLinkException.errorCode:
            return new AmqpSessionErrantLinkException(description);
        case AmqpFrameSizeTooSmallException.errorCode:
            return new AmqpFrameSizeTooSmallException(description);
        case AmqpConnectionFramingErrorException.errorCode:
            return new AmqpConnectionFramingErrorException(description);
        case AmqpSessionHandleInUseException.errorCode:
            return new AmqpSessionHandleInUseException(description);
        case AmqpIllegalStateException.errorCode:
            return new AmqpIllegalStateException(description);
        case AmqpInternalErrorException.errorCode:
            return new AmqpInternalErrorException(description);
        case AmqpInvalidFieldException.errorCode:
            return new AmqpInvalidFieldException(description);
        case AmqpLinkRedirectException.errorCode:
            return new AmqpLinkRedirectException(description);
        case AmqpLinkStolenException.errorCode:
            return new AmqpLinkStolenException(description);
        case AmqpLinkMessageSizeExceededException.errorCode:
            return new AmqpLinkMessageSizeExceededException(description);
        case AmqpNotAllowedException.errorCode:
            return new AmqpNotAllowedException(description);
        case AmqpNotFoundException.errorCode:
            return new AmqpNotFoundException(description);
        case AmqpNotImplementedException.errorCode:
            return new AmqpNotImplementedException(description);
        case AmqpPreconditionFailedException.errorCode:
            return new AmqpPreconditionFailedException(description);
        case AmqpResourceDeletedException.errorCode:
            return new AmqpResourceDeletedException(description);
        case AmqpResourceLimitExceededException.errorCode:
            return new AmqpResourceLimitExceededException(description);
        case AmqpResourceLockedException.errorCode:
            return new AmqpResourceLockedException(description);
        case AmqpLinkTransferLimitExceededException.errorCode:
            return new AmqpLinkTransferLimitExceededException(description);
        case AmqpSessionUnattachedHandleException.errorCode:
            return new AmqpSessionUnattachedHandleException(description);
        case AmqpUnauthorizedAccessException.errorCode:
            return new AmqpUnauthorizedAccessException(description);
        case AmqpSessionWindowViolationException.errorCode:
            return new AmqpSessionWindowViolationException(description);
        case AmqpConnectionThrottledException.errorCode:
            return new AmqpConnectionThrottledException(description);
        case ProtonIOException.errorCode:
            return new ProtonIOException(description);
        default:
            TransportException t = new TransportException("An unknown transport exception occurred");
            t.setRetryable(true);
            return t;
    }
}
Also used : TransportException(com.microsoft.azure.sdk.iot.device.exceptions.TransportException)

Example 27 with TransportException

use of com.microsoft.azure.sdk.iot.device.exceptions.TransportException in project azure-iot-sdk-java by Azure.

the class AmqpsIotHubConnection method onMessageAcknowledged.

@Override
public void onMessageAcknowledged(Message message, DeliveryState deliveryState, String deviceId) {
    if (deliveryState == Accepted.getInstance()) {
        this.listener.onMessageSent(message, deviceId, null);
    } else if (deliveryState instanceof Rejected) {
        // The message was not accepted by the server, and the reason why is found within the nested error
        TransportException ex = AmqpsExceptionTranslator.convertFromAmqpException(((Rejected) deliveryState).getError());
        this.listener.onMessageSent(message, deviceId, ex);
    } else if (deliveryState == Released.getInstance()) {
        // As per AMQP spec, this state means the message should be re-delivered to the server at a later time
        ProtocolException protocolException = new ProtocolException("Message was released by the amqp server");
        protocolException.setRetryable(true);
        this.listener.onMessageSent(message, deviceId, protocolException);
    } else {
        log.warn("Unexpected delivery state for sent message ({})", message);
    }
}
Also used : ProtocolException(com.microsoft.azure.sdk.iot.device.exceptions.ProtocolException) Rejected(org.apache.qpid.proton.amqp.messaging.Rejected) TransportException(com.microsoft.azure.sdk.iot.device.exceptions.TransportException)

Example 28 with TransportException

use of com.microsoft.azure.sdk.iot.device.exceptions.TransportException in project azure-iot-sdk-java by Azure.

the class AmqpsIotHubConnection method createReactor.

private Reactor createReactor() throws TransportException {
    try {
        ReactorOptions options = new ReactorOptions();
        // If this option isn't set, proton defaults to 16 * 1024 max frame size. This used to default to 4 * 1024,
        // and this change to 16 * 1024 broke the websocket implementation that we layer on top of proton-j.
        // By setting this frame size back to 4 * 1024, AMQPS_WS clients can send messages with payloads up to the
        // expected 256 * 1024 bytes. For more context, see https://github.com/Azure/azure-iot-sdk-java/issues/742
        options.setMaxFrameSize(MAX_FRAME_SIZE);
        if (this.authenticationType == DeviceClientConfig.AuthType.X509_CERTIFICATE) {
            // x509 authentication does not use SASL, so disable it
            options.setEnableSaslByDefault(false);
        }
        return Proton.reactor(options, this);
    } catch (IOException e) {
        throw new TransportException("Could not create Proton reactor", e);
    }
}
Also used : ReactorOptions(org.apache.qpid.proton.reactor.ReactorOptions) IOException(java.io.IOException) TransportException(com.microsoft.azure.sdk.iot.device.exceptions.TransportException)

Example 29 with TransportException

use of com.microsoft.azure.sdk.iot.device.exceptions.TransportException in project azure-iot-sdk-java by Azure.

the class AmqpsIotHubConnection method onSessionClosedUnexpectedly.

@Override
public void onSessionClosedUnexpectedly(ErrorCondition errorCondition, String deviceId) {
    TransportException savedException = AmqpsExceptionTranslator.convertFromAmqpException(errorCondition);
    if (this.isMultiplexing) {
        // If a device is registered to an active multiplexed connection, and the session closes locally before opening,
        // need to notify upper layer that the register call failed, and that it shouldn't wait for it to report having opened.
        this.listener.onMultiplexedDeviceSessionRegistrationFailed(this.connectionId, deviceId, savedException);
    }
    // If the session closes during an open call, need to decrement this latch so that the open call doesn't wait
    // for this session to open. The above call to onMultiplexedDeviceSessionRegistrationFailed will report
    // the relevant exception.
    this.deviceSessionsOpenedLatches.get(deviceId).countDown();
    if (isMultiplexing) {
        // When multiplexing, don't kill the connection just because a session dropped.
        log.error("Amqp session closed unexpectedly. notifying the transport layer to start reconnection logic...", this.savedException);
        scheduleDeviceSessionReconnection(savedException, deviceId);
    } else {
        // When not multiplexing, reconnection logic will just spin up the whole connection again.
        this.savedException = savedException;
        log.error("Amqp session closed unexpectedly. Closing this connection...", this.savedException);
        this.connection.close();
    }
}
Also used : TransportException(com.microsoft.azure.sdk.iot.device.exceptions.TransportException)

Example 30 with TransportException

use of com.microsoft.azure.sdk.iot.device.exceptions.TransportException in project azure-iot-sdk-java by Azure.

the class TransportUtils method throwTransportExceptionWithIotHubServiceType.

public static void throwTransportExceptionWithIotHubServiceType(String message, TransportException.IotHubService service) throws TransportException {
    TransportException transportException = new TransportException(message);
    transportException.setIotHubService(service);
    throw transportException;
}
Also used : TransportException(com.microsoft.azure.sdk.iot.device.exceptions.TransportException)

Aggregations

TransportException (com.microsoft.azure.sdk.iot.device.exceptions.TransportException)46 Test (org.junit.Test)18 IOException (java.io.IOException)14 ProtocolException (com.microsoft.azure.sdk.iot.device.exceptions.ProtocolException)8 MqttException (org.eclipse.paho.client.mqttv3.MqttException)7 CountDownLatch (java.util.concurrent.CountDownLatch)4 Expectations (mockit.Expectations)4 NonStrictExpectations (mockit.NonStrictExpectations)4 Message (com.microsoft.azure.sdk.iot.device.Message)3 HttpsConnection (com.microsoft.azure.sdk.iot.device.transport.https.HttpsConnection)3 HttpsMethod (com.microsoft.azure.sdk.iot.device.transport.https.HttpsMethod)3 MqttMessaging (com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttMessaging)3 Pair (org.apache.commons.lang3.tuple.Pair)3 IotHubConnectionString (com.microsoft.azure.sdk.iot.device.IotHubConnectionString)2 ModuleClientException (com.microsoft.azure.sdk.iot.device.exceptions.ModuleClientException)2 URISyntaxException (java.net.URISyntaxException)2 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)2 IotHubSSLContext (com.microsoft.azure.sdk.iot.deps.auth.IotHubSSLContext)1 IotHubAuthenticationProvider (com.microsoft.azure.sdk.iot.device.auth.IotHubAuthenticationProvider)1 SignatureProvider (com.microsoft.azure.sdk.iot.device.auth.SignatureProvider)1