我不是很喜欢WSO2 ESB而且我有以下问题。
在我的ESB项目中,我有2个不同的API,它们具有相同的上下文但处理不同的URL。
1)第一个名为CommoditiesInACountry,它以这种方式定义:
<?xml version="1.0" encoding="UTF-8"?>
<api context="/country" name="CommoditiesInACountry" xmlns="http://ws.apache.org/ns/synapse">
<resource methods="GET" uri-template="/{localizationId}/commodities">
..............................................................
..............................................................
..............................................................
2)第二个名为CommodityInLocationMarkets,它以这种方式定义:
<?xml version="1.0" encoding="UTF-8"?>
<api context="/country" name="CommodityInLocationMarkets" xmlns="http://ws.apache.org/ns/synapse">
<resource methods="GET" uri-template="/{localizationId}/commodity/{commodityId}">
..............................................................
..............................................................
..............................................................
因此,您可以看到两者具有相同的上下文具有值/国家,但是2个API处理不同的URL,实际上第一个处理资源... / country / {localizationId} / commodities,第二个处理资源。 ./country/{localizationId}/commodity/{commodityId}
问题是当我部署我的Carbon应用程序时,我获得了以下错误消息:我有2个具有相同上下文值的不同API:
TID: [-1234] [] [2017-12-01 15:37:31,573] INFO {org.apache.synapse.rest.API} - Initializing API: CommodityInLocationMarkets {org.apache.synapse.rest.API}
TID: [-1234] [] [2017-12-01 15:37:31,573] ERROR {org.apache.synapse.config.SynapseConfiguration} - URL context: /country is already registered with the API: CommoditiesInACountry {org.apache.synapse.config.SynapseConfiguration}
TID: [-1234] [] [2017-12-01 15:37:31,573] ERROR {org.wso2.carbon.rest.api.ApiDeployer} - API deployment from the file : /opt/wso2/wso2ei-6.1.1/wso2/tmp/carbonapps/-1234/1512139051333agrimarketprice-cap_1.0.0.car/CommodityInLocationMarkets_1.0.0/CommodityInLocationMarkets-1.0.0.xml : Failed. {org.wso2.carbon.rest.api.ApiDeployer}
org.apache.synapse.SynapseException: URL context: /country is already registered with the API: CommoditiesInACountry
at org.apache.synapse.config.SynapseConfiguration.handleException(SynapseConfiguration.java:1629)
at org.apache.synapse.config.SynapseConfiguration.addAPI(SynapseConfiguration.java:407)
at org.apache.synapse.deployers.APIDeployer.deploySynapseArtifact(APIDeployer.java:59)
at org.wso2.carbon.rest.api.ApiDeployer.deploySynapseArtifact(ApiDeployer.java:34)
at org.apache.synapse.deployers.AbstractSynapseArtifactDeployer.deploy(AbstractSynapseArtifactDeployer.java:194)
at org.wso2.carbon.application.deployer.synapse.SynapseAppDeployer.deployArtifacts(SynapseAppDeployer.java:131)
at org.wso2.carbon.application.deployer.internal.ApplicationManager.deployCarbonApp(ApplicationManager.java:272)
at org.wso2.carbon.application.deployer.CappAxis2Deployer.deploy(CappAxis2Deployer.java:72)
at org.apache.axis2.deployment.repository.util.DeploymentFileData.deploy(DeploymentFileData.java:136)
at org.apache.axis2.deployment.DeploymentEngine.doDeploy(DeploymentEngine.java:807)
at org.apache.axis2.deployment.repository.util.WSInfoList.update(WSInfoList.java:144)
at org.apache.axis2.deployment.RepositoryListener.update(RepositoryListener.java:377)
at org.apache.axis2.deployment.RepositoryListener.checkServices(RepositoryListener.java:254)
at org.apache.axis2.deployment.RepositoryListener.startListener(RepositoryListener.java:371)
at org.apache.axis2.deployment.scheduler.SchedulerTask.checkRepository(SchedulerTask.java:59)
at org.apache.axis2.deployment.scheduler.SchedulerTask.run(SchedulerTask.java:67)
at org.wso2.carbon.core.deployment.CarbonDeploymentSchedulerTask.runAxisDeployment(CarbonDeploymentSchedulerTask.java:93)
at org.wso2.carbon.core.deployment.CarbonDeploymentSchedulerTask.run(CarbonDeploymentSchedulerTask.java:138)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:180)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
TID: [-1234] [] [2017-12-01 15:37:31,574] ERROR {org.apache.synapse.deployers.AbstractSynapseArtifactDeployer} - Deployment of the Synapse Artifact from file : /opt/wso2/wso2ei-6.1.1/wso2/tmp/carbonapps/-1234/1512139051333agrimarketprice-cap_1.0.0.car/CommodityInLocationMarkets_1.0.0/CommodityInLocationMarkets-1.0.0.xml : Failed! {org.apache.synapse.deployers.AbstractSynapseArtifactDeployer}
org.apache.synapse.deployers.SynapseArtifactDeploymentException: API deployment from the file : /opt/wso2/wso2ei-6.1.1/wso2/tmp/carbonapps/-1234/1512139051333agrimarketprice-cap_1.0.0.car/CommodityInLocationMarkets_1.0.0/CommodityInLocationMarkets-1.0.0.xml : Failed.
at org.apache.synapse.deployers.AbstractSynapseArtifactDeployer.handleSynapseArtifactDeploymentError(AbstractSynapseArtifactDeployer.java:474)
at org.apache.synapse.deployers.APIDeployer.deploySynapseArtifact(APIDeployer.java:71)
at org.wso2.carbon.rest.api.ApiDeployer.deploySynapseArtifact(ApiDeployer.java:34)
at org.apache.synapse.deployers.AbstractSynapseArtifactDeployer.deploy(AbstractSynapseArtifactDeployer.java:194)
at org.wso2.carbon.application.deployer.synapse.SynapseAppDeployer.deployArtifacts(SynapseAppDeployer.java:131)
at org.wso2.carbon.application.deployer.internal.ApplicationManager.deployCarbonApp(ApplicationManager.java:272)
at org.wso2.carbon.application.deployer.CappAxis2Deployer.deploy(CappAxis2Deployer.java:72)
at org.apache.axis2.deployment.repository.util.DeploymentFileData.deploy(DeploymentFileData.java:136)
at org.apache.axis2.deployment.DeploymentEngine.doDeploy(DeploymentEngine.java:807)
at org.apache.axis2.deployment.repository.util.WSInfoList.update(WSInfoList.java:144)
at org.apache.axis2.deployment.RepositoryListener.update(RepositoryListener.java:377)
at org.apache.axis2.deployment.RepositoryListener.checkServices(RepositoryListener.java:254)
at org.apache.axis2.deployment.RepositoryListener.startListener(RepositoryListener.java:371)
at org.apache.axis2.deployment.scheduler.SchedulerTask.checkRepository(SchedulerTask.java:59)
at org.apache.axis2.deployment.scheduler.SchedulerTask.run(SchedulerTask.java:67)
at org.wso2.carbon.core.deployment.CarbonDeploymentSchedulerTask.runAxisDeployment(CarbonDeploymentSchedulerTask.java:93)
at org.wso2.carbon.core.deployment.CarbonDeploymentSchedulerTask.run(CarbonDeploymentSchedulerTask.java:138)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:180)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Caused by: org.apache.synapse.SynapseException: URL context: /country is already registered with the API: CommoditiesInACountry
at org.apache.synapse.config.SynapseConfiguration.handleException(SynapseConfiguration.java:1629)
at org.apache.synapse.config.SynapseConfiguration.addAPI(SynapseConfiguration.java:407)
at org.apache.synapse.deployers.APIDeployer.deploySynapseArtifact(APIDeployer.java:59)
... 22 more
TID: [-1234] [] [2017-12-01 15:37:31,576] INFO {org.apache.synapse.deployers.AbstractSynapseArtifactDeployer} - The file has been backed up into : NO_BACKUP_ON_WORKER.INFO {org.apache.synapse.deployers.AbstractSynapseArtifactDeployer}
TID: [-1234] [] [2017-12-01 15:37:31,576] ERROR {org.apache.synapse.deployers.AbstractSynapseArtifactDeployer} - Deployment of synapse artifact failed. Error reading /opt/wso2/wso2ei-6.1.1/wso2/tmp/carbonapps/-1234/1512139051333agrimarketprice-cap_1.0.0.car/CommodityInLocationMarkets_1.0.0/CommodityInLocationMarkets-1.0.0.xml : API deployment from the file : /opt/wso2/wso2ei-6.1.1/wso2/tmp/carbonapps/-1234/1512139051333agrimarketprice-cap_1.0.0.car/CommodityInLocationMarkets_1.0.0/CommodityInLocationMarkets-1.0.0.xml : Failed. {org.apache.synapse.deployers.AbstractSynapseArtifactDeployer}
org.apache.axis2.deployment.DeploymentException: API deployment from the file : /opt/wso2/wso2ei-6.1.1/wso2/tmp/carbonapps/-1234/1512139051333agrimarketprice-cap_1.0.0.car/CommodityInLocationMarkets_1.0.0/CommodityInLocationMarkets-1.0.0.xml : Failed.
at org.apache.synapse.deployers.AbstractSynapseArtifactDeployer.deploy(AbstractSynapseArtifactDeployer.java:201)
at org.wso2.carbon.application.deployer.synapse.SynapseAppDeployer.deployArtifacts(SynapseAppDeployer.java:131)
at org.wso2.carbon.application.deployer.internal.ApplicationManager.deployCarbonApp(ApplicationManager.java:272)
at org.wso2.carbon.application.deployer.CappAxis2Deployer.deploy(CappAxis2Deployer.java:72)
at org.apache.axis2.deployment.repository.util.DeploymentFileData.deploy(DeploymentFileData.java:136)
at org.apache.axis2.deployment.DeploymentEngine.doDeploy(DeploymentEngine.java:807)
at org.apache.axis2.deployment.repository.util.WSInfoList.update(WSInfoList.java:144)
at org.apache.axis2.deployment.RepositoryListener.update(RepositoryListener.java:377)
at org.apache.axis2.deployment.RepositoryListener.checkServices(RepositoryListener.java:254)
at org.apache.axis2.deployment.RepositoryListener.startListener(RepositoryListener.java:371)
at org.apache.axis2.deployment.scheduler.SchedulerTask.checkRepository(SchedulerTask.java:59)
at org.apache.axis2.deployment.scheduler.SchedulerTask.run(SchedulerTask.java:67)
at org.wso2.carbon.core.deployment.CarbonDeploymentSchedulerTask.runAxisDeployment(CarbonDeploymentSchedulerTask.java:93)
at org.wso2.carbon.core.deployment.CarbonDeploymentSchedulerTask.run(CarbonDeploymentSchedulerTask.java:138)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:180)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Caused by: org.apache.synapse.deployers.SynapseArtifactDeploymentException: API deployment from the file : /opt/wso2/wso2ei-6.1.1/wso2/tmp/carbonapps/-1234/1512139051333agrimarketprice-cap_1.0.0.car/CommodityInLocationMarkets_1.0.0/CommodityInLocationMarkets-1.0.0.xml : Failed.
at org.apache.synapse.deployers.AbstractSynapseArtifactDeployer.handleSynapseArtifactDeploymentError(AbstractSynapseArtifactDeployer.java:474)
at org.apache.synapse.deployers.APIDeployer.deploySynapseArtifact(APIDeployer.java:71)
at org.wso2.carbon.rest.api.ApiDeployer.deploySynapseArtifact(ApiDeployer.java:34)
at org.apache.synapse.deployers.AbstractSynapseArtifactDeployer.deploy(AbstractSynapseArtifactDeployer.java:194)
... 20 more
Caused by: org.apache.synapse.SynapseException: URL context: /country is already registered with the API: CommoditiesInACountry
at org.apache.synapse.config.SynapseConfiguration.handleException(SynapseConfiguration.java:1629)
at org.apache.synapse.config.SynapseConfiguration.addAPI(SynapseConfiguration.java:407)
at org.apache.synapse.deployers.APIDeployer.deploySynapseArtifact(APIDeployer.java:59)
... 22 more
TID: [-1234] [] [2017-12-01 15:37:31,577] ERROR {org.wso2.carbon.application.deployer.internal.ApplicationManager} - Error occurred while deploying Carbon Application {org.wso2.carbon.application.deployer.internal.ApplicationManager}
org.apache.axis2.deployment.DeploymentException: API deployment from the file : /opt/wso2/wso2ei-6.1.1/wso2/tmp/carbonapps/-1234/1512139051333agrimarketprice-cap_1.0.0.car/CommodityInLocationMarkets_1.0.0/CommodityInLocationMarkets-1.0.0.xml : Failed.
at org.apache.synapse.deployers.AbstractSynapseArtifactDeployer.deploy(AbstractSynapseArtifactDeployer.java:213)
at org.wso2.carbon.application.deployer.synapse.SynapseAppDeployer.deployArtifacts(SynapseAppDeployer.java:131)
at org.wso2.carbon.application.deployer.internal.ApplicationManager.deployCarbonApp(ApplicationManager.java:272)
at org.wso2.carbon.application.deployer.CappAxis2Deployer.deploy(CappAxis2Deployer.java:72)
at org.apache.axis2.deployment.repository.util.DeploymentFileData.deploy(DeploymentFileData.java:136)
at org.apache.axis2.deployment.DeploymentEngine.doDeploy(DeploymentEngine.java:807)
at org.apache.axis2.deployment.repository.util.WSInfoList.update(WSInfoList.java:144)
at org.apache.axis2.deployment.RepositoryListener.update(RepositoryListener.java:377)
at org.apache.axis2.deployment.RepositoryListener.checkServices(RepositoryListener.java:254)
at org.apache.axis2.deployment.RepositoryListener.startListener(RepositoryListener.java:371)
at org.apache.axis2.deployment.scheduler.SchedulerTask.checkRepository(SchedulerTask.java:59)
at org.apache.axis2.deployment.scheduler.SchedulerTask.run(SchedulerTask.java:67)
at org.wso2.carbon.core.deployment.CarbonDeploymentSchedulerTask.runAxisDeployment(CarbonDeploymentSchedulerTask.java:93)
at org.wso2.carbon.core.deployment.CarbonDeploymentSchedulerTask.run(CarbonDeploymentSchedulerTask.java:138)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:180)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Caused by: org.apache.axis2.deployment.DeploymentException: API deployment from the file : /opt/wso2/wso2ei-6.1.1/wso2/tmp/carbonapps/-1234/1512139051333agrimarketprice-cap_1.0.0.car/CommodityInLocationMarkets_1.0.0/CommodityInLocationMarkets-1.0.0.xml : Failed.
at org.apache.synapse.deployers.AbstractSynapseArtifactDeployer.deploy(AbstractSynapseArtifactDeployer.java:201)
... 20 more
Caused by: org.apache.synapse.deployers.SynapseArtifactDeploymentException: API deployment from the file : /opt/wso2/wso2ei-6.1.1/wso2/tmp/carbonapps/-1234/1512139051333agrimarketprice-cap_1.0.0.car/CommodityInLocationMarkets_1.0.0/CommodityInLocationMarkets-1.0.0.xml : Failed.
at org.apache.synapse.deployers.AbstractSynapseArtifactDeployer.handleSynapseArtifactDeploymentError(AbstractSynapseArtifactDeployer.java:474)
at org.apache.synapse.deployers.APIDeployer.deploySynapseArtifact(APIDeployer.java:71)
at org.wso2.carbon.rest.api.ApiDeployer.deploySynapseArtifact(ApiDeployer.java:34)
at org.apache.synapse.deployers.AbstractSynapseArtifactDeployer.deploy(AbstractSynapseArtifactDeployer.java:194)
... 20 more
Caused by: org.apache.synapse.SynapseException: URL context: /country is already registered with the API: CommoditiesInACountry
at org.apache.synapse.config.SynapseConfiguration.handleException(SynapseConfiguration.java:1629)
at org.apache.synapse.config.SynapseConfiguration.addAPI(SynapseConfiguration.java:407)
at org.apache.synapse.deployers.APIDeployer.deploySynapseArtifact(APIDeployer.java:59)
更改2个API上下文值中的一个,它在我的Carbon服务器上正确部署。
我的问题是,我需要这两个API的URL以... / country开头,由上下文值定义。
WSO2 ESB如何不允许为两个API提供相同的上下文?如何创建两个具有以下URL的不同API:XXX.YYY.ZZZ.RRR / country / ...
是否可以使用WSO2 ESB?
一个可能的解决方案(纠正我,如果它是错误的)可能有两个不同的我的API,然后将其映射到WSO2 API MANAGER,在这里定义最终用户消耗的最终URL。
什么可以解决方案?
ESB / APIM不允许创建具有相同上下文的2个API。但是,您可以使用一个API并拥有多个这样的资源。
<?xml version="1.0" encoding="UTF-8"?>
<api context="/country" name="CommoditiesInACountry" xmlns="http://ws.apache.org/ns/synapse">
<resource methods="GET" uri-template="/{localizationId}/commodities">
................................
................................
</resource>
<resource methods="GET" uri-template="/{localizationId}/commodity/{commodityId}">
................................
................................
</resource>
</api>
在相关的说明:要遵守REST标准,您的第二个资源应该是/{localizationId}/commodities/{commodityId}