use of com.adaptris.core.ProduceException in project interlok by adaptris.
the class StandardResponseProducer method doProduce.
@Override
public void doProduce(AdaptrisMessage msg, String endpint) throws ProduceException {
JettyWrapper wrapper = JettyWrapper.unwrap(msg);
try {
wrapper.lock();
if (responseAlreadyAttempted(wrapper)) {
log.debug("No HttpServletResponse in object metadata, nothing to do");
return;
}
HttpServletResponse response = wrapper.getResponse();
getResponseHeaderProvider().addHeaders(msg, response);
String contentType = getContentTypeProvider().getContentType(msg);
response.setContentType(contentType);
response.setStatus(getStatus(msg).getCode());
commitResponse(msg, response);
wrapper.setResponse(null);
} catch (Exception e) {
throw ExceptionHelper.wrapProduceException(e);
} finally {
wrapper.unlock();
}
}
use of com.adaptris.core.ProduceException in project interlok by adaptris.
the class JdbcStoredProcedureProducer method doRequest.
@Override
protected AdaptrisMessage doRequest(AdaptrisMessage msg, String endpoint, long timeout) throws ProduceException {
Connection connection = null;
JdbcResult results = null;
try {
connection = getConnection(msg);
StoredProcedure storedProcedure = new StoredProcedure();
storedProcedure.setConnection(connection);
storedProcedure.setName(endpoint);
storedProcedure.setStatementCreator(getStatementCreator());
storedProcedure.setParameters(parseInParameters(msg));
storedProcedure.setStatementExecutor(getStatementExecutor());
storedProcedure.setTimeout(defaultTimeout());
storedProcedure.setAdaptrisMessage(msg);
storedProcedure.setResultSetTranslator(getResultSetTranslator());
results = storedProcedure.execute();
parseOutParameters(msg, results.getParameters());
commit(connection, msg);
} catch (Exception e) {
rollback(connection, msg);
throw new ProduceException(e);
} finally {
JdbcUtil.closeQuietly(results);
JdbcUtil.closeQuietly(connection);
}
return msg;
}
use of com.adaptris.core.ProduceException in project interlok by adaptris.
the class StandardHttpProducerTest method testRequest_Get_ExpectHeader.
// HttpURLConnection doesn't support the Expect: 102-Processing
// So this should throw a Produce Exception
@Test
public void testRequest_Get_ExpectHeader() throws Exception {
MockMessageProducer mock = new MockMessageProducer();
HttpConnection jc = HttpHelper.createConnection();
JettyMessageConsumer mc = createConsumer(HttpHelper.URL_TO_POST_TO);
mc.setSendProcessingInterval(new TimeInterval(100L, TimeUnit.MILLISECONDS));
ServiceList services = new ServiceList();
services.add(new PayloadFromTemplateService().withTemplate(TEXT));
services.add(new WaitService(new TimeInterval(2L, TimeUnit.SECONDS)));
services.add(new StandaloneProducer(new StandardResponseProducer(HttpStatus.OK_200)));
Channel c = createChannel(jc, createWorkflow(mc, mock, services));
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.GET));
stdHttp.setRequestHeaderProvider(new ConfiguredRequestHeaders().withHeaders(new KeyValuePair(HttpConstants.EXPECT, "102-Processing")));
StandaloneRequestor producer = new StandaloneRequestor(stdHttp);
AdaptrisMessage msg = new DefaultMessageFactory().newMessage(ALT_TEXT);
try {
start(c);
start(producer);
producer.doService(msg);
fail();
} catch (ProduceException | ServiceException e) {
assertTrue(e.getMessage().contains("Failed to send payload, got 102"));
} finally {
stop(c);
stop(producer);
}
}
use of com.adaptris.core.ProduceException in project interlok by adaptris.
the class HttpConsumerTest method testDestinationNotFound.
@Test
public void testDestinationNotFound() throws Exception {
HttpConnection connection = createConnection(null);
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");
stop(httpProducer);
String pd = createProduceDestinationUrl(connection.getPort());
pd += "/some/unknownURL";
httpProducer.setUrl(pd);
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();
assertEquals("Reply Response Code Value", HttpURLConnection.HTTP_NOT_FOUND, rc);
} catch (ProduceException e) {
if (!(e.getCause() instanceof FileNotFoundException)) {
throw e;
}
} finally {
stop(httpProducer);
adapter.requestClose();
PortManager.release(connection.getPort());
}
}
Aggregations