Search in sources :

Example 41 with Channel

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

the class HttpRequestServiceTest method testRequest_ObjectMetadataResponseHeaders.

@Test
public void testRequest_ObjectMetadataResponseHeaders() throws Exception {
    MockMessageProducer mock = new MockMessageProducer();
    Channel c = HttpHelper.createAndStartChannel(mock);
    HttpRequestService service = new HttpRequestService(HttpHelper.createProduceDestination(c)).withContentType("%message{" + HttpHelper.CONTENT_TYPE + "}").withResponseHeaderHandler(new ResponseHeadersAsObjectMetadata());
    AdaptrisMessage msg = new DefaultMessageFactory().newMessage(TEXT);
    msg.addMetadata(HttpHelper.CONTENT_TYPE, "text/complicated");
    assertFalse(msg.headersContainsKey("Server"));
    try {
        c.requestStart();
        execute(service, msg);
        waitForMessages(mock, 1);
    } finally {
        HttpHelper.stopChannelAndRelease(c);
    }
    assertFalse(msg.headersContainsKey("Server"));
    assertTrue(msg.getObjectHeaders().containsKey("Server"));
}
Also used : DefaultMessageFactory(com.adaptris.core.DefaultMessageFactory) MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) JettyHelper.createChannel(com.adaptris.core.http.jetty.JettyHelper.createChannel) Channel(com.adaptris.core.Channel) Test(org.junit.Test) HttpConsumerTest(com.adaptris.core.http.jetty.HttpConsumerTest)

Example 42 with Channel

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

the class HttpRequestServiceTest method testRequest_GetMethod_ZeroBytes.

@Test
public void testRequest_GetMethod_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(new Service[] { new PayloadFromTemplateService().withTemplate(TEXT), new StandaloneProducer(new StandardResponseProducer(HttpStatus.OK_200)) })));
    HttpRequestService service = new HttpRequestService(HttpHelper.createProduceDestination(c)).withMethod("GET");
    AdaptrisMessage msg = new DefaultMessageFactory().newMessage();
    try {
        start(c);
        execute(service, msg);
        waitForMessages(mock, 1);
    } finally {
        HttpHelper.stopChannelAndRelease(c);
    }
    assertEquals(1, mock.messageCount());
    AdaptrisMessage m2 = mock.getMessages().get(0);
    assertEquals("GET", m2.getMetadataValue(CoreConstants.HTTP_METHOD));
    assertEquals(TEXT, msg.getContent());
}
Also used : DefaultMessageFactory(com.adaptris.core.DefaultMessageFactory) MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) HttpConnection(com.adaptris.core.http.jetty.HttpConnection) StandardResponseProducer(com.adaptris.core.http.jetty.StandardResponseProducer) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) ServiceList(com.adaptris.core.ServiceList) JettyHelper.createChannel(com.adaptris.core.http.jetty.JettyHelper.createChannel) Channel(com.adaptris.core.Channel) JettyMessageConsumer(com.adaptris.core.http.jetty.JettyMessageConsumer) PayloadFromTemplateService(com.adaptris.core.services.metadata.PayloadFromTemplateService) StandaloneProducer(com.adaptris.core.StandaloneProducer) Test(org.junit.Test) HttpConsumerTest(com.adaptris.core.http.jetty.HttpConsumerTest)

Example 43 with Channel

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

the class MetadataRequestHeadersTest method testAddHeaders.

@Test
public void testAddHeaders() throws Exception {
    Channel c = null;
    HttpURLConnection urlC = null;
    try {
        c = HttpHelper.createAndStartChannel();
        URL url = new URL(HttpHelper.createProduceDestination(c));
        urlC = (HttpURLConnection) url.openConnection();
        MetadataRequestHeaders headers = new MetadataRequestHeaders();
        headers.setFilter(new RegexMetadataFilter());
        AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage("");
        String name = testName.getMethodName();
        msg.addMetadata(name, name);
        urlC = headers.addHeaders(msg, urlC);
        assertTrue(contains(urlC, name, name));
    } finally {
        HttpHelper.stopChannelAndRelease(c);
    }
}
Also used : RegexMetadataFilter(com.adaptris.core.metadata.RegexMetadataFilter) HttpURLConnection(java.net.HttpURLConnection) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) Channel(com.adaptris.core.Channel) URL(java.net.URL) Test(org.junit.Test)

Example 44 with Channel

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

the class MetadataRequestHeadersTest method testAddHeaders_Flatten.

@Test
public void testAddHeaders_Flatten() throws Exception {
    Channel c = null;
    HttpURLConnection urlC = null;
    try {
        c = HttpHelper.createAndStartChannel();
        URL url = new URL(HttpHelper.createProduceDestination(c));
        urlC = (HttpURLConnection) url.openConnection();
        MetadataRequestHeaders headers = new MetadataRequestHeaders();
        headers.setUnfold(true);
        headers.setFilter(new RegexMetadataFilter());
        AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage("");
        String name = testName.getMethodName();
        msg.addMetadata(name, name + "\r\n     " + name);
        urlC = headers.addHeaders(msg, urlC);
        assertTrue(contains(urlC, name, name + " " + name));
    } finally {
        HttpHelper.stopChannelAndRelease(c);
    }
}
Also used : RegexMetadataFilter(com.adaptris.core.metadata.RegexMetadataFilter) HttpURLConnection(java.net.HttpURLConnection) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) Channel(com.adaptris.core.Channel) URL(java.net.URL) Test(org.junit.Test)

Example 45 with Channel

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

the class JettyNoBacklogInterceptorTest method retrieveObjectForSampleConfig.

@Override
protected Channel retrieveObjectForSampleConfig() {
    Channel c = new Channel();
    PoolingWorkflow wf = new PoolingWorkflow();
    wf.addInterceptor(new JettyPoolingWorkflowInterceptor());
    wf.addInterceptor(new JettyNoBacklogInterceptor());
    c.setUniqueId(UUID.randomUUID().toString());
    wf.setUniqueId(UUID.randomUUID().toString());
    c.getWorkflowList().add(wf);
    return c;
}
Also used : Channel(com.adaptris.core.Channel) PoolingWorkflow(com.adaptris.core.PoolingWorkflow)

Aggregations

Channel (com.adaptris.core.Channel)322 Test (org.junit.Test)276 Adapter (com.adaptris.core.Adapter)136 MockMessageProducer (com.adaptris.core.stubs.MockMessageProducer)125 AdaptrisMessage (com.adaptris.core.AdaptrisMessage)122 StandardWorkflow (com.adaptris.core.StandardWorkflow)111 ObjectName (javax.management.ObjectName)97 ArrayList (java.util.ArrayList)74 StandaloneProducer (com.adaptris.core.StandaloneProducer)64 PoolingWorkflow (com.adaptris.core.PoolingWorkflow)57 JettyHelper.createChannel (com.adaptris.core.http.jetty.JettyHelper.createChannel)52 Workflow (com.adaptris.core.Workflow)44 MockChannel (com.adaptris.core.stubs.MockChannel)43 DefaultMessageFactory (com.adaptris.core.DefaultMessageFactory)37 TimeInterval (com.adaptris.util.TimeInterval)36 HttpConsumerTest (com.adaptris.core.http.jetty.HttpConsumerTest)35 StaticMockMessageProducer (com.adaptris.core.stubs.StaticMockMessageProducer)35 ServiceList (com.adaptris.core.ServiceList)31 StandaloneRequestor (com.adaptris.core.StandaloneRequestor)30 CoreException (com.adaptris.core.CoreException)29