Example usage for javax.jms TextMessage getJMSCorrelationID

List of usage examples for javax.jms TextMessage getJMSCorrelationID

Introduction

In this page you can find the example usage for javax.jms TextMessage getJMSCorrelationID.

Prototype


String getJMSCorrelationID() throws JMSException;

Source Link

Document

Gets the correlation ID for the message.

Usage

From source file:eu.europa.ec.fisheries.uvms.spatial.service.bean.impl.SpatialUserServiceBean.java

private static void validateResponse(TextMessage response, String correlationId)
        throws SpatialModelValidationException {

    try {//from  ww w .  j  a  v  a2s  .  c  o  m
        if (response == null) {
            throw new SpatialModelValidationException(
                    "Error when validating response in ResponseMapper: Response is Null");
        }

        if (response.getJMSCorrelationID() == null) {
            throw new SpatialModelValidationException(
                    "No correlationId in response (Null) . Expected was: " + correlationId);
        }

        if (!correlationId.equalsIgnoreCase(response.getJMSCorrelationID())) {
            throw new SpatialModelValidationException("Wrong correlationId in response. Expected was: "
                    + correlationId + " But actual was: " + response.getJMSCorrelationID());
        }

        try {
            Fault fault = JAXBUtils.unMarshallMessage(response.getText(), Fault.class);
            throw new SpatialModelValidationException(fault.getCode() + " : " + fault.getFault());
        } catch (JAXBException e) {
            log.info("Expected Exception"); // Exception received in case if the validation is success
        }

    } catch (JMSException e) {
        log.error("JMS exception during validation ", e);
        throw new SpatialModelValidationException("JMS exception during validation " + e.getMessage());
    }
}

From source file:com.oneops.controller.jms.InductorListenerTest.java

@Test
/** test with message where JMSException is forced to happend
 * but we effectively are asserting it must get swallowed*/
public void testBadMessage() throws JMSException {
    TextMessage message = mock(TextMessage.class);
    when(message.getJMSCorrelationID()).thenThrow(new JMSException("mock-force"));
    listener.onMessage(message);/*from   w ww. j  a  va  2  s .  c  o  m*/
}

From source file:com.oneops.controller.jms.CmsListenerTest.java

@Test
public void msgOpsProcedure() throws Exception {
    TextMessage message = mock(TextMessage.class);
    when(message.getStringProperty("source")).thenReturn("opsprocedure");
    when(message.getJMSCorrelationID()).thenReturn(null);

    String msgJson = gson.toJson(createCmsOpsProcedure(OpsProcedureState.active));
    when(message.getText()).thenReturn(msgJson);

    listener.onMessage(message);/* w w w .ja  va2 s  . c  o  m*/
    //once more to get a SKIP
    when(message.getText()).thenReturn(gson.toJson(createCmsOpsProcedure(OpsProcedureState.discarded)));
    listener.onMessage(message);
}

From source file:org.fatal1t.forexapp.spring.api.adapters.SyncListener.java

@JmsListener(destination = "forex.sync.listener.connector.request", containerFactory = "myJmsContainerFactory")
public void receiveMessage(TextMessage message) throws JMSException {
    log.info("Source Queue: " + message.getJMSDestination().toString());
    log.info("Target Queue: " + message.getJMSReplyTo().toString());
    log.info("Received:" + message.getJMSCorrelationID() + " " + message.getJMSType() + " <"
            + message.getText().substring(0, 50) + ">");
    initiateAdapter();/*from w w w. j  a  v a2  s  .c om*/
    if (!initiateAdapter()) {
        log.info("pruser s adapterem");
        sendMessage("Error in adapter setting, cant login", message.getJMSCorrelationID(),
                message.getJMSReplyTo());
    }
    XStream xs = new XStream();
    Object o = xs.fromXML(message.getText());
    System.out.println(message.getText());
    switch (message.getJMSType()) {
    case "GetUserData": {
        GetUserDataResp APIResponse = this.APIAdapter.GetUserData();
        sendMessage(xs.toXML(APIResponse), message.getJMSCorrelationID(), message.getJMSReplyTo());
        break;
    }
    case "GetAllSymbols": {
        GetAllSymbolsResp APIResp = this.APIAdapter.GetAllSymbols();
        sendMessage(xs.toXML(APIResp), message.getJMSCorrelationID(), message.getJMSReplyTo());
        break;
    }
    case "GetTradingHours": {
        GetTradingHoursResp APIResp = this.APIAdapter.GetTradingHours((GetTradingHoursReq) o);
        sendMessage(xs.toXML(APIResp), message.getJMSCorrelationID(), message.getJMSReplyTo());
        break;
    }
    case "GetCandlesHistory": {
        GetCandlesHistoryReq request = (GetCandlesHistoryReq) o;
        GetCandlesHistoryResp response = new GetCandlesHistoryResp();
        request.getRequestList().forEach((CandlesRange range) -> {
            GetCandlesRangeResp APIResp = this.APIAdapter.getCandlesRange(request.getSymbol(), range);
            response.getRecords().put(range.getId(), APIResp.getRecords());
        });
        sendMessage(xs.toXML(response), message.getJMSCorrelationID(), message.getJMSReplyTo());
        break;
    }
    }
}

From source file:com.oneops.controller.jms.InductorListener.java

private void processResponseMessage(TextMessage msg) throws JMSException {
    String corelationId = msg.getJMSCorrelationID();
    if (corelationId == null) {
        corelationId = msg.getStringProperty("task_id");
    }//  ww  w.  j  a va2s. com
    String[] props = corelationId.split("!");
    String processId = props[0];
    String executionId = props[1];
    //String taskName = props[2];

    String woTaskResult = msg.getStringProperty("task_result_code");
    logger.debug("Inductor responce >>>>>>" + ((TextMessage) msg).getText());

    String type = msg.getStringProperty("type");
    Map<String, Object> params = new HashMap<String, Object>();

    logger.info("Got inductor response with JMSCorrelationID: " + corelationId + " result " + woTaskResult);

    CmsWorkOrderSimpleBase wo = null;
    CmsWorkOrderSimple strippedWo = null;

    if ("opsprocedure".equalsIgnoreCase(type)) {
        wo = gson.fromJson(((TextMessage) msg).getText(), CmsActionOrderSimple.class);
        logger.info("Action ci_id = " + ((CmsActionOrderSimple) wo).getCiId());
    } else if ("deploybom".equalsIgnoreCase(type)) {
        wo = gson.fromJson(((TextMessage) msg).getText(), CmsWorkOrderSimple.class);
        strippedWo = controllerUtil.stripWO((CmsWorkOrderSimple) wo);
        if (woTaskResult.equalsIgnoreCase("200")) {
            try {
                sensorClient.processMonitors((CmsWorkOrderSimple) wo);
            } catch (SensorClientException e) {
                logger.error(e);
                e.printStackTrace();
            }
        }
        logger.info("WorkOrder rfc_id = " + ((CmsWorkOrderSimple) wo).getRfcId());
    } else {
        throw new JMSException("the type property of the received msg is uknown - " + type);
    }

    if (strippedWo != null) {
        params.put("wo", strippedWo);
    } else {
        params.put("wo", wo);
    }

    if (woTaskResult.equalsIgnoreCase("200")) {
        params.put("wostate", "complete");
    } else {
        params.put("wostate", "failed");
    }

    setWoTimeStamps(wo);

    String woCorelationId = processId + executionId;
    wfController.pokeSubProcess(processId, executionId, params);
    woPublisher.publishMessage(wo, type, woCorelationId);

}

From source file:com.adaptris.core.jms.MetadataCorrelationIdSourceTest.java

public void testAdaptrisMessageMetadataToJmsCorrelationId_EmptyValue() throws Exception {
    EmbeddedActiveMq broker = new EmbeddedActiveMq();
    JmsConnection conn = broker.getJmsConnection();
    try {//from   ww w .j a va 2  s . c  o  m
        broker.start();
        start(conn);
        Session session = conn.createSession(false, Session.CLIENT_ACKNOWLEDGE);
        AdaptrisMessage adpMsg = AdaptrisMessageFactory.getDefaultInstance().newMessage(TEXT);
        adpMsg.addMetadata(CORRELATIONID_KEY, "");
        TextMessage jmsMsg = session.createTextMessage();
        MetadataCorrelationIdSource mcs = new MetadataCorrelationIdSource(CORRELATIONID_KEY);
        mcs.processCorrelationId(adpMsg, jmsMsg);
        assertTrue(StringUtils.isEmpty(jmsMsg.getJMSCorrelationID()));
        session.close();
    } finally {
        stop(conn);
        broker.destroy();
    }
}

From source file:com.adaptris.core.jms.MetadataCorrelationIdSourceTest.java

public void testAdaptrisMessageMetadataToJmsCorrelationId_NoMetadataKey() throws Exception {
    EmbeddedActiveMq broker = new EmbeddedActiveMq();
    JmsConnection conn = broker.getJmsConnection();
    try {//from  w  ww . ja v a2s.  com
        broker.start();
        start(conn);
        Session session = conn.createSession(false, Session.CLIENT_ACKNOWLEDGE);
        AdaptrisMessage adpMsg = AdaptrisMessageFactory.getDefaultInstance().newMessage(TEXT);
        adpMsg.addMetadata(CORRELATIONID_KEY, TEXT2);
        TextMessage jmsMsg = session.createTextMessage();
        MetadataCorrelationIdSource mcs = new MetadataCorrelationIdSource();
        mcs.processCorrelationId(adpMsg, jmsMsg);
        assertNotSame(adpMsg.getMetadataValue(CORRELATIONID_KEY), jmsMsg.getJMSCorrelationID());
        session.close();
    } finally {
        stop(conn);
        broker.destroy();
    }
}

From source file:com.adaptris.core.jms.MetadataCorrelationIdSourceTest.java

public void testJmsCorrelationIdToAdaptrisMessageMetadata_NoMetadataKey() throws Exception {
    EmbeddedActiveMq broker = new EmbeddedActiveMq();
    JmsConnection conn = broker.getJmsConnection();
    try {//  www . j  a  v a2 s  . c om
        broker.start();
        start(conn);
        Session session = conn.createSession(false, Session.CLIENT_ACKNOWLEDGE);
        AdaptrisMessage adpMsg = AdaptrisMessageFactory.getDefaultInstance().newMessage(TEXT);
        TextMessage jmsMsg = session.createTextMessage();
        jmsMsg.setJMSCorrelationID(TEXT2);
        MetadataCorrelationIdSource mcs = new MetadataCorrelationIdSource();
        mcs.processCorrelationId(jmsMsg, adpMsg);
        assertNotSame(jmsMsg.getJMSCorrelationID(), adpMsg.getMetadataValue(CORRELATIONID_KEY));
        session.close();
    } finally {
        stop(conn);
        broker.destroy();
    }
}

From source file:com.adaptris.core.jms.MetadataCorrelationIdSourceTest.java

public void testAdaptrisMessageMetadataToJmsCorrelationId() throws Exception {

    EmbeddedActiveMq broker = new EmbeddedActiveMq();
    JmsConnection conn = broker.getJmsConnection();
    try {//from  ww  w . j  a  v  a 2  s. c  om
        broker.start();
        start(conn);
        Session session = conn.createSession(false, Session.CLIENT_ACKNOWLEDGE);
        AdaptrisMessage adpMsg = AdaptrisMessageFactory.getDefaultInstance().newMessage(TEXT);
        adpMsg.addMetadata(CORRELATIONID_KEY, TEXT2);
        TextMessage jmsMsg = session.createTextMessage();
        MetadataCorrelationIdSource mcs = new MetadataCorrelationIdSource(CORRELATIONID_KEY);
        mcs.processCorrelationId(adpMsg, jmsMsg);
        assertEquals(adpMsg.getMetadataValue(CORRELATIONID_KEY), jmsMsg.getJMSCorrelationID());
        session.close();
    } finally {
        stop(conn);
        broker.destroy();
    }
}

From source file:com.oneops.controller.jms.InductorListenerTest.java

@Test
/** test the message impl */
public void testListening() throws JMSException {
    try {/*  ww  w .j  av a  2s .  c o  m*/
        listener.init();

        TextMessage message = mock(TextMessage.class);
        when(message.getText()).thenReturn("{messgetext:true}");
        when(message.getStringProperty("task_id")).thenReturn("corel-id");
        when(message.getStringProperty("task_result_code")).thenReturn("200");
        when(message.getStringProperty("type")).thenReturn("deploybom");
        when(message.getJMSCorrelationID()).thenReturn("jms|cor!rel!ation!id");

        listener.onMessage(message);
        listener.cleanup();
        listener.getConnectionStats();
    } catch (JMSException e) {
        System.out.println("CAUTH EXCEPTION " + e.getMessage());
        e.printStackTrace();
        throw e;
    }

}