Search in sources :

Example 6 with ConfiguredRequestMethodProvider

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

the class StandardHttpProducerTest method testRequest_ErrorCode_NullResponseBody.

@Test
public void testRequest_ErrorCode_NullResponseBody() throws Exception {
    // INTERLOK-3527 - make sure we don't get an NPE.
    MockMessageProducer mock = new MockMessageProducer();
    HttpConnection jc = HttpHelper.createConnection();
    JettyMessageConsumer mc = createConsumer(HttpHelper.URL_TO_POST_TO);
    ServiceList sl = new ServiceList();
    // To trigger the bug we need the getErrorStream() method to return null.  A response code > 400 will not.
    sl.add(new StandaloneProducer(new StandardResponseProducer(HttpStatus.SWITCH_PROTOCOL_101)));
    Channel c = createChannel(jc, createWorkflow(mc, mock, sl));
    StandardHttpProducer stdHttp = new StandardHttpProducer().withURL(HttpHelper.createURL(c));
    stdHttp.setMethodProvider(new ConfiguredRequestMethodProvider(RequestMethodProvider.RequestMethod.GET));
    stdHttp.setIgnoreServerResponseCode(true);
    // Metadata stream is the source of the bug, so lets use it here rather than the payload default.
    stdHttp.setResponseBody(new MetadataStreamOutputParameter());
    StandaloneRequestor producer = new StandaloneRequestor(stdHttp);
    AdaptrisMessage msg = new DefaultMessageFactory().newMessage();
    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));
}
Also used : DefaultMessageFactory(com.adaptris.core.DefaultMessageFactory) 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) MetadataStreamOutputParameter(com.adaptris.core.common.MetadataStreamOutputParameter) 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 7 with ConfiguredRequestMethodProvider

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

the class StandardHttpProducerTest method testRequest_PostMethod_ZeroBytes.

@Test
public void testRequest_PostMethod_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()));
    StandardWorkflow workflow = (StandardWorkflow) c.getWorkflowList().get(0);
    PayloadFromTemplateService pms = new PayloadFromTemplateService().withTemplate(TEXT);
    workflow.getServiceCollection().add(pms);
    workflow.getServiceCollection().add(new StandaloneProducer(new StandardResponseProducer(HttpStatus.OK_200)));
    StandardHttpProducer stdHttp = new StandardHttpProducer().withURL(HttpHelper.createURL(c));
    stdHttp.setMethodProvider(new ConfiguredRequestMethodProvider(RequestMethodProvider.RequestMethod.POST));
    StandaloneRequestor producer = new StandaloneRequestor(stdHttp);
    AdaptrisMessage msg = new DefaultMessageFactory().newMessage();
    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(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) 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) ConfiguredRequestMethodProvider(com.adaptris.core.http.client.ConfiguredRequestMethodProvider) HttpConsumerTest(com.adaptris.core.http.jetty.HttpConsumerTest) Test(org.junit.Test)

Example 8 with ConfiguredRequestMethodProvider

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

the class RetryFromJettyTest method testRetry_WrongMethod.

@Test
public void testRetry_WrongMethod() throws Exception {
    RetryFromJetty retrier = create();
    StandardWorkflow workflow = createWorkflow();
    try {
        MockMessageProducer workflowProducer = (MockMessageProducer) workflow.getProducer();
        retrier.addWorkflow(workflow);
        retrier.addWorkflow(createWorkflow());
        start(workflow, retrier);
        AdaptrisMessage baseMsg = AdaptrisMessageFactory.getDefaultInstance().newMessage();
        baseMsg.addMetadata(Workflow.WORKFLOW_ID_KEY, workflow.obtainWorkflowId());
        retryStore.write(baseMsg);
        assertNotNull(retryStore.getMetadata(baseMsg.getUniqueId()));
        // This should result in a route condition that doesn't match POST + the msgId so 400 is
        // expected
        String url = jettyHelper.buildUrl(RetryFromJetty.DEFAULT_ENDPOINT_PREFIX + baseMsg.getUniqueId());
        StandardHttpProducer http = buildProducer(url);
        http.setIgnoreServerResponseCode(true);
        http.setMethodProvider(new ConfiguredRequestMethodProvider(RequestMethodProvider.RequestMethod.GET));
        AdaptrisMessage triggerMsg = AdaptrisMessageFactory.getDefaultInstance().newMessage();
        ExampleServiceCase.execute(new StandaloneRequestor(http), triggerMsg);
        assertEquals(RetryFromJetty.HTTP_BAD, triggerMsg.getMetadataValue(CoreConstants.HTTP_PRODUCER_RESPONSE_CODE));
    } finally {
        stop(retrier, workflow);
    }
}
Also used : StandardHttpProducer(com.adaptris.core.http.client.net.StandardHttpProducer) StandaloneRequestor(com.adaptris.core.StandaloneRequestor) StandardWorkflow(com.adaptris.core.StandardWorkflow) MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) ConfiguredRequestMethodProvider(com.adaptris.core.http.client.ConfiguredRequestMethodProvider) Test(org.junit.Test)

Example 9 with ConfiguredRequestMethodProvider

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

the class RetryFromJettyTest method testDelete.

@Test
public void testDelete() throws Exception {
    RetryFromJetty retrier = create();
    try {
        start(retrier);
        AdaptrisMessage baseMsg = AdaptrisMessageFactory.getDefaultInstance().newMessage();
        retryStore.write(baseMsg);
        assertNotNull(retryStore.getMetadata(baseMsg.getUniqueId()));
        // This should result in a msgId that isn't found; so we get a 500...
        AdaptrisMessage triggerMsg = AdaptrisMessageFactory.getDefaultInstance().newMessage();
        String url = jettyHelper.buildUrl(RetryFromJetty.DEFAULT_DELETE_PREFIX + baseMsg.getUniqueId());
        StandardHttpProducer http = buildProducer(url);
        http.setMethodProvider(new ConfiguredRequestMethodProvider(RequestMethod.DELETE));
        http.setIgnoreServerResponseCode(true);
        ExampleServiceCase.execute(new StandaloneRequestor(http), triggerMsg);
        assertEquals(RetryFromJetty.HTTP_OK, 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)

Example 10 with ConfiguredRequestMethodProvider

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

the class RetryFromJettyTest method testDelete_NotFound.

@Test
public void testDelete_NotFound() throws Exception {
    RetryFromJetty retrier = create();
    try {
        start(retrier);
        AdaptrisMessage baseMsg = AdaptrisMessageFactory.getDefaultInstance().newMessage();
        retryStore.write(baseMsg);
        assertNotNull(retryStore.getMetadata(baseMsg.getUniqueId()));
        // This should result in a msgId that isn't found; so we get a 500...
        AdaptrisMessage triggerMsg = AdaptrisMessageFactory.getDefaultInstance().newMessage();
        String url = jettyHelper.buildUrl(RetryFromJetty.DEFAULT_DELETE_PREFIX + triggerMsg.getUniqueId());
        StandardHttpProducer http = buildProducer(url);
        http.setMethodProvider(new ConfiguredRequestMethodProvider(RequestMethod.DELETE));
        http.setIgnoreServerResponseCode(true);
        ExampleServiceCase.execute(new StandaloneRequestor(http), triggerMsg);
        assertEquals(RetryFromJetty.HTTP_NOT_FOUND, 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