Search in sources :

Example 26 with ProduceException

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();
    }
}
Also used : HttpServletResponse(javax.servlet.http.HttpServletResponse) ProduceException(com.adaptris.core.ProduceException) IOException(java.io.IOException) CoreException(com.adaptris.core.CoreException)

Example 27 with ProduceException

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;
}
Also used : StoredProcedure(com.adaptris.jdbc.StoredProcedure) Connection(java.sql.Connection) JdbcResult(com.adaptris.jdbc.JdbcResult) ProduceException(com.adaptris.core.ProduceException) SQLException(java.sql.SQLException) ProduceException(com.adaptris.core.ProduceException)

Example 28 with ProduceException

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);
    }
}
Also used : DefaultMessageFactory(com.adaptris.core.DefaultMessageFactory) WaitService(com.adaptris.core.services.WaitService) StandardWorkflow(com.adaptris.core.StandardWorkflow) MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) TimeInterval(com.adaptris.util.TimeInterval) KeyValuePair(com.adaptris.util.KeyValuePair) HttpConnection(com.adaptris.core.http.jetty.HttpConnection) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) ServiceList(com.adaptris.core.ServiceList) JettyHelper.createChannel(com.adaptris.core.http.jetty.JettyHelper.createChannel) Channel(com.adaptris.core.Channel) ProduceException(com.adaptris.core.ProduceException) StandaloneRequestor(com.adaptris.core.StandaloneRequestor) ServiceException(com.adaptris.core.ServiceException) StandardResponseProducer(com.adaptris.core.http.jetty.StandardResponseProducer) JettyMessageConsumer(com.adaptris.core.http.jetty.JettyMessageConsumer) PayloadFromTemplateService(com.adaptris.core.services.metadata.PayloadFromTemplateService) StandaloneProducer(com.adaptris.core.StandaloneProducer) ConfiguredRequestMethodProvider(com.adaptris.core.http.client.ConfiguredRequestMethodProvider) HttpConsumerTest(com.adaptris.core.http.jetty.HttpConsumerTest) Test(org.junit.Test)

Example 29 with ProduceException

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());
    }
}
Also used : MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) StaticMockMessageProducer(com.adaptris.core.stubs.StaticMockMessageProducer) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) Channel(com.adaptris.core.Channel) FileNotFoundException(java.io.FileNotFoundException) Constraint(org.eclipse.jetty.util.security.Constraint) ProduceException(com.adaptris.core.ProduceException) Test(org.junit.Test)

Aggregations

ProduceException (com.adaptris.core.ProduceException)29 Test (org.junit.Test)17 AdaptrisMessage (com.adaptris.core.AdaptrisMessage)13 CoreException (com.adaptris.core.CoreException)9 MockMessageProducer (com.adaptris.core.stubs.MockMessageProducer)7 Channel (com.adaptris.core.Channel)6 StandaloneProducer (com.adaptris.core.StandaloneProducer)6 IOException (java.io.IOException)6 DefaultMessageFactory (com.adaptris.core.DefaultMessageFactory)5 File (java.io.File)5 GuidGenerator (com.adaptris.util.GuidGenerator)4 JMSException (javax.jms.JMSException)4 PtpProducer (com.adaptris.core.jms.PtpProducer)3 MockChannel (com.adaptris.core.stubs.MockChannel)3 InputStream (java.io.InputStream)3 Destination (javax.jms.Destination)3 FileNameCreator (com.adaptris.core.FileNameCreator)2 MetadataElement (com.adaptris.core.MetadataElement)2 MetadataFileNameCreator (com.adaptris.core.MetadataFileNameCreator)2 ServiceException (com.adaptris.core.ServiceException)2