cancel
Showing results for 
Search instead for 
Did you mean: 

Deploy a .bpmn file

jaksur
Champ in-the-making
Champ in-the-making
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 Smiley Happy


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;
   }
   
}
3 REPLIES 3

vasile_dirla
Star Contributor
Star Contributor
the docs says:
400: "Indicates there was no content present in the request body or the content mime-type is not supported for deployment. The status-description contains additional information."
have a look into this test:
<code>org.activiti.rest.service.api.repository.DeploymentResourceTest</code>

what if you will post the fileRepresentation and change the MediaType to application/xml ?

jaksur
Champ in-the-making
Champ in-the-making
Hi,

when i change the MediaType i get a
406:"Not Acceptable (406) - The resource identified by the request is only capable of generating response entities which have content characteristics not acceptable according to the accept headers sent in the request"

any idea?

jaksur
Champ in-the-making
Champ in-the-making
I solved my problem. Here is the code:

<code>
public void createDeployment() throws Exception {
  String deploymentURI = REST_URI + "/repository/deployments";

 
            CloseableHttpClient client = HttpClients.createDefault();
     HttpPost httpPost = new HttpPost(deploymentURI);      
     httpPost.addHeader("Authorization", "Basic a2VybWl0Omtlcm1pdA==");
    
     File file  = new File("C:\\process.bpmn");

     MultipartEntityBuilder builder = MultipartEntityBuilder.create();
     builder.addBinaryBody("file", file, ContentType.APPLICATION_OCTET_STREAM, file.getName());
    
     HttpEntity multipart = builder.build();
     httpPost.setEntity(multipart);
 
     CloseableHttpResponse response = client.execute(httpPost);
     client.close();
   }
</code>