cancel
Showing results for 
Search instead for 
Did you mean: 

Unable to attach a file using REST

dan1
Champ in-the-making
Champ in-the-making
Hi,

I have 5.11 installed. I'm only using the activiti-rest application. I'm using curl to deploy processes and start instances. However, I'm unable to attach a file to a user task. Here is the process definition:


<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:activiti="http://activiti.org/bpmn" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" typeLanguage="http://www.w3.org/2001/XMLSchema" expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://www.cisco.com/hcs">
  <process id="AttachFileProcess" name="Attach File Process">
    <startEvent id="startevent1" name="Start" activiti:initiator="initiator"></startEvent>
    <endEvent id="endevent3" name="End"></endEvent>
    <serviceTask id="servicetask1" name="Process File" activiti:class="com.example.ProcessFile"></serviceTask>
    <sequenceFlow id="flow1" name="" sourceRef="startevent1" targetRef="usertask1"></sequenceFlow>
    <sequenceFlow id="flow14" name="" sourceRef="servicetask1" targetRef="endevent3"></sequenceFlow>
    <userTask id="usertask1" name="Attach File" activiti:assignee="${initiator}"></userTask>
    <sequenceFlow id="flow15" name="" sourceRef="usertask1" targetRef="servicetask1"></sequenceFlow>
  </process>
  <bpmndi:BPMNDiagram id="BPMNDiagram_AttachFileProcess">
    <bpmndi:BPMNPlane bpmnElement="AttachFileProcess" id="BPMNPlane_AttachFileProcess">
      <bpmndi:BPMNShape bpmnElement="startevent1" id="BPMNShape_startevent1">
        <omgdc:Bounds height="35" width="35" x="50" y="84"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="endevent3" id="BPMNShape_endevent3">
        <omgdc:Bounds height="35" width="35" x="400" y="84"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="servicetask1" id="BPMNShape_servicetask1">
        <omgdc:Bounds height="55" width="105" x="260" y="74"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="usertask1" id="BPMNShape_usertask1">
        <omgdc:Bounds height="55" width="105" x="119" y="74"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNEdge bpmnElement="flow1" id="BPMNEdge_flow1">
        <omgdi:waypoint x="85" y="101"></omgdi:waypoint>
        <omgdi:waypoint x="119" y="101"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="flow14" id="BPMNEdge_flow14">
        <omgdi:waypoint x="365" y="101"></omgdi:waypoint>
        <omgdi:waypoint x="400" y="101"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="flow15" id="BPMNEdge_flow15">
        <omgdi:waypoint x="224" y="101"></omgdi:waypoint>
        <omgdi:waypoint x="260" y="101"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
    </bpmndi:BPMNPlane>
  </bpmndi:BPMNDiagram>
</definitions>

Here are the process details. Note that the user task id is 809.


>  curl -u"admin:admin" http://localhost/activiti-rest/service/process-instance/805

{"processInstanceId":"805","businessKey":"attach-1","processDefinitionId":"AttachFileProcess:1:804","startTime":"2013-02-18T05:59:06EST","startActivityId":"startevent1","startUserId":"admin","completed":false,"tasks":[{"taskId":"809","taskDefinitionKey":"usertask1","taskName":"Attach File","owner":null,"assignee":"admin","startTime":"2013-02-18T05:59:06EST","completed":false}],"activities":[{"activityId":"startevent1","activityName":"Start","activityType":"startEvent","startTime":"2013-02-18T05:59:06EST","completed":true,"endTime":"2013-02-18T05:59:06EST","duration":15},{"activityId":"usertask1","activityName":"Attach File","activityType":"userTask","startTime":"2013-02-18T05:59:06EST","completed":false}],"variables":[{"variableName":"initiator","variableValue":"admin"}]}

Here is the output from attempting to upload a file:


> curl -v -u"admin:admin" –upload-file /activiti/attachments/junk.txt -H "Content-Type: text/plain; charset=UTF-8" http://localhost/activiti-rest/service/task/809/attachment

* About to connect() to localhost port 80
*   Trying 127.0.0.1… connected
* Connected to localhost (127.0.0.1) port 80
* Server auth using Basic with user 'admin'
> PUT /activiti-rest/service/task/809/attachment HTTP/1.1
> Authorization: Basic YWRtaW46YWRtaW4=
> User-Agent: curl/7.15.5 (i386-redhat-linux-gnu) libcurl/7.15.5 OpenSSL/0.9.8b zlib/1.2.3 libidn/0.6.5
> Host: localhost
> Accept: */*
> Content-Type: text/plain; charset=UTF-8
> Content-Length: 4
> Expect: 100-continue
>
< HTTP/1.1 100 Continue
< HTTP/1.1 500 Internal Server Error
< Date: Mon, 18 Feb 2013 11:26:51 GMT
< Accept-Ranges: bytes
< Server: 
< Vary: Accept-Charset, Accept-Encoding, Accept-Language, Accept
< Content-Type: text/html;charset=UTF-8
< Content-Length: 486
< Connection: close
<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;">Internal Server Error</p>
<p>The server encountered an unexpected condition which prevented it from fulfilling the request</p>
<p>You can get technical details <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.5.1">here</a>.<br>
Please continue your visit at our <a href="/">home page</a>.
</p>
</body>
</html>
* Closing connection #0

Here the logs from activiti:


Feb 18, 2013 6:26:51 AM org.restlet.resource.UniformResource doCatch
WARNING: Exception or error caught in resource
org.activiti.engine.ActivitiException: Unable to add new attachment to task 809
        at org.activiti.rest.api.task.TaskAttachmentAddResource.addAttachment(TaskAttachmentAddResource.java:58)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.restlet.resource.ServerResource.doHandle(ServerResource.java:449)
        at org.restlet.resource.ServerResource.put(ServerResource.java:1173)
        at org.restlet.resource.ServerResource.doHandle(ServerResource.java:524)
        at org.restlet.resource.ServerResource.doNegotiatedHandle(ServerResource.java:590)
        at org.restlet.resource.ServerResource.doConditionalHandle(ServerResource.java:302)
        at org.restlet.resource.ServerResource.handle(ServerResource.java:849)
        at org.restlet.resource.Finder.handle(Finder.java:513)
        at org.restlet.routing.Filter.doHandle(Filter.java:159)
        at org.restlet.routing.Filter.handle(Filter.java:206)
        at org.restlet.routing.Router.doHandle(Router.java:500)
        at org.restlet.routing.Router.handle(Router.java:740)
        at org.restlet.routing.Filter.doHandle(Filter.java:159)
        at org.restlet.routing.Filter.handle(Filter.java:206)
        at org.restlet.routing.Filter.doHandle(Filter.java:159)
        at org.restlet.routing.Filter.handle(Filter.java:206)
        at org.restlet.routing.Filter.doHandle(Filter.java:159)
        at org.restlet.routing.Filter.handle(Filter.java:206)
        at org.restlet.routing.Filter.doHandle(Filter.java:159)
        at org.restlet.engine.application.StatusFilter.doHandle(StatusFilter.java:155)
        at org.restlet.routing.Filter.handle(Filter.java:206)
        at org.restlet.routing.Filter.doHandle(Filter.java:159)
        at org.restlet.routing.Filter.handle(Filter.java:206)
        at org.restlet.engine.ChainHelper.handle(ChainHelper.java:114)
        at org.restlet.engine.application.ApplicationHelper.handle(ApplicationHelper.java:75)
        at org.restlet.Application.handle(Application.java:391)
        at org.restlet.routing.Filter.doHandle(Filter.java:159)
        at org.restlet.routing.Filter.handle(Filter.java:206)
        at org.restlet.routing.Router.doHandle(Router.java:500)
        at org.restlet.routing.Router.handle(Router.java:740)
        at org.restlet.routing.Filter.doHandle(Filter.java:159)
        at org.restlet.routing.Filter.handle(Filter.java:206)
        at org.restlet.routing.Router.doHandle(Router.java:500)
        at org.restlet.routing.Router.handle(Router.java:740)
        at org.restlet.routing.Filter.doHandle(Filter.java:159)
        at org.restlet.routing.Filter.handle(Filter.java:206)
        at org.restlet.engine.ChainHelper.handle(ChainHelper.java:114)
        at org.restlet.Component.handle(Component.java:391)
        at org.restlet.Server.handle(Server.java:491)
        at org.restlet.engine.ServerHelper.handle(ServerHelper.java:74)
        at org.restlet.engine.http.HttpServerHelper.handle(HttpServerHelper.java:153)
        at org.restlet.ext.servlet.ServerServlet.service(ServerServlet.java:1031)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
        at sun.reflect.GeneratedMethodAccessor151.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.apache.catalina.security.SecurityUtil$1.run(SecurityUtil.java:273)
        at org.apache.catalina.security.SecurityUtil$1.run(SecurityUtil.java:270)
        at java.security.AccessController.doPrivileged(Native Method)
        at javax.security.auth.Subject.doAsPrivileged(Subject.java:517)
        at org.apache.catalina.security.SecurityUtil.execute(SecurityUtil.java:305)
        at org.apache.catalina.security.SecurityUtil.doAsPrivilege(SecurityUtil.java:165)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:298)
        at org.apache.catalina.core.ApplicationFilterChain.access$000(ApplicationFilterChain.java:57)
        at org.apache.catalina.core.ApplicationFilterChain$1.run(ApplicationFilterChain.java:193)
        at org.apache.catalina.core.ApplicationFilterChain$1.run(ApplicationFilterChain.java:189)
        at java.security.AccessController.doPrivileged(Native Method)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:224)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
        at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
        at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:929)
        at org.apache.catalina.authenticator.SingleSignOn.invoke(SingleSignOn.java:308)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:405)
        at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:279)
        at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:515)
        at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:300)
        at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
        at java.lang.Thread.run(Thread.java:662)
Feb 18, 2013 6:26:51 AM org.restlet.engine.log.LogFilter afterHandle
INFO: 2013-02-18        06:26:51        127.0.0.1       admin   127.0.0.1       80      PUT     /activiti-rest/service/task/809/attachment      -       500     486     4       4       http://localhost        curl/7.15.5 (i386-redhat-linux-gnu) libcurl/7.15.5 OpenSSL/0.9.8b zlib/1.2.3 libidn/0.6.5       -

Last note. I traced the code to some degree and check the DB to ensure that the task is not suspended.

Any clue as to what is wrong or how I might work around this?

Thanks,
Dan
6 REPLIES 6

frederikherema1
Star Contributor
Star Contributor
Unfortunately, the original exception is not used as cause, so it's not easy to see what's happening:


} catch(Exception e) {
      if(e instanceof ActivitiException) {
        throw (ActivitiException) e;
      }
      throw new ActivitiException("Unable to add new attachment to task " + taskId);
    }

Are you able to debug the activiti-server in org.activiti.rest.api.task.TaskAttachmentAddResource.addAttachment? This may show you the root cause and take it from there…

dan1
Champ in-the-making
Champ in-the-making
Thanks for the response. I ran the debugger and the exception came from RestletUpload parseRepresentation. It's expecting multipart/form-data. I modified the curl command and all is well!


> curl -u"admin:admin" –form upload=@/activiti/attachments/junk.txt -X PUT http://localhost/activiti-rest/service/task/809/attachment

{"id":"901","name":"junk.txt","description":"junk.txt","type":"text/plain","url":null}

Thanks,
Dan

jbarrez
Star Contributor
Star Contributor
Thanks for posting back. Curl is indeed a funny beast sometimes.

chittaranjan168
Champ in-the-making
Champ in-the-making
Could not able to start process, through RuntimeService instance. Showing

Called Application
Called Method
Before process start
————
java.lang.NullPointerException
at com.test.jp.resource.HelloWorldResource.printHelloWorld(HelloWorldResource.java:58)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

HelloWorldResource.java
________________________

*
*
*
*
  System.out.println("Before process start");
            try {
            
       System.out.println("———— ");
       someBean.doTransactionalStuff(true);
      
       //runtimeService.startProcessInstanceByKey("helloProcess");
       System.out.println("After process start");
      } catch (RuntimeException re) {
       re.printStackTrace();
      }
******
Some Bean

public class SomeBean {


private RuntimeService runtimeService;

@Transactional
public void doTransactionalStuff(boolean error){
  System.out.println("stsrt process>>>>>>>>>!!!!!");
 
  String str=runtimeService.startProcessInstanceByKey("helloProcess").getId();
 
    if(str!=null){
     System.out.println("Process Instance is null!!!");
      throw new UnsupportedOperationException("Rollback needed!!");
    }
  }

public void setRuntimeService(RuntimeService runtimeService) {
  this.runtimeService = runtimeService;
}

}

and bpmn20.xml file
<process id="helloProcess" name="Hello Process" isExecutable="true">
    <startEvent id="start" name="Start"></startEvent>
    <sequenceFlow id="flow1" sourceRef="start" targetRef="print"></sequenceFlow>
    <serviceTask id="print" name="Service Task" activiti:expression="#{someOtherBean.doSimpleStuff()}" ></serviceTask>
    <sequenceFlow id="flow2" sourceRef="print" targetRef="end"></sequenceFlow>
    <endEvent id="end" name="End"></endEvent>
  </process>

chittaranjan168
Champ in-the-making
Champ in-the-making
Please help me…..

martin_grofcik
Confirmed Champ
Confirmed Champ
Hi,

what is the issue is someBean null? From where do you obtain someBean?
Could you prepare jUnit test for it?
http://forums.activiti.org/content/sticky-how-write-unit-test

Regards
Martin
Getting started

Tags


Find what you came for

We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.