use of com.adaptris.core.http.jetty.JettyHelper.createChannel in project interlok by adaptris.
the class StandardHttpProducerTest 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 = getAuthenticator(getName(), getName());
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.JettyHelper.createChannel in project interlok by adaptris.
the class StandardHttpProducerTest method testProduce_WithUsernamePassword_BadCredentials.
@Test
public void testProduce_WithUsernamePassword_BadCredentials() 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 = getAuthenticator(getName(), getName());
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);
fail();
} catch (ProduceException expected) {
} finally {
stop(stdHttp);
HttpHelper.stopChannelAndRelease(channel);
Thread.currentThread().setName(threadName);
}
}
use of com.adaptris.core.http.jetty.JettyHelper.createChannel 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.JettyHelper.createChannel 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.JettyHelper.createChannel 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);
}
}
Aggregations