use of com.adaptris.core.AdaptrisMessage in project interlok by adaptris.
the class HttpConsumerTest method testBasicConsumeWorkflow_ConsumeDestinationContainsURL.
@Test
public void testBasicConsumeWorkflow_ConsumeDestinationContainsURL() throws Exception {
HttpConnection connection = createConnection(null);
MockMessageProducer mockProducer = new MockMessageProducer();
Channel channel = JettyHelper.createChannel(connection, JettyHelper.createConsumer("http://localhost:8080" + URL_TO_POST_TO), mockProducer);
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();
PortManager.release(connection.getPort());
}
}
use of com.adaptris.core.AdaptrisMessage 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.AdaptrisMessage 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.AdaptrisMessage in project interlok by adaptris.
the class JettyAsyncWorkflowInterceptorTest method testInterceptor_Cache.
@Test
public void testInterceptor_Cache() throws Exception {
JettyAsyncWorkflowInterceptor requestor = new JettyAsyncWorkflowInterceptor().withMode(JettyAsyncWorkflowInterceptor.Mode.REQUEST);
JettyAsyncWorkflowInterceptor responder = new JettyAsyncWorkflowInterceptor().withMode(JettyAsyncWorkflowInterceptor.Mode.RESPONSE);
AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(XML_PAYLOAD);
try {
assertFalse(JettyAsyncWorkflowInterceptor.cacheContains("hello"));
assertFalse(JettyAsyncWorkflowInterceptor.removeEntry("hello"));
start(responder, requestor);
requestor.workflowStart(msg);
assertTrue(JettyAsyncWorkflowInterceptor.cacheContains(msg.getUniqueId()));
responder.workflowStart(msg);
responder.workflowStart(AdaptrisMessageFactory.getDefaultInstance().newMessage(XML_PAYLOAD));
responder.workflowEnd(AdaptrisMessageFactory.getDefaultInstance().newMessage(XML_PAYLOAD), AdaptrisMessageFactory.getDefaultInstance().newMessage());
assertFalse(JettyAsyncWorkflowInterceptor.cacheContains(msg.getUniqueId()));
} finally {
stop(responder, requestor);
}
}
use of com.adaptris.core.AdaptrisMessage 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);
}
}
Aggregations