use of com.adaptris.core.ServiceList in project interlok by adaptris.
the class StandardResponseProducerTest method testResponse_CompositeResponseHeaders.
@Test
public void testResponse_CompositeResponseHeaders() throws Exception {
StandardResponseProducer responder = new StandardResponseProducer(HttpStatus.OK_200);
responder.setSendPayload(false);
CompositeResponseHeaderProvider provider = new CompositeResponseHeaderProvider(new MetadataResponseHeaderProvider(new RegexMetadataFilter()), new ConfiguredResponseHeaderProvider(new KeyValuePair("Hello", "World")));
responder.setResponseHeaderProvider(provider);
AddMetadataService meta = new AddMetadataService();
meta.addMetadataElement(getName(), getName());
ServiceList sl = new ServiceList(new Service[] { meta, new StandaloneProducer(responder) });
HttpConnection httpConnection = createConnection();
Channel c = createChannel(httpConnection, createWorkflow(createConsumer(URL_TO_POST_TO), new MockMessageProducer(), sl));
StandaloneRequestor requestor = createRequestor(httpConnection.getPort());
AdaptrisMessage msg = createMessage();
try {
c.requestStart();
start(requestor);
requestor.doService(msg);
assertNotSame(TEXT, msg.getContent());
assertTrue(msg.containsKey(getName()));
assertTrue(msg.containsKey("Hello"));
} finally {
c.requestClose();
stop(requestor);
PortManager.release(httpConnection.getPort());
}
}
use of com.adaptris.core.ServiceList 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.ServiceList in project interlok by adaptris.
the class StandardResponseProducerTest method testResponse_MetadataResponseHeaders.
@Test
public void testResponse_MetadataResponseHeaders() throws Exception {
StandardResponseProducer responder = new StandardResponseProducer(HttpStatus.OK_200);
RegexMetadataFilter filter = new RegexMetadataFilter();
filter.addIncludePattern(METADATA_REGEXP);
responder.setResponseHeaderProvider(new MetadataResponseHeaderProvider(filter));
AddMetadataService addMetadata = new AddMetadataService(Arrays.asList(new MetadataElement[] { new MetadataElement(CUSTOM_HEADER1, CUSTOM_VALUE1), new MetadataElement(CUSTOM_HEADER2, CUSTOM_VALUE2) }));
HttpConnection httpConnection = createConnection();
Channel c = createChannel(httpConnection, createWorkflow(createConsumer(URL_TO_POST_TO), new MockMessageProducer(), new ServiceList(new Service[] { addMetadata, new StandaloneProducer(responder) })));
StandaloneRequestor requestor = createRequestor(httpConnection.getPort());
AdaptrisMessage msg = createMessage();
try {
c.requestStart();
start(requestor);
requestor.doService(msg);
assertEquals(TEXT, msg.getContent());
assertTrue(msg.containsKey(CUSTOM_HEADER1));
assertTrue(msg.containsKey(CUSTOM_HEADER2));
assertEquals(CUSTOM_VALUE1, msg.getMetadataValue(CUSTOM_HEADER1));
assertEquals(CUSTOM_VALUE2, msg.getMetadataValue(CUSTOM_HEADER2));
} finally {
c.requestClose();
stop(requestor);
PortManager.release(httpConnection.getPort());
}
}
use of com.adaptris.core.ServiceList 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.ServiceList in project interlok by adaptris.
the class StandardResponseProducerTest method testResponse_MetadataContentType_MissingMetadata.
@Test
public void testResponse_MetadataContentType_MissingMetadata() throws Exception {
StandardResponseProducer responder = new StandardResponseProducer(HttpStatus.OK_200);
responder.setContentTypeProvider(new MetadataContentTypeProvider("MyContentType"));
HttpConnection httpConnection = createConnection();
Channel c = createChannel(httpConnection, createWorkflow(createConsumer(URL_TO_POST_TO), new MockMessageProducer(), new ServiceList(new Service[] { new StandaloneProducer(responder) })));
StandaloneRequestor requestor = createRequestor(httpConnection.getPort());
AdaptrisMessage msg = createMessage();
try {
c.requestStart();
start(requestor);
requestor.doService(msg);
assertEquals(TEXT, msg.getContent());
} finally {
c.requestClose();
stop(requestor);
PortManager.release(httpConnection.getPort());
}
}
Aggregations