use of com.alliander.osgp.adapter.protocol.oslp.elster.exceptions.ProtocolAdapterException in project Protocol-Adapter-OSLP by OSGP.
the class DeviceManagementService method revokeKey.
// === REVOKE KEY ===
public void revokeKey(final String organisationIdentification, final String deviceIdentification, final String correlationUid, final DeviceResponseMessageSender responseMessageSender, final String domain, final String domainVersion, final String messageType) {
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(domain, domainVersion, messageType, correlationUid, organisationIdentification, deviceIdentification, 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(domain, domainVersion, messageType, correlationUid, organisationIdentification, deviceIdentification, ResponseMessageResultType.NOT_OK, ex, responseMessageSender);
}
}
use of com.alliander.osgp.adapter.protocol.oslp.elster.exceptions.ProtocolAdapterException in project Protocol-Adapter-OSLP 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 com.alliander.osgp.adapter.protocol.oslp.elster.exceptions.ProtocolAdapterException in project Protocol-Adapter-OSLP 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 deviceIdentifcation = 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();
switch(DeviceFunctionDto.valueOf(messageType)) {
case REGISTER_DEVICE:
if (ResponseMessageResultType.valueOf(result).equals(ResponseMessageResultType.NOT_OK)) {
throw new ProtocolAdapterException(String.format("Response for device: %s for MessageType: %s is: %s, error: %s", deviceIdentifcation, messageType, result, osgpException));
}
break;
default:
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 com.alliander.osgp.adapter.protocol.oslp.elster.exceptions.ProtocolAdapterException in project Protocol-Adapter-OSLP by OSGP.
the class OslpConfig method serverBootstrap.
@Bean(destroyMethod = "releaseExternalResources")
public ServerBootstrap serverBootstrap() {
final ChannelFactory factory = new NioServerSocketChannelFactory(Executors.newCachedThreadPool(), Executors.newCachedThreadPool());
final ServerBootstrap bootstrap = new ServerBootstrap(factory);
bootstrap.setPipelineFactory(new ChannelPipelineFactory() {
@Override
public ChannelPipeline getPipeline() throws ProtocolAdapterException {
final ChannelPipeline pipeline = OslpConfig.this.createChannelPipeline(OslpConfig.this.oslpChannelHandlerServer());
LOGGER.info("Created server new pipeline");
return pipeline;
}
});
bootstrap.setOption("child.tcpNoDelay", true);
bootstrap.setOption("child.keepAlive", false);
bootstrap.bind(new InetSocketAddress(this.oslpPortServer()));
return bootstrap;
}
Aggregations