Example usage for javax.jms ObjectMessage getObject

List of usage examples for javax.jms ObjectMessage getObject

Introduction

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

Prototype


Serializable getObject() throws JMSException;

Source Link

Document

Gets the serializable object containing this message's data.

Usage

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

@Override
public void processMessage(final ObjectMessage message) {
    LOGGER.debug("Processing public lighting set light request message");

    String correlationUid = null;
    String domain = null;//w  w w  .  ja  va 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;
    LightValueMessageDataContainerDto lightValueMessageDataContainer = 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);
        ipAddress = message.getStringProperty(Constants.IP_ADDRESS);
        retryCount = message.getIntProperty(Constants.RETRY_COUNT);
        isScheduled = message.propertyExists(Constants.IS_SCHEDULED)
                ? message.getBooleanProperty(Constants.IS_SCHEDULED)
                : false;

        lightValueMessageDataContainer = (LightValueMessageDataContainerDto) message.getObject();

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

    final RequestMessageData requestMessageData = new RequestMessageData(lightValueMessageDataContainer, domain,
            domainVersion, messageType, retryCount, isScheduled, correlationUid, organisationIdentification,
            deviceIdentification);

    final DeviceResponseHandler deviceResponseHandler = new DeviceResponseHandler() {

        @Override
        public void handleResponse(final DeviceResponse deviceResponse) {
            PublicLightingSetLightRequestMessageProcessor.this.handleEmptyDeviceResponse(deviceResponse,
                    PublicLightingSetLightRequestMessageProcessor.this.responseMessageSender,
                    requestMessageData.getDomain(), requestMessageData.getDomainVersion(),
                    requestMessageData.getMessageType(), requestMessageData.getRetryCount());
        }

        @Override
        public void handleException(final Throwable t, final DeviceResponse deviceResponse,
                final boolean expected) {

            if (expected) {
                PublicLightingSetLightRequestMessageProcessor.this.handleExpectedError(
                        new ConnectionFailureException(ComponentType.PROTOCOL_IEC61850, t.getMessage()),
                        requestMessageData.getCorrelationUid(),
                        requestMessageData.getOrganisationIdentification(),
                        requestMessageData.getDeviceIdentification(), requestMessageData.getDomain(),
                        requestMessageData.getDomainVersion(), requestMessageData.getMessageType());
            } else {
                PublicLightingSetLightRequestMessageProcessor.this.handleUnExpectedError(deviceResponse, t,
                        requestMessageData.getMessageData(), requestMessageData.getDomain(),
                        requestMessageData.getDomainVersion(), requestMessageData.getMessageType(),
                        requestMessageData.isScheduled(), requestMessageData.getRetryCount());
            }
        }
    };

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

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

    this.deviceService.setLight(deviceRequest, deviceResponseHandler);
}

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

@Override
public void processMessage(final ObjectMessage message) {
    LOGGER.debug("Processing public lighting set transition request message");

    String correlationUid = null;
    String domain = null;// w  w  w  .  j a  v  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;
    TransitionMessageDataContainerDto transitionMessageDataContainer = 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);
        ipAddress = message.getStringProperty(Constants.IP_ADDRESS);
        retryCount = message.getIntProperty(Constants.RETRY_COUNT);
        isScheduled = message.propertyExists(Constants.IS_SCHEDULED)
                ? message.getBooleanProperty(Constants.IS_SCHEDULED)
                : false;
        transitionMessageDataContainer = (TransitionMessageDataContainerDto) message.getObject();
    } 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;
    }

    final RequestMessageData requestMessageData = new RequestMessageData(transitionMessageDataContainer, domain,
            domainVersion, messageType, retryCount, isScheduled, correlationUid, organisationIdentification,
            deviceIdentification);

    final DeviceResponseHandler deviceResponseHandler = new DeviceResponseHandler() {

        @Override
        public void handleResponse(final DeviceResponse deviceResponse) {
            PublicLightingSetTransitionRequestMessageProcessor.this.handleEmptyDeviceResponse(deviceResponse,
                    PublicLightingSetTransitionRequestMessageProcessor.this.responseMessageSender,
                    requestMessageData.getDomain(), requestMessageData.getDomainVersion(),
                    requestMessageData.getMessageType(), requestMessageData.getRetryCount());
        }

        @Override
        public void handleException(final Throwable t, final DeviceResponse deviceResponse,
                final boolean expected) {

            if (expected) {
                PublicLightingSetTransitionRequestMessageProcessor.this.handleExpectedError(
                        new ConnectionFailureException(ComponentType.PROTOCOL_IEC61850, t.getMessage()),
                        requestMessageData.getCorrelationUid(),
                        requestMessageData.getOrganisationIdentification(),
                        requestMessageData.getDeviceIdentification(), requestMessageData.getDomain(),
                        requestMessageData.getDomainVersion(), requestMessageData.getMessageType());
            } else {
                PublicLightingSetTransitionRequestMessageProcessor.this.handleUnExpectedError(deviceResponse, t,
                        requestMessageData.getMessageData(), requestMessageData.getDomain(),
                        requestMessageData.getDomainVersion(), requestMessageData.getMessageType(),
                        requestMessageData.isScheduled(), requestMessageData.getRetryCount());
            }
        }
    };

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

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

    this.deviceService.setTransition(deviceRequest, deviceResponseHandler);
}

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 . j  av a 2  s. com*/
            "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.adhocmanagement.SetTransitionSteps.java

@DomainStep("a set transition response message with correlationId (.*), deviceId (.*), qresult (.*) and qdescription (.*) is found in the queue (.*)")
public void givenASetTransitionResponseMessageIsFoundInTheQueue(final String correlationId,
        final String deviceId, final String qresult, final String qdescription, final Boolean isFound) {
    LOGGER.info(//from ww  w .j  ava2s.c  om
            "GIVEN: \"a set transition 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) {
            LOGGER.error("JMSException", e);
        }

        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.schedulemanagement.SetTariffScheduleSteps.java

@DomainStep("a set tariff schedule response message with correlationId (.*), deviceId (.*), qresult (.*) and qdescription (.*) is found in the queue (.*)")
public void givenATariffScheduleLightResponseMessageIsFoundInTheQueue(final String correlationId,
        final String deviceId, final String qresult, final String qdescription, final Boolean isFound) {
    LOGGER.info(//ww  w  .jav  a2 s. c o  m
            "GIVEN: \"a set tariff schedule 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, null,
                        new ValidationException());
                exception = (OsgpException) dataObject;
            }
            final ResponseMessage message = new ResponseMessage(correlationId, ORGANISATION_ID, deviceId,
                    ResponseMessageResultType.valueOf(qresult), exception, dataObject);
            when(messageMock.getObject()).thenReturn(message);
        } catch (final JMSException e) {
            LOGGER.error("JMSException", e);
        }

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

From source file:com.alliander.osgp.acceptancetests.devicemanagement.SetEventNotificationsSteps.java

@DomainStep("a set event notifications response message with correlationId (.*), deviceId (.*), qresult (.*) and qdescription (.*) is found in the queue (.*)")
public void givenASetEventNotificationsResponseMessageIsFoundInTheQueue(final String correlationId,
        final String deviceId, final String qresult, final String qdescription, final Boolean isFound) {
    LOGGER.info(//from w  w  w  .ja  v  a  2  s.c o m
            "GIVEN: \"a set event notifications 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_OWNER);
            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_OWNER, deviceId,
                    result, exception, dataObject);
            when(messageMock.getObject()).thenReturn(message);
        } catch (final JMSException e) {
            LOGGER.error("given a set event notifications response", 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.schedulemanagement.SetScheduleSteps.java

@DomainStep("a set schedule response message with correlationId (.*), deviceId (.*), qresult (.*) and qdescription (.*) is found in the queue (.*)")
public void givenAScheduleLightResponseMessageIsFoundInTheQueue(final String correlationId,
        final String deviceId, final String qresult, final String qdescription, final Boolean isFound) {
    LOGGER.info(// w  w w .j  a  va  2  s  . c o m
            "GIVEN: \"a set schedule 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, null,
                        new ValidationException());
                exception = (OsgpException) dataObject;
            }
            final ResponseMessage message = new ResponseMessage(correlationId, ORGANISATION_ID, deviceId,
                    ResponseMessageResultType.valueOf(qresult), 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.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(// w  ww  . j a va  2  s .  com
            "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(//  ww  w. j a  v  a 2s.  c om
            "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(/*  www.j a va2  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);
    }
}