public static String getEndpointURL(
     Definition wsdlDefinition,
     String serviceName,
     String portName,
     String bindingName,
     String opName) {
   Map<?, ?> services = wsdlDefinition.getServices();
   Set<?> serviceKeys = services.keySet();
   for (Iterator<?> it = serviceKeys.iterator(); it.hasNext(); ) {
     QName serviceKey = (QName) it.next();
     if (serviceName != null && serviceKey.getLocalPart().contentEquals(serviceName)) {
       Service service = (Service) services.get(serviceKey);
       Map<?, ?> ports = service.getPorts();
       Set<?> portKeys = ports.keySet();
       for (Iterator<?> it2 = portKeys.iterator(); it2.hasNext(); ) {
         String portKey = (String) it2.next();
         if (portName != null && portKey.contentEquals(portName)) {
           Port port = (Port) ports.get(portKey);
           List<?> elements = port.getExtensibilityElements();
           for (Iterator<?> it3 = elements.iterator(); it3.hasNext(); ) {
             Object element = it3.next();
             if (element instanceof SOAPAddress) {
               SOAPAddress address = (SOAPAddress) element;
               return address.getLocationURI();
             } else if (element instanceof SOAP12Address) {
               SOAP12Address address = (SOAP12Address) element;
               return address.getLocationURI();
             }
           }
         }
       }
     }
   }
   return null;
 }
 public static String[] getNSServiceNameAndMessageNameArray(
     Definition wsdlDefinition,
     String serviceName,
     String portName,
     String bindingName,
     String opName) {
   Map<?, ?> services = wsdlDefinition.getServices();
   Set<?> serviceKeys = services.keySet();
   for (Iterator<?> it = serviceKeys.iterator(); it.hasNext(); ) {
     QName serviceKey = (QName) it.next();
     if (serviceName != null && serviceKey.getLocalPart().contentEquals(serviceName)) {
       Service service = (Service) services.get(serviceKey);
       Map<?, ?> ports = service.getPorts();
       Set<?> portKeys = ports.keySet();
       for (Iterator<?> it2 = portKeys.iterator(); it2.hasNext(); ) {
         String portKey = (String) it2.next();
         if (portName != null && portKey.contentEquals(portName)) {
           Port port = (Port) ports.get(portKey);
           Binding wsdlBinding = port.getBinding();
           PortType portType = wsdlBinding.getPortType();
           String ns = portType.getQName().getNamespaceURI();
           List<?> operations = portType.getOperations();
           for (Iterator<?> it3 = operations.iterator(); it3.hasNext(); ) {
             Operation operation = (Operation) it3.next();
             if (opName != null && operation.getName().contentEquals(opName)) {
               return new String[] {ns, serviceName, portName};
             }
           }
         }
       }
     }
   }
   return null;
 }
 public static boolean isSOAP12(Definition wsdlDefinition, String serviceName, String portName) {
   Map<?, ?> services = wsdlDefinition.getServices();
   Set<?> serviceKeys = services.keySet();
   for (Iterator<?> it = serviceKeys.iterator(); it.hasNext(); ) {
     QName serviceKey = (QName) it.next();
     if (serviceName != null && serviceKey.getLocalPart().contentEquals(serviceName)) {
       Service service = (Service) services.get(serviceKey);
       Map<?, ?> ports = service.getPorts();
       Set<?> portKeys = ports.keySet();
       for (Iterator<?> it2 = portKeys.iterator(); it2.hasNext(); ) {
         String portKey = (String) it2.next();
         if (portName != null && portKey.contentEquals(portName)) {
           Port port = (Port) ports.get(portKey);
           List<?> extElements = port.getExtensibilityElements();
           for (Iterator<?> it3 = extElements.iterator(); it3.hasNext(); ) {
             ExtensibilityElement element = (ExtensibilityElement) it3.next();
             String nsURI = element.getElementType().getNamespaceURI();
             if (nsURI.contentEquals(SOAP12_NS_URI)) {
               return true;
             }
             return false;
           }
         }
       }
     }
   }
   return false;
 }
示例#4
0
  /**
   * 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);
    }
  }
示例#5
0
  private Map<QName, XNode> getBindings(Service service) {
    Map<QName, XNode> bindings = new HashMap<QName, XNode>();

    if (service.getPorts().values().size() == 0) {
      throw new ToolException(
          "Service " + service.getQName() + " does not contain any usable ports");
    }
    Collection<Port> ports = CastUtils.cast(service.getPorts().values());
    for (Port port : ports) {
      Binding binding = port.getBinding();
      bindings.put(binding.getQName(), getXNode(service, port));
      if (WSDLConstants.NS_WSDL11.equals(binding.getQName().getNamespaceURI())) {
        throw new ToolException(
            "Binding " + binding.getQName().getLocalPart() + " namespace set improperly.");
      }
    }

    return bindings;
  }
 public static String getEndpointName(Binding binding, Definition wsdlDef) {
   LOG.log(Level.FINE, "Getting endpoint name for an object reference");
   Collection<Service> services = CastUtils.cast(wsdlDef.getServices().values());
   for (Service serv : services) {
     Collection<Port> ports = CastUtils.cast(serv.getPorts().values());
     for (Port pt : ports) {
       if (pt.getBinding().equals(binding)) {
         return pt.getName();
       }
     }
   }
   return null;
 }
 public static String getActionURL(
     Definition wsdlDefinition,
     String serviceName,
     String portName,
     String bindingName,
     String opName) {
   Map<?, ?> services = wsdlDefinition.getServices();
   Set<?> serviceKeys = services.keySet();
   for (Iterator<?> it = serviceKeys.iterator(); it.hasNext(); ) {
     QName serviceKey = (QName) it.next();
     if (serviceName != null && serviceKey.getLocalPart().contentEquals(serviceName)) {
       Service service = (Service) services.get(serviceKey);
       Map<?, ?> ports = service.getPorts();
       Set<?> portKeys = ports.keySet();
       for (Iterator<?> it2 = portKeys.iterator(); it2.hasNext(); ) {
         String portKey = (String) it2.next();
         if (portName != null && portKey.contentEquals(portName)) {
           Port port = (Port) ports.get(portKey);
           Binding wsdlBinding = port.getBinding();
           List<?> operations = wsdlBinding.getBindingOperations();
           for (Iterator<?> it3 = operations.iterator(); it3.hasNext(); ) {
             BindingOperation operation = (BindingOperation) it3.next();
             if (opName != null && operation.getName().contentEquals(opName)) {
               List<?> attributesList = operation.getExtensibilityElements();
               for (Iterator<?> it4 = attributesList.iterator(); it4.hasNext(); ) {
                 Object test = it4.next();
                 if (test instanceof SOAPOperation) {
                   SOAPOperation soapOp = (SOAPOperation) test;
                   return soapOp.getSoapActionURI();
                 } else if (test instanceof SOAP12Operation) {
                   SOAP12Operation soapOp = (SOAP12Operation) test;
                   return soapOp.getSoapActionURI();
                 }
               }
             }
           }
         }
       }
     }
   }
   return null;
 }
示例#8
0
  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);
          }
        }
      }
    }
  }
示例#9
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 static void populateEprInfo(EprMetaData info) {
    if (!info.isValid()) {
      return;
    }
    Binding match = info.getBinding();
    Definition wsdlDef = info.getCandidateWsdlDef();
    Collection<Service> services = CastUtils.cast(wsdlDef.getServices().values());
    for (Service serv : services) {
      Collection<Port> ports = CastUtils.cast(serv.getPorts().values());
      for (Port pt : ports) {
        if (pt.getBinding().equals(match)) {
          info.setPortName(pt.getName());
          info.setServiceQName(serv.getQName());
          break;
        }
      }
    }

    if (info.getServiceQName() == null) {
      Iterator<?> importLists = wsdlDef.getImports().values().iterator();
      while (info.getServiceQName() == null && importLists.hasNext()) {
        List<?> imports = (List<?>) importLists.next();
        for (java.lang.Object imp : imports) {
          if (imp instanceof Import) {
            Definition importDef = ((Import) imp).getDefinition();
            LOG.log(Level.FINE, "following wsdl import " + importDef.getDocumentBaseURI());
            info.setCandidateWsdlDef(importDef);
            populateEprInfo(info);
            if (info.getServiceQName() != null) {
              break;
            }
          }
        }
      }
    }
  }
示例#11
0
 private void convertService(Service service) throws IOException {
   // String comment = service.getDocumentationElement().getNodeValue();
   for (Entry<String, Port> entry : (Set<Entry<String, Port>>) service.getPorts().entrySet()) {
     convertPort(entry.getValue());
   }
 }
示例#12
0
  protected static void initializeService(
      org.w3c.dom.Element service,
      TProcess bpelProcess,
      TPartnerLink pl,
      java.util.Collection<javax.wsdl.Definition> wsdls,
      org.w3c.dom.Element partnerLinkTypes,
      java.util.Map<String, String> nsMap) {
    QName serviceName = null;
    String servicePort = null;

    // Get partner link type details
    QName partnerLinkType = pl.getPartnerLinkType();

    org.w3c.dom.NodeList nl = partnerLinkTypes.getChildNodes();

    String portType = null;

    for (int i = 0; portType == null && i < nl.getLength(); i++) {
      org.w3c.dom.Node n = nl.item(i);

      if (n instanceof org.w3c.dom.Element
          && XMLUtils.getLocalname(n.getNodeName()).equals(PARTNER_LINK_TYPE)) {
        org.w3c.dom.Element plt = (org.w3c.dom.Element) nl.item(i);

        String name = plt.getAttribute("name");

        if (name != null && name.equals(partnerLinkType.getLocalPart())) {
          org.w3c.dom.NodeList nl2 = plt.getChildNodes();

          for (int j = 0; portType == null && j < nl2.getLength(); j++) {
            org.w3c.dom.Node n2 = nl2.item(j);

            if (n2 instanceof org.w3c.dom.Element
                && XMLUtils.getLocalname(n2.getNodeName()).equals("role")) {
              org.w3c.dom.Element role = (org.w3c.dom.Element) n2;
              String roleName = role.getAttribute("name");

              if ((pl.getMyRole() != null && pl.getMyRole().equals(roleName))
                  || (pl.getPartnerRole() != null && pl.getPartnerRole().equals(roleName))) {
                portType = role.getAttribute("portType");

                String ptprefix = XMLUtils.getPrefix(portType);

                String ptns = partnerLinkTypes.getAttribute("xmlns:" + ptprefix);

                String newprefix = XMLUtils.getPrefixForNamespace(ptns, nsMap);

                portType = newprefix + ":" + XMLUtils.getLocalname(portType);
              }
            }
          }
        }
      }
    }

    if (portType != null) {
      String portTypePrefix = XMLUtils.getPrefix(portType);
      String portTypeNS = XMLUtils.getNamespaceForPrefix(portTypePrefix, nsMap);
      QName ptQName = new QName(portTypeNS, XMLUtils.getLocalname(portType));

      for (javax.wsdl.Definition wsdl : wsdls) {
        if (wsdl.getTargetNamespace().equals(portTypeNS)) {

          @SuppressWarnings("unchecked")
          java.util.Collection<javax.wsdl.Service> services = wsdl.getServices().values();

          for (javax.wsdl.Service s : services) {

            @SuppressWarnings("unchecked")
            java.util.Collection<javax.wsdl.Port> ports = s.getPorts().values();

            for (javax.wsdl.Port p : ports) {

              if (p.getBinding() != null
                  && p.getBinding().getPortType() != null
                  && p.getBinding().getPortType().getQName().equals(ptQName)) {
                serviceName = s.getQName();
                servicePort = p.getName();
              }
            }
          }
        }
      }

      if (serviceName != null) {
        String prefix = XMLUtils.getPrefixForNamespace(serviceName.getNamespaceURI(), nsMap);

        service.setAttribute("name", prefix + ":" + serviceName.getLocalPart());
      }

      if (servicePort != null) {
        service.setAttribute("port", servicePort);
      }
    }
  }
 private boolean hasPort(QName serviceName, Port port) {
   Service service = catalog.lookupService(serviceName);
   return service.getPorts().containsKey(port.getName());
 }