У меня есть веб-сервис, который вызывает API с именем API1, тогда, если ответ API1 будет {"result":"0"}
, будет вызван второй API, API2.API2 предназначен для загрузки файла, и если загрузка завершится успешно, будет вызван третий API, API3.Моя проблема в том, что тело сообщения не отправляет в API3 должным образом без каких-либо ошибок!
Мой код такой, как показано ниже: сначала я отправляю запрос на публикацию с содержанием:
{
"API1": {
"version": "Tooba_Uni_Appv0.4.1.apk"
},
"API2": {
"password": "password",
"username": "username",
"file": "/home/.../index.png"
},
"API3": {
"lastVer": "apk.1.10.0"
}
}
SetMainBodyпроцесс устанавливает содержимое сообщения как упомянутое выше содержимое init.
<camelContext id="camel-CallAPI" xmlns="http://camel.apache.org/schema/blueprint" >
<!-- Web service starts working -->
<restConfiguration component="restlet" host="192.168.100.232" port="8889"/>
<rest path="/say">
<post uri="/hi" consumes="application/json" produces="application/json">
<to uri="direct:start"/>
</post>
</rest>
<route>
<from uri="direct:start"/>
<convertBodyTo type="java.lang.String"/>
<setProperty propertyName="mainBody">
<simple>${body}</simple>
</setProperty>
<removeHeaders pattern="*" excludePattern="Content-Type|CamelHttpMethod"/>
<setHeader headerName="CONTENT_TYPE" >
<constant>application/json</constant>
</setHeader>
<process ref="getVersionParam"/>
<convertBodyTo type="java.lang.String"/>
<log message="before api1 and after process :: ${body}"/>
<to uri="direct:first"/>
</route>
<route>
<from uri="direct:first"/>
<to uri="http4://...path to API1"/>
<convertBodyTo type="java.lang.String"/>
<log message="after api1 :: ${body}"/>
<log message="if the result is 0 the Upload API should be called, otherwise the result should be stored in queue!"/>
<!-- <setProperty propertyName="BodyAfterAPI1">
<simple>${body}</simple>
</setProperty> -->
<setProperty propertyName="AccessResultAPI1">
<jsonpath>$.result</jsonpath>
</setProperty>
<choice>
<when>
<!-- the testCheckLastVersion API does not work fine and The result of API will be stored in the queue-->
<simple>${property.AccessResultAPI1} != '0'</simple>
<inOnly id="ErrorQueueTestVersion" uri="activemq:queue:ErrorQueueTestVersionAPI"/>
<log message="the testCheckLastVersion API has a problem and the Upload API can not be called."/>
</when>
<when>
<!-- the testCheckLastVersion API works fine and Upload API must be called-->
<simple>${property.AccessResultAPI1} == '0'</simple>
<log message="the testCheckLastVersion work fine and the Upload API will be call soon,${property.AccessResultAPI1}"/>
<to uri="direct:callUploadAPI" />
</when>
</choice>
</route>
<route id="route_callUploadAPI">
<from uri="direct:callUploadAPI" id="from_callUploadAPI"/>
<process ref="setMainBody"/>
<convertBodyTo type="java.lang.String"/>
<log message="pure body: ${body}"/>
<removeHeaders pattern="*" excludePattern="Content-Type|CamelHttpMethod"/>
<setHeader headerName="CONTENT_TYPE" >
<constant>multipart/form-data</constant>
</setHeader>
<process ref="getUploadParam"/>
<to uri="http4://...path to upload API2"/>
<convertBodyTo type="java.lang.String"/>
<log message="the Upload API: ${body} :: if the success was 1 the third API will be called "/>
<setProperty propertyName="AccessResultAPI2">
<jsonpath>$.success</jsonpath>
</setProperty>
<choice>
<when>
<!--when the Upload API does not works fine and the result of Upload API must be stored in the queue-->
<simple>${property.AccessResultAPI2} != '1'</simple>
<inOnly id="ErrorQueueAPIUpload" uri="activemq:queue:ErrorQueueUploadAPI"/>
<log message="the Upload API has a problem and the TestsetVersion API can not be called."/>
</when>
<!--when the Upload API works fine and TestsetLastVersion API must be called-->
<when>
<simple>${property.AccessResultAPI2} == '1'</simple>
<log message="the Upload API works, success: ${property.AccessResultAPI2}"/>
<to uri="direct:midle"/>
</when>
</choice>
</route>
<route>
<from uri="direct:midle"/>
<!-- <process ref="setMainBody"/>
<convertBodyTo type="java.lang.String"/>-->
<log message="body aftre setMainbody: ${body}"/>
<removeHeaders pattern="*" excludePattern="Content-Type|CamelHttpMethod"/>
<setHeader headerName="CamelHttpMethod" >
<constant>POST</constant>
</setHeader>
<setHeader headerName="CONTENT_TYPE" >
<constant>application/json</constant>
</setHeader>
<!-- <process ref="getLastVersionParam"/>
<convertBodyTo type="java.lang.String"/>-->
<setBody>
<constant>{"lastVer":"apk.1.10.0"}</constant>
</setBody>
<convertBodyTo type="java.lang.String"/>
<to uri="http4://...path to API3"/>
<convertBodyTo type="java.lang.String"/>
<log message="the testsetLastVersion API: ${body}"/>
<log message="The TestsetLastversion API is ok and the process finished successfuly."/>
</route>
</camelContext>
проблема в том, что содержимое тела не отправляется третьему API и не возвращает ответ!