Search in sources :

Example 1 with StandardHttpProducer

use of com.adaptris.core.http.client.net.StandardHttpProducer 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 2 with StandardHttpProducer

use of com.adaptris.core.http.client.net.StandardHttpProducer 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 3 with StandardHttpProducer

use of com.adaptris.core.http.client.net.StandardHttpProducer 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 4 with StandardHttpProducer

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

Example 5 with StandardHttpProducer

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

the class RetryFromJettyTest method testRetry.

@Test
public void testRetry() 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()));
        String url = jettyHelper.buildUrl(RetryFromJetty.DEFAULT_ENDPOINT_PREFIX + baseMsg.getUniqueId());
        StandardHttpProducer http = buildProducer(url);
        AdaptrisMessage triggerMsg = AdaptrisMessageFactory.getDefaultInstance().newMessage();
        ExampleServiceCase.execute(new StandaloneRequestor(http), triggerMsg);
        assertEquals(RetryFromJetty.HTTP_ACCEPTED, triggerMsg.getMetadataValue(CoreConstants.HTTP_PRODUCER_RESPONSE_CODE));
        // This should trigger the workflow, so we should wait for the message
        await().atMost(Duration.ofSeconds(1)).with().pollInterval(Duration.ofMillis(100)).until(workflowProducer::messageCount, greaterThanOrEqualTo(1));
        assertEquals(1, workflowProducer.messageCount());
    } 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) Test(org.junit.Test)

Aggregations

StandardHttpProducer (com.adaptris.core.http.client.net.StandardHttpProducer)9 StandaloneRequestor (com.adaptris.core.StandaloneRequestor)8 AdaptrisMessage (com.adaptris.core.AdaptrisMessage)7 Test (org.junit.Test)7 ConfiguredRequestMethodProvider (com.adaptris.core.http.client.ConfiguredRequestMethodProvider)5 StandardWorkflow (com.adaptris.core.StandardWorkflow)3 MockMessageProducer (com.adaptris.core.stubs.MockMessageProducer)3 MetadataContentTypeProvider (com.adaptris.core.http.MetadataContentTypeProvider)2 NullConnection (com.adaptris.core.NullConnection)1 ResponseHeadersAsMetadata (com.adaptris.core.http.client.net.ResponseHeadersAsMetadata)1