Search in sources :

Example 1 with MetadataRequestMethodProvider

use of com.adaptris.core.http.client.MetadataRequestMethodProvider in project interlok by adaptris.

the class StandardHttpProducerTest method testProduce_WithMetadataMethod.

@Test
public void testProduce_WithMetadataMethod() throws Exception {
    MockMessageProducer mock = new MockMessageProducer();
    HttpConnection jc = HttpHelper.createConnection();
    JettyMessageConsumer mc = createConsumer(HttpHelper.URL_TO_POST_TO);
    ServiceList sl = new ServiceList();
    PayloadFromTemplateService pms = new PayloadFromTemplateService().withTemplate(TEXT);
    sl.add(pms);
    sl.add(new StandaloneProducer(new StandardResponseProducer(HttpStatus.OK_200)));
    Channel c = createChannel(jc, createWorkflow(mc, mock, sl));
    StandardWorkflow workflow = (StandardWorkflow) c.getWorkflowList().get(0);
    StandardHttpProducer stdHttp = new StandardHttpProducer().withURL(HttpHelper.createURL(c));
    stdHttp.setMethodProvider(new MetadataRequestMethodProvider("httpMethod"));
    StandaloneRequestor producer = new StandaloneRequestor(stdHttp);
    AdaptrisMessage msg = new DefaultMessageFactory().newMessage();
    msg.addMetadata("httpMethod", "get");
    try {
        start(c);
        start(producer);
        producer.doService(msg);
        waitForMessages(mock, 1);
    } finally {
        HttpHelper.stopChannelAndRelease(c);
        stop(producer);
    }
    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) StandardWorkflow(com.adaptris.core.StandardWorkflow) 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) MetadataRequestMethodProvider(com.adaptris.core.http.client.MetadataRequestMethodProvider) StandaloneRequestor(com.adaptris.core.StandaloneRequestor) StandardResponseProducer(com.adaptris.core.http.jetty.StandardResponseProducer) JettyMessageConsumer(com.adaptris.core.http.jetty.JettyMessageConsumer) PayloadFromTemplateService(com.adaptris.core.services.metadata.PayloadFromTemplateService) StandaloneProducer(com.adaptris.core.StandaloneProducer) HttpConsumerTest(com.adaptris.core.http.jetty.HttpConsumerTest) Test(org.junit.Test)

Example 2 with MetadataRequestMethodProvider

use of com.adaptris.core.http.client.MetadataRequestMethodProvider in project interlok by adaptris.

the class MetadataRequestMethodProviderTest method testDefaultMethod.

@Test
public void testDefaultMethod() {
    MetadataRequestMethodProvider prov = new MetadataRequestMethodProvider("httpMethod");
    AdaptrisMessage msg = new DefaultMessageFactory().newMessage("");
    assertEquals(RequestMethod.POST, prov.getMethod(msg));
}
Also used : DefaultMessageFactory(com.adaptris.core.DefaultMessageFactory) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) MetadataRequestMethodProvider(com.adaptris.core.http.client.MetadataRequestMethodProvider) Test(org.junit.Test)

Example 3 with MetadataRequestMethodProvider

use of com.adaptris.core.http.client.MetadataRequestMethodProvider in project interlok by adaptris.

the class MetadataRequestMethodProviderTest method testGetMethod_WithMetadata.

@Test
public void testGetMethod_WithMetadata() {
    MetadataRequestMethodProvider prov = new MetadataRequestMethodProvider("httpMethod");
    AdaptrisMessage msg = new DefaultMessageFactory().newMessage("");
    msg.addMetadata("httpMethod", "GET");
    assertEquals(RequestMethod.GET, prov.getMethod(msg));
}
Also used : DefaultMessageFactory(com.adaptris.core.DefaultMessageFactory) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) MetadataRequestMethodProvider(com.adaptris.core.http.client.MetadataRequestMethodProvider) Test(org.junit.Test)

Aggregations

AdaptrisMessage (com.adaptris.core.AdaptrisMessage)3 DefaultMessageFactory (com.adaptris.core.DefaultMessageFactory)3 MetadataRequestMethodProvider (com.adaptris.core.http.client.MetadataRequestMethodProvider)3 Test (org.junit.Test)3 Channel (com.adaptris.core.Channel)1 ServiceList (com.adaptris.core.ServiceList)1 StandaloneProducer (com.adaptris.core.StandaloneProducer)1 StandaloneRequestor (com.adaptris.core.StandaloneRequestor)1 StandardWorkflow (com.adaptris.core.StandardWorkflow)1 HttpConnection (com.adaptris.core.http.jetty.HttpConnection)1 HttpConsumerTest (com.adaptris.core.http.jetty.HttpConsumerTest)1 JettyHelper.createChannel (com.adaptris.core.http.jetty.JettyHelper.createChannel)1 JettyMessageConsumer (com.adaptris.core.http.jetty.JettyMessageConsumer)1 StandardResponseProducer (com.adaptris.core.http.jetty.StandardResponseProducer)1 PayloadFromTemplateService (com.adaptris.core.services.metadata.PayloadFromTemplateService)1 MockMessageProducer (com.adaptris.core.stubs.MockMessageProducer)1