Example #1
0
  private void createMessage(String paramName, Object value, XmlElement inputMsgElem)
      throws ComponentRegistryException {
    XmlElement paramsElem = builder.newFragment(this.requestNS, paramName);
    if (value instanceof String) {
      paramsElem.addChild(value);
    } else if (value instanceof Collection) {
      Collection list = (Collection) value;
      Iterator arrayValues = list.iterator();
      while (arrayValues.hasNext()) {
        XmlElement item = builder.newFragment("value");
        item.addChild(arrayValues.next());
        paramsElem.addChild(item);
      }
    } else if (value instanceof ArrayList) {
      Collection list = (Collection) value;
      Iterator arrayValues = list.iterator();
      while (arrayValues.hasNext()) {
        XmlElement item = builder.newFragment("value");
        item.addChild(arrayValues.next());
        paramsElem.addChild(item);
      }
    } else if (value instanceof String[]) {
      String[] list = (String[]) value;
      for (int i = 0; i < list.length; i++) {
        XmlElement item = builder.newFragment("value");
        item.addChild(list[i]);
        paramsElem.addChild(item);
      }
    } else {
      throw new ComponentRegistryException(
          "Simple WS Client can not handle the value of type " + value);
    }

    inputMsgElem.addElement(paramsElem);
  }
Example #2
0
  /**
   * @param wclient
   * @param args
   * @param opName
   * @return The output
   * @throws ComponentRegistryException
   */
  public WSIFMessage sendSOAPMessage(WSIFClient wclient, Object[][] args, String opName)
      throws ComponentRegistryException {

    WSIFPort port = wclient.getPort();

    WSIFOperation operation = port.createOperation(opName);
    WSIFMessage outputMessage = operation.createOutputMessage();
    WSIFMessage faultMessage = operation.createFaultMessage();
    String messageName = operation.createInputMessage().getName();
    XmlElement inputMsgElem = builder.newFragment(this.requestNS, messageName);

    for (int i = 0; i < args.length; i++) {
      createMessage((String) args[i][0], args[i][1], inputMsgElem);
    }

    WSIFMessageElement inputMessage = new WSIFMessageElement(inputMsgElem);

    boolean success =
        operation.executeRequestResponseOperation(inputMessage, outputMessage, faultMessage);
    if (success) {
      logger.debug("" + outputMessage);
      return outputMessage;
    } else {
      throw new ComponentRegistryException("Excpetion at server " + faultMessage);
    }
  }
Example #3
0
  public XmlElement generateSoapFault(
      XmlNamespace faultCodeValueNs,
      String faultCodeValueName,
      String reasonTextEnglish,
      Throwable ex)
      throws XsulException {
    XmlElement faultEl = builder.newFragment(SOAP11_NS, "Fault");
    if (!NS_URI_SOAP11.equals(faultCodeValueNs.getNamespaceName())) {
      faultEl.declareNamespace("n", faultCodeValueNs.getNamespaceName());
    }

    XmlElement faultCodeEl = faultEl.addElement("faultcode");
    faultCodeEl.addChild(
        new QNameElText(faultCodeEl, faultCodeValueNs.getNamespaceName(), faultCodeValueName));
    if (reasonTextEnglish == null) reasonTextEnglish = "{null}";
    faultEl.addElement("faultstring").addChild(reasonTextEnglish);

    XmlElement detail = faultEl.addElement("detail");
    if (ex != null) {
      final XmlNamespace axisNs = faultEl.newNamespace("n", "http://xml.apache.org/axis/");

      String msg = ex.getMessage();
      if (msg != null) {
        XmlElement exName = detail.addElement(axisNs, "exceptionName");
        exName.declareNamespace(axisNs);
        exName.addChild(msg);
      }
      XmlElement stackTrace = detail.addElement(axisNs, "stackTrace");
      stackTrace.declareNamespace(axisNs);
      StringWriter sw = new StringWriter();
      ex.printStackTrace(new PrintWriter(sw));
      stackTrace.addChild(sw.toString());
    }

    return faultEl;
    // XmlDocument envelope = wrapBodyContent(faultEl);

    //        // resolve prefix to use in fault code (it MUST be done after SOAP:Envelope is
    // constructed!
    //        XmlNamespace ns = faultCodeEl.lookupNamespaceByName(faultCodeNs);
    //        if(ns == null || ns.getPrefix() == null) {
    //            // declare prefix if does nto exist
    //            final XmlNamespace faultNs = builder.newNamespace("ns", faultCodeNs);
    //            ns = faultCodeEl.declareNamespace(faultNs);
    //        }
    //        String faultcode = ns.getPrefix() + ':' + faultCodeName;
    //        faultCodeEl.addChild(faultcode);

    // return envelope;
  }