Example usage for javax.xml.soap SOAPFault getFaultString

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

Introduction

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

Prototype

public String getFaultString();

Source Link

Document

Gets the fault string for this SOAPFault object.

Usage

From source file:com.palominolabs.crm.sf.soap.MetadataConnectionImplTest.java

License:asdf

private static void assertInvalidSession(ApiException e) {
    assertEquals("Call failed", e.getMessage());
    Throwable cause = e.getCause();
    assertTrue(cause instanceof SOAPFaultException);
    SOAPFaultException soapFaultException = (SOAPFaultException) cause;

    String expectedMsg = "INVALID_SESSION_ID: Invalid Session ID found in SessionHeader: Illegal Session. Session not found, missing session key: ";

    String actualMsg = soapFaultException.getMessage();
    assertEquals(expectedMsg, truncateSessionId(actualMsg));

    SOAPFault fault = soapFaultException.getFault();

    QName codeQname = fault.getFaultCodeAsQName();
    assertEquals("INVALID_SESSION_ID", codeQname.getLocalPart());

    String faultMsg = fault.getFaultString();
    assertEquals(expectedMsg, truncateSessionId(faultMsg));
}

From source file:com.jkoolcloud.tnt4j.streams.custom.inputs.CastIronWsStream.java

/**
 * Handles response contained SOAP fault. If fault indicates expired/invalid session id reissues {@code "login"}
 * request./*from   w ww . j  av  a2  s.  c  om*/
 *
 * @param fault
 *            SOAP fault to handle
 * @param scenario
 *            scenario of failed request
 */
@Override
protected void handleFault(SOAPFault fault, WsScenario scenario) {
    if (fault.getFaultString().equals("Expired or invalid session ID")) { // TODO use code
        faultHandlingLock.lock();
        try {
            if (scenario.getLoginStep() == null || scenario.getLoginStep().isEmpty()) {
                throw new RuntimeException(
                        StreamsResources.getStringFormatted(WsStreamConstants.RESOURCE_BUNDLE_NAME,
                                "CastIronStream.empty.login.step", scenario.getName()));
            }

            login(scenario.getLoginStep());
            String cachedToken = String.valueOf(StreamsCache.getValue(tokenCacheKey));
            throw new RuntimeException(
                    StreamsResources.getStringFormatted(WsStreamConstants.RESOURCE_BUNDLE_NAME,
                            "CastIronStream.logged.in.after.fault", scenario.getName(), cachedToken));
        } finally {
            faultHandlingLock.unlock();
        }
    } else {
        super.handleFault(fault, scenario);
    }
}

From source file:com.legstar.proxy.invoke.jaxws.WebServiceInvoker.java

/**
 * Try to extract something meaningful from a SOAP Fault.
 * //from  w  ww  .  ja  v a2s. c  o m
 * @param e the SOAP Fault exception
 * @return a fault description
 */
@SuppressWarnings("rawtypes")
public String getFaultReasonText(final SOAPFaultException e) {
    if (_log.isDebugEnabled()) {
        SOAPFault fault = e.getFault();
        if (fault != null) {
            QName code = fault.getFaultCodeAsQName();
            String string = fault.getFaultString();
            String actor = fault.getFaultActor();
            _log.debug("SOAP fault contains: ");
            _log.debug("  Fault code = " + code.toString());
            _log.debug("  Local name = " + code.getLocalPart());
            _log.debug("  Namespace prefix = " + code.getPrefix() + ", bound to " + code.getNamespaceURI());
            _log.debug("  Fault string = " + string);
            if (actor != null) {
                _log.debug("  Fault actor = " + actor);
            }
            Detail detail = fault.getDetail();
            if (detail != null) {
                Iterator entries = detail.getDetailEntries();
                while (entries.hasNext()) {
                    DetailEntry newEntry = (DetailEntry) entries.next();
                    String value = newEntry.getValue();
                    _log.debug("  Detail entry = " + value);
                }
            }
        } else {
            _log.debug(e);
        }
    }
    SOAPFault fault = e.getFault();
    if (fault != null) {
        StringBuffer faultMessage = new StringBuffer(e.getFault().getFaultString());
        Detail detail = fault.getDetail();
        if (detail != null) {
            Iterator entries = detail.getDetailEntries();
            while (entries.hasNext()) {
                DetailEntry newEntry = (DetailEntry) entries.next();
                faultMessage.append(" [" + newEntry.getValue() + "]");
            }
        }
        return faultMessage.toString();
    } else {
        return e.getMessage();
    }

}

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);// w ww.j  ava  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.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
 *  //from  w w  w. ja v a 2  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: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);//from   w  w w  .jav  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.streamreduce.util.JiraClient.java

public SOAPMessage invokeSoap(JiraStudioApp app, String soapBody) throws SOAPException {
    String cacheKey = (app + "-SOAP-" + soapBody.hashCode());
    Object objectFromCache = requestCache.getIfPresent(cacheKey);

    if (objectFromCache != null) {
        debugLog(LOGGER, "  (From cache)");
        return (SOAPMessage) objectFromCache;
    }//from  www  .j  a v  a  2 s  .com

    // Wrap the SOAP body content in an envelope/body container
    StringBuilder sb = new StringBuilder();
    String soapBaseURL = getBaseUrl();
    String soapNamespaceURL;

    sb.append("<soapenv:Envelope ").append("xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" ")
            .append("xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" ")
            .append("xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" ");

    switch (app) {
    case CONFLUENCE:
        soapNamespaceURL = "http://soap.rpc.confluence.atlassian.com";
        soapBaseURL += "/wiki/rpc/soap-axis/confluenceservice-v1";
        break;
    case JIRA:
        soapNamespaceURL = "http://soap.rpc.jira.atlassian.com";
        soapBaseURL += "/rpc/soap/jirasoapservice-v2";
        break;
    default:
        throw new SOAPException("Unknown Jira Studio application: " + app);
    }

    sb.append("xmlns:soap=\"" + soapNamespaceURL + "\">\n");
    sb.append("<soapenv:Body>\n");
    sb.append(soapBody);
    sb.append("</soapenv:Body></soapenv:Envelope>");

    String rawResponse;
    List<Header> requestHeaders = new ArrayList<>();

    requestHeaders.add(new BasicHeader("SOAPAction", ""));

    try {
        rawResponse = HTTPUtils.openUrl(soapBaseURL, "POST", sb.toString(), MediaType.TEXT_XML, null, null,
                requestHeaders, null);
    } catch (Exception e) {
        LOGGER.error(String.format("Unable to make SOAP call to %s: %s", soapBaseURL, e.getMessage()), e);
        throw new SOAPException(e);
    }

    Source response = new StreamSource(new StringReader(rawResponse));
    MessageFactory msgFactory = MessageFactory.newInstance();
    SOAPMessage message = msgFactory.createMessage();
    SOAPPart env = message.getSOAPPart();
    env.setContent(response);

    if (message.getSOAPBody().hasFault()) {
        SOAPFault fault = message.getSOAPBody().getFault();
        LOGGER.error("soap fault in jira soap response: " + fault.getFaultString());
    }

    requestCache.put(cacheKey, message);

    return message;
}

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

/**
 * Convert SOAPFault back to RegistryException (if possible)
 * @param fault SOAPFault/*from w  w  w  .  ja v a2  s.c  o 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: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);
    }/*from   ww w. ja  v  a 2s.c  o 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.belio.service.gateway.SafcomGateway.java

private boolean sendMessage(QueueType queueType, Outbox outbox) {
    try {//w  w  w.j a v a2 s . co m
        String now = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date());
        MessageDigest md = MessageDigest.getInstance("MD5");
        String serviceId = outbox.getServiceID();
        String endpointDef = "";
        //            if (queueType.equals(QueueType.BULK)) {
        //                endpointDef = networkproperties.getProperty("safcom_mt_endpoint");
        //            } else {
        endpointDef = networkproperties.getProperty("safcom_endpoint");
        // }
        String code = outbox.getShortCode();
        String spIdString = outbox.getSdpId();
        String spPasswordString = createSpPass(spIdString, now, md);
        String recepient = "tel:" + outbox.getMsisdn();
        String actualmessage = URLDecoder.decode(URLEncoder.encode(outbox.getText(), "UTF-8"), "UTF-8");
        Launcher.LOG.info("T----------------------------------------J" + actualmessage);
        String gencorrelator = String.valueOf(outbox.getRefNo());
        // Create SOAP Connection
        SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance();
        SOAPConnection soapConnection = soapConnectionFactory.createConnection();
        // Send SOAP Message to SOAP Server
        SOAPMessage messageToSend = getSoapMessageFromString(getMessage(spIdString, spPasswordString, recepient,
                serviceId, now, actualmessage, code, gencorrelator, endpointDef));
        Calendar start = Calendar.getInstance();
        SOAPMessage soapResponse = soapConnection.call(messageToSend,
                networkproperties.getProperty("safcom_sms"));
        Launcher.LOG.info(
                recepient + " - took " + (Calendar.getInstance().getTimeInMillis() - start.getTimeInMillis()));
        //            SOAPMessage soapResponse = null;
        System.out.println("XXXXXXXXXXXXXXXXXXX====Sending Safaricom message");
        //            printSOAPResponse(soapResponse);//TODO log
        SOAPBody body = soapResponse.getSOAPBody();
        if (body.hasFault()) {
            SOAPFault newFault = body.getFault();
            //                QName fcode = newFault.getFaultCodeAsQName();
            //                String string = newFault.getFaultString();
            //                String actor = newFault.getFaultActor();
            // System.out.println(">>>>>>>>>>>>>"+fcode);
            System.out.println(">>>>>>>>>>>>>" + newFault.getFaultString());
            soapConnection.close();
            return false;
        } else {
            //TO DO log
            soapConnection.close();
            return true;

        }
    } catch (Exception ex) {
        Launcher.LOG.info(ex.getMessage());
    }

    return false;
}