use of com.adaptris.core.StandardWorkflow in project interlok by adaptris.
the class StandardHttpProducerTest method testRequest_EmptyReply.
@Test
public void testRequest_EmptyReply() throws Exception {
MockMessageProducer mock = new MockMessageProducer();
HttpConnection jc = HttpHelper.createConnection();
JettyMessageConsumer mc = createConsumer(HttpHelper.URL_TO_POST_TO);
Channel c = createChannel(jc, createWorkflow(mc, mock, new ServiceList()));
StandardWorkflow workflow = (StandardWorkflow) c.getWorkflowList().get(0);
StandardResponseProducer responder = new StandardResponseProducer(HttpStatus.OK_200);
responder.setSendPayload(false);
workflow.getServiceCollection().add(new StandaloneProducer(responder));
StandardHttpProducer stdHttp = new StandardHttpProducer().withURL(HttpHelper.createURL(c));
stdHttp.setMethodProvider(new ConfiguredRequestMethodProvider(RequestMethodProvider.RequestMethod.POST));
stdHttp.setConnectTimeout(new TimeInterval(60L, TimeUnit.SECONDS));
stdHttp.setReadTimeout(new TimeInterval(60L, TimeUnit.SECONDS));
StandaloneRequestor producer = new StandaloneRequestor(stdHttp);
producer.setReplyTimeout(new TimeInterval(60L, TimeUnit.SECONDS));
AdaptrisMessage msg = new DefaultMessageFactory().newMessage(TEXT);
try {
start(c);
start(producer);
producer.doService(msg);
waitForMessages(mock, 1);
} finally {
HttpHelper.stopChannelAndRelease(c);
stop(producer);
}
assertEquals(1, mock.messageCount());
AdaptrisMessage m2 = mock.getMessages().get(0);
assertEquals("POST", m2.getMetadataValue(CoreConstants.HTTP_METHOD));
assertEquals(0, msg.getSize());
}
use of com.adaptris.core.StandardWorkflow in project interlok by adaptris.
the class JettyAsyncWorkflowInterceptorTest method testAcrossMultipleWorkflows.
@Test
public void testAcrossMultipleWorkflows() 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();
receivingWF.addInterceptor(new JettyAsyncWorkflowInterceptor().withMode(JettyAsyncWorkflowInterceptor.Mode.REQUEST));
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));
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 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);
}
}
use of com.adaptris.core.StandardWorkflow in project interlok by adaptris.
the class HttpConsumerTest method testBasicConsumeWorkflow_LongLived_Expect.
@Test
public void testBasicConsumeWorkflow_LongLived_Expect() throws Exception {
HttpConnection connection = createConnection(null);
MockMessageProducer mockProducer = new MockMessageProducer();
JettyMessageConsumer consumer = JettyHelper.createConsumer(URL_TO_POST_TO, getName());
consumer.setSendProcessingInterval(new TimeInterval(1L, TimeUnit.SECONDS));
StandardWorkflow wf = (StandardWorkflow) JettyHelper.createWorkflow(consumer, mockProducer);
wf.getServiceCollection().add(new WaitService(new TimeInterval(3L, TimeUnit.SECONDS)));
Channel channel = JettyHelper.createChannel(connection, wf);
try {
channel.requestStart();
AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(XML_PAYLOAD);
msg.addMetadata(CONTENT_TYPE_METADATA_KEY, "text/xml");
httpProducer.getAdditionalHeaders().add(new KeyValuePair("Expect", "102-Processing"));
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();
PortManager.release(connection.getPort());
}
}
use of com.adaptris.core.StandardWorkflow in project interlok by adaptris.
the class RetryFromJettyTest method testRetry_NotFound.
@Test
public void testRetry_NotFound() throws Exception {
RetryFromJetty retrier = create();
StandardWorkflow workflow = createWorkflow();
try {
MockMessageProducer workflowProducer = (MockMessageProducer) workflow.getProducer();
retrier.addWorkflow(workflow);
retrier.addWorkflow(createWorkflow());
start(workflow, retrier);
AdaptrisMessage baseMsg = AdaptrisMessageFactory.getDefaultInstance().newMessage();
baseMsg.addMetadata(Workflow.WORKFLOW_ID_KEY, workflow.obtainWorkflowId());
retryStore.write(baseMsg);
assertNotNull(retryStore.getMetadata(baseMsg.getUniqueId()));
// This should result in a msgId that isn't found; so we get a 500...
AdaptrisMessage triggerMsg = AdaptrisMessageFactory.getDefaultInstance().newMessage();
String url = jettyHelper.buildUrl(RetryFromJetty.DEFAULT_ENDPOINT_PREFIX + triggerMsg.getUniqueId());
StandardHttpProducer http = buildProducer(url);
http.setIgnoreServerResponseCode(true);
ExampleServiceCase.execute(new StandaloneRequestor(http), triggerMsg);
assertEquals(RetryFromJetty.HTTP_ERROR, triggerMsg.getMetadataValue(CoreConstants.HTTP_PRODUCER_RESPONSE_CODE));
} finally {
stop(retrier, workflow);
}
}
Aggregations