Example usage for javax.jms ObjectMessage propertyExists

List of usage examples for javax.jms ObjectMessage propertyExists

Introduction

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

Prototype


boolean propertyExists(String name) throws JMSException;

Source Link

Document

Indicates whether a property value exists.

Usage

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

@Override
public void processMessage(final ObjectMessage message) {
    LOGGER.debug("Processing public lighting get power usage history request message");

    String correlationUid = null;
    String domain = null;// w ww  .ja  v a2  s  .com
    String domainVersion = null;
    String messageType = null;
    String organisationIdentification = null;
    String deviceIdentification = null;
    String ipAddress = null;
    Boolean isScheduled = null;
    int retryCount = 0;
    final int messagePriority;
    final Long scheduleTime;
    PowerUsageHistoryMessageDataContainerDto powerUsageHistoryMessageDataContainerDto;

    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);
        isScheduled = message.getBooleanProperty(Constants.IS_SCHEDULED);
        retryCount = message.getIntProperty(Constants.RETRY_COUNT);
        messagePriority = message.getJMSPriority();
        scheduleTime = message.propertyExists(Constants.SCHEDULE_TIME)
                ? message.getLongProperty(Constants.SCHEDULE_TIME)
                : null;
        powerUsageHistoryMessageDataContainerDto = (PowerUsageHistoryMessageDataContainerDto) 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);
        LOGGER.debug("scheduled: {}", isScheduled);
        return;
    }

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

    final DeviceResponseHandler deviceResponseHandler = new DeviceResponseHandler() {

        @Override
        public void handleResponse(final DeviceResponse deviceResponse) {
            PublicLightingGetPowerUsageHistoryRequestMessageProcessor.this
                    .handleGetPowerUsageHistoryDeviceResponse(
                            (GetPowerUsageHistoryDeviceResponse) deviceResponse,
                            PublicLightingGetPowerUsageHistoryRequestMessageProcessor.this.responseMessageSender,
                            requestMessageData.getDomain(), requestMessageData.getDomainVersion(),
                            requestMessageData.getMessageType(), requestMessageData.getRetryCount(),
                            messagePriority, scheduleTime);
        }

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

            if (expected) {
                PublicLightingGetPowerUsageHistoryRequestMessageProcessor.this.handleExpectedError(
                        new ConnectionFailureException(ComponentType.PROTOCOL_IEC61850, t.getMessage()),
                        requestMessageData.getCorrelationUid(),
                        requestMessageData.getOrganisationIdentification(),
                        requestMessageData.getDeviceIdentification(), requestMessageData.getDomain(),
                        requestMessageData.getDomainVersion(), requestMessageData.getMessageType());
            } else {
                PublicLightingGetPowerUsageHistoryRequestMessageProcessor.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 GetPowerUsageHistoryDeviceRequest deviceRequest = new GetPowerUsageHistoryDeviceRequest(
            organisationIdentification, deviceIdentification, correlationUid,
            powerUsageHistoryMessageDataContainerDto, domain, domainVersion, messageType, ipAddress, retryCount,
            isScheduled);

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