use of nl.nn.adapterframework.core.SenderException in project iaf by ibissource.
the class HttpSender method handleMultipartResponse.
public static String handleMultipartResponse(String contentType, InputStream inputStream, ParameterResolutionContext prc, HttpResponseHandler httpHandler) throws IOException, SenderException {
String result = null;
try {
InputStreamDataSource dataSource = new InputStreamDataSource(httpHandler.getContentType(), inputStream);
MimeMultipart mimeMultipart = new MimeMultipart(dataSource);
for (int i = 0; i < mimeMultipart.getCount(); i++) {
BodyPart bodyPart = mimeMultipart.getBodyPart(i);
boolean lastPart = mimeMultipart.getCount() == i + 1;
if (i == 0) {
String charset = ContentType.parse(bodyPart.getContentType()).getCharset().name();
InputStream bodyPartInputStream = bodyPart.getInputStream();
result = Misc.streamToString(bodyPartInputStream, charset);
if (lastPart) {
bodyPartInputStream.close();
}
} else {
// When the last stream is read the
// httpMethod.releaseConnection() can be called, hence pass
// httpMethod to ReleaseConnectionAfterReadInputStream.
prc.getSession().put("multipart" + i, new ReleaseConnectionAfterReadInputStream(lastPart ? httpHandler : null, bodyPart.getInputStream()));
}
}
} catch (MessagingException e) {
throw new SenderException("Could not read mime multipart response", e);
}
return result;
}
use of nl.nn.adapterframework.core.SenderException in project iaf by ibissource.
the class HttpSender method getPostMethodWithParamsInBody.
protected HttpPost getPostMethodWithParamsInBody(URIBuilder uri, String message, ParameterValueList parameters, Map<String, String> headersParamsMap, IPipeLineSession session) throws SenderException {
try {
HttpPost hmethod = new HttpPost(uri.build());
if (!isMultipart() && StringUtils.isEmpty(getMultipartXmlSessionKey())) {
List<NameValuePair> Parameters = new ArrayList<NameValuePair>();
if (StringUtils.isNotEmpty(getInputMessageParam())) {
Parameters.add(new BasicNameValuePair(getInputMessageParam(), message));
log.debug(getLogPrefix() + "appended parameter [" + getInputMessageParam() + "] with value [" + message + "]");
}
if (parameters != null) {
for (int i = 0; i < parameters.size(); i++) {
ParameterValue pv = parameters.getParameterValue(i);
String name = pv.getDefinition().getName();
String value = pv.asStringValue("");
if (headersParamsMap.keySet().contains(name)) {
hmethod.addHeader(name, value);
if (log.isDebugEnabled())
log.debug(getLogPrefix() + "appended header [" + name + "] with value [" + value + "]");
} else {
Parameters.add(new BasicNameValuePair(name, value));
if (log.isDebugEnabled())
log.debug(getLogPrefix() + "appended parameter [" + name + "] with value [" + value + "]");
}
}
}
try {
hmethod.setEntity(new UrlEncodedFormEntity(Parameters));
} catch (UnsupportedEncodingException e) {
throw new SenderException(getLogPrefix() + "unsupported encoding for one or more post parameters");
}
} else {
HttpEntity requestEntity = createMultiPartEntity(message, parameters, session);
hmethod.setEntity(requestEntity);
}
return hmethod;
} catch (URISyntaxException e) {
throw new SenderException(getLogPrefix() + "cannot find path from url [" + getUrl() + "]", e);
}
}
use of nl.nn.adapterframework.core.SenderException in project iaf by ibissource.
the class WebServiceNtlmSender method sendMessage.
public String sendMessage(String correlationID, String message, ParameterResolutionContext prc) throws SenderException, TimeOutException {
String result = null;
HttpPost httpPost = new HttpPost(getUrl());
try {
StringEntity se = new StringEntity(message);
httpPost.setEntity(se);
if (StringUtils.isNotEmpty(getContentType())) {
log.debug(getLogPrefix() + "setting Content-Type header [" + getContentType() + "]");
httpPost.addHeader("Content-Type", getContentType());
}
if (StringUtils.isNotEmpty(getSoapAction())) {
log.debug(getLogPrefix() + "setting SOAPAction header [" + getSoapAction() + "]");
httpPost.addHeader("SOAPAction", getSoapAction());
}
log.debug(getLogPrefix() + "executing method");
HttpResponse httpresponse = httpClient.execute(httpPost);
log.debug(getLogPrefix() + "executed method");
StatusLine statusLine = httpresponse.getStatusLine();
if (statusLine == null) {
throw new SenderException(getLogPrefix() + "no statusline found");
} else {
int statusCode = statusLine.getStatusCode();
String statusMessage = statusLine.getReasonPhrase();
if (statusCode == HttpServletResponse.SC_OK) {
log.debug(getLogPrefix() + "status code [" + statusCode + "] message [" + statusMessage + "]");
} else {
throw new SenderException(getLogPrefix() + "status code [" + statusCode + "] message [" + statusMessage + "]");
}
}
HttpEntity httpEntity = httpresponse.getEntity();
if (httpEntity == null) {
log.warn(getLogPrefix() + "no response found");
} else {
log.debug(getLogPrefix() + "response content length [" + httpEntity.getContentLength() + "]");
result = EntityUtils.toString(httpEntity);
log.debug(getLogPrefix() + "retrieved result [" + result + "]");
}
} catch (Exception e) {
if (e instanceof SocketTimeoutException) {
throw new TimeOutException(e);
}
if (e instanceof ConnectTimeoutException) {
throw new TimeOutException(e);
}
throw new SenderException(e);
} finally {
httpPost.releaseConnection();
}
return result;
}
use of nl.nn.adapterframework.core.SenderException in project iaf by ibissource.
the class BisJmsSender method sendMessage.
public String sendMessage(String correlationID, String message, ParameterResolutionContext prc) throws SenderException, TimeOutException {
String messageHeader;
try {
messageHeader = bisUtils.prepareMessageHeader(null, isMessageHeaderInSoapBody(), (String) prc.getSession().get(getConversationIdSessionKey()), (String) prc.getSession().get(getExternalRefToMessageIdSessionKey()));
} catch (Exception e) {
throw new SenderException(e);
}
String payload;
try {
payload = bisUtils.prepareReply(message, isMessageHeaderInSoapBody() ? messageHeader : null, null, false);
if (StringUtils.isNotEmpty(getRequestNamespace())) {
payload = XmlUtils.addRootNamespace(payload, getRequestNamespace());
}
} catch (Exception e) {
throw new SenderException(e);
}
String replyMessage = super.sendMessage(correlationID, payload, prc, isMessageHeaderInSoapBody() ? null : messageHeader);
if (isSynchronous()) {
String bisError;
String bisErrorList;
try {
bisError = bisErrorTp.transform(replyMessage, null, true);
bisErrorList = bisErrorListTp.transform(replyMessage, null, true);
} catch (Exception e) {
throw new SenderException(e);
}
if (Boolean.valueOf(bisError).booleanValue()) {
log.debug("put in session [" + getErrorListSessionKey() + "] [" + bisErrorList + "]");
prc.getSession().put(getErrorListSessionKey(), bisErrorList);
throw new SenderException("bisErrorXPath [" + (isResultInPayload() ? bisUtils.getBisErrorXPath() : bisUtils.getOldBisErrorXPath()) + "] returns true");
}
try {
replyMessage = responseTp.transform(replyMessage, null, true);
if (isRemoveResponseNamespaces()) {
replyMessage = XmlUtils.removeNamespaces(replyMessage);
}
if (isResultInPayload()) {
Element soapBodyElement = XmlUtils.buildElement(replyMessage, true);
Element resultElement = XmlUtils.getFirstChildTag(soapBodyElement, "Result");
if (resultElement != null) {
soapBodyElement.removeChild(resultElement);
}
replyMessage = XmlUtils.nodeToString(soapBodyElement);
}
return replyMessage;
} catch (Exception e) {
throw new SenderException(e);
}
} else {
return replyMessage;
}
}
use of nl.nn.adapterframework.core.SenderException in project iaf by ibissource.
the class HttpSenderBase method open.
public void open() throws SenderException {
connectionManager = new PoolingHttpClientConnectionManager();
connectionManager.setMaxTotal(getMaxConnections());
log.debug(getLogPrefix() + "set up connectionManager, inactivity checking [" + connectionManager.getValidateAfterInactivity() + "]");
boolean staleChecking = (connectionManager.getValidateAfterInactivity() >= 0);
if (staleChecking != isStaleChecking()) {
log.info(getLogPrefix() + "set up connectionManager, setting stale checking [" + isStaleChecking() + "]");
connectionManager.setValidateAfterInactivity(getStaleTimeout());
}
httpClientBuilder.useSystemProperties();
httpClientBuilder.disableAuthCaching();
httpClientBuilder.setConnectionManager(connectionManager);
if (transformerPool != null) {
try {
transformerPool.open();
} catch (Exception e) {
throw new SenderException(getLogPrefix() + "cannot start TransformerPool", e);
}
}
}
Aggregations