Exemple #1
0
 public static String getNamespace(final XmlObject doc) {
   String namespaceURI = doc.getDomNode().getNamespaceURI();
   if (namespaceURI == null && doc.getDomNode().getFirstChild() != null) {
     namespaceURI = doc.getDomNode().getFirstChild().getNamespaceURI();
   }
   /*
    * if document starts with a comment, get next sibling (and ignore
    * initial comment)
    */
   if (namespaceURI == null
       && doc.getDomNode().getFirstChild() != null
       && doc.getDomNode().getFirstChild().getNextSibling() != null) {
     namespaceURI = doc.getDomNode().getFirstChild().getNextSibling().getNamespaceURI();
   }
   // check with schemaType namespace, necessary for anyType elements
   final String schemaTypeNamespace = getSchemaTypeNamespace(doc);
   if (schemaTypeNamespace == null) {
     return namespaceURI;
   } else {
     if (schemaTypeNamespace.equals(namespaceURI)) {
       return namespaceURI;
     } else {
       return schemaTypeNamespace;
     }
   }
 }
 /**
  * Check SOS response for xsi:schemaLocation, remove attribute and add attribute to SOAP message
  *
  * @param xmlObject
  * @param soapResponseMessage SOAP response message
  * @throws SOAPException If an error occurs
  */
 private void addAndRemoveSchemaLocationForSOAP(
     XmlObject xmlObject, SOAPMessage soapResponseMessage) throws SOAPException {
   String value = null;
   Node nodeToRemove = null;
   NamedNodeMap attributeMap = xmlObject.getDomNode().getFirstChild().getAttributes();
   for (int i = 0; i < attributeMap.getLength(); i++) {
     Node node = attributeMap.item(i);
     if (node.getLocalName().equals(W3CConstants.AN_SCHEMA_LOCATION)) {
       value = node.getNodeValue();
       nodeToRemove = node;
     }
   }
   if (nodeToRemove != null) {
     attributeMap.removeNamedItem(nodeToRemove.getNodeName());
   }
   SOAPEnvelope envelope = soapResponseMessage.getSOAPPart().getEnvelope();
   StringBuilder string = new StringBuilder();
   string.append(envelope.getNamespaceURI());
   string.append(BLANK_CHAR);
   string.append(envelope.getNamespaceURI());
   if (value != null && !value.isEmpty()) {
     string.append(BLANK_CHAR);
     string.append(value);
   }
   envelope.addAttribute(N52XmlHelper.getSchemaLocationQNameWithPrefix(), string.toString());
 }
Exemple #3
0
  private QName getResponseBodyElementName(RestMessageExchange messageExchange) {
    try {
      XmlObject xmlObject = XmlObject.Factory.parse(messageExchange.getResponseContentAsXml());
      Element docElement = ((Document) xmlObject.getDomNode()).getDocumentElement();

      return new QName(docElement.getNamespaceURI(), docElement.getLocalName());
    } catch (XmlException e) {
      SoapUI.logError(e);
    }

    return null;
  }
  /**
   * Creates a SOAPBody element from SOS response
   *
   * @param soapResponseMessage SOAPBody element
   * @param sosResponse SOS response
   * @param actionURI the action URI
   * @return the action URI
   * @throws SOAPException if an error occurs.
   */
  protected String createSOAPBody(
      SOAPMessage soapResponseMessage, XmlObject sosResponse, String actionURI)
      throws SOAPException {

    if (sosResponse != null) {
      addAndRemoveSchemaLocationForSOAP(sosResponse, soapResponseMessage);
      soapResponseMessage.getSOAPBody().addDocument((Document) sosResponse.getDomNode());
      return actionURI;
    } else {
      SoapFault fault = new SoapFault();
      fault.setFaultCode(SOAPConstants.SOAP_RECEIVER_FAULT);
      fault.setFaultSubcode(
          new QName(
              OWSConstants.NS_OWS,
              OwsExceptionCode.NoApplicableCode.name(),
              OWSConstants.NS_OWS_PREFIX));
      fault.setFaultReason(DEFAULT_FAULT_REASON);
      fault.setLocale(Locale.ENGLISH);
      fault.setDetailText(MISSING_RESPONSE_DETAIL_TEXT);
      createSOAPFault(soapResponseMessage.getSOAPBody().addFault(), fault);
    }
    return null;
  }
Exemple #5
0
 public static XmlObject substituteElement(
     final XmlObject elementToSubstitute, final XmlObject substitutionElement) {
   final Node domNode = substitutionElement.getDomNode();
   QName name = null;
   if (domNode.getNamespaceURI() != null && domNode.getLocalName() != null) {
     final String prefix = getPrefixForNamespace(elementToSubstitute, domNode.getNamespaceURI());
     if (prefix != null && !prefix.isEmpty()) {
       name = new QName(domNode.getNamespaceURI(), domNode.getLocalName(), prefix);
     } else {
       name = new QName(domNode.getNamespaceURI(), domNode.getLocalName());
     }
   } else {
     final QName nameOfElement = substitutionElement.schemaType().getName();
     final String localPart =
         nameOfElement.getLocalPart().replace(GmlConstants.EN_PART_TYPE, Constants.EMPTY_STRING);
     name =
         new QName(
             nameOfElement.getNamespaceURI(),
             localPart,
             getPrefixForNamespace(elementToSubstitute, nameOfElement.getNamespaceURI()));
   }
   return substituteElement(elementToSubstitute, substitutionElement.schemaType(), name);
 }
Exemple #6
0
 public static String getLocalName(final XmlObject element) {
   return (element == null) ? null : element.getDomNode().getLocalName();
 }
Exemple #7
0
  public void initFromWadl(String wadlUrl) {
    try {
      // XmlObject xmlObject = XmlObject.Factory.parse( new URL( wadlUrl ) );
      XmlObject xmlObject = XmlUtils.createXmlObject(new URL(wadlUrl));

      String content = xmlObject.xmlText();
      Element element = ((Document) xmlObject.getDomNode()).getDocumentElement();

      // try to allow older namespaces
      if (element.getLocalName().equals("application")
          && element.getNamespaceURI().startsWith("http://research.sun.com/wadl")) {
        isWADL11 = false;
        content =
            content.replaceAll(
                "\"" + element.getNamespaceURI() + "\"", "\"" + Constants.WADL11_NS + "\"");
      } else if (!element.getLocalName().equals("application")
          || !element.getNamespaceURI().equals(Constants.WADL11_NS)) {
        throw new Exception(
            "Document is not a WADL application with " + Constants.WADL11_NS + " namespace");
      }
      content = PropertyExpansionRemover.removeExpansions(content);
      ApplicationDocument applicationDocument = ApplicationDocument.Factory.parse(content);
      application = applicationDocument.getApplication();

      resourcesList = application.getResourcesList();

      service.setName(getFirstTitle(application.getDocList(), service.getName()));

      String base = resourcesList.size() == 1 ? resourcesList.get(0).getBase() : "";

      try {
        URL baseUrl = new URL(base);
        service.setBasePath(baseUrl.getPath());

        service.addEndpoint(Tools.getEndpointFromUrl(baseUrl));
      } catch (Exception e) {
        service.setBasePath(base);
      }

      service.setWadlUrl(wadlUrl);
      service.getConfig().setWadlVersion(isWADL11 ? Constants.WADL11_NS : Constants.WADL10_NS);

      for (Resources resources : resourcesList) {
        RestResource baseResource = null;
        if (resourcesList.size() > 1) {
          String path = resources.getBase();
          baseResource = service.addNewResource(path, path);
        }
        for (Resource resource : resources.getResourceList()) {
          String name = getFirstTitle(resource.getDocList(), resource.getPath());
          String path = resource.getPath();

          RestResource newResource = null;

          if (baseResource != null && path != null) {
            for (RestResource res : baseResource.getChildResourceList()) {
              if (path.equals(res.getPath())) {
                newResource = res;
                break;
              }
            }

            if (newResource == null) {
              newResource = baseResource.addNewChildResource(name, path);
            }
          } else if (path != null) {
            for (RestResource res : service.getResourceList()) {
              if (path.equals(res.getPath())) {
                newResource = res;
                break;
              }
            }

            if (newResource == null) {
              newResource = service.addNewResource(name, path);
            }
          } else {
            newResource = service.addNewResource(name, "");
          }

          initResourceFromWadlResource(newResource, resource);
          addSubResources(newResource, resource);
        }
      }
    } catch (InvalidDefinitionException ex) {
      ex.show();
    } catch (Exception e) {
      UISupport.showErrorMessage(e);
    }
  }