cancel
Showing results for 
Search instead for 
Did you mean: 

Deploying with REST

rdiaz1
Champ in-the-making
Champ in-the-making
Hi there,

I´m trying to deploy a bpmn20.xml in Activiti with the REST Api.
I can see in the user guide the explication for this..

Request: POST /deployments

success={success}&failure={success}&deployment={file}

But when I access with the browser to all Web Scripts, this service is not found.
I´ve seen checking the source code the resource "deployment.post.desc.xml" but with a change in the path (/deployment) and the DeploymentPost web script is there also..

FormData.FormField file = ((WebScriptServletRequest) req.getWebScriptRequest()).getFileField("deployment");     

How i have to put the param "file"? what is "file"? I´m using Jax-rs client api and I tried with Attachment and MultipartBody but doesn´t work
I don´t know if I´m wrong in something or this service is not possible currently.

Thanks
3 REPLIES 3

frederikherema1
Star Contributor
Star Contributor
The parameter 'file' should be the filename of the file you want to upload, not the actual file itself.
The property "deployment" is the actual content, which is a multipart massage.

About the URL, that should indeed be '/deployment POST' instead of deployments.

Thanks for pointing that out!

rdiaz1
Champ in-the-making
Champ in-the-making
Hi again,

Can you give me an example with a simple http client, please?It´s impossible to me make it work…

If the url is only "/deployment", how can I set the argument "file"?and the property "deployment"?

I´m sorry but I didn´t understand your reply really..

Tanks a lot

saurabhmittal
Champ in-the-making
Champ in-the-making
i have written  the client for uploading in activiti 5.6 rest service  , but its not working
What should be set for attribute deployment ?


import java.io.File;
import java.io.FileInputStream;
import java.nio.charset.Charset;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.HttpVersion;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.FileEntity;
import org.apache.http.entity.StringEntity;
import org.apache.http.entity.mime.MultipartEntity;
import org.apache.http.entity.mime.content.InputStreamBody;
import org.apache.http.entity.mime.content.StringBody;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.params.CoreProtocolPNames;
import org.apache.http.util.EntityUtils;

import sun.misc.BASE64Encoder;


public class PostFile {
  public static void main(String[] args) throws Exception {
   final String userName = "kermit";
   final String password = "kermit";
   
    HttpClient httpclient = new DefaultHttpClient();
    httpclient.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
    HttpPost httppost = new HttpPost("http://localhost:8080/activiti-rest/service/deployment");
    File file = new File("SubProcessTest.fixSystemFailureProcess.bpmn20.xml");
    FileEntity reqEntity = new FileEntity(file, "text/xml; UTF-8");
    httppost.setEntity(reqEntity);
    String data ="success=1&failure=0&deployment=SubProcessTest.fixSystemFailureProcess.bpmn20.xml";
    httppost.setEntity(new StringEntity(data, "UTF-8"));
    //reqEntity.setContentType("multipart/form-data");
    System.out.println("executing request&&&&&&&&&&& " + httppost.getRequestLine());
    // write auth header
    BASE64Encoder encoder = new BASE64Encoder();
    String encodedCredential = encoder.encode( (userName + ":" + password).getBytes() );
    httppost.setHeader("Authorization", "BASIC " + encodedCredential);
    //.setRequestProperty("Authorization", "BASIC " + encodedCredential);
    httppost.setHeader("Content-Type", "multipart/form-data");
   
    HttpResponse response = httpclient.execute(httppost);
    HttpEntity resEntity = response.getEntity();

    System.out.println(response.getStatusLine());
    if (resEntity != null) {
      System.out.println(EntityUtils.toString(resEntity));
    }
    if (resEntity != null) {
      resEntity.consumeContent();
    }

    httpclient.getConnectionManager().shutdown();
  }
}