如何在JBPM中设置HTTP请求标头

时间:2019-03-05 15:16:52

标签: java rest postman jbpm

我想在JBPM中设置HTTP请求标头。我正在尝试邮递员的请求,它的工作原理...我已经用java做了一个简单的例子,现在我需要发送标头,例如邮递员,存在如下内容:

  

workItem.setParameter(“ Headers”,Headers);

enter image description here

代码有效:

import java.util.Map;
import org.drools.core.process.instance.impl.WorkItemImpl;
import org.jbpm.process.workitem.rest.RESTWorkItemHandler;
import org.kie.api.runtime.process.WorkItem;
import org.kie.api.runtime.process.WorkItemHandler;
import org.kie.api.runtime.process.WorkItemManager;

public class test {

    public static void main(String[] args) {
        test t=new test();
        System.out.println(t.getFiles("xxx","xxx","xxx","xxx"));
    }

    public String getFiles(String user,String pwd,String site,String path) {
        String result="Error getFiles ";
        try {           
            RESTWorkItemHandler handler = new RESTWorkItemHandler();
            WorkItemImpl workItem = new WorkItemImpl();
            workItem.setParameter("Url", "https://mywebsite.com/sharing/api/v1/files"+"?path="+path);
            workItem.setParameter("Method", "GET");
            // workItem.setParameter("Headers", Headers); Exists ?
            WorkItemManager manager = new TestWorkItemManager(workItem);
            handler.executeWorkItem(workItem, manager);
            int responseCode = (Integer) workItem.getResult("Status");      
            if(responseCode==200) {
                result = (String) workItem.getResult("Result");
            }   
        }catch(Exception e) {
            result+=e.getMessage();
        }
        return result;
    }   
}

class TestWorkItemManager implements WorkItemManager {    
    private WorkItem workItem;

    TestWorkItemManager(WorkItem workItem) {
        this.workItem = workItem;
    }

    @Override
    public void completeWorkItem(long id, Map<String, Object> results) {
        ((WorkItemImpl)workItem).setResults(results);        
    }

    @Override
    public void abortWorkItem(long id) {}

    @Override
    public void registerWorkItemHandler(String workItemName, WorkItemHandler handler) {

    }

}

1 个答案:

答案 0 :(得分:1)

经过少量研究,看来char方法可以处理参数executeWorkItem。内容应如下所示:

"Headers"

整个方法调用:

"HeaderName=HeaderValue;SecondHeaderName=SecondHeaderValue"