我想在JBPM中设置HTTP请求标头。我正在尝试邮递员的请求而且它的工作原理...我做了一个简单的例子,使用java及其工作现在我需要发送标题,如postman,存在类似于:
workItem.setParameter(“Headers”,Headers);
代码有效:
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) {
}
}
经过小规模的研究,它看起来像executeWorkItem
方法可以处理参数"Headers"
。内容应如下所示:
"HeaderName=HeaderValue;SecondHeaderName=SecondHeaderValue"
所以整个方法调用:
workItem.setParameter("Headers", "usr=yourUsr;pwd=yourPwd");