use of com.adaptris.core.StandaloneProducer in project interlok by adaptris.
the class HttpRequestServiceTest method testRequest_GetMethod_NonZeroBytes_WithErrorResponse.
@Test
public void testRequest_GetMethod_NonZeroBytes_WithErrorResponse() 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.UNAUTHORIZED_401)) })));
HttpRequestService service = new HttpRequestService(HttpHelper.createProduceDestination(c)).withMethod("GET");
AdaptrisMessage msg = new DefaultMessageFactory().newMessage(TEXT);
try {
start(c);
execute(service, msg);
fail();
} catch (ServiceException expect) {
} finally {
stop(c);
}
}
use of com.adaptris.core.StandaloneProducer in project interlok by adaptris.
the class HttpRequestServiceTest method testRequest_GetMethod_ZeroBytes.
@Test
public void testRequest_GetMethod_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("GET");
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("GET", m2.getMetadataValue(CoreConstants.HTTP_METHOD));
assertEquals(TEXT, msg.getContent());
}
use of com.adaptris.core.StandaloneProducer in project interlok by adaptris.
the class StandardResponseProducerTest method testResponse_NoOpResponseHeaders.
@Test
public void testResponse_NoOpResponseHeaders() throws Exception {
StandardResponseProducer responder = new StandardResponseProducer(HttpStatus.OK_200);
responder.setResponseHeaderProvider(new NoOpResponseHeaderProvider());
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());
}
}
use of com.adaptris.core.StandaloneProducer in project interlok by adaptris.
the class StandardResponseProducerTest method testNoObjectMetadata.
@Test
public void testNoObjectMetadata() throws Exception {
StandardResponseProducer responder = new StandardResponseProducer(HttpStatus.OK_200);
StandaloneProducer p = new StandaloneProducer(responder);
try {
// INTERLOK-3329 For coverage so the prepare() warning is executed 2x
LifecycleHelper.prepare(p);
start(p);
AdaptrisMessage msg = createMessage();
p.doService(msg);
} finally {
stop(p);
}
}
use of com.adaptris.core.StandaloneProducer in project interlok by adaptris.
the class StandardResponseProducerTest method testResponse_MetadataContentType.
@Test
public void testResponse_MetadataContentType() throws Exception {
StandardResponseProducer responder = new StandardResponseProducer(HttpStatus.OK_200);
responder.setContentTypeProvider(new MetadataContentTypeProvider("MyContentType"));
AddMetadataService addMetadata = new AddMetadataService(Arrays.asList(new MetadataElement[] { new MetadataElement("MyContentType", "text/xml") }));
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("Content-Type"));
assertTrue(msg.getMetadataValue("Content-Type").startsWith("text/xml"));
} finally {
c.requestClose();
stop(requestor);
PortManager.release(httpConnection.getPort());
}
}
Aggregations