use of com.adaptris.core.StandaloneRequestor in project interlok by adaptris.
the class StandardHttpProducerTest method testRequest_TraceMethod_AlwaysSendPayload.
@Test
public void testRequest_TraceMethod_AlwaysSendPayload() 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);
workflow.getServiceCollection().add(new StandaloneProducer(new StandardResponseProducer(HttpStatus.OK_200)));
StandardHttpProducer stdHttp = new StandardHttpProducer().withURL(HttpHelper.createURL(c));
;
stdHttp.setMethodProvider(new ConfiguredRequestMethodProvider(RequestMethodProvider.RequestMethod.TRACE));
stdHttp.setAlwaysSendPayload(true);
StandaloneRequestor producer = new StandaloneRequestor(stdHttp);
AdaptrisMessage msg = new DefaultMessageFactory().newMessage(ALT_TEXT);
try {
start(c);
start(producer);
producer.doService(msg);
waitForMessages(mock, 1);
} finally {
stop(c);
stop(producer);
}
assertEquals(1, mock.messageCount());
AdaptrisMessage m2 = mock.getMessages().get(0);
assertEquals("TRACE", m2.getMetadataValue(CoreConstants.HTTP_METHOD));
assertEquals(0, m2.getSize());
}
use of com.adaptris.core.StandaloneRequestor in project interlok by adaptris.
the class StandardHttpProducerTest method testRequest_EmptyReply.
@Test
public void testRequest_EmptyReply() 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);
StandardResponseProducer responder = new StandardResponseProducer(HttpStatus.OK_200);
responder.setSendPayload(false);
workflow.getServiceCollection().add(new StandaloneProducer(responder));
StandardHttpProducer stdHttp = new StandardHttpProducer().withURL(HttpHelper.createURL(c));
stdHttp.setMethodProvider(new ConfiguredRequestMethodProvider(RequestMethodProvider.RequestMethod.POST));
stdHttp.setConnectTimeout(new TimeInterval(60L, TimeUnit.SECONDS));
stdHttp.setReadTimeout(new TimeInterval(60L, TimeUnit.SECONDS));
StandaloneRequestor producer = new StandaloneRequestor(stdHttp);
producer.setReplyTimeout(new TimeInterval(60L, TimeUnit.SECONDS));
AdaptrisMessage msg = new DefaultMessageFactory().newMessage(TEXT);
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(0, msg.getSize());
}
use of com.adaptris.core.StandaloneRequestor in project interlok by adaptris.
the class RetryFromJettyTest method testReport_Broken.
@Test
public void testReport_Broken() throws Exception {
RetryFromJetty retrier = create();
try {
retrier.setRetryStore(new BrokenRetryStore());
start(retrier);
String url = jettyHelper.buildUrl(RetryFromJetty.DEFAULT_REPORTING_ENDPOINT);
AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage();
StandardHttpProducer http = buildProducer(url);
http.setIgnoreServerResponseCode(true);
http.setMethodProvider(new ConfiguredRequestMethodProvider(RequestMethodProvider.RequestMethod.GET));
ExampleServiceCase.execute(new StandaloneRequestor(http), msg);
assertEquals(RetryFromJetty.HTTP_ERROR, msg.getMetadataValue(CoreConstants.HTTP_PRODUCER_RESPONSE_CODE));
} finally {
stop(retrier);
}
}
use of com.adaptris.core.StandaloneRequestor in project interlok by adaptris.
the class RetryFromJettyTest method testRetry_NotFound.
@Test
public void testRetry_NotFound() throws Exception {
RetryFromJetty retrier = create();
StandardWorkflow workflow = createWorkflow();
try {
MockMessageProducer workflowProducer = (MockMessageProducer) workflow.getProducer();
retrier.addWorkflow(workflow);
retrier.addWorkflow(createWorkflow());
start(workflow, retrier);
AdaptrisMessage baseMsg = AdaptrisMessageFactory.getDefaultInstance().newMessage();
baseMsg.addMetadata(Workflow.WORKFLOW_ID_KEY, workflow.obtainWorkflowId());
retryStore.write(baseMsg);
assertNotNull(retryStore.getMetadata(baseMsg.getUniqueId()));
// This should result in a msgId that isn't found; so we get a 500...
AdaptrisMessage triggerMsg = AdaptrisMessageFactory.getDefaultInstance().newMessage();
String url = jettyHelper.buildUrl(RetryFromJetty.DEFAULT_ENDPOINT_PREFIX + triggerMsg.getUniqueId());
StandardHttpProducer http = buildProducer(url);
http.setIgnoreServerResponseCode(true);
ExampleServiceCase.execute(new StandaloneRequestor(http), triggerMsg);
assertEquals(RetryFromJetty.HTTP_ERROR, triggerMsg.getMetadataValue(CoreConstants.HTTP_PRODUCER_RESPONSE_CODE));
} finally {
stop(retrier, workflow);
}
}
use of com.adaptris.core.StandaloneRequestor in project interlok by adaptris.
the class RetryFromJettyTest method testDelete_BadRequest.
@Test
public void testDelete_BadRequest() throws Exception {
RetryFromJetty retrier = create();
try {
start(retrier);
AdaptrisMessage baseMsg = AdaptrisMessageFactory.getDefaultInstance().newMessage();
retryStore.write(baseMsg);
assertNotNull(retryStore.getMetadata(baseMsg.getUniqueId()));
// we're going to use a POST but with the correct URL.
// so should be a BAD request.
AdaptrisMessage triggerMsg = AdaptrisMessageFactory.getDefaultInstance().newMessage();
String url = jettyHelper.buildUrl(RetryFromJetty.DEFAULT_DELETE_PREFIX + baseMsg.getUniqueId());
StandardHttpProducer http = buildProducer(url);
http.setIgnoreServerResponseCode(true);
http.setMethodProvider(new ConfiguredRequestMethodProvider(RequestMethod.POST));
ExampleServiceCase.execute(new StandaloneRequestor(http), triggerMsg);
assertEquals(RetryFromJetty.HTTP_BAD, triggerMsg.getMetadataValue(CoreConstants.HTTP_PRODUCER_RESPONSE_CODE));
} finally {
stop(retrier);
}
}
Aggregations