Search in sources :

Example 6 with MetadataContentTypeProvider

use of com.adaptris.core.http.MetadataContentTypeProvider in project interlok by adaptris.

the class StandardHttpProducerTest method testRequest_MetadataResponseHeaders.

@Test
public void testRequest_MetadataResponseHeaders() throws Exception {
    MockMessageProducer mock = new MockMessageProducer();
    Channel c = HttpHelper.createAndStartChannel(mock);
    StandardHttpProducer stdHttp = new StandardHttpProducer().withURL(HttpHelper.createURL(c));
    stdHttp.setContentTypeProvider(new MetadataContentTypeProvider(HttpHelper.CONTENT_TYPE));
    stdHttp.setResponseHeaderHandler(new ResponseHeadersAsMetadata("", "|"));
    StandaloneRequestor producer = new StandaloneRequestor(stdHttp);
    AdaptrisMessage msg = new DefaultMessageFactory().newMessage(TEXT);
    msg.addMetadata(HttpHelper.CONTENT_TYPE, "text/complicated");
    assertFalse(msg.headersContainsKey("Server"));
    try {
        c.requestStart();
        start(producer);
        producer.doService(msg);
        waitForMessages(mock, 1);
    } finally {
        HttpHelper.stopChannelAndRelease(c);
        stop(producer);
    }
    assertEquals(1, mock.messageCount());
    AdaptrisMessage m2 = mock.getMessages().get(0);
    assertTrue(m2.headersContainsKey("Content-Type"));
    assertEquals("text/complicated", m2.getMetadataValue("Content-Type"));
    assertTrue(msg.headersContainsKey("Server"));
}
Also used : DefaultMessageFactory(com.adaptris.core.DefaultMessageFactory) MetadataContentTypeProvider(com.adaptris.core.http.MetadataContentTypeProvider) 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) HttpConsumerTest(com.adaptris.core.http.jetty.HttpConsumerTest) Test(org.junit.Test)

Example 7 with MetadataContentTypeProvider

use of com.adaptris.core.http.MetadataContentTypeProvider in project interlok by adaptris.

the class StandardHttpProducerTest method testRequest_CompositeMetadataResponseHeaders.

@Test
public void testRequest_CompositeMetadataResponseHeaders() throws Exception {
    MockMessageProducer mock = new MockMessageProducer();
    Channel c = HttpHelper.createAndStartChannel(mock);
    StandardHttpProducer stdHttp = new StandardHttpProducer().withURL(HttpHelper.createURL(c));
    ;
    stdHttp.setContentTypeProvider(new MetadataContentTypeProvider(HttpHelper.CONTENT_TYPE));
    stdHttp.setResponseHeaderHandler(new CompositeResponseHeaderHandler(new ResponseHeadersAsMetadata(), new ResponseHeadersAsObjectMetadata()));
    StandaloneRequestor producer = new StandaloneRequestor(stdHttp);
    AdaptrisMessage msg = new DefaultMessageFactory().newMessage(TEXT);
    msg.addMetadata(HttpHelper.CONTENT_TYPE, "text/complicated");
    assertFalse(msg.headersContainsKey("Server"));
    try {
        c.requestStart();
        start(producer);
        producer.doService(msg);
        waitForMessages(mock, 1);
    } finally {
        HttpHelper.stopChannelAndRelease(c);
        stop(producer);
    }
    assertTrue(msg.headersContainsKey("Server"));
    assertTrue(msg.getObjectHeaders().containsKey("Server"));
}
Also used : DefaultMessageFactory(com.adaptris.core.DefaultMessageFactory) MetadataContentTypeProvider(com.adaptris.core.http.MetadataContentTypeProvider) 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) HttpConsumerTest(com.adaptris.core.http.jetty.HttpConsumerTest) Test(org.junit.Test)

Example 8 with MetadataContentTypeProvider

use of com.adaptris.core.http.MetadataContentTypeProvider in project interlok by adaptris.

the class StandardHttpProducerTest method testProduceWithContentTypeMetadata.

@Test
public void testProduceWithContentTypeMetadata() throws Exception {
    MockMessageProducer mock = new MockMessageProducer();
    Channel c = HttpHelper.createAndStartChannel(mock);
    StandardHttpProducer stdHttp = new StandardHttpProducer().withURL(HttpHelper.createURL(c));
    stdHttp.setContentTypeProvider(new MetadataContentTypeProvider(HttpHelper.CONTENT_TYPE));
    StandaloneProducer producer = new StandaloneProducer(stdHttp);
    AdaptrisMessage msg = new DefaultMessageFactory().newMessage(TEXT);
    msg.addMetadata(HttpHelper.CONTENT_TYPE, "text/complicated");
    try {
        c.requestStart();
        start(producer);
        producer.produce(msg);
        waitForMessages(mock, 1);
    } finally {
        HttpHelper.stopChannelAndRelease(c);
        stop(producer);
    }
    assertEquals(1, mock.messageCount());
    AdaptrisMessage m2 = mock.getMessages().get(0);
    assertTrue(m2.headersContainsKey("Content-Type"));
    assertEquals("text/complicated", m2.getMetadataValue("Content-Type"));
}
Also used : DefaultMessageFactory(com.adaptris.core.DefaultMessageFactory) MetadataContentTypeProvider(com.adaptris.core.http.MetadataContentTypeProvider) 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) StandaloneProducer(com.adaptris.core.StandaloneProducer) HttpConsumerTest(com.adaptris.core.http.jetty.HttpConsumerTest) Test(org.junit.Test)

Aggregations

MetadataContentTypeProvider (com.adaptris.core.http.MetadataContentTypeProvider)8 AdaptrisMessage (com.adaptris.core.AdaptrisMessage)6 Channel (com.adaptris.core.Channel)6 StandaloneRequestor (com.adaptris.core.StandaloneRequestor)6 JettyHelper.createChannel (com.adaptris.core.http.jetty.JettyHelper.createChannel)6 MockMessageProducer (com.adaptris.core.stubs.MockMessageProducer)6 Test (org.junit.Test)6 DefaultMessageFactory (com.adaptris.core.DefaultMessageFactory)4 HttpConsumerTest (com.adaptris.core.http.jetty.HttpConsumerTest)4 StandaloneProducer (com.adaptris.core.StandaloneProducer)3 ServiceList (com.adaptris.core.ServiceList)2 StandardHttpProducer (com.adaptris.core.http.client.net.StandardHttpProducer)2 MetadataElement (com.adaptris.core.MetadataElement)1 NullConnection (com.adaptris.core.NullConnection)1 ResponseHeadersAsMetadata (com.adaptris.core.http.client.net.ResponseHeadersAsMetadata)1 AddMetadataService (com.adaptris.core.services.metadata.AddMetadataService)1