List of usage examples for javax.jms ObjectMessage getStringProperty
String getStringProperty(String name) throws JMSException;
From source file:com.alliander.osgp.adapter.protocol.oslp.elster.infra.messaging.DeviceRequestMessageListener.java
private void sendException(final ObjectMessage objectMessage, final Exception exception, final String errorMessage) { try {//w ww . j a v a2 s .c o m final String domain = objectMessage.getStringProperty(Constants.DOMAIN); final String domainVersion = objectMessage.getStringProperty(Constants.DOMAIN_VERSION); final ResponseMessageResultType result = ResponseMessageResultType.NOT_OK; final OsgpException osgpException = new OsgpException(ComponentType.PROTOCOL_OSLP, errorMessage, exception); final Serializable dataObject = objectMessage.getObject(); final DeviceMessageMetadata deviceMessageMetadata = new DeviceMessageMetadata(objectMessage); final ProtocolResponseMessage protocolResponseMessage = new ProtocolResponseMessage.Builder() .deviceMessageMetadata(deviceMessageMetadata).domain(domain).domainVersion(domainVersion) .result(result).osgpException(osgpException).dataObject(dataObject).scheduled(false).build(); this.deviceResponseMessageSender.send(protocolResponseMessage); } catch (final Exception e) { LOGGER.error("Unexpected error during sendException(ObjectMessage, Exception)", e); } }
From source file:com.alliander.osgp.adapter.protocol.iec61850.infra.messaging.DeviceRequestMessageListener.java
private void sendException(final ObjectMessage objectMessage, final Exception exception, final String errorMessage) { try {/*from w w w . j a v a 2s. c o m*/ final String domain = objectMessage.getStringProperty(Constants.DOMAIN); final String domainVersion = objectMessage.getStringProperty(Constants.DOMAIN_VERSION); final ResponseMessageResultType result = ResponseMessageResultType.NOT_OK; final OsgpException osgpException = new OsgpException(ComponentType.PROTOCOL_IEC61850, errorMessage, exception); final Serializable dataObject = objectMessage.getObject(); final DeviceMessageMetadata deviceMessageMetadata = new DeviceMessageMetadata(objectMessage); final ProtocolResponseMessage protocolResponseMessage = new ProtocolResponseMessage.Builder() .deviceMessageMetadata(deviceMessageMetadata).domain(domain).domainVersion(domainVersion) .result(result).osgpException(osgpException).dataObject(dataObject).scheduled(false).build(); this.deviceResponseMessageSender.send(protocolResponseMessage); } catch (final Exception e) { LOGGER.error("Unexpected error during sendException(ObjectMessage, Exception)", e); } }
From source file:org.apache.servicemix.audit.async.AbstractJmsExchangeListener.java
public void afterPropertiesSet() throws Exception { if (factory == null) { throw new IllegalStateException( "Unable to initialize JMS ExchangeListener -- no ConnectionFactory set"); }// www. j ava2s . c om container = new DefaultMessageListenerContainer(); container.setConnectionFactory(factory); container.setDestinationName(getDestinationName()); container.setMessageListener(new MessageListener() { @SuppressWarnings("unchecked") public void onMessage(Message message) { ObjectMessage om = (ObjectMessage) message; try { T object = (T) om.getObject(); switch (Event.valueOf(om.getStringProperty(EVENT))) { case Sent: onSent(object); case Accepted: onAccepted(object); } } catch (JMSException e) { e.printStackTrace(); } } }); container.afterPropertiesSet(); container.setConcurrentConsumers(10); container.start(); jmsTemplate = new JmsTemplate(factory); jmsTemplate.setDefaultDestinationName(getDestinationName()); }
From source file:com.alliander.osgp.adapter.protocol.oslp.elster.infra.messaging.SigningServerResponsesMessageListener.java
@Override public void onMessage(final Message message) { try {//from w w w .j a v a 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.chakray.chilcano.wso2.rabbitmq.message.store.RabbitMQConsumer.java
public MessageContext receive() { boolean error; JMSException exception;//from w w w. java 2 s . c o m if (!checkConnection()) { if (!reconnect()) { if (logger.isDebugEnabled()) { logger.debug(getId() + " cannot receive message from store. Cannot reconnect."); } return null; } else { logger.info(getId() + " reconnected to store."); isReceiveError = false; } } if (!checkConnection()) { if (logger.isDebugEnabled()) { logger.debug(getId() + " cannot receive message from store."); } return null; } try { Message message = consumer.receive(3000); if (message == null) { return null; } if (!(message instanceof ObjectMessage)) { logger.warn(getId() + ". Did not receive a javax.jms.ObjectMessage"); message.acknowledge(); // TODO: return null; } ObjectMessage msg = (ObjectMessage) message; String messageId = msg.getStringProperty(Constants.OriginalMessageID); if (!(msg.getObject() instanceof StorableMessage)) { logger.warn(getId() + ". Did not receive a valid message."); message.acknowledge(); return null; } StorableMessage storableMessage = (StorableMessage) msg.getObject(); org.apache.axis2.context.MessageContext axis2Mc = store.newAxis2Mc(); MessageContext synapseMc = store.newSynapseMc(axis2Mc); synapseMc = MessageConverter.toMessageContext(storableMessage, axis2Mc, synapseMc); updateCache(message, synapseMc, messageId, false); if (logger.isDebugEnabled()) { logger.debug( getId() + " Received MessageId:" + messageId + " priority:" + message.getJMSPriority()); } return synapseMc; } catch (JMSException e) { error = true; exception = e; } if (error) { if (!isReceiveError) { logger.error( getId() + " cannot receive message from store. Error:" + exception.getLocalizedMessage());//, exception); } updateCache(null, null, "", true); cleanup(); return null; } return null; }
From source file:org.yestech.publish.service.JmsQueuePublishConsumer.java
public void onMessage(Message message) { if (message instanceof ObjectMessage) { ObjectMessage objMessage = (ObjectMessage) message; String fileLocation = ""; try {//from w ww . j av a 2 s . c o m IArtifact artifact = translateArtifact((IArtifact) objMessage.getObject()); if (PublishUtils.isFileArtifact(artifact)) { IFileArtifact fileArtifact = (IFileArtifact) artifact; String url = objMessage.getStringProperty(IPublishConstant.URL); String fileName = objMessage.getStringProperty(IPublishConstant.FILE_NAME); fileLocation = url + fileName; URL artifactUrl = new URL(fileLocation); String fqn = PublishUtils.saveTempFile(tempDirectory, artifactUrl.openStream(), fileArtifact); recieve(fileArtifact); PublishUtils.removeTempFile(fqn); } else { recieve(artifact); } } catch (Exception e) { logger.error("error retrieving artifact...", e); } } }
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;//ww w . j a v a 2s. 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; } 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;// w ww .j a v a 2 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; } 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 w w w .j a va2s . c o 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.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 . j a v a 2 s .c om "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); } }