Axway-API-Management-Plus / apim-cli

Axway API-Management CLI - Manage your platform from the command line or with your CI/CD pipeline
Apache License 2.0
46 stars 17 forks source link

Attempt to import WSDL API definition produces HTTP error code 400 when creating front end API #308

Closed saper closed 2 years ago

saper commented 2 years ago

APIM-CLI version

1.12.4-SNAPSHOT 5d30676416873d0f28ba4656c5bc9020542888c9

API-Management version

7.7.20211130

Bug description

Trying to import WSDL API from https://almdemo.polarion.com/polarion/ws/services/SessionWebService?wsdl

A copy of WSDL is stored on a local HTTP server due to firewall restrictions.

Judging from CLI logs, backend API is created fine, but frontend API cannot be created.

It works if trying to import this WSDL from the API manager GUI.

Steps to reproduce

api-config.json:

{
  "name" : "almdemo Polarion Session",
  "path" : "/engineering/system/almdemo-polarion/sandbox/v3/SessionWebService",
  "state" : "unpublished",
  "organization" : "MY-ORG",
  "apiSpecification" : {
    "resource" : "http://localcopy.contoso.net:8000/SessionWebService%3Fwsdl"
  },
  "backendBasepath" : "https://almdemo.polarion.com",
  "customProperties" : {
    "visibility" : "org"
  },
  "securityProfiles" : [ {
    "name" : "_default",
    "isDefault" : true,
    "devices" : [ {
      "name" : "API Key",
      "type" : "apiKey",
      "order" : 1,
      "properties" : {
        "apiKeyFieldName" : "KeyId",
        "takeFrom" : "HEADER",
        "removeCredentialsOnSuccess" : "true"
      }
    } ]
  } ]
}

Command:

     apim api import -s my-profile -c api-config.json

Relevant log output

----------------------------------------------------------------------------------------
API-Manager CLI: 1.12.4-SNAPSHOT

To report issues or get help, please visit:
https://github.com/Axway-API-Management-Plus/apim-cli
----------------------------------------------------------------------------------------
Module: API - I M P O R T (1.12.4-SNAPSHOT)
----------------------------------------------------------------------------------------
594    DEBUG nvironmentProperties| Trying to load environment properties from file: /home/user/sw/apim-cli-1.12.4-SNAPSHOT/conf/env.properties ... not found.
600    DEBUG nvironmentProperties| Loaded environment properties from file: /home/user/sw/apim-cli-1.12.4-SNAPSHOT/conf/env.ews-bcn.properties
734    DEBUG    APIManagerAdapter| Logging in with User: 'user@contoso.com_1'
1401   DEBUG ManagerConfigAdapter| Load API-Manager configuration.
1484   INFO     APIManagerAdapter| Successfully connected to API-Manager (7.7.20211130) on: https://api-manager-gateway.contoso.net:8075
1591   WARN  rOrganizationAdapter| Using OrgAdmin only to load all organizations.
1592   DEBUG rOrganizationAdapter| Load organizations from API-Manager using filter: OrgFilter [name=null, id=096df03c-ca15-429b-a66b-b37ac157a1f4]
1674   DEBUG SpecificationFactory| Handle API-Specification: '<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions targetNamespace="http://ws.polarion.com/SessionWebService" xmlns:apachesoap="http://xml.apache.org/xml-soap" xmlns:impl="http://ws.polarion.com......', apiDefinitionFile: 'http://localcopy.contoso.net:8000/SessionWebService%3Fwsdl'
1696   DEBUG SpecificationFactory| Can't handle API specification with class: com.axway.apim.api.apiSpecification.Swagger2xSpecification
1697   DEBUG SpecificationFactory| Can't handle API specification with class: com.axway.apim.api.apiSpecification.Swagger1xSpecification
1698   DEBUG SpecificationFactory| Can't handle API specification with class: com.axway.apim.api.apiSpecification.OAS3xSpecification
1699   INFO  SpecificationFactory| Detected: WSDL specification.
1701   DEBUG tomPropertiesAdapter| Read configured custom properties from API-Manager
1771   INFO          APIImportApp| Lookup actual API based on Path: /engineering/system/almdemo-polarion/sandbox/v3/SessionWebService
1782   DEBUG APIManagerAPIAdapter| Sending request to find existing APIs: https://api-manager-gateway.contoso.net:8075/api/portal/v1.4/proxies?field=path&op=eq&value=%2Fengineering%2Fsystem%2Falmdemo-polarion%2Fsandbox%2Fv3%2FSessionWebService&field=state&op=ne&value=published
1919   DEBUG APIManagerAPIAdapter| No existing API found based on filter: [apiPath=/engineering/system/almdemo-polarion/sandbox/v3/SessionWebService]
1921   DEBUG       APIChangeState| No existing API found. Creating  complete new API
1923   INFO      APIImportManager| No existing API found, creating new!
1924   DEBUG APIManagerAPIAdapter| Import backend API: almdemo Polarion Session based on WSDL specification.
2131   INFO          CreateNewAPI| Create unpublished API: 'almdemo Polarion Session' null based on WSDL specification.
2132   DEBUG APIManagerAPIAdapter| Create Front-End API: 'almdemo Polarion Session' (API-Proxy)
2234   DEBUG agerAPIMethodAdapter| Load API-Methods for API: 017bb4c6-37ac-489e-bf1a-9a2604755fc5 from API-Manager.
2281   DEBUG         CreateNewAPI| Number of Methods : 7
2286   DEBUG APIManagerAPIAdapter| Updating API-Proxy: 'almdemo Polarion Session  (017bb4c6-37ac-489e-bf1a-9a2604755fc5)'
2286   DEBUG APIManagerAPIAdapter| **API** : com.axway.apim.api.API
2354   ERROR APIManagerAPIAdapter| Error updating API-Proxy. Response-Code: 400. Got response: '{"errors":[{"code":400,"message":"Invalid JSON format"}]}'
2355   DEBUG APIManagerAPIAdapter| Request sent:{"caCerts":[],"descriptionType":"original","securityProfiles":[{"name":"_default","isDefault":true,"devices":[{"name":"API Key","type":"apiKey","order":1,"properties":{"apiKeyFieldName":"KeyId","takeFrom":"HEADER","removeCredentialsOnSuccess":"true"}}]}],"authenticationProfiles":[{"name":"_default","isDefault":true,"parameters":{"_id_":0},"type":"none"}],"tags":{},"outboundProfiles":{"_default":{"routeType":"proxy","authenticationProfile":"_default"}},"serviceProfiles":{"_default":{"basePath":"https://almdemo.polarion.com"}},"inboundProfiles":{"_default":{"monitorAPI":true,"queryStringPassThrough":false,"monitorSubject":"authentication.subject.id","securityProfile":"_default","corsProfile":"_default"}},"corsProfiles":[{"name":"_default","isDefault":true,"origins":["*"],"allowedHeaders":[],"exposedHeaders":["X-CorrelationID"],"supportCredentials":false,"maxAgeSeconds":"0"}],"path":"/engineering/system/almdemo-polarion/sandbox/v3/SessionWebService","state":"unpublished","version":"","name":"almdemo Polarion Session","summary":"","createdOn":1661904734878,"createdBy":"c66bc818-2f6a-47d9-93d7-a417b775851a","customProperties":{"visibility":"org"},"id":"017bb4c6-37ac-489e-bf1a-9a2604755fc5","apiId":"40ca986e-cdc4-4ef7-b49f-2675fcd90bd7","deprecated":"false","retirementDate":0,"organizationId":"096df03c-ca15-429b-a66b-b37ac157a1f4"}
2357   INFO      RollbackAPIProxy| Rollback FE-API: 'almdemo Polarion Session' (ID: '017bb4c6-37ac-489e-bf1a-9a2604755fc5' / State: 'unpublished')
2357   DEBUG APIManagerAPIAdapter| Sending request to find existing APIs: https://api-manager-gateway.contoso.net:8075/api/portal/v1.4/proxies/017bb4c6-37ac-489e-bf1a-9a2604755fc5
2389   DEBUG APIManagerAPIAdapter| Found: 1 exposed API(s)
2390   DEBUG     APIStatusManager| Desired and actual status equal. No need to update status!
2390   DEBUG APIManagerAPIAdapter| Deleting API-Proxy
2466   INFO  APIManagerAPIAdapter| API: almdemo Polarion Session null (017bb4c6-37ac-489e-bf1a-9a2604755fc5) successfully deleted
2466   DEBUG APIManagerAPIAdapter| Deleting API-Proxy
2513   DEBUG APIManagerAPIAdapter| Sending request to find existing APIs: https://api-manager-gateway.contoso.net:8075/api/portal/v1.4/apirepo?field=name&op=eq&value=almdemo+Polarion+Session&field=createdOn&op=gt&value=1661904733736
2790   DEBUG APIManagerAPIAdapter| No existing API found based on filter: []
2791   INFO       RollbackHandler| Rolled back: '[Frontend-API: false, Backend-API: true]'
2792   ERROR         AppException| Cannot update API-Proxy.
                                 | Error updating API-Proxy. Response-Code: 400
com.axway.apim.lib.errorHandling.AppException: Cannot update API-Proxy.
        at com.axway.apim.adapter.apis.APIManagerAPIAdapter.updateAPIProxy(APIManagerAPIAdapter.java:646) ~[apimcli-apim-adapter-1.12.4-SNAPSHOT.jar:1.12.4-SNAPSHOT]
        at com.axway.apim.apiimport.actions.CreateNewAPI.execute(CreateNewAPI.java:66) ~[apimcli-apis-1.12.4-SNAPSHOT.jar:1.12.4-SNAPSHOT]
        at com.axway.apim.apiimport.APIImportManager.applyChanges(APIImportManager.java:49) ~[apimcli-apis-1.12.4-SNAPSHOT.jar:1.12.4-SNAPSHOT]
        at com.axway.apim.APIImportApp.importAPI(APIImportApp.java:100) ~[apimcli-apis-1.12.4-SNAPSHOT.jar:1.12.4-SNAPSHOT]
        at com.axway.apim.APIImportApp.importAPI(APIImportApp.java:58) ~[apimcli-apis-1.12.4-SNAPSHOT.jar:1.12.4-SNAPSHOT]
        at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:?]
        at jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:?]
        at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?]
        at java.lang.reflect.Method.invoke(Method.java:566) ~[?:?]
        at com.axway.apim.cli.APIManagerCLI.run(APIManagerCLI.java:141) ~[apimcli-tool-1.12.4-SNAPSHOT.jar:1.12.4-SNAPSHOT]
        at com.axway.apim.cli.APIManagerCLI.main(APIManagerCLI.java:77) ~[apimcli-tool-1.12.4-SNAPSHOT.jar:1.12.4-SNAPSHOT]
Caused by: com.axway.apim.lib.errorHandling.AppException: Error updating API-Proxy. Response-Code: 400
        at com.axway.apim.adapter.apis.APIManagerAPIAdapter.updateAPIProxy(APIManagerAPIAdapter.java:642) ~[apimcli-apim-adapter-1.12.4-SNAPSHOT.jar:1.12.4-SNAPSHOT]
        ... 10 more
2798   DEBUG    APIManagerAdapter| Closing cache ...
rathnapandi commented 2 years ago

Hi @saper,

My changes were breaking API import on version Feb 2022 and below. I have rolled back the changes and tested it, it is working now.

Please test and let me know if you see any issues.

saper commented 2 years ago

Thank you, this is fixed as of 7c87e7331be48d40e7c48871a8312393285e8a4c

Nitpick: I have noticed that https://github.com/Axway-API-Management-Plus/apim-cli/compare/5d306764...develop introduced some strange while space changes (some tabs, CR LF at the end) that are not visible on Github - just with git diff 7c87e733..5d306764 if you care.