Close popover
Chandrasekhar Allampati (allac)
Principal Solutions Engineer
Pegasystems Inc.
allac Member since 2017 9 posts
Posted: January 24, 2018
Last activity: January 25, 2018

Need help in implementing Connect-REST (Post Method for sending Document)

We have requirement to implement Connect-Rest to post documents over the web service for 3rd party application, and 3rd party Rest service implemented in such away that we have to send 3 parameters in request body itself as a multipart.

we have implemented solution using java code and its working fine as expected when we run through eclipse, but we are facing issues when we try to implement same java code in activity java step. we are expecting assistance on implementing this with either Connect-REST or using JAVA step in actvity.


Instructions on have already been used. But there are 2 additional parameters called SessionTicket and folderUid which have to be sent as Strings. But in InvokeHTTPConnector, everything is getting converted into Bytes and hence the webservice is failing.

Java Code which implemented in eclipse:


import org.apache.http.HttpEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.mime.MultipartEntityBuilder;
import org.apache.http.entity.mime.content.FileBody;
import org.apache.http.entity.mime.content.StringBody;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
public class CallProj {
public CallProj() {
// TODO Auto-generated constructor stub
public static void main(String[] args) {
// TODO Auto-generated method stub
public static void uploadDocumentToProjector(String fileName) {
// the file we want to upload
CloseableHttpClient httpclient = HttpClients.createDefault();
try {
// server back-end URL
HttpPost httppost = new HttpPost("");
FileBody bin = new FileBody(new File(fileName));
HttpEntity entity = (HttpEntity) MultipartEntityBuilder.create()
.addPart("SessionTicket", new StringBody("xxxxxxxxxxxx", ContentType.TEXT_PLAIN))
.addPart("folderUid", new StringBody("xxxxxxx", ContentType.TEXT_PLAIN))
.addPart("file", bin).build();
// execute the request
CloseableHttpResponse response = httpclient.execute(httppost);
int statusCode = response.getStatusLine().getStatusCode();
HttpEntity responseEntity = response.getEntity();
String responseString = EntityUtils.toString(responseEntity, "UTF-8");
System.out.println("[" + statusCode + "] " + responseString);
} catch (Exception e) {


java code which we tried in java step in Activity:


String fileName= "XXXXXXXXXXX";
String SessionTicket= "ApTmcqHc4YkYDhq2YdQYyw==";
String folderUid = "xxxxxxxxxxxxx";
com.pega.apache.http.impl.client.DefaultHttpClient client = null;
com.pega.apache.http.HttpResponse httpResponse = null;
try {
if (client == null)
client = new com.pega.apache.http.impl.client.DefaultHttpClient();
// server back-end URL
com.pega.apache.http.client.methods.HttpPost httppost = new com.pega.apache.http.client.methods.HttpPost("");
//Create file body
com.pega.apache.http.entity.mime.content.FileBody bin = new com.pega.apache.http.entity.mime.content.FileBody(new;
com.pega.apache.http.HttpEntity entity = new com.pega.apache.http.entity.mime.MultipartEntity();
((com.pega.apache.http.entity.mime.MultipartEntity) entity).addPart("SessionTicket", new com.pega.apache.http.entity.mime.content.StringBody(SessionTicket));
((com.pega.apache.http.entity.mime.MultipartEntity) entity).addPart("folderUid", new com.pega.apache.http.entity.mime.content.StringBody(folderUid));
((com.pega.apache.http.entity.mime.MultipartEntity) entity).addPart("file", bin);
httpResponse = client.execute(httppost, (com.pega.apache.http.protocol.BasicHttpContext)localContext); // This step not excuting,and moving to catch block
} catch (Exception e) {
System.err.println("Exception couured");
Please suggest your thoughts to implement our requirement.
Thank you.
Data Integration
Moderation Team has archived post,
Close popover This thread is closed to future replies. Content and links will no longer be updated. If you have the same/similar Question, please write a new Question.