use of com.adaptris.core.StandardWorkflow in project interlok by adaptris.
the class HttpConsumerTest method testChannelStarted_MultipleWorkflows_OneWorkflowStopped.
@Test
public void testChannelStarted_MultipleWorkflows_OneWorkflowStopped() throws Exception {
HttpConnection connection = createConnection(null);
JettyMessageConsumer consumer1 = JettyHelper.createConsumer(URL_TO_POST_TO);
StandardWorkflow workflow1 = new StandardWorkflow();
workflow1.setConsumer(consumer1);
workflow1.getServiceCollection().add(new StandaloneProducer(new StandardResponseProducer(HttpStatus.OK_200)));
Channel channel = JettyHelper.createChannel(connection, workflow1);
JettyMessageConsumer consumer2 = JettyHelper.createConsumer("/some/other/urlmapping/");
StandardWorkflow workflow2 = new StandardWorkflow();
workflow2.setConsumer(consumer2);
workflow2.getServiceCollection().add(new StandaloneProducer(new StandardResponseProducer(HttpStatus.OK_200)));
channel.getWorkflowList().add(workflow2);
try {
channel.requestStart();
AdaptrisMessage msg1 = AdaptrisMessageFactory.getDefaultInstance().newMessage(XML_PAYLOAD);
msg1.addMetadata(CONTENT_TYPE_METADATA_KEY, "text/xml");
httpProducer.setUrl(createProduceDestinationUrl(connection.getPort()));
start(httpProducer);
AdaptrisMessage reply = httpProducer.request(msg1);
assertEquals("200", reply.getMetadataValue(CoreConstants.HTTP_PRODUCER_RESPONSE_CODE));
workflow2.requestClose();
// Stopping Workflow 2 means nothing, workflow1 should still be working!
AdaptrisMessage msg2 = AdaptrisMessageFactory.getDefaultInstance().newMessage(XML_PAYLOAD);
msg1.addMetadata(CONTENT_TYPE_METADATA_KEY, "text/xml");
AdaptrisMessage reply2 = httpProducer.request(msg2);
assertEquals("200", reply2.getMetadataValue(CoreConstants.HTTP_PRODUCER_RESPONSE_CODE));
} finally {
channel.requestClose();
}
}
use of com.adaptris.core.StandardWorkflow in project interlok by adaptris.
the class HttpConsumerTest method testChannelStarted_WorkflowStopped.
@Test
public void testChannelStarted_WorkflowStopped() throws Exception {
HttpConnection connection = createConnection(null);
JettyMessageConsumer consumer1 = JettyHelper.createConsumer(URL_TO_POST_TO);
StandardWorkflow workflow1 = new StandardWorkflow();
workflow1.setConsumer(consumer1);
workflow1.getServiceCollection().add(new StandaloneProducer(new StandardResponseProducer(HttpStatus.OK_200)));
Channel channel = JettyHelper.createChannel(connection, workflow1);
try {
channel.requestStart();
AdaptrisMessage msg1 = AdaptrisMessageFactory.getDefaultInstance().newMessage(XML_PAYLOAD);
msg1.addMetadata(CONTENT_TYPE_METADATA_KEY, "text/xml");
httpProducer.setUrl(createProduceDestinationUrl(connection.getPort()));
start(httpProducer);
AdaptrisMessage reply = httpProducer.request(msg1);
assertEquals("200", reply.getMetadataValue(CoreConstants.HTTP_PRODUCER_RESPONSE_CODE));
workflow1.requestClose();
AdaptrisMessage msg2 = AdaptrisMessageFactory.getDefaultInstance().newMessage(XML_PAYLOAD);
msg1.addMetadata(CONTENT_TYPE_METADATA_KEY, "text/xml");
AdaptrisMessage reply2 = httpProducer.request(msg2);
assertEquals("404", reply2.getMetadataValue(CoreConstants.HTTP_PRODUCER_RESPONSE_CODE));
} finally {
channel.requestClose();
}
}
use of com.adaptris.core.StandardWorkflow 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);
}
}
use of com.adaptris.core.StandardWorkflow in project interlok by adaptris.
the class JettyHelper method createWorkflow.
public static Workflow createWorkflow(JettyMessageConsumer consumer, AdaptrisMessageProducer producer, ServiceList list) {
StandardWorkflow wf = new StandardWorkflow();
wf.setConsumer(consumer);
wf.setProducer(producer);
wf.setServiceCollection(list);
return wf;
}
use of com.adaptris.core.StandardWorkflow in project interlok by adaptris.
the class EmbeddedHttpConsumerTest method testChannelStarted_WorkflowStopped.
@Test
public void testChannelStarted_WorkflowStopped() throws Exception {
EmbeddedJettyHelper helper = new EmbeddedJettyHelper();
helper.startServer();
JettyMessageConsumer consumer1 = JettyHelper.createConsumer(URL_TO_POST_TO);
StandardWorkflow workflow1 = new StandardWorkflow();
workflow1.setConsumer(consumer1);
workflow1.getServiceCollection().add(new StandaloneProducer(new StandardResponseProducer(HttpStatus.OK_200)));
Channel channel = JettyHelper.createChannel(new EmbeddedConnection(), workflow1);
try {
channel.requestStart();
AdaptrisMessage msg1 = AdaptrisMessageFactory.getDefaultInstance().newMessage(XML_PAYLOAD);
msg1.addMetadata(CONTENT_TYPE_METADATA_KEY, "text/xml");
httpProducer.setUrl(helper.createProduceDestination());
start(httpProducer);
AdaptrisMessage reply = httpProducer.request(msg1);
assertEquals("200", reply.getMetadataValue(CoreConstants.HTTP_PRODUCER_RESPONSE_CODE));
workflow1.requestClose();
AdaptrisMessage msg2 = AdaptrisMessageFactory.getDefaultInstance().newMessage(XML_PAYLOAD);
msg1.addMetadata(CONTENT_TYPE_METADATA_KEY, "text/xml");
AdaptrisMessage reply2 = httpProducer.request(msg2);
assertEquals("404", reply2.getMetadataValue(CoreConstants.HTTP_PRODUCER_RESPONSE_CODE));
} finally {
stop(httpProducer);
channel.requestClose();
helper.stopServer();
}
}
Aggregations