|
1 | 1 | package com.axway.apim.adapter; |
2 | 2 |
|
| 3 | +import java.io.File; |
3 | 4 | import java.io.InputStream; |
4 | 5 | import java.net.URI; |
5 | 6 | import java.net.URL; |
@@ -542,21 +543,26 @@ public static String getApiManagerName() throws AppException { |
542 | 543 | return APIManagerAdapter.apiManagerName; |
543 | 544 | } |
544 | 545 |
|
545 | | - public static JsonNode getCertInfoFromFile(InputStream certFile, CaCert cert) throws AppException { |
| 546 | + public static JsonNode getCertInfo(InputStream certificate, String password, CaCert cert) throws AppException { |
546 | 547 | URI uri; |
547 | 548 | HttpResponse httpResponse = null; |
548 | 549 | try { |
549 | 550 | uri = new URIBuilder(cmd.getAPIManagerURL()).setPath(cmd.getApiBasepath() + "/certinfo").build(); |
550 | 551 | HttpEntity entity = MultipartEntityBuilder.create() |
551 | | - .addBinaryBody("file", IOUtils.toByteArray(certFile), ContentType.create("application/x-x509-ca-cert"), cert.getCertFile()) |
| 552 | + .addBinaryBody("file", certificate, ContentType.create("application/x-x509-ca-cert"), cert.getCertFile()) |
552 | 553 | .addTextBody("inbound", cert.getInbound()) |
553 | 554 | .addTextBody("outbound", cert.getOutbound()) |
| 555 | + .addTextBody("passphrase", password) |
554 | 556 | .build(); |
555 | 557 | POSTRequest postRequest = new POSTRequest(entity, uri); |
556 | 558 | httpResponse = postRequest.execute(); |
557 | 559 | int statusCode = httpResponse.getStatusLine().getStatusCode(); |
558 | 560 | String response = EntityUtils.toString(httpResponse.getEntity()); |
559 | 561 | if( statusCode != 200){ |
| 562 | + if(response!=null && response.contains("Bad password")) { |
| 563 | + LOG.debug("API-Manager failed to read certificate information: " + cert.getCertFile() + ". Got response: '"+response+"'."); |
| 564 | + throw new AppException("Password for keystore: '" + cert.getCertFile() + "' is wrong.", ErrorCode.WRONG_KEYSTORE_PASSWORD); |
| 565 | + } |
560 | 566 | throw new AppException("API-Manager failed to read certificate information from file. Got response: '"+response+"'", ErrorCode.API_MANAGER_COMMUNICATION); |
561 | 567 | } |
562 | 568 | JsonNode jsonResponse = mapper.readTree(response); |
|
0 commit comments