如何使用jboss fuse连接器更新ServiceNow表

时间:2018-03-30 11:01:40

标签: jbossfuse connector servicenow

将JSON输入到REST API

`{
    "userName" : "UserName",
    "password" : "Password",
    "instance"  : "Instance Name",
    "table":"incident",
    "sysId": "9d385017c611228701d22104cc95c371",
    "model":"{'assigned_to':'681b365ec0a80164000fb0b05854a0cd','urgency':'2','comments':'Elevating urgency, this is a blocking issue'}"
}`

处理器包含以下标题:

`    Map<String, Object> headers = new HashMap<>();
    headers.put(ServiceNowConstants.ACTION, ServiceNowConstants.ACTION_UPDATE);
    headers.put(ServiceNowConstants.RESOURCE, "table");
    headers.put(ServiceNowConstants.TABLE, msg.getTable());
    headers.put(ServiceNowConstants.SYSPARM_ID , msg.getSysId());
    headers.put(ServiceNowConstants.MODEL, msg.getModel()); 
    exchange.getOut().setHeaders(headers);`

Spring Camel Context Bean文件有端点:

`servicenow://${header.instance}?userName=${header.name}&amp;password=${header.password}&amp;apiUrl=${header.apiUrl}`

输出:

`<h2>HTTP ERROR 500</h2>
        <p>Problem accessing /servicenow/update. Reason:    
            <pre>model must be specified</pre>`

CamelServiceNowModel在文档中被称为Class,但是没有相同的实现。请帮忙,将Model String / Class放在正确的位置,以便在ServiceNow中更新。

1 个答案:

答案 0 :(得分:0)

  1. 根据ServiceNow REST API的文档,POST / PATCH操作,数据应该在Body中发送

      
        

    这是通过下面的代码段解决的     Map<String, Object> body = new HashMap<>(); body.put("short_description", msg.getShort_description()); body.put("priority", msg.getPriority()); exchange.getOut().setBody(body);

      
  2. ServiceNowConstants.MODEL接受String(类路径)

      
        

    headers.put(ServiceNowConstants.MODEL, "java.util.HashMap");