Search in sources :

Example 11 with ServiceList

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

the class HttpRequestServiceTest method testRequest_GetMethod_ZeroBytes.

@Test
public void testRequest_GetMethod_ZeroBytes() 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.OK_200)) })));
    HttpRequestService service = new HttpRequestService(HttpHelper.createProduceDestination(c)).withMethod("GET");
    AdaptrisMessage msg = new DefaultMessageFactory().newMessage();
    try {
        start(c);
        execute(service, msg);
        waitForMessages(mock, 1);
    } finally {
        HttpHelper.stopChannelAndRelease(c);
    }
    assertEquals(1, mock.messageCount());
    AdaptrisMessage m2 = mock.getMessages().get(0);
    assertEquals("GET", m2.getMetadataValue(CoreConstants.HTTP_METHOD));
    assertEquals(TEXT, msg.getContent());
}
Also used : DefaultMessageFactory(com.adaptris.core.DefaultMessageFactory) MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) 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 12 with ServiceList

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

the class JettyResponseServiceTest method testDoService.

@Test
public void testDoService() throws Exception {
    JettyResponseService responder = new JettyResponseService(200, "text/plain");
    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);
        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) ServiceList(com.adaptris.core.ServiceList) JettyHelper.createChannel(com.adaptris.core.http.jetty.JettyHelper.createChannel) Channel(com.adaptris.core.Channel) Test(org.junit.Test)

Example 13 with ServiceList

use of com.adaptris.core.ServiceList 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 14 with ServiceList

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

the class StandardResponseProducerTest method testResponse_NoOpResponseHeaders.

@Test
public void testResponse_NoOpResponseHeaders() throws Exception {
    StandardResponseProducer responder = new StandardResponseProducer(HttpStatus.OK_200);
    responder.setResponseHeaderProvider(new NoOpResponseHeaderProvider());
    HttpConnection httpConnection = createConnection();
    Channel c = createChannel(httpConnection, createWorkflow(createConsumer(URL_TO_POST_TO), new MockMessageProducer(), new ServiceList(new Service[] { new StandaloneProducer(responder) })));
    StandaloneRequestor requestor = createRequestor(httpConnection.getPort());
    AdaptrisMessage msg = createMessage();
    try {
        c.requestStart();
        start(requestor);
        requestor.doService(msg);
        assertEquals(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) ServiceList(com.adaptris.core.ServiceList) JettyHelper.createChannel(com.adaptris.core.http.jetty.JettyHelper.createChannel) Channel(com.adaptris.core.Channel) StandaloneProducer(com.adaptris.core.StandaloneProducer) Test(org.junit.Test)

Example 15 with ServiceList

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

the class StandardResponseProducerTest method testResponse_MetadataContentType.

@Test
public void testResponse_MetadataContentType() throws Exception {
    StandardResponseProducer responder = new StandardResponseProducer(HttpStatus.OK_200);
    responder.setContentTypeProvider(new MetadataContentTypeProvider("MyContentType"));
    AddMetadataService addMetadata = new AddMetadataService(Arrays.asList(new MetadataElement[] { new MetadataElement("MyContentType", "text/xml") }));
    HttpConnection httpConnection = createConnection();
    Channel c = createChannel(httpConnection, createWorkflow(createConsumer(URL_TO_POST_TO), new MockMessageProducer(), new ServiceList(new Service[] { addMetadata, new StandaloneProducer(responder) })));
    StandaloneRequestor requestor = createRequestor(httpConnection.getPort());
    AdaptrisMessage msg = createMessage();
    try {
        c.requestStart();
        start(requestor);
        requestor.doService(msg);
        assertEquals(TEXT, msg.getContent());
        assertTrue(msg.containsKey("Content-Type"));
        assertTrue(msg.getMetadataValue("Content-Type").startsWith("text/xml"));
    } finally {
        c.requestClose();
        stop(requestor);
        PortManager.release(httpConnection.getPort());
    }
}
Also used : MetadataContentTypeProvider(com.adaptris.core.http.MetadataContentTypeProvider) StandaloneRequestor(com.adaptris.core.StandaloneRequestor) 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) MetadataElement(com.adaptris.core.MetadataElement) AddMetadataService(com.adaptris.core.services.metadata.AddMetadataService) StandaloneProducer(com.adaptris.core.StandaloneProducer) Test(org.junit.Test)

Aggregations

ServiceList (com.adaptris.core.ServiceList)64 Test (org.junit.Test)52 AdaptrisMessage (com.adaptris.core.AdaptrisMessage)43 StandaloneProducer (com.adaptris.core.StandaloneProducer)39 MockMessageProducer (com.adaptris.core.stubs.MockMessageProducer)33 Channel (com.adaptris.core.Channel)31 JettyHelper.createChannel (com.adaptris.core.http.jetty.JettyHelper.createChannel)29 StandaloneRequestor (com.adaptris.core.StandaloneRequestor)23 HttpConnection (com.adaptris.core.http.jetty.HttpConnection)20 JettyMessageConsumer (com.adaptris.core.http.jetty.JettyMessageConsumer)20 StandardResponseProducer (com.adaptris.core.http.jetty.StandardResponseProducer)20 DefaultMessageFactory (com.adaptris.core.DefaultMessageFactory)18 HttpConsumerTest (com.adaptris.core.http.jetty.HttpConsumerTest)18 PayloadFromTemplateService (com.adaptris.core.services.metadata.PayloadFromTemplateService)17 Service (com.adaptris.core.Service)16 AddMetadataService (com.adaptris.core.services.metadata.AddMetadataService)16 MetadataElement (com.adaptris.core.MetadataElement)14 ConfiguredRequestMethodProvider (com.adaptris.core.http.client.ConfiguredRequestMethodProvider)11 LogMessageService (com.adaptris.core.services.LogMessageService)11 StandardWorkflow (com.adaptris.core.StandardWorkflow)10