single step package creation classissue with prod account
Thursday, September 29, 2016 at 01:02amHi Team ,
As suggested by you we are using single step package creation call where in package creation, doc upload and status sent happens at one go .For this we are using silanis provided java class.
This is wrking perfectly fine in all environments but when we moved to production , its giving connection refused exception.
We have whitelisted silanis IP's and when we try using POSTMAN it works but when we run same java class from our integration , its giving connection refused error.
Even if we try as standalone class from eclipse it gives same error.
Please help. we have to move to production resloving this issue and need your immediate help.
Java class that we are using:-
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.nio.file.Files;
import java.nio.file.Paths;
public class MultipleDocumentUpload {
public static void main(String[] args) throws MalformedURLException, IOException {
//US Account
//String requestURL = "https://sandbox.e-signlive.com/api";
//String apiKey = "V1pvdGNaTWI5endROmRZZXU1ajRQYVZJQQ==";
//Canada Account
//String requestURL = "https://sandbox.e-signlive.ca/api";
//String apiKey = "Z2hiZ1k0WkVYendFOnpEVWlHN1JRWDc0MA==";
//Production Account
String requestURL = "https://apps.e-signlive.ca/api";
String apiKey = "NDU1dGZmYmFmblFLOkJheEpiV0NqMzI4WQ==";
String charset = "UTF-8";
//File uploadFile1 = new File("D:/multipart/WMA010 Signature Pages.pdf"); //first pdf
//File uploadFile2 = new File("D:/multipart/WMA010 Signature Pages - 2015.pdf"); //second pdf
//File uploadFile3 = new File("D:/multipart/WMA100 Policy Transfer Disclosure Agreement - 2015.pdf"); //second pdf
File uploadFile1 = new File("D:/multipart/WMA010.pdf"); //first pdf
File uploadFile2 = new File("D:/multipart/LIF131-0.pdf"); //second pdf
//File uploadFile3 = new File("D:/multipart/LUR332-0.pdf"); //second pdf
//File uploadFile4 = new File("D:/multipart/LIF131-0.pdf"); //second pdf
String boundary = Long.toHexString(System.currentTimeMillis()); // Generate a random value for the form boundary
String CRLF = "\r\n"; // Line separator used in multipart/form-data.
//String jsonContent = "{ \"roles\":[ { \"locked\":false, \"emailMessage\": { \"content\":\"\" }, \"attachmentRequirements\":[], \"reassign\":false, \"specialTypes\":[], \"id\":\"Sender\", \"data\":null, \"type\":\"SIGNER\", \"index\":0, \"signers\":[ { \"auth\": { \"challenges\":[], \"scheme\":\"NONE\" }, \"company\":\"Silanis\", \"firstName\":\"YOUR_FIRST_NAME\", \"lastName\":\"YOUR_LAST_NAME\", \"phone\":\"\", \"email\":\"[email protected]\", \"knowledgeBasedAuthentication\":null, \"language\":\"en\", \"title\":\"\", \"external\":null, \"professionalIdentityFields\":[], \"userCustomFields\":[], \"delivery\": { \"email\":true, \"provider\":false, \"download\":true }, \"group\":null, \"signature\":null, \"address\":null, \"data\":null, \"name\":\"\", \"specialTypes\":[] }], \"name\":\"Sender\" }, { \"locked\":false, \"emailMessage\": { \"content\":\"\" }, \"attachmentRequirements\":[], \"reassign\":false, \"specialTypes\":[], \"id\":\"Signer\", \"data\":null, \"type\":\"SIGNER\", \"index\":0, \"signers\":[ { \"auth\": { \"challenges\":[], \"scheme\":\"NONE\" }, \"company\":\"\", \"firstName\":\"SIGNER_FIRST_NAME\", \"lastName\":\"SIGNER_LAST_NAME\", \"phone\":\"\", \"email\":\"[email protected]\", \"knowledgeBasedAuthentication\":null, \"language\":\"en\", \"title\":\"\", \"external\":null, \"professionalIdentityFields\":[], \"userCustomFields\":[], \"delivery\": { \"email\":false, \"provider\":false, \"download\":false }, \"group\":null, \"id\":\"Signer\", \"signature\":null, \"address\":null, \"data\":null, \"name\":\"\", \"specialTypes\":[] }], \"name\":\"Signer\" }], \"documents\":[ { \"approvals\":[ { \"role\":\"Signer\", \"signed\":null, \"accepted\":null, \"data\":null, \"fields\":[ { \"page\":0, \"subtype\":\"FULLNAME\", \"width\":200, \"binding\":null, \"extract\":false, \"extractAnchor\":null, \"left\":175, \"top\":165, \"validation\":null, \"height\":50, \"data\":null, \"type\":\"SIGNATURE\", \"value\":\"\" }], \"name\":\"\" }, { \"role\":\"Sender\", \"signed\":null, \"accepted\":null, \"data\":null, \"fields\":[ { \"page\":0, \"subtype\":\"FULLNAME\", \"width\":200, \"binding\":null, \"extract\":false, \"extractAnchor\":null, \"left\":550, \"top\":165, \"validation\":null, \"height\":50, \"data\":null, \"type\":\"SIGNATURE\", \"value\":\"\" }], \"name\":\"\" }], \"name\": \"sampleAgreement\" }, { \"approvals\":[ { \"role\":\"Signer\", \"signed\":null, \"accepted\":null, \"data\":null, \"fields\":[ { \"page\":0, \"subtype\":\"FULLNAME\", \"width\":200, \"binding\":null, \"extract\":false, \"extractAnchor\":null, \"left\":175, \"top\":165, \"validation\":null, \"height\":50, \"data\":null, \"type\":\"SIGNATURE\", \"value\":\"\" }], \"name\":\"\" }, { \"role\":\"Sender\", \"signed\":null, \"accepted\":null, \"data\":null, \"fields\":[ { \"page\":0, \"subtype\":\"FULLNAME\", \"width\":200, \"binding\":null, \"extract\":false, \"extractAnchor\":null, \"left\":550, \"top\":165, \"validation\":null, \"height\":50, \"data\":null, \"type\":\"SIGNATURE\", \"value\":\"\" }], \"name\":\"\" }], \"name\": \"myDocument\" }], \"name\": \"Test Package REST\", \"type\":\"PACKAGE\", \"language\":\"en\", \"emailMessage\":\"\", \"description\":\"New Package\", \"autoComplete\":true, \"status\":\"SENT\" }";
byte[] encoded = Files.readAllBytes(Paths.get("D:/multipart/silanis.json"));
String jsonContent = new String(encoded, charset);
URLConnection connection = new URL(requestURL + "/packages/").openConnection();
connection.setDoOutput(true);
connection.setRequestProperty("Content-Type", "multipart/form-data; boundary=" + boundary);
connection.setRequestProperty("Authorization", "Basic " + apiKey);
connection.setRequestProperty("Accept", "application/json");
OutputStream output = connection.getOutputStream();
PrintWriter writer = new PrintWriter(new OutputStreamWriter(output, charset), true);
try {
// Add first pdf file.
writer.append("--" + boundary).append(CRLF);
writer.append("Content-Disposition: form-data; name=\"file\"; filename=\"" + uploadFile1.getName() + "\"").append(CRLF);
writer.append("Content-Type: " + URLConnection.guessContentTypeFromName(uploadFile1.getName())).append(CRLF);
writer.append("Content-Transfer-Encoding: application/pdf").append(CRLF);
writer.append(CRLF).flush();
Files.copy(uploadFile1.toPath(), output);
output.flush();
writer.append(CRLF).flush();
// Add second file.
writer.append("--" + boundary).append(CRLF);
writer.append("Content-Disposition: form-data; name=\"file\"; filename=\"" + uploadFile2.getName() + "\"").append(CRLF);
writer.append("Content-Type: " + URLConnection.guessContentTypeFromName(uploadFile2.getName())).append(CRLF);
writer.append("Content-Transfer-Encoding: application/pdf").append(CRLF);
writer.append(CRLF).flush();
Files.copy(uploadFile2.toPath(), output);
output.flush();
writer.append(CRLF).flush();
// Add third file.
/*writer.append("--" + boundary).append(CRLF);
writer.append("Content-Disposition: form-data; name=\"file\"; filename=\"" + uploadFile3.getName() + "\"").append(CRLF);
writer.append("Content-Type: " + URLConnection.guessContentTypeFromName(uploadFile3.getName())).append(CRLF);
writer.append("Content-Transfer-Encoding: application/pdf").append(CRLF);
writer.append(CRLF).flush();
Files.copy(uploadFile3.toPath(), output);
output.flush();
writer.append(CRLF).flush();*/
// Add third file.
/*writer.append("--" + boundary).append(CRLF);
writer.append("Content-Disposition: form-data; name=\"file\"; filename=\"" + uploadFile4.getName() + "\"").append(CRLF);
writer.append("Content-Type: " + URLConnection.guessContentTypeFromName(uploadFile4.getName())).append(CRLF);
writer.append("Content-Transfer-Encoding: application/pdf").append(CRLF);
writer.append(CRLF).flush();
Files.copy(uploadFile4.toPath(), output);
output.flush();
writer.append(CRLF).flush();*/
// add json payload
writer.append("--" + boundary).append(CRLF);
writer.append("Content-Disposition: form-data; name=\"payload\"").append(CRLF);
writer.append("Content-Type: application/json; charset=" + charset).append(CRLF);
writer.append(CRLF).append(jsonContent).append(CRLF).flush();
// End of multipart/form-data.
writer.append("--" + boundary + "--").append(CRLF).flush();
}
catch (IOException ex) {
System.err.println(ex);
}
//get and write out response code
int responseCode = ((HttpURLConnection) connection).getResponseCode();
System.out.println(responseCode);
//get and write out response
BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
String inputLine;
StringBuffer response = new StringBuffer();
while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
}
in.close();
//print result
System.out.println(response.toString());
}
}
Regards
Madhavi
Reply to: single step package creation classissue with prod account
Friday, September 30, 2016 at 05:21am