Search in sources :

Example 41 with AdaptrisMessage

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

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

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

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

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

the class ResponseHeaderAsMetadataTest method testAddMetadata.

@Test
public void testAddMetadata() {
    List<String> allow = Arrays.asList("GET", "HEAD", "OPTIONS");
    Map<String, List<String>> headers = new HashMap<>();
    headers.put("Allow", allow);
    headers.put("Content-Type", Arrays.asList("text/xml"));
    ResponseHeadersAsMetadata handler = new ResponseHeadersAsMetadata("", "|");
    AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage();
    handler.addMetadata(headers, msg);
    assertEquals("text/xml", msg.getMetadataValue("Content-Type"));
    assertEquals("GET|HEAD|OPTIONS", msg.getMetadataValue("Allow"));
}
Also used : HashMap(java.util.HashMap) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) List(java.util.List) 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