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"));
}
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());
}
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);
}
}
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);
}
}
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"));
}
Aggregations