Search in sources :

Example 1 with ProtocolAdapterException

use of org.opensmartgridplatform.adapter.protocol.oslp.elster.exceptions.ProtocolAdapterException in project open-smart-grid-platform by OSGP.

the class MetricsCounterTest method countFailureInChannelRead.

@Test
void countFailureInChannelRead() throws Exception {
    doThrow(new ProtocolAdapterException("")).when(this.deviceRegistrationService).checkSequenceNumber(any(byte[].class), anyInt());
    this.channel.writeInbound(this.oslpEnvelope());
    final Counter counter = Metrics.globalRegistry.find(MESSAGES_FAILED).counter();
    assertThat(counter.count()).isEqualTo(1.0);
}
Also used : Counter(io.micrometer.core.instrument.Counter) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.oslp.elster.exceptions.ProtocolAdapterException) Test(org.junit.jupiter.api.Test)

Example 2 with ProtocolAdapterException

use of org.opensmartgridplatform.adapter.protocol.oslp.elster.exceptions.ProtocolAdapterException in project open-smart-grid-platform by OSGP.

the class OsgpResponseMessageListener method onMessage.

@Override
public void onMessage(final Message message) {
    try {
        LOGGER.info("Received message of type: {}", message.getJMSType());
        final ObjectMessage objectMessage = (ObjectMessage) message;
        final String messageType = objectMessage.getJMSType();
        final String deviceIdentification = objectMessage.getStringProperty(Constants.DEVICE_IDENTIFICATION);
        final ResponseMessage responseMessage = (ResponseMessage) objectMessage.getObject();
        final String result = responseMessage == null ? null : responseMessage.getResult().toString();
        final OsgpException osgpException = responseMessage == null ? null : responseMessage.getOsgpException();
        if (MessageType.REGISTER_DEVICE.name().equals(messageType)) {
            if (ResponseMessageResultType.valueOf(result).equals(ResponseMessageResultType.NOT_OK)) {
                throw new ProtocolAdapterException(String.format("Response for device: %s for MessageType: %s is: %s, error: %s", deviceIdentification, messageType, result, osgpException));
            } else {
                throw new UnknownMessageTypeException("Unknown JMSType: " + messageType);
            }
        }
    } catch (final JMSException ex) {
        LOGGER.error("Exception: {} ", ex.getMessage(), ex);
    } catch (final ProtocolAdapterException e) {
        LOGGER.error("ProtocolAdapterException", e);
    } catch (final UnknownMessageTypeException e) {
        LOGGER.error("UnknownMessageTypeException", e);
    }
}
Also used : OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) ObjectMessage(javax.jms.ObjectMessage) JMSException(javax.jms.JMSException) ResponseMessage(org.opensmartgridplatform.shared.infra.jms.ResponseMessage) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.oslp.elster.exceptions.ProtocolAdapterException) UnknownMessageTypeException(org.opensmartgridplatform.shared.infra.jms.UnknownMessageTypeException)

Example 3 with ProtocolAdapterException

use of org.opensmartgridplatform.adapter.protocol.oslp.elster.exceptions.ProtocolAdapterException in project open-smart-grid-platform by OSGP.

the class DeviceRegistrationService method findDevice.

public OslpDevice findDevice(final byte[] deviceId) throws ProtocolAdapterException {
    // Convert byte array to String.
    final String deviceUid = Base64.encodeBase64String(deviceId);
    final OslpDevice oslpDevice = this.oslpDeviceSettingsService.getDeviceByUid(deviceUid);
    if (oslpDevice == null) {
        throw new ProtocolAdapterException("Unable to find device using deviceUid: " + deviceUid);
    }
    return oslpDevice;
}
Also used : ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.oslp.elster.exceptions.ProtocolAdapterException) OslpDevice(org.opensmartgridplatform.adapter.protocol.oslp.elster.domain.entities.OslpDevice)

Example 4 with ProtocolAdapterException

use of org.opensmartgridplatform.adapter.protocol.oslp.elster.exceptions.ProtocolAdapterException in project open-smart-grid-platform by OSGP.

the class DeviceManagementService method revokeKey.

// === REVOKE KEY ===
public void revokeKey(final MessageMetadata messageMetadata, final DeviceResponseMessageSender responseMessageSender) {
    final String deviceIdentification = messageMetadata.getDeviceIdentification();
    final String organisationIdentification = messageMetadata.getOrganisationIdentification();
    LOGGER.info("revokeKey called for device: {} for organisation: {}", deviceIdentification, organisationIdentification);
    try {
        final OslpDevice oslpDevice = this.oslpDeviceSettingsService.getDeviceByDeviceIdentification(deviceIdentification);
        if (oslpDevice == null) {
            throw new ProtocolAdapterException(String.format("Device not found: %s", deviceIdentification));
        }
        oslpDevice.revokePublicKey();
        this.oslpDeviceSettingsService.updateDevice(oslpDevice);
        this.sendResponseMessage(messageMetadata, ResponseMessageResultType.OK, null, responseMessageSender);
    } catch (final Exception e) {
        LOGGER.error("Unexpected exception during revokeKey", e);
        final TechnicalException ex = new TechnicalException(ComponentType.UNKNOWN, "Exception occurred while revoking key", e);
        this.sendResponseMessage(messageMetadata, ResponseMessageResultType.NOT_OK, ex, responseMessageSender);
    }
}
Also used : TechnicalException(org.opensmartgridplatform.shared.exceptionhandling.TechnicalException) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.oslp.elster.exceptions.ProtocolAdapterException) OslpDevice(org.opensmartgridplatform.adapter.protocol.oslp.elster.domain.entities.OslpDevice) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.oslp.elster.exceptions.ProtocolAdapterException) OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) TechnicalException(org.opensmartgridplatform.shared.exceptionhandling.TechnicalException)

Aggregations

ProtocolAdapterException (org.opensmartgridplatform.adapter.protocol.oslp.elster.exceptions.ProtocolAdapterException)4 OslpDevice (org.opensmartgridplatform.adapter.protocol.oslp.elster.domain.entities.OslpDevice)2 OsgpException (org.opensmartgridplatform.shared.exceptionhandling.OsgpException)2 Counter (io.micrometer.core.instrument.Counter)1 JMSException (javax.jms.JMSException)1 ObjectMessage (javax.jms.ObjectMessage)1 Test (org.junit.jupiter.api.Test)1 TechnicalException (org.opensmartgridplatform.shared.exceptionhandling.TechnicalException)1 ResponseMessage (org.opensmartgridplatform.shared.infra.jms.ResponseMessage)1 UnknownMessageTypeException (org.opensmartgridplatform.shared.infra.jms.UnknownMessageTypeException)1