Search in sources :

Example 1 with ProtocolAdapterException

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);
    }
}
Also used : TechnicalException(com.alliander.osgp.shared.exceptionhandling.TechnicalException) ProtocolAdapterException(com.alliander.osgp.adapter.protocol.oslp.elster.exceptions.ProtocolAdapterException) OslpDevice(com.alliander.osgp.adapter.protocol.oslp.elster.domain.entities.OslpDevice) OsgpException(com.alliander.osgp.shared.exceptionhandling.OsgpException) ProtocolAdapterException(com.alliander.osgp.adapter.protocol.oslp.elster.exceptions.ProtocolAdapterException) TechnicalException(com.alliander.osgp.shared.exceptionhandling.TechnicalException)

Example 2 with ProtocolAdapterException

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;
}
Also used : ProtocolAdapterException(com.alliander.osgp.adapter.protocol.oslp.elster.exceptions.ProtocolAdapterException) OslpDevice(com.alliander.osgp.adapter.protocol.oslp.elster.domain.entities.OslpDevice)

Example 3 with ProtocolAdapterException

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);
    }
}
Also used : OsgpException(com.alliander.osgp.shared.exceptionhandling.OsgpException) ObjectMessage(javax.jms.ObjectMessage) JMSException(javax.jms.JMSException) ResponseMessage(com.alliander.osgp.shared.infra.jms.ResponseMessage) ProtocolAdapterException(com.alliander.osgp.adapter.protocol.oslp.elster.exceptions.ProtocolAdapterException) UnknownMessageTypeException(com.alliander.osgp.shared.infra.jms.UnknownMessageTypeException)

Example 4 with ProtocolAdapterException

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;
}
Also used : NioServerSocketChannelFactory(org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory) InetSocketAddress(java.net.InetSocketAddress) ProtocolAdapterException(com.alliander.osgp.adapter.protocol.oslp.elster.exceptions.ProtocolAdapterException) NioClientSocketChannelFactory(org.jboss.netty.channel.socket.nio.NioClientSocketChannelFactory) NioServerSocketChannelFactory(org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory) ChannelFactory(org.jboss.netty.channel.ChannelFactory) ChannelPipelineFactory(org.jboss.netty.channel.ChannelPipelineFactory) ServerBootstrap(org.jboss.netty.bootstrap.ServerBootstrap) ChannelPipeline(org.jboss.netty.channel.ChannelPipeline) Bean(org.springframework.context.annotation.Bean)

Aggregations

ProtocolAdapterException (com.alliander.osgp.adapter.protocol.oslp.elster.exceptions.ProtocolAdapterException)4 OslpDevice (com.alliander.osgp.adapter.protocol.oslp.elster.domain.entities.OslpDevice)2 OsgpException (com.alliander.osgp.shared.exceptionhandling.OsgpException)2 TechnicalException (com.alliander.osgp.shared.exceptionhandling.TechnicalException)1 ResponseMessage (com.alliander.osgp.shared.infra.jms.ResponseMessage)1 UnknownMessageTypeException (com.alliander.osgp.shared.infra.jms.UnknownMessageTypeException)1 InetSocketAddress (java.net.InetSocketAddress)1 JMSException (javax.jms.JMSException)1 ObjectMessage (javax.jms.ObjectMessage)1 ServerBootstrap (org.jboss.netty.bootstrap.ServerBootstrap)1 ChannelFactory (org.jboss.netty.channel.ChannelFactory)1 ChannelPipeline (org.jboss.netty.channel.ChannelPipeline)1 ChannelPipelineFactory (org.jboss.netty.channel.ChannelPipelineFactory)1 NioClientSocketChannelFactory (org.jboss.netty.channel.socket.nio.NioClientSocketChannelFactory)1 NioServerSocketChannelFactory (org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory)1 Bean (org.springframework.context.annotation.Bean)1