Search in sources :

Example 1 with HttpRequestService

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

the class JettyAsyncWorkflowInterceptorTest method createRequestor.

private HttpRequestService createRequestor(int port) {
    final HttpRequestService httpService = new HttpRequestService();
    httpService.setUrl("http://localhost:" + port + URL_TO_POST_TO);
    httpService.setContentType("text/xml");
    return httpService;
}
Also used : HttpRequestService(com.adaptris.core.http.client.net.HttpRequestService)

Example 2 with HttpRequestService

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

the class JettyAsyncWorkflowInterceptorTest method testAcrossMultipleWorkflows_WithCacheKey.

@Test
public void testAcrossMultipleWorkflows_WithCacheKey() throws Exception {
    HttpConnection connection = createConnection(Integer.parseInt(PROPERTIES.getProperty(JETTY_HTTP_PORT)));
    JettyMessageConsumer consumer = JettyHelper.createConsumer(URL_TO_POST_TO, getName());
    PoolingWorkflow receivingWF = new PoolingWorkflow();
    // It's a bit lame, but we have to use something that is populated *before entry into the workflow*
    String cacheKey = "%message{" + JettyConstants.JETTY_URI + "}";
    receivingWF.addInterceptor(new JettyAsyncWorkflowInterceptor().withMode(JettyAsyncWorkflowInterceptor.Mode.REQUEST).withCacheKey(cacheKey));
    receivingWF.setShutdownWaitTime(new TimeInterval(1L, TimeUnit.SECONDS));
    receivingWF.setConsumer(consumer);
    StandardWorkflow respondingWF = new StandardWorkflow();
    // Mainly to keep track of the msgID. we use a standard workflow so new objects aren't created.
    MockMessageProducer producer = new MockMessageProducer();
    respondingWF.addInterceptor(new JettyAsyncWorkflowInterceptor().withMode(JettyAsyncWorkflowInterceptor.Mode.RESPONSE).withCacheKey(cacheKey));
    respondingWF.getServiceCollection().add(new PayloadFromTemplateService().withTemplate("hello world"));
    respondingWF.getServiceCollection().add(new JettyResponseService(200, "text/plain"));
    respondingWF.getServiceCollection().add(new StandaloneProducer(producer));
    receivingWF.setProducer(new WorkflowProducer(respondingWF));
    Channel channel = JettyHelper.createChannel(connection, receivingWF, respondingWF);
    HttpRequestService httpService = createRequestor(connection.getPort());
    try {
        start(channel);
        LifecycleHelper.initAndStart(httpService);
        AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(XML_PAYLOAD);
        ExampleServiceCase.execute(httpService, msg);
        assertEquals("hello world", msg.getContent());
        waitForMessages(producer, 1);
        // Grab the message that the standardWorkflow handled; and check the msgId.
        // Should be removed from the static cache.
        assertFalse(JettyAsyncWorkflowInterceptor.cacheContains(producer.getMessages().get(0).getUniqueId()));
    } finally {
        stop(channel);
    }
}
Also used : StandardWorkflow(com.adaptris.core.StandardWorkflow) TimeInterval(com.adaptris.util.TimeInterval) MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) Channel(com.adaptris.core.Channel) HttpRequestService(com.adaptris.core.http.client.net.HttpRequestService) PayloadFromTemplateService(com.adaptris.core.services.metadata.PayloadFromTemplateService) PoolingWorkflow(com.adaptris.core.PoolingWorkflow) StandaloneProducer(com.adaptris.core.StandaloneProducer) Test(org.junit.Test)

Example 3 with HttpRequestService

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

the class ShortCutJettyResponseTest method testService.

@Test
public void testService() throws Exception {
    HttpConnection connection = createConnection(Integer.parseInt(PROPERTIES.getProperty(JETTY_HTTP_PORT)));
    MockMessageProducer mockProducer = new StaticMockMessageProducer();
    mockProducer.getMessages().clear();
    JettyMessageConsumer consumer = JettyHelper.createConsumer(URL_TO_POST_TO);
    PoolingWorkflow workflow = new PoolingWorkflow();
    workflow.setShutdownWaitTime(new TimeInterval(1L, TimeUnit.SECONDS));
    StandardResponseProducer responder = new StandardResponseProducer(HttpStatus.OK_200);
    workflow.setConsumer(consumer);
    workflow.getServiceCollection().add(new WaitService(new TimeInterval(1L, TimeUnit.SECONDS)));
    workflow.getServiceCollection().add(new StandaloneProducer(mockProducer));
    workflow.getServiceCollection().add(new StandaloneProducer(responder));
    workflow.getServiceCollection().add(new ShortCutJettyResponse());
    // Workflow won't get to this before we get the response.
    workflow.getServiceCollection().add(new WaitService(new TimeInterval(10L, TimeUnit.SECONDS)));
    workflow.addInterceptor(new JettyPoolingWorkflowInterceptor());
    Channel channel = JettyHelper.createChannel(connection, workflow);
    HttpRequestService service = JettyHelper.createService(connection.getPort());
    try {
        start(channel);
        AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(XML_PAYLOAD);
        msg.addMetadata(HttpConsumerTest.CONTENT_TYPE_METADATA_KEY, "text/xml");
        long start = System.currentTimeMillis();
        ExampleServiceCase.execute(service, msg);
        ;
        long end = System.currentTimeMillis();
        assertTrue(end - start < TimeUnit.SECONDS.toMillis(10));
    } finally {
        stop(channel);
    }
}
Also used : WaitService(com.adaptris.core.services.WaitService) StaticMockMessageProducer(com.adaptris.core.stubs.StaticMockMessageProducer) MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) TimeInterval(com.adaptris.util.TimeInterval) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) Channel(com.adaptris.core.Channel) HttpRequestService(com.adaptris.core.http.client.net.HttpRequestService) PoolingWorkflow(com.adaptris.core.PoolingWorkflow) StaticMockMessageProducer(com.adaptris.core.stubs.StaticMockMessageProducer) StandaloneProducer(com.adaptris.core.StandaloneProducer) Test(org.junit.Test)

Example 4 with HttpRequestService

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

the class JettyNoBacklogInterceptorTest method testInterceptor.

@Test
public void testInterceptor() throws Exception {
    int jettyPort = PortManager.nextUnusedPort(Integer.parseInt(PROPERTIES.getProperty(JETTY_HTTP_PORT)));
    HttpConnection connection = createConnection(jettyPort);
    JettyMessageConsumer consumer = JettyHelper.createConsumer(URL_TO_POST_TO);
    PoolingWorkflow workflow = new PoolingWorkflow();
    workflow.setPoolSize(1);
    workflow.addInterceptor(new JettyPoolingWorkflowInterceptor());
    workflow.addInterceptor(new JettyNoBacklogInterceptor());
    workflow.setShutdownWaitTime(new TimeInterval(1L, TimeUnit.SECONDS));
    workflow.setConsumer(consumer);
    workflow.getServiceCollection().add(new WaitService(new TimeInterval(3L, TimeUnit.SECONDS)));
    Channel channel = JettyHelper.createChannel(connection, workflow);
    final HttpRequestService httpService = new HttpRequestService();
    httpService.setUrl("http://localhost:" + connection.getPort() + URL_TO_POST_TO);
    httpService.setContentType("text/xml");
    HttpRequestService expect503 = DefaultMarshaller.roundTrip(httpService);
    try {
        start(channel);
        new Thread(runnableWrapper(httpService)).start();
        Awaitility.await().atMost(Duration.ofSeconds(5)).with().pollInterval(Duration.ofMillis(100)).until(() -> workflow.currentlyActiveObjects() == 1);
        // LifecycleHelper.waitQuietly(500);
        // should be waiting in the WaitService.
        ExampleServiceCase.execute(expect503, AdaptrisMessageFactory.getDefaultInstance().newMessage(XML_PAYLOAD));
        fail();
    } catch (ServiceException expected) {
        assertEquals(ProduceException.class, expected.getCause().getClass());
        assertTrue(expected.getCause().getMessage().contains("503"));
    } finally {
        stop(channel);
        PortManager.release(jettyPort);
    }
}
Also used : WaitService(com.adaptris.core.services.WaitService) TimeInterval(com.adaptris.util.TimeInterval) Channel(com.adaptris.core.Channel) ProduceException(com.adaptris.core.ProduceException) HttpRequestService(com.adaptris.core.http.client.net.HttpRequestService) ServiceException(com.adaptris.core.ServiceException) PoolingWorkflow(com.adaptris.core.PoolingWorkflow) Test(org.junit.Test)

Example 5 with HttpRequestService

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

the class JettyAsyncWorkflowInterceptorTest method testAcrossMultipleWorkflows.

@Test
public void testAcrossMultipleWorkflows() throws Exception {
    HttpConnection connection = createConnection(Integer.parseInt(PROPERTIES.getProperty(JETTY_HTTP_PORT)));
    JettyMessageConsumer consumer = JettyHelper.createConsumer(URL_TO_POST_TO, getName());
    PoolingWorkflow receivingWF = new PoolingWorkflow();
    receivingWF.addInterceptor(new JettyAsyncWorkflowInterceptor().withMode(JettyAsyncWorkflowInterceptor.Mode.REQUEST));
    receivingWF.setShutdownWaitTime(new TimeInterval(1L, TimeUnit.SECONDS));
    receivingWF.setConsumer(consumer);
    StandardWorkflow respondingWF = new StandardWorkflow();
    // Mainly to keep track of the msgID. we use a standard workflow so new objects aren't created.
    MockMessageProducer producer = new MockMessageProducer();
    respondingWF.addInterceptor(new JettyAsyncWorkflowInterceptor().withMode(JettyAsyncWorkflowInterceptor.Mode.RESPONSE));
    respondingWF.getServiceCollection().add(new PayloadFromTemplateService().withTemplate("hello world"));
    respondingWF.getServiceCollection().add(new JettyResponseService(200, "text/plain"));
    respondingWF.getServiceCollection().add(new StandaloneProducer(producer));
    receivingWF.setProducer(new WorkflowProducer(respondingWF));
    Channel channel = JettyHelper.createChannel(connection, receivingWF, respondingWF);
    HttpRequestService httpService = createRequestor(connection.getPort());
    try {
        start(channel);
        LifecycleHelper.initAndStart(httpService);
        AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(XML_PAYLOAD);
        ExampleServiceCase.execute(httpService, msg);
        assertEquals("hello world", msg.getContent());
        waitForMessages(producer, 1);
        // Grab the message that the standardWorkflow handled; and check the msgId.
        // Should be removed from the static cache.
        assertFalse(JettyAsyncWorkflowInterceptor.cacheContains(producer.getMessages().get(0).getUniqueId()));
    } finally {
        stop(channel);
    }
}
Also used : StandardWorkflow(com.adaptris.core.StandardWorkflow) TimeInterval(com.adaptris.util.TimeInterval) MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) Channel(com.adaptris.core.Channel) HttpRequestService(com.adaptris.core.http.client.net.HttpRequestService) PayloadFromTemplateService(com.adaptris.core.services.metadata.PayloadFromTemplateService) PoolingWorkflow(com.adaptris.core.PoolingWorkflow) StandaloneProducer(com.adaptris.core.StandaloneProducer) Test(org.junit.Test)

Aggregations

HttpRequestService (com.adaptris.core.http.client.net.HttpRequestService)7 Test (org.junit.Test)6 AdaptrisMessage (com.adaptris.core.AdaptrisMessage)5 Channel (com.adaptris.core.Channel)5 PoolingWorkflow (com.adaptris.core.PoolingWorkflow)4 StandaloneProducer (com.adaptris.core.StandaloneProducer)4 MockMessageProducer (com.adaptris.core.stubs.MockMessageProducer)4 TimeInterval (com.adaptris.util.TimeInterval)4 StandardWorkflow (com.adaptris.core.StandardWorkflow)3 PayloadFromTemplateService (com.adaptris.core.services.metadata.PayloadFromTemplateService)3 WaitService (com.adaptris.core.services.WaitService)2 ChannelList (com.adaptris.core.ChannelList)1 ProduceException (com.adaptris.core.ProduceException)1 ServiceException (com.adaptris.core.ServiceException)1 StaticMockMessageProducer (com.adaptris.core.stubs.StaticMockMessageProducer)1 InputStream (java.io.InputStream)1 List (java.util.List)1