-3

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

Has anybody an idea what i'm doing wrong??? I use restlet to upload my code. 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;
}

}

Jaksur
  • 1
  • 1

1 Answers1

0

You are not generating the multipart-form-data request properly with Restlet.

You could have done the following to deploy a business process to activiti REST API:

String deploymentURI = REST_URI + "/repository/deployments";

File file = new File("/home/toto/fake-process.bpmn20.xml");

FileRepresentation entity = new FileRepresentation(file, MediaType.MULTIPART_FORM_DATA);

FormDataSet fds = new FormDataSet();
FormData fd = new FormData("upload_file", entity);    
fds.getEntries().add(fd);
fds.setMultipart(true);

try {
    Representation response = getClientResource(deploymentURI).post(fds);
} catch (Exception e) {
    System.out.println("Error:");
    e.printStackTrace();
}

See also this post

Community
  • 1
  • 1
Rémi Bantos
  • 1,899
  • 14
  • 27