Deploy a .bpmn file
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-30-2015 09:51 AM
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
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; } }
Labels:
- Labels:
-
Archive
3 REPLIES 3
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-30-2015 12:06 PM
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 ?
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 ?
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-30-2015 01:47 PM
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?
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?
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-04-2015 06:38 PM
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>
<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>
