我使用mfpdev adapter create
创建了一个http适配器
但我发现adatper.xml配置文件包含服务器连接配置,我想根据dev,test,produciton进行相应更改
环境。
所以我尝试通过更改pom.xml来使用maven资源过滤器,如下所示
的pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.my.adapter</groupId>
<artifactId>MYAPIAdapter</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>adapter</packaging>
<name>MYAPIAdapter</name>
<properties>
<!-- Use UTF-8 as the encoding of the adapter -->
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<!-- MobileFirst adapter deployment properties -->
<mfpfUrl>http://localhost:9080/mfpadmin</mfpfUrl>
<mfpfUser>admin</mfpfUser>
<mfpfPassword>admin</mfpfPassword>
<mfpfRuntime>mfp</mfpfRuntime>
</properties>
<dependencies>
<dependency>
<groupId>com.ibm.mfp</groupId>
<artifactId>adapter-maven-api</artifactId>
<scope>provided</scope>
<version>[8.0.0,9.0.0)</version>
</dependency>
<dependency>
<groupId>com.ibm.mfp</groupId>
<artifactId>mfp-security-checks-base</artifactId>
<version>[8.0.0,9.0.0)</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>com.ibm.mfp</groupId>
<artifactId>adapter-maven-plugin</artifactId>
<extensions>true</extensions>
</plugin>
</plugins>
<filters>
<filter>profiles/${build.profile.id}/config.properties</filter>
</filters>
<resources>
<resource>
<directory>src/main/adapter-resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</build>
<profiles>
<profile>
<id>pc</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<build.profile.id>pc</build.profile.id>
</properties>
</profile>
<profile>
<id>sit</id>
<properties>
<build.profile.id>sit</build.profile.id>
</properties>
</profile>
<profile>
<id>uat</id>
<properties>
<build.profile.id>uat</build.profile.id>
</properties>
</profile>
<profile>
<id>prod</id>
<properties>
<build.profile.id>prod</build.profile.id>
</properties>
</profile>
</profiles>
adapter.xml
<mfp:adapter name="MYAPIAdapter"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mfp="http://www.ibm.com/mfp/integration"
xmlns:http="http://www.ibm.com/mfp/integration/http">
<displayName>MYAPIAdapter</displayName>
<description>MYAPIAdapter</description>
<connectivity>
<connectionPolicy xsi:type="http:HTTPConnectionPolicyType">
<protocol> ${connect.protocol}</protocol>
<domain> ${connect.domain}</domain>
<port> ${connect.port}</port>
<connectionTimeoutInMilliseconds> ${connect.timeout.ms}</connectionTimeoutInMilliseconds>
<socketTimeoutInMilliseconds> ${connect.sockettimeout.ms}</socketTimeoutInMilliseconds>
<maxConcurrentConnectionsPerNode> ${max.concurrentconnections}</maxConcurrentConnectionsPerNode>
</connectionPolicy>
</connectivity>
<procedure name="getFeed"/>
<procedure name="unprotected" secured="false"/>
当我运行mvn install
时,我遇到以下错误,看起来像mfp maven插件验证适配器xml文件。运行mvn compile
没有问题,并且适配器xml值已成功替换为属性文件中的值。无论如何在构建mfp适配器时从属性文件中指定配置?
ERROR] Failed to execute goal com.ibm.mfp:adapter-maven-plugin:8.0.2016082422:build (default-build) on project MYAPIAdapter: Adapter xml file schema validation encountered errors: [cvc-datatype-valid.1.2.1: '${connect.port}' is not a valid value for 'integer'., cvc-type.3.1.3: The value '${connect.port}' of element 'port' is not valid., cvc-datatype-valid.1.2.1: '${connect.timeout.ms}' is not a valid value for 'integer'., cvc-type.3.1.3: The value '${connect.timeout.ms}' of element 'connectionTimeoutInMilliseconds' is not valid., cvc-datatype-valid.1.2.1: '${connect.sockettimeout.ms}' is not a valid value for 'integer'., cvc-type.3.1.3: The value '${connect.sockettimeout.ms}' of element 'socketTimeoutInMilliseconds' is not valid., cvc-datatype-valid.1.2.1: '${max.concurrentconnections}' is not a valid value for 'integer'., cvc-type.3.1.3: The value '${max.concurrentconnections}' of element 'maxConcurrentConnectionsPerNode' is not valid.] -> [Help 1] [ERROR]
答案 0 :(得分:1)
在MobileFirst Foundation 8.0中,您可以使用MobileFirst CLI或Maven使用不同的&#34;配置文件更新服务器&#34;。见这里:https://mobilefirstplatform.ibmcloud.com/tutorials/en/foundation/8.0/adapters/javascript-adapters/#pull-and-push-configurations
CLI:
mfpdev adapter pull
mfpdev adapter push
的Maven:
mvn adapter:configpull -DmfpfConfigFile=config.json
mvn adapter:configpush -DmfpfConfigFile=config.json
首次部署适配器后,请使用mfpdev adapter pull
命令。因为您尚未通过MobileFirst Operations Console 更改任何值,这将在适配器目录的根目录(即JavaScriptHTTP \ config)创建空 config.json文件上传.json):
{ }
您现在可以编辑此配置文件以获取特定的&#34;个人资料&#34;,然后为其他每个&#34;个人资料&#34;复制它。
要更轻松地编辑它,最好先在控制台中编辑各种属性,然后再将它们拉出来,以便创建一个填充的config.json文件。例如,在更改domain
,port
和protocol
值,保存更改并运行pull
命令后,将使用以下内容填充config.json文件:
{"connectivity":{"http":{"protocol":{"value":"http"},"port":{"value":4431},"domain":{"value":"ibmcloud.com"}}}}
你可以美化它:
{
"connectivity": {
"http": {
"protocol": {
"value": "http"
},
"port": {
"value": 4431
},
"domain": {
"value": "ibmcloud.com"
}
}
}
}
现在为每个&#34;个人资料&#34;复制此文件并自定义值
然后,您可以push
将其重新发送回服务器。
按原样部署适配器(在adapter.xml中它的默认属性并不重要,因为这些属性将根据您推送的配置文件被覆盖。)
推送特定的config.json文件:mfpdev adapter push
。
如果您需要存储不同的文件,例如:dev.json,qa.json,uat.json和prod.json,您仍然可以执行此操作,但不是使用CLI - 使用Maven:
mvn adapter:configpush -DmfpfConfigFile=config.json
替换&#34; config.json&#34;使用相应的.json文件的名称。
或者,继续使用当前的实现并使用mvn compile
。您还可以使用Maven命令构建和部署适配器:https://mobilefirstplatform.ibmcloud.com/tutorials/en/foundation/8.0/adapters/creating-adapters/
答案 1 :(得分:0)
作为一种解决方法,您可以在pom.xml中设置生成的adapter.xml的路径。
```
<build>
<resources>
<resource>
<directory>src/main/adapter-resources</directory>
<filtering>true</filtering>
<targetPath>${adapterResourcePath}</targetPath>
</resource>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>com.ibm.mfp</groupId>
<artifactId>adapter-maven-plugin</artifactId>
<version>${version.mffadapter.plugin}</version>
<extensions>true</extensions>
<executions>
<execution>
<goals>
<goal>build</goal>
</goals>
<configuration combine.self="override">
<adapterResourcesDir implementation="java.io.File">${adapterResourcePath}
</adapterResourcesDir>
</configuration>
</execution>
</executions>
</plugin>