in this example, i am getting body as null but before there is a log which prints body.please help thank u in advance
Camel- 2.15.1.redhat-621084
fuse-6.2.1
IDE-codeready studio
salesforce.xml
-----------
<?xml version="1.0" encoding="UTF-8"?>
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.0.0 https://aries.apache.org/schemas/blueprint-cm/blueprint-cm-1.0.0.xsd http://www.osgi.org/xmlns/blueprint/v1.0.0 https://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd http://camel.apache.org/schema/blueprint https://camel.apache.org/schema/blueprint/camel-blueprint.xsd">
<!-- OSGi blueprint property placeholder -->
<cm:property-placeholder id="placeholder" persistent-id="org.jboss.quickstarts.fuse.salesforce"/>
<bean
class="org.apache.camel.component.salesforce.SalesforceComponent" id="salesforce">
<property name="loginConfig">
<bean class="org.apache.camel.component.salesforce.SalesforceLoginConfig">
<property name="loginUrl" value="${loginUrl}"/>
<property name="clientId" value="${clientId}"/>
<property name="clientSecret" value="${clientSecret}"/>
<property name="userName" value="${userName}"/>
<property name="password" value="${password}"/>
</bean>
</property>
<property name="packages">
<array>
<value>com.cg.Pojos</value>
</array>
</property>
</bean>
<bean class="org.jboss.quickstarts.fuse.salesforce.RouteXml" id="data"/>
<camelContext id="salesforce-example-context" xmlns="http://camel.apache.org/schema/blueprint">
<routeBuilder ref="data"/>
</camelContext>
</blueprint>
Route
-------
from("direct:sale").log("============Received Request from User To get XML===========")
.pollEnrich("file:C:/jboss-fuse-6.2.1.redhat-084/work/camel-salesforce/input")
.doTry()
.unmarshal(xmlDataFormat).log("${body}")
.bean(JobCardBean.class,"WriteFile")//just for make json
.bean(JobCardBean.class,"readFile")//just for json to object
.log("${body}")//till here i got object in body
.to("salesforce:upsertSObject?sObjectIdName=Name")
.choice()
.when()
.simple("${body} != null")
.log("Created job with result success=${body.success} and errors=${body.errors}")
.otherwise()
.log("Updated job in salesforce")
.end();
[route56] [to63] [direct:sale] [1842] n | [route58] [log162] [log] [0] n | [1011] n | [route58] [pollEnrich23] [pollEnrich [文件:C:/jboss-fuse-6.2.1.redhat-084/work/camel-salesforce/input] [route58] [doTry20] [doTry] [830] n | [route58] [unmarshal20] [unmarshal [org.apache.camel.model.DataFormatDefinition@1b5fd83]] [3] n | [route58] [log163] [log] [30] n | [route58] [bean35] [bean [com.capgemini.beans.JobCardBean@461fb6bd]] [8] n | [route58] [bean36] [bean [com.capgemini.beans.JobCardBean@5afe909b]] [4] n | [route58] [setHeader33] [setHeader [CamelHttpQuery]] [0] n | [route58] [setHeader34] [setHeader [CamelHttpMethod]] [0] n | [route58] [log164] [log] [1] n | [route58] [to66] [salesforce:upsertSObject?sObjectIdName = Name] [783] n | n |交换| -------------------------------------------------- -------------------------------------------------- ----------------------------------- n |交换[ n | ID ID-DIN17000356-51667-1583407046067-12-2 n | ExchangePattern输入输出 n |标头{CamelFileAbsolute = true,CamelFileAbsolutePath = C:\ jboss-fuse-6.2.1.redhat-084 \ work \ camel-salesforce \ input \ job.xml,CamelFileContentType = text / xml,CamelFileLastModified = 1583322179800,CamelFileLength = 330,CamelFileName = job.xml,CamelFileNameConsumed = job.xml,CamelFileNameOnly = job.xml,CamelFileParent = C:\ jboss-fuse-6.2.1.redhat-084 \ work \ camel-salesforce \ input,CamelFilePath = C:\ jboss-fuse -6.2.1.redhat-084 \ work \ camel-salesforce \ input \ job.xml,CamelFileRelativePath = job.xml,CamelHttpMethod = POST,CamelHttpQuery = _HTTPMethod = PATCH,CamelRedelivered = false,CamelRedeliveryCounter = 0,CamelToEndpoint = file:/ /C:/jboss-fuse-6.2.1.redhat-084/work/camel-salesforce/input} n | BodyType null n |身体[身体为空] n | ] n | n | Stacktracen | -------------------------------------------------- -------------------------------------------------- ----------------------------------- {消息:'错误{400:错误请求},正在org.apache.camel.component.salesforce.internal执行{PATCH:/services/data/v33.0/sobjects/PSA_Job_Master__c/Name/temp}',statusCode:400} .client.AbstractClientBase $ 1.onResponseComplete(AbstractClientBase.java:140)[314:org.apache.camel.camel-salesforce:2.15.1.redhat-621084]
答案 0 :(得分:0)
我认为是这样的:PATCH /services/data/v33.0/sobjects/PSA_Job_Master__c/Name/temp
。
Upsert操作必须使用自定义的外部ID字段。您不能将标准名称字段标记为ext id,UI中不存在该复选框。
尝试创建一个自定义字段(可能是type = text?对您有用),将其标记为外部ID,并且(可选,但建议)将其标识为唯一。甚至可以填充您的旧数据(将值从“名称”复制到新字段?),然后类似
PATCH /services/data/v33.0/sobjects/PSA_Job_Master__c/ExternalID__c/temp
在修改作业之前,您可以在Workbench(实用程序-> REST Explorer),Postman或SoapUI中进行实验
https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/dome_upsert.htm
编辑-要发送XML(并希望以其他方式期望响应),您需要发送正确的HTTP标头。参见https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/intro_usage_rest_resources.htm
POST to
/services/data/v48.0/sobjects/Account
With headers
Content-Type: application/xml
Accept: application/xml
Authorization: Bearer {session id goes here}
With body
<records>
<Name>Hi Stack</Name>
<Description>Lorem ipsum...</Description>
</records>
应该产生这样的内容(您将有必填字段,验证规则等,但仍需要担心)
<?xml version="1.0" encoding="UTF-8"?>
<Result>
<id>0013s00000xJsS9AAK</id>
<success>true</success>
</Result>
与JSON example进行比较,您应该很好地知道upsert消息应该是什么样的?