Search in sources :

Example 26 with AdaptrisMessage

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

the class HttpConsumerTest method testBasicConsumeWorkflow_ConsumeDestinationContainsURL.

@Test
public void testBasicConsumeWorkflow_ConsumeDestinationContainsURL() throws Exception {
    HttpConnection connection = createConnection(null);
    MockMessageProducer mockProducer = new MockMessageProducer();
    Channel channel = JettyHelper.createChannel(connection, JettyHelper.createConsumer("http://localhost:8080" + URL_TO_POST_TO), mockProducer);
    try {
        channel.requestStart();
        AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(XML_PAYLOAD);
        msg.addMetadata(CONTENT_TYPE_METADATA_KEY, "text/xml");
        httpProducer.setUrl(createProduceDestinationUrl(connection.getPort()));
        start(httpProducer);
        AdaptrisMessage reply = httpProducer.request(msg);
        assertEquals("Reply Payloads", XML_PAYLOAD, reply.getContent());
        doAssertions(mockProducer);
    } finally {
        stop(httpProducer);
        channel.requestClose();
        PortManager.release(connection.getPort());
    }
}
Also used : MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) StaticMockMessageProducer(com.adaptris.core.stubs.StaticMockMessageProducer) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) Channel(com.adaptris.core.Channel) Test(org.junit.Test)

Example 27 with AdaptrisMessage

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

the class HttpConsumerTest method testBasicConsumeWorkflow_AcrossRestarts.

@Test
public void testBasicConsumeWorkflow_AcrossRestarts() throws Exception {
    HttpConnection connection = createConnection(null);
    MockMessageProducer mockProducer = new MockMessageProducer();
    Channel channel = JettyHelper.createChannel(connection, JettyHelper.createConsumer(URL_TO_POST_TO), mockProducer);
    try {
        channel.requestStart();
        channel.requestClose();
        channel.requestStart();
        AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(XML_PAYLOAD);
        msg.addMetadata(CONTENT_TYPE_METADATA_KEY, "text/xml");
        httpProducer.setUrl(createProduceDestinationUrl(connection.getPort()));
        start(httpProducer);
        AdaptrisMessage reply = httpProducer.request(msg);
        assertEquals("Reply Payloads", XML_PAYLOAD, reply.getContent());
        doAssertions(mockProducer);
    } finally {
        stop(httpProducer);
        channel.requestClose();
        PortManager.release(connection.getPort());
    }
}
Also used : MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) StaticMockMessageProducer(com.adaptris.core.stubs.StaticMockMessageProducer) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) Channel(com.adaptris.core.Channel) Test(org.junit.Test)

Example 28 with AdaptrisMessage

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

the class HttpsConsumerTest method testTLS_ConsumeWorkflow.

@Test
public void testTLS_ConsumeWorkflow() throws Exception {
    String oldName = Thread.currentThread().getName();
    Thread.currentThread().setName(getName());
    HttpConnection connection = createConnection(null);
    ((HttpsConnection) connection).getSslProperties().add(new KeyValuePair(SslProperty.ExcludeProtocols.name(), "SSLv3,TLSv1.1,"));
    MockMessageProducer mockProducer = new MockMessageProducer();
    SimpleHttpProducer myHttpProducer = createProducer(new VersionedHttpsProduceConnection("TLSv1.2"));
    Channel channel = JettyHelper.createChannel(connection, JettyHelper.createConsumer(URL_TO_POST_TO), mockProducer);
    try {
        channel.requestStart();
        AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(XML_PAYLOAD);
        msg.addMetadata(CONTENT_TYPE_METADATA_KEY, "text/xml");
        myHttpProducer.setUrl(createProduceDestinationUrl(connection.getPort()));
        start(myHttpProducer);
        AdaptrisMessage reply = myHttpProducer.request(msg);
        assertEquals("Reply Payloads", XML_PAYLOAD, reply.getContent());
        doAssertions(mockProducer);
    } finally {
        stop(myHttpProducer);
        channel.requestClose();
        PortManager.release(connection.getPort());
        Thread.currentThread().setName(oldName);
    }
}
Also used : KeyValuePair(com.adaptris.util.KeyValuePair) MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) SimpleHttpProducer(com.adaptris.http.legacy.SimpleHttpProducer) Channel(com.adaptris.core.Channel) VersionedHttpsProduceConnection(com.adaptris.http.legacy.VersionedHttpsProduceConnection) Test(org.junit.Test)

Example 29 with AdaptrisMessage

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

the class JettyAsyncWorkflowInterceptorTest method testInterceptor_Cache.

@Test
public void testInterceptor_Cache() throws Exception {
    JettyAsyncWorkflowInterceptor requestor = new JettyAsyncWorkflowInterceptor().withMode(JettyAsyncWorkflowInterceptor.Mode.REQUEST);
    JettyAsyncWorkflowInterceptor responder = new JettyAsyncWorkflowInterceptor().withMode(JettyAsyncWorkflowInterceptor.Mode.RESPONSE);
    AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(XML_PAYLOAD);
    try {
        assertFalse(JettyAsyncWorkflowInterceptor.cacheContains("hello"));
        assertFalse(JettyAsyncWorkflowInterceptor.removeEntry("hello"));
        start(responder, requestor);
        requestor.workflowStart(msg);
        assertTrue(JettyAsyncWorkflowInterceptor.cacheContains(msg.getUniqueId()));
        responder.workflowStart(msg);
        responder.workflowStart(AdaptrisMessageFactory.getDefaultInstance().newMessage(XML_PAYLOAD));
        responder.workflowEnd(AdaptrisMessageFactory.getDefaultInstance().newMessage(XML_PAYLOAD), AdaptrisMessageFactory.getDefaultInstance().newMessage());
        assertFalse(JettyAsyncWorkflowInterceptor.cacheContains(msg.getUniqueId()));
    } finally {
        stop(responder, requestor);
    }
}
Also used : AdaptrisMessage(com.adaptris.core.AdaptrisMessage) Test(org.junit.Test)

Example 30 with AdaptrisMessage

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

Aggregations

AdaptrisMessage (com.adaptris.core.AdaptrisMessage)1495 Test (org.junit.Test)1362 ServiceException (com.adaptris.core.ServiceException)171 DefaultMessageFactory (com.adaptris.core.DefaultMessageFactory)158 MockMessageProducer (com.adaptris.core.stubs.MockMessageProducer)156 StandaloneProducer (com.adaptris.core.StandaloneProducer)125 Channel (com.adaptris.core.Channel)122 MetadataElement (com.adaptris.core.MetadataElement)94 File (java.io.File)89 TimeInterval (com.adaptris.util.TimeInterval)77 CoreException (com.adaptris.core.CoreException)67 Session (javax.jms.Session)62 StandardWorkflow (com.adaptris.core.StandardWorkflow)57 GuidGenerator (com.adaptris.util.GuidGenerator)56 JettyHelper.createChannel (com.adaptris.core.http.jetty.JettyHelper.createChannel)50 StandaloneRequestor (com.adaptris.core.StandaloneRequestor)49 Message (javax.jms.Message)47 XPath (com.adaptris.util.text.xml.XPath)45 ServiceList (com.adaptris.core.ServiceList)43 Document (org.w3c.dom.Document)40