Search in sources :

Example 1 with PoolingWorkflow

use of com.adaptris.core.PoolingWorkflow in project interlok by adaptris.

the class HttpConsumerTest method testPoolingWorkflow_TimeoutAction_TimeoutExceeded.

@Test
public void testPoolingWorkflow_TimeoutAction_TimeoutExceeded() throws Exception {
    HttpConnection connection = createConnection(null);
    MockMessageProducer mockProducer = new StaticMockMessageProducer();
    mockProducer.getMessages().clear();
    JettyMessageConsumer consumer = JettyHelper.createConsumer(URL_TO_POST_TO);
    consumer.setAdditionalDebug(false);
    consumer.setTimeoutAction(new TimeoutAction(new TimeInterval(100L, TimeUnit.MILLISECONDS)));
    PoolingWorkflow workflow = new PoolingWorkflow();
    workflow.setShutdownWaitTime(new TimeInterval(100L, TimeUnit.MILLISECONDS));
    StandardResponseProducer responder = new StandardResponseProducer(HttpStatus.OK_200);
    workflow.setConsumer(consumer);
    workflow.getServiceCollection().add(new WaitService(new TimeInterval(5L, TimeUnit.SECONDS)));
    workflow.getServiceCollection().add(new StandaloneProducer(mockProducer));
    workflow.getServiceCollection().add(new StandaloneProducer(responder));
    workflow.addInterceptor(new JettyPoolingWorkflowInterceptor());
    Channel channel = JettyHelper.createChannel(connection, workflow);
    try {
        channel.requestStart();
        AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(XML_PAYLOAD);
        msg.addMetadata(CONTENT_TYPE_METADATA_KEY, "text/xml");
        httpProducer.setUrl(createProduceDestinationUrl(connection.getPort()));
        start(httpProducer);
        AdaptrisMessage reply = httpProducer.request(msg);
        assertEquals(Integer.valueOf(HttpStatus.ACCEPTED_202.getStatusCode()), Integer.valueOf(reply.getMetadataValue(CoreConstants.HTTP_PRODUCER_RESPONSE_CODE)));
    } finally {
        stop(httpProducer);
        channel.requestClose();
    }
}
Also used : WaitService(com.adaptris.core.services.WaitService) MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) StaticMockMessageProducer(com.adaptris.core.stubs.StaticMockMessageProducer) TimeInterval(com.adaptris.util.TimeInterval) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) Channel(com.adaptris.core.Channel) PoolingWorkflow(com.adaptris.core.PoolingWorkflow) StaticMockMessageProducer(com.adaptris.core.stubs.StaticMockMessageProducer) StandaloneProducer(com.adaptris.core.StandaloneProducer) Test(org.junit.Test)

Example 2 with PoolingWorkflow

use of com.adaptris.core.PoolingWorkflow in project interlok by adaptris.

the class JettyAsyncWorkflowInterceptorTest method testAcrossMultipleWorkflows_WithCacheKey.

@Test
public void testAcrossMultipleWorkflows_WithCacheKey() throws Exception {
    HttpConnection connection = createConnection(Integer.parseInt(PROPERTIES.getProperty(JETTY_HTTP_PORT)));
    JettyMessageConsumer consumer = JettyHelper.createConsumer(URL_TO_POST_TO, getName());
    PoolingWorkflow receivingWF = new PoolingWorkflow();
    // It's a bit lame, but we have to use something that is populated *before entry into the workflow*
    String cacheKey = "%message{" + JettyConstants.JETTY_URI + "}";
    receivingWF.addInterceptor(new JettyAsyncWorkflowInterceptor().withMode(JettyAsyncWorkflowInterceptor.Mode.REQUEST).withCacheKey(cacheKey));
    receivingWF.setShutdownWaitTime(new TimeInterval(1L, TimeUnit.SECONDS));
    receivingWF.setConsumer(consumer);
    StandardWorkflow respondingWF = new StandardWorkflow();
    // Mainly to keep track of the msgID. we use a standard workflow so new objects aren't created.
    MockMessageProducer producer = new MockMessageProducer();
    respondingWF.addInterceptor(new JettyAsyncWorkflowInterceptor().withMode(JettyAsyncWorkflowInterceptor.Mode.RESPONSE).withCacheKey(cacheKey));
    respondingWF.getServiceCollection().add(new PayloadFromTemplateService().withTemplate("hello world"));
    respondingWF.getServiceCollection().add(new JettyResponseService(200, "text/plain"));
    respondingWF.getServiceCollection().add(new StandaloneProducer(producer));
    receivingWF.setProducer(new WorkflowProducer(respondingWF));
    Channel channel = JettyHelper.createChannel(connection, receivingWF, respondingWF);
    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());
        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 : StandardWorkflow(com.adaptris.core.StandardWorkflow) TimeInterval(com.adaptris.util.TimeInterval) MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) Channel(com.adaptris.core.Channel) HttpRequestService(com.adaptris.core.http.client.net.HttpRequestService) PayloadFromTemplateService(com.adaptris.core.services.metadata.PayloadFromTemplateService) PoolingWorkflow(com.adaptris.core.PoolingWorkflow) StandaloneProducer(com.adaptris.core.StandaloneProducer) Test(org.junit.Test)

Example 3 with PoolingWorkflow

use of com.adaptris.core.PoolingWorkflow in project interlok by adaptris.

the class JettyAsyncWorkflowInterceptorTest method retrieveObjectForSampleConfig.

@Override
protected Channel retrieveObjectForSampleConfig() {
    try {
        Channel c = new Channel("JettyHandler");
        PoolingWorkflow wf1 = new PoolingWorkflow("receiveJettyRequest");
        wf1.addInterceptor(new JettyAsyncWorkflowInterceptor().withMode(JettyAsyncWorkflowInterceptor.Mode.REQUEST));
        PoolingWorkflow wf2 = new PoolingWorkflow("respondToJetty");
        wf2.addInterceptor(new JettyAsyncWorkflowInterceptor().withMode(JettyAsyncWorkflowInterceptor.Mode.RESPONSE));
        wf2.getServiceCollection().add(new JettyResponseService(200, "text/plain"));
        c.getWorkflowList().add(wf1);
        c.getWorkflowList().add(wf2);
        return c;
    } catch (CoreException e) {
        throw new RuntimeException(e);
    }
}
Also used : CoreException(com.adaptris.core.CoreException) Channel(com.adaptris.core.Channel) PoolingWorkflow(com.adaptris.core.PoolingWorkflow)

Example 4 with PoolingWorkflow

use of com.adaptris.core.PoolingWorkflow in project interlok by adaptris.

the class EmbeddedHttpConsumerTest method testPoolingWorkflow_WithoutInterceptor.

@Test
public void testPoolingWorkflow_WithoutInterceptor() throws Exception {
    EmbeddedJettyHelper helper = new EmbeddedJettyHelper();
    helper.startServer();
    MockMessageProducer mockProducer = new StaticMockMessageProducer();
    mockProducer.getMessages().clear();
    JettyMessageConsumer consumer = JettyHelper.createConsumer(URL_TO_POST_TO);
    PoolingWorkflow workflow = new PoolingWorkflow();
    workflow.setShutdownWaitTime(new TimeInterval(100L, TimeUnit.MILLISECONDS));
    StandardResponseProducer responder = new StandardResponseProducer(HttpStatus.OK_200);
    workflow.setConsumer(consumer);
    workflow.getServiceCollection().add(new WaitService(new TimeInterval(1L, TimeUnit.SECONDS)));
    workflow.getServiceCollection().add(new StandaloneProducer(mockProducer));
    workflow.getServiceCollection().add(new StandaloneProducer(responder));
    Channel channel = JettyHelper.createChannel(new EmbeddedConnection(), workflow);
    try {
        channel.requestStart();
        AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(XML_PAYLOAD);
        msg.addMetadata(CONTENT_TYPE_METADATA_KEY, "text/xml");
        httpProducer.setUrl(helper.createProduceDestination());
        start(httpProducer);
        AdaptrisMessage reply = httpProducer.request(msg);
        // Because of redmineID #4715 it should just "return immediatel" which flushes the stream so there's no content.
        assertEquals("Reply Payloads", "", reply.getContent());
    } finally {
        stop(httpProducer);
        channel.requestClose();
        helper.stopServer();
    }
}
Also used : WaitService(com.adaptris.core.services.WaitService) MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) StaticMockMessageProducer(com.adaptris.core.stubs.StaticMockMessageProducer) TimeInterval(com.adaptris.util.TimeInterval) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) Channel(com.adaptris.core.Channel) PoolingWorkflow(com.adaptris.core.PoolingWorkflow) StaticMockMessageProducer(com.adaptris.core.stubs.StaticMockMessageProducer) StandaloneProducer(com.adaptris.core.StandaloneProducer) Test(org.junit.Test)

Example 5 with PoolingWorkflow

use of com.adaptris.core.PoolingWorkflow in project interlok by adaptris.

the class HttpConsumerTest method testPoolingWorkflow_WithInterceptor.

@Test
public void testPoolingWorkflow_WithInterceptor() throws Exception {
    HttpConnection connection = createConnection(null);
    MockMessageProducer mockProducer = new StaticMockMessageProducer();
    mockProducer.getMessages().clear();
    JettyMessageConsumer consumer = JettyHelper.createConsumer(URL_TO_POST_TO);
    consumer.setWarnAfter(new TimeInterval(10L, TimeUnit.MILLISECONDS));
    PoolingWorkflow workflow = new PoolingWorkflow();
    StandardResponseProducer responder = new StandardResponseProducer(HttpStatus.OK_200);
    workflow.setConsumer(consumer);
    workflow.getServiceCollection().add(new WaitService(new TimeInterval(1L, TimeUnit.SECONDS)));
    workflow.getServiceCollection().add(new StandaloneProducer(mockProducer));
    workflow.getServiceCollection().add(new StandaloneProducer(responder));
    workflow.addInterceptor(new JettyPoolingWorkflowInterceptor());
    Channel channel = JettyHelper.createChannel(connection, workflow);
    try {
        channel.requestStart();
        AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(XML_PAYLOAD);
        msg.addMetadata(CONTENT_TYPE_METADATA_KEY, "text/xml");
        httpProducer.setUrl(createProduceDestinationUrl(connection.getPort()));
        start(httpProducer);
        AdaptrisMessage reply = httpProducer.request(msg);
        assertEquals("Reply Payloads", XML_PAYLOAD, reply.getContent());
        doAssertions(mockProducer);
    } finally {
        stop(httpProducer);
        channel.requestClose();
    }
}
Also used : WaitService(com.adaptris.core.services.WaitService) MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) StaticMockMessageProducer(com.adaptris.core.stubs.StaticMockMessageProducer) TimeInterval(com.adaptris.util.TimeInterval) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) Channel(com.adaptris.core.Channel) PoolingWorkflow(com.adaptris.core.PoolingWorkflow) StaticMockMessageProducer(com.adaptris.core.stubs.StaticMockMessageProducer) StandaloneProducer(com.adaptris.core.StandaloneProducer) Test(org.junit.Test)

Aggregations

PoolingWorkflow (com.adaptris.core.PoolingWorkflow)21 Test (org.junit.Test)17 Channel (com.adaptris.core.Channel)15 TimeInterval (com.adaptris.util.TimeInterval)10 MockMessageProducer (com.adaptris.core.stubs.MockMessageProducer)9 AdaptrisMessage (com.adaptris.core.AdaptrisMessage)8 StandaloneProducer (com.adaptris.core.StandaloneProducer)8 WaitService (com.adaptris.core.services.WaitService)8 Adapter (com.adaptris.core.Adapter)7 StaticMockMessageProducer (com.adaptris.core.stubs.StaticMockMessageProducer)6 ObjectName (javax.management.ObjectName)5 HttpRequestService (com.adaptris.core.http.client.net.HttpRequestService)4 StandardWorkflow (com.adaptris.core.StandardWorkflow)3 Notification (javax.management.Notification)3 NotificationFilterSupport (javax.management.NotificationFilterSupport)3 JettyMessageConsumer (com.adaptris.core.http.jetty.JettyMessageConsumer)2 MessageInFlightMBean (com.adaptris.core.interceptor.MessageInFlightMBean)2 PayloadFromTemplateService (com.adaptris.core.services.metadata.PayloadFromTemplateService)2 CoreException (com.adaptris.core.CoreException)1 ProduceException (com.adaptris.core.ProduceException)1