use of com.adaptris.core.services.metadata.PayloadFromTemplateService in project interlok by adaptris.
the class MultiProducerWorkflowTest method testHandleChannelUnavailable_bug2343.
@Test
public void testHandleChannelUnavailable_bug2343() throws Exception {
MockMessageProducer mock1 = new MockMessageProducer();
MockMessageProducer mock2 = new MockMessageProducer();
final MockChannel channel = createChannel(Arrays.asList(new AdaptrisMessageProducer[] { mock1, mock2 }), Arrays.asList(new Service[] { new PayloadFromTemplateService().withTemplate(MODIFIED_PAYLOAD) }));
try {
MultiProducerWorkflow workflow = (MultiProducerWorkflow) channel.getWorkflowList().get(0);
workflow.setUseProcessedMessage(true);
workflow.setChannelUnavailableWaitInterval(new TimeInterval(1200L, TimeUnit.MILLISECONDS));
channel.prepare();
channel.requestStart();
AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(ORIGINAL_PAYLOAD);
channel.toggleAvailability(false);
Timer t = new Timer();
t.schedule(new TimerTask() {
@Override
public void run() {
channel.toggleAvailability(true);
}
}, 500);
workflow.onAdaptrisMessage(msg);
log.debug("After workflow.onMessage()");
assertEquals(1, mock1.getMessages().size());
assertEquals(MODIFIED_PAYLOAD, mock1.getMessages().get(0).getContent());
assertEquals(1, mock2.getMessages().size());
assertEquals(MODIFIED_PAYLOAD, mock2.getMessages().get(0).getContent());
t.cancel();
} finally {
channel.requestClose();
}
}
use of com.adaptris.core.services.metadata.PayloadFromTemplateService 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.services.metadata.PayloadFromTemplateService in project interlok by adaptris.
the class StandardResponseProducerTest method testResponseWithZeroLengthPayload.
@Test
public void testResponseWithZeroLengthPayload() throws Exception {
StandardResponseProducer responder = new StandardResponseProducer(HttpStatus.OK_200);
PayloadFromTemplateService pms = new PayloadFromTemplateService();
pms.setTemplate("");
HttpConnection httpConnection = createConnection();
Channel c = createChannel(httpConnection, createWorkflow(createConsumer(URL_TO_POST_TO), new MockMessageProducer(), new ServiceList(new Service[] { pms, new StandaloneProducer(responder) })));
StandaloneRequestor requestor = createRequestor(httpConnection.getPort());
AdaptrisMessage msg = createMessage();
try {
c.requestStart();
start(requestor);
requestor.doService(msg);
assertNotSame(TEXT, msg.getContent());
} finally {
c.requestClose();
stop(requestor);
PortManager.release(httpConnection.getPort());
}
}
use of com.adaptris.core.services.metadata.PayloadFromTemplateService in project interlok by adaptris.
the class StandardResponseProducerTest method testResponse_MultipleAttempts.
@Test
public void testResponse_MultipleAttempts() throws Exception {
StandardResponseProducer r1 = new StandardResponseProducer(HttpStatus.OK_200);
// 2nd responder will not fire...
StandardResponseProducer r2 = new StandardResponseProducer(HttpStatus.INTERNAL_ERROR_500);
PayloadFromTemplateService pms = new PayloadFromTemplateService();
pms.setTemplate("");
HttpConnection httpConnection = createConnection();
Channel c = createChannel(httpConnection, createWorkflow(createConsumer(URL_TO_POST_TO), new MockMessageProducer(), new ServiceList(new Service[] { pms, new StandaloneProducer(r1), new StandaloneProducer(r2) })));
StandaloneRequestor requestor = createRequestor(httpConnection.getPort());
AdaptrisMessage msg = createMessage();
try {
c.requestStart();
start(requestor);
requestor.doService(msg);
assertNotSame(TEXT, msg.getContent());
} finally {
c.requestClose();
stop(requestor);
PortManager.release(httpConnection.getPort());
}
}
use of com.adaptris.core.services.metadata.PayloadFromTemplateService 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