예제 #1
0
  private SOAPFaultException createSOAPFaultException() {
    try {
      String namespace = "http://example.com/auctiontraq/schemas/doclit";
      SOAPFactory soapFactory = SOAPFactory.newInstance();
      Name name = soapFactory.createName("MySOAPFault", "ns0", namespace);
      Detail detail = soapFactory.createDetail();
      DetailEntry entry = detail.addDetailEntry(name);
      entry.addNamespaceDeclaration("data", namespace);
      Name attrName1 = soapFactory.createName("myAttr", "data", namespace);
      entry.addAttribute(attrName1, "myvalue");
      SOAPElement child = entry.addChildElement("message");
      child.addTextNode("Server Exception");

      Name name2 = soapFactory.createName("ExtraInformation", "ns0", namespace);
      DetailEntry entry2 = detail.addDetailEntry(name2);

      SOAPElement child2 = entry2.addChildElement("Reason");
      child2.addTextNode("Address Not Found");

      QName qname = new QName("http://schemas.xmlsoap.org/soap/envelope/", "server");
      SOAPFault sf = soapFactory.createFault("SOAP Fault Exception:Address Not Found", qname);
      org.w3c.dom.Node n = sf.getOwnerDocument().importNode(detail, true);
      sf.appendChild(n);
      return new SOAPFaultException(sf);
      // printDetail(detail);
      // return new SOAPFaultException(qname,
      //       "SOAP Fault Exception:Address Not Found", null, detail);

    } catch (SOAPException e) {
      e.printStackTrace();
      // QName qname = new QName("http://schemas.xmlsoap.org/soap/envelope/", "client");
      throw new WebServiceException("Exception While Creating SOAP Fault Exception", e);
    }
  }
  protected void handleCellErrors(Iterator errorElems) throws SOAPException {
    SOAPElement errorElem = (SOAPElement) errorElems.next();

    StringBuffer errorMsg = new StringBuffer();
    errorMsg.append("Cell error: ");

    Iterator descriptionElems =
        errorElem.getChildElements(sf.createName("Description", "", MDD_URI));
    if (descriptionElems.hasNext()) {
      SOAPElement descrElem = (SOAPElement) descriptionElems.next();
      errorMsg.append(descrElem.getValue());
      errorMsg.append("; ");
    }

    Iterator sourceElems = errorElem.getChildElements(sf.createName("Source", "", MDD_URI));
    if (sourceElems.hasNext()) {
      SOAPElement sourceElem = (SOAPElement) sourceElems.next();
      errorMsg.append("Source: ");
      errorMsg.append(sourceElem.getValue());
      errorMsg.append("; ");
    }

    Iterator codeElems = errorElem.getChildElements(sf.createName("ErrorCode", "", MDD_URI));
    if (codeElems.hasNext()) {
      SOAPElement codeElem = (SOAPElement) codeElems.next();
      errorMsg.append("Code: ");
      errorMsg.append(codeElem.getValue());
      errorMsg.append("; ");
    }

    throw new JRRuntimeException(errorMsg.toString());
  }
  protected void parseAxesElement(SOAPElement axesElement) throws SOAPException {
    // Cycle over Axis-Elements
    Name aName = sf.createName("Axis", "", MDD_URI);
    Iterator itAxis = axesElement.getChildElements(aName);
    while (itAxis.hasNext()) {
      SOAPElement axisElement = (SOAPElement) itAxis.next();
      Name name = sf.createName("name");
      String axisName = axisElement.getAttributeValue(name);

      if (axisName.equals(SLICER_AXIS_NAME)) {
        continue;
      }

      // LookUp for the Axis
      JRXmlaResultAxis axis = xmlaResult.getAxisByName(axisName);

      // retrieve the tuples by <Tuples>
      name = sf.createName("Tuples", "", MDD_URI);
      Iterator itTuples = axisElement.getChildElements(name);
      if (itTuples.hasNext()) {
        SOAPElement eTuples = (SOAPElement) itTuples.next();
        handleTuplesElement(axis, eTuples);
      }
    }
  }
예제 #4
0
  public SOAPMessage invoke(SOAPMessage request) {
    SOAPBody requestBody;
    try {
      requestBody = request.getSOAPBody();
      if (requestBody.getElementName().getLocalName().equals("Body")) {
        MessageFactory mf = MessageFactory.newInstance();
        SOAPFactory sf = SOAPFactory.newInstance();

        SOAPMessage response = mf.createMessage();
        SOAPBody respBody = response.getSOAPBody();
        Name bodyName;
        if (requestBody
            .getFirstChild()
            .getNextSibling()
            .getLocalName()
            .equals("getTomorrowForecast")) {
          bodyName = sf.createName("getTomorrowForecastResponse");
        } else if (requestBody.getFirstChild().getNextSibling().getLocalName().equals("invoke")) {
          bodyName = sf.createName("invokeResponse");
        } else {
          throw new SOAPException(
              "No operation named 'getTomorrowForecast' or 'invoke' was found !");
        }
        respBody.addBodyElement(bodyName);
        SOAPElement respContent = respBody.addChildElement("return");
        respContent.setValue(soapResponse);
        response.saveChanges();
        return response;
      }
    } catch (SOAPException soapEx) {
      logger.error("An error occurs !", soapEx);
    }
    return null;
  }
 protected void handleTuplesElement(JRXmlaResultAxis axis, SOAPElement tuplesElement)
     throws SOAPException {
   Name tName = sf.createName("Tuple", "", MDD_URI);
   for (Iterator itTuple = tuplesElement.getChildElements(tName); itTuple.hasNext(); ) {
     SOAPElement eTuple = (SOAPElement) itTuple.next();
     handleTupleElement(axis, eTuple);
   }
 }
  protected void handleHierInfo(JRXmlaResultAxis axis, SOAPElement hierInfoElement)
      throws SOAPException {
    Name name = sf.createName("name");
    String dimName = hierInfoElement.getAttributeValue(name); // Get the Dimension Name

    JRXmlaHierarchy hier = new JRXmlaHierarchy(dimName);
    axis.addHierarchy(hier);
  }
  protected void parseCellDataElement(SOAPElement cellDataElement) throws SOAPException {
    Name name = sf.createName("Cell", "", MDD_URI);
    Iterator itCells = cellDataElement.getChildElements(name);
    while (itCells.hasNext()) {
      SOAPElement cellElement = (SOAPElement) itCells.next();

      Name errorName = sf.createName("Error", "", MDD_URI);
      Iterator errorElems = cellElement.getChildElements(errorName);
      if (errorElems.hasNext()) {
        handleCellErrors(errorElems);
      }

      Name ordinalName = sf.createName("CellOrdinal");
      String cellOrdinal = cellElement.getAttributeValue(ordinalName);

      Object value = null;
      Iterator valueElements = cellElement.getChildElements(sf.createName("Value", "", MDD_URI));
      if (valueElements.hasNext()) {
        SOAPElement valueElement = (SOAPElement) valueElements.next();
        String valueType = valueElement.getAttribute("xsi:type");
        if (valueType.equals("xsd:int")) {
          value = new Long(valueElement.getValue());
        } else if (valueType.equals("xsd:double")) {
          value = new Double(valueElement.getValue());
        } else if (valueType.equals("xsd:decimal")) {
          value = new Double(valueElement.getValue());
        } else {
          value = valueElement.getValue();
        }
      }

      String fmtValue = "";
      Iterator fmtValueElements =
          cellElement.getChildElements(sf.createName("FmtValue", "", MDD_URI));
      if (fmtValueElements.hasNext()) {
        SOAPElement fmtValueElement = ((SOAPElement) fmtValueElements.next());
        fmtValue = fmtValueElement.getValue();
      }

      int pos = Integer.parseInt(cellOrdinal);
      JRXmlaCell cell = new JRXmlaCell(value, fmtValue);
      xmlaResult.setCell(cell, pos);
    }
  }
  /**
   * Clear the soap MustUnderstand.
   *
   * @param soapHeader The SOAP header.
   * @param soapHeaderElement The SOAP header element.
   */
  private void clearMustUnderstand(
      final SOAPHeader soapHeader, final SOAPHeaderElement soapHeaderElement) throws SOAPException {
    final Name headerName = soapHeader.getElementName();

    final SOAPFactory factory = SOAPFactory.newInstance();
    final Name attributeName =
        factory.createName("mustUnderstand", headerName.getPrefix(), headerName.getURI());

    soapHeaderElement.removeAttribute(attributeName);
  }
  protected void parseAxesInfoElement(SOAPElement axesInfoElement) throws SOAPException {
    // Cycle over AxisInfo-Elements
    Name axisInfoName = sf.createName("AxisInfo", "", MDD_URI);
    Iterator itAxis = axesInfoElement.getChildElements(axisInfoName);
    while (itAxis.hasNext()) {
      SOAPElement axisElement = (SOAPElement) itAxis.next();
      Name name = sf.createName("name");
      String axisName = axisElement.getAttributeValue(name);
      if (axisName.equals(SLICER_AXIS_NAME)) {
        continue;
      }

      JRXmlaResultAxis axis = new JRXmlaResultAxis(axisName);
      xmlaResult.addAxis(axis);

      // retrieve the hierarchies by <HierarchyInfo>
      name = sf.createName("HierarchyInfo", "", MDD_URI);
      Iterator itHierInfo = axisElement.getChildElements(name);
      while (itHierInfo.hasNext()) {
        SOAPElement eHierInfo = (SOAPElement) itHierInfo.next();
        handleHierInfo(axis, eHierInfo);
      }
    }
  }
예제 #10
0
 private static SOAPFactory createSoapFactory() {
   try {
     SOAPFactory factory = SOAPFactory.newInstance();
     Name name =
         factory.createName(
             CoordinationConstants.WSARJ_ELEMENT_INSTANCE_IDENTIFIER,
             CoordinationConstants.WSARJ_PREFIX,
             CoordinationConstants.WSARJ_NAMESPACE);
     WSARJ_ELEMENT_INSTANCE_NAME = name;
     return factory;
   } catch (SOAPException e) {
     // TODO log error here (should never happen)
   }
   return null;
 }
  protected void parseOLAPInfoElement(SOAPElement olapInfoElement) throws SOAPException {
    // CubeInfo-Element is not needed

    // Get the AxesInfo-Node
    Name axesInfoName = sf.createName("AxesInfo", "", MDD_URI);
    SOAPElement axesElement = null;
    Iterator axesInfoElements = olapInfoElement.getChildElements(axesInfoName);
    if (axesInfoElements.hasNext()) {
      Object axesObj = axesInfoElements.next();
      if (axesObj == null) {
        throw new JRRuntimeException("AxisInfo Element is null.");
      }
      axesElement = (SOAPElement) axesObj;
    } else {
      throw new JRRuntimeException("Could not retrieve AxesInfo Element.");
    }

    parseAxesInfoElement(axesElement);

    // CellInfo is not needed
  }
  protected void handleTupleElement(JRXmlaResultAxis axis, SOAPElement tupleElement)
      throws SOAPException {
    JRXmlaMemberTuple tuple = new JRXmlaMemberTuple(axis.getHierarchiesOnAxis().length);

    Name memName = sf.createName("Member", "", MDD_URI);
    Iterator itMember = tupleElement.getChildElements(memName);
    int memNum = 0;
    while (itMember.hasNext()) {
      SOAPElement memElement = (SOAPElement) itMember.next();

      Name name = sf.createName("Hierarchy", "", "");
      String hierName = memElement.getAttributeValue(name);

      String uName = "";
      Iterator uNameElements = memElement.getChildElements(sf.createName("UName", "", MDD_URI));
      if (uNameElements.hasNext()) {
        uName = ((SOAPElement) uNameElements.next()).getValue();
      }
      String caption = "";
      Iterator captionElements = memElement.getChildElements(sf.createName("Caption", "", MDD_URI));
      if (captionElements.hasNext()) {
        caption = ((SOAPElement) captionElements.next()).getValue();
      }
      String lName = "";
      Iterator lNameElements = memElement.getChildElements(sf.createName("LName", "", MDD_URI));
      if (lNameElements.hasNext()) {
        String levelUniqueName = ((SOAPElement) lNameElements.next()).getValue();
        Matcher matcher = LEVEL_UNIQUE_NAME_PATTERN.matcher(levelUniqueName);
        if (matcher.matches()) {
          lName = matcher.group(LEVEL_UNIQUE_NAME_PATTERN_NAME_GROUP);
        }
      }

      int lNum = 0;
      Iterator lNumElements = memElement.getChildElements(sf.createName("LNum", "", MDD_URI));
      if (lNumElements.hasNext()) {
        lNum = Integer.parseInt(((SOAPElement) lNumElements.next()).getValue());
      }
      JRXmlaMember member = new JRXmlaMember(caption, uName, hierName, lName, lNum);
      tuple.setMember(memNum++, member);
    }

    axis.addTuple(tuple);
  }
예제 #13
0
 protected void createBody(SOAPBodyElement body, SOAPFactory spf) throws SOAPException {
   body.addChildElement(spf.createName("MaxEnvelopes")).setValue(String.valueOf(MaxEnvelopes));
 }
예제 #14
0
  @Validated
  @Test
  public void testHeaders() {
    try {
      // Create message factory and SOAP factory
      MessageFactory messageFactory = MessageFactory.newInstance();
      SOAPFactory soapFactory = SOAPFactory.newInstance();

      // Create a message
      SOAPMessage message = messageFactory.createMessage();

      // Get the SOAP header from the message and
      //  add headers to it
      SOAPHeader header = message.getSOAPHeader();

      String nameSpace = "ns";
      String nameSpaceURI = "http://gizmos.com/NSURI";

      Name order = soapFactory.createName("orderDesk", nameSpace, nameSpaceURI);
      SOAPHeaderElement orderHeader = header.addHeaderElement(order);
      orderHeader.setActor("http://gizmos.com/orders");

      Name shipping = soapFactory.createName("shippingDesk", nameSpace, nameSpaceURI);
      SOAPHeaderElement shippingHeader = header.addHeaderElement(shipping);
      shippingHeader.setActor("http://gizmos.com/shipping");

      Name confirmation = soapFactory.createName("confirmationDesk", nameSpace, nameSpaceURI);
      SOAPHeaderElement confirmationHeader = header.addHeaderElement(confirmation);
      confirmationHeader.setActor("http://gizmos.com/confirmations");

      Name billing = soapFactory.createName("billingDesk", nameSpace, nameSpaceURI);
      SOAPHeaderElement billingHeader = header.addHeaderElement(billing);
      billingHeader.setActor("http://gizmos.com/billing");

      // Add header with mustUnderstand attribute
      Name tName = soapFactory.createName("Transaction", "t", "http://gizmos.com/orders");

      SOAPHeaderElement transaction = header.addHeaderElement(tName);
      transaction.setMustUnderstand(true);
      transaction.addTextNode("5");

      // Get the SOAP body from the message but leave
      // it empty
      SOAPBody body = message.getSOAPBody();

      message.saveChanges();

      // Display the message that would be sent
      // System.out.println("\n----- Request Message ----\n");
      // message.writeTo(System.out);

      // Look at the headers
      Iterator allHeaders = header.examineAllHeaderElements();

      while (allHeaders.hasNext()) {
        SOAPHeaderElement headerElement = (SOAPHeaderElement) allHeaders.next();
        Name headerName = headerElement.getElementName();
        // System.out.println("\nHeader name is " +
        //                   headerName.getQualifiedName());
        // System.out.println("Actor is " + headerElement.getActor());
        // System.out.println("mustUnderstand is " +
        //                   headerElement.getMustUnderstand());
      }
    } catch (Exception e) {
      fail("Enexpected Exception " + e);
    }
  }