Example #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);
    }
  }
Example #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);
    }
  }
Example #3
0
 /**
  * Forms a SOAP Fault and puts it in the SOAP Message's Body.
  *
  * @param faultcode fault code to be set in SOAPMEssage
  * @param faultString fault string
  * @param detail the details of the fault condition
  * @return <code>SOAPMessage</code> containing the SOAP fault
  */
 public SOAPMessage formSOAPError(String faultcode, String faultString, String detail) {
   SOAPMessage msg = null;
   SOAPEnvelope envelope = null;
   SOAPFault sf = null;
   SOAPBody body = null;
   SOAPElement se = null;
   try {
     msg = fac.createMessage();
     envelope = msg.getSOAPPart().getEnvelope();
     body = envelope.getBody();
     sf = body.addFault();
     Name qname = envelope.createName(faultcode, null, IFSConstants.SOAP_URI);
     sf.setFaultCode(qname);
     sf.setFaultString(FSUtils.bundle.getString(faultString));
     if ((detail != null) && !(detail.length() == 0)) {
       Detail det = sf.addDetail();
       se = (SOAPElement) det.addDetailEntry(envelope.createName("Problem"));
       se.addAttribute(envelope.createName("details"), FSUtils.bundle.getString(detail));
     }
   } catch (SOAPException e) {
     FSUtils.debug.error("FSSOAPService.formSOAPError:", e);
     return null;
   }
   return msg;
 }
Example #4
0
 @Validated
 @Test
 public final void testAddDetailEntryUsingQName() throws Exception {
   Detail detail = createEmptySOAPFault().addDetail();
   DetailEntry detailEntry = detail.addDetailEntry(new QName("urn:ns", "mydetail", "p"));
   assertEquals("urn:ns", detailEntry.getNamespaceURI());
   assertEquals("mydetail", detailEntry.getLocalName());
   assertEquals("p", detailEntry.getPrefix());
   assertSame(detailEntry, detail.getFirstChild());
 }
Example #5
0
 @Validated
 @Test
 public final void testAddDetailEntryUsingName() throws Exception {
   SOAPEnvelope envelope = createSOAPEnvelope();
   Detail detail = envelope.addBody().addFault().addDetail();
   DetailEntry detailEntry = detail.addDetailEntry(envelope.createName("mydetail", "p", "urn:ns"));
   assertEquals("urn:ns", detailEntry.getNamespaceURI());
   assertEquals("mydetail", detailEntry.getLocalName());
   assertEquals("p", detailEntry.getPrefix());
   assertSame(detailEntry, detail.getFirstChild());
 }
Example #6
0
 @Validated
 @Test
 public final void testAddDetailEntryUsingQNameWithoutNamespace() throws Exception {
   Detail detail = createEmptySOAPFault().addDetail();
   DetailEntry detailEntry = detail.addDetailEntry(new QName("mydetail"));
   // TODO: Sun's implementation returns an empty string here (which I believe is incorrect)
   //        assertNull(detailEntry.getNamespaceURI());
   assertEquals("mydetail", detailEntry.getLocalName());
   assertNull(detailEntry.getPrefix());
   assertSame(detailEntry, detail.getFirstChild());
 }
  private boolean isFileNotFound(SOAPFaultException e) {
    Detail detail = e.getFault().getDetail();
    NodeList childNodes = detail.getChildNodes();

    for (int i = 0; i < childNodes.getLength(); ++i) {
      // I hate soap...
      if (childNodes.item(i).getNodeName().equals("FileNotFoundFault")) {
        return true;
      }
    }
    return false;
  }
Example #8
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());
 }
Example #9
0
 /**
  * Creates a SOAPDetail element from SOS exception document.
  *
  * @param detail SOAPDetail
  * @param exception SOS Exception document
  * @throws SOAPException if an error occurs.
  */
 private void createSOAPFaultDetail(Detail detail, CodedException exception) throws SOAPException {
   SOAPElement exRep = detail.addChildElement(OWSConstants.QN_EXCEPTION);
   exRep.addNamespaceDeclaration(OWSConstants.NS_OWS_PREFIX, OWSConstants.NS_OWS);
   String code = exception.getCode().toString();
   String locator = exception.getLocator();
   StringBuilder exceptionText = new StringBuilder();
   exceptionText.append(exception.getMessage());
   exceptionText.append(LINE_SEPARATOR_CHAR);
   if (exception.getCause() != null) {
     exceptionText.append(LINE_SEPARATOR_CHAR).append("[EXCEPTION]: ").append(LINE_SEPARATOR_CHAR);
     if (exception.getCause().getLocalizedMessage() != null
         && !exception.getCause().getLocalizedMessage().isEmpty()) {
       exceptionText.append(exception.getCause().getLocalizedMessage());
       exceptionText.append(LINE_SEPARATOR_CHAR);
     }
     if (exception.getCause().getMessage() != null
         && !exception.getCause().getMessage().isEmpty()) {
       exceptionText.append(exception.getCause().getMessage());
       exceptionText.append(LINE_SEPARATOR_CHAR);
     }
   }
   exRep.addAttribute(new QName(OWSConstants.EN_EXCEPTION_CODE), code);
   if (locator != null && !locator.isEmpty()) {
     exRep.addAttribute(new QName(OWSConstants.EN_LOCATOR), locator);
   }
   if (exceptionText.length() != 0) {
     SOAPElement execText = exRep.addChildElement(OWSConstants.QN_EXCEPTION_TEXT);
     execText.setTextContent(exceptionText.toString());
   }
 }
Example #10
0
 public Detail getDetail() {
   if (detail == null) initializeDetail();
   if ((detail != null) && (detail.getParentNode() == null)) {
     // a detach node was called on it
     detail = null;
   }
   return detail;
 }