Search in sources :

Example 16 with ConfiguredRequestMethodProvider

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

the class StandardHttpProducerTest method testRequest_EmptyReply.

@Test
public void testRequest_EmptyReply() 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()));
    StandardWorkflow workflow = (StandardWorkflow) c.getWorkflowList().get(0);
    StandardResponseProducer responder = new StandardResponseProducer(HttpStatus.OK_200);
    responder.setSendPayload(false);
    workflow.getServiceCollection().add(new StandaloneProducer(responder));
    StandardHttpProducer stdHttp = new StandardHttpProducer().withURL(HttpHelper.createURL(c));
    stdHttp.setMethodProvider(new ConfiguredRequestMethodProvider(RequestMethodProvider.RequestMethod.POST));
    stdHttp.setConnectTimeout(new TimeInterval(60L, TimeUnit.SECONDS));
    stdHttp.setReadTimeout(new TimeInterval(60L, TimeUnit.SECONDS));
    StandaloneRequestor producer = new StandaloneRequestor(stdHttp);
    producer.setReplyTimeout(new TimeInterval(60L, TimeUnit.SECONDS));
    AdaptrisMessage msg = new DefaultMessageFactory().newMessage(TEXT);
    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("POST", m2.getMetadataValue(CoreConstants.HTTP_METHOD));
    assertEquals(0, msg.getSize());
}
Also used : DefaultMessageFactory(com.adaptris.core.DefaultMessageFactory) StandardWorkflow(com.adaptris.core.StandardWorkflow) MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) TimeInterval(com.adaptris.util.TimeInterval) 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) StandaloneRequestor(com.adaptris.core.StandaloneRequestor) StandardResponseProducer(com.adaptris.core.http.jetty.StandardResponseProducer) JettyMessageConsumer(com.adaptris.core.http.jetty.JettyMessageConsumer) StandaloneProducer(com.adaptris.core.StandaloneProducer) ConfiguredRequestMethodProvider(com.adaptris.core.http.client.ConfiguredRequestMethodProvider) HttpConsumerTest(com.adaptris.core.http.jetty.HttpConsumerTest) Test(org.junit.Test)

Example 17 with ConfiguredRequestMethodProvider

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

the class RetryFromJettyTest method testReport_Broken.

@Test
public void testReport_Broken() throws Exception {
    RetryFromJetty retrier = create();
    try {
        retrier.setRetryStore(new BrokenRetryStore());
        start(retrier);
        String url = jettyHelper.buildUrl(RetryFromJetty.DEFAULT_REPORTING_ENDPOINT);
        AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage();
        StandardHttpProducer http = buildProducer(url);
        http.setIgnoreServerResponseCode(true);
        http.setMethodProvider(new ConfiguredRequestMethodProvider(RequestMethodProvider.RequestMethod.GET));
        ExampleServiceCase.execute(new StandaloneRequestor(http), msg);
        assertEquals(RetryFromJetty.HTTP_ERROR, msg.getMetadataValue(CoreConstants.HTTP_PRODUCER_RESPONSE_CODE));
    } finally {
        stop(retrier);
    }
}
Also used : StandardHttpProducer(com.adaptris.core.http.client.net.StandardHttpProducer) StandaloneRequestor(com.adaptris.core.StandaloneRequestor) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) ConfiguredRequestMethodProvider(com.adaptris.core.http.client.ConfiguredRequestMethodProvider) Test(org.junit.Test)

Example 18 with ConfiguredRequestMethodProvider

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

the class RetryFromJettyTest method testDelete_BadRequest.

@Test
public void testDelete_BadRequest() throws Exception {
    RetryFromJetty retrier = create();
    try {
        start(retrier);
        AdaptrisMessage baseMsg = AdaptrisMessageFactory.getDefaultInstance().newMessage();
        retryStore.write(baseMsg);
        assertNotNull(retryStore.getMetadata(baseMsg.getUniqueId()));
        // we're going to use a POST but with the correct URL.
        // so should be a BAD request.
        AdaptrisMessage triggerMsg = AdaptrisMessageFactory.getDefaultInstance().newMessage();
        String url = jettyHelper.buildUrl(RetryFromJetty.DEFAULT_DELETE_PREFIX + baseMsg.getUniqueId());
        StandardHttpProducer http = buildProducer(url);
        http.setIgnoreServerResponseCode(true);
        http.setMethodProvider(new ConfiguredRequestMethodProvider(RequestMethod.POST));
        ExampleServiceCase.execute(new StandaloneRequestor(http), triggerMsg);
        assertEquals(RetryFromJetty.HTTP_BAD, triggerMsg.getMetadataValue(CoreConstants.HTTP_PRODUCER_RESPONSE_CODE));
    } finally {
        stop(retrier);
    }
}
Also used : StandardHttpProducer(com.adaptris.core.http.client.net.StandardHttpProducer) StandaloneRequestor(com.adaptris.core.StandaloneRequestor) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) ConfiguredRequestMethodProvider(com.adaptris.core.http.client.ConfiguredRequestMethodProvider) Test(org.junit.Test)

Aggregations

ConfiguredRequestMethodProvider (com.adaptris.core.http.client.ConfiguredRequestMethodProvider)18 AdaptrisMessage (com.adaptris.core.AdaptrisMessage)17 Test (org.junit.Test)17 StandaloneRequestor (com.adaptris.core.StandaloneRequestor)16 DefaultMessageFactory (com.adaptris.core.DefaultMessageFactory)12 MockMessageProducer (com.adaptris.core.stubs.MockMessageProducer)12 Channel (com.adaptris.core.Channel)11 ServiceList (com.adaptris.core.ServiceList)11 StandaloneProducer (com.adaptris.core.StandaloneProducer)11 HttpConnection (com.adaptris.core.http.jetty.HttpConnection)11 HttpConsumerTest (com.adaptris.core.http.jetty.HttpConsumerTest)11 JettyHelper.createChannel (com.adaptris.core.http.jetty.JettyHelper.createChannel)11 JettyMessageConsumer (com.adaptris.core.http.jetty.JettyMessageConsumer)11 StandardResponseProducer (com.adaptris.core.http.jetty.StandardResponseProducer)11 StandardWorkflow (com.adaptris.core.StandardWorkflow)9 StandardHttpProducer (com.adaptris.core.http.client.net.StandardHttpProducer)5 PayloadFromTemplateService (com.adaptris.core.services.metadata.PayloadFromTemplateService)5 ServiceException (com.adaptris.core.ServiceException)2 MetadataStreamOutputParameter (com.adaptris.core.common.MetadataStreamOutputParameter)2 TimeInterval (com.adaptris.util.TimeInterval)2