0

我创建了 2 个 api:一个项目的系统和经验。系统已经部署到cloudhub并成功运行。体验api需要通过路由器使用url调用系统api:

http://demo-insurance-system-api.us-e2.cloudhub.io 和 uriparam 是 :customer 和 queryparams 是:?fname=James&lname=Butt 它工作得很好。但是当我想从体验 api 的请求者那里点击相同的网址时,它给了我

ERROR 2020-05-18 01:58:15,217 [[muleinsurance-exp-api].http.requester.requestConfig.04 SelectorRunner] [event: ] org.mule.runtime.core.internal.exception.OnErrorPropagateHandler: 
********************************************************************************
Message               : HTTP OPTIONS on resource 'http://demo-insurance-system-api.us-e2.cloudhub.io' failed: not found (404).
Error type            : HTTP:NOT_FOUND
Element               : muleinsurance-experience-api-main/processors/0 @ muleinsurance-exp-api:muleinsurance-experience-api.xml:17
Element XML           : <apikit:router config-ref="muleinsurance-experience-api-config"></apikit:router>

  (set debug level logging or '-Dmule.verbose.exceptions=true' for everything)

使用 postman 进行本地测试,体验网址为: http://localhost:8081/demoapi/customer?fname=James

经验api raml是:

#%RAML 1.0
title: muleinsurance-experience-api
version: 1.0.0

traits:
  client-id-required:
    headers:
      client_id:
        type: string
      client_secret:
        type: string

    responses:
      401:
        description: Unauthorized, The client_id or client_secret are not valid or the client does not have access.
      404:
        description: No Record found.
      429:
        description: The client used all of it's request quota for the current period.
      500:
        description: Server error ocurred
      503:
        description: Contracts Information Unreachable.
/demoapi:
  /{searchString}:
      get:
        description: invokes either customer or policy request
        queryParameters:
          fname:
            description: first name
            example: Sumitra
            required: false
            type: string
          lname:
            description: Last name
            example: Ojha
            required: false
            type: string
          dob:
            description: Date of Birth
            example: 1/2/2003
            required: false
            type: string
          customerID:
            description: CustomerID
            example: BU79786
            required: false
            type: string
          policytype:
            description: type of policy taken
            example: Personal Auto
            required: false
            type: string            
        responses:
          200:
            body:
              application/json:
                example: 
                  {"message": "connecting to System API"}

在这里,我添加了HTTP 请求 xml 片段

   <choice doc:name="Choice" doc:id="444a5cd6-4aee-441a-8736-2d2fff681e2e" >
            <when expression="#[attributes.uriParams.searchString == 'customer']"> 
                 <http:request method="GET" doc:name="Request" doc:id="30958d05-467a-41b1-bef3-83426359f2aa" url="http://demo-insurance-system-api.us-e2.cloudhub.io"><http:uri-params ><![CDATA[#[output application/java
---
{   customer : attributes.uriParams.searchString}]]]></http:uri-params>
    <http:query-params ><![CDATA[#[output application/java
---
{   fname : vars.fname,
    lname : vars.lname,
    dob : vars.dob}]]]>

请指出我需要改进的地方。提前致谢。

4

1 回答 1

0

错误消息中指出了该问题:HTTP OPTIONS on resource 'http://demo-insurance-system-api.us-e2.cloudhub.io' failed: not found (404).

看起来您在体验 API 中的 HTTP 请求正在使用 HTTP 选项方法。RAML 表示 API 只接受 HTTP GET 方法。在 XML 中,它应该如下所示:<http:request method="GET" ...

于 2020-05-17T22:56:56.777 回答