首页 > 解决方案 > 带有 baseUriParameter 的 Mule-APIkit 会截断资源路径,从而出错为“找不到资源”

问题描述

任何人都可以在这里建议/纠正我如何让 APIkit 路由器与baseUriParameter. 如果 HTTP 侦听器连接器中的路径被硬编码为/api/process/30001/*,则一切正常。APIKit 路由器能够路由请求的资源路径。但是,当 HTTP 侦听器连接器路径中有一个占位符时/api/process/{clientID}/*,APIkit 路由器会抛出一个错误,如No resource found.

从下面的堆栈跟踪中,我可以看到请求资源路径被截断,例如,/sample变得公正ple,我找不到原因。通过调试,我可以看到完整的请求 URI。调试模式下的图像查看完整的请求路径

我尝试了其他一些选项,例如:

  1. 在路由器配置中检查'keep raml base uri'
  2. 取消选中HTTP 侦听器连接器高级选项卡中的“解析请求”框

我也检查了这一点,以确保我的 RAML 符合raml-template-uris 和 uriparams

我在 MuleSoft 文档中找到了这个:

在 API Gateway Runtime 2.x 及更早版本中,APIkit 旨在与 RAML 接口紧密配合,但不会自动从 RAML 定义中导入以下项目:

安全方案

协议

baseUriParameters

那么,我该如何导入baseUriParameters?我如何使它工作?

我已经被这个问题困扰了很长时间,所以非常感谢任何帮助。如果我遗漏了什么,请纠正我。非常感谢!

#%RAML 1.0
title: Test API
baseUri: /api/process/{clientID}
baseUriParameters: 
  clientID:
   type: number
   example: 300001
  
/sample:
  get:
    responses:
      200:
        body:
          application/json: 

流动:

 <http:listener-config xmlns:http="http://www.mulesoft.org/schema/mule/http" name="baseuriprameter-apikit-httpListenerConfig" host="0.0.0.0" port="8081" doc:name="HTTP Listener Configuration" />
<apikit:config xmlns:apikit="http://www.mulesoft.org/schema/mule/apikit" name="baseuriprameter-apikit-config" raml="baseuriprameter-apikit.raml" consoleEnabled="false" doc:name="Router" keepRamlBaseUri="false"/>
<flow name="baseuriprameter-apikit-main">
    <http:listener xmlns:http="http://www.mulesoft.org/schema/mule/http" config-ref="baseuriprameter-apikit-httpListenerConfig" path="/api/process/{clientID}/*" doc:name="HTTP" parseRequest="false"/>
    <apikit:router xmlns:apikit="http://www.mulesoft.org/schema/mule/apikit" config-ref="baseuriprameter-apikit-config" doc:name="APIkit Router"/>
    <exception-strategy ref="baseuriprameter-apikit-apiKitGlobalExceptionMapping" doc:name="Reference Exception Strategy"/>
</flow>
<flow name="baseuriprameter-apikit-console">
    <http:listener xmlns:http="http://www.mulesoft.org/schema/mule/http" config-ref="baseuriprameter-apikit-httpListenerConfig" path="/console/*" doc:name="HTTP" parseRequest="false"/>
    <apikit:console xmlns:apikit="http://www.mulesoft.org/schema/mule/apikit" config-ref="baseuriprameter-apikit-config" doc:name="APIkit Console"/>
</flow>
<flow name="get:/sample:baseuriprameter-apikit-config">
    <set-payload value="Hello World!" doc:name="Set Payload"/>
</flow>

堆栈跟踪:

 WARN  2018-06-11 19:52:27,452 [[baseuriprameter-apikit].baseuriprameter- 
 apikit-httpListenerConfig.worker.01] org.mule.module.apikit.Configuration: 
No matching patterns for URI ple
ERROR 2018-06-11 19:52:28,082 [[baseuriprameter-apikit].baseuriprameter- 
apikit-httpListenerConfig.worker.01] 
org.mule.module.apikit.MappingExceptionListener: 

**************************************************
Message               : ple
Payload               : {NullPayload}
Payload Type          : org.mule.transport.NullPayload
Element               : /baseuriprameter-apikit-main/processors/0 @ 
baseuriprameter-apikit:baseuriprameter-apikit.xml:11 (APIkit Router)
Element XML           : <apikit:router 
xmlns:apikit="http://www.mulesoft.org/schema/mule/apikit" config- 
ref="baseuriprameter-apikit-config" doc:name="APIkit Router"> 
</apikit:router>
--------------------------------------------------------
Root Exception stack trace:
org.mule.module.apikit.exception.NotFoundException: ple
atorg.mule.module.apikit.AbstractConfiguration$2.load(AbstractConfiguration.java:178)atorg.mule.module.apikit.AbstractConfiguration$2.load(AbstractConfiguration.java:169)
atcom.google.common.cache.LocalCache$LoadingValueReference.loadFuture(LocalCache.java:3527)atcom.google.common.cache.LocalCache$Segment.loadSync(LocalCache.java:2319)
atcom.google.common.cache.LocalCache$Segment.lockedGetOrLoad(LocalCache.java:2282)
at com.google.common.cache.LocalCache$Segment.get(LocalCache.java:2197)
at com.google.common.cache.LocalCache.get(LocalCache.java:3937)
at com.google.common.cache.LocalCache.getOrLoad(LocalCache.java:3941)
at com.google.common.cache.LocalCache$LocalLoadingCache.get(LocalCache.java:4824)
at org.mule.module.apikit.AbstractRouter.processRouterRequest(AbstractRouter.java:177)
at org.mule.module.apikit.AbstractRouter.processBlockingRequest(AbstractRouter.java:104)
at org.mule.module.apikit.AbstractRouter.processBlocking(AbstractRouter.java:98)

标签: parametersbase-urlmule-esbapikitraml-1.0

解决方案


推荐阅读