HttpSender extends HttpSenderBase { @Override public void configure() throws ConfigurationException { if(StringUtils.isEmpty(getContentType()) && (getMethodType().equals("POST") || getMethodType().equals("PUT"))) { setContentType("text/html"); } super.configure(); if (!getMethodType().equals("POST")) { if (!isParamsInUrl()) { throw new ConfigurationException(getLogPrefix()+"paramsInUrl can only be set to false for methodType POST"); } if (StringUtils.isNotEmpty(getInputMessageParam())) { throw new ConfigurationException(getLogPrefix()+"inputMessageParam can only be set for methodType POST"); } } }  @Override void configure(); String getResponseBodyAsString(HttpResponseHandler responseHandler); Message getResponseBodyAsBase64(InputStream is); static Message handleMultipartResponse(HttpResponseHandler httpHandler, IPipeLineSession session); static Message handleMultipartResponse(String mimeType, InputStream inputStream, IPipeLineSession session, HttpResponseHandler httpHandler); void streamResponseBody(HttpResponseHandler responseHandler, HttpServletResponse response); static void streamResponseBody(InputStream is, String contentType,
			String contentDisposition, HttpServletResponse response,
			Logger log, String logPrefix); static void streamResponseBody(InputStream is, String contentType,
			String contentDisposition, HttpServletResponse response,
			Logger log, String logPrefix, String redirectLocation); @IbisDoc({"When false and <code>methodeType=POST</code> the type of post request, must be one of [RAW (text/xml/json), BINARY (file), URLENCODED, FORMDATA, MTOM]", "RAW"}) void setPostType(String type); @IbisDoc({"When false and <code>methodeType=POST</code>, request parameters are put in the request body instead of in the url", "true"}) void setParamsInUrl(boolean b); boolean isParamsInUrl(); @IbisDoc({"(Only used when <code>methodeType=POST</code> and <code>paramsInUrl=false</code>) Name of the request parameter which is used to put the input message in", ""}) void setInputMessageParam(String inputMessageParam); String getInputMessageParam(); @IbisDoc({"When true, besides http status code 200 (OK) also the code 301 (MOVED_PERMANENTLY), 302 (MOVED_TEMPORARILY) and 307 (TEMPORARY_REDIRECT) are considered successful", "false"}) void setIgnoreRedirects(boolean b); boolean isIgnoreRedirects(); String getStreamResultToFileNameSessionKey(); @IbisDoc({"if set, the result is streamed to a file (instead of passed as a string)", ""}) void setStreamResultToFileNameSessionKey(String string); String getStoreResultAsStreamInSessionKey(); @IbisDoc({"if set, a pointer to an input stream of the result is put in the specified sessionkey (as the sender interface only allows a sender to return a string a sessionkey is used instead to return the stream)", ""}) void setStoreResultAsStreamInSessionKey(String storeResultAsStreamInSessionKey); String getStoreResultAsByteArrayInSessionKey(); void setStoreResultAsByteArrayInSessionKey(String storeResultAsByteArrayInSessionKey); @IbisDoc({"when true, the result is base64 encoded", "false"}) void setBase64(boolean b); boolean isBase64(); @IbisDoc({"if set, the result is streamed to the httpservletresponse object of the restservicedispatcher (instead of passed as a string)", "false"}) void setStreamResultToServlet(boolean b); boolean isStreamResultToServlet(); @Deprecated @ConfigurationWarning("multipart has been replaced by postType='formdata'") @IbisDoc({"when true and <code>methodetype=post</code> and <code>paramsinurl=false</code>, request parameters are put in a multipart/form-data entity instead of in the request body", "false"}) void setMultipart(boolean b); @IbisDoc({"when true the response body is expected to be in mime multipart which is the case when a soap message with attachments is received (see also <a href=\"https://docs.oracle.com/javaee/7/api/javax/xml/soap/soapmessage.html\">https://docs.oracle.com/javaee/7/api/javax/xml/soap/soapmessage.html</a>). the first part will be returned as result of this sender. other parts are returned as streams in sessionkeys with names multipart1, multipart2, etc. the http connection is held open until the last stream is read.", "false"}) void setMultipartResponse(boolean b); boolean isMultipartResponse(); @IbisDoc({"if set and <code>methodetype=post</code> and <code>paramsinurl=false</code>, a multipart/form-data entity is created instead of a request body. for each part element in the session key a part in the multipart entity is created", ""}) void setMultipartXmlSessionKey(String multipartXmlSessionKey); String getMultipartXmlSessionKey(); @Deprecated @ConfigurationWarning("mtomEnabled has been replaced by postType='mtom'") void setMtomEnabled(boolean b); String getMtomContentTransferEncoding(); void setMtomContentTransferEncoding(String mtomContentTransferEncoding); @IbisDoc({"64", "specifies whether messages will encoded, e.g. spaces will be replaced by '+' etc.", "false"}) void setEncodeMessages(boolean b); boolean isEncodeMessages();  }
@Test public void specialCharactersDoubleEscaped() throws Throwable { HttpSender sender = getSender(); Message input = new Message("hallo"); IPipeLineSession pls = new PipeLineSessionBase(session); Parameter param1 = new Parameter(); param1.setName("url"); param1.setValue("HTTP: sender.addParameter(param1); Parameter param2 = new Parameter(); param2.setName("otherKey"); param2.setValue("otherValue"); sender.addParameter(param2); sender.setMethodType("GET"); sender.configure(); sender.open(); String result = sender.sendMessage(input, pls).asString(); assertEquals(getFile("specialCharactersDoubleEscaped.txt"), result.trim()); }
@Test(expected = SenderException.class) public void unsupportedScheme() throws Throwable { HttpSender sender = getSender(); Message input = new Message("hallo"); IPipeLineSession pls = new PipeLineSessionBase(session); Parameter param1 = new Parameter(); param1.setName("url"); param1.setValue("ftp: sender.addParameter(param1); sender.setMethodType("GET"); sender.configure(); sender.open(); sender.sendMessage(input, pls).asString(); assertTrue(false); }
@Test public void paramsWithoutValue() throws Throwable { HttpSender sender = getSender(); Message input = new Message("paramterValue"); IPipeLineSession pls = new PipeLineSessionBase(session); Parameter param1 = new Parameter(); param1.setName("url"); param1.setValue("http: sender.addParameter(param1); Parameter param2 = new Parameter(); param2.setName("myParam"); param2.setValue(""); sender.addParameter(param2); sender.setMethodType("GET"); sender.configure(); sender.open(); String result = sender.sendMessage(input, pls).asString(); assertEquals(getFile("paramsWithoutValue.txt"), result.trim()); }
@Test public void relativeUrl() throws Throwable { exception.expect(ConfigurationException.class); exception.expectMessage("must use an absolute url starting with http(s): HttpSender sender = getSender(false); sender.setMethodType("GET"); sender.setUrl("relative/path"); sender.configure(); }
@Test public void relativeUrlParameter() throws Throwable { exception.expect(SenderException.class); exception.expectMessage("must use an absolute url starting with http(s): HttpSender sender = getSender(false); sender.setMethodType("GET"); sender.setUrl(null); Parameter urlParam = new Parameter(); urlParam.setName("url"); urlParam.setValue("relative/path"); sender.addParameter(urlParam); sender.configure(); sender.open(); sender.sendMessage(null, null); }
@Test public void simpleMockedHttpGetWithoutPRC() throws Throwable { HttpSender sender = getSender(false); Message input = new Message("hallo"); sender.setMethodType("GET"); sender.configure(); sender.open(); String result = sender.sendMessage(input, null).asString(); assertEquals(getFile("simpleMockedHttpGetWithoutPRC.txt"), result.trim()); }
@Test public void testContentType() throws Throwable { HttpSender sender = getSender(false); sender.setContentType("text/xml"); sender.configure(); assertEquals("text/xml; charset=UTF-8", sender.getFullContentType().toString()); }
@Test() public void testCharset() throws Throwable { HttpSender sender = getSender(false); sender.setCharSet("ISO-8859-1"); sender.setMethodType("post"); sender.configure(); assertEquals("text/html; charset=ISO-8859-1", sender.getFullContentType().toString()); }
@Test public void testContentTypeAndCharset1() throws Throwable { HttpSender sender = getSender(false); sender.setCharSet("IsO-8859-1"); sender.setContentType("text/xml"); sender.configure(); assertEquals("text/xml; charset=ISO-8859-1", sender.getFullContentType().toString()); }
@Test public void testContentTypeAndCharset2() throws Throwable { HttpSender sender = getSender(false); sender.setContentType("application/xml"); sender.setCharSet("uTf-8"); sender.configure(); assertEquals("application/xml; charset=UTF-8", sender.getFullContentType().toString()); }
@Test public void parseContentTypeWithCharset() throws Throwable { HttpSender sender = getSender(false); sender.setContentType("text/xml; charset=ISO-8859-1"); sender.configure(); assertEquals("text/xml; charset=ISO-8859-1", sender.getFullContentType().toString()); }
@Test public void notContentTypeUnlessExplicitlySet() throws Throwable { HttpSender sender = getSender(false); sender.configure(); assertNull(sender.getFullContentType()); }
@Test() public void notCharsetUnlessContentTypeExplicitlySet() throws Throwable { HttpSender sender = getSender(false); sender.setCharSet("ISO-8859-1"); sender.configure(); assertNull(sender.getFullContentType()); }
@Test public void simpleMockedHttpGet() throws Throwable { HttpSender sender = getSender(false); Message input = new Message("hallo"); IPipeLineSession pls = new PipeLineSessionBase(session); sender.setMethodType("GET"); sender.configure(); sender.open(); String result = sender.sendMessage(input, pls).asString(); assertEquals(getFile("simpleMockedHttpGet.txt"), result.trim()); }
@Test public void simpleMockedHttpGetWithContentType() throws Throwable { HttpSender sender = getSender(false); Message input = new Message("hallo"); IPipeLineSession pls = new PipeLineSessionBase(session); sender.setMethodType("GET"); sender.setContentType("application/json"); sender.configure(); sender.open(); String result = sender.sendMessage(input, pls).asString(); assertEquals(getFile("simpleMockedHttpGetWithContentType.txt"), result.trim()); }
@Test public void simpleMockedHttpGetWithContentTypeAndCharset() throws Throwable { HttpSender sender = getSender(false); Message input = new Message("hallo"); IPipeLineSession pls = new PipeLineSessionBase(session); sender.setMethodType("GET"); sender.setContentType("application/json"); sender.setCharSet("ISO-8859-1"); sender.configure(); sender.open(); String result = sender.sendMessage(input, pls).asString(); assertEquals(getFile("simpleMockedHttpGetWithContentTypeAndCharset.txt"), result.trim()); }
@Test public void simpleMockedHttpPost() throws Throwable { HttpSender sender = getSender(false); Message input = new Message("hallo this is my message"); IPipeLineSession pls = new PipeLineSessionBase(session); sender.setMethodType("post"); sender.configure(); sender.open(); String result = sender.sendMessage(input, pls).asString(); assertEquals(getFile("simpleMockedHttpPost.txt"), result.trim()); }
@Test public void simpleMockedHttpPostAppendParamsToBody() throws Throwable { HttpSender sender = getSender(false); sender.setUrl("http: Message input = new Message("hallo"); IPipeLineSession pls = new PipeLineSessionBase(session); sender.setMethodType("post"); Parameter param1 = new Parameter(); param1.setName("key"); param1.setValue("value"); sender.addParameter(param1); Parameter param2 = new Parameter(); param2.setName("otherKey"); param2.setValue("otherValue"); sender.addParameter(param2); sender.configure(); sender.open(); String result = sender.sendMessage(input, pls).asString(); assertEquals(getFile("simpleMockedHttpPostAppendParamsToBody.txt"), result.trim()); }
@Test public void simpleMockedHttpPostAppendParamsToBodyAndEmptyBody() throws Throwable { HttpSender sender = getSender(false); sender.setUrl("http: Message input = new Message(""); IPipeLineSession pls = new PipeLineSessionBase(session); sender.setMethodType("post"); Parameter param1 = new Parameter(); param1.setName("key"); param1.setValue("value"); sender.addParameter(param1); Parameter param2 = new Parameter(); param2.setName("otherKey"); param2.setValue("otherValue"); sender.addParameter(param2); sender.configure(); sender.open(); String result = sender.sendMessage(input, pls).asString(); assertEquals(getFile("simpleMockedHttpPostAppendParamsToBodyAndEmptyBody.txt"), result.trim()); }
@Test public void simpleMockedHttpPut() throws Throwable { HttpSender sender = getSender(false); Message input = new Message("hallo"); IPipeLineSession pls = new PipeLineSessionBase(session); sender.setMethodType("pUT"); sender.configure(); sender.open(); String result = sender.sendMessage(input, pls).asString(); assertEquals(getFile("simpleMockedHttpPut.txt"), result.trim()); }
@Test public void simpleMockedHttpGetWithParams() throws Throwable { HttpSender sender = getSender(); Message input = new Message("hallo"); IPipeLineSession pls = new PipeLineSessionBase(session); Parameter param1 = new Parameter(); param1.setName("key"); param1.setValue("value"); sender.addParameter(param1); Parameter param2 = new Parameter(); param2.setName("otherKey"); param2.setValue("otherValue"); sender.addParameter(param2); sender.setMethodType("GET"); sender.configure(); sender.open(); String result = sender.sendMessage(input, pls).asString(); assertEquals(getFile("simpleMockedHttpGetWithParams.txt"), result.trim()); }
@Test public void simpleMockedHttpGetWithUrlParamAndPath() throws Throwable { HttpSender sender = getSender(); sender.setUrl(null); Message input = new Message("hallo"); IPipeLineSession pls = new PipeLineSessionBase(session); Parameter urlParam = new Parameter(); urlParam.setName("url"); urlParam.setValue("http: sender.addParameter(urlParam); Parameter param1 = new Parameter(); param1.setName("illegalCharacters"); param1.setValue("o@t&h=e+r$V,a/lue"); sender.addParameter(param1); Parameter param2 = new Parameter(); param2.setName("normalCharacters"); param2.setValue("helloWorld"); sender.addParameter(param2); sender.setMethodType("GET"); sender.configure(); sender.open(); String result = sender.sendMessage(input, pls).asString(); assertEquals(getFile("simpleMockedHttpGetWithUrlParamAndPath.txt"), result.trim()); }
@Test public void simpleMockedHttpCharset() throws Throwable { HttpSender sender = getSender(); Message input = new Message("hallo"); IPipeLineSession pls = new PipeLineSessionBase(session); sender.setCharSet("ISO-8859-1"); sender.setMethodType("POST"); sender.configure(); sender.open(); String result = sender.sendMessage(input, pls).asString(); assertEquals(getFile("simpleMockedHttpCharset.txt"), result.trim()); }
@Test public void simpleMockedHttpUnknownHeaderParam() throws Throwable { HttpSender sender = getSender(); Message input = new Message("hallo"); IPipeLineSession pls = new PipeLineSessionBase(session); Parameter param1 = new Parameter(); param1.setName("key"); param1.setValue("value"); sender.addParameter(param1); Parameter param2 = new Parameter(); param2.setName("otherKey"); param2.setValue("otherValue"); sender.addParameter(param2); sender.setMethodType("GET"); sender.setHeadersParams("custom-header, doesn-t-exist"); sender.configure(); sender.open(); String result = sender.sendMessage(input, pls).asString(); assertEquals(getFile("simpleMockedHttpGetWithParams.txt"), result.trim()); }
@Test public void simpleMockedHttpPostJSON() throws Throwable { HttpSender sender = getSender(); Message input = new Message("{\"key\": \"value\"}"); IPipeLineSession pls = new PipeLineSessionBase(session); sender.setMethodType("POST"); sender.setContentType("application/json"); sender.configure(); sender.open(); String result = sender.sendMessage(input, pls).asString(); assertEquals(getFile("simpleMockedHttpPostJSON.txt"), result); }
@Test public void simpleMockedHttpPutJSON() throws Throwable { HttpSender sender = getSender(); Message input = new Message("{\"key\": \"value\"}"); IPipeLineSession pls = new PipeLineSessionBase(session); sender.setMethodType("PUT"); sender.setContentType("application/json"); sender.configure(); sender.open(); String result = sender.sendMessage(input, pls).asString(); assertEquals(getFile("simpleMockedHttpPutJSON.txt"), result); }
@Test public void specialCharactersInURLParam() throws Throwable { HttpSender sender = getSender(); Message input = new Message("hallo"); IPipeLineSession pls = new PipeLineSessionBase(session); Parameter param1 = new Parameter(); param1.setName("url"); param1.setValue("http: sender.addParameter(param1); Parameter param2 = new Parameter(); param2.setName("otherKey"); param2.setValue("otherValue"); sender.addParameter(param2); sender.setMethodType("GET"); sender.configure(); sender.open(); String result = sender.sendMessage(input, pls).asString(); assertEquals(getFile("specialCharactersInURLParam.txt"), result.trim()); }