use of com.adaptris.core.Channel in project interlok by adaptris.
the class HttpConsumerTest method testConsumeWorkflow_PreserveObjectParams_NoPrefix.
@Test
public void testConsumeWorkflow_PreserveObjectParams_NoPrefix() throws Exception {
HttpConnection connection = createConnection(null);
MockMessageProducer mockProducer = new MockMessageProducer();
JettyMessageConsumer consumer = JettyHelper.createConsumer("/*");
consumer.setHeaderHandler(new ObjectMetadataHeaderHandler("Http_Header_"));
consumer.setParameterHandler(new ObjectMetadataParameterHandler());
Channel channel = JettyHelper.createChannel(connection, consumer, mockProducer);
try {
channel.requestStart();
AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(XML_PAYLOAD);
msg.addMetadata(CONTENT_TYPE_METADATA_KEY, "text/xml");
String dest = createProduceDestinationUrl(connection.getPort());
dest += "?queryParam1=1&queryParam2=2&queryParam3=3";
httpProducer.setUrl(dest);
start(httpProducer);
AdaptrisMessage reply = httpProducer.request(msg);
assertEquals("Reply Payloads", XML_PAYLOAD, reply.getContent());
AdaptrisMessage receivedMsg = doAssertions(mockProducer);
System.out.println("XXX - " + receivedMsg);
assertTrue(receivedMsg.containsKey(JettyConstants.JETTY_QUERY_STRING));
assertEquals("queryParam1=1&queryParam2=2&queryParam3=3", receivedMsg.getMetadataValue(JettyConstants.JETTY_QUERY_STRING));
assertEquals("1", receivedMsg.getObjectHeaders().get("queryParam1"));
assertEquals("2", receivedMsg.getObjectHeaders().get("queryParam2"));
assertEquals("3", receivedMsg.getObjectHeaders().get("queryParam3"));
} finally {
stop(httpProducer);
channel.requestClose();
PortManager.release(connection.getPort());
}
}
use of com.adaptris.core.Channel in project interlok by adaptris.
the class HttpConsumerTest method testConsume_WithACL_WithNoRoles.
@Test
public void testConsume_WithACL_WithNoRoles() throws Exception {
String threadName = Thread.currentThread().getName();
Thread.currentThread().setName(getName());
ConfigurableSecurityHandler csh = new ConfigurableSecurityHandler();
HashLoginServiceFactory hsl = new HashLoginServiceFactory("InterlokJetty", PROPERTIES.getProperty(JETTY_USER_REALM));
csh.setLoginService(hsl);
SecurityConstraint securityConstraint = new SecurityConstraint();
securityConstraint.setMustAuthenticate(true);
securityConstraint.setPaths(Arrays.asList("/"));
csh.setSecurityConstraints(Arrays.asList(securityConstraint));
HttpConnection connection = createConnection(csh);
MockMessageProducer mockProducer = new MockMessageProducer();
JettyMessageConsumer consumer = JettyHelper.createConsumer(URL_TO_POST_TO);
Channel adapter = JettyHelper.createChannel(connection, consumer, mockProducer);
try {
adapter.requestStart();
AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(XML_PAYLOAD);
msg.addMetadata("content.type", "text/xml");
httpProducer.setUserName("user");
httpProducer.setPassword("password");
httpProducer.setUrl(createProduceDestinationUrl(connection.getPort()));
start(httpProducer);
AdaptrisMessage reply = httpProducer.request(msg);
assertEquals("0 message consumed", 0, mockProducer.getMessages().size());
assertTrue("Reply Response Code present", reply.containsKey(CoreConstants.HTTP_PRODUCER_RESPONSE_CODE));
int rc = Integer.valueOf(reply.getMetadataValue(CoreConstants.HTTP_PRODUCER_RESPONSE_CODE)).intValue();
assertTrue("Reply Response Value 401 || 403", rc == HttpURLConnection.HTTP_UNAUTHORIZED || rc == HttpURLConnection.HTTP_FORBIDDEN);
} catch (Exception e) {
e.printStackTrace();
// This is expected actually,.
if (e.getCause() instanceof IOException) {
String s = ((IOException) e.getCause()).getMessage();
String httpString = "Server returned HTTP response code: ";
if (s.startsWith(httpString)) {
int rc = Integer.parseInt(s.substring(httpString.length(), httpString.length() + 3));
assertTrue(rc == HttpURLConnection.HTTP_UNAUTHORIZED || rc == HttpURLConnection.HTTP_FORBIDDEN);
} else {
throw e;
}
} else {
throw e;
}
} finally {
stop(httpProducer);
adapter.requestClose();
Thread.currentThread().setName(threadName);
PortManager.release(connection.getPort());
assertEquals(0, AdapterResourceAuthenticator.getInstance().currentAuthenticators().size());
}
}
use of com.adaptris.core.Channel in project interlok by adaptris.
the class HttpConsumerTest method testConsume_WithACL.
@Test
public void testConsume_WithACL() throws Exception {
String threadName = Thread.currentThread().getName();
Thread.currentThread().setName(getName());
ConfigurableSecurityHandler csh = new ConfigurableSecurityHandler();
HashLoginServiceFactory hsl = new HashLoginServiceFactory("InterlokJetty", PROPERTIES.getProperty(JETTY_USER_REALM));
csh.setLoginService(hsl);
csh.setAuthenticator(new BasicAuthenticatorFactory());
SecurityConstraint securityConstraint = new SecurityConstraint();
securityConstraint.setMustAuthenticate(true);
securityConstraint.setRoles("user");
securityConstraint.setConstraintName(Constraint.__BASIC_AUTH);
csh.setSecurityConstraints(Arrays.asList(securityConstraint));
HttpConnection connection = createConnection(csh);
MockMessageProducer mockProducer = new MockMessageProducer();
JettyMessageConsumer consumer = JettyHelper.createConsumer(URL_TO_POST_TO);
Channel adapter = JettyHelper.createChannel(connection, consumer, mockProducer);
try {
adapter.requestStart();
AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(XML_PAYLOAD);
msg.addMetadata("content.type", "text/xml");
httpProducer.setUserName("user");
httpProducer.setPassword("password");
httpProducer.setUrl(createProduceDestinationUrl(connection.getPort()));
start(httpProducer);
AdaptrisMessage reply = httpProducer.request(msg);
assertEquals("Reply Payloads", XML_PAYLOAD, reply.getContent());
AdaptrisMessage consumedMessage = doAssertions(mockProducer);
assertTrue(consumedMessage.headersContainsKey(JettyConstants.JETTY_USER_ROLES));
List<String> roles = Arrays.asList(consumedMessage.getMetadataValue(JettyConstants.JETTY_USER_ROLES).split(","));
assertTrue(roles.contains("user"));
assertTrue(roles.contains("anotherRole"));
} finally {
stop(httpProducer);
adapter.requestClose();
Thread.currentThread().setName(threadName);
PortManager.release(connection.getPort());
assertEquals(0, AdapterResourceAuthenticator.getInstance().currentAuthenticators().size());
}
}
use of com.adaptris.core.Channel in project interlok by adaptris.
the class HttpConsumerTest method testPoolingWorkflow_TimeoutAction_TimeoutExceeded.
@Test
public void testPoolingWorkflow_TimeoutAction_TimeoutExceeded() throws Exception {
HttpConnection connection = createConnection(null);
MockMessageProducer mockProducer = new StaticMockMessageProducer();
mockProducer.getMessages().clear();
JettyMessageConsumer consumer = JettyHelper.createConsumer(URL_TO_POST_TO);
consumer.setAdditionalDebug(false);
consumer.setTimeoutAction(new TimeoutAction(new TimeInterval(100L, TimeUnit.MILLISECONDS)));
PoolingWorkflow workflow = new PoolingWorkflow();
workflow.setShutdownWaitTime(new TimeInterval(100L, TimeUnit.MILLISECONDS));
StandardResponseProducer responder = new StandardResponseProducer(HttpStatus.OK_200);
workflow.setConsumer(consumer);
workflow.getServiceCollection().add(new WaitService(new TimeInterval(5L, TimeUnit.SECONDS)));
workflow.getServiceCollection().add(new StandaloneProducer(mockProducer));
workflow.getServiceCollection().add(new StandaloneProducer(responder));
workflow.addInterceptor(new JettyPoolingWorkflowInterceptor());
Channel channel = JettyHelper.createChannel(connection, workflow);
try {
channel.requestStart();
AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(XML_PAYLOAD);
msg.addMetadata(CONTENT_TYPE_METADATA_KEY, "text/xml");
httpProducer.setUrl(createProduceDestinationUrl(connection.getPort()));
start(httpProducer);
AdaptrisMessage reply = httpProducer.request(msg);
assertEquals(Integer.valueOf(HttpStatus.ACCEPTED_202.getStatusCode()), Integer.valueOf(reply.getMetadataValue(CoreConstants.HTTP_PRODUCER_RESPONSE_CODE)));
} finally {
stop(httpProducer);
channel.requestClose();
}
}
use of com.adaptris.core.Channel in project interlok by adaptris.
the class HttpConsumerTest method testChannelStarted_MultipleWorkflows_OneWorkflowStopped.
@Test
public void testChannelStarted_MultipleWorkflows_OneWorkflowStopped() throws Exception {
HttpConnection connection = createConnection(null);
JettyMessageConsumer consumer1 = JettyHelper.createConsumer(URL_TO_POST_TO);
StandardWorkflow workflow1 = new StandardWorkflow();
workflow1.setConsumer(consumer1);
workflow1.getServiceCollection().add(new StandaloneProducer(new StandardResponseProducer(HttpStatus.OK_200)));
Channel channel = JettyHelper.createChannel(connection, workflow1);
JettyMessageConsumer consumer2 = JettyHelper.createConsumer("/some/other/urlmapping/");
StandardWorkflow workflow2 = new StandardWorkflow();
workflow2.setConsumer(consumer2);
workflow2.getServiceCollection().add(new StandaloneProducer(new StandardResponseProducer(HttpStatus.OK_200)));
channel.getWorkflowList().add(workflow2);
try {
channel.requestStart();
AdaptrisMessage msg1 = AdaptrisMessageFactory.getDefaultInstance().newMessage(XML_PAYLOAD);
msg1.addMetadata(CONTENT_TYPE_METADATA_KEY, "text/xml");
httpProducer.setUrl(createProduceDestinationUrl(connection.getPort()));
start(httpProducer);
AdaptrisMessage reply = httpProducer.request(msg1);
assertEquals("200", reply.getMetadataValue(CoreConstants.HTTP_PRODUCER_RESPONSE_CODE));
workflow2.requestClose();
// Stopping Workflow 2 means nothing, workflow1 should still be working!
AdaptrisMessage msg2 = AdaptrisMessageFactory.getDefaultInstance().newMessage(XML_PAYLOAD);
msg1.addMetadata(CONTENT_TYPE_METADATA_KEY, "text/xml");
AdaptrisMessage reply2 = httpProducer.request(msg2);
assertEquals("200", reply2.getMetadataValue(CoreConstants.HTTP_PRODUCER_RESPONSE_CODE));
} finally {
channel.requestClose();
}
}
Aggregations