Package org.apache.servicemix.nmr.api

Examples of org.apache.servicemix.nmr.api.Message


        assertNotNull(msg.getHeader("name"));
    }

    @Test
    public void testContentType() {
        Message msg = new MessageImpl();
        assertNull(msg.getContentType());
        msg.setContentType("type");
        assertEquals("type", msg.getContentType());
    }
View Full Code Here


        assertEquals("type", msg.getContentType());
    }

    @Test
    public void testContentEncoding() {
        Message msg = new MessageImpl();
        assertNull(msg.getContentEncoding());
        msg.setContentEncoding("enc");
        assertEquals("enc", msg.getContentEncoding());
    }
View Full Code Here

        assertEquals("enc", msg.getContentEncoding());
    }

    @Test
    public void testAttachments() {
        Message msg = new MessageImpl();
        assertNull(msg.getAttachment("id"));
        msg.removeAttachment("id");
        assertNotNull(msg.getAttachments());
        assertNull(msg.getAttachment("id"));
        msg.addAttachment("id", "value");
        assertEquals("value", msg.getAttachment("id"));
        msg.removeAttachment("id");
        assertNull(msg.getAttachment("id"));
        assertTrue(msg.getAttachments().isEmpty());
    }
View Full Code Here

        assertTrue(msg.getAttachments().isEmpty());
    }

    @Test
    public void testCopy() {
        Message msg = new MessageImpl();
        Message cpy = msg.copy();
        assertNotNull(cpy);

        msg = new MessageImpl();
        msg.setHeader("header", "value");
        msg.addAttachment("id", "att");
        cpy = msg.copy();
        assertNotNull(cpy);
        assertNotNull(cpy.getHeader("header"));
        assertNotNull(cpy.getAttachment("id"));
    }
View Full Code Here

        assertNotNull(cpy.getAttachment("id"));
    }

    @Test
    public void testWrite() throws Exception {
        Message msg = new MessageImpl();
        msg.setHeader("header", "value");
        msg.addAttachment("id", "att");
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        ObjectOutputStream os = new ObjectOutputStream(baos);
        os.writeObject(msg);
        os.close();
        ObjectInputStream is = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray()));
        Message cpy = (Message) is.readObject();
        assertNotNull(cpy);
        assertNotNull(cpy.getHeader("header"));
        assertNotNull(cpy.getAttachment("id"));
    }
View Full Code Here

        assertNotNull(cpy.getAttachment("id"));
    }

    @Test
    public void testDisplay() {
        Message msg = new MessageImpl();
        msg.toString();
        msg.display(false);
    }
View Full Code Here

        sb.append("]\n");
        return sb.toString();
    }

    public static void display(Exchange exchange, Type type, StringBuffer sb) {
        Message message = exchange.getMessage(type, false);
        if (message != null) {
            sb.append("  ").append(type).append(": [").append('\n');
            sb.append("    content: ");
            try {
                if (message.getBody() != null) {
                    Object contents = message.getBody();
                    sb.append(convertDisplay(contents));
                } else {
                    sb.append("null");
                }
            } catch (Exception e) {
                sb.append("Unable to display: ").append(e);
            }
            sb.append('\n');
            if (message.getAttachments().size() > 0) {
                sb.append("    attachments: [").append('\n');
                for (String key : message.getAttachments().keySet()) {
                    Object contents = message.getAttachment(key);
                    sb.append("      ").append(key).append(" = ").append(convertDisplay(contents)).append('\n');
                }
                sb.append("    ]").append('\n');
            }
            if (message.getHeaders().size() > 0) {
                sb.append("    properties: [").append('\n');
                for (String key : message.getHeaders().keySet()) {
                    sb.append("      ").append(key).append(" = ");
                    Object contents = message.getHeader(key);
                    sb.append(convertDisplay(contents));
                    sb.append('\n');
                }
                sb.append("    ]").append('\n');
            }
View Full Code Here

    private static final Log LOG = LogFactory.getLog(ExchangeUtilsTest.class);

    public void testReReadable() throws Exception {
        Exchange e = new ExchangeImpl(Pattern.InOnly);
        Message msg = e.getIn();
        msg.addAttachment("id", new BufferedInputStream(new ByteArrayInputStream(new byte[] { 1, 2, 3, 4 })));
        msg.setBody(new StringSource("<hello/>"));

        e.ensureReReadable();

        assertNotNull(msg.getBody());
        assertTrue(msg.getBody() instanceof DOMSource);
        assertNotNull(msg.getAttachment("id"));
        assertTrue(msg.getAttachment("id") instanceof ByteArrayInputStream);
    }
View Full Code Here

    public void testDisplay() throws Exception {
        Exchange e = new ExchangeImpl(Pattern.InOnly);
        e.setOperation(new QName("op"));
        e.setProperty("key", "value");
        e.setStatus(Status.Done);
        Message msg = e.getIn();
        msg.setHeader("header", "value");
        msg.addAttachment("id", new BufferedInputStream(new ByteArrayInputStream(new byte[] { 1, 2, 3, 4 })));
        msg.setBody(new StringSource("<hello/>"));

        String str = e.display(false);
        LOG.info(str);
        assertNotNull(msg.getBody());
        assertTrue(msg.getBody() instanceof StringSource);
        assertNotNull(msg.getAttachment("id"));
        assertTrue(msg.getAttachment("id") instanceof BufferedInputStream);

        str = e.display(true);
        LOG.info(str);
        assertNotNull(msg.getBody());
        assertTrue(msg.getBody() instanceof DOMSource);
        assertNotNull(msg.getAttachment("id"));
        assertTrue(msg.getAttachment("id") instanceof ByteArrayInputStream);
    }
View Full Code Here

                    exchange.setProperty(MessageExchangeImpl.SERVICE_ENDPOINT_PROP, se);
                }
                // Re-process JBI addressing
                DeliveryChannelImpl.createTarget(getChannel().getNMR(), exchange);
                // TODO: read exchange properties
                Message msg = unmarshallMessage(message);
                exchange.setIn(msg);
                exchanges.put(exchange.getId(), exchange);
                if (pendingExchanges.incrementAndGet() >= maxPendingExchanges) {
                    if (pauseConsumption.compareAndSet(false, true)) {
                        invalidateSelector();
                    }
                }
                exchange.setProperty(PROPERTY_CORR_ID + "." + name, exchange.getId());
                requestor.suspend(exchange.getId());
                if (requestor.getTransaction() != null) {
                    exchange.setProperty(MessageExchange.JTA_TRANSACTION_PROPERTY_NAME, requestor.getTransaction());
                }
                send(exchange);
                break;
            }
            case JBI_MESSAGE_OUT: {
                String corrId = message.getStringProperty(PROPERTY_CORR_ID);
                if (corrId == null) {
                    throw new IllegalStateException("Incoming JMS message has no correlationId");
                }
                Exchange exchange = exchanges.get(corrId);
                if (exchange == null) {
                    throw new IllegalStateException("Exchange not found for id " + corrId);
                }
                Message msg = unmarshallMessage(message);
                exchange.setOut(msg);
                exchanges.put(exchange.getId(), exchange);
                exchange.setProperty(PROPERTY_CORR_ID + "." + name, exchange.getId());
                requestor.suspend(exchange.getId());
                if (requestor.getTransaction() != null) {
                    exchange.setProperty(MessageExchange.JTA_TRANSACTION_PROPERTY_NAME, requestor.getTransaction());
                }
                send(exchange);
                break;
            }
            case JBI_MESSAGE_FAULT: {
                String corrId = message.getStringProperty(PROPERTY_CORR_ID);
                if (corrId == null) {
                    throw new IllegalStateException("Incoming JMS message has no correlationId");
                }
                Exchange exchange = exchanges.get(corrId);
                if (exchange == null) {
                    throw new IllegalStateException("Exchange not found for id " + corrId);
                }
                Message msg = unmarshallMessage(message);
                exchange.setFault(msg);
                exchanges.put(exchange.getId(), exchange);
                exchange.setProperty(PROPERTY_CORR_ID + "." + name, exchange.getId());
                requestor.suspend(exchange.getId());
                if (requestor.getTransaction() != null) {
View Full Code Here

TOP

Related Classes of org.apache.servicemix.nmr.api.Message

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.