if (credentials != null) {
LoginResult loginResult = login(credentials);
if (loginResult.isOk()) {
sessionToken = loginResult.getHttpResult().getSessionToken();
} else {
SignatureResult result = new SignatureResult();
result.setHttpResult(loginResult.getHttpResult());
result.setBasicResponse(loginResult.getBasicResponse());
return result;
}
}
Map<String, String> params = new HashMap<String, String>();
params.put("recipientEmail", recipientEmail);
params.put("resourceName", documentTitle);
params.put("message", message);
if (internalFolderReference != null
&& !"".equals(internalFolderReference)) {
params.put("internalFolderReference", internalFolderReference);
}
if (fileName != null && !"".equals(fileName)) {
params.put("fileName", fileName);
}
params.put("mailAttachement", Boolean.toString(isMailAttachement));
params.put("storeStrategy", storeStrategy.name());
String resSign = null;
HttpResult httpResult;
if (code != null) {
params.put("code", code);
httpResult = httpHelper.doPostMultipart("/basic/signPlus",
httpConfiguration, sessionToken, file, "file", params);
resSign = ResponseUtil.getBasicResponse(httpResult);
} else {
httpResult = httpHelper.doPostMultipart("/basic/sign",
httpConfiguration, sessionToken, file, "file", params);
resSign = ResponseUtil.getBasicResponse(httpResult);
}
SignatureResult result = new SignatureResult();
result.setHttpResult(httpResult);
result.setBasicResponse(resSign);
String resSignSplit[] = resSign.split("\\s");
if (resSignSplit[1].equals("OK")) {
result.setOk(true);
result.setSignatureId(resSignSplit[3]);
}
if (!keepAlive) {
logout(httpResult.getSessionToken());
}