AnsweredAssumed Answered

Deploy a .bpmn file

Question asked by jaksur on Nov 30, 2015
Latest reply on Dec 4, 2015 by jaksur
Hi everybody,

i want to deploy a BPMN-file with the REST-API. But i always get a Bad Request (400) error…

Has anybody an idea what i'm doing wrong??? My code is below.


Thank your very much :)


import java.io.File;
import java.io.IOException;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.restlet.data.ChallengeScheme;
import org.restlet.data.Disposition;
import org.restlet.data.Form;
import org.restlet.data.MediaType;
import org.restlet.representation.FileRepresentation;
import org.restlet.representation.Representation;
import org.restlet.resource.ClientResource;



public class REST {

   private static String REST_URI = "http://localhost:8080/activiti-rest/service";
   
   private static ClientResource getClientResource(String uri) {
      ClientResource resource = new ClientResource(uri);
      resource.setChallengeResponse(ChallengeScheme.HTTP_BASIC, "kermit", "kermit");
      return resource;
   }
   
   public static JSONArray postDeployments() throws JSONException, IOException {
      String deploymentURI = REST_URI + "/repository/deployments";
      File file  = new File("C:\\Users\\Test\\Desktop\\process.bpmn");
      FileRepresentation fr = new FileRepresentation(file, MediaType.TEXT_PLAIN);
      
      System.out.println("Size sent: " + fr.getSize());
       
        try{
          Representation response = getClientResource(deploymentURI).post(file, MediaType.MULTIPART_FORM_DATA);
           JSONObject object = new JSONObject(response.getText());
         if (object != null) {
            JSONArray dataArray = (JSONArray) object.get("data");
            return dataArray;
         }
        }
        catch(Exception e){
           System.out.println("Error:");
           e.printStackTrace();
        }    
      return null;
   }
   
}

Outcomes