Search in sources :

Example 1 with BrowsableEndpoint

use of org.apache.camel.spi.BrowsableEndpoint in project camel by apache.

the class FtpBrowsableEndpointTest method testBrowsableNoFiles.

@Test
public void testBrowsableNoFiles() throws Exception {
    // make sure starting directory exists
    createDirectory(FTP_ROOT_DIR + "/browse");
    BrowsableEndpoint browse = context.getEndpoint(getFtpUrl(), BrowsableEndpoint.class);
    assertNotNull(browse);
    List<Exchange> list = browse.getExchanges();
    assertNotNull(list);
    assertEquals(0, list.size());
}
Also used : Exchange(org.apache.camel.Exchange) BrowsableEndpoint(org.apache.camel.spi.BrowsableEndpoint) Test(org.junit.Test)

Example 2 with BrowsableEndpoint

use of org.apache.camel.spi.BrowsableEndpoint in project camel by apache.

the class EndpointHelper method browseRangeMessagesAsXml.

/**
     * Browses the {@link BrowsableEndpoint} within the given range, and returns the messages as a XML payload.
     *
     * @param endpoint    the browsable endpoint
     * @param fromIndex   from range
     * @param toIndex     to range
     * @param includeBody whether to include the message body in the XML payload
     * @return XML payload with the messages
     * @throws IllegalArgumentException if the from and to range is invalid
     * @see MessageHelper#dumpAsXml(org.apache.camel.Message)
     */
public static String browseRangeMessagesAsXml(BrowsableEndpoint endpoint, Integer fromIndex, Integer toIndex, Boolean includeBody) {
    if (fromIndex == null) {
        fromIndex = 0;
    }
    if (toIndex == null) {
        toIndex = Integer.MAX_VALUE;
    }
    if (fromIndex > toIndex) {
        throw new IllegalArgumentException("From index cannot be larger than to index, was: " + fromIndex + " > " + toIndex);
    }
    List<Exchange> exchanges = endpoint.getExchanges();
    if (exchanges.size() == 0) {
        return null;
    }
    StringBuilder sb = new StringBuilder();
    sb.append("<messages>");
    for (int i = fromIndex; i < exchanges.size() && i <= toIndex; i++) {
        Exchange exchange = exchanges.get(i);
        Message msg = exchange.hasOut() ? exchange.getOut() : exchange.getIn();
        String xml = MessageHelper.dumpAsXml(msg, includeBody);
        sb.append("\n").append(xml);
    }
    sb.append("\n</messages>");
    return sb.toString();
}
Also used : Exchange(org.apache.camel.Exchange) Message(org.apache.camel.Message) Endpoint(org.apache.camel.Endpoint) DelegateEndpoint(org.apache.camel.DelegateEndpoint) BrowsableEndpoint(org.apache.camel.spi.BrowsableEndpoint)

Example 3 with BrowsableEndpoint

use of org.apache.camel.spi.BrowsableEndpoint in project camel by apache.

the class BrowseRouteTest method testBrowseRoute.

public void testBrowseRoute() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedBodiesReceived("Hello World", "Bye World");
    template.sendBody("direct:start", "Hello World");
    template.sendBody("direct:start", "Bye World");
    assertMockEndpointsSatisfied();
    BrowsableEndpoint list = context.getEndpoint("browse:foo", BrowsableEndpoint.class);
    mock.getExchanges().get(0).equals(list.getExchanges().get(0));
    mock.getExchanges().get(1).equals(list.getExchanges().get(1));
}
Also used : MockEndpoint(org.apache.camel.component.mock.MockEndpoint) BrowsableEndpoint(org.apache.camel.spi.BrowsableEndpoint)

Example 4 with BrowsableEndpoint

use of org.apache.camel.spi.BrowsableEndpoint in project camel by apache.

the class FileBrowsableEndpointTest method testBrowsableNoFiles.

public void testBrowsableNoFiles() throws Exception {
    BrowsableEndpoint browse = context.getEndpoint("file:target/browse", BrowsableEndpoint.class);
    assertNotNull(browse);
    List<Exchange> list = browse.getExchanges();
    assertNotNull(list);
    assertEquals(0, list.size());
}
Also used : Exchange(org.apache.camel.Exchange) BrowsableEndpoint(org.apache.camel.spi.BrowsableEndpoint)

Aggregations

BrowsableEndpoint (org.apache.camel.spi.BrowsableEndpoint)4 Exchange (org.apache.camel.Exchange)3 DelegateEndpoint (org.apache.camel.DelegateEndpoint)1 Endpoint (org.apache.camel.Endpoint)1 Message (org.apache.camel.Message)1 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)1 Test (org.junit.Test)1