Search in sources :

Example 11 with StandaloneRequestor

use of com.adaptris.core.StandaloneRequestor in project interlok by adaptris.

the class JettyResponseServiceTest method testResponseWithError.

@Test
public void testResponseWithError() throws Exception {
    JettyResponseService responder = new JettyResponseService().withHttpStatus("500").withContentType("text/plain").withResponseHeaderProvider(new NoOpResponseHeaderProvider());
    HttpConnection httpConnection = createConnection();
    ServiceList list = new ServiceList(responder);
    Channel c = createChannel(httpConnection, createWorkflow(createConsumer(URL_TO_POST_TO), new MockMessageProducer(), list));
    StandaloneRequestor requestor = createRequestor(httpConnection.getPort());
    AdaptrisMessage msg = createMessage();
    try {
        c.requestStart();
        start(requestor);
        requestor.doService(msg);
        fail("StandaloneRequestor.doService() success even though we should have got a 500 error back");
    } catch (ServiceException expected) {
        ;
    } finally {
        c.requestClose();
        stop(requestor);
        PortManager.release(httpConnection.getPort());
    }
}
Also used : StandaloneRequestor(com.adaptris.core.StandaloneRequestor) MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) ServiceException(com.adaptris.core.ServiceException) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) ServiceList(com.adaptris.core.ServiceList) JettyHelper.createChannel(com.adaptris.core.http.jetty.JettyHelper.createChannel) Channel(com.adaptris.core.Channel) Test(org.junit.Test)

Example 12 with StandaloneRequestor

use of com.adaptris.core.StandaloneRequestor in project interlok by adaptris.

the class StandardResponseProducerTest method testResponse_NoOpResponseHeaders.

@Test
public void testResponse_NoOpResponseHeaders() throws Exception {
    StandardResponseProducer responder = new StandardResponseProducer(HttpStatus.OK_200);
    responder.setResponseHeaderProvider(new NoOpResponseHeaderProvider());
    HttpConnection httpConnection = createConnection();
    Channel c = createChannel(httpConnection, createWorkflow(createConsumer(URL_TO_POST_TO), new MockMessageProducer(), new ServiceList(new Service[] { new StandaloneProducer(responder) })));
    StandaloneRequestor requestor = createRequestor(httpConnection.getPort());
    AdaptrisMessage msg = createMessage();
    try {
        c.requestStart();
        start(requestor);
        requestor.doService(msg);
        assertEquals(TEXT, msg.getContent());
    } finally {
        c.requestClose();
        stop(requestor);
        PortManager.release(httpConnection.getPort());
    }
}
Also used : StandaloneRequestor(com.adaptris.core.StandaloneRequestor) MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) ServiceList(com.adaptris.core.ServiceList) JettyHelper.createChannel(com.adaptris.core.http.jetty.JettyHelper.createChannel) Channel(com.adaptris.core.Channel) StandaloneProducer(com.adaptris.core.StandaloneProducer) Test(org.junit.Test)

Example 13 with StandaloneRequestor

use of com.adaptris.core.StandaloneRequestor 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 14 with StandaloneRequestor

use of com.adaptris.core.StandaloneRequestor in project interlok by adaptris.

the class StandardResponseProducerTest method testResponse_MetadataContentType.

@Test
public void testResponse_MetadataContentType() throws Exception {
    StandardResponseProducer responder = new StandardResponseProducer(HttpStatus.OK_200);
    responder.setContentTypeProvider(new MetadataContentTypeProvider("MyContentType"));
    AddMetadataService addMetadata = new AddMetadataService(Arrays.asList(new MetadataElement[] { new MetadataElement("MyContentType", "text/xml") }));
    HttpConnection httpConnection = createConnection();
    Channel c = createChannel(httpConnection, createWorkflow(createConsumer(URL_TO_POST_TO), new MockMessageProducer(), new ServiceList(new Service[] { addMetadata, new StandaloneProducer(responder) })));
    StandaloneRequestor requestor = createRequestor(httpConnection.getPort());
    AdaptrisMessage msg = createMessage();
    try {
        c.requestStart();
        start(requestor);
        requestor.doService(msg);
        assertEquals(TEXT, msg.getContent());
        assertTrue(msg.containsKey("Content-Type"));
        assertTrue(msg.getMetadataValue("Content-Type").startsWith("text/xml"));
    } finally {
        c.requestClose();
        stop(requestor);
        PortManager.release(httpConnection.getPort());
    }
}
Also used : MetadataContentTypeProvider(com.adaptris.core.http.MetadataContentTypeProvider) StandaloneRequestor(com.adaptris.core.StandaloneRequestor) MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) ServiceList(com.adaptris.core.ServiceList) JettyHelper.createChannel(com.adaptris.core.http.jetty.JettyHelper.createChannel) Channel(com.adaptris.core.Channel) MetadataElement(com.adaptris.core.MetadataElement) AddMetadataService(com.adaptris.core.services.metadata.AddMetadataService) StandaloneProducer(com.adaptris.core.StandaloneProducer) Test(org.junit.Test)

Example 15 with StandaloneRequestor

use of com.adaptris.core.StandaloneRequestor 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)

Aggregations

StandaloneRequestor (com.adaptris.core.StandaloneRequestor)50 AdaptrisMessage (com.adaptris.core.AdaptrisMessage)49 Test (org.junit.Test)49 MockMessageProducer (com.adaptris.core.stubs.MockMessageProducer)33 Channel (com.adaptris.core.Channel)30 JettyHelper.createChannel (com.adaptris.core.http.jetty.JettyHelper.createChannel)30 ServiceList (com.adaptris.core.ServiceList)23 StandaloneProducer (com.adaptris.core.StandaloneProducer)19 ConfiguredRequestMethodProvider (com.adaptris.core.http.client.ConfiguredRequestMethodProvider)16 DefaultMessageFactory (com.adaptris.core.DefaultMessageFactory)15 HttpConsumerTest (com.adaptris.core.http.jetty.HttpConsumerTest)15 StandardWorkflow (com.adaptris.core.StandardWorkflow)12 HttpConnection (com.adaptris.core.http.jetty.HttpConnection)12 JettyMessageConsumer (com.adaptris.core.http.jetty.JettyMessageConsumer)12 StandardResponseProducer (com.adaptris.core.http.jetty.StandardResponseProducer)12 StandardHttpProducer (com.adaptris.core.http.client.net.StandardHttpProducer)8 PayloadFromTemplateService (com.adaptris.core.services.metadata.PayloadFromTemplateService)8 TimeInterval (com.adaptris.util.TimeInterval)7 MetadataContentTypeProvider (com.adaptris.core.http.MetadataContentTypeProvider)6 ServiceException (com.adaptris.core.ServiceException)5