Search in sources :

Example 46 with PipeLineSession

use of nl.nn.adapterframework.core.PipeLineSession in project iaf by ibissource.

the class HttpSenderTest method simpleMockedHttpPostJSON.

@Test
public void simpleMockedHttpPostJSON() throws Throwable {
    sender = getSender();
    Message input = new Message("{\"key\": \"value\"}");
    PipeLineSession pls = new PipeLineSession(session);
    sender.setMethodType(HttpMethod.POST);
    sender.setContentType("application/json");
    sender.configure();
    sender.open();
    String result = sender.sendMessage(input, pls).asString();
    assertEqualsIgnoreCRLF(getFile("simpleMockedHttpPostJSON.txt"), result);
}
Also used : Message(nl.nn.adapterframework.stream.Message) UrlMessage(nl.nn.adapterframework.stream.UrlMessage) PipeLineSession(nl.nn.adapterframework.core.PipeLineSession) Test(org.junit.Test)

Example 47 with PipeLineSession

use of nl.nn.adapterframework.core.PipeLineSession in project iaf by ibissource.

the class HttpSenderResultTest method simpleMultiPartResponseMockedHttpGet.

@Test
public void simpleMultiPartResponseMockedHttpGet() throws Exception {
    HttpSender sender = createHttpSenderFromFile("multipart1.txt");
    PipeLineSession pls = new PipeLineSession();
    sender.setMethodType(HttpMethod.GET);
    sender.setMultipartResponse(true);
    sender.configure();
    sender.open();
    String result = sender.sendMessage(new Message("tralala"), pls).asString();
    assertEquals("text default", result);
    int multipartAttachmentCount = 0;
    for (Map.Entry<String, Object> entry : pls.entrySet()) {
        System.out.println("found multipart [" + entry.getKey() + "]");
        multipartAttachmentCount++;
    }
    assertEquals(2, multipartAttachmentCount);
    InputStream multipart1 = pls.getMessage("multipart1").asInputStream();
    assertEquals("Content of a txt file.", Misc.streamToString(multipart1).trim());
    InputStream multipart2 = pls.getMessage("multipart2").asInputStream();
    assertEquals("<!DOCTYPE html><title>Content of a html file.</title>", Misc.streamToString(multipart2).trim());
}
Also used : Message(nl.nn.adapterframework.stream.Message) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) PipeLineSession(nl.nn.adapterframework.core.PipeLineSession) Map(java.util.Map) Test(org.junit.Test)

Example 48 with PipeLineSession

use of nl.nn.adapterframework.core.PipeLineSession in project iaf by ibissource.

the class HttpSenderResultTest method simpleBase64MockedHttpGet.

@Test
public void simpleBase64MockedHttpGet() throws Exception {
    HttpSender sender = createHttpSender();
    PipeLineSession session = new PipeLineSession();
    sender.setMethodType(HttpMethod.GET);
    sender.setBase64(true);
    sender.configure();
    sender.open();
    // Use InputStream 'content' as result.
    String result = sender.sendMessage(new Message(""), session).asString();
    assertEquals("PGR1bW15IHJlc3VsdC8+", result.trim());
}
Also used : Message(nl.nn.adapterframework.stream.Message) PipeLineSession(nl.nn.adapterframework.core.PipeLineSession) Test(org.junit.Test)

Example 49 with PipeLineSession

use of nl.nn.adapterframework.core.PipeLineSession in project iaf by ibissource.

the class HttpSenderTest method simpleMockedHttpPut.

@Test
public void simpleMockedHttpPut() throws Throwable {
    // Cannot add headers (aka parameters) for this test!
    sender = getSender(false);
    Message input = new Message("hallo");
    PipeLineSession pls = new PipeLineSession(session);
    // should handle a mix of upper and lowercase characters :)
    sender.setMethodType(HttpMethod.PUT);
    sender.configure();
    sender.open();
    String result = sender.sendMessage(input, pls).asString();
    assertEqualsIgnoreCRLF(getFile("simpleMockedHttpPut.txt"), result.trim());
}
Also used : Message(nl.nn.adapterframework.stream.Message) UrlMessage(nl.nn.adapterframework.stream.UrlMessage) PipeLineSession(nl.nn.adapterframework.core.PipeLineSession) Test(org.junit.Test)

Example 50 with PipeLineSession

use of nl.nn.adapterframework.core.PipeLineSession in project iaf by ibissource.

the class HttpSenderTest method postTypeMtom.

@Test
public void postTypeMtom() throws Throwable {
    sender = getSender();
    Message input = new Message("<xml>input</xml>");
    PipeLineSession pls = new PipeLineSession(session);
    sender.setMethodType(HttpMethod.POST);
    sender.setPostType(PostType.MTOM);
    sender.setInputMessageParam("request");
    String xmlMultipart = "<parts><part type=\"file\" name=\"document.pdf\" " + "sessionKey=\"part_file\" size=\"72833\" " + "mimeType=\"application/pdf\"/></parts>";
    pls.put("multipartXml", xmlMultipart);
    pls.put("part_file", new ByteArrayInputStream("<dummy xml file/>".getBytes()));
    sender.setMtomEnabled(true);
    sender.setMultipartXmlSessionKey("multipartXml");
    sender.configure();
    sender.open();
    String result = sender.sendMessage(input, pls).asString();
    assertEqualsIgnoreCRLF(getFile("simpleMockedHttpMtom.txt"), result.trim());
}
Also used : Message(nl.nn.adapterframework.stream.Message) UrlMessage(nl.nn.adapterframework.stream.UrlMessage) ByteArrayInputStream(java.io.ByteArrayInputStream) PipeLineSession(nl.nn.adapterframework.core.PipeLineSession) Test(org.junit.Test)

Aggregations

PipeLineSession (nl.nn.adapterframework.core.PipeLineSession)270 Message (nl.nn.adapterframework.stream.Message)210 Test (org.junit.Test)202 SenderException (nl.nn.adapterframework.core.SenderException)43 PipeRunResult (nl.nn.adapterframework.core.PipeRunResult)33 UrlMessage (nl.nn.adapterframework.stream.UrlMessage)30 ByteArrayInputStream (java.io.ByteArrayInputStream)26 IOException (java.io.IOException)25 Parameter (nl.nn.adapterframework.parameters.Parameter)23 PipeForward (nl.nn.adapterframework.core.PipeForward)21 ParameterValueList (nl.nn.adapterframework.parameters.ParameterValueList)17 Date (java.util.Date)15 ConfigurationException (nl.nn.adapterframework.configuration.ConfigurationException)14 InputStream (java.io.InputStream)11 TimeoutException (nl.nn.adapterframework.core.TimeoutException)11 ParameterList (nl.nn.adapterframework.parameters.ParameterList)11 Map (java.util.Map)10 SimpleDateFormat (java.text.SimpleDateFormat)9 SOAPMessage (javax.xml.soap.SOAPMessage)9 URL (java.net.URL)8