Skip to content

Commit 519ee7f

Browse files
author
Chris Wiechmann
committed
Added support for unknown API-Specs
1 parent 57fd54e commit 519ee7f

6 files changed

Lines changed: 60 additions & 5 deletions

File tree

modules/api-export/src/main/java/com/axway/apim/api/export/impl/APIResultHandler.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,8 @@ protected Builder getBaseAPIFilterBuilder() {
9595
.includeCustomProperties(APIManagerAdapter.getAllConfiguredCustomProperties(CUSTOM_PROP_TYPE.api))
9696
.translateMethods(METHOD_TRANSLATION.AS_NAME)
9797
.translatePolicies(POLICY_TRANSLATION.TO_NAME)
98-
.useFEAPIDefinition(params.isUseFEAPIDefinition());
98+
.useFEAPIDefinition(params.isUseFEAPIDefinition())
99+
.failOnError(false);
99100
return builder;
100101
}
101102

modules/apim-adapter/src/main/java/com/axway/apim/adapter/apis/APIFilter.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ public static enum FILTER_OP {
8787

8888
private boolean useFEAPIDefinition = false;
8989

90+
private boolean failOnError = true;
91+
9092
POLICY_TRANSLATION translatePolicyMode = POLICY_TRANSLATION.NONE;
9193

9294
List<NameValuePair> filters = new ArrayList<NameValuePair>();
@@ -364,6 +366,14 @@ public void setCustomProperties(Map<String, String> customProperties) {
364366
this.customProperties = customProperties;
365367
}
366368

369+
public boolean isFailOnError() {
370+
return failOnError;
371+
}
372+
373+
public void setFailOnError(boolean failOnError) {
374+
this.failOnError = failOnError;
375+
}
376+
367377
@Override
368378
public boolean equals(Object obj) {
369379
if (obj == null) return false;
@@ -512,6 +522,8 @@ public static enum APIType {
512522

513523
boolean useFEAPIDefinition = false;
514524

525+
boolean failOnError = true;
526+
515527
POLICY_TRANSLATION translatePolicyMode = POLICY_TRANSLATION.NONE;
516528

517529
List<NameValuePair> filters = new ArrayList<NameValuePair>();
@@ -566,6 +578,7 @@ public APIFilter build() {
566578
apiFilter.setCustomProperties(this.customProperties);
567579
apiFilter.setCreatedOn(this.createdOn, this.createdOnOp);
568580
apiFilter.setBackendBasepath(this.backendBasepath);
581+
apiFilter.setFailOnError(this.failOnError);
569582
return apiFilter;
570583
}
571584

@@ -717,6 +730,11 @@ public Builder hasBackendBasepath(String backendBasepath) {
717730
this.backendBasepath = backendBasepath;
718731
return this;
719732
}
733+
734+
public Builder failOnError(boolean failOnError) {
735+
this.failOnError = failOnError;
736+
return this;
737+
}
720738
}
721739

722740
}

modules/apim-adapter/src/main/java/com/axway/apim/adapter/apis/APIManagerAPIAdapter.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ public List<API> getAPIs(APIFilter filter, boolean logProgress) throws AppExcept
129129
addCustomProperties(apis, filter);
130130
if(logProgress && apis.size()>5) System.out.print("\n");
131131
} catch (IOException e) {
132-
throw new AppException("Cant reads API from API-Manager", ErrorCode.API_MANAGER_COMMUNICATION, e);
132+
throw new AppException("Cannot read APIs from API-Manager", ErrorCode.API_MANAGER_COMMUNICATION, e);
133133
}
134134
return apis;
135135
}
@@ -485,7 +485,7 @@ private static void addOriginalAPIDefinitionFromAPIM(API api, APIFilter filter)
485485
if(httpResponse.containsHeader("Content-Disposition")) {
486486
origFilename = httpResponse.getHeaders("Content-Disposition")[0].getValue();
487487
}
488-
apiDefinition = APISpecificationFactory.getAPISpecification(res.getBytes(StandardCharsets.UTF_8), origFilename.substring(origFilename.indexOf("filename=")+9), null);
488+
apiDefinition = APISpecificationFactory.getAPISpecification(res.getBytes(StandardCharsets.UTF_8), origFilename.substring(origFilename.indexOf("filename=")+9), null, filter.isFailOnError());
489489
api.setApiDefinition(apiDefinition);
490490
} catch (Exception e) {
491491
throw new AppException("Cannot parse API-Definition for API: '" + api.getName() + "' ("+api.getVersion()+") on path: '"+api.getPath()+"'", ErrorCode.CANT_READ_API_DEFINITION_FILE, e);

modules/apim-adapter/src/main/java/com/axway/apim/api/definition/APISpecification.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ public static enum APISpecType {
2727
SWAGGGER_API_20_YAML("Swagger 2.0 (YAML)", ".yaml"),
2828
OPEN_API_30("Open API 3.0", ".json"),
2929
OPEN_API_30_YAML("Open API 3.0 (YAML)", ".yaml"),
30-
WSDL_API ("WSDL", ".xml");
30+
WSDL_API ("WSDL", ".xml"),
31+
UNKNOWN ("Unknown", ".txt");
3132

3233
String niceName;
3334
String fileExtension;

modules/apim-adapter/src/main/java/com/axway/apim/api/definition/APISpecificationFactory.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,11 @@ public class APISpecificationFactory {
2424
add(WSDLSpecification.class);
2525
}};
2626

27-
2827
public static APISpecification getAPISpecification(byte[] apiSpecificationContent, String apiDefinitionFile, String backendBasepath) throws AppException {
28+
return getAPISpecification(apiSpecificationContent, apiDefinitionFile, backendBasepath, true);
29+
}
30+
31+
public static APISpecification getAPISpecification(byte[] apiSpecificationContent, String apiDefinitionFile, String backendBasepath, boolean failOnError) throws AppException {
2932
if(LOG.isDebugEnabled()) {
3033
LOG.debug("Handle API-Specification: '" + getContentStart(apiSpecificationContent) + "...', apiDefinitionFile: '"+apiDefinitionFile+"'");
3134
}
@@ -50,6 +53,10 @@ public static APISpecification getAPISpecification(byte[] apiSpecificationConten
5053
}
5154
}
5255
}
56+
if(!failOnError) {
57+
LOG.error("Can't handle API specification: '" + getContentStart(apiSpecificationContent) + "'");
58+
return new UnknownAPISpecification(apiSpecificationContent, backendBasepath);
59+
}
5360
LOG.error("Can't handle API specification: '" + getContentStart(apiSpecificationContent) + "'");
5461
throw new AppException("Can't handle API specification. No suiteable API-Specification implementation available.", ErrorCode.UNXPECTED_ERROR);
5562
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package com.axway.apim.api.definition;
2+
3+
import com.axway.apim.lib.errorHandling.AppException;
4+
5+
public class UnknownAPISpecification extends APISpecification {
6+
7+
public UnknownAPISpecification(byte[] apiSpecificationContent, String backendBasepath) throws AppException {
8+
super(apiSpecificationContent, backendBasepath);
9+
}
10+
11+
public UnknownAPISpecification() {
12+
}
13+
14+
@Override
15+
protected void configureBasepath() throws AppException {
16+
}
17+
18+
@Override
19+
public APISpecType getAPIDefinitionType() throws AppException {
20+
return APISpecType.UNKNOWN;
21+
}
22+
23+
@Override
24+
public boolean configure() throws AppException {
25+
return false;
26+
}
27+
28+
}

0 commit comments

Comments
 (0)