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