Exemple #1
0
  @Test
  public void testEqualNamespaces() {
    Capability c1 = factory.createCapability("cap");
    Capability c2 = factory.createCapability("cap");
    Capability c3 = factory.createCapability("cap3");

    assertTrue(c1.equalsTo(c2, EqualityLevel.SHALLOW_NO_KEY));
    assertFalse(c1.equalsTo(c3, EqualityLevel.SHALLOW_NO_KEY));
    assertFalse(c2.equalsTo(c3, EqualityLevel.SHALLOW_NO_KEY));
  }
Exemple #2
0
  @Test
  public void testHierarchy() {
    Capability root = factory.createCapability("a");

    Capability child1 = factory.createCapability("a.b");
    child1.setAttribute("key", String.class, "child1");

    Capability child2 = factory.createCapability("a.b");
    child2.setAttribute("key", String.class, "child2");

    Capability child3 = factory.createCapability("a.c");

    root.addChild(child1);
    root.addChild(child1);
    root.addChild(child2);
    root.addChild(child2);
    root.addChild(child3);
    root.addChild(child3);

    // checking of presence of added child is commented because of possible performance decrease

    List<Capability> children = root.getChildren();
    // with the check enabled, expected value would be 3
    assertEquals(6, children.size());

    assertTrue(children.contains(child1));
    assertTrue(children.contains(child2));
    assertTrue(children.contains(child3));
  }
Exemple #3
0
  @Test
  public void testHashSetContains() throws Exception {
    Capability c1 = factory.createCapability("a");
    Capability c2 = factory.createCapability("a");

    assertNotNull(c1);
    assertNotNull(c2);

    assertNotEquals(c1.hashCode(), c2.hashCode());

    c1.setAttribute(ATTR_P1, "p1");

    assertNotEquals(c1.hashCode(), c2.hashCode());

    c2.setAttribute(ATTR_P1, "p1");

    assertNotEquals(c1.hashCode(), c2.hashCode());
  }
Exemple #4
0
  @Test
  public void testUniqueAttributes() throws Exception {
    Capability c1 = factory.createCapability("a");

    c1.setAttribute(ATTR_P1, "a");
    assertEquals(1, c1.getAttributes().size());

    c1.setAttribute(ATTR_P1, "a");
    assertEquals(1, c1.getAttributes().size());

    c1.setAttribute(ATTR_P1, "b");
    assertEquals(1, c1.getAttributes().size());

    c1.setAttribute(ATTR_P3, "a");
    assertEquals(2, c1.getAttributes().size());
  }
Exemple #5
0
  @Test
  public void testUnsetAttribute() throws Exception {
    Capability c = factory.createCapability("a");
    c.setAttribute(ATTR_P1, "1");
    c.setAttribute(ATTR_P2, 2L);

    assertNotNull(c.getAttribute(ATTR_P1));
    assertNotNull(c.getAttribute(ATTR_P2));

    c.removeAttribute(ATTR_P1);

    assertNull(c.getAttribute(ATTR_P1));
    assertNotNull(c.getAttribute(ATTR_P2));

    Attribute<Long> attribute = c.getAttribute(ATTR_P2);

    assertNotNull(attribute);

    c.removeAttribute(attribute);

    assertNull(c.getAttribute(ATTR_P1));
    assertNull(c.getAttribute(ATTR_P2));
  }
Exemple #6
0
  @Test
  public void equals() throws Exception {
    Capability c1 = factory.createCapability("a");
    Capability c2 = factory.createCapability("a");

    assertTrue(c1.equalsTo(c2, EqualityLevel.SHALLOW_NO_KEY));

    c1.setAttribute(ATTR_P1, "v1");
    assertFalse(c1.equalsTo(c2, EqualityLevel.SHALLOW_NO_KEY));

    c2.setAttribute(ATTR_P1, "v1");
    assertTrue(c1.equalsTo(c2, EqualityLevel.SHALLOW_NO_KEY));
  }
Exemple #7
0
  @Test
  public void testSetAttribute() throws Exception {
    Capability c = factory.createCapability("a");
    c.setAttribute(ATTR_P1, "1");
    c.setAttribute(ATTR_P2, 2L);

    assertEquals("a", c.getNamespace());
    assertEquals("1", c.getAttributeValue(ATTR_P1));
    assertEquals(2L, (long) c.getAttributeValue(ATTR_P2));
  }
Exemple #8
0
  @Override
  public int parseIDL(String idl, Resource resource) {

    ////////////////////////////////////////////
    // process idl and get all necessary info //
    ////////////////////////////////////////////

    // process IDL into XML DOM object
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    DocumentBuilder builder;
    Document document = null;
    try {
      builder = factory.newDocumentBuilder();
      document = builder.parse(new InputSource(new StringReader(idl)));
    } catch (ParserConfigurationException | SAXException | IOException ex) {
      logger.debug("IDL is not a valid XML object", ex);
    }
    if (document == null) {
      return -1;
    }

    // get root WSDL element and thus detect WSDL version
    Element root = document.getDocumentElement();
    String rootWsdlVersion;
    stripOfNamespaceRecursive(root);
    if (root.getNodeName().equalsIgnoreCase(WSDL_DESCRIPTION_V_1_1)) {
      rootWsdlVersion = WSDL_V_1_1;
    } else {
      if (root.getNodeName().equalsIgnoreCase(WSDL_DESCRIPTION_V_2_0)) {
        rootWsdlVersion = WSDL_V_2_0;
      } else {
        logger.debug(
            "IDL is not a valid WSDL. Does not have a root element \"{}\" or \"{}\"",
            WSDL_DESCRIPTION_V_1_1,
            WSDL_DESCRIPTION_V_2_0);
        return -1;
      }
    }

    // process all messages into list (WSDL 2.0 does not define any message elements)
    NodeList messages = root.getElementsByTagName(WSDL_MESSAGE);
    List<WebserviceTypeWsdlMessage> processedMessges = new ArrayList<>();
    if (messages.getLength() > 0) {
      processMessages(messages, processedMessges);
    }

    // process all portTypes / interfaces into list
    NodeList portTypes = root.getElementsByTagName(WSDL_SERVICE_INTERFACE_V_1_1);
    NodeList interfaces = root.getElementsByTagName(WSDL_SERVICE_INTERFACE_V_2_0);
    List<WebserviceTypeWsdlInterface> processedInterfaces = new ArrayList<>();
    if (portTypes.getLength() > 0 && interfaces.getLength() == 0) {
      // wsdlVersion = WSDL_V_1_1;
      processInterfaces(portTypes, processedInterfaces);
    } else if (portTypes.getLength() == 0 && interfaces.getLength() > 0) {
      // wsdlVersion = WSDL_V_2_0;
      processInterfaces(interfaces, processedInterfaces);
    } else {
      logger.warn(
          "Processed WSDL seems to use both {} and {} specification. Parsing both \"{}\" and \"{}\" elements.",
          WSDL_V_1_1,
          WSDL_V_2_0,
          WSDL_SERVICE_INTERFACE_V_1_1,
          WSDL_SERVICE_INTERFACE_V_2_0);
      processInterfaces(portTypes, processedInterfaces);
      processInterfaces(interfaces, processedInterfaces);
    }

    // process all bindings into list
    NodeList bindings = root.getElementsByTagName(WSDL_BINDING);
    List<WebserviceTypeWsdlBinding> processedBindings = new ArrayList<>();
    processBindings(bindings, processedBindings);

    // process all services defined in this WSDL
    List<Webservice> processedWebservices = new ArrayList<>();
    NodeList services = root.getElementsByTagName(WSDL_SERVICE);
    for (int i = 0; i < services.getLength(); i++) {
      Node service = services.item(i);
      NamedNodeMap serviceAttributes = service.getAttributes();
      String serviceName = returnNodeValue(serviceAttributes, "name");
      String serviceIdlVersion = null;

      // get info about service endpoints
      List<WebserviceEndpoint> processedEndpoints = new ArrayList<>();
      NodeList endpoints = service.getChildNodes();
      for (int j = 0; j < endpoints.getLength(); j++) {
        Node endpoint = endpoints.item(j);

        if (endpoint.getNodeName().equalsIgnoreCase(WSDL_SERVICE_ENDPOINT_V_1_1)) {
          // detected as WSDL 1.1
          serviceIdlVersion = WSDL_V_1_1;
        } else if (endpoint.getNodeName().equalsIgnoreCase(WSDL_SERVICE_ENDPOINT_V_2_0)) {
          // detected as WSDL 2.0
          serviceIdlVersion = WSDL_V_2_0;
        } else {
          logger.warn(
              "Unrecognizable element \"{}\" in WSDL \"{}\" element",
              endpoint.getNodeName(),
              WSDL_SERVICE);
          continue;
        }

        NamedNodeMap endpointAttributes = endpoint.getAttributes();
        String endpointBinding = returnNodeValue(endpointAttributes, "binding");

        // get all operations implemented by this endpoint via its's binding object and list of
        // operations defined in corresponding interface
        WebserviceTypeWsdlBinding binding = getBindingByName(processedBindings, endpointBinding);
        List<WebserviceTypeWsdlBindedOperation> bindedOperations = binding.getBindedOperations();
        List<WebserviceTypeWsdlOperation> interfaceOperations =
            getInterfaceByName(processedInterfaces, binding.getInterface_()).getOperations();

        // process all operation defined in binding
        for (WebserviceTypeWsdlBindedOperation bindedOperation : bindedOperations) {
          // Note: This single binded operation represent endpoint in CRCE semantics. One WSDL port
          // / endpoint can bind multiple particular operations
          // each with their parameters, datatypes, return value etc. That is why CRCE Webservice
          // Endpoint corresponds to WSDL Operation.

          WebserviceTypeWsdlOperation operation =
              getOperationByName(interfaceOperations, bindedOperation.getName());

          // proces all input parts defined in this operation as endpoint parameters
          List<WebserviceEndpointParameter> processedParameters = new ArrayList<>();
          if (operation.getInputMessage() != null) {
            List<WebserviceTypeWsdlPart> parts =
                getMessageByName(processedMessges, operation.getInputMessage()).getParts();
            for (int k = 0; k < parts.size(); k++) {
              WebserviceTypeWsdlPart part = parts.get(k);
              String endpointParameterType =
                  part.getType() != null ? part.getType() : part.getElement();
              processedParameters.add(
                  new WebserviceEndpointParameter(
                      part.getName(), endpointParameterType, (long) k + 1, null, null));
            }
          } else if (operation.getInputElement() != null) {
            processedParameters.add(
                new WebserviceEndpointParameter(
                    operation.getName(), operation.getInputElement(), null, null, null));
          } else {
            logger.warn(
                "WSDL \"input\" element of operation \"{}\" does not have \"message\" or \"element\" attributes.");
          }

          // proces all output parts defined in this operation as endpoint response
          // TODO In document (i.e. messaging) communication style, output message can generally
          // contain multiple parts - now we just grab a first one.
          String endpointResponseType = null;
          if (operation.getOutputMessage() != null) {
            List<WebserviceTypeWsdlPart> parts =
                getMessageByName(processedMessges, operation.getOutputMessage()).getParts();
            if (parts.size() > 0) {
              endpointResponseType =
                  parts.get(0).getType() != null
                      ? parts.get(0).getType()
                      : parts.get(0).getElement();
            }
          } else if (operation.getOutputElement() != null) {
            endpointResponseType = operation.getOutputElement();
          } else {
            logger.warn(
                "WSDL \"output\" element of operation \"{}\" does not have \"message\" or \"element\" attributes.");
          }
          WebserviceEndpointResponse processedResponse =
              new WebserviceEndpointResponse(endpointResponseType, null);

          // add info about new endpoint
          processedEndpoints.add(
              new WebserviceEndpoint(
                  operation.getName(),
                  bindedOperation.getSoapAction(),
                  processedParameters,
                  processedResponse));
        }
      }

      processedWebservices.add(
          new Webservice(
              serviceName,
              null,
              serviceIdlVersion,
              getSpecificWebserviceType(),
              processedEndpoints));
    }

    ////////////////////////////////////////////////////////////////////////////
    // create CRCE metadata structures and fill it by retrieved info from idl //
    ////////////////////////////////////////////////////////////////////////////

    // create new variables for holding references to current capabilities
    Capability capability, webservice_capability, endpoint_capability;

    // Capability - CRCE Identity
    String main_name;
    switch (processedWebservices.size()) {
      case 0:
        main_name = "No webservice descriptions";
        break;
      case 1:
        main_name = processedWebservices.get(0).getName();
        break;
      default:
        main_name = "Multiple webservice descriptions";
        break;
    }
    capability = metadataService.getIdentity(resource);
    metadataService.setPresentationName(resource, main_name);
    metadataService.setSize(resource, idl.length());
    setIfSet(capability, ATTRIBUTE__CRCE_IDENTITY__MIME, WSDL_MIME);
    setIfSet(capability, ATTRIBUTE__CRCE_IDENTITY__HASH, getIdlHash(idl));

    // Capability - Webserviceschema Identity
    capability = metadataFactory.createCapability(NAMESPACE__WEBSERVICESCHEMA_IDENTITY);
    setIfSet(capability, ATTRIBUTE__WEBSERVICESCHEMA_IDENTITY__IDL_VERSION, rootWsdlVersion);
    resource.addCapability(capability);
    resource.addRootCapability(capability);

    // create one capability for each detected webservice representation
    for (Webservice processedWebservice : processedWebservices) {

      // Capability - Webserviceschema Webservice
      webservice_capability =
          metadataFactory.createCapability(NAMESPACE__WEBSERVICESCHEMA_WEBSERVICE);
      setIfSet(
          webservice_capability,
          ATTRIBUTE__WEBSERVICESCHEMA_WEBSERVICE__NAME,
          processedWebservice.getName());
      setIfSet(
          webservice_capability,
          ATTRIBUTE__WEBSERVICESCHEMA_WEBSERVICE__TYPE,
          processedWebservice.getType());
      setIfSet(
          webservice_capability,
          ATTRIBUTE__WEBSERVICESCHEMA_WEBSERVICE__URI,
          processedWebservice.getUrl());

      // Capabilities - Webservice Endpoint
      List<WebserviceEndpoint> processedEndpoints = processedWebservice.getEndpoints();
      for (int i = 0; i < processedEndpoints.size(); i++) {
        endpoint_capability = metadataFactory.createCapability(NAMESPACE__WEBSERVICE_ENDPOINT);
        setIfSet(
            endpoint_capability,
            ATTRIBUTE__WEBSERVICE_ENDPOINT__NAME,
            processedEndpoints.get(i).getName());

        // Properties - Webservice Enpoint Parameter
        List<WebserviceEndpointParameter> processedParams =
            processedEndpoints.get(i).getParameters();
        for (int j = 0; j < processedParams.size(); j++) {
          Property property =
              metadataFactory.createProperty(NAMESPACE__WEBSERVICE_ENDPOINT_PARAMETER);
          setIfSet(
              property,
              ATTRIBUTE__WEBSERVICE_ENDPOINT_PARAMETER__NAME,
              processedParams.get(j).getName());
          setIfSet(
              property,
              ATTRIBUTE__WEBSERVICE_ENDPOINT_PARAMETER__TYPE,
              processedParams.get(j).getType());
          setIfSet(
              property,
              ATTRIBUTE__WEBSERVICE_ENDPOINT_PARAMETER__ORDER,
              processedParams.get(j).getOrder());
          endpoint_capability.addProperty(property);
        }

        // Property - Webservice Endpoint Response
        Property property = metadataFactory.createProperty(NAMESPACE__WEBSERVICE_ENDPOINT_RESPONSE);
        setIfSet(
            property,
            ATTRIBUTE__WEBSERVICE_ENDPOINT_RESPONSE__TYPE,
            processedEndpoints.get(i).getResponse().getType());
        endpoint_capability.addProperty(property);

        resource.addCapability(endpoint_capability);
        webservice_capability.addChild(endpoint_capability);
      }

      resource.addCapability(webservice_capability);
      capability.addChild(webservice_capability);
    }

    return processedWebservices.size();
  }