Example usage for javax.jms ObjectMessage getJMSType

List of usage examples for javax.jms ObjectMessage getJMSType

Introduction

In this page you can find the example usage for javax.jms ObjectMessage getJMSType.

Prototype


String getJMSType() throws JMSException;

Source Link

Document

Gets the message type identifier supplied by the client when the message was sent.

Usage

From source file:org.osgp.adapter.protocol.dlms.infra.messaging.DeviceRequestMessageProcessorMap.java

@Override
public MessageProcessor getMessageProcessor(final ObjectMessage message) throws JMSException {

    if (message.getJMSType() == null) {
        LOGGER.error("Unknown message type: {}", message.getJMSType());
        throw new JMSException("Unknown message type");
    }//w ww  .ja v a  2  s . c om

    final DeviceRequestMessageType messageType = DeviceRequestMessageType.valueOf(message.getJMSType());

    if (messageType.name() == null) {
        LOGGER.error("No message processor found for message type: {}", message.getJMSType());
        throw new JMSException("Unknown message processor");
    }

    return this.messageProcessors.get(messageType.ordinal());
}

From source file:com.alliander.osgp.adapter.protocol.oslp.elster.infra.messaging.DeviceRequestMessageProcessorMap.java

@Override
public MessageProcessor getMessageProcessor(final ObjectMessage message) throws JMSException {

    if (message.getJMSType() == null) {
        LOGGER.error("Unknown message type: {}", message.getJMSType());
        throw new JMSException("Unknown message type");
    }/*from   w w  w  .  j  av  a 2s  .c o m*/

    final DeviceRequestMessageType messageType = DeviceRequestMessageType.valueOf(message.getJMSType());
    if (messageType.name() == null) {
        LOGGER.error("No message processor found for message type: {}", message.getJMSType());
        throw new JMSException("Unknown message processor");
    }

    final MessageProcessor messageProcessor = this.messageProcessors.get(messageType.ordinal());
    if (messageProcessor == null) {
        throw new IllegalArgumentException("Message type is not supported: " + message.getJMSType());
    }

    return messageProcessor;
}

From source file:com.alliander.osgp.adapter.protocol.iec61850.infra.messaging.DeviceRequestMessageProcessorMap.java

@Override
public MessageProcessor getMessageProcessor(final ObjectMessage message) throws JMSException {

    if (message.getJMSType() == null) {
        LOGGER.error("Unknown message type: {}", message.getJMSType());
        throw new JMSException("Unknown message type");
    }/*from   w  ww . j  a  v a 2  s. co m*/

    final DeviceRequestMessageType messageType = DeviceRequestMessageType.valueOf(message.getJMSType());
    if (messageType.name() == null) {
        LOGGER.error("No message processor found for message type: {}", message.getJMSType());
        throw new JMSException("Unknown message processor for message type: " + message.getJMSType());
    }

    final MessageProcessor messageProcessor = this.messageProcessors.get(messageType.ordinal());
    if (messageProcessor == null) {
        LOGGER.error("No message processor instance found in message processor map for message type: {}",
                message.getJMSType());
        throw new JMSException("Unknown message processor");
    }

    return messageProcessor;
}

From source file:com.alliander.osgp.adapter.protocol.oslp.elster.infra.messaging.SigningServerResponsesMessageListener.java

@Override
public void onMessage(final Message message) {
    try {/*from www. j ava 2  s.c om*/
        LOGGER.info("Received message of type: {}", message.getJMSType());

        final ObjectMessage objectMessage = (ObjectMessage) message;
        final String messageType = objectMessage.getJMSType();
        final String correlationId = objectMessage.getJMSCorrelationID();
        final String deviceIdentification = objectMessage.getStringProperty(Constants.DEVICE_IDENTIFICATION);
        final ResponseMessage responseMessage = (ResponseMessage) objectMessage.getObject();
        final ResponseMessageResultType result = responseMessage == null ? null : responseMessage.getResult();

        // Check the result.
        if (result.equals(ResponseMessageResultType.NOT_OK)) {
            LOGGER.error("OslpEnvelope was not signed by signing-server. Unable to send request to device: {}",
                    deviceIdentification);
            this.oslpSigningService.handleError(deviceIdentification, responseMessage);
            return;
        }

        LOGGER.info("messageType: {}, deviceIdentification: {}, result: {}, correlationId: {}", messageType,
                deviceIdentification, result, correlationId);

        // Get the DTO object containing signed OslpEnvelope.
        final SignedOslpEnvelopeDto signedOslpEnvelopeDto = (SignedOslpEnvelopeDto) responseMessage
                .getDataObject();

        this.oslpSigningService.handleSignedOslpEnvelope(signedOslpEnvelopeDto, deviceIdentification);
    } catch (final JMSException ex) {
        LOGGER.error("Exception: {} ", ex.getMessage(), ex);
    }
}

From source file:com.alliander.osgp.adapter.protocol.oslp.elster.infra.messaging.processors.AdminRevokeKeyRequestMessageProcessor.java

@Override
public void processMessage(final ObjectMessage message) {
    LOGGER.debug("Processing admin revoke key message");

    String correlationUid = null;
    String domain = null;//from w w w.j a  v a2 s .co m
    String domainVersion = null;
    String messageType = null;
    String organisationIdentification = null;
    String deviceIdentification = null;

    try {
        correlationUid = message.getJMSCorrelationID();
        domain = message.getStringProperty(Constants.DOMAIN);
        domainVersion = message.getStringProperty(Constants.DOMAIN_VERSION);
        messageType = message.getJMSType();
        organisationIdentification = message.getStringProperty(Constants.ORGANISATION_IDENTIFICATION);
        deviceIdentification = message.getStringProperty(Constants.DEVICE_IDENTIFICATION);
    } catch (final JMSException e) {
        LOGGER.error("UNRECOVERABLE ERROR, unable to read ObjectMessage instance, giving up.", e);
        LOGGER.debug("correlationUid: {}", correlationUid);
        LOGGER.debug("domain: {}", domain);
        LOGGER.debug("domainVersion: {}", domainVersion);
        LOGGER.debug("messageType: {}", messageType);
        LOGGER.debug("organisationIdentification: {}", organisationIdentification);
        LOGGER.debug("deviceIdentification: {}", deviceIdentification);
        return;
    }

    LOGGER.info("Calling application service function: {} for domain: {} {}", messageType, domain,
            domainVersion);

    this.deviceManagementService.revokeKey(organisationIdentification, deviceIdentification, correlationUid,
            this.responseMessageSender, domain, domainVersion, messageType);
}

From source file:com.alliander.osgp.adapter.protocol.oslp.elster.infra.messaging.processors.AdminUpdateKeyRequestMessageProcessor.java

@Override
public void processMessage(final ObjectMessage message) {
    LOGGER.debug("Processing admin update key message");

    String correlationUid = null;
    String domain = null;//from w  w w.j av a 2 s.  c o m
    String domainVersion = null;
    String messageType = null;
    String organisationIdentification = null;
    String deviceIdentification = null;

    try {
        correlationUid = message.getJMSCorrelationID();
        domain = message.getStringProperty(Constants.DOMAIN);
        domainVersion = message.getStringProperty(Constants.DOMAIN_VERSION);
        messageType = message.getJMSType();
        organisationIdentification = message.getStringProperty(Constants.ORGANISATION_IDENTIFICATION);
        deviceIdentification = message.getStringProperty(Constants.DEVICE_IDENTIFICATION);
    } catch (final JMSException e) {
        LOGGER.error("UNRECOVERABLE ERROR, unable to read ObjectMessage instance, giving up.", e);
        LOGGER.debug("correlationUid: {}", correlationUid);
        LOGGER.debug("domain: {}", domain);
        LOGGER.debug("domainVersion: {}", domainVersion);
        LOGGER.debug("messageType: {}", messageType);
        LOGGER.debug("organisationIdentification: {}", organisationIdentification);
        LOGGER.debug("deviceIdentification: {}", deviceIdentification);
        return;
    }

    try {
        final String publicKey = (String) message.getObject();

        LOGGER.info("Calling application service function: {} for domain: {} {}", messageType, domain,
                domainVersion);

        this.deviceManagementService.updateKey(organisationIdentification, deviceIdentification, correlationUid,
                this.responseMessageSender, domain, domainVersion, messageType, publicKey);
    } catch (final Exception e) {
        this.handleError(e, correlationUid, organisationIdentification, deviceIdentification, domain,
                domainVersion, messageType);
    }
}

From source file:org.osgp.adapter.protocol.dlms.infra.messaging.DeviceRequestMessageProcessor.java

@Override
public void processMessage(final ObjectMessage message) throws JMSException {
    LOGGER.debug("Processing {} request message", this.deviceRequestMessageType.name());
    final DlmsDeviceMessageMetadata messageMetadata = new DlmsDeviceMessageMetadata();

    ClientConnection conn = null;/* w  w w .j a  va 2  s.  c o m*/
    DlmsDevice device = null;

    try {
        // Handle message
        messageMetadata.handleMessage(message);

        LOGGER.info("{} called for device: {} for organisation: {}", message.getJMSType(),
                messageMetadata.getDeviceIdentification(), messageMetadata.getOrganisationIdentification());

        device = this.domainHelperService.findDlmsDevice(messageMetadata);
        conn = this.dlmsConnectionFactory.getConnection(device);

        final Serializable response = this.handleMessage(conn, device, message.getObject());

        // Send response
        this.sendResponseMessage(messageMetadata, ResponseMessageResultType.OK, null,
                this.responseMessageSender, response);
    } catch (final ConnectionException exception) {
        // Retry / redeliver by throwing RuntimeException.
        LOGGER.info("ConnectionException occurred, JMS will catch this exception.");
        throw exception;
    } catch (final JMSException exception) {
        this.logJmsException(LOGGER, exception, messageMetadata);
    } catch (final Exception exception) {
        // Return original request + exception
        LOGGER.error("Unexpected exception during {}", this.deviceRequestMessageType.name(), exception);

        final OsgpException ex = this.osgpExceptionConverter.ensureOsgpOrTechnicalException(exception);
        this.sendResponseMessage(messageMetadata, ResponseMessageResultType.NOT_OK, ex,
                this.responseMessageSender, message.getObject());
    } finally {
        if (conn != null) {
            LOGGER.info("Closing connection with {}", device.getDeviceIdentification());
            conn.close();
        }
    }
}

From source file:com.alliander.osgp.signing.server.infra.messaging.SigningServerRequestMessageListener.java

@Override
public void onMessage(final Message message) {
    try {/*from ww  w . ja  v a2  s .  co m*/
        final ObjectMessage objectMessage = (ObjectMessage) message;
        final Destination replyToQueue = objectMessage.getJMSReplyTo();
        final RequestMessage requestMessage = (RequestMessage) objectMessage.getObject();
        final UnsignedOslpEnvelopeDto unsignedOslpEnvelopeDto = (UnsignedOslpEnvelopeDto) requestMessage
                .getRequest();
        final String correlationUid = objectMessage.getJMSCorrelationID();
        final String deviceIdentification = objectMessage.getStringProperty(Constants.DEVICE_IDENTIFICATION);

        LOGGER.info("Received message of type: {}, for device: {} with correlationId: {} and replyToQueue: {}",
                objectMessage.getJMSType(), deviceIdentification, correlationUid, replyToQueue.toString());

        LOGGER.debug("-----------------------------------------------------------------------------");
        LOGGER.debug("unsignedOslpEnvelopeDto.getCorrelationUid() : {}",
                unsignedOslpEnvelopeDto.getCorrelationUid());
        LOGGER.debug("unsignedOslpEnvelopeDto.getDeviceId() : {}", unsignedOslpEnvelopeDto.getDeviceId());
        LOGGER.debug("unsignedOslpEnvelopeDto.getDomain() : {}", unsignedOslpEnvelopeDto.getDomain());
        LOGGER.debug("unsignedOslpEnvelopeDto.getDomainVersion() : {}",
                unsignedOslpEnvelopeDto.getDomainVersion());
        LOGGER.debug("unsignedOslpEnvelopeDto.getIpAddress() : {}", unsignedOslpEnvelopeDto.getIpAddress());
        LOGGER.debug("unsignedOslpEnvelopeDto.getMessageType() : {}", unsignedOslpEnvelopeDto.getMessageType());
        LOGGER.debug("unsignedOslpEnvelopeDto.getOrganisationIdentification() : {}",
                unsignedOslpEnvelopeDto.getOrganisationIdentification());
        LOGGER.debug("unsignedOslpEnvelopeDto.getPayloadMessage() : {}",
                unsignedOslpEnvelopeDto.getPayloadMessage().toString());
        LOGGER.debug("unsignedOslpEnvelopeDto.getRetryCount() : {}", unsignedOslpEnvelopeDto.getRetryCount());
        LOGGER.debug("unsignedOslpEnvelopeDto.getSequenceNumber() : {}",
                unsignedOslpEnvelopeDto.getSequenceNumber());
        LOGGER.debug("unsignedOslpEnvelopeDto.isScheduled() : {}", unsignedOslpEnvelopeDto.isScheduled());
        LOGGER.debug("-----------------------------------------------------------------------------");

        this.signingService.sign(unsignedOslpEnvelopeDto, correlationUid, deviceIdentification, replyToQueue);

    } catch (final JMSException ex) {
        LOGGER.error("Exception: {} ", ex.getMessage(), ex);
    }
}

From source file:com.alliander.osgp.adapter.protocol.oslp.elster.infra.messaging.processors.CommonRebootRequestMessageProcessor.java

@Override
public void processMessage(final ObjectMessage message) {
    LOGGER.debug("Processing common reboot request message");

    String correlationUid = null;
    String domain = null;//from   w  ww.  j  av a  2 s .  com
    String domainVersion = null;
    String messageType = null;
    String organisationIdentification = null;
    String deviceIdentification = null;
    String ipAddress = null;
    int retryCount = 0;
    boolean isScheduled = false;

    try {
        correlationUid = message.getJMSCorrelationID();
        domain = message.getStringProperty(Constants.DOMAIN);
        domainVersion = message.getStringProperty(Constants.DOMAIN_VERSION);
        messageType = message.getJMSType();
        organisationIdentification = message.getStringProperty(Constants.ORGANISATION_IDENTIFICATION);
        deviceIdentification = message.getStringProperty(Constants.DEVICE_IDENTIFICATION);
        ipAddress = message.getStringProperty(Constants.IP_ADDRESS);
        retryCount = message.getIntProperty(Constants.RETRY_COUNT);
        isScheduled = message.propertyExists(Constants.IS_SCHEDULED)
                ? message.getBooleanProperty(Constants.IS_SCHEDULED)
                : false;
    } catch (final JMSException e) {
        LOGGER.error("UNRECOVERABLE ERROR, unable to read ObjectMessage instance, giving up.", e);
        LOGGER.debug("correlationUid: {}", correlationUid);
        LOGGER.debug("domain: {}", domain);
        LOGGER.debug("domainVersion: {}", domainVersion);
        LOGGER.debug("messageType: {}", messageType);
        LOGGER.debug("organisationIdentification: {}", organisationIdentification);
        LOGGER.debug("deviceIdentification: {}", deviceIdentification);
        LOGGER.debug("ipAddress: {}", ipAddress);
        return;
    }

    LOGGER.info("Calling DeviceService function: {} for domain: {} {}", messageType, domain, domainVersion);

    final DeviceRequest deviceRequest = new DeviceRequest(organisationIdentification, deviceIdentification,
            correlationUid, domain, domainVersion, messageType, ipAddress, retryCount, isScheduled);

    this.deviceService.setReboot(deviceRequest);
}

From source file:com.alliander.osgp.adapter.protocol.oslp.elster.infra.messaging.processors.CommonStartDeviceTestRequestMessageProcessor.java

@Override
public void processMessage(final ObjectMessage message) {
    LOGGER.debug("Processing common start device test request message");

    String correlationUid = null;
    String domain = null;//w  w w.  j av a 2 s .c  o m
    String domainVersion = null;
    String messageType = null;
    String organisationIdentification = null;
    String deviceIdentification = null;
    String ipAddress = null;
    int retryCount = 0;
    boolean isScheduled = false;

    try {
        correlationUid = message.getJMSCorrelationID();
        domain = message.getStringProperty(Constants.DOMAIN);
        domainVersion = message.getStringProperty(Constants.DOMAIN_VERSION);
        messageType = message.getJMSType();
        organisationIdentification = message.getStringProperty(Constants.ORGANISATION_IDENTIFICATION);
        deviceIdentification = message.getStringProperty(Constants.DEVICE_IDENTIFICATION);
        ipAddress = message.getStringProperty(Constants.IP_ADDRESS);
        retryCount = message.getIntProperty(Constants.RETRY_COUNT);
        isScheduled = message.propertyExists(Constants.IS_SCHEDULED)
                ? message.getBooleanProperty(Constants.IS_SCHEDULED)
                : false;
    } catch (final JMSException e) {
        LOGGER.error("UNRECOVERABLE ERROR, unable to read ObjectMessage instance, giving up.", e);
        LOGGER.debug("correlationUid: {}", correlationUid);
        LOGGER.debug("domain: {}", domain);
        LOGGER.debug("domainVersion: {}", domainVersion);
        LOGGER.debug("messageType: {}", messageType);
        LOGGER.debug("organisationIdentification: {}", organisationIdentification);
        LOGGER.debug("deviceIdentification: {}", deviceIdentification);
        LOGGER.debug("ipAddress: {}", ipAddress);
        return;
    }

    LOGGER.info("Calling DeviceService function: {} for domain: {} {}", messageType, domain, domainVersion);

    final DeviceRequest deviceRequest = new DeviceRequest(organisationIdentification, deviceIdentification,
            correlationUid, domain, domainVersion, messageType, ipAddress, retryCount, isScheduled);

    this.deviceService.startSelfTest(deviceRequest);
}