Пример #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);
    }
  }
Пример #2
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;
 }
Пример #3
0
 /**
  * Creates a SOAPFault element from SOS internal fault
  *
  * @param fault SOAPFault element
  * @param soapFault SOS internal fault
  * @throws SOAPException if an error occurs.
  */
 protected void createSOAPFault(SOAPFault fault, SoapFault soapFault) throws SOAPException {
   fault.setFaultCode(soapFault.getFaultCode());
   fault.setFaultString(soapFault.getFaultReason(), soapFault.getLocale());
   if (soapFault.getDetailText() != null) {
     fault.addDetail().setTextContent(soapFault.getDetailText());
   }
 }
Пример #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;
  }
Пример #5
0
 @Validated
 @Test
 public final void testSetFaultString() throws Exception {
   SOAPFault fault = createEmptySOAPFault();
   fault.setFaultString("test");
   Node child = fault.getFirstChild();
   assertTrue(child instanceof SOAPFaultElement);
   checkFaultStringElement((SOAPFaultElement) child);
 }
  protected final Message createSoapFaultMessage(
      RuntimeContext rc, boolean attachSequenceFaultElement) {
    try {
      // TODO P1 where to set soap fault code?
      SOAPFault soapFault = rc.soapVersion.saajSoapFactory.createFault();

      // common SOAP1.1 and SOAP1.2 Fault settings
      if (faultReasonText != null) {
        soapFault.setFaultString(faultReasonText, java.util.Locale.ENGLISH);
      }

      soapFault.setFaultCode(getCode().asQName(rc.soapVersion));

      // SOAP version-specific SOAP Fault settings
      switch (rc.soapVersion) {
        case SOAP_11:
          break;
        case SOAP_12:
          soapFault.appendFaultSubcode(getSubcode(rc.rmVersion));
          soapFault.addDetail().setValue(getDetailValue());
          break;
        default:
          throw new RxRuntimeException(
              "Unsupported SOAP version: '" + rc.soapVersion.toString() + "'");
      }

      Message soapFaultMessage = Messages.create(soapFault);

      if (attachSequenceFaultElement && rc.soapVersion == SOAPVersion.SOAP_11) {
        soapFaultMessage
            .getHeaders()
            .add(
                rc.protocolHandler.createSequenceFaultElementHeader(
                    getSubcode(rc.rmVersion), getDetailValue()));
      }

      return soapFaultMessage;

    } catch (SOAPException ex) {
      throw new RxRuntimeException("Error creating a SOAP fault", ex);
    }
  }