use of com.adaptris.core.common.MetadataStreamOutputParameter in project interlok by adaptris.
the class StandardHttpProducerTest method testRequest_ErrorCode_NullResponseBody.
@Test
public void testRequest_ErrorCode_NullResponseBody() throws Exception {
// INTERLOK-3527 - make sure we don't get an NPE.
MockMessageProducer mock = new MockMessageProducer();
HttpConnection jc = HttpHelper.createConnection();
JettyMessageConsumer mc = createConsumer(HttpHelper.URL_TO_POST_TO);
ServiceList sl = new ServiceList();
// To trigger the bug we need the getErrorStream() method to return null. A response code > 400 will not.
sl.add(new StandaloneProducer(new StandardResponseProducer(HttpStatus.SWITCH_PROTOCOL_101)));
Channel c = createChannel(jc, createWorkflow(mc, mock, sl));
StandardHttpProducer stdHttp = new StandardHttpProducer().withURL(HttpHelper.createURL(c));
stdHttp.setMethodProvider(new ConfiguredRequestMethodProvider(RequestMethodProvider.RequestMethod.GET));
stdHttp.setIgnoreServerResponseCode(true);
// Metadata stream is the source of the bug, so lets use it here rather than the payload default.
stdHttp.setResponseBody(new MetadataStreamOutputParameter());
StandaloneRequestor producer = new StandaloneRequestor(stdHttp);
AdaptrisMessage msg = new DefaultMessageFactory().newMessage();
try {
start(c);
start(producer);
producer.doService(msg);
waitForMessages(mock, 1);
} finally {
HttpHelper.stopChannelAndRelease(c);
stop(producer);
}
assertEquals(1, mock.messageCount());
AdaptrisMessage m2 = mock.getMessages().get(0);
assertEquals("GET", m2.getMetadataValue(CoreConstants.HTTP_METHOD));
}
use of com.adaptris.core.common.MetadataStreamOutputParameter in project interlok by adaptris.
the class StandardHttpProducerTest method testRequest_Post_ZeroBytes_ReplyToMetadata.
@Test
public void testRequest_Post_ZeroBytes_ReplyToMetadata() 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()));
StandardWorkflow workflow = (StandardWorkflow) c.getWorkflowList().get(0);
PayloadFromTemplateService pms = new PayloadFromTemplateService().withTemplate(TEXT);
workflow.getServiceCollection().add(pms);
workflow.getServiceCollection().add(new StandaloneProducer(new StandardResponseProducer(HttpStatus.OK_200)));
StandardHttpProducer stdHttp = new StandardHttpProducer().withURL(HttpHelper.createURL(c));
stdHttp.setMethodProvider(new ConfiguredRequestMethodProvider(RequestMethodProvider.RequestMethod.POST));
stdHttp.setResponseBody(new MetadataStreamOutputParameter(getName()));
StandaloneRequestor producer = new StandaloneRequestor(stdHttp);
AdaptrisMessage msg = new DefaultMessageFactory().newMessage();
try {
start(c);
start(producer);
producer.doService(msg);
waitForMessages(mock, 1);
} finally {
HttpHelper.stopChannelAndRelease(c);
stop(producer);
}
assertEquals(1, mock.messageCount());
AdaptrisMessage m2 = mock.getMessages().get(0);
assertNotSame(TEXT, msg.getContent());
assertEquals(0, msg.getSize());
assertTrue(msg.headersContainsKey(getName()));
assertEquals(TEXT, msg.getMetadataValue(getName()));
}
Aggregations