Example usage for javax.xml.soap SOAPFault getFaultCode

List of usage examples for javax.xml.soap SOAPFault getFaultCode

Introduction

In this page you can find the example usage for javax.xml.soap SOAPFault getFaultCode.

Prototype

public String getFaultCode();

Source Link

Document

Gets the fault code for this SOAPFault object.

Usage

From source file:com.evolveum.midpoint.testing.wstest.AbstractWebserviceTest.java

protected void assertSoapFault(SOAPFaultException e, String expectedCode, String expectedMessage) {
    SOAPFault fault = e.getFault();
    String faultCode = fault.getFaultCode();
    display("SOAP fault code: " + faultCode);
    assertTrue("Unexpected fault code: " + faultCode, faultCode.endsWith(expectedCode));
    String message = e.getMessage();
    assertTrue("Unexpected fault message: " + message, message.contains(expectedMessage));
}

From source file:org.jasig.portal.security.provider.saml.SAMLDelegatedAuthenticationService.java

/**
 * Assume that the InputStream has a SOAP fault message and return a String
 * suitable to present as an exception message
 *  /*w w w .  j a  v a2  s  . c  om*/
 * @param is InputStream that contains a SOAP message
 * @return String containing a formated error message
 * 
 * @throws IOException
 * @throws SOAPException
 */
private String getSOAPFaultAsString(InputStream is) throws IOException, SOAPException {
    is.reset();
    MessageFactory factory = MessageFactory.newInstance();
    SOAPMessage message = factory.createMessage(null, is);
    SOAPBody body = message.getSOAPBody();

    if (body.hasFault()) {
        SOAPFault fault = body.getFault();
        String code, string, actor;
        code = fault.getFaultCode();
        string = fault.getFaultString();
        actor = fault.getFaultActor();
        String formatedMessage = "SOAP transaction resulted in a SOAP fault.";

        if (code != null)
            formatedMessage += "  Code=\"" + code + ".\"";

        if (string != null)
            formatedMessage += "  String=\"" + string + ".\"";

        if (actor != null)
            formatedMessage += "  Actor=\"" + actor + ".\"";

        return formatedMessage;
    }
    return null;
}

From source file:it.cnr.icar.eric.common.SOAPMessenger.java

/**
 * Convert SOAPFault back to RegistryException (if possible)
 * @param fault SOAPFault//from  www  .  j av a  2s. co m
 * @return RegistryException
 */
RegistryException createRegistryException(SOAPFault fault) {
    RegistryException result = null;

    //is this message too generic?
    String unknownError = resourceBundle.getString("message.unknown");

    if (log.isDebugEnabled()) {
        log.debug(fault.toString());
    }

    String exceptionName = null;
    if (fault.getFaultCode().startsWith(BindingUtility.SOAP_FAULT_PREFIX)) {
        // Old style faultcode value, skip prefix and colon
        exceptionName = fault.getFaultCode().substring(BindingUtility.SOAP_FAULT_PREFIX.length() + 1);
    } else if ( // TODO: SAAJ 1.3 has introduced preferred QName interfaces
    fault.getFaultCodeAsName().getURI().equals(BindingUtility.SOAP_FAULT_PREFIX)) {
        // New style
        exceptionName = fault.getFaultCodeAsName().getLocalName();
    }

    if (null == exceptionName) {
        // not a recognized ebXML fault
        result = new RegistryException(unknownError);
    } else {
        // ebXML fault
        String exceptionMessage = fault.getFaultString();
        unknownError = resourceBundle.getString("message.exception",
                new String[] { exceptionName, exceptionMessage });

        /*
           Detail detail = fault.getDetail();
           Iterator iter = detail.getDetailEntries();
           int i=0;
           while (iter.hasNext()) {
        DetailEntry detailEntry = (DetailEntry)iter.next();
        unknownError += " detailEntry[" + i++ + "] = " + detailEntry.toString();
           }
         **/

        //TODO: get and reconstruct Stacktrace
        try {

            Class<?> exceptionClass = null;
            //exceptionClass = Class.forName("it.cnr.icar.eric.common.exceptions." + exceptionName);
            exceptionClass = Class.forName(exceptionName);

            if (RegistryException.class.isAssignableFrom(exceptionClass)) {
                //Exception is a RegistryException. Reconstitute it as a RegistryException

                // NPE has null message..
                if (exceptionMessage != null) {
                    @SuppressWarnings("rawtypes")
                    Class[] parameterDefinition = { String.class };
                    Constructor<?> exceptionConstructor = exceptionClass.getConstructor(parameterDefinition);
                    Object[] parameters = { exceptionMessage };
                    result = (RegistryException) exceptionConstructor.newInstance(parameters);
                } else {
                    @SuppressWarnings("rawtypes")
                    Class[] parameterDefinition = {};
                    Constructor<?> exceptionConstructor = exceptionClass.getConstructor(parameterDefinition);
                    Object[] parameters = {};
                    result = (RegistryException) exceptionConstructor.newInstance(parameters);
                }
            } else {
                //Exception is not a RegistryException.

                //Make it a RegistryException with exceptionMessage
                //In future make it a nested Throwable of a RegistryException
                // NPE has null message..
                result = new RegistryException(unknownError);
            }
        } catch (ClassNotFoundException e) {
            //could happen with non-eric server?
            result = new RegistryException(unknownError, e);
        } catch (NoSuchMethodException e) {
            //should not happen
            result = new RegistryException(unknownError, e);
        } catch (IllegalAccessException e) {
            //happens when?
            result = new RegistryException(unknownError, e);
        } catch (InvocationTargetException e) {
            //happens when?
            result = new RegistryException(unknownError, e);
        } catch (InstantiationException e) {
            //happens when trying to instantiate Interface
            result = new RegistryException(unknownError, e);
        }
    }
    return result;
}

From source file:net.sf.jasperreports.olap.xmla.JRXmlaQueryExecuter.java

protected void handleResultFault(SOAPFault fault) {
    StringBuilder errorMsg = new StringBuilder();
    errorMsg.append("XML/A fault: ");

    String faultString = fault.getFaultString();
    if (faultString != null) {
        errorMsg.append(faultString);// www  .  j a v  a 2 s .c o m
        errorMsg.append("; ");
    }

    String faultActor = fault.getFaultActor();
    if (faultActor != null) {
        errorMsg.append("Actor: ");
        errorMsg.append(faultActor);
        errorMsg.append("; ");
    }

    String faultCode = fault.getFaultCode();
    if (faultCode != null) {
        errorMsg.append("Code: ");
        errorMsg.append(faultCode);
        errorMsg.append("; ");
    }

    throw new JRRuntimeException(errorMsg.toString());
}

From source file:com.jaspersoft.ireport.designer.data.fieldsproviders.olap.OLAPQueryExecuter.java

protected void handleResultFault(SOAPFault fault) {
    StringBuffer errorMsg = new StringBuffer();
    errorMsg.append("XML/A fault: ");

    String faultString = fault.getFaultString();
    if (faultString != null) {
        errorMsg.append(faultString);/*w  ww .  j a va  2  s .  c o m*/
        errorMsg.append("; ");
    }

    String faultActor = fault.getFaultActor();
    if (faultActor != null) {
        errorMsg.append("Actor: ");
        errorMsg.append(faultActor);
        errorMsg.append("; ");
    }

    String faultCode = fault.getFaultCode();
    if (faultCode != null) {
        errorMsg.append("Code: ");
        errorMsg.append(faultCode);
        errorMsg.append("; ");
    }

    throw new JRRuntimeException(errorMsg.toString());
}

From source file:org.apache.ws.scout.transport.SaajTransport.java

public Element send(Element request, URI endpointURL) throws TransportException {
    if (log.isDebugEnabled()) {
        String requestMessage = XMLUtils.convertNodeToXMLString(request);
        log.debug("Request message: %s\n%s" + endpointURL + ":" + requestMessage);
    }/* w w w  .  ja va 2 s  .  co m*/

    Element response = null;
    try {
        SOAPMessage message = this.createSOAPMessage(request);
        //Make the SAAJ Call now
        SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance();
        SOAPConnection connection = soapConnectionFactory.createConnection();
        SOAPMessage soapResponse = connection.call(message, endpointURL.toURL());

        SOAPBody soapBody = soapResponse.getSOAPBody();
        boolean hasFault = soapBody.hasFault();
        if (hasFault) {
            SOAPFault soapFault = soapBody.getFault();
            String faultStr = soapFault.getFaultCode() + "::" + soapFault.getFaultString();
            throw new RegistryException(faultStr);
        }
        response = getFirstChildElement(soapBody);
    } catch (Exception ex) {
        log.error("Exception::" + ex.getMessage(), ex);
        throw new TransportException(ex);
    }
    if (log.isDebugEnabled()) {
        String responseMessage = XMLUtils.convertNodeToXMLString(response);
        log.debug("Response message: %s" + responseMessage);
    }

    return response;
}

From source file:org.jboss.jaxr.juddi.transport.SaajTransport.java

/**
 * @see Transport#send(org.w3c.dom.Element, java.net.URL)
 *//* w ww . ja v a2 s .  co m*/
public Element send(Element request, URL endpointURL) throws RegistryException {
    String requestMessage = XMLUtils.toString(request);
    log.debug("Request message:" + requestMessage);

    Element response = null;
    try {
        SOAPMessage message = this.createSOAPMessage(request);
        //Make the SAAJ Call now
        SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance();
        SOAPConnection connection = soapConnectionFactory.createConnection();
        SOAPMessage soapResponse = connection.call(message, endpointURL);

        SOAPBody soapBody = soapResponse.getSOAPBody();
        boolean hasFault = soapBody.hasFault();
        if (hasFault) {
            SOAPFault soapFault = soapBody.getFault();
            String faultStr = soapFault.getFaultCode() + "::" + soapFault.getFaultString();
            throw new RegistryException(faultStr);
        }
        response = getFirstChildElement(soapBody);
    } catch (Exception ex) {
        log.error("Exception::", ex);
        throw new RegistryException(ex);
    }

    log.debug("Response message:" + XMLUtils.getText(response));
    return response;
}

From source file:org.jboss.jaxr.juddi.transport.WS4EESaajTransport.java

public Element send(Element request, URL endpointURL) throws RegistryException {
    log.debug("Request message:" + XMLUtils.toString(request));
    if ("true".equalsIgnoreCase(debugProp))
        System.out.println("Request Element:" + XMLUtils.toString(request));

    Element response = null;//from  ww  w. ja v a  2 s  .co m
    try {
        MessageFactory msgFactory = MessageFactory.newInstance();
        SOAPMessage message = msgFactory.createMessage();
        message.getSOAPHeader().detachNode();
        SOAPPart soapPart = message.getSOAPPart();
        SOAPBody soapBody = soapPart.getEnvelope().getBody();
        soapBody.addChildElement(getSOAPElement(soapBody, request));
        //There seems to be a bug in the Saaj/Axis implementation that requires
        //message to be written to an output stream
        ByteArrayOutputStream by = new ByteArrayOutputStream();
        message.writeTo(by); //Does not do anything
        by.close();
        if ("true".equalsIgnoreCase(debugProp))
            message.writeTo(System.out);

        //Make the SAAJ Call now
        SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance();
        SOAPConnection connection = soapConnectionFactory.createConnection();
        SOAPMessage soapResponse = connection.call(message, endpointURL);
        if ("true".equalsIgnoreCase(debugProp)) {
            System.out.println("Response is:");
            soapResponse.writeTo(System.out);
        }

        soapBody = soapResponse.getSOAPBody();
        boolean hasFault = soapBody.hasFault();
        if (hasFault) {
            SOAPFault soapFault = soapBody.getFault();
            String faultStr = soapFault.getFaultCode() + "::" + soapFault.getFaultString();
            throw new RegistryException(faultStr);
        }
        response = getFirstChildElement(soapBody);
    } catch (Exception ex) {
        ex.printStackTrace();
        log.error(ex);
        throw new RegistryException(ex);
    }

    log.debug("Response message:" + XMLUtils.getText(response));

    return response;
}

From source file:org.pentaho.platform.plugin.action.xmla.XMLABaseComponent.java

/**
 * check SOAP reply for Error, return fault Code
 *
 * @param reply   the message to check//from ww w  .ja  va2  s . c  o m
 * @param aReturn ArrayList containing faultcode,faultstring,faultactor
 */
private boolean soapFault(final SOAPMessage reply, final String[] faults) throws SOAPException {
    SOAPPart sp = reply.getSOAPPart();
    SOAPEnvelope envelope = sp.getEnvelope();
    SOAPBody body = envelope.getBody();
    if (!body.hasFault()) {
        return false;
    }
    SOAPFault fault = body.getFault();

    faults[0] = fault.getFaultCode();
    faults[1] = fault.getFaultString();
    faults[2] = fault.getFaultActor();

    // probably not neccessary with Microsoft;
    Detail detail = fault.getDetail();
    if (detail == null) {
        return true;
    }
    String detailMsg = ""; //$NON-NLS-1$
    Iterator it = detail.getDetailEntries();
    for (; it.hasNext();) {
        DetailEntry det = (DetailEntry) it.next();
        Iterator ita = det.getAllAttributes();
        for (boolean cont = false; ita.hasNext(); cont = true) {
            Name name = (Name) ita.next();
            if (cont) {
                detailMsg += "; "; //$NON-NLS-1$
            }
            detailMsg += name.getLocalName();
            detailMsg += " = "; //$NON-NLS-1$
            detailMsg += det.getAttributeValue(name);
        }
    }
    faults[3] = detailMsg;

    return true;
}