AnsweredAssumed Answered

error while programmatically deploying with rest api

Question asked by halilagin on Jul 12, 2012
Latest reply on Jul 12, 2012 by trademak
Hi List,

I am trying to programmatically deploy a bar file to activiti-explorer by the help of rest api provided. I search the net and forum but couldnot find any example.
In the below segment, there are three part:

1. http post sent by restlet api
2. http responce received by the client api
3. the code I wrote wh,ch does not work.


In the code, deploy method is working, but deployInrestlet method does not work. To watch the data sent from the client I used tcpmon program. The main sympthom is that "HTTP/1.1 405 Method Not Allowed". I tested ACTIVITI_REST_URI + "/process-definitions?size=100" address programmatically and  I saw that it works correctly. What could be the problem?

best,

-halil agin.

—————————— http post sent —————————–

POST /activiti-rest/service/deploy HTTP/1.1
Date: Thu, 12 Jul 2012 08:21:37 GMT
Accept: */*
Host: localhost:8111
User-Agent: Restlet-Framework/2.0.0
Authorization: Basic a2VybWl0Omtlcm1pdA==
Content-Length: 78168
Content-Type: multipart/form-data
Last-Modified: Thu, 28 Jun 2012 14:23:05 GMT
Content-Disposition: inline; filename=activiti-engine-examples.bar

<zipped-file-content>

—————————— http post sent —————————–

—————————— http response received —————————–
HTTP/1.1 405 Method Not Allowed
Date: Thu, 12 Jul 2012 08:21:37 GMT
Accept-Ranges: bytes
Allow: GET
Server: Restlet-Framework/2.0.8
Content-Type: text/html;charset=UTF-8
Content-Length: 487

<html>
<head>
   <title>Status page</title>
</head>
<body style="font-family: sans-serif;">
<p style="font-size: 1.2em;font-weight: bold;margin: 1em 0px;">Method Not Allowed</p>
<p>The method specified in the request is not allowed for the resource identified by the request URI</p>
<p>You can get technical details <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4.6">here</a>.<br>
Please continue your visit at our <a href="/">home page</a>.
</p>
</body>
</html>

—————————— http response received —————————–



—————————————– code ——————————————————-
private static String ACTIVITI_REST_URI = "http://localhost:8111/activiti-rest/service";
   private static String barFileName = "/home/halil/projects/workspace_btg/activiti-engine-examples/target/activiti-engine-examples.bar";

   public void deploy() {
      try {
         ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext(
               "/activiti.deployment.manager.cfg.xml");

         RepositoryService repositoryService = (RepositoryService) applicationContext
               .getBean("repositoryService");

         String barFileName = "/home/halil/projects/workspace_btg/activiti-engine-examples/target/activiti-engine-examples.bar";
         ZipInputStream inputStream = new ZipInputStream(
               new FileInputStream(barFileName));
         /*
          * repositoryService.createDeployment()
          * .name("activiti-engine-examples.bar")
          * .addZipInputStream(inputStream) .deploy();
          */

         final Deployment deployment = repositoryService
               .createDeploymentQuery().deploymentName("depnum2")
               .singleResult();
         if (deployment == null) {
            final DeploymentBuilder deploymentBuilder = repositoryService
                  .createDeployment().enableDuplicateFiltering()
                  .name("depnum2");
            deploymentBuilder.addZipInputStream(inputStream);
            deploymentBuilder.deploy();

         }
         System.exit(0);
      } catch (Exception ex) {
         ex.printStackTrace();
         System.exit(-1);
      }

   }

   public void deployInRestlet() {
      try {

         ClientResource clientResource = new ClientResource(
               ACTIVITI_REST_URI + "/deploy");
         clientResource.setChallengeResponse(ChallengeScheme.HTTP_BASIC,
               "kermit", "kermit");
         FileResource fileResources = clientResource
               .wrap(FileResource.class);
         Representation rep = new FileRepresentation(new File(barFileName),
               MediaType.MULTIPART_FORM_DATA);
         // Prepare the disposition header with the file name.
         File myzipfile = new File(barFileName);
         Form form = new Form();
         form.add(Disposition.NAME_FILENAME, myzipfile.getName());
         rep.setDisposition(new Disposition(Disposition.TYPE_INLINE, form));
         fileResources.upload(rep);

         clientResource.get().write(System.out);
         System.exit(0);
      } catch (Exception ex) {
         ex.printStackTrace();
         System.exit(-1);
      }

   }

—————————————– code ——————————————————-

Outcomes