use of com.adaptris.core.http.client.net.HttpRequestService in project interlok by adaptris.
the class JettyAsyncWorkflowInterceptorTest method createRequestor.
private HttpRequestService createRequestor(int port) {
final HttpRequestService httpService = new HttpRequestService();
httpService.setUrl("http://localhost:" + port + URL_TO_POST_TO);
httpService.setContentType("text/xml");
return httpService;
}
use of com.adaptris.core.http.client.net.HttpRequestService 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.http.client.net.HttpRequestService in project interlok by adaptris.
the class ShortCutJettyResponseTest method testService.
@Test
public void testService() throws Exception {
HttpConnection connection = createConnection(Integer.parseInt(PROPERTIES.getProperty(JETTY_HTTP_PORT)));
MockMessageProducer mockProducer = new StaticMockMessageProducer();
mockProducer.getMessages().clear();
JettyMessageConsumer consumer = JettyHelper.createConsumer(URL_TO_POST_TO);
PoolingWorkflow workflow = new PoolingWorkflow();
workflow.setShutdownWaitTime(new TimeInterval(1L, TimeUnit.SECONDS));
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.getServiceCollection().add(new ShortCutJettyResponse());
// Workflow won't get to this before we get the response.
workflow.getServiceCollection().add(new WaitService(new TimeInterval(10L, TimeUnit.SECONDS)));
workflow.addInterceptor(new JettyPoolingWorkflowInterceptor());
Channel channel = JettyHelper.createChannel(connection, workflow);
HttpRequestService service = JettyHelper.createService(connection.getPort());
try {
start(channel);
AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(XML_PAYLOAD);
msg.addMetadata(HttpConsumerTest.CONTENT_TYPE_METADATA_KEY, "text/xml");
long start = System.currentTimeMillis();
ExampleServiceCase.execute(service, msg);
;
long end = System.currentTimeMillis();
assertTrue(end - start < TimeUnit.SECONDS.toMillis(10));
} finally {
stop(channel);
}
}
use of com.adaptris.core.http.client.net.HttpRequestService in project interlok by adaptris.
the class JettyNoBacklogInterceptorTest method testInterceptor.
@Test
public void testInterceptor() throws Exception {
int jettyPort = PortManager.nextUnusedPort(Integer.parseInt(PROPERTIES.getProperty(JETTY_HTTP_PORT)));
HttpConnection connection = createConnection(jettyPort);
JettyMessageConsumer consumer = JettyHelper.createConsumer(URL_TO_POST_TO);
PoolingWorkflow workflow = new PoolingWorkflow();
workflow.setPoolSize(1);
workflow.addInterceptor(new JettyPoolingWorkflowInterceptor());
workflow.addInterceptor(new JettyNoBacklogInterceptor());
workflow.setShutdownWaitTime(new TimeInterval(1L, TimeUnit.SECONDS));
workflow.setConsumer(consumer);
workflow.getServiceCollection().add(new WaitService(new TimeInterval(3L, TimeUnit.SECONDS)));
Channel channel = JettyHelper.createChannel(connection, workflow);
final HttpRequestService httpService = new HttpRequestService();
httpService.setUrl("http://localhost:" + connection.getPort() + URL_TO_POST_TO);
httpService.setContentType("text/xml");
HttpRequestService expect503 = DefaultMarshaller.roundTrip(httpService);
try {
start(channel);
new Thread(runnableWrapper(httpService)).start();
Awaitility.await().atMost(Duration.ofSeconds(5)).with().pollInterval(Duration.ofMillis(100)).until(() -> workflow.currentlyActiveObjects() == 1);
// LifecycleHelper.waitQuietly(500);
// should be waiting in the WaitService.
ExampleServiceCase.execute(expect503, AdaptrisMessageFactory.getDefaultInstance().newMessage(XML_PAYLOAD));
fail();
} catch (ServiceException expected) {
assertEquals(ProduceException.class, expected.getCause().getClass());
assertTrue(expected.getCause().getMessage().contains("503"));
} finally {
stop(channel);
PortManager.release(jettyPort);
}
}
use of com.adaptris.core.http.client.net.HttpRequestService 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);
}
}
Aggregations