如何使用raml?

时间:2017-10-12 07:40:53

标签: mule raml

我第一次使用raml我的raml文件如下所示。

#%RAML 0.8
title: Contact
version: 1
baseUri: http://abc/api/{version}
traits:
  - client-id-required:
      queryParameters:
        client_id:
          type: string
        client_secret:
          type: string
/contact:
  post:
    is: [client-id-required]
    description: Create a new contact record
    body:
      application/json:
        example: !include contactCreateReq_sample.json
        schema: !include contactCreateReq.json
    responses:
      200:
        body:
          application/json:
            example: !include contactCreateRes_sample.json
            schema: !include contactCreateRes.json
  put:
    is: [client-id-required]
    description: update a customer record
    body:
      application/json:
        example: !include contactUpdateReq_sample.json
        schema: !include contactUpdateReq.json
    responses:
      200:
        body:
          application/json:
            example: !include contactUpdateRes_sample.json
            schema: !include contactUpdateRes.json
  delete:
    is: [client-id-required]
    description: update a customer record
    body:
      application/json:
        example: !include contactUpdateReq_sample.json
        schema: !include contactUpdateReq.json
    responses:
      200:
        body:
          application/json:
            example: !include contactUpdateRes_sample.json
            schema: !include contactUpdateRes.json    
  /{functionId}:
    post:
      is: [client-id-required]
      description: Create a new contact function record
      responses:
        200:
          body:
            application/json:
              example: !include contactCreateReq_sample.json
              schema: !include contactCreateReq.json
    put:
      is: [client-id-required]
      description: Update an existing contact function record
      responses:
        200:
          body:
            application/json:
              example: !include contactUpdateRes_sample.json
              schema: !include contactUpdateRes.json

在运行我的界面时收到以下错误消息,我有几个raml文件在所有raml文件情况下都出现同样的错误。它是生产中的工作界面我试图在我的本地机器上运行并得到上述错误。请让我知道我的代码中缺少什么?

ERROR 2017-10-12 13:02:26,292 [main] org.mule.module.launcher.application.DefaultMuleApplication: null
org.mule.module.apikit.exception.ApikitRuntimeException: Invalid API descriptor -- errors found: 1

RAML resource not found --  file: contact.raml

    at org.mule.module.apikit.parser.ParserWrapperV1.validate(ParserWrapperV1.java:68) ~[mule-module-apikit-3.8.5-HF1.jar:?]
    at org.mule.module.apikit.ParserService.validateRaml(ParserService.java:86) ~[mule-module-apikit-3.8.5-HF1.jar:?]
    at org.mule.module.apikit.AbstractConfiguration.initialise(AbstractConfiguration.java:112) ~[mule-module-apikit-3.8.5-HF1.jar:?]
    at sun.reflect.GeneratedMethodAccessor24.invoke(Unknown Source) ~[?:?]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_121]
    at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_121]
    at org.mule.lifecycle.phases.DefaultLifecyclePhase.applyLifecycle(DefaultLifecyclePhase.java:237) ~[mule-core-3.8.5.jar:3.8.5]
    at org.mule.lifecycle.phases.MuleContextInitialisePhase.applyLifecycle(MuleContextInitialisePhase.java:71) ~[mule-core-3.8.5.jar:3.8.5]
    at org.mule.lifecycle.RegistryLifecycleCallback.doApplyLifecycle(RegistryLifecycleCallback.java:99) ~[mule-core-3.8.5.jar:3.8.5]
    at org.mule.lifecycle.RegistryLifecycleCallback.onTransition(RegistryLifecycleCallback.java:71) ~[mule-core-3.8.5.jar:3.8.5]
    at org.mule.lifecycle.RegistryLifecycleManager.invokePhase(RegistryLifecycleManager.java:155) ~[mule-core-3.8.5.jar:3.8.5]
    at org.mule.lifecycle.RegistryLifecycleManager.fireLifecycle(RegistryLifecycleManager.java:126) ~[mule-core-3.8.5.jar:3.8.5]
    at org.mule.registry.AbstractRegistry.fireLifecycle(AbstractRegistry.java:146) ~[mule-core-3.8.5.jar:3.8.5]
    at org.mule.registry.AbstractRegistry.initialise(AbstractRegistry.java:116) ~[mule-core-3.8.5.jar:3.8.5]
    at org.mule.config.spring.SpringXmlConfigurationBuilder.createSpringRegistry(SpringXmlConfigurationBuilder.java:177) ~[mule-module-spring-config-3.8.5.jar:3.8.5]
    at org.mule.config.spring.SpringXmlConfigurationBuilder.doConfigure(SpringXmlConfigurationBuilder.java:100) ~[mule-module-spring-config-3.8.5.jar:3.8.5]
    at org.mule.config.builders.AbstractConfigurationBuilder.configure(AbstractConfigurationBuilder.java:43) ~[mule-core-3.8.5.jar:3.8.5]
    at org.mule.config.builders.AbstractResourceConfigurationBuilder.configure(AbstractResourceConfigurationBuilder.java:69) ~[mule-core-3.8.5.jar:3.8.5]
    at org.mule.config.builders.AutoConfigurationBuilder.autoConfigure(AutoConfigurationBuilder.java:102) ~[mule-core-3.8.5.jar:3.8.5]
    at org.mule.config.builders.AutoConfigurationBuilder.doConfigure(AutoConfigurationBuilder.java:54) ~[mule-core-3.8.5.jar:3.8.5]
    at org.mule.config.builders.AbstractConfigurationBuilder.configure(AbstractConfigurationBuilder.java:43) ~[mule-core-3.8.5.jar:3.8.5]
    at org.mule.config.builders.AbstractResourceConfigurationBuilder.configure(AbstractResourceConfigurationBuilder.java:69) ~[mule-core-3.8.5.jar:3.8.5]
    at org.mule.context.DefaultMuleContextFactory$1.configure(DefaultMuleContextFactory.java:89) ~[mule-core-3.8.5.jar:3.8.5]
    at org.mule.context.DefaultMuleContextFactory.doCreateMuleContext(DefaultMuleContextFactory.java:222) ~[mule-core-3.8.5.jar:3.8.5]
    at org.mule.context.DefaultMuleContextFactory.createMuleContext(DefaultMuleContextFactory.java:81) ~[mule-core-3.8.5.jar:3.8.5]
    at org.mule.module.launcher.application.DefaultMuleApplication.init(DefaultMuleApplication.java:203) ~[mule-module-launcher-3.8.5.jar:3.8.5]
    at org.mule.module.launcher.artifact.ArtifactWrapper$2.execute(ArtifactWrapper.java:63) ~[mule-module-launcher-3.8.5.jar:3.8.5]
    at org.mule.module.launcher.artifact.ArtifactWrapper.executeWithinArtifactClassLoader(ArtifactWrapper.java:136) ~[mule-module-launcher-3.8.5.jar:3.8.5]
    at org.mule.module.launcher.artifact.ArtifactWrapper.init(ArtifactWrapper.java:58) ~[mule-module-launcher-3.8.5.jar:3.8.5]
    at org.mule.module.launcher.DefaultArtifactDeployer.deploy(DefaultArtifactDeployer.java:25) ~[mule-module-launcher-3.8.5.jar:3.8.5]
    at org.mule.module.launcher.DefaultArchiveDeployer.deployArtifact(DefaultArchiveDeployer.java:317) ~[mule-module-launcher-3.8.5.jar:3.8.5]
    at org.mule.module.launcher.DefaultArchiveDeployer.deployPackagedArtifact(DefaultArchiveDeployer.java:172) ~[mule-module-launcher-3.8.5.jar:3.8.5]
    at org.mule.module.launcher.DefaultArchiveDeployer.deployPackagedArtifact(DefaultArchiveDeployer.java:261) ~[mule-module-launcher-3.8.5.jar:3.8.5]
    at org.mule.module.launcher.DefaultArchiveDeployer.deployPackagedArtifact(DefaultArchiveDeployer.java:76) ~[mule-module-launcher-3.8.5.jar:3.8.5]
    at org.mule.module.launcher.DeploymentDirectoryWatcher.deployPackedApps(DeploymentDirectoryWatcher.java:279) ~[mule-module-launcher-3.8.5.jar:3.8.5]
    at org.mule.module.launcher.DeploymentDirectoryWatcher.start(DeploymentDirectoryWatcher.java:151) ~[mule-module-launcher-3.8.5.jar:3.8.5]
    at org.mule.module.launcher.MuleDeploymentService.start(MuleDeploymentService.java:134) ~[mule-module-launcher-3.8.5.jar:3.8.5]
    at org.mule.module.launcher.MuleContainer.start(MuleContainer.java:172) ~[mule-module-launcher-3.8.5.jar:3.8.5]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_121]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_121]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_121]
    at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_121]
    at org.mule.tooling.server.application.ApplicationDeployer.main(ApplicationDeployer.java:33) ~[tooling-support-3.8.5.jar:?]
INFO  2017-10-12 13:02:26,292 [main] org.mule.module.launcher.application.DefaultMuleApplication: App 'sfdc-sap-api-interface-v4.7-prod' never started, nothing to dispose of
ERROR 2017-10-12 13:02:26,307 [main] org.mule.module.launcher.DefaultArchiveDeployer: 
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+ Failed to deploy artifact                                +
+ 'sfdc-sap-api-interface-v4.7-prod', see below            +
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
org.mule.module.launcher.DeploymentInitException: ApikitRuntimeException: Invalid API descriptor -- errors found: 1

RAML resource not found --  file: contact.raml

    at org.mule.module.launcher.application.DefaultMuleApplication.init(DefaultMuleApplication.java:212) ~[mule-module-launcher-3.8.5.jar:3.8.5]
    at org.mule.module.launcher.artifact.ArtifactWrapper$2.execute(ArtifactWrapper.java:63) ~[mule-module-launcher-3.8.5.jar:3.8.5]
    at org.mule.module.launcher.artifact.ArtifactWrapper.executeWithinArtifactClassLoader(ArtifactWrapper.java:136) ~[mule-module-launcher-3.8.5.jar:3.8.5]

1 个答案:

答案 0 :(得分:1)

Such error comes, if raml file is not present in class path while the application in being build.

A. If you are building using Anypoint Studio.

1.Go To Java Build Path in your project properties.

2.Click on "Source" tab

3.Click on Add Folder button.

4.Check the folder where “contact.raml” is present. Generally raml filet is kept in the “ api” folder. Hence if it so, check “api” folder and click “OK”.

5.Click "Apply"

Add the folder where “contact.raml” is present. Generally raml filet is kept in the “ api” folder. Hence if it so, check “api” folder and click “OK”.After that clean and rebuild project.

B.If you are using maven to build the project.

Make sure you have the "mule-module-apikit" dependency in pom file, if not add it and also specify the resource directory as below in the plugin and give it a try.Consider below example from my pom.xml

    <groupId>org.codehaus.mojo</groupId>
         <artifactId>build-helper-maven-plugin</artifactId>
         <version>1.7</version>
         <executions>
             <execution>
                 <id>add-resource</id>
                 <phase>generate-resources</phase>
                 <goals>
                     <goal>add-resource</goal>
                 </goals>
                 <configuration>
                     <resources>
                         <resource>
                             <directory>src/main/app/</directory>
                         </resource>
                         <resource>
                             <directory>mappings/</directory>
                         </resource>
                         <resource>
                             <directory>src/main/api</directory>
                         </resource>
                     </resources>
                 </configuration>
             </execution>
         </executions>
     </plugin>