Search in sources :

Example 1 with MetadataContentTypeProvider

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

the class StandardHttpProducerTest method testRequest_ObjectMetadataResponseHeaders.

@Test
public void testRequest_ObjectMetadataResponseHeaders() 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 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);
    }
    assertFalse(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 2 with MetadataContentTypeProvider

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

the class StandardResponseProducerTest method createRequestor.

protected static StandaloneRequestor createRequestor(int port) {
    StandardHttpProducer producer = new StandardHttpProducer().withURL(createURL(port));
    producer.setContentTypeProvider(new MetadataContentTypeProvider(CONTENT_TYPE));
    producer.setResponseHeaderHandler(new ResponseHeadersAsMetadata());
    return new StandaloneRequestor(producer);
}
Also used : StandardHttpProducer(com.adaptris.core.http.client.net.StandardHttpProducer) MetadataContentTypeProvider(com.adaptris.core.http.MetadataContentTypeProvider) StandaloneRequestor(com.adaptris.core.StandaloneRequestor) ResponseHeadersAsMetadata(com.adaptris.core.http.client.net.ResponseHeadersAsMetadata)

Example 3 with MetadataContentTypeProvider

use of com.adaptris.core.http.MetadataContentTypeProvider 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)

Example 4 with MetadataContentTypeProvider

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

the class StandardResponseProducerTest method testResponse_MetadataContentType_MissingMetadata.

@Test
public void testResponse_MetadataContentType_MissingMetadata() throws Exception {
    StandardResponseProducer responder = new StandardResponseProducer(HttpStatus.OK_200);
    responder.setContentTypeProvider(new MetadataContentTypeProvider("MyContentType"));
    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 : 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) StandaloneProducer(com.adaptris.core.StandaloneProducer) Test(org.junit.Test)

Example 5 with MetadataContentTypeProvider

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

the class EmbeddedHttpConsumerTest method createProducer.

protected StandardHttpProducer createProducer() {
    StandardHttpProducer p = new StandardHttpProducer();
    p.setContentTypeProvider(new MetadataContentTypeProvider("content.type"));
    p.setUrl("dummy_url");
    p.setIgnoreServerResponseCode(true);
    p.registerConnection(new NullConnection());
    return p;
}
Also used : StandardHttpProducer(com.adaptris.core.http.client.net.StandardHttpProducer) MetadataContentTypeProvider(com.adaptris.core.http.MetadataContentTypeProvider) NullConnection(com.adaptris.core.NullConnection)

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