use of com.adaptris.core.http.jetty.JettyMessageConsumer in project interlok by adaptris.
the class StandardHttpProducerTest method testProduce_WithDynamicUsernamePassword.
@Test
public void testProduce_WithDynamicUsernamePassword() 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);
String password = Password.encode(getName(), Password.PORTABLE_PASSWORD);
HttpAuthenticator auth = new DynamicBasicAuthorizationHeader(getName(), password);
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);
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 HttpRequestServiceTest method testProduce_WithUsernamePassword.
@Test
public void testProduce_WithUsernamePassword() 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);
HttpAuthenticator auth = buildAuthenticator(getName(), getName());
HttpRequestService service = new HttpRequestService(HttpHelper.createProduceDestination(channel)).withAuthenticator(auth).withMethod("POST");
AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(TEXT);
try {
start(channel);
execute(service, msg);
waitForMessages(mockProducer, 1);
assertEquals(TEXT, mockProducer.getMessages().get(0).getContent());
} finally {
HttpHelper.stopChannelAndRelease(channel);
Thread.currentThread().setName(threadName);
}
}
use of com.adaptris.core.http.jetty.JettyMessageConsumer 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.http.jetty.JettyMessageConsumer 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.http.jetty.JettyMessageConsumer 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());
}
Aggregations