use of com.adaptris.core.Channel in project interlok by adaptris.
the class HttpConsumerTest method testBasicConsumeWorkflow_AcrossRestarts.
@Test
public void testBasicConsumeWorkflow_AcrossRestarts() throws Exception {
HttpConnection connection = createConnection(null);
MockMessageProducer mockProducer = new MockMessageProducer();
Channel channel = JettyHelper.createChannel(connection, JettyHelper.createConsumer(URL_TO_POST_TO), mockProducer);
try {
channel.requestStart();
channel.requestClose();
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();
PortManager.release(connection.getPort());
}
}
use of com.adaptris.core.Channel in project interlok by adaptris.
the class HttpsConsumerTest method testTLS_ConsumeWorkflow.
@Test
public void testTLS_ConsumeWorkflow() throws Exception {
String oldName = Thread.currentThread().getName();
Thread.currentThread().setName(getName());
HttpConnection connection = createConnection(null);
((HttpsConnection) connection).getSslProperties().add(new KeyValuePair(SslProperty.ExcludeProtocols.name(), "SSLv3,TLSv1.1,"));
MockMessageProducer mockProducer = new MockMessageProducer();
SimpleHttpProducer myHttpProducer = createProducer(new VersionedHttpsProduceConnection("TLSv1.2"));
Channel channel = JettyHelper.createChannel(connection, JettyHelper.createConsumer(URL_TO_POST_TO), mockProducer);
try {
channel.requestStart();
AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(XML_PAYLOAD);
msg.addMetadata(CONTENT_TYPE_METADATA_KEY, "text/xml");
myHttpProducer.setUrl(createProduceDestinationUrl(connection.getPort()));
start(myHttpProducer);
AdaptrisMessage reply = myHttpProducer.request(msg);
assertEquals("Reply Payloads", XML_PAYLOAD, reply.getContent());
doAssertions(mockProducer);
} finally {
stop(myHttpProducer);
channel.requestClose();
PortManager.release(connection.getPort());
Thread.currentThread().setName(oldName);
}
}
use of com.adaptris.core.Channel 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.Channel 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);
}
}
use of com.adaptris.core.Channel in project interlok by adaptris.
the class EmbeddedHttpConsumerTest method testStart_WithWait.
@Test
public void testStart_WithWait() throws Exception {
EmbeddedJettyHelper helper = new EmbeddedJettyHelper();
EmbeddedConnection connection = new EmbeddedConnection();
connection.setMaxStartupWait(new TimeInterval(100L, TimeUnit.MILLISECONDS));
Channel channel = JettyHelper.createChannel(connection, JettyHelper.createConsumer(URL_TO_POST_TO), new MockMessageProducer());
try {
new Thread(() -> {
startQuietly(channel);
}).start();
LifecycleHelper.waitQuietly(250L);
helper.startServer();
LifecycleHelper.waitQuietly(600L);
assertEquals(StartedState.getInstance(), channel.retrieveComponentState());
} finally {
LifecycleHelper.stopAndClose(channel);
helper.stopServer();
}
}
Aggregations