调用部署在 Mule 3.8.3 runtime w/o API Gateway 上的 APIKit 项目

Calling the APIKit project deployed on Mule 3.8.3 runtime w/o API Gateway

我使用单个 GET 创建了一个简单的 API RAML 文件,不需要任何参数,它 returns 是一个简单的负载。我使用 Anypoint Studio(上周的最新版本)将其正确地引入了我的项目,并在本地创建了 运行 项目 w/o 一个障碍。我在前提 3.8.3 上有一个 mule 运行时,我已经存档并成功部署了它。我可以在带有正确 .txt 文件的 /apps 目录中看到它,并且我在 Mule Mgmt 控制台中看到它作为我服务器上已部署的应用程序。我似乎无法正确调用它?你能在 mule runtime 上使用已部署的 APIKit 项目来做到这一点吗?我的简单设置如下所示,并且可以(当然)w/in Anypoint studio 在 运行 和调试模式下工作。

我调用 http://localhost:8081/api/testthis as my URL fine but when I go to my mulesoft server where I deployed this and call that IP http://x.x.x.x:8081/api/testthis 只是为了取回有效负载,它显示没有侦听器。我一定是遗漏了一个步骤或配置或其他东西,我似乎无法搜索他们的 DOC 或 SO 站点来找到问题。

感谢任何帮助(即使是讽刺!)。

<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:apikit="http://www.mulesoft.org/schema/mule/apikit" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:spring="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/core 
http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/http     
http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/apikit
 http://www.mulesoft.org/schema/mule/apikit/current/mule-apikit.xsd
http://www.springframework.org/schema/beans 
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd">
        <http:listener-config name="testapi-httpListenerConfig" host="0.0.0.0" port="8081" doc:name="HTTP Listener Configuration"/>
    <apikit:config name="testapi-config" raml="testapi.raml" consoleEnabled="false" doc:name="Router"/>
    <flow name="testapi-main">
        <http:listener config-ref="testapi-httpListenerConfig" path="/api/*" doc:name="HTTP"/>
        <apikit:router config-ref="testapi-config" doc:name="APIkit Router"/>
        <exception-strategy ref="testapi-apiKitGlobalExceptionMapping" doc:name="Reference Exception Strategy"/>
    </flow>
    <flow name="testapi-console">
        <http:listener config-ref="testapi-httpListenerConfig" path="/console/*" doc:name="HTTP"/>
        <apikit:console config-ref="testapi-config" doc:name="APIkit Console"/>
    </flow>
    <flow name="get:/testthis:testapi-config">
        <set-payload value="[  {&quot;code&quot;: &quot;MyCode1&quot;, &quot;name&quot; : &quot;My Code 1&quot;, &quot;ID&quot; : &quot;1111&quot;  }, {&quot;code&quot;: &quot;MyCode2&quot;, &quot;name&quot; : &quot;My Code 2&quot;, &quot;ID&quot; : &quot;2222&quot;  } ]" doc:name="Set Payload"/>
    </flow>
    <apikit:mapping-exception-strategy name="testapi-apiKitGlobalExceptionMapping">
        <apikit:mapping statusCode="404">
            <apikit:exception value="org.mule.module.apikit.exception.NotFoundException" />
        <set-property propertyName="Content-Type" value="application/json" doc:name="Property"/>
        <set-payload value="{ &quot;message&quot;: &quot;Resource not found&quot; }" doc:name="Set Payload"/>
    </apikit:mapping>
    <apikit:mapping statusCode="405">
        <apikit:exception value="org.mule.module.apikit.exception.MethodNotAllowedException" />
        <set-property propertyName="Content-Type" value="application/json" doc:name="Property"/>
        <set-payload value="{ &quot;message&quot;: &quot;Method not allowed&quot; }" doc:name="Set Payload"/>
    </apikit:mapping>
    <apikit:mapping statusCode="415">
        <apikit:exception value="org.mule.module.apikit.exception.UnsupportedMediaTypeException" />
        <set-property propertyName="Content-Type" value="application/json" doc:name="Property"/>
        <set-payload value="{ &quot;message&quot;: &quot;Unsupported media type&quot; }" doc:name="Set Payload"/>
    </apikit:mapping>
    <apikit:mapping statusCode="406">
        <apikit:exception value="org.mule.module.apikit.exception.NotAcceptableException" />
        <set-property propertyName="Content-Type" value="application/json" doc:name="Property"/>
        <set-payload value="{ &quot;message&quot;: &quot;Not acceptable&quot; }" doc:name="Set Payload"/>
    </apikit:mapping>
    <apikit:mapping statusCode="400">
        <apikit:exception value="org.mule.module.apikit.exception.BadRequestException" />
        <set-property propertyName="Content-Type" value="application/json" doc:name="Property"/>
        <set-payload value="{ &quot;message&quot;: &quot;Bad request&quot; }" doc:name="Set Payload"/>
    </apikit:mapping>
    </apikit:mapping-exception-strategy>
</mule>

这是它部署的地方

这就是 MMC 看到它部署到我们的 1 开发服务器的方式。

我用来创建项目的 RAML:

#%RAML 0.8
title: mmctest
version: 1.0

/testthis:
  get:
    queryParameters: 
      code:
          displayName: "Code"
          type: string
          description: "The code to pass through on a querystring"
          required: false
    responses: 
      200:
        body: 
          application/json:
            example: |
              [  {"code": "MyCode1", "name" : "My Code 1", "ID" : "1111"  }, {"code": "MyCode2", "name" : "My Code 2", "ID" : "2222"  } ]              

而我必须部署的 mule-config.xml 只是一个 shell 文件。

我的设置有两处错误。因此,对于占用您的时间,我向 Anirban 表示歉意。

  1. 我已经在 8081 端口上安装了另一个应用程序。所以我不得不将我的端口更改为 8080。
  2. 我没有为部署正确存档我的项目,所以我修复了它。导出到 Mule > Anypoint Studio 项目到 Mule 可部署存档

当我正确执行此操作时,一切都很好。所以我需要注意这一点,并确保我在未使用的有效端口上正确部署。