Search in sources :

Example 31 with StandaloneRequestor

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

the class StandardResponseProducerTest method testResponseWithEncoder.

@Test
public void testResponseWithEncoder() throws Exception {
    StandardResponseProducer responder = new StandardResponseProducer(HttpStatus.OK_200);
    responder.setSendPayload(true);
    responder.setEncoder(new MyMimeEncoder());
    HttpConnection httpConnection = createConnection();
    Channel c = createChannel(httpConnection, createWorkflow(createConsumer(URL_TO_POST_TO), new MockMessageProducer(), responder));
    StandaloneRequestor requestor = createRequestor(httpConnection.getPort());
    AdaptrisMessage msg = createMessage();
    try {
        c.requestStart();
        start(requestor);
        requestor.doService(msg);
        System.err.println(msg.getContent());
        assertNotSame(TEXT, msg.getContent());
    } finally {
        c.requestClose();
        stop(requestor);
        PortManager.release(httpConnection.getPort());
    }
}
Also used : StandaloneRequestor(com.adaptris.core.StandaloneRequestor) MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) JettyHelper.createChannel(com.adaptris.core.http.jetty.JettyHelper.createChannel) Channel(com.adaptris.core.Channel) Test(org.junit.Test)

Example 32 with StandaloneRequestor

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

the class StandardResponseProducerTest method testDoService_NoFlush.

@Test
public void testDoService_NoFlush() throws Exception {
    StandardResponseProducer responder = new StandardResponseProducer(HttpStatus.OK_200);
    responder.setFlushBuffer(Boolean.FALSE);
    HttpConnection httpConnection = createConnection();
    Channel c = createChannel(httpConnection, createWorkflow(createConsumer(URL_TO_POST_TO), new MockMessageProducer(), responder));
    StandaloneRequestor requestor = createRequestor(httpConnection.getPort());
    AdaptrisMessage msg = createMessage();
    try {
        c.requestStart();
        start(requestor);
        requestor.doService(msg);
        assertEquals(TEXT, msg.getContent());
        assertFalse(msg.containsKey(CUSTOM_HEADER1));
        assertFalse(msg.containsKey(CUSTOM_HEADER2));
    } finally {
        c.requestClose();
        stop(requestor);
        PortManager.release(httpConnection.getPort());
    }
}
Also used : StandaloneRequestor(com.adaptris.core.StandaloneRequestor) MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) JettyHelper.createChannel(com.adaptris.core.http.jetty.JettyHelper.createChannel) Channel(com.adaptris.core.Channel) Test(org.junit.Test)

Example 33 with StandaloneRequestor

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

the class StandardResponseProducerTest method testResponse_CompositeResponseHeaders.

@Test
public void testResponse_CompositeResponseHeaders() throws Exception {
    StandardResponseProducer responder = new StandardResponseProducer(HttpStatus.OK_200);
    responder.setSendPayload(false);
    CompositeResponseHeaderProvider provider = new CompositeResponseHeaderProvider(new MetadataResponseHeaderProvider(new RegexMetadataFilter()), new ConfiguredResponseHeaderProvider(new KeyValuePair("Hello", "World")));
    responder.setResponseHeaderProvider(provider);
    AddMetadataService meta = new AddMetadataService();
    meta.addMetadataElement(getName(), getName());
    ServiceList sl = new ServiceList(new Service[] { meta, new StandaloneProducer(responder) });
    HttpConnection httpConnection = createConnection();
    Channel c = createChannel(httpConnection, createWorkflow(createConsumer(URL_TO_POST_TO), new MockMessageProducer(), sl));
    StandaloneRequestor requestor = createRequestor(httpConnection.getPort());
    AdaptrisMessage msg = createMessage();
    try {
        c.requestStart();
        start(requestor);
        requestor.doService(msg);
        assertNotSame(TEXT, msg.getContent());
        assertTrue(msg.containsKey(getName()));
        assertTrue(msg.containsKey("Hello"));
    } finally {
        c.requestClose();
        stop(requestor);
        PortManager.release(httpConnection.getPort());
    }
}
Also used : KeyValuePair(com.adaptris.util.KeyValuePair) MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) ServiceList(com.adaptris.core.ServiceList) JettyHelper.createChannel(com.adaptris.core.http.jetty.JettyHelper.createChannel) Channel(com.adaptris.core.Channel) AddMetadataService(com.adaptris.core.services.metadata.AddMetadataService) RegexMetadataFilter(com.adaptris.core.metadata.RegexMetadataFilter) StandaloneRequestor(com.adaptris.core.StandaloneRequestor) StandaloneProducer(com.adaptris.core.StandaloneProducer) Test(org.junit.Test)

Example 34 with StandaloneRequestor

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

the class StandardResponseProducerTest method testDoService.

@Test
public void testDoService() throws Exception {
    StandardResponseProducer responder = new StandardResponseProducer(HttpStatus.OK_200);
    HttpConnection httpConnection = createConnection();
    Channel c = createChannel(httpConnection, createWorkflow(createConsumer(URL_TO_POST_TO), new MockMessageProducer(), responder));
    StandaloneRequestor requestor = createRequestor(httpConnection.getPort());
    AdaptrisMessage msg = createMessage();
    try {
        c.requestStart();
        start(requestor);
        requestor.doService(msg);
        assertEquals(TEXT, msg.getContent());
        assertFalse(msg.containsKey(CUSTOM_HEADER1));
        assertFalse(msg.containsKey(CUSTOM_HEADER2));
    } finally {
        c.requestClose();
        stop(requestor);
        PortManager.release(httpConnection.getPort());
    }
}
Also used : StandaloneRequestor(com.adaptris.core.StandaloneRequestor) MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) JettyHelper.createChannel(com.adaptris.core.http.jetty.JettyHelper.createChannel) Channel(com.adaptris.core.Channel) Test(org.junit.Test)

Example 35 with StandaloneRequestor

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

the class StandardResponseProducerTest method testResponseWithError.

@Test
public void testResponseWithError() throws Exception {
    StandardResponseProducer responder = new StandardResponseProducer(HttpStatus.INTERNAL_ERROR_500);
    HttpConnection httpConnection = createConnection();
    Channel c = createChannel(httpConnection, createWorkflow(createConsumer(URL_TO_POST_TO), new MockMessageProducer(), responder));
    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) JettyHelper.createChannel(com.adaptris.core.http.jetty.JettyHelper.createChannel) Channel(com.adaptris.core.Channel) Test(org.junit.Test)

Aggregations

StandaloneRequestor (com.adaptris.core.StandaloneRequestor)50 AdaptrisMessage (com.adaptris.core.AdaptrisMessage)49 Test (org.junit.Test)49 MockMessageProducer (com.adaptris.core.stubs.MockMessageProducer)33 Channel (com.adaptris.core.Channel)30 JettyHelper.createChannel (com.adaptris.core.http.jetty.JettyHelper.createChannel)30 ServiceList (com.adaptris.core.ServiceList)23 StandaloneProducer (com.adaptris.core.StandaloneProducer)19 ConfiguredRequestMethodProvider (com.adaptris.core.http.client.ConfiguredRequestMethodProvider)16 DefaultMessageFactory (com.adaptris.core.DefaultMessageFactory)15 HttpConsumerTest (com.adaptris.core.http.jetty.HttpConsumerTest)15 StandardWorkflow (com.adaptris.core.StandardWorkflow)12 HttpConnection (com.adaptris.core.http.jetty.HttpConnection)12 JettyMessageConsumer (com.adaptris.core.http.jetty.JettyMessageConsumer)12 StandardResponseProducer (com.adaptris.core.http.jetty.StandardResponseProducer)12 StandardHttpProducer (com.adaptris.core.http.client.net.StandardHttpProducer)8 PayloadFromTemplateService (com.adaptris.core.services.metadata.PayloadFromTemplateService)8 TimeInterval (com.adaptris.util.TimeInterval)7 MetadataContentTypeProvider (com.adaptris.core.http.MetadataContentTypeProvider)6 ServiceException (com.adaptris.core.ServiceException)5