use of com.adaptris.core.ProduceException 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.ProduceException in project interlok by adaptris.
the class HttpConsumerTest method testLoopbackWithIncorrectRole.
@Test
public void testLoopbackWithIncorrectRole() 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.setRoles("admin");
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 (ProduceException e) {
// 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();
PortManager.release(connection.getPort());
Thread.currentThread().setName(threadName);
assertEquals(0, AdapterResourceAuthenticator.getInstance().currentAuthenticators().size());
}
}
use of com.adaptris.core.ProduceException in project interlok by adaptris.
the class JndiPasProducerCase method testProduceJndiOnlyObjectNotFound.
@Test
public void testProduceJndiOnlyObjectNotFound() throws Exception {
String queueName = testName.getMethodName() + "_queue";
String topicName = testName.getMethodName() + "_topic";
StandardJndiImplementation sendVendorImp = createVendorImplementation();
StandaloneProducer standaloneProducer = new StandaloneProducer(activeMqBroker.getJndiPasConnection(sendVendorImp, true, queueName, topicName), new PasProducer().withTopic(this.getClass().getSimpleName()));
try {
start(standaloneProducer);
standaloneProducer.produce(createMessage(null));
fail("Expected ProduceException");
} catch (ProduceException expected) {
} finally {
stop(standaloneProducer);
}
}
use of com.adaptris.core.ProduceException in project interlok by adaptris.
the class JndiPtpProducerCase method testProduceJndiOnlyObjectNotFound.
@Test
public void testProduceJndiOnlyObjectNotFound() throws Exception {
String queueName = testName.getMethodName() + "_queue";
String topicName = testName.getMethodName() + "_topic";
StandardJndiImplementation sendVendorImp = createVendorImplementation();
StandaloneProducer standaloneProducer = new StandaloneProducer(activeMqBroker.getJndiPtpConnection(sendVendorImp, true, queueName, topicName), new PtpProducer().withQueue((this.getClass().getSimpleName())));
try {
start(standaloneProducer);
standaloneProducer.produce(createMessage(null));
fail("Expected ProduceException");
} catch (ProduceException expected) {
} finally {
stop(standaloneProducer);
}
}
use of com.adaptris.core.ProduceException in project interlok by adaptris.
the class LargeMessageWorkflowTest method testProduceException.
@Override
@Test
public void testProduceException() throws Exception {
MockMessageProducer producer = new MockMessageProducer() {
@Override
protected void doProduce(AdaptrisMessage msg, String endpoint) throws ProduceException {
throw new ProduceException();
}
};
;
MockMessageProducer meh = new MockMessageProducer();
MockChannel channel = createChannel(producer, Arrays.asList(new Service[] { new AddMetadataService(Arrays.asList(new MetadataElement[] { new MetadataElement(METADATA_KEY, METADATA_VALUE) })), new PayloadFromTemplateService().withTemplate(PAYLOAD_2) }));
try {
LargeMessageWorkflow workflow = (LargeMessageWorkflow) channel.getWorkflowList().get(0);
channel.setMessageErrorHandler(new StandardProcessingExceptionHandler(new ServiceList(new ArrayList<Service>(Arrays.asList(new Service[] { new StandaloneProducer(meh) })))));
channel.prepare();
AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(PAYLOAD_1);
start(channel);
workflow.onAdaptrisMessage(msg);
assertEquals("Make none produced", 0, producer.getMessages().size());
assertEquals(1, meh.getMessages().size());
for (AdaptrisMessage m : meh.getMessages()) {
assertEquals(PAYLOAD_2, m.getContent());
assertTrue("Contains correct metadata key", m.containsKey(METADATA_KEY));
assertEquals(METADATA_VALUE, m.getMetadataValue(METADATA_KEY));
}
} finally {
stop(channel);
}
}
Aggregations