use of com.adaptris.core.http.jetty.JettyMessageConsumer 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()));
}
use of com.adaptris.core.http.jetty.JettyMessageConsumer in project interlok by adaptris.
the class StandardHttpProducerTest method testProduce_WithMetadataUsernamePassword.
@Test
public void testProduce_WithMetadataUsernamePassword() throws Exception {
String threadName = Thread.currentThread().getName();
Thread.currentThread().setName(getName());
ConfigurableSecurityHandler csh = new ConfigurableSecurityHandler();
HashLoginServiceFactory hsl = new HashLoginServiceFactory("InterlokJetty", PROPERTIES.getProperty(HttpConsumerTest.JETTY_USER_REALM));
csh.setLoginService(hsl);
SecurityConstraint securityConstraint = new SecurityConstraint();
securityConstraint.setMustAuthenticate(true);
securityConstraint.setRoles("user");
csh.setSecurityConstraints(Arrays.asList(securityConstraint));
HttpConnection jc = HttpHelper.createConnection();
jc.setSecurityHandler(csh);
MockMessageProducer mockProducer = new MockMessageProducer();
JettyMessageConsumer consumer = JettyHelper.createConsumer(HttpHelper.URL_TO_POST_TO);
Channel channel = JettyHelper.createChannel(jc, consumer, mockProducer);
MetadataUsernamePassword auth = new MetadataUsernamePassword();
auth.setUsernameMetadataKey("user-key");
auth.setPasswordMetadataKey("pass-key");
StandardHttpProducer stdHttp = new StandardHttpProducer().withURL(HttpHelper.createURL(channel));
stdHttp.setIgnoreServerResponseCode(false);
stdHttp.registerConnection(new NullConnection());
stdHttp.setAuthenticator(auth);
try {
start(channel);
AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(TEXT);
msg.addMetadata("user-key", getName());
msg.addMetadata("pass-key", getName());
start(stdHttp);
AdaptrisMessage reply = stdHttp.request(msg);
waitForMessages(mockProducer, 1);
assertEquals(TEXT, mockProducer.getMessages().get(0).getContent());
} finally {
stop(stdHttp);
HttpHelper.stopChannelAndRelease(channel);
Thread.currentThread().setName(threadName);
}
}
use of com.adaptris.core.http.jetty.JettyMessageConsumer 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.http.jetty.JettyMessageConsumer 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());
}
Aggregations