Search in sources :

Example 1 with IStorage

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);
}
Also used : ApiGatewayBean(io.apiman.manager.api.beans.apis.ApiGatewayBean) Element(org.w3c.dom.Element) NodeList(org.w3c.dom.NodeList) ApiGatewayBean(io.apiman.manager.api.beans.apis.ApiGatewayBean) GatewayBean(io.apiman.manager.api.beans.gateways.GatewayBean) IStorage(io.apiman.manager.api.core.IStorage) Document(org.w3c.dom.Document) ApiVersionBean(io.apiman.manager.api.beans.apis.ApiVersionBean) LinkedList(java.util.LinkedList) IGatewayLink(io.apiman.manager.api.gateway.IGatewayLink)

Aggregations

ApiGatewayBean (io.apiman.manager.api.beans.apis.ApiGatewayBean)1 ApiVersionBean (io.apiman.manager.api.beans.apis.ApiVersionBean)1 GatewayBean (io.apiman.manager.api.beans.gateways.GatewayBean)1 IStorage (io.apiman.manager.api.core.IStorage)1 IGatewayLink (io.apiman.manager.api.gateway.IGatewayLink)1 LinkedList (java.util.LinkedList)1 Document (org.w3c.dom.Document)1 Element (org.w3c.dom.Element)1 NodeList (org.w3c.dom.NodeList)1