/**
   * Clear the actual service Endpoint and use Gateway Endpoint instead of the actual Endpoint.
   *
   * @param definition - {@link Definition} - WSDL4j wsdl definition
   * @throws APIManagementException
   */
  private void setServiceDefinition(Definition definition) throws APIManagementException {

    Map serviceMap = definition.getAllServices();
    Iterator serviceItr = serviceMap.entrySet().iterator();
    URL addressURI = null;
    try {
      while (serviceItr.hasNext()) {
        Map.Entry svcEntry = (Map.Entry) serviceItr.next();
        Service svc = (Service) svcEntry.getValue();
        Map portMap = svc.getPorts();
        Iterator portItr = portMap.entrySet().iterator();
        while (portItr.hasNext()) {
          Map.Entry portEntry = (Map.Entry) portItr.next();
          Port port = (Port) portEntry.getValue();

          List<ExtensibilityElement> extensibilityElementList = port.getExtensibilityElements();
          for (int i = 0; i < extensibilityElementList.size(); i++) {

            ExtensibilityElement extensibilityElement =
                (ExtensibilityElement) port.getExtensibilityElements().get(i);

            addressURI = new URL(getAddressUrl(extensibilityElement));
            if (addressURI == null) {
              break;
            } else {
              setAddressUrl(extensibilityElement);
            }
          }
        }
      }
    } catch (Exception e) {
      log.error("Error occured while getting the wsdl address location", e);
      throw new APIManagementException(e);
    }
  }
Beispiel #2
0
  @SuppressWarnings("unchecked")
  private BindingTuple findBinding(WsdlContext newContext) throws Exception {
    BindingTuple tuple = new BindingTuple();
    tuple.context = newContext;

    // start by finding the old binding in the new definition
    Definition definition = newContext.getDefinition();
    Map serviceMap = definition.getAllServices();
    Iterator<String> i = serviceMap.keySet().iterator();
    while (i.hasNext()) {
      tuple.service = (Service) serviceMap.get(i.next());
      Map portMap = tuple.service.getPorts();

      Iterator i2 = portMap.keySet().iterator();
      while (i2.hasNext()) {
        tuple.port = (Port) portMap.get(i2.next());
        if (tuple.port.getBinding().getQName().equals(getBindingName())) {
          tuple.binding = tuple.port.getBinding();
        }
      }

      if (tuple.binding != null) break;
      tuple.service = null;
    }

    if (tuple.service == null && tuple.binding == null) {
      tuple.binding = definition.getBinding(getBindingName());
    }

    // missing matching binding, prompt for new one to use instead (will
    // happen if binding has been renamed)
    if (tuple.binding == null) {
      Map bindings = definition.getAllBindings();

      Object retval =
          UISupport.prompt(
              "Missing matching binding ["
                  + getBindingName()
                  + "] in definition, select new\nbinding to map to",
              "Map Binding",
              bindings.keySet().toArray());

      if (retval == null) return null;

      tuple.binding = (Binding) bindings.get(retval);
    }

    return tuple;
  }
  protected void updatePublishedEndpointUrl(String publishingUrl, Definition def, QName name) {
    Collection<Service> services = CastUtils.cast(def.getAllServices().values());
    for (Service service : services) {
      Collection<Port> ports = CastUtils.cast(service.getPorts().values());
      if (ports.isEmpty()) {
        continue;
      }

      if (name == null) {
        setSoapAddressLocationOn(ports.iterator().next(), publishingUrl);
        break; // only update the first port since we don't target any specific port
      } else {
        for (Port port : ports) {
          if (name.getLocalPart().equals(port.getName())) {
            setSoapAddressLocationOn(port, publishingUrl);
          }
        }
      }
    }
  }
Beispiel #4
0
  private void updateWsaPolicy(String url, WsdlContext newContext) throws Exception {

    Definition definition = newContext.getDefinition();
    policyFlag = false;
    processPolicy(PolicyUtils.getAttachedPolicy(getBinding(), definition));
    Map<?, ?> serviceMap = definition.getAllServices();
    if (serviceMap.isEmpty()) log.info("Missing services in [" + url + "], check for bindings");
    else {
      Iterator<?> i = serviceMap.values().iterator();
      while (i.hasNext()) {
        Service service = (Service) i.next();
        Map<?, ?> portMap = service.getPorts();
        Iterator<?> i2 = portMap.values().iterator();
        while (i2.hasNext()) {
          Port port = (Port) i2.next();
          processPolicy(PolicyUtils.getAttachedPolicy(port, definition));
        }
      }
    }
  }
  public void testCompare() throws WSDLException, ComparisonException {

    Comparator<Definition> comparator = new WSDLDeclarationComparator();
    Definition originalWSDL = WSDLTestUtils.getWSDLDefinition();
    Definition changedWSDL = WSDLTestUtils.getWSDLDefinitionWithDetails();

    //        originalWSDL.setExtensionAttribute();

    //        originalWSDL.setTypes();

    //      originalWSDL.addBinding();
    //      originalWSDL.addImport();
    //        originalWSDL.addMessage();
    //        originalWSDL.addBinding();
    //        originalWSDL.addPortType();
    //        originalWSDL.addService();
    //        originalWSDL.addExtensibilityElement();

    originalWSDL.getAllBindings();
    originalWSDL.getAllPortTypes();
    originalWSDL.getAllServices();
    originalWSDL.getDocumentBaseURI();
    originalWSDL.getImports();
    originalWSDL.getMessages();
    originalWSDL.getNamespaces();
    originalWSDL.getPortTypes();
    originalWSDL.getQName();
    originalWSDL.getTargetNamespace();
    originalWSDL.getTypes();
    originalWSDL.getDocumentationElement();
    originalWSDL.getExtensibilityElements();
    // TODO Fix me
    originalWSDL.getExtensionAttributes();

    Comparison defaultComparison = new DefaultComparison();
    comparator.compare(originalWSDL, changedWSDL, defaultComparison);
    System.out.println(defaultComparison);
    assertNotNull(defaultComparison);
  }