Search in sources :

Example 96 with ObjectMessage

use of javax.jms.ObjectMessage in project ArachneCentralAPI by OHDSI.

the class BaseDataNodeMessagingController method saveCommonEntity.

private void saveCommonEntity(Principal principal, String id, Serializable object) throws PermissionDeniedException {
    DataNode dataNode = getDatanode(principal);
    String queueBase = MessagingUtils.Entities.getBaseQueue(dataNode);
    String responseQueue = getResponseQueueName(queueBase);
    jmsTemplate.send(responseQueue, session -> {
        ObjectMessage message = session.createObjectMessage(object);
        message.setJMSCorrelationID(id);
        return message;
    });
}
Also used : DataNode(com.odysseusinc.arachne.portal.model.DataNode) ObjectMessage(javax.jms.ObjectMessage)

Example 97 with ObjectMessage

use of javax.jms.ObjectMessage in project ArachneCentralAPI by OHDSI.

the class BaseDataNodeMessagingController method saveListResponse.

/**
 * Posts responses for for CommonEntity list requests
 * (for pushing by Node's back)
 */
@ApiOperation("Posts responses for for CommonEntity list requests")
@RequestMapping(value = "/api/v1/data-nodes/entity-lists/responses", method = POST)
public void saveListResponse(@RequestBody @Valid CommonListEntityResponseDTO commonListEntityResponseDTO, Principal principal) throws PermissionDeniedException {
    DataNode dataNode = getDatanode(principal);
    String responseQueue = getResponseQueueName(MessagingUtils.EntitiesList.getBaseQueue(dataNode));
    List<CommonEntityDTO> response = (List<CommonEntityDTO>) commonListEntityResponseDTO.getEntities();
    for (String correlationId : commonListEntityResponseDTO.getRequestIds()) {
        jmsTemplate.send(responseQueue, session -> {
            ObjectMessage message = session.createObjectMessage((Serializable) response);
            message.setJMSCorrelationID(correlationId);
            return message;
        });
    }
}
Also used : DataNode(com.odysseusinc.arachne.portal.model.DataNode) ObjectMessage(javax.jms.ObjectMessage) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) CommonEntityDTO(com.odysseusinc.arachne.commons.api.v1.dto.CommonEntityDTO) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 98 with ObjectMessage

use of javax.jms.ObjectMessage in project qpid-broker-j by apache.

the class ObjectMessageClassAllowlistingTest method doTestAllowListedEnclosedClassTest.

private void doTestAllowListedEnclosedClassTest(Connection c, Serializable content) throws Exception {
    Queue destination = createQueue(getTestName());
    c.start();
    Session s = c.createSession(false, Session.AUTO_ACKNOWLEDGE);
    MessageConsumer consumer = s.createConsumer(destination);
    MessageProducer producer = s.createProducer(destination);
    final ObjectMessage sendMessage = s.createObjectMessage();
    sendMessage.setObject(content);
    producer.send(sendMessage);
    Message receivedMessage = consumer.receive(getReceiveTimeout());
    assertNotNull("did not receive message within receive timeout", receivedMessage);
    assertTrue("message is of wrong type", receivedMessage instanceof ObjectMessage);
    Object receivedObject = ((ObjectMessage) receivedMessage).getObject();
    assertEquals("Received object has unexpected class", content.getClass(), receivedObject.getClass());
    assertEquals("Received object has unexpected content", content, receivedObject);
}
Also used : MessageConsumer(javax.jms.MessageConsumer) ObjectMessage(javax.jms.ObjectMessage) Message(javax.jms.Message) ObjectMessage(javax.jms.ObjectMessage) MessageProducer(javax.jms.MessageProducer) Queue(javax.jms.Queue) Session(javax.jms.Session)

Example 99 with ObjectMessage

use of javax.jms.ObjectMessage in project qpid-broker-j by apache.

the class ObjectMessageClassAllowlistingTest method testDenyListedClassByConnectionUrlObjectMessage.

@Test
public void testDenyListedClassByConnectionUrlObjectMessage() throws Exception {
    Queue destination = createQueue(getTestName());
    final Connection c = getConnectionBuilder().setDeserializationPolicyAllowList("java").setDeserializationPolicyDenyList("java.lang.Integer").build();
    try {
        c.start();
        Session s = c.createSession(false, Session.AUTO_ACKNOWLEDGE);
        MessageConsumer consumer = s.createConsumer(destination);
        MessageProducer producer = s.createProducer(destination);
        sendTestObjectMessage(s, producer);
        Message receivedMessage = consumer.receive(getReceiveTimeout());
        assertNotNull("did not receive message within receive timeout", receivedMessage);
        assertTrue("message is of wrong type", receivedMessage instanceof ObjectMessage);
        ObjectMessage receivedObjectMessage = (ObjectMessage) receivedMessage;
        try {
            receivedObjectMessage.getObject();
            fail("Should not be allowed to deserialize black listed class");
        } catch (JMSException e) {
        // pass
        }
    } finally {
        c.close();
    }
}
Also used : MessageConsumer(javax.jms.MessageConsumer) ObjectMessage(javax.jms.ObjectMessage) Message(javax.jms.Message) ObjectMessage(javax.jms.ObjectMessage) Connection(javax.jms.Connection) JMSException(javax.jms.JMSException) MessageProducer(javax.jms.MessageProducer) Queue(javax.jms.Queue) Session(javax.jms.Session) Test(org.junit.Test)

Example 100 with ObjectMessage

use of javax.jms.ObjectMessage in project qpid-broker-j by apache.

the class ObjectMessageClassAllowlistingTest method sendTestObjectMessage.

private void sendTestObjectMessage(final Session s, final MessageProducer producer) throws JMSException {
    HashMap<String, Integer> messageContent = new HashMap<>();
    messageContent.put("value", TEST_VALUE);
    Message objectMessage = s.createObjectMessage(messageContent);
    producer.send(objectMessage);
}
Also used : ObjectMessage(javax.jms.ObjectMessage) Message(javax.jms.Message) HashMap(java.util.HashMap)

Aggregations

ObjectMessage (javax.jms.ObjectMessage)227 Test (org.junit.Test)85 JMSException (javax.jms.JMSException)82 Session (javax.jms.Session)79 Message (javax.jms.Message)70 MessageProducer (javax.jms.MessageProducer)64 MessageConsumer (javax.jms.MessageConsumer)52 Connection (javax.jms.Connection)46 Queue (javax.jms.Queue)40 TextMessage (javax.jms.TextMessage)38 BytesMessage (javax.jms.BytesMessage)30 Destination (javax.jms.Destination)29 MapMessage (javax.jms.MapMessage)28 AbstractServiceComponentAgentFunctionalIntegrationTest (com.hack23.cia.service.component.agent.impl.AbstractServiceComponentAgentFunctionalIntegrationTest)25 StreamMessage (javax.jms.StreamMessage)21 HashMap (java.util.HashMap)18 Serializable (java.io.Serializable)17 Map (java.util.Map)16 ArrayList (java.util.ArrayList)13 QueueSession (javax.jms.QueueSession)11