Example #1
0
  protected static Pair<Filter, ConstraintLanguage> parseConstraint(
      XMLAdapter adapter, OMElement omQueryElement) {
    Pair<Filter, ConstraintLanguage> pc = null;
    if (omQueryElement != null
        && new QName(CSWConstants.CSW_202_NS, "Constraint").equals(omQueryElement.getQName())) {
      Version versionConstraint =
          adapter.getRequiredNodeAsVersion(omQueryElement, new XPath("@version", nsContext));

      OMElement filterEl = omQueryElement.getFirstChildWithName(new QName(OGCNS, "Filter"));
      OMElement cqlTextEl = omQueryElement.getFirstChildWithName(new QName("", "CQLTEXT"));
      if ((filterEl != null) && (cqlTextEl == null)) {

        ConstraintLanguage constraintLanguage = ConstraintLanguage.FILTER;
        Filter constraint;
        try {
          // TODO remove usage of wrapper (necessary at the moment to work around problems
          // with AXIOM's

          XMLStreamReader xmlStream =
              new XMLStreamReaderWrapper(filterEl.getXMLStreamReaderWithoutCaching(), null);
          // skip START_DOCUMENT
          xmlStream.nextTag();

          if (versionConstraint.equals(new Version(1, 1, 0))) {

            constraint = Filter110XMLDecoder.parse(xmlStream);

          } else if (versionConstraint.equals(new Version(1, 0, 0))) {
            constraint = Filter100XMLDecoder.parse(xmlStream);
          } else {
            String msg =
                Messages.get(
                    "CSW_FILTER_VERSION_NOT_SPECIFIED",
                    versionConstraint,
                    Version.getVersionsString(new Version(1, 1, 0)),
                    Version.getVersionsString(new Version(1, 0, 0)));
            LOG.info(msg);
            throw new InvalidParameterValueException(msg);
          }
        } catch (XMLStreamException e) {
          String msg =
              "FilterParsingException: There went something wrong while parsing the filter expression, so please check this!";
          LOG.debug(msg);
          throw new XMLParsingException(adapter, filterEl, e.getMessage());
        }
        pc = new Pair<Filter, CSWConstants.ConstraintLanguage>(constraint, constraintLanguage);
      } else if ((filterEl == null) && (cqlTextEl != null)) {
        String msg = Messages.get("CSW_UNSUPPORTED_CQL_FILTER");
        LOG.info(msg);
        throw new NotImplementedError(msg);
      } else {
        String msg = Messages.get("CSW_MISSING_FILTER_OR_CQL");
        LOG.debug(msg);
        throw new InvalidParameterValueException(msg);
      }
    }
    return pc;
  }
 public void setSmartLifecycleLinks(OMElement locationConfiguration) throws RegistryException {
   Iterator confElements = locationConfiguration.getChildElements();
   while (confElements.hasNext()) {
     OMElement confElement = (OMElement) confElements.next();
     if (confElement.getQName().equals(new QName("key"))) {
       smartLifecycleLinks.add(confElement.getText());
     }
   }
 }
  public void deserialize(OMElement throttlingConfigEle) throws ThrottlingException {
    OMElement throttlingManagerConfigs = null;
    Iterator childElements = throttlingConfigEle.getChildElements();
    while (childElements.hasNext()) {
      Object configChildElement = childElements.next();

      if (!(configChildElement instanceof OMElement)) {
        continue;
      }
      OMElement configChildOMElement = (OMElement) configChildElement;
      if (new QName(CONFIG_NS, "ThrottlingManagerTask", "")
          .equals(configChildOMElement.getQName())) {
        throttlingManagerConfigs = (OMElement) configChildElement;
      }
    }
    // Iterator throttlingConfigChildIt = throttlingConfigEle.getChildElements();
    Iterator throttlingConfigChildIt = throttlingManagerConfigs.getChildElements();
    while (throttlingConfigChildIt.hasNext()) {
      Object throttlingConfigChild = throttlingConfigChildIt.next();
      if (!(throttlingConfigChild instanceof OMElement)) {
        continue;
      }
      OMElement throttlingConfigChildEle = (OMElement) throttlingConfigChild;

      if (new QName(CONFIG_NS, "tasks", "").equals(throttlingConfigChildEle.getQName())) {
        throttlingTaskConfigs = new ArrayList<ThrottlingTaskConfiguration>();
        tasks = new ArrayList<Task>();
        Iterator tasksConfigChildIt = throttlingConfigChildEle.getChildElements();
        while (tasksConfigChildIt.hasNext()) {
          Object taskConfigChild = tasksConfigChildIt.next();
          if (!(taskConfigChild instanceof OMElement)) {
            continue;
          }
          ThrottlingTaskConfiguration taskConfiguration =
              new ThrottlingTaskConfiguration((OMElement) taskConfigChild);
          throttlingTaskConfigs.add(taskConfiguration);
          tasks.add(taskConfiguration.getTask());
        }
      }
    }
  }
Example #4
0
  @Override
  protected WMTSCapabilitiesAdapter getCapabilitiesAdapter(OMElement root, String version)
      throws IOException {

    QName rootElName = root.getQName();

    if (!new QName(WMTS_100_NS, "Capabilities").equals(rootElName)) {
      String msg = "Unexpected WMTS GetCapabilities response element: '" + rootElName + "'.";
      throw new IOException(msg);
    }

    WMTSCapabilitiesAdapter capaAdapter = new WMTSCapabilitiesAdapter();
    capaAdapter.setRootElement(root);
    return capaAdapter;
  }
Example #5
0
  @Test(
      groups = "wso2.esb",
      description = "- Transformer proxy" + "- Proxy service enabling only http")
  public void testTransformerProxy() throws Exception {

    OMElement response =
        axis2Client.sendCustomQuoteRequest(getProxyServiceURL("StockQuoteProxy"), null, "WSO2");

    assertNotNull(response, "Fault response message null");

    assertNotNull(response.getQName().getLocalPart(), "Fault response null localpart");
    assertEquals(
        response.getQName().getLocalPart(), "CheckPriceResponse", "Fault localpart mismatched");

    assertNotNull(
        response.getFirstElement().getQName().getLocalPart(), " Fault response null localpart");
    assertEquals(
        response.getFirstElement().getQName().getLocalPart(), "Code", "Fault localpart mismatched");
    assertEquals(response.getFirstElement().getText(), "WSO2", "Fault value mismatched");

    assertNotNull(
        response.getFirstChildWithName(new QName("http://services.samples/xsd", "Price")),
        "Fault response null localpart");
  }
Example #6
0
  /**
   * This static method will be used to build the Target from the specified element
   *
   * @param elem - OMElement describing the xml configuration of the target
   * @return Target built by parsing the given element
   */
  public static Target createTarget(OMElement elem) {

    if (!TARGET_Q.equals(elem.getQName())) {
      handleException("Element does not match with the target QName");
    }

    Target target = new Target();
    OMAttribute toAttr = elem.getAttribute(new QName(XMLConfigConstants.NULL_NAMESPACE, "to"));
    if (toAttr != null && toAttr.getAttributeValue() != null) {
      target.setToAddress(toAttr.getAttributeValue());
    }

    OMAttribute soapAction =
        elem.getAttribute(new QName(XMLConfigConstants.NULL_NAMESPACE, "soapAction"));
    if (soapAction != null && soapAction.getAttributeValue() != null) {
      target.setSoapAction(soapAction.getAttributeValue());
    }

    OMAttribute sequenceAttr =
        elem.getAttribute(new QName(XMLConfigConstants.NULL_NAMESPACE, "sequence"));
    if (sequenceAttr != null && sequenceAttr.getAttributeValue() != null) {
      target.setSequenceRef(sequenceAttr.getAttributeValue());
    }

    OMAttribute endpointAttr =
        elem.getAttribute(new QName(XMLConfigConstants.NULL_NAMESPACE, "endpoint"));
    if (endpointAttr != null && endpointAttr.getAttributeValue() != null) {
      target.setEndpointRef(endpointAttr.getAttributeValue());
    }

    OMElement sequence =
        elem.getFirstChildWithName(new QName(XMLConfigConstants.SYNAPSE_NAMESPACE, "sequence"));
    if (sequence != null) {
      SequenceMediatorFactory fac = new SequenceMediatorFactory();
      target.setSequence(fac.createAnonymousSequence(sequence));
    }

    OMElement endpoint =
        elem.getFirstChildWithName(new QName(XMLConfigConstants.SYNAPSE_NAMESPACE, "endpoint"));
    if (endpoint != null) {
      target.setEndpoint(EndpointFactory.getEndpointFromElement(endpoint, true));
    }

    return target;
  }
 public static String parseResponseFeedback(org.apache.axiom.soap.SOAPBody soapBody)
     throws FaultException {
   /*  Sample feedback response
   *   <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
       <soapenv:Body><part><axis2ns3:correlation xmlns:axis2ns3="http://wso2.org/humantask/feedback">
       <axis2ns3:taskid>10001</axis2ns3:taskid></axis2ns3:correlation></part></soapenv:Body></soapenv:Envelope>
   * */
   Iterator<OMElement> srcParts = soapBody.getChildElements();
   if (srcParts.hasNext()) {
     OMElement srcPart = srcParts.next();
     if (!srcPart.getQName().equals(new QName(null, "part"))) {
       throw new FaultException(
           BPEL4PeopleConstants.B4P_FAULT,
           "Unexpected element in SOAP body: " + srcPart.toString());
     }
     OMElement hifb =
         srcPart.getFirstChildWithName(
             new QName(
                 BPEL4PeopleConstants.B4P_NAMESPACE, BPEL4PeopleConstants.B4P_CORRELATION_HEADER));
     if (hifb == null) {
       throw new FaultException(
           BPEL4PeopleConstants.B4P_FAULT,
           "Unexpected element in SOAP body: " + srcPart.toString());
     }
     OMElement taskIDele =
         hifb.getFirstChildWithName(
             new QName(
                 BPEL4PeopleConstants.B4P_NAMESPACE,
                 BPEL4PeopleConstants.B4P_CORRELATION_HEADER_ATTRIBUTE));
     if (taskIDele == null) {
       throw new FaultException(
           BPEL4PeopleConstants.B4P_FAULT,
           "Unexpected element in SOAP body: " + srcPart.toString());
     }
     return taskIDele.getText();
     //            Document doc = DOMUtils.newDocument();
     //            Element destPart = doc.createElementNS(null, "part");
     //            destPart.appendChild(doc.importNode(OMUtils.toDOM(srcPart), true));
     //            message.setPart("part", destPart);
   }
   throw new FaultException(
       BPEL4PeopleConstants.B4P_FAULT, "TaskID not found in the feedback message");
 }
 private boolean checkAndReplaceEnvelope(OMElement resultElement, MessageContext synCtx) {
   OMElement firstChild = resultElement.getFirstElement();
   QName resultQName = firstChild.getQName();
   if (resultQName.getLocalPart().equals("Envelope")
       && (resultQName.getNamespaceURI().equals(SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI)
           || resultQName.getNamespaceURI().equals(SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI))) {
     SOAPEnvelope soapEnvelope = AXIOMUtils.getSOAPEnvFromOM(resultElement.getFirstElement());
     if (soapEnvelope != null) {
       try {
         soapEnvelope.buildWithAttachments();
         synCtx.setEnvelope(soapEnvelope);
       } catch (AxisFault axisFault) {
         handleException("Unable to attach SOAPEnvelope", axisFault, synCtx);
       }
     }
   } else {
     return false;
   }
   return true;
 }
  /**
   * Auto generated method signature
   *
   * @see com.pa.SecondFileService#getEmp
   * @param getEmp4
   */
  public com.pa.GetEmpResponse getEmp(com.pa.GetEmp getEmp4) throws java.rmi.RemoteException {

    org.apache.axis2.context.MessageContext _messageContext = null;
    try {
      org.apache.axis2.client.OperationClient _operationClient =
          _serviceClient.createClient(_operations[1].getName());
      _operationClient.getOptions().setAction("urn:getEmp");
      _operationClient.getOptions().setExceptionToBeThrownOnSOAPFault(true);

      addPropertyToOperationClient(
          _operationClient,
          org.apache.axis2.description.WSDL2Constants.ATTR_WHTTP_QUERY_PARAMETER_SEPARATOR,
          "&");

      // create a message context
      _messageContext = new org.apache.axis2.context.MessageContext();

      // create SOAP envelope with that payload
      org.apache.axiom.soap.SOAPEnvelope env = null;

      env =
          toEnvelope(
              getFactory(_operationClient.getOptions().getSoapVersionURI()),
              getEmp4,
              optimizeContent(new javax.xml.namespace.QName("http://pa.com", "getEmp")),
              new javax.xml.namespace.QName("http://pa.com", "getEmp"));

      // adding SOAP soap_headers
      _serviceClient.addHeadersToEnvelope(env);
      // set the message context with that soap envelope
      _messageContext.setEnvelope(env);

      // add the message contxt to the operation client
      _operationClient.addMessageContext(_messageContext);

      // execute the operation client
      _operationClient.execute(true);

      org.apache.axis2.context.MessageContext _returnMessageContext =
          _operationClient.getMessageContext(
              org.apache.axis2.wsdl.WSDLConstants.MESSAGE_LABEL_IN_VALUE);
      org.apache.axiom.soap.SOAPEnvelope _returnEnv = _returnMessageContext.getEnvelope();

      java.lang.Object object =
          fromOM(
              _returnEnv.getBody().getFirstElement(),
              com.pa.GetEmpResponse.class,
              getEnvelopeNamespaces(_returnEnv));

      return (com.pa.GetEmpResponse) object;

    } catch (org.apache.axis2.AxisFault f) {

      org.apache.axiom.om.OMElement faultElt = f.getDetail();
      if (faultElt != null) {
        if (faultExceptionNameMap.containsKey(
            new org.apache.axis2.client.FaultMapKey(faultElt.getQName(), "getEmp"))) {
          // make the fault by reflection
          try {
            java.lang.String exceptionClassName =
                (java.lang.String)
                    faultExceptionClassNameMap.get(
                        new org.apache.axis2.client.FaultMapKey(faultElt.getQName(), "getEmp"));
            java.lang.Class exceptionClass = java.lang.Class.forName(exceptionClassName);
            java.lang.reflect.Constructor constructor = exceptionClass.getConstructor(String.class);
            java.lang.Exception ex = (java.lang.Exception) constructor.newInstance(f.getMessage());
            // message class
            java.lang.String messageClassName =
                (java.lang.String)
                    faultMessageMap.get(
                        new org.apache.axis2.client.FaultMapKey(faultElt.getQName(), "getEmp"));
            java.lang.Class messageClass = java.lang.Class.forName(messageClassName);
            java.lang.Object messageObject = fromOM(faultElt, messageClass, null);
            java.lang.reflect.Method m =
                exceptionClass.getMethod("setFaultMessage", new java.lang.Class[] {messageClass});
            m.invoke(ex, new java.lang.Object[] {messageObject});

            throw new java.rmi.RemoteException(ex.getMessage(), ex);
          } catch (java.lang.ClassCastException e) {
            // we cannot intantiate the class - throw the original Axis fault
            throw f;
          } catch (java.lang.ClassNotFoundException e) {
            // we cannot intantiate the class - throw the original Axis fault
            throw f;
          } catch (java.lang.NoSuchMethodException e) {
            // we cannot intantiate the class - throw the original Axis fault
            throw f;
          } catch (java.lang.reflect.InvocationTargetException e) {
            // we cannot intantiate the class - throw the original Axis fault
            throw f;
          } catch (java.lang.IllegalAccessException e) {
            // we cannot intantiate the class - throw the original Axis fault
            throw f;
          } catch (java.lang.InstantiationException e) {
            // we cannot intantiate the class - throw the original Axis fault
            throw f;
          }
        } else {
          throw f;
        }
      } else {
        throw f;
      }
    } finally {
      if (_messageContext.getTransportOut() != null) {
        _messageContext.getTransportOut().getSender().cleanup(_messageContext);
      }
    }
  }
Example #10
0
  public CadConsultaCadastro2Stub.ConsultaCadastro2Result consultaCadastro2(
      final CadConsultaCadastro2Stub.NfeDadosMsg nfeDadosMsg,
      final CadConsultaCadastro2Stub.NfeCabecMsgE nfeCabecMsg)
      throws java.rmi.RemoteException {

    org.apache.axis2.context.MessageContext _messageContext = null;
    try {
      final org.apache.axis2.client.OperationClient _operationClient =
          this._serviceClient.createClient(this._operations[0].getName());
      _operationClient
          .getOptions()
          .setAction(
              "http://www.portalfiscal.inf.br/nfe/wsdl/CadConsultaCadastro2/consultaCadastro2");
      _operationClient.getOptions().setExceptionToBeThrownOnSOAPFault(true);

      this.addPropertyToOperationClient(
          _operationClient,
          org.apache.axis2.description.WSDL2Constants.ATTR_WHTTP_QUERY_PARAMETER_SEPARATOR,
          "&");

      // create a message context
      _messageContext = new org.apache.axis2.context.MessageContext();

      // create SOAP envelope with that payload
      org.apache.axiom.soap.SOAPEnvelope env = null;

      env =
          this.toEnvelope(
              Stub.getFactory(_operationClient.getOptions().getSoapVersionURI()),
              nfeDadosMsg,
              this.optimizeContent(
                  new javax.xml.namespace.QName(
                      "http://www.portalfiscal.inf.br/nfe/wsdl/CadConsultaCadastro2",
                      "consultaCadastro2")),
              new javax.xml.namespace.QName(
                  "http://www.portalfiscal.inf.br/nfe/wsdl/CadConsultaCadastro2",
                  "consultaCadastro2"));

      env.build();

      // add the children only if the parameter is not null
      if (nfeCabecMsg != null) {

        final org.apache.axiom.om.OMElement omElementnfeCabecMsg =
            this.toOM(
                nfeCabecMsg,
                this.optimizeContent(
                    new javax.xml.namespace.QName(
                        "http://www.portalfiscal.inf.br/nfe/wsdl/CadConsultaCadastro2",
                        "consultaCadastro2")));
        this.addHeader(omElementnfeCabecMsg, env);
      }

      // adding SOAP soap_headers
      this._serviceClient.addHeadersToEnvelope(env);
      // set the message context with that soap envelope
      _messageContext.setEnvelope(env);

      // add the message contxt to the operation client
      _operationClient.addMessageContext(_messageContext);

      // execute the operation client
      _operationClient.execute(true);

      final org.apache.axis2.context.MessageContext _returnMessageContext =
          _operationClient.getMessageContext(
              org.apache.axis2.wsdl.WSDLConstants.MESSAGE_LABEL_IN_VALUE);
      final org.apache.axiom.soap.SOAPEnvelope _returnEnv = _returnMessageContext.getEnvelope();

      final java.lang.Object object =
          this.fromOM(
              _returnEnv.getBody().getFirstElement(),
              CadConsultaCadastro2Stub.ConsultaCadastro2Result.class,
              this.getEnvelopeNamespaces(_returnEnv));

      return (CadConsultaCadastro2Stub.ConsultaCadastro2Result) object;

    } catch (final org.apache.axis2.AxisFault f) {

      final org.apache.axiom.om.OMElement faultElt = f.getDetail();
      if (faultElt != null) {
        if (this.faultExceptionNameMap.containsKey(
            new org.apache.axis2.client.FaultMapKey(faultElt.getQName(), "consultaCadastro2"))) {
          // make the fault by reflection
          try {
            final java.lang.String exceptionClassName =
                (java.lang.String)
                    this.faultExceptionClassNameMap.get(
                        new org.apache.axis2.client.FaultMapKey(
                            faultElt.getQName(), "consultaCadastro2"));
            final Class<?> exceptionClass = java.lang.Class.forName(exceptionClassName);
            final Constructor<?> constructor = exceptionClass.getConstructor(String.class);
            final java.lang.Exception ex =
                (java.lang.Exception) constructor.newInstance(f.getMessage());
            // message class
            final java.lang.String messageClassName =
                (java.lang.String)
                    this.faultMessageMap.get(
                        new org.apache.axis2.client.FaultMapKey(
                            faultElt.getQName(), "consultaCadastro2"));
            final Class<?> messageClass = java.lang.Class.forName(messageClassName);
            final java.lang.Object messageObject = this.fromOM(faultElt, messageClass, null);
            final java.lang.reflect.Method m =
                exceptionClass.getMethod("setFaultMessage", messageClass);
            m.invoke(ex, messageObject);

            throw new java.rmi.RemoteException(ex.getMessage(), ex);
          } catch (final ClassCastException
              | InstantiationException
              | IllegalAccessException
              | java.lang.reflect.InvocationTargetException
              | NoSuchMethodException
              | ClassNotFoundException e) {
            // we cannot intantiate the class - throw the original Axis fault
            throw f;
          }
        } else {
          throw f;
        }
      } else {
        throw f;
      }
    } finally {
      if (_messageContext.getTransportOut() != null) {
        _messageContext.getTransportOut().getSender().cleanup(_messageContext);
      }
    }
  }
Example #11
0
  public static Query getQuery(OMElement omElement) {
    if (new QName(CSWConstants.CSW_202_NS, "Query").equals(omElement.getQName())) {
      XMLAdapter adapter = new XMLAdapter(omElement);
      SortProperty[] sortProps = null;
      Filter constraint = null;
      ReturnableElement elementSetName = null;
      String[] elementName = null;
      ConstraintLanguage constraintLanguage = null;

      List<OMElement> queryChildElements =
          adapter.getRequiredElements(omElement, new XPath("*", nsContext));

      String typeQuery =
          adapter.getNodeAsString(omElement, new XPath("./@typeNames", nsContext), "");

      if ("".equals(typeQuery)) {
        String msg =
            "ERROR in XML document: Required attribute \"typeNames\" in element \"Query\" is missing!";
        throw new MissingParameterException(msg);
      }

      String[] queryTypeNamesString = StringUtils.split(typeQuery, " ");
      QName[] queryTypeNames = new QName[queryTypeNamesString.length];
      int counterQName = 0;
      for (String s : queryTypeNamesString) {
        LOG.debug("Parsing typeName '" + s + "' of Query as QName. ");
        QName qname = adapter.parseQName(s, adapter.getRootElement());
        queryTypeNames[counterQName++] = qname;
      }
      elementName = adapter.getNodesAsStrings(omElement, new XPath("./csw:ElementName", nsContext));
      QName[] returnTypeNames = null;
      for (OMElement omQueryElement : queryChildElements) {

        // TODO mandatory exclusiveness between ElementSetName vs. ElementName not implemented yet
        if (new QName(CSWConstants.CSW_202_NS, "ElementSetName")
            .equals(omQueryElement.getQName())) {
          String elementSetNameString = omQueryElement.getText();
          elementSetName = ReturnableElement.determineReturnableElement(elementSetNameString);

          // elementSetNameTypeNames = getNodesAsQNames( omQueryElement, new XPath( "@typeNames",
          // nsContext ) );
          String typeElementSetName =
              adapter
                  .getNodeAsString(omQueryElement, new XPath("./@typeNames", nsContext), "")
                  .trim();
          String[] elementSetNameTypeNamesString = StringUtils.split(typeElementSetName, " ");
          returnTypeNames = new QName[elementSetNameTypeNamesString.length];
          for (int i = 0; i < elementSetNameTypeNamesString.length; i++) {
            returnTypeNames[i] = adapter.parseQName(elementSetNameTypeNamesString[i], omElement);
          }
        }
        Pair<Filter, ConstraintLanguage> parsedConstraint =
            parseConstraint(adapter, omQueryElement);
        if (parsedConstraint != null) {
          constraintLanguage = parsedConstraint.second;
          constraint = parsedConstraint.first;
        }

        if (new QName(OGCNS, "SortBy").equals(omQueryElement.getQName())) {

          List<OMElement> sortPropertyElements =
              adapter.getRequiredElements(omQueryElement, new XPath("ogc:SortProperty", nsContext));
          sortProps = new SortProperty[sortPropertyElements.size()];
          int counter = 0;
          for (OMElement sortPropertyEl : sortPropertyElements) {
            OMElement propNameEl =
                adapter.getRequiredElement(
                    sortPropertyEl, new XPath("ogc:PropertyName", nsContext));
            String sortOrder =
                adapter.getNodeAsString(
                    sortPropertyEl, new XPath("ogc:SortOrder", nsContext), "ASC");
            SortProperty sortProp =
                new SortProperty(
                    new ValueReference(
                        propNameEl.getText(), adapter.getNamespaceContext(propNameEl)),
                    sortOrder.equals("ASC"));
            sortProps[counter++] = sortProp;
          }
        }
      }
      return new Query(
          elementSetName,
          elementName,
          constraint,
          constraintLanguage,
          sortProps,
          queryTypeNames,
          returnTypeNames);
    }
    return null;
  }
Example #12
0
  /**
   * Builds a SOAPEnvelope from DOM Document.
   *
   * @param doc - The dom document that contains a SOAP message
   * @param useDoom
   * @return
   * @throws WSSecurityException
   */
  public static SOAPEnvelope getSOAPEnvelopeFromDOMDocument(Document doc, boolean useDoom)
      throws WSSecurityException {

    if (useDoom) {
      try {
        // Get processed headers
        SOAPEnvelope env = (SOAPEnvelope) doc.getDocumentElement();
        ArrayList processedHeaderQNames = new ArrayList();
        SOAPHeader soapHeader = env.getHeader();

        if (soapHeader != null) {
          Iterator headerBlocs = soapHeader.getChildElements();
          while (headerBlocs.hasNext()) {

            OMElement element = (OMElement) headerBlocs.next();
            SOAPHeaderBlock header = null;

            if (element instanceof SOAPHeaderBlock) {
              header = (SOAPHeaderBlock) element;

              // If a header block is not an instance of SOAPHeaderBlock, it means that
              // it is a header we have added in rampart eg. EncryptedHeader and should
              // be converted to SOAPHeaderBlock for processing
            } else {
              header = soapHeader.addHeaderBlock(element.getLocalName(), element.getNamespace());
              Iterator attrIter = element.getAllAttributes();
              while (attrIter.hasNext()) {
                OMAttribute attr = (OMAttribute) attrIter.next();
                header.addAttribute(
                    attr.getLocalName(), attr.getAttributeValue(), attr.getNamespace());
              }
              Iterator nsIter = element.getAllDeclaredNamespaces();
              while (nsIter.hasNext()) {
                OMNamespace ns = (OMNamespace) nsIter.next();
                header.declareNamespace(ns);
              }
              // retrieve all child nodes (including any text nodes)
              // and re-attach to header block
              Iterator children = element.getChildren();
              while (children.hasNext()) {
                OMNode child = (OMNode) children.next();
                child.detach();
                header.addChild(child);
              }

              element.detach();

              soapHeader.build();

              header.setProcessed();
            }

            if (header.isProcessed()) {
              processedHeaderQNames.add(element.getQName());
            }
          }
        }
        XMLStreamReader reader = ((OMElement) doc.getDocumentElement()).getXMLStreamReader();
        StAXSOAPModelBuilder stAXSOAPModelBuilder = new StAXSOAPModelBuilder(reader, null);
        SOAPEnvelope envelope = stAXSOAPModelBuilder.getSOAPEnvelope();

        // Set the processed flag of the processed headers
        SOAPHeader header = envelope.getHeader();
        for (Iterator iter = processedHeaderQNames.iterator(); iter.hasNext(); ) {
          QName name = (QName) iter.next();
          Iterator omKids = header.getChildrenWithName(name);
          if (omKids.hasNext()) {
            ((SOAPHeaderBlock) omKids.next()).setProcessed();
          }
        }

        envelope.build();

        return envelope;

      } catch (FactoryConfigurationError e) {
        throw new WSSecurityException(e.getMessage());
      }
    } else {
      try {
        ByteArrayOutputStream os = new ByteArrayOutputStream();
        XMLUtils.outputDOM(doc.getDocumentElement(), os, true);
        ByteArrayInputStream bais = new ByteArrayInputStream(os.toByteArray());

        StAXSOAPModelBuilder stAXSOAPModelBuilder =
            new StAXSOAPModelBuilder(
                XMLInputFactory.newInstance().createXMLStreamReader(bais), null);
        return stAXSOAPModelBuilder.getSOAPEnvelope();
      } catch (Exception e) {
        throw new WSSecurityException(e.getMessage());
      }
    }
  }
Example #13
0
  public Object fromHeaderBlock(SOAPHeaderBlock sequenceAckElement)
      throws OMException, SandeshaException {
    originalSequenceAckElement = sequenceAckElement;
    OMElement identifierPart = null;
    Iterator childElements = sequenceAckElement.getChildElements();
    while (childElements.hasNext()) {
      OMElement element = (OMElement) childElements.next();
      String elementNamespace = element.getQName().getNamespaceURI();
      String elementLocalName = element.getQName().getLocalPart();
      if (namespaceValue.equals(elementNamespace)) {
        if (Sandesha2Constants.WSRM_COMMON.ACK_RANGE.equals(elementLocalName)) {
          String lowerAttribValue =
              element.getAttributeValue(new QName(Sandesha2Constants.WSRM_COMMON.LOWER));
          String upperAttribValue =
              element.getAttributeValue(new QName(Sandesha2Constants.WSRM_COMMON.UPPER));

          if (lowerAttribValue == null || upperAttribValue == null)
            throw new OMException(
                SandeshaMessageHelper.getMessage(
                    SandeshaMessageKeys.noUpperOrLowerAttributesInElement, element.toString()));

          try {
            long lower = Long.parseLong(lowerAttribValue);
            long upper = Long.parseLong(upperAttribValue);
            acknowledgementRangeList.add(new Range(lower, upper));
          } catch (Exception ex) {
            throw new OMException(
                SandeshaMessageHelper.getMessage(
                    SandeshaMessageKeys.ackRandDoesNotHaveCorrectValues, element.toString()));
          }
        } else if (Sandesha2Constants.WSRM_COMMON.NACK.equals(elementLocalName)) {
          try {
            Long nack = Long.valueOf(element.getText());
            nackList.add(nack);
          } catch (Exception ex) {
            throw new OMException(
                SandeshaMessageHelper.getMessage(
                    SandeshaMessageKeys.nackDoesNotContainValidLongValue));
          }
        } else if (Sandesha2Constants.WSRM_COMMON.IDENTIFIER.equals(elementLocalName)) {
          identifierPart = element;
        } else {
          String rmSpecVersion = SpecSpecificConstants.getSpecVersionString(namespaceValue);
          if (SpecSpecificConstants.isAckFinalAllowed(rmSpecVersion)) {
            if (Sandesha2Constants.WSRM_COMMON.FINAL.equals(elementLocalName)) {
              ackFinal = true;
            }
          }
          if (SpecSpecificConstants.isAckNoneAllowed(rmSpecVersion)) {
            if (Sandesha2Constants.WSRM_COMMON.NONE.equals(elementLocalName)) {
              ackNone = true;
            }
          }
        }
      }
    }

    identifier = new Identifier(namespaceValue);
    identifier.fromOMElement(identifierPart);

    // Indicate that we have processed this part of the message.
    sequenceAckElement.setProcessed();
    return this;
  }