use of com.adaptris.core.StandaloneProducer 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();
}
}
use of com.adaptris.core.StandaloneProducer 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();
}
}
use of com.adaptris.core.StandaloneProducer in project interlok by adaptris.
the class EmbeddedHttpConsumerTest method testChannelStarted_MultipleWorkflows_OneWorkflowStopped.
@Test
public void testChannelStarted_MultipleWorkflows_OneWorkflowStopped() 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);
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(helper.createProduceDestination());
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 {
stop(httpProducer);
channel.requestClose();
helper.stopServer();
}
}
use of com.adaptris.core.StandaloneProducer 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();
}
}
use of com.adaptris.core.StandaloneProducer in project interlok by adaptris.
the class HttpRequestServiceTest method testService_WithMetadataMethod.
@Test
public void testService_WithMetadataMethod() 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(new Service[] { new PayloadFromTemplateService().withTemplate(TEXT), new StandaloneProducer(new StandardResponseProducer(HttpStatus.OK_200)) })));
HttpRequestService service = new HttpRequestService(HttpHelper.createProduceDestination(c)).withMethod("%message{httpMethod}");
AdaptrisMessage msg = new DefaultMessageFactory().newMessage();
msg.addMetadata("httpMethod", "get");
try {
start(c);
execute(service, msg);
waitForMessages(mock, 1);
} finally {
HttpHelper.stopChannelAndRelease(c);
}
assertEquals(1, mock.messageCount());
AdaptrisMessage m2 = mock.getMessages().get(0);
assertEquals("GET", m2.getMetadataValue(CoreConstants.HTTP_METHOD));
assertEquals(TEXT, msg.getContent());
}
Aggregations