Search in sources :

Example 1 with ServiceException

use of com.adaptris.core.ServiceException in project interlok by adaptris.

the class StandardHttpProducerTest method testRequest_GetMethod_WithErrorResponse.

@Test
public void testRequest_GetMethod_WithErrorResponse() throws Exception {
    MockMessageProducer mock = new MockMessageProducer();
    HttpConnection jc = HttpHelper.createConnection();
    JettyMessageConsumer mc = createConsumer(HttpHelper.URL_TO_POST_TO);
    ServiceList services = new ServiceList();
    services.add(new StandaloneProducer(new StandardResponseProducer(HttpStatus.UNAUTHORIZED_401)));
    Channel c = createChannel(jc, createWorkflow(mc, mock, services));
    StandardHttpProducer stdHttp = new StandardHttpProducer().withURL(HttpHelper.createURL(c));
    ;
    stdHttp.setMethodProvider(new ConfiguredRequestMethodProvider(RequestMethodProvider.RequestMethod.GET));
    StandaloneRequestor producer = new StandaloneRequestor(stdHttp);
    AdaptrisMessage msg = new DefaultMessageFactory().newMessage(ALT_TEXT);
    try {
        start(c);
        start(producer);
        producer.doService(msg);
        fail();
    } catch (ServiceException expected) {
    } finally {
        stop(c);
        stop(producer);
    }
    assertEquals(1, mock.messageCount());
}
Also used : DefaultMessageFactory(com.adaptris.core.DefaultMessageFactory) MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) 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) StandaloneRequestor(com.adaptris.core.StandaloneRequestor) ServiceException(com.adaptris.core.ServiceException) StandardResponseProducer(com.adaptris.core.http.jetty.StandardResponseProducer) JettyMessageConsumer(com.adaptris.core.http.jetty.JettyMessageConsumer) StandaloneProducer(com.adaptris.core.StandaloneProducer) ConfiguredRequestMethodProvider(com.adaptris.core.http.client.ConfiguredRequestMethodProvider) HttpConsumerTest(com.adaptris.core.http.jetty.HttpConsumerTest) Test(org.junit.Test)

Example 2 with ServiceException

use of com.adaptris.core.ServiceException in project interlok by adaptris.

the class HttpRequestServiceTest method testRequest_GetMethod_NonZeroBytes_WithErrorResponse.

@Test
public void testRequest_GetMethod_NonZeroBytes_WithErrorResponse() throws Exception {
    MockMessageProducer mock = new MockMessageProducer();
    HttpConnection jc = HttpHelper.createConnection();
    JettyMessageConsumer mc = createConsumer(HttpHelper.URL_TO_POST_TO);
    Channel c = createChannel(jc, createWorkflow(mc, mock, new ServiceList(new Service[] { new PayloadFromTemplateService().withTemplate(TEXT), new StandaloneProducer(new StandardResponseProducer(HttpStatus.UNAUTHORIZED_401)) })));
    HttpRequestService service = new HttpRequestService(HttpHelper.createProduceDestination(c)).withMethod("GET");
    AdaptrisMessage msg = new DefaultMessageFactory().newMessage(TEXT);
    try {
        start(c);
        execute(service, msg);
        fail();
    } catch (ServiceException expect) {
    } finally {
        stop(c);
    }
}
Also used : DefaultMessageFactory(com.adaptris.core.DefaultMessageFactory) MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) ServiceException(com.adaptris.core.ServiceException) HttpConnection(com.adaptris.core.http.jetty.HttpConnection) StandardResponseProducer(com.adaptris.core.http.jetty.StandardResponseProducer) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) ServiceList(com.adaptris.core.ServiceList) JettyHelper.createChannel(com.adaptris.core.http.jetty.JettyHelper.createChannel) Channel(com.adaptris.core.Channel) JettyMessageConsumer(com.adaptris.core.http.jetty.JettyMessageConsumer) PayloadFromTemplateService(com.adaptris.core.services.metadata.PayloadFromTemplateService) StandaloneProducer(com.adaptris.core.StandaloneProducer) Test(org.junit.Test) HttpConsumerTest(com.adaptris.core.http.jetty.HttpConsumerTest)

Example 3 with ServiceException

use of com.adaptris.core.ServiceException in project interlok by adaptris.

the class JettyResponseServiceTest method testResponseWithError.

@Test
public void testResponseWithError() throws Exception {
    JettyResponseService responder = new JettyResponseService().withHttpStatus("500").withContentType("text/plain").withResponseHeaderProvider(new NoOpResponseHeaderProvider());
    HttpConnection httpConnection = createConnection();
    ServiceList list = new ServiceList(responder);
    Channel c = createChannel(httpConnection, createWorkflow(createConsumer(URL_TO_POST_TO), new MockMessageProducer(), list));
    StandaloneRequestor requestor = createRequestor(httpConnection.getPort());
    AdaptrisMessage msg = createMessage();
    try {
        c.requestStart();
        start(requestor);
        requestor.doService(msg);
        fail("StandaloneRequestor.doService() success even though we should have got a 500 error back");
    } catch (ServiceException expected) {
        ;
    } finally {
        c.requestClose();
        stop(requestor);
        PortManager.release(httpConnection.getPort());
    }
}
Also used : StandaloneRequestor(com.adaptris.core.StandaloneRequestor) MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) ServiceException(com.adaptris.core.ServiceException) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) ServiceList(com.adaptris.core.ServiceList) JettyHelper.createChannel(com.adaptris.core.http.jetty.JettyHelper.createChannel) Channel(com.adaptris.core.Channel) Test(org.junit.Test)

Example 4 with ServiceException

use of com.adaptris.core.ServiceException in project interlok by adaptris.

the class StoredProcedureProducerTest method testOneConstantParamInOut.

@Test
public void testOneConstantParamInOut() throws Exception {
    if (areTestsEnabled()) {
        JdbcStoredProcedureProducer spp = new JdbcStoredProcedureProducer();
        spp.setProcedureName(("one_inout"));
        JdbcConstantParameter inParameter = new JdbcConstantParameter();
        inParameter.setName("xSomeAmount");
        inParameter.setType(ParameterValueType.VARCHAR);
        inParameter.setConstant("100");
        InOutParameters inOutParameters = new InOutParameters();
        inOutParameters.add(inParameter);
        spp.setInOutParameters(inOutParameters);
        StandaloneProducer producer = configureForTests(spp, true);
        AdaptrisMessage message = createMessage();
        try {
            start(producer);
            producer.doService(message);
            fail("Cannot use a constant for InOut parameters");
        } catch (ServiceException ex) {
        // pass, expected
        } finally {
            stop(producer);
        }
    }
}
Also used : ServiceException(com.adaptris.core.ServiceException) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) StandaloneProducer(com.adaptris.core.StandaloneProducer) Test(org.junit.Test)

Example 5 with ServiceException

use of com.adaptris.core.ServiceException in project interlok by adaptris.

the class StoredProcedureProducerTest method testOneMetadataParamInButDoesntExist.

@Test
public void testOneMetadataParamInButDoesntExist() throws Exception {
    if (areTestsEnabled()) {
        JdbcStoredProcedureProducer spp = new JdbcStoredProcedureProducer();
        spp.setProcedureName(("one_in"));
        JdbcMetadataParameter inParameter = new JdbcMetadataParameter();
        inParameter.setMetadataKey("xType");
        inParameter.setName("xType");
        inParameter.setType(ParameterValueType.VARCHAR);
        InParameters inParameters = new InParameters();
        inParameters.add(inParameter);
        spp.setInParameters(inParameters);
        StandaloneProducer producer = configureForTests(spp, true);
        AdaptrisMessage message = createMessage();
        try {
            start(producer);
            producer.doService(message);
            fail("Should have thrown ProduceException, because the metadata does not exist in the message.");
        } catch (ServiceException ex) {
        // pass, expected
        } finally {
            stop(producer);
        }
    }
}
Also used : ServiceException(com.adaptris.core.ServiceException) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) StandaloneProducer(com.adaptris.core.StandaloneProducer) Test(org.junit.Test)

Aggregations

ServiceException (com.adaptris.core.ServiceException)236 Test (org.junit.Test)172 AdaptrisMessage (com.adaptris.core.AdaptrisMessage)161 CoreException (com.adaptris.core.CoreException)45 DefaultMessageFactory (com.adaptris.core.DefaultMessageFactory)26 StandaloneProducer (com.adaptris.core.StandaloneProducer)18 MetadataElement (com.adaptris.core.MetadataElement)17 ValidationStage (com.adaptris.transform.validate.ValidationStage)16 Cache (com.adaptris.core.cache.Cache)15 DefectiveMessageFactory (com.adaptris.core.stubs.DefectiveMessageFactory)13 TimeInterval (com.adaptris.util.TimeInterval)13 MockMessageProducer (com.adaptris.core.stubs.MockMessageProducer)11 Connection (java.sql.Connection)10 File (java.io.File)9 IOException (java.io.IOException)9 OutputStream (java.io.OutputStream)9 SQLException (java.sql.SQLException)9 InputStream (java.io.InputStream)8 Document (org.w3c.dom.Document)8 Channel (com.adaptris.core.Channel)7