use of io.apiman.manager.api.core.IStorage in project apiman by apiman.
the class WsdlRewriter method rewrite.
@Override
public String rewrite(ProviderContext ctx, InputStream wsdlStream, ApiDefinitionType apiDefinitionType) throws IOException, StorageException, GatewayAuthenticationException, Exception {
IStorage storage = ctx.getStorage();
ApiVersionBean avb = ctx.getAvb();
String orgId = avb.getApi().getOrganization().getId();
String apiId = avb.getApi().getId();
String apiVersion = avb.getVersion();
Document document = readWsdlInputStream(wsdlStream);
// Collection of all SOAP binding addresses
List<Element> allSoapAddresses = new LinkedList<>();
for (String soapNamespace : SOAP_NAMESPACES) {
NodeList soapAddresses = document.getDocumentElement().getElementsByTagNameNS(soapNamespace, SOAP_ADDRESS);
if (soapAddresses.getLength() > 0) {
for (int j = 0; j < soapAddresses.getLength(); j++) {
allSoapAddresses.add((Element) soapAddresses.item(j));
}
}
}
// Find IDs of all GWs this ApiVersion is published onto.
String firstGateway = avb.getGateways().stream().map(ApiGatewayBean::getGatewayId).findFirst().orElse("");
GatewayBean gateway = storage.getGateway(firstGateway);
IGatewayLink link = ctx.getGatewayLinkFactory().create(gateway);
// Go through the addresses we've found (if any) and update the 'location' attribute if needed.
String endpoint = link.getApiEndpoint(orgId, apiId, apiVersion).getEndpoint();
for (Element addressElem : allSoapAddresses) {
String location = addressElem.getAttribute(LOCATION);
if (!location.equals(endpoint)) {
addressElem.setAttribute(LOCATION, endpoint);
}
}
// Convert document back to string and update in storage.
return xmlDocumentToString(document);
}
Aggregations