Exemplo n.º 1
0
  protected Throwable getProtocolException() {
    try {
      SOAPFault fault = SOAPVersion.SOAP_12.getSOAPFactory().createFault();
      ;
      if (reason != null) {
        for (TextType tt : reason.texts()) {
          fault.setFaultString(tt.getText());
        }
      }

      if (code != null) {
        fault.setFaultCode(code.getValue());
        fillFaultSubCodes(fault, code.getSubcode());
      }

      if (detail != null && detail.getDetail(0) != null) {
        javax.xml.soap.Detail detail = fault.addDetail();
        for (Node obj : this.detail.getDetails()) {
          Node n = fault.getOwnerDocument().importNode(obj, true);
          detail.appendChild(n);
        }
      }

      if (node != null) {
        fault.setFaultNode(node);
      }

      return new ServerSOAPFaultException(fault);
    } catch (SOAPException e) {
      throw new WebServiceException(e);
    }
  }
Exemplo n.º 2
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);
    }
  }
Exemplo n.º 3
0
 @Validated
 @Test
 public final void testCreateDetailEntryUsingCreateElementNS() throws Exception {
   SOAPFault fault = createEmptySOAPFault();
   Detail detail = fault.addDetail();
   detail.appendChild(fault.getOwnerDocument().createElementNS("urn:ns", "p:test"));
   Iterator<?> it = detail.getDetailEntries();
   assertTrue(it.hasNext());
   // The implementation silently replaces the Element by a DetailEntry
   DetailEntry detailEntry = (DetailEntry) it.next();
   assertEquals("urn:ns", detailEntry.getNamespaceURI());
   assertEquals("test", detailEntry.getLocalName());
 }
Exemplo n.º 4
0
  static SOAPFault createSoapFault(SOAPBinding binding, Exception ex) throws SOAPException {
    SOAPFault soapFault;
    try {
      soapFault = binding.getSOAPFactory().createFault();
    } catch (Throwable t) {
      // probably an old version of saaj or something that is not allowing createFault
      // method to work.  Try the saaj 1.2 method of doing this.
      try {
        soapFault = binding.getMessageFactory().createMessage().getSOAPBody().addFault();
      } catch (Throwable t2) {
        // still didn't work, we'll just throw what we have
        return null;
      }
    }

    if (ex instanceof SoapFault) {
      if (!soapFault.getNamespaceURI().equals(((SoapFault) ex).getFaultCode().getNamespaceURI())
          && SOAPConstants.URI_NS_SOAP_1_1_ENVELOPE.equals(
              ((SoapFault) ex).getFaultCode().getNamespaceURI())) {
        // change to 1.1
        try {
          soapFault = SOAPFactory.newInstance().createFault();
        } catch (Throwable t) {
          // ignore
        }
      }
      soapFault.setFaultString(((SoapFault) ex).getReason());
      soapFault.setFaultCode(((SoapFault) ex).getFaultCode());
      soapFault.setFaultActor(((SoapFault) ex).getRole());

      Node nd = soapFault.getOwnerDocument().importNode(((SoapFault) ex).getOrCreateDetail(), true);
      nd = nd.getFirstChild();
      soapFault.addDetail();
      while (nd != null) {
        Node next = nd.getNextSibling();
        soapFault.getDetail().appendChild(nd);
        nd = next;
      }

    } else {
      String msg = ex.getMessage();
      if (msg != null) {
        soapFault.setFaultString(msg);
      }
    }
    return soapFault;
  }