Пример #1
0
  private void convertPort(Port port) throws IOException {
    String comment = "";
    String name = port.getName();
    String protocol = "soap";
    String location = "socket://localhost:80/";
    if (port.getDocumentationElement() != null) {
      comment = port.getDocumentationElement().getNodeValue();
    }
    List<ExtensibilityElement> extElements = port.getExtensibilityElements();
    for (ExtensibilityElement element : extElements) {
      if (element instanceof SOAPAddress) {
        location = ((SOAPAddress) element).getLocationURI().toString();
        StringBuilder builder = new StringBuilder();
        builder
            .append("soap {\n")
            .append("\t.wsdl = \"")
            .append(definition.getDocumentBaseURI())
            .append("\";\n")
            .append("\t.wsdl.port = \"")
            .append(port.getName())
            .append("\"\n}");
        protocol = builder.toString();

      } else if (element instanceof HTTPAddress) {
        location = ((HTTPAddress) element).getLocationURI().toString();
        protocol = "http";
      }
    }
    try {
      URI uri = new URI(location);
      uri =
          new URI(
              "socket",
              uri.getUserInfo(),
              uri.getHost(),
              (uri.getPort() < 1) ? 80 : uri.getPort(),
              uri.getPath(),
              uri.getQuery(),
              uri.getFragment());
      location = uri.toString();
    } catch (URISyntaxException e) {
      e.printStackTrace();
    }
    Binding binding = port.getBinding();
    PortType portType = binding.getPortType();
    convertPortType(portType, binding);
    outputPorts.put(
        name,
        new OutputPort(name, location, protocol, portType.getQName().getLocalPart(), comment));
  }
Пример #2
0
  private XNode getXNode(Service service, Port port) {
    XNode vService = getXNode(service);

    XPort pNode = new XPort();
    pNode.setName(port.getName());
    pNode.setParentNode(vService);
    return pNode;
  }
Пример #3
0
 @Test
 public void nullPortName() throws Exception {
   Service service = WSDLUtil.getService("MultiplePortService.wsdl", new PortName(null));
   Assert.assertNotNull(service);
   Assert.assertEquals(
       service.getQName(),
       new QName("urn:switchyard-component-soap:test-ws:1.0", "GoodbyeWebService"));
   Port port = WSDLUtil.getPort(service, new PortName(null));
   Assert.assertNotNull(port);
   Assert.assertEquals(port.getName(), "GoodbyeWebServicePort");
   service = WSDLUtil.getService("MultiplePortService.wsdl", new PortName("HelloWebService:"));
   Assert.assertNotNull(service);
   Assert.assertEquals(
       service.getQName(),
       new QName("urn:switchyard-component-soap:test-ws:1.0", "HelloWebService"));
   port = WSDLUtil.getPort(service, new PortName(null));
   Assert.assertEquals(port.getName(), "HelloWebServicePortFrench");
 }
Пример #4
0
 @Test
 public void halfQualifiedPortName() throws Exception {
   PortName portName = new PortName("HelloWebService:HelloWebServicePort");
   Service service = WSDLUtil.getService("MultiplePortService.wsdl", portName);
   Assert.assertNotNull(service);
   Assert.assertEquals(
       service.getQName(),
       new QName("urn:switchyard-component-soap:test-ws:1.0", "HelloWebService"));
   Port port = WSDLUtil.getPort(service, portName);
   Assert.assertNotNull(port);
   Assert.assertEquals(port.getName(), "HelloWebServicePort");
 }
 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 void testSelectPort_service_port() {
    QName portTypeName = new QName("http://example.com/translator", "documentTranslator");
    QName serviceName = new QName("http://example.com/translator", "translatorService");
    String portName = "documentTranslatorPort";

    SoapEndpointReference reference = getReference();
    reference.setPortTypeName(portTypeName);
    reference.setServiceName(serviceName);
    reference.setPortName(portName);
    Port port = reference.selectPort(catalog);

    assertEquals(portTypeName, port.getBinding().getPortType().getQName());
    assertTrue(hasPort(serviceName, port));
    assertEquals(portName, port.getName());
  }
Пример #7
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);
          }
        }
      }
    }
  }
  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;
            }
          }
        }
      }
    }
  }
Пример #9
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());
 }