Skip to content

Commit fa36eed

Browse files
author
Chris Wiechmann
committed
Merge branch 'develop' into test-with-7.7-20200130
2 parents aff187b + 15ecb6b commit fa36eed

7 files changed

Lines changed: 67 additions & 25 deletions

File tree

CHANGELOG.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,16 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
99
- Feature to use a YAML based API-Definition for Swagger & OpenAPI (API-Manager 7.7 only)
1010
- API Backend-Server information in wide and ultra view console get view
1111
- Option to filter API having a specificied backendBasepath
12-
- Show API detail information if only 1 API is found (See issue [#11](https://github.com/Axway-API-Management-Plus/apim-cli/issues/11))
13-
- Feature to load the API-Definition from FE-API (See issue [#4](https://github.com/Axway-API-Management-Plus/apim-cli/issues/4))
14-
- Feature to export APIs as a CSV-File
12+
- Show detailed API information if only 1 API is returned (See issue [#11](https://github.com/Axway-API-Management-Plus/apim-cli/issues/11))
13+
- Feature to load the API-Definition from the FE-API (See issue [#4](https://github.com/Axway-API-Management-Plus/apim-cli/issues/4))
14+
- Feature to export APIs as a CSV-File incl. used polices and subscribed applications
1515
- CLI usage information for all operations improved
1616

1717
### Changed
1818
- API Console ultra view not longer renders API-Tags in detail. Only indicated with True & False
19-
- renamed parameter -l / --localFolder TO -t / --target
20-
- renamed parameter -df / --deleteFolder TO -deleteTarget
21-
- renamed parameter -f / --format TO -o --output
19+
- renamed parameter `-l / --localFolder` TO `-t / --target`
20+
- renamed parameter `-df / --deleteFolder` TO `-deleteTarget`
21+
- renamed parameter `-f / --format` TO `-o --output`
2222

2323
### Fixed
2424
- Wrong info text during deletion of an unpublished API proxy (See issue [#25](https://github.com/Axway-API-Management-Plus/apim-cli/issues/25))

modules/apim-adapter/src/main/java/com/axway/apim/adapter/APIManagerAdapter.java

Lines changed: 39 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
import com.axway.apim.lib.errorHandling.ErrorState;
5555
import com.axway.apim.lib.utils.TestIndicator;
5656
import com.axway.apim.lib.utils.rest.APIMHttpClient;
57+
import com.axway.apim.lib.utils.rest.DELRequest;
5758
import com.axway.apim.lib.utils.rest.GETRequest;
5859
import com.axway.apim.lib.utils.rest.POSTRequest;
5960
import com.axway.apim.lib.utils.rest.RestAPICall;
@@ -143,7 +144,11 @@ public static synchronized void deleteInstance() throws AppException {
143144
APIManagerAdapter.cacheManager.close();
144145
LOG.debug("Closing cache end");
145146
}
146-
APIManagerAdapter.instance = null;
147+
if(APIManagerAdapter.instance!=null) {
148+
APIManagerAdapter.instance.logoutFromAPIManager(false); // Logout potentially logged in OrgAdmin
149+
APIManagerAdapter.instance.logoutFromAPIManager(true); // Logout potentially logged in Admin
150+
APIManagerAdapter.instance = null;
151+
}
147152
}
148153

149154
private APIManagerAdapter() throws AppException {
@@ -197,19 +202,17 @@ public void loginToAPIManager(boolean useAdminClient) throws AppException {
197202
loginRequest.setContentType(null);
198203
httpResponse = loginRequest.execute();
199204
int statusCode = httpResponse.getStatusLine().getStatusCode();
200-
if(statusCode < 200 || statusCode > 299){
205+
if(statusCode != 303){
201206
String response = EntityUtils.toString(httpResponse.getEntity());
202-
if(statusCode==403 && response.contains("Unknown API")) {
203-
LOG.warn("Login failed with statusCode: " +statusCode+ ". Got response: '"+response+"' ... Try again in 1 second.");
204-
Thread.sleep(1000);
205-
httpResponse = loginRequest.execute();
206-
statusCode = httpResponse.getStatusLine().getStatusCode();
207-
if(statusCode < 200 || statusCode > 299){
208-
LOG.error("Login finally failed with statusCode: " +statusCode+ ". Got response: '"+response+"' Got response: '"+response+"'");
209-
throw new AppException("Login finally failed with statusCode: " +statusCode, ErrorCode.API_MANAGER_COMMUNICATION);
210-
} else {
211-
LOG.info("Successfully logged in on retry. Received Status-Code: " +statusCode );
212-
}
207+
LOG.warn("Login failed with statusCode: " +statusCode+ ". Got response: '"+response+"' ... Try again in 1 second.");
208+
Thread.sleep(1000);
209+
httpResponse = loginRequest.execute();
210+
statusCode = httpResponse.getStatusLine().getStatusCode();
211+
if(statusCode != 303){
212+
LOG.error("Login finally failed with statusCode: " +statusCode+ ". Got response: '"+response+"' Got response: '"+response+"'");
213+
throw new AppException("Login finally failed with statusCode: " +statusCode, ErrorCode.API_MANAGER_COMMUNICATION);
214+
} else {
215+
LOG.info("Successfully logged in on retry. Received Status-Code: " +statusCode );
213216
}
214217
}
215218

@@ -234,6 +237,29 @@ public void loginToAPIManager(boolean useAdminClient) throws AppException {
234237
}
235238
}
236239

240+
public void logoutFromAPIManager(boolean useAdminClient) throws AppException {
241+
if(useAdminClient && !hasAdminAccount()) return;
242+
URI uri;
243+
HttpResponse httpResponse = null;
244+
try {
245+
uri = new URIBuilder(cmd.getAPIManagerURL()).setPath(RestAPICall.API_VERSION+"/login").build();
246+
DELRequest logoutRequest = new DELRequest(uri, useAdminClient);
247+
httpResponse = logoutRequest.execute();
248+
int statusCode = httpResponse.getStatusLine().getStatusCode();
249+
if(statusCode != 204){
250+
String response = EntityUtils.toString(httpResponse.getEntity());
251+
LOG.warn("Logout failed with statusCode: " +statusCode+ ". Got response: '"+response+"'");
252+
}
253+
} catch (Exception e) {
254+
throw new AppException("Can't logout from API-Manager", ErrorCode.API_MANAGER_COMMUNICATION, e);
255+
} finally {
256+
try {
257+
if(httpResponse!=null)
258+
((CloseableHttpResponse)httpResponse).close();
259+
} catch (Exception ignore) {}
260+
}
261+
}
262+
237263
private String[] getAdminUsernamePassword() throws AppException {
238264
if(CommandParameters.getInstance().getAdminUsername()==null) return null;
239265
String[] usernamePassword = {CommandParameters.getInstance().getAdminUsername(), CommandParameters.getInstance().getAdminPassword()};

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,9 @@ public APIAccess createAPIAccess(APIAccess apiAccess, String parentId, Type type
196196
} else {
197197
LOG.info("Successfully created API-Access on retry. Received Status-Code: " +statusCode );
198198
}
199+
} else if(statusCode==409 && response.contains("resource already exists")) {
200+
LOG.warn("Unexpected response while creating/updating API Access: "+apiAccess+". Response-Code: "+statusCode+". Got response: '"+response+"'. Ignoring this error.");
201+
return apiAccess;
199202
} else {
200203
LOG.error("Error creating/updating API Access: "+apiAccess+". Response-Code: "+statusCode+". Got response: '"+response+"'");
201204
throw new AppException("Error creating/updating API Access. Response-Code: "+statusCode+"", ErrorCode.API_MANAGER_COMMUNICATION);

modules/apim-adapter/src/main/java/com/axway/apim/lib/utils/rest/APIMHttpClient.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,4 +132,9 @@ public String getCsrfToken() {
132132
public void setCsrfToken(String csrfToken) {
133133
this.csrfToken = csrfToken;
134134
}
135+
136+
@Override
137+
public String toString() {
138+
return "APIMHttpClient [cookieStore=" + cookieStore + ", csrfToken=" + csrfToken + "]";
139+
}
135140
}

modules/apim-adapter/src/main/java/com/axway/apim/lib/utils/rest/RestAPICall.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ public abstract class RestAPICall {
3333

3434
protected HttpHost target;
3535

36+
protected boolean logHTTPClientInfo = false;
37+
3638
protected String contentType = "application/json";
3739

3840
protected boolean useAdmin = false;
@@ -55,9 +57,12 @@ public RestAPICall(HttpEntity entity, URI uri) {
5557
protected HttpResponse sendRequest(HttpUriRequest request) throws AppException {
5658
try {
5759
APIMHttpClient apimClient = APIMHttpClient.getInstance(this.useAdmin);
60+
if(logHTTPClientInfo) {
61+
LOG.info("Using APIM-Manager Client: " + apimClient.toString() + " ");
62+
LOG.info("Send request: "+this.getClass().getSimpleName()+" using admin-account: " + this.useAdmin + " to: " + request.getURI());
63+
}
5864
if(apimClient.getCsrfToken()!=null) request.addHeader("CSRF-Token", apimClient.getCsrfToken());
5965
HttpResponse response = apimClient.getHttpClient().execute(request, apimClient.getClientContext());
60-
//LOG.info("Send request: "+this.getClass().getSimpleName()+" using admin-account: " + this.useAdmin + " to: " + request.getURI());
6166
return response;
6267
} catch (ClientProtocolException e) {
6368
throw new AppException("Unable to send HTTP-Request.", ErrorCode.CANT_SEND_HTTP_REQUEST, e);
@@ -70,4 +75,11 @@ public void setContentType(String contentType) {
7075
this.contentType = contentType;
7176
}
7277

78+
public boolean isLogHTTPClientInfo() {
79+
return logHTTPClientInfo;
80+
}
81+
82+
public void setLogHTTPClientInfo(boolean logHTTPClientInfo) {
83+
this.logHTTPClientInfo = logHTTPClientInfo;
84+
}
7385
}

modules/app-export/src/main/java/com/axway/apim/appexport/impl/JsonApplicationExporter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public void export(List<ClientApplication> apps) throws AppException {
4040

4141
private void saveApplicationLocally(ExportApplication app) throws AppException {
4242
String folderName = getExportFolder(app);
43-
String targetFolder = params.getLocalFolder();
43+
String targetFolder = params.getTarget();
4444
File localFolder = new File(targetFolder +File.separator+ folderName);
4545
LOG.info("Going to export applications into folder: " + localFolder);
4646
if(localFolder.exists()) {

modules/app-export/src/main/java/com/axway/apim/appexport/lib/AppExportParams.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,4 @@ public String getAppId() {
3232
public String getOrgName() {
3333
return getValue("orgName");
3434
}
35-
36-
public String getLocalFolder() {
37-
return (getValue("localFolder")==null) ? "." : getValue("localFolder");
38-
}
3935
}

0 commit comments

Comments
 (0)