use of nl.nn.adapterframework.core.SenderException in project iaf by ibissource.
the class NetStorageSender method getMethod.
@Override
public HttpRequestBase getMethod(URIBuilder uri, String message, ParameterValueList parameters, Map<String, String> headersParamsMap, IPipeLineSession session) throws SenderException {
NetStorageAction netStorageAction = new NetStorageAction(getAction());
netStorageAction.setVersion(actionVersion);
netStorageAction.setHashAlgorithm(hashAlgorithm);
if (parameters != null)
netStorageAction.mapParameters(parameters);
try {
URL url = uri.build().toURL();
setMethodType(netStorageAction.getMethod());
log.debug("opening [" + netStorageAction.getMethod() + "] connection to [" + url + "] with action [" + getAction() + "]");
NetStorageCmsSigner signer = new NetStorageCmsSigner(url, accessTokenCf.getUsername(), accessTokenCf.getPassword(), netStorageAction, getSignType());
Map<String, String> headers = signer.computeHeaders();
boolean queryParametersAppended = false;
StringBuffer path = new StringBuffer(uri.getPath());
if (getMethodType().equals("GET")) {
if (parameters != null) {
queryParametersAppended = appendParameters(queryParametersAppended, path, parameters, headersParamsMap);
log.debug(getLogPrefix() + "path after appending of parameters [" + path.toString() + "]");
}
HttpGet method = new HttpGet(uri.build());
for (Map.Entry<String, String> entry : headers.entrySet()) {
log.debug("append header [" + entry.getKey() + "] with value [" + entry.getValue() + "]");
method.setHeader(entry.getKey(), entry.getValue());
}
log.debug(getLogPrefix() + "HttpSender constructed GET-method [" + method.getURI() + "] query [" + method.getURI().getQuery() + "] ");
return method;
} else if (getMethodType().equals("PUT")) {
HttpPut method = new HttpPut(uri.build());
for (Map.Entry<String, String> entry : headers.entrySet()) {
log.debug("append header [" + entry.getKey() + "] with value [" + entry.getValue() + "]");
method.setHeader(entry.getKey(), entry.getValue());
}
log.debug(getLogPrefix() + "HttpSender constructed GET-method [" + method.getURI() + "] query [" + method.getURI().getQuery() + "] ");
if (netStorageAction.getFile() != null) {
HttpEntity entity = new InputStreamEntity(netStorageAction.getFile());
method.setEntity(entity);
}
return method;
} else if (getMethodType().equals("POST")) {
HttpPost method = new HttpPost(uri.build());
for (Map.Entry<String, String> entry : headers.entrySet()) {
log.debug("append header [" + entry.getKey() + "] with value [" + entry.getValue() + "]");
method.setHeader(entry.getKey(), entry.getValue());
}
log.debug(getLogPrefix() + "HttpSender constructed GET-method [" + method.getURI() + "] query [" + method.getURI().getQuery() + "] ");
if (netStorageAction.getFile() != null) {
HttpEntity entity = new InputStreamEntity(netStorageAction.getFile());
method.setEntity(entity);
}
return method;
}
} catch (Exception e) {
throw new SenderException(e);
}
return null;
}
use of nl.nn.adapterframework.core.SenderException in project iaf by ibissource.
the class CmisHttpSender method invoke.
public Response invoke(String url, Map<String, String> headers, Output writer, BindingSession session, BigInteger offset, BigInteger length) throws SenderException, TimeOutException {
// Prepare the message. We will overwrite things later...
this.headers = headers;
int responseCode = -1;
IPipeLineSession pls = new PipeLineSessionBase();
pls.put("writer", writer);
pls.put("url", url);
ParameterResolutionContext prc = new ParameterResolutionContext("", pls);
try {
sendMessageWithTimeoutGuarded(null, null, prc);
return (Response) pls.get("response");
} catch (Exception e) {
throw new CmisConnectionException(getUrl(), responseCode, e);
}
}
use of nl.nn.adapterframework.core.SenderException in project iaf by ibissource.
the class CmisHttpSender method extractResult.
@Override
public String extractResult(HttpResponseHandler responseHandler, ParameterResolutionContext prc) throws SenderException, IOException {
int responseCode = -1;
try {
StatusLine statusline = responseHandler.getStatusLine();
responseCode = statusline.getStatusCode();
InputStream responseStream = null;
InputStream errorStream = null;
Map<String, List<String>> headerFields = responseHandler.getHeaderFields();
if (responseCode == 200 || responseCode == 201 || responseCode == 203 || responseCode == 206) {
responseStream = responseHandler.getResponse();
} else {
errorStream = new ByteArrayInputStream("ERROR".getBytes());
responseHandler.close();
}
Response response = new Response(responseCode, statusline.toString(), headerFields, responseStream, errorStream);
prc.getSession().put("response", response);
} catch (Exception e) {
throw new CmisConnectionException(getUrl(), responseCode, e);
}
return "response";
}
use of nl.nn.adapterframework.core.SenderException in project iaf by ibissource.
the class CmisSender method sendMessageForActionCreate.
private String sendMessageForActionCreate(String correlationID, String message, ParameterResolutionContext prc) throws SenderException, TimeOutException {
String fileName = (String) prc.getSession().get(getFileNameSessionKey());
InputStream inputStream = null;
if (StringUtils.isNotEmpty(fileInputStreamSessionKey)) {
inputStream = (FileInputStream) prc.getSession().get(getFileInputStreamSessionKey());
} else {
String fileContent = (String) prc.getSession().get(getFileContentSessionKey());
byte[] bytes = Base64.decodeBase64((String) fileContent);
inputStream = new ByteArrayInputStream(bytes);
}
long fileLength = 0;
try {
fileLength = inputStream.available();
} catch (IOException e) {
log.warn(getLogPrefix() + "could not determine file size", e);
}
String mediaType;
Map props = new HashMap();
Element cmisElement;
try {
if (XmlUtils.isWellFormed(message, "cmis")) {
cmisElement = XmlUtils.buildElement(message);
} else {
cmisElement = XmlUtils.buildElement("<cmis/>");
}
String objectTypeId = XmlUtils.getChildTagAsString(cmisElement, "objectTypeId");
if (StringUtils.isNotEmpty(objectTypeId)) {
props.put(PropertyIds.OBJECT_TYPE_ID, objectTypeId);
} else {
props.put(PropertyIds.OBJECT_TYPE_ID, "cmis:document");
}
String name = XmlUtils.getChildTagAsString(cmisElement, "name");
if (StringUtils.isEmpty(fileName)) {
fileName = XmlUtils.getChildTagAsString(cmisElement, "fileName");
}
mediaType = XmlUtils.getChildTagAsString(cmisElement, "mediaType");
if (StringUtils.isNotEmpty(name)) {
props.put(PropertyIds.NAME, name);
} else if (StringUtils.isNotEmpty(fileName)) {
props.put(PropertyIds.NAME, fileName);
} else {
props.put(PropertyIds.NAME, "[unknown]");
}
Element propertiesElement = XmlUtils.getFirstChildTag(cmisElement, "properties");
if (propertiesElement != null) {
processProperties(propertiesElement, props);
}
} catch (DomBuilderException e) {
throw new SenderException(getLogPrefix() + "exception parsing [" + message + "]", e);
}
if (StringUtils.isEmpty(mediaType)) {
mediaType = getDefaultMediaType();
}
if (isUseRootFolder()) {
Folder folder = session.getRootFolder();
ContentStream contentStream = session.getObjectFactory().createContentStream(fileName, fileLength, mediaType, inputStream);
Document document = folder.createDocument(props, contentStream, null);
log.debug(getLogPrefix() + "created new document [ " + document.getId() + "]");
return document.getId();
} else {
ContentStream contentStream = session.getObjectFactory().createContentStream(fileName, fileLength, mediaType, inputStream);
ObjectId objectId = session.createDocument(props, null, contentStream, null);
log.debug(getLogPrefix() + "created new document [ " + objectId.getId() + "]");
return objectId.getId();
}
}
use of nl.nn.adapterframework.core.SenderException in project iaf by ibissource.
the class EsbJmsTransactionalStorage method storeMessage.
public String storeMessage(String messageId, String correlationId, Date receivedDate, String comments, String label, Serializable message) throws SenderException {
Session session = null;
try {
Map parameterValues = createParameterValues(messageId, correlationId, receivedDate, comments, label, message);
String logRequest;
if (getType().equalsIgnoreCase("E")) {
log.debug(getLogPrefix() + "creating exceptionLog request");
logRequest = exceptionLogTp.transform("<dummy/>", parameterValues, true);
} else {
log.debug(getLogPrefix() + "creating auditLog request");
logRequest = auditLogTp.transform("<dummy/>", parameterValues, true);
}
session = createSession();
TextMessage msg = createTextMessage(session, null, logRequest);
String returnMessage = send(session, getDestination(), msg);
log.debug(getLogPrefix() + "sent message [" + logRequest + "] " + "to [" + getDestination() + "] " + "msgID [" + msg.getJMSMessageID() + "] " + "correlationID [" + msg.getJMSCorrelationID() + "]");
return returnMessage;
} catch (Exception e) {
throw new SenderException(e);
} finally {
closeSession(session);
}
}
Aggregations