use of com.adaptris.core.http.jetty.JettyMessageConsumer in project interlok by adaptris.
the class HttpHelper method createAndStartChannel.
public static Channel createAndStartChannel(MockMessageProducer mock, HttpStatusProvider.HttpStatus status) throws Exception {
JettyMessageConsumer mc = createConsumer(URL_TO_POST_TO);
mc.setHeaderHandler(new MetadataHeaderHandler());
HttpConnection jc = createConnection();
Channel c = createChannel(jc, createWorkflow(mc, mock, new ServiceList(new Service[] { new StandaloneProducer(new StandardResponseProducer(status)) })));
start(c);
return c;
}
use of com.adaptris.core.http.jetty.JettyMessageConsumer in project interlok by adaptris.
the class HttpRequestServiceTest 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);
StandardResponseProducer responder = new StandardResponseProducer(HttpStatus.OK_200);
responder.setSendPayload(false);
Channel c = createChannel(jc, createWorkflow(mc, mock, new ServiceList(new Service[] { new StandaloneProducer(responder) })));
HttpRequestService service = new HttpRequestService(HttpHelper.createProduceDestination(c)).withMethod("POST");
AdaptrisMessage msg = new DefaultMessageFactory().newMessage(TEXT);
try {
start(c);
execute(service, msg);
waitForMessages(mock, 1);
} finally {
HttpHelper.stopChannelAndRelease(c);
}
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.http.jetty.JettyMessageConsumer in project interlok by adaptris.
the class HttpRequestServiceTest method testRequest_PostMethod_ZeroBytes.
@Test
public void testRequest_PostMethod_ZeroBytes() 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("POST");
AdaptrisMessage msg = new DefaultMessageFactory().newMessage();
try {
start(c);
execute(service, msg);
waitForMessages(mock, 1);
} finally {
HttpHelper.stopChannelAndRelease(c);
}
assertEquals(1, mock.messageCount());
AdaptrisMessage m2 = mock.getMessages().get(0);
assertEquals("POST", m2.getMetadataValue(CoreConstants.HTTP_METHOD));
assertEquals(TEXT, msg.getContent());
}
use of com.adaptris.core.http.jetty.JettyMessageConsumer in project interlok by adaptris.
the class WorkflowManagerTest method testJettyInterceptor_NotAddedTo_StandardWorkflow.
@Test
public void testJettyInterceptor_NotAddedTo_StandardWorkflow() throws Exception {
String adapterName = this.getClass().getSimpleName() + "." + getName();
Adapter adapter = createAdapter(adapterName);
AdapterManager adapterManager = new AdapterManager(adapter);
Channel channel = createChannel("c1");
ChannelManager channelManager = new ChannelManager(channel, adapterManager);
StandardWorkflow workflow = createWorkflow("w1");
workflow.setConsumer(new JettyMessageConsumer());
new WorkflowManager(workflow, channelManager);
assertEquals(2, workflow.getInterceptors().size());
assertEquals(MessageMetricsInterceptor.class, workflow.getInterceptors().get(0).getClass());
assertEquals(InFlightWorkflowInterceptor.class, workflow.getInterceptors().get(1).getClass());
}
use of com.adaptris.core.http.jetty.JettyMessageConsumer in project interlok by adaptris.
the class StandardHttpProducerTest method testRequest_Get_ExpectHeader.
// HttpURLConnection doesn't support the Expect: 102-Processing
// So this should throw a Produce Exception
@Test
public void testRequest_Get_ExpectHeader() throws Exception {
MockMessageProducer mock = new MockMessageProducer();
HttpConnection jc = HttpHelper.createConnection();
JettyMessageConsumer mc = createConsumer(HttpHelper.URL_TO_POST_TO);
mc.setSendProcessingInterval(new TimeInterval(100L, TimeUnit.MILLISECONDS));
ServiceList services = new ServiceList();
services.add(new PayloadFromTemplateService().withTemplate(TEXT));
services.add(new WaitService(new TimeInterval(2L, TimeUnit.SECONDS)));
services.add(new StandaloneProducer(new StandardResponseProducer(HttpStatus.OK_200)));
Channel c = createChannel(jc, createWorkflow(mc, mock, services));
StandardWorkflow workflow = (StandardWorkflow) c.getWorkflowList().get(0);
workflow.getServiceCollection().add(new StandaloneProducer(new StandardResponseProducer(HttpStatus.OK_200)));
StandardHttpProducer stdHttp = new StandardHttpProducer().withURL(HttpHelper.createURL(c));
;
stdHttp.setMethodProvider(new ConfiguredRequestMethodProvider(RequestMethodProvider.RequestMethod.GET));
stdHttp.setRequestHeaderProvider(new ConfiguredRequestHeaders().withHeaders(new KeyValuePair(HttpConstants.EXPECT, "102-Processing")));
StandaloneRequestor producer = new StandaloneRequestor(stdHttp);
AdaptrisMessage msg = new DefaultMessageFactory().newMessage(ALT_TEXT);
try {
start(c);
start(producer);
producer.doService(msg);
fail();
} catch (ProduceException | ServiceException e) {
assertTrue(e.getMessage().contains("Failed to send payload, got 102"));
} finally {
stop(c);
stop(producer);
}
}
Aggregations