Search in sources :

Example 6 with HttpRequestService

use of com.adaptris.core.http.client.net.HttpRequestService in project interlok by adaptris.

the class JettyAsyncWorkflowInterceptorTest method testInterceptor_WithShortcut.

@Test
public void testInterceptor_WithShortcut() throws Exception {
    HttpConnection connection = createConnection(Integer.parseInt(PROPERTIES.getProperty(JETTY_HTTP_PORT)));
    JettyMessageConsumer consumer = JettyHelper.createConsumer(URL_TO_POST_TO, getName());
    StandardWorkflow receivingWF = new StandardWorkflow();
    MockMessageProducer producer = new MockMessageProducer();
    receivingWF.addInterceptor(new JettyAsyncWorkflowInterceptor().withMode(JettyAsyncWorkflowInterceptor.Mode.REQUEST));
    receivingWF.getServiceCollection().add(new PayloadFromTemplateService().withTemplate("hello world"));
    receivingWF.getServiceCollection().add(new StandaloneProducer(producer));
    receivingWF.getServiceCollection().add(new JettyResponseService(200, "text/plain"));
    receivingWF.getServiceCollection().add(new ShortCutJettyResponse());
    receivingWF.setConsumer(consumer);
    Channel channel = JettyHelper.createChannel(connection, receivingWF);
    HttpRequestService httpService = createRequestor(connection.getPort());
    try {
        start(channel);
        LifecycleHelper.initAndStart(httpService);
        AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(XML_PAYLOAD);
        ExampleServiceCase.execute(httpService, msg);
        assertEquals("hello world", msg.getContent());
        // Should be removed from the static cache.
        waitForMessages(producer, 1);
        // Grab the message that the standardWorkflow handled; and check the msgId.
        // Should be removed from the static cache.
        assertFalse(JettyAsyncWorkflowInterceptor.cacheContains(producer.getMessages().get(0).getUniqueId()));
    } finally {
        stop(channel);
    }
}
Also used : HttpRequestService(com.adaptris.core.http.client.net.HttpRequestService) StandardWorkflow(com.adaptris.core.StandardWorkflow) MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) Channel(com.adaptris.core.Channel) PayloadFromTemplateService(com.adaptris.core.services.metadata.PayloadFromTemplateService) StandaloneProducer(com.adaptris.core.StandaloneProducer) Test(org.junit.Test)

Example 7 with HttpRequestService

use of com.adaptris.core.http.client.net.HttpRequestService in project interlok by adaptris.

the class RetryFromJettyTest method testReport.

@Test
public void testReport() throws Exception {
    RetryFromJetty retrier = create();
    try {
        start(retrier);
        String url = jettyHelper.buildUrl(RetryFromJetty.DEFAULT_REPORTING_ENDPOINT);
        HttpRequestService http = new HttpRequestService(url);
        AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage();
        ExampleServiceCase.execute(http, msg);
        assertEquals(RetryFromJetty.HTTP_OK, msg.getMetadataValue(CoreConstants.HTTP_PRODUCER_RESPONSE_CODE));
        // We know there should be at least 2 messages seeded...
        try (InputStream in = msg.getInputStream()) {
            List lines = IOUtils.readLines(in, StandardCharsets.UTF_8);
            assertTrue(lines.size() >= 2);
        }
    } finally {
        stop(retrier);
    }
}
Also used : HttpRequestService(com.adaptris.core.http.client.net.HttpRequestService) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) InputStream(java.io.InputStream) ChannelList(com.adaptris.core.ChannelList) List(java.util.List) Test(org.junit.Test)

Aggregations

HttpRequestService (com.adaptris.core.http.client.net.HttpRequestService)7 Test (org.junit.Test)6 AdaptrisMessage (com.adaptris.core.AdaptrisMessage)5 Channel (com.adaptris.core.Channel)5 PoolingWorkflow (com.adaptris.core.PoolingWorkflow)4 StandaloneProducer (com.adaptris.core.StandaloneProducer)4 MockMessageProducer (com.adaptris.core.stubs.MockMessageProducer)4 TimeInterval (com.adaptris.util.TimeInterval)4 StandardWorkflow (com.adaptris.core.StandardWorkflow)3 PayloadFromTemplateService (com.adaptris.core.services.metadata.PayloadFromTemplateService)3 WaitService (com.adaptris.core.services.WaitService)2 ChannelList (com.adaptris.core.ChannelList)1 ProduceException (com.adaptris.core.ProduceException)1 ServiceException (com.adaptris.core.ServiceException)1 StaticMockMessageProducer (com.adaptris.core.stubs.StaticMockMessageProducer)1 InputStream (java.io.InputStream)1 List (java.util.List)1