Search in sources :

Example 1 with StatusCodeMapper

use of org.eclipse.hono.client.StatusCodeMapper in project hono by eclipse.

the class GenericSenderLink method mapUnacceptedOutcomeToErrorResult.

private Future<ProtonDelivery> mapUnacceptedOutcomeToErrorResult(final ProtonDelivery delivery) {
    final DeliveryState remoteState = delivery.getRemoteState();
    if (Accepted.class.isInstance(remoteState)) {
        throw new IllegalStateException("delivery is expected to be rejected, released or modified here, not accepted");
    }
    ServiceInvocationException e = null;
    if (Rejected.class.isInstance(remoteState)) {
        final Rejected rejected = (Rejected) remoteState;
        e = Optional.ofNullable(rejected.getError()).map(StatusCodeMapper::fromTransferError).orElseGet(() -> new ClientErrorException(HttpURLConnection.HTTP_BAD_REQUEST));
    } else if (Released.class.isInstance(remoteState)) {
        e = new MessageNotProcessedException();
    } else if (Modified.class.isInstance(remoteState)) {
        final Modified modified = (Modified) remoteState;
        if (modified.getUndeliverableHere()) {
            e = new MessageUndeliverableException();
        } else {
            e = new MessageNotProcessedException();
        }
    }
    return Future.failedFuture(e);
}
Also used : MessageUndeliverableException(org.eclipse.hono.client.MessageUndeliverableException) Released(org.apache.qpid.proton.amqp.messaging.Released) Modified(org.apache.qpid.proton.amqp.messaging.Modified) DeliveryState(org.apache.qpid.proton.amqp.transport.DeliveryState) ClientErrorException(org.eclipse.hono.client.ClientErrorException) Rejected(org.apache.qpid.proton.amqp.messaging.Rejected) ServiceInvocationException(org.eclipse.hono.client.ServiceInvocationException) StatusCodeMapper(org.eclipse.hono.client.StatusCodeMapper) MessageNotProcessedException(org.eclipse.hono.client.MessageNotProcessedException)

Aggregations

Modified (org.apache.qpid.proton.amqp.messaging.Modified)1 Rejected (org.apache.qpid.proton.amqp.messaging.Rejected)1 Released (org.apache.qpid.proton.amqp.messaging.Released)1 DeliveryState (org.apache.qpid.proton.amqp.transport.DeliveryState)1 ClientErrorException (org.eclipse.hono.client.ClientErrorException)1 MessageNotProcessedException (org.eclipse.hono.client.MessageNotProcessedException)1 MessageUndeliverableException (org.eclipse.hono.client.MessageUndeliverableException)1 ServiceInvocationException (org.eclipse.hono.client.ServiceInvocationException)1 StatusCodeMapper (org.eclipse.hono.client.StatusCodeMapper)1