Example usage for javax.jms ObjectMessage getJMSCorrelationID

List of usage examples for javax.jms ObjectMessage getJMSCorrelationID

Introduction

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

Prototype


String getJMSCorrelationID() throws JMSException;

Source Link

Document

Gets the correlation ID for the message.

Usage

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

@Override
public void onMessage(final Message message) {
    try {/*  ww w .ja  v a 2s. c o  m*/
        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  va2s.com
    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;// ww  w  .j a  v a  2  s .c om
    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:com.alliander.osgp.signing.server.infra.messaging.SigningServerRequestMessageListener.java

@Override
public void onMessage(final Message message) {
    try {//from   ww w .  j  a  va  2 s  .  com
        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.acceptancetests.firmwaremanagement.UpdateFirmwareSteps.java

@DomainStep("an update firmware response message with correlationId (.*), deviceId (.*), qresult (.*) and qdescription (.*) is found in the queue (.*)")
public void givenAnUpdateFirmwareVersionResponseMessageIsFoundInTheQueue(final String correlationId,
        final String deviceId, final String qresult, final String qdescription, final Boolean isFound) {
    LOGGER.info(/*w ww . ja  v a  2  s . co m*/
            "a update firmware response message with correlationId {}, deviceId {}, qresult {} and qdescription {} is found in the queue {}",
            correlationId, deviceId, qresult, qdescription, isFound);
    if (isFound) {
        final ObjectMessage messageMock = mock(ObjectMessage.class);

        try {
            when(messageMock.getJMSCorrelationID()).thenReturn(correlationId);
            when(messageMock.getStringProperty("OrganisationIdentification")).thenReturn(ORGANISATION_ID);
            when(messageMock.getStringProperty("DeviceIdentification")).thenReturn(deviceId);
            final ResponseMessageResultType result = ResponseMessageResultType.valueOf(qresult);
            Serializable dataObject = null;
            OsgpException exception = null;
            if (result.equals(ResponseMessageResultType.NOT_OK)) {
                dataObject = new FunctionalException(FunctionalExceptionType.VALIDATION_ERROR,
                        ComponentType.UNKNOWN, new ValidationException());
                exception = (OsgpException) dataObject;
            }
            final ResponseMessage message = new ResponseMessage(correlationId, ORGANISATION_ID, deviceId,
                    result, exception, dataObject);
            when(messageMock.getObject()).thenReturn(message);
        } catch (final JMSException e) {
            LOGGER.error("JMSException", e);
        }

        when(this.commonResponsesJmsTemplate.receiveSelected(any(String.class))).thenReturn(messageMock);
    } else {
        when(this.commonResponsesJmsTemplate.receiveSelected(any(String.class))).thenReturn(null);
    }
}

From source file:com.alliander.osgp.acceptancetests.adhocmanagement.ResumeScheduleSteps.java

@DomainStep("a resume schedule response message with correlationId (.*), deviceId (.*), qresult (.*) and qdescription (.*) is found in the queue (.*)")
public void givenAResumeScheduleResponseMessageIsFoundInTheQueue(final String correlationId,
        final String deviceId, final String qresult, final String qdescription, final Boolean isFound) {
    LOGGER.info(/*from   w  w w . ja  va  2 s  . c om*/
            "GIVEN: \"a resume schedule response message with correlationId {}, deviceId {}, qresult {} and qdescription {} is found in the queue {}\".",
            correlationId, deviceId, qresult, qdescription, isFound);
    if (isFound) {
        final ObjectMessage messageMock = mock(ObjectMessage.class);

        try {
            when(messageMock.getJMSCorrelationID()).thenReturn(correlationId);
            when(messageMock.getStringProperty("OrganisationIdentification"))
                    .thenReturn(this.organisation.getOrganisationIdentification());
            when(messageMock.getStringProperty("DeviceIdentification")).thenReturn(deviceId);

            final ResponseMessageResultType result = ResponseMessageResultType.valueOf(qresult);
            Serializable dataObject = null;
            OsgpException exception = null;
            if (result.equals(ResponseMessageResultType.NOT_OK)) {
                dataObject = new FunctionalException(FunctionalExceptionType.VALIDATION_ERROR,
                        ComponentType.UNKNOWN, new ValidationException());
                exception = (OsgpException) dataObject;
            }
            final ResponseMessage message = new ResponseMessage(correlationId,
                    this.organisation.getOrganisationIdentification(), deviceId, result, exception, dataObject);
            when(messageMock.getObject()).thenReturn(message);
        } catch (final JMSException e) {
            e.printStackTrace();
        }

        when(this.publicLightingResponsesJmsTemplate.receiveSelected(any(String.class)))
                .thenReturn(messageMock);
    } else {
        when(this.publicLightingResponsesJmsTemplate.receiveSelected(any(String.class))).thenReturn(null);
    }
}

From source file:com.alliander.osgp.acceptancetests.deviceinstallation.StopDeviceTestSteps.java

@DomainStep("a stop device test response message with correlationId (.*), deviceId (.*), qresult (.*) and qdescription (.*) is found in the queue (.*)")
public void givenAStopDeviceTestResponseMessageIsFoundInTheQueue(final String correlationId,
        final String deviceId, final String qresult, final String qdescription, final Boolean isFound) {
    LOGGER.info(//from   ww w  .  ja  v  a  2s  . co  m
            "a stop device test response message with correlationId {}, deviceId {}, qresult {} and qdescription {} is found in the queue {}",
            correlationId, deviceId, qresult, qdescription, isFound);
    if (isFound) {
        final ObjectMessage messageMock = mock(ObjectMessage.class);

        try {
            when(messageMock.getJMSCorrelationID()).thenReturn(correlationId);
            when(messageMock.getStringProperty("OrganisationIdentification"))
                    .thenReturn(this.organisation.getOrganisationIdentification());
            when(messageMock.getStringProperty("DeviceIdentification")).thenReturn(deviceId);
            final ResponseMessageResultType result = ResponseMessageResultType.valueOf(qresult);
            Serializable dataObject = null;
            OsgpException exception = null;
            if (result.equals(ResponseMessageResultType.NOT_OK)) {
                dataObject = new FunctionalException(FunctionalExceptionType.VALIDATION_ERROR,
                        ComponentType.UNKNOWN, new ValidationException());
                exception = (OsgpException) dataObject;
            }
            final ResponseMessage message = new ResponseMessage(correlationId,
                    this.organisation.getOrganisationIdentification(), deviceId, result, exception, dataObject);
            when(messageMock.getObject()).thenReturn(message);
        } catch (final JMSException e) {
            LOGGER.error("JMSException", e);
        }

        when(this.commonResponsesJmsTemplate.receiveSelected(any(String.class))).thenReturn(messageMock);
    } else {
        when(this.commonResponsesJmsTemplate.receiveSelected(any(String.class))).thenReturn(null);
    }
}

From source file:com.alliander.osgp.acceptancetests.deviceinstallation.StartDeviceTestSteps.java

@DomainStep("a start device test response message with correlationId (.*), deviceId (.*), qresult (.*) and qdescription (.*) is found in the queue (.*)")
public void givenAStartDeviceTestResponseMessageIsFoundInTheQueue(final String correlationId,
        final String deviceId, final String qresult, final String qdescription, final Boolean isFound) {
    LOGGER.info(/*from  ww w  . ja va  2  s.co m*/
            "a start device test response message with correlationId {}, deviceId {}, qresult {} and qdescription {} is found in the queue {}",
            correlationId, deviceId, qresult, qdescription, isFound);
    if (isFound) {
        final ObjectMessage messageMock = mock(ObjectMessage.class);

        try {
            when(messageMock.getJMSCorrelationID()).thenReturn(correlationId);
            when(messageMock.getStringProperty("OrganisationIdentification"))
                    .thenReturn(this.organisation.getOrganisationIdentification());
            when(messageMock.getStringProperty("DeviceIdentification")).thenReturn(deviceId);
            final ResponseMessageResultType result = ResponseMessageResultType.valueOf(qresult);
            Serializable dataObject = null;
            OsgpException exception = null;
            if (result.equals(ResponseMessageResultType.NOT_OK)) {
                dataObject = new FunctionalException(FunctionalExceptionType.VALIDATION_ERROR,
                        ComponentType.UNKNOWN, new ValidationException());
                exception = (OsgpException) dataObject;
            }
            final ResponseMessage message = new ResponseMessage(correlationId,
                    this.organisation.getOrganisationIdentification(), deviceId, result, exception, dataObject);
            when(messageMock.getObject()).thenReturn(message);
        } catch (final JMSException e) {
            e.printStackTrace();
        }

        when(this.commonResponsesJmsTemplate.receiveSelected(any(String.class))).thenReturn(messageMock);
    } else {
        when(this.commonResponsesJmsTemplate.receiveSelected(any(String.class))).thenReturn(null);
    }
}

From source file:com.alliander.osgp.acceptancetests.adhocmanagement.SetRebootSteps.java

@DomainStep("a set reboot response message with correlationId (.*), deviceId (.*), qresult (.*) and qdescription (.*) is found in the queue (.*)")
public void givenASetRebootResponseMessageIsFoundInTheQueue(final String correlationId, final String deviceId,
        final String qresult, final String qdescription, final Boolean isFound) {
    LOGGER.info(//  w  w  w  . jav a  2s .  c  om
            "GIVEN: \"a set reboot response message with correlationId {}, deviceId {}, qresult {} and qdescription {} is found {}\".",
            correlationId, deviceId, qresult, qdescription, isFound);

    if (isFound) {
        final ObjectMessage messageMock = mock(ObjectMessage.class);

        try {
            when(messageMock.getJMSCorrelationID()).thenReturn(correlationId);
            when(messageMock.getStringProperty("OrganisationIdentification")).thenReturn(ORGANISATION_ID);
            when(messageMock.getStringProperty("DeviceIdentification")).thenReturn(deviceId);
            final ResponseMessageResultType result = ResponseMessageResultType.valueOf(qresult);
            Serializable dataObject = null;
            OsgpException exception = null;
            if (result.equals(ResponseMessageResultType.NOT_OK)) {
                dataObject = new FunctionalException(FunctionalExceptionType.VALIDATION_ERROR,
                        ComponentType.UNKNOWN, new ValidationException());
                exception = (OsgpException) dataObject;
            }
            final ResponseMessage message = new ResponseMessage(correlationId, ORGANISATION_ID, deviceId,
                    result, exception, dataObject);
            when(messageMock.getObject()).thenReturn(message);
        } catch (final JMSException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        when(this.commonResponsesJmsTemplate.receiveSelected(any(String.class))).thenReturn(messageMock);
    } else {
        when(this.commonResponsesJmsTemplate.receiveSelected(any(String.class))).thenReturn(null);
    }
}

From source file:com.alliander.osgp.acceptancetests.firmwaremanagement.GetFirmwareVersionSteps.java

@DomainStep("a get firmware version response message with correlationId (.*), deviceId (.*), qresult (.*), qdescription (.*) and firmwareversion (.*) is found in the queue (.*)")
public void givenAGetFirmwareVersionResponseMessageIsFoundInTheQueue(final String correlationId,
        final String deviceId, final String qresult, final String qdescription, final String firmwareversion,
        final Boolean isFound) {
    LOGGER.info(//  w w w  .ja va 2s  .co m
            "a firmware response message with correlationId {}, deviceId {}, qresult {}, qdescription {} and firmwareversion {} is found in the queue {}",
            correlationId, deviceId, qresult, qdescription, firmwareversion, isFound);
    if (isFound) {
        final ObjectMessage messageMock = mock(ObjectMessage.class);

        try {
            when(messageMock.getJMSCorrelationID()).thenReturn(correlationId);
            when(messageMock.getStringProperty("OrganisationIdentification")).thenReturn(ORGANISATION_ID);
            when(messageMock.getStringProperty("DeviceIdentification")).thenReturn(deviceId);
            final ResponseMessageResultType result = ResponseMessageResultType.valueOf(qresult);
            Serializable dataObject = null;
            OsgpException exception = null;
            if (result.equals(ResponseMessageResultType.NOT_OK)) {
                dataObject = new FunctionalException(FunctionalExceptionType.VALIDATION_ERROR,
                        ComponentType.UNKNOWN, new ValidationException());
                exception = (OsgpException) dataObject;
            } else {
                final List<FirmwareVersion> firmwareVersions = new ArrayList<FirmwareVersion>();
                final FirmwareVersion fw = new FirmwareVersion();
                fw.setType("Firmware");
                fw.setVersion(firmwareversion);
                firmwareVersions.add(fw);
                dataObject = (Serializable) firmwareVersions;
            }
            final ResponseMessage message = new ResponseMessage(correlationId, ORGANISATION_ID, deviceId,
                    result, exception, dataObject);
            when(messageMock.getObject()).thenReturn(message);
        } catch (final JMSException e) {
            LOGGER.error("JMSException", e);
        }

        when(this.commonResponsesJmsTemplate.receiveSelected(any(String.class))).thenReturn(messageMock);
    } else {
        when(this.commonResponsesJmsTemplate.receiveSelected(any(String.class))).thenReturn(null);
    }
}