Example usage for org.apache.commons.lang ObjectUtils toString

List of usage examples for org.apache.commons.lang ObjectUtils toString

Introduction

In this page you can find the example usage for org.apache.commons.lang ObjectUtils toString.

Prototype

public static String toString(Object obj) 

Source Link

Document

Gets the toString of an Object returning an empty string ("") if null input.

 ObjectUtils.toString(null)         = "" ObjectUtils.toString("")           = "" ObjectUtils.toString("bat")        = "bat" ObjectUtils.toString(Boolean.TRUE) = "true" 

Usage

From source file:org.marketcetera.client.ClientImpl.java

void exceptionThrown(ConnectionException inException) {
    synchronized (mExceptionListeners) {
        for (ExceptionListener l : mExceptionListeners) {
            try {
                l.exceptionThrown(inException);
            } catch (Exception e) {
                Messages.LOG_ERROR_NOTIFY_EXCEPTION.warn(this, e, ObjectUtils.toString(inException));
                ExceptUtils.interrupt(e);
            }// w w  w.  j  a va2 s.c  o  m
        }
    }
}

From source file:org.marketcetera.client.ClientImpl.java

private void convertAndSend(Order inOrder) throws ConnectionException {
    ThreadedMetric.event("client-OUT", //$NON-NLS-1$ 
            inOrder instanceof OrderBase ? ((OrderBase) inOrder).getOrderID() : null);
    failIfClosed();/*from   w  w  w .ja v  a2s . c o m*/
    SLF4JLoggerProxy.debug(TRAFFIC, "Sending order:{}", inOrder); //$NON-NLS-1$
    try {
        if (mToServer == null) {
            throw new ClientInitException(Messages.NOT_CONNECTED_TO_SERVER);
        }
        failIfDisconnected();
        SpringConfig cfg = SpringConfig.getSingleton();
        Collection<OrderModifier> orderModifiers = cfg.getOrderModifiers();
        for (OrderModifier modifier : orderModifiers) {
            modifier.modify(inOrder);
        }
        mToServer.convertAndSend(new OrderEnvelope(inOrder, getSessionId()));
    } catch (Exception e) {
        ConnectionException exception;
        exception = new ConnectionException(e,
                new I18NBoundMessage1P(Messages.ERROR_SEND_MESSAGE, ObjectUtils.toString(inOrder)));
        Messages.LOG_ERROR_SEND_EXCEPTION.warn(this, exception, ObjectUtils.toString(inOrder));
        ExceptUtils.interrupt(e);
        exceptionThrown(exception);
        throw exception;
    }
}

From source file:org.marketcetera.client.ClientModule.java

@Override
public void receiveData(DataFlowID inFlowID, Object inData) throws ReceiveDataException {
    ThreadedMetric.event("client-IN"); //$NON-NLS-1$
    try {/*  w w  w .ja v a  2s  .co  m*/
        if (inData instanceof OrderSingle) {
            getClient().sendOrder((OrderSingle) inData);
        } else if (inData instanceof OrderCancel) {
            getClient().sendOrder((OrderCancel) inData);
        } else if (inData instanceof OrderReplace) {
            getClient().sendOrder((OrderReplace) inData);
        } else if (inData instanceof FIXOrder) {
            getClient().sendOrderRaw((FIXOrder) inData);
        } else {
            throw new UnsupportedDataTypeException(new I18NBoundMessage2P(Messages.UNSUPPORTED_DATA_TYPE,
                    inFlowID.getValue(), ObjectUtils.toString(inData)));
        }
    } catch (ConnectionException e) {
        throw new ReceiveDataException(e,
                new I18NBoundMessage1P(Messages.SEND_ORDER_FAIL_NO_CONNECT, ObjectUtils.toString(inData)));
    } catch (OrderValidationException e) {
        throw new ReceiveDataException(e, new I18NBoundMessage2P(Messages.SEND_ORDER_VALIDATION_FAILED,
                inFlowID.getValue(), ObjectUtils.toString(inData)));
    } catch (ClientInitException e) {
        throw new StopDataFlowException(e,
                new I18NBoundMessage1P(Messages.SEND_ORDER_FAIL_NO_CONNECT, ObjectUtils.toString(inData)));
    }
}

From source file:org.marketcetera.client.ClientModuleTestBase.java

@Test
public void dataFlowUnsupportedTypeError() throws Exception {
    //test suggestion
    OrderSingleSuggestion errorData = Factory.getInstance().createOrderSingleSuggestion();
    ModuleURN senderURN = mManager.createModule(OrderSenderModuleFactory.PROVIDER_URN, "unsupported",
            new Object[] { errorData, ClientTest.createOrderSingle() });
    BlockingSinkDataListener sink = new BlockingSinkDataListener();
    mManager.addSinkListener(sink);/*from   ww  w . j  av  a 2 s.c  o  m*/
    DataFlowID flowID = mManager.createDataFlow(new DataRequest[] { new DataRequest(senderURN, null),
            new DataRequest(ClientModuleFactory.INSTANCE_URN, null) });
    assertFlowInfo(mManager.getDataFlowInfo(flowID), flowID, 3, true, false, null, null);
    //Wait for sink to receive the report in respose to the order.
    Object data = sink.getNextData();
    assertTrue(data.getClass().getName(), data instanceof ExecutionReport);
    //Sleep for a little while to let the sendMessage() call to the MQ
    //Broker to return back. It's been observed that sometimes we receive
    //execution reports even though the sendMessage() call has not returned.
    //Cancelling the data flow at that point results in the sendMessage()
    //call failing, as it's I/O gets interrupted.
    Thread.sleep(1000);
    //We've received all data, cancel the data flow
    mManager.cancel(flowID);
    assertTrue(mManager.getDataFlows(true).isEmpty());
    List<DataFlowInfo> history = mManager.getDataFlowHistory();
    assertEquals(1, history.size());
    DataFlowInfo info = history.get(0);
    assertFlowInfo(info, flowID, 3, true, true, null, null);
    assertFlowStep(info.getFlowSteps()[0], senderURN, true, 2, 0, null, false, 0, 0, null, null, null);
    assertFlowStep(info.getFlowSteps()[1], ClientModuleFactory.INSTANCE_URN, true, 1, 0, null, true, 2, 1,
            Messages.UNSUPPORTED_DATA_TYPE.getText(flowID, ObjectUtils.toString(errorData)),
            ClientModuleFactory.INSTANCE_URN, null);
    assertFlowStep(info.getFlowSteps()[2], SinkModuleFactory.INSTANCE_URN, false, 0, 0, null, true, 1, 0, null,
            SinkModuleFactory.INSTANCE_URN, null);
    mManager.removeSinkListener(sink);
    mManager.stop(senderURN);
    mManager.deleteModule(senderURN);
}

From source file:org.marketcetera.client.ClientModuleTestBase.java

@Test(timeout = 60000)
public void dataFlowNotInitializedError() throws Exception {
    OrderSingle order = ClientTest.createOrderSingle();
    ModuleURN senderURN = mManager.createModule(OrderSenderModuleFactory.PROVIDER_URN, "clientNotInit",
            new Object[] { Boolean.FALSE, order });
    DataFlowID flowID = mManager.createDataFlow(new DataRequest[] { new DataRequest(senderURN, null),
            new DataRequest(ClientModuleFactory.INSTANCE_URN, null) });
    assertFlowInfo(mManager.getDataFlowInfo(flowID), flowID, 3, true, false, null, null);
    //The data flow should terminate as the client is not initialized
    while (!mManager.getDataFlows(true).isEmpty()) {
        Thread.sleep(1000);// w ww .  jav a  2  s  .c o  m
    }
    List<DataFlowInfo> history = mManager.getDataFlowHistory();
    assertEquals(1, history.size());
    DataFlowInfo info = history.get(0);
    assertFlowInfo(info, flowID, 3, true, true, null, ClientModuleFactory.INSTANCE_URN);
    assertFlowStep(info.getFlowSteps()[0], senderURN, true, 1, 0, null, false, 0, 0, null, null, null);
    assertFlowStep(info.getFlowSteps()[1], ClientModuleFactory.INSTANCE_URN, true, 0, 0, null, true, 1, 1,
            Messages.SEND_ORDER_FAIL_NO_CONNECT.getText(ObjectUtils.toString(order)),
            ClientModuleFactory.INSTANCE_URN, null);
    assertFlowStep(info.getFlowSteps()[2], SinkModuleFactory.INSTANCE_URN, false, 0, 0, null, true, 0, 0, null,
            SinkModuleFactory.INSTANCE_URN, null);
    mManager.stop(senderURN);
    mManager.deleteModule(senderURN);

}

From source file:org.marketcetera.client.jms.JMSMessageConverter.java

/**
 * Converts a JMS Message to a trade message.
 *
 * @param message the received JMS message. It should be of type
 * {@link ObjectMessage}./*from www.j  ava 2  s . co  m*/
 *
 * @return the trade message converted from the supplied JMS message.
 *
 * @throws JMSException if there were errors extracting the contents
 * of the JMS message.
 * @throws MessageConversionException if there were errors converting
 * the contents of the JMS message to a trade message.
 */
@Override
public Object fromMessage(Message message) throws JMSException, MessageConversionException {
    SLF4JLoggerProxy.debug(this, "Converting from JMS {}", message); //$NON-NLS-1$
    if (message instanceof ObjectMessage) {
        Serializable object = ((ObjectMessage) message).getObject();
        if (object instanceof TradeMessage) {
            return object;
        } else {
            throw new MessageConversionException(
                    new I18NBoundMessage1P(Messages.UNEXPECTED_MESSAGE_RECEIVED, ObjectUtils.toString(object))
                            .getText());
        }
    } else {
        throw new MessageConversionException(
                new I18NBoundMessage1P(Messages.UNEXPECTED_MESSAGE_RECEIVED, ObjectUtils.toString(message))
                        .getText());
    }
}

From source file:org.marketcetera.client.jms.JMSMessageConverter.java

/**
 * Converts a trade message to a JMS Message.
 *
 * @param inObject the message to be converted. It should either be
 * an order or a report./*from  w  w  w .j  a  v a2  s  . co m*/
 * @param session the JMS Session instance.
 *
 * @return the JMS message.
 *
 * @throws JMSException if there were errors serializing the
 * trade message.
 * @throws MessageConversionException if the supplied object was not
 * an acceptable trade message.
 */
@Override
public Message toMessage(Object inObject, Session session) throws JMSException, MessageConversionException {
    SLF4JLoggerProxy.debug(this, "Converting to JMS {}", inObject); //$NON-NLS-1$
    if (inObject instanceof TradeMessage) {
        return session.createObjectMessage((Serializable) inObject);
    } else {
        throw new MessageConversionException(
                new I18NBoundMessage1P(Messages.UNEXPECTED_MESSAGE_TO_SEND, ObjectUtils.toString(inObject))
                        .getText());
    }
}

From source file:org.marketcetera.client.jms.JMSXMLMessageConverter.java

/**
 * Converts a JMS Message to a messaging object.
 *
 * @param message the received JMS message. It should be of type
 * {@link javax.jms.ObjectMessage}./*from w w  w  . j  a  va2s  .  c o  m*/
 *
 * @return the messaging object converted from the supplied JMS message.
 *
 * @throws javax.jms.JMSException if there were errors extracting the contents
 * of the JMS message.
 * @throws org.springframework.jms.support.converter.MessageConversionException if there were errors converting
 * the contents of the JMS message to a messaging object.
 */
@Override
public Object fromMessage(Message message) throws JMSException, MessageConversionException {
    SLF4JLoggerProxy.debug(this, "Converting from JMS {}", message); //$NON-NLS-1$
    if (message instanceof TextMessage) {
        Object object = null;
        try {
            object = fromXML(((TextMessage) message).getText());
        } catch (JAXBException e) {
            throw new MessageConversionException(new I18NBoundMessage1P(
                    Messages.ERROR_CONVERTING_MESSAGE_TO_OBJECT, ObjectUtils.toString(object)).getText(), e);
        }
        if ((object instanceof ReportBaseImpl) || (object instanceof FIXResponseImpl)
                || (object instanceof OrderEnvelope) || (object instanceof BrokerStatus)) {
            return object;
        } else {
            throw new MessageConversionException(
                    new I18NBoundMessage1P(Messages.UNEXPECTED_MESSAGE_RECEIVED, ObjectUtils.toString(object))
                            .getText());
        }
    } else {
        throw new MessageConversionException(
                new I18NBoundMessage1P(Messages.UNEXPECTED_MESSAGE_RECEIVED, ObjectUtils.toString(message))
                        .getText());
    }
}

From source file:org.marketcetera.client.jms.JMSXMLMessageConverter.java

/**
 * Converts a messaging object to a JMS Message.
 *
 * @param inObject the message to be converted. It should either be
 * an order or a report.// w  ww  .  j  av a  2  s  .  c  o  m
 * @param session the JMS Session instance.
 *
 * @return the JMS message.
 *
 * @throws javax.jms.JMSException if there were errors serializing the
 * messaging object.
 * @throws org.springframework.jms.support.converter.MessageConversionException if the supplied object was not
 * an acceptable messaging object.
 */
@Override
public Message toMessage(Object inObject, Session session) throws JMSException, MessageConversionException {
    SLF4JLoggerProxy.debug(this, "Converting to JMS {}", inObject); //$NON-NLS-1$
    if ((inObject instanceof ReportBaseImpl) || (inObject instanceof FIXResponseImpl)
            || (inObject instanceof OrderEnvelope) || (inObject instanceof BrokerStatus)) {
        try {
            TextMessage message = session.createTextMessage(toXML(inObject));
            //Set the type property for interoperability with .NET client.
            message.setStringProperty(JMS_TYPE_PROPERTY, inObject.getClass().getSimpleName());
            return message;
        } catch (JAXBException e) {
            throw new MessageConversionException(new I18NBoundMessage1P(
                    Messages.ERROR_CONVERTING_OBJECT_TO_MESSAGE, ObjectUtils.toString(inObject)).getText(), e);
        }
    } else {
        throw new MessageConversionException(
                new I18NBoundMessage1P(Messages.UNEXPECTED_MESSAGE_TO_SEND, ObjectUtils.toString(inObject))
                        .getText());
    }
}

From source file:org.marketcetera.jms.JMSSerMessageConverter.java

/**
 * Converts a JMS Message to an object.//w  w  w .  j a va2  s .com
 *
 * @param message the received JMS message. It should be of type
 * {@link ObjectMessage}.
 *
 * @return the object converted from the supplied JMS message.
 *
 * @throws JMSException if there were errors extracting the contents
 * of the JMS message.
 * @throws MessageConversionException if there were errors converting
 * the contents of the JMS message to an object.
 */
@Override
public Object fromMessage(Message message) throws JMSException, MessageConversionException {
    SLF4JLoggerProxy.debug(this, "Converting from JMS {}", message); //$NON-NLS-1$
    if (message instanceof ObjectMessage) {
        return ((ObjectMessage) message).getObject();
    } else {
        throw new MessageConversionException(
                new I18NBoundMessage1P(Messages.UNEXPECTED_MESSAGE_RECEIVED, ObjectUtils.toString(message))
                        .getText());
    }
}