Search in sources :

Example 66 with ObjectMessage

use of javax.jms.ObjectMessage in project Protocol-Adapter-OSLP by OSGP.

the class DeviceRequestMessageListener method onMessage.

@Override
public void onMessage(final Message message) {
    final ObjectMessage objectMessage = (ObjectMessage) message;
    String messageType = null;
    try {
        messageType = message.getJMSType();
        LOGGER.info("Received message of type: {}", messageType);
        final MessageProcessor processor = this.oslpRequestMessageProcessorMap.getMessageProcessor(objectMessage);
        processor.processMessage(objectMessage);
    } catch (final JMSException ex) {
        LOGGER.error("Unexpected JMSException during onMessage(Message)", ex);
        this.sendException(objectMessage, ex, "JMSException while processing message");
    } catch (final IllegalArgumentException e) {
        LOGGER.error("Unexpected IllegalArgumentException during onMessage(Message)", e);
        this.sendException(objectMessage, new NotSupportedException(ComponentType.PROTOCOL_OSLP, messageType), "Unsupported device function: " + messageType);
    }
}
Also used : ObjectMessage(javax.jms.ObjectMessage) MessageProcessor(com.alliander.osgp.shared.infra.jms.MessageProcessor) JMSException(javax.jms.JMSException) NotSupportedException(com.alliander.osgp.shared.exceptionhandling.NotSupportedException)

Example 67 with ObjectMessage

use of javax.jms.ObjectMessage 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 68 with ObjectMessage

use of javax.jms.ObjectMessage in project Protocol-Adapter-OSLP by OSGP.

the class OslpLogItemRequestMessageSender method send.

public void send(final OslpLogItemRequestMessage oslpLogItemRequestMessage) {
    LOGGER.debug("Sending OslpLogItemRequestMessage");
    this.oslpLogItemRequestsJmsTemplate.send(new MessageCreator() {

        @Override
        public Message createMessage(final Session session) throws JMSException {
            final ObjectMessage objectMessage = session.createObjectMessage();
            objectMessage.setJMSType(Constants.OSLP_LOG_ITEM_REQUEST);
            objectMessage.setStringProperty(Constants.IS_INCOMING, oslpLogItemRequestMessage.isIncoming().toString());
            objectMessage.setStringProperty(Constants.DEVICE_UID, oslpLogItemRequestMessage.getDeviceUid());
            objectMessage.setStringProperty(Constants.ENCODED_MESSAGE, oslpLogItemRequestMessage.getEncodedMessage());
            objectMessage.setStringProperty(Constants.DECODED_MESSAGE, oslpLogItemRequestMessage.getDecodedMessage());
            objectMessage.setStringProperty(Constants.DEVICE_IDENTIFICATION, oslpLogItemRequestMessage.getDeviceIdentification());
            objectMessage.setStringProperty(Constants.ORGANISATION_IDENTIFICATION, oslpLogItemRequestMessage.getOrganisationIdentification());
            objectMessage.setStringProperty(Constants.IS_VALID, oslpLogItemRequestMessage.isValid().toString());
            objectMessage.setIntProperty(Constants.PAYLOAD_MESSAGE_SERIALIZED_SIZE, oslpLogItemRequestMessage.getPayloadMessageSerializedSize());
            return objectMessage;
        }
    });
}
Also used : ObjectMessage(javax.jms.ObjectMessage) Message(javax.jms.Message) ObjectMessage(javax.jms.ObjectMessage) JMSException(javax.jms.JMSException) MessageCreator(org.springframework.jms.core.MessageCreator) Session(javax.jms.Session)

Example 69 with ObjectMessage

use of javax.jms.ObjectMessage in project Protocol-Adapter-OSLP by OSGP.

the class SigningServerRequestMessageListener method onMessage.

@Override
public void onMessage(final Message message) {
    try {
        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);
    }
}
Also used : Destination(javax.jms.Destination) UnsignedOslpEnvelopeDto(com.alliander.osgp.oslp.UnsignedOslpEnvelopeDto) ObjectMessage(javax.jms.ObjectMessage) RequestMessage(com.alliander.osgp.shared.infra.jms.RequestMessage) JMSException(javax.jms.JMSException)

Example 70 with ObjectMessage

use of javax.jms.ObjectMessage in project cayenne by apache.

the class JMSBridge method onMessage.

/**
 * JMS MessageListener implementation. Injects received events to the EventManager
 * local event queue.
 */
public void onMessage(Message message) {
    try {
        Object vmID = message.getObjectProperty(JMSBridge.VM_ID_PROPERTY);
        if (JMSBridge.VM_ID.equals(vmID)) {
            return;
        }
        if (!(message instanceof ObjectMessage)) {
            return;
        }
        ObjectMessage objectMessage = (ObjectMessage) message;
        CayenneEvent event = messageObjectToEvent(objectMessage.getObject());
        if (event != null) {
            onExternalEvent(event);
        }
    } catch (MessageFormatException mfex) {
    // TODO: Andrus, 2/8/2006 logging... Log4J was removed to make this usable on
    // the client
    } catch (Exception ex) {
    // TODO: Andrus, 2/8/2006 logging... Log4J was removed to make this usable on
    // the client
    }
}
Also used : MessageFormatException(javax.jms.MessageFormatException) ObjectMessage(javax.jms.ObjectMessage) NamingException(javax.naming.NamingException) MessageFormatException(javax.jms.MessageFormatException) NameNotFoundException(javax.naming.NameNotFoundException)

Aggregations

ObjectMessage (javax.jms.ObjectMessage)71 JMSException (javax.jms.JMSException)29 Message (javax.jms.Message)24 Session (javax.jms.Session)18 Test (org.junit.Test)18 TextMessage (javax.jms.TextMessage)14 Serializable (java.io.Serializable)11 Destination (javax.jms.Destination)11 Map (java.util.Map)10 BytesMessage (javax.jms.BytesMessage)10 MapMessage (javax.jms.MapMessage)9 MessageProducer (javax.jms.MessageProducer)8 MessageConsumer (javax.jms.MessageConsumer)7 TreeMap (java.util.TreeMap)6 MessageCreator (org.springframework.jms.core.MessageCreator)5 DataNode (com.odysseusinc.arachne.portal.model.DataNode)4 HashMap (java.util.HashMap)4 CountDownLatch (java.util.concurrent.CountDownLatch)4 RequestMessage (com.alliander.osgp.shared.infra.jms.RequestMessage)3 ConsumerTemplate (com.odysseusinc.arachne.commons.service.messaging.ConsumerTemplate)3