コード例 #1
0
 public static Source getSoapFaultSource(SoapFaultClientException sp) {
   SoapFaultDetail details = sp.getSoapFault().getFaultDetail();
   Source s = null;
   if (details != null) {
     Iterator<SoapFaultDetailElement> iter = details.getDetailEntries();
     SoapFaultDetailElement elmt = (SoapFaultDetailElement) iter.next();
     s = elmt.getSource();
     return s;
   }
   return s;
 }
コード例 #2
0
  /**
   * Calls {@link WebServiceTemplate#marshalSendAndReceive(Object)} on the passed in argument, and
   * returns the result.
   *
   * <p>In the event a SOAP Fault occurs (e.g. {@link SoapFaultClientException}, this method
   * inspects the faultStringOrReason field. Based on the contents of that field, this method may
   * throw a {@link ClientRuntimeException} or return null.
   *
   * <p>null return values are used as hints to callers that they should throw either the checked
   * {@link ClassNotFoundException}.
   *
   * @param request
   * @return the result of {@link WebServiceTemplate#marshalSendAndReceive(Object)}, or null if the
   *     caller should throw a {@link ClassNotFoundException}
   * @throws AuthenticationFailedException if the username/password configured on the
   *     webServiceTemplate are incorrect
   * @throws AuthorizationFailedException if the user is authenticated but not authorized to call
   *     the particular method
   * @throws WebServiceFaultException for other soap faults
   */
  @SuppressWarnings("unchecked")
  protected <T> T internalInvoke(Object request) {
    final WebServiceOperations webServiceOperations = this.getWebServiceOperations();
    try {
      return (T) webServiceOperations.marshalSendAndReceive(request, this.soapActionCallback);
    } catch (SoapFaultClientException e) {
      final StringBuilder errorMessage = new StringBuilder("Failed to call ");
      errorMessage.append(this.soapActionCallback.getSoapAction());
      errorMessage.append(" with ");
      errorMessage.append(request);

      final SoapFault soapFault = e.getSoapFault();
      final SoapFaultDetail faultDetail = soapFault.getFaultDetail();

      for (final Iterator<SoapFaultDetailElement> detailEntryItr = faultDetail.getDetailEntries();
          detailEntryItr.hasNext(); ) {
        final SoapFaultDetailElement detailEntry = detailEntryItr.next();
        final Source source = detailEntry.getSource();

        //		        TODO Once PS adds a namespace declaration to the fault document unmarshaller can
        // be used to pull out the error message
        //              final Object result = this.unmarshaller.unmarshal(source);

        final Node node = this.getNode(source);
        if (node == null) {
          // Couldn't turn the source into a node, no detailed error message for us :(
          continue;
        }

        final String defaultTitle = evaluateXPath(node, "DefaultTitle");
        final String defaultMessage = evaluateXPath(node, "DefaultMessage");

        errorMessage.append("\n\t").append(defaultTitle).append(" - ").append(defaultMessage);
      }

      final WebServiceFaultException webServiceFaultException =
          new WebServiceFaultException(errorMessage.toString());
      webServiceFaultException.initCause(e);
      throw webServiceFaultException;
    }
  }