use of com.adaptris.core.ServiceList in project interlok by adaptris.
the class StandardHttpProducerTest 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);
ServiceList sl = new ServiceList();
PayloadFromTemplateService pms = new PayloadFromTemplateService().withTemplate(TEXT);
sl.add(pms);
sl.add(new StandaloneProducer(new StandardResponseProducer(HttpStatus.OK_200)));
Channel c = createChannel(jc, createWorkflow(mc, mock, sl));
StandardWorkflow workflow = (StandardWorkflow) c.getWorkflowList().get(0);
StandardHttpProducer stdHttp = new StandardHttpProducer().withURL(HttpHelper.createURL(c));
stdHttp.setMethodProvider(new ConfiguredRequestMethodProvider(RequestMethodProvider.RequestMethod.GET));
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));
assertEquals(TEXT, msg.getContent());
}
use of com.adaptris.core.ServiceList 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.ServiceList in project interlok by adaptris.
the class StandardHttpProducerTest 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()));
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));
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("POST", m2.getMetadataValue(CoreConstants.HTTP_METHOD));
assertEquals(TEXT, msg.getContent());
}
use of com.adaptris.core.ServiceList in project interlok by adaptris.
the class HttpRequestServiceTest method testService_WithMetadataMethod.
@Test
public void testService_WithMetadataMethod() 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("%message{httpMethod}");
AdaptrisMessage msg = new DefaultMessageFactory().newMessage();
msg.addMetadata("httpMethod", "get");
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.ServiceList 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);
}
}
Aggregations