Example usage for javax.xml.soap SOAPBody hasFault

List of usage examples for javax.xml.soap SOAPBody hasFault

Introduction

In this page you can find the example usage for javax.xml.soap SOAPBody hasFault.

Prototype

public boolean hasFault();

Source Link

Document

Indicates whether a SOAPFault object exists in this SOAPBody object.

Usage

From source file:com.inbravo.scribe.rest.service.crm.ms.auth.SOAPExecutor.java

/**
 * Executes SOAP message/*from w  w w. ja v a  2 s . co  m*/
 * 
 * @param endpointUrl SOAP endpoint
 * @param message SOAP request
 * @return SOAP response message
 * @throws SOAPException in case of a SOAP issue
 * @throws IOException in case of an IO issue
 */
private final SOAPMessage execute(final String endpointUrl, final SOAPMessage message) throws Exception {
    SOAPConnection conn = null;
    try {

        /* Create new SOAP connection */
        conn = SOAPConnectionFactory.newInstance().createConnection();

        if (logger.isDebugEnabled()) {
            logger.debug("----Inside execute, going to execute SOAP message : "
                    + message.getSOAPBody().getTextContent());
        }

        /* Call SOAP service */
        final SOAPMessage response = conn.call(message, endpointUrl);

        /* Get SOAP response body */
        final SOAPBody body = response.getSOAPBody();

        if (logger.isDebugEnabled()) {
            logger.debug("----Inside execute, has fault? :  " + body.hasFault());
        }

        if (body.hasFault() && body.getFault() != null) {

            logger.error("----Inside execute, fault :  " + body.getFault().getTextContent()
                    + ", fault reason : " + body.getFault().getFaultString());

            /* Throw error */
            throw new SOAPException(body.getFault().getTextContent());
        }
        return response;
    } catch (final Exception e) {

        logger.error("----Inside execute, error recieved :  " + e.getMessage() + ", error : " + e);

        /* Throw user error */
        throw new SOAPException(e);
    } finally {
        if (conn != null) {
            conn.close();
        }
    }
}

From source file:edu.xtec.colex.client.beans.ColexIndexBean.java

/**
 * Calls the web service operation <I>deleteCollection(User,Collection) :
 * void</I>/*  w  w  w  .ja va2  s .  c om*/
 *
 * @param sCollection the String name of the Collection to delete
 * @throws javax.xml.soap.SOAPException when a SOAPException error occurs
 */
private void deleteCollection(String sCollection) throws SOAPException {
    User uRequest = new User(getUserId());

    try {

        smRequest = mf.createMessage();

        SOAPBodyElement sbeRequest = setRequestName(smRequest, "deleteCollection");

        addParam(sbeRequest, uRequest);
        addParam(sbeRequest, new Collection(sCollection));

        smRequest.saveChanges();

        SOAPMessage smResponse = sendMessage(smRequest,
                this.getJspProperties().getProperty("url.servlet.collection"));

        SOAPBody sbResponse = smResponse.getSOAPBody();

        if (sbResponse.hasFault()) {
            checkFault(sbResponse, "delete");
        } else {
        }
    } catch (SOAPException se) {
        throw se;
    }
}

From source file:edu.xtec.colex.client.beans.ColexIndexBean.java

/**
 * Calls the web service operation <I>listGuestCollections (User) :
 * [Collection+Guest]</I>// www .  j a v a 2 s  .c  o  m
 *
 * @throws javax.xml.soap.SOAPException when a SOAPException error occurs
 */
private void listGuestCollections() throws SOAPException {
    logger.debug("listGuestCollections IN <<");
    User uRequest = new User(getUserId());
    Vector vGuestCollections = new Vector();

    try {

        smRequest = mf.createMessage();

        SOAPBodyElement sbeRequest = setRequestName(smRequest, "listGuestCollections");

        addParam(sbeRequest, uRequest);

        smRequest.saveChanges();

        SOAPMessage smResponse = sendMessage(smRequest,
                this.getJspProperties().getProperty("url.servlet.share"));

        SOAPBody sbResponse = smResponse.getSOAPBody();

        if (sbResponse.hasFault()) {
            checkFault(sbResponse, "listGuestCollections");
        } else {
            vGuestCollections = getListGuestCollections(smResponse);

            if (vGuestCollections != null) {
                vCollections.addAll(vGuestCollections);
            }
        }
        logger.debug("listGuestCollections OUT >> " + vCollections);
    } catch (SOAPException se) {
        throw se;
    }
}

From source file:edu.xtec.colex.client.beans.ColexIndexBean.java

/**
 * Calls the web service operation <I>createCollection(User,Collection) :
 * void</I>/* ww w. j  a v  a  2s . c  o  m*/
 *
 * @param sCollection the String name of the Collection to create
 * @throws javax.xml.soap.SOAPException when a SOAPException error occurs
 * @throws java.io.IOException when an IOException error occurs
 */
private void createCollection(String sCollection) throws SOAPException, IOException {
    User uRequest = new User(getUserId());
    Collection cRequest = new Collection(sCollection);

    cRequest.setDescription("");
    cRequest.setTags("");
    cRequest.setIsPublic(0);

    try {

        smRequest = mf.createMessage();

        SOAPBodyElement sbeRequest = setRequestName(smRequest, "createCollection");

        addParam(sbeRequest, uRequest);
        addParam(sbeRequest, cRequest);

        smRequest.saveChanges();

        SOAPMessage smResponse = sendMessage(smRequest,
                this.getJspProperties().getProperty("url.servlet.collection"));

        SOAPBody sbResponse = smResponse.getSOAPBody();

        if (sbResponse.hasFault()) {
            checkFault(sbResponse, "create");
        } else {
            try {
                String sRedirectPage = buildRedirectURL(request, "structure.jsp?collection=" + sCollection);
                response.sendRedirect(sRedirectPage);
            } catch (IOException ioe) {
                throw ioe;
            }
        }
    } catch (SOAPException se) {
        throw se;
    }
}

From source file:edu.xtec.colex.client.beans.ColexIndexBean.java

/**
 * Calls the web service operation <I>importCollection(User,Collection,FILE)
 * : void</I>/*from   www  .  j  a va  2 s. c  om*/
 *
 * @param importName the String name of the Collection to import
 * @param fiImport the FileItem Zip of the Collection to import
 * @throws java.lang.Exception when an Exception error occurs
 */
private void importCollection(String importName, FileItem fiImport) throws Exception {
    User uRequest = new User(getUserId());
    Collection cRequest = new Collection(importName);
    File fTemp = null;

    try {
        smRequest = mf.createMessage();

        SOAPBody sbRequest = smRequest.getSOAPBody();

        Name n = sf.createName("importCollection");

        SOAPBodyElement sbeRequest = sbRequest.addBodyElement(n);

        sbeRequest.addChildElement(uRequest.toXml());
        sbeRequest.addChildElement(cRequest.toXml());

        String sNomFitxer = Utils.getFileName(fiImport.getName());

        fTemp = File.createTempFile("attach", null);

        fiImport.write(fTemp);

        URL urlFile = new URL("file://" + fTemp.getPath());

        AttachmentPart ap = smRequest.createAttachmentPart(new DataHandler(urlFile));

        smRequest.addAttachmentPart(ap);

        smRequest.saveChanges();

        SOAPMessage smResponse = sendMessage(smRequest,
                this.getJspProperties().getProperty("url.servlet.collection"));

        SOAPBody sbResponse = smResponse.getSOAPBody();

        if (sbResponse.hasFault()) {
            checkFault(sbResponse, "import");
        } else {

        }

    } catch (Exception e) {
        throw e;
    } finally {
        if (fTemp != null) {
            fTemp.delete();
        }
    }
}

From source file:edu.xtec.colex.client.beans.ColexIndexBean.java

/**
 * Calls the web service operation <I>listCollections(User) :
 * [Collection]</I>/*from   www  .j  a va  2 s. c om*/
 *
 * @throws javax.xml.soap.SOAPException when a SOAPException error occurs
 */
private void listCollections() throws SOAPException {
    logger.debug("ListCollections IN << ");
    User uRequest = new User(getUserId());
    logger.debug("uRequest: " + uRequest);

    vCollections = new Vector();

    try {

        smRequest = mf.createMessage();
        logger.debug("smRequest: " + smRequest);

        SOAPBodyElement sbeRequest = setRequestName(smRequest, "listCollections");

        addParam(sbeRequest, uRequest);

        smRequest.saveChanges();
        logger.debug("sbeRequest: " + sbeRequest);

        SOAPMessage smResponse = sendMessage(smRequest,
                this.getJspProperties().getProperty("url.servlet.collection"));
        logger.debug("smResponse: " + smResponse);

        SOAPBody sbResponse = smResponse.getSOAPBody();
        logger.debug("sbResponse: " + sbResponse);

        if (sbResponse.hasFault()) {
            logger.debug("sbResponse.hasFault() IN ");
            checkFault(sbResponse, "list");
            logger.debug("sbResponse.hasFault() OUT");
        } else {
            vCollections = getCollections(smResponse);
            iOwnedCollections = vCollections.size();
        }
        logger.debug("ListCollections OUT >> " + vCollections);
    } catch (SOAPException se) {
        throw se;
    }
}

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
 *  //  www  . j a  va  2  s  .  co m
 * @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:edu.xtec.colex.client.beans.ColexRecordBean.java

/**
 * Calls the web service operation//from  w  w  w  .  j  av a  2 s .co m
 * <I>deleteRecord(User,Owner,Collection,Record) : void</I>
 *
 * @throws javax.xml.soap.SOAPException when a SOAPException error occurs
 */
protected void deleteRecord() throws SOAPException {
    User u = new User(getUserId());

    Collection c = new Collection("");
    Record r = new Record();

    r.setId(Integer.parseInt(pmRequest.getParameter("idRecord")));
    c.setName(collection);

    try {
        smRequest = mf.createMessage();

        SOAPBodyElement sbeRequest = setRequestName(smRequest, "deleteRecord");

        addParam(sbeRequest, u);
        if (owner != null) {
            Owner oRequest = new Owner(owner);
            addParam(sbeRequest, oRequest);
        }
        addParam(sbeRequest, c);
        addParam(sbeRequest, r);

        smRequest.saveChanges();

        SOAPMessage smResponse = sendMessage(smRequest,
                this.getJspProperties().getProperty("url.servlet.record"));

        SOAPBody sbResponse = smResponse.getSOAPBody();

        if (sbResponse.hasFault()) {
            checkFault(sbResponse, "delete");
        } else {

        }
    } catch (SOAPException se) {
        throw se;
    }
}

From source file:edu.xtec.colex.client.beans.ColexRecordBean.java

/**
 * Calls the web service operation <I>getStructure(User,Owner,Collection) :
 * [FieldDef]</I>//from  w  w w.  ja  v a2s  .c o  m
 *
 * @throws javax.xml.soap.SOAPException when a SOAPException error occurs
 */
protected void getStructure() throws SOAPException {
    User u = new User("");

    if (sUserVisitor != null) {
        u.setUserId(sUserVisitor);
    } else {
        u = new User(getUserId());
    }

    vFieldDefs = new Vector();

    try {
        smRequest = mf.createMessage();

        SOAPBodyElement sbeRequest = setRequestName(smRequest, "getStructure");

        addParam(sbeRequest, u);

        if (owner != null) {
            Owner oRequest = new Owner(owner);
            addParam(sbeRequest, oRequest);
        }
        addParam(sbeRequest, new Collection(collection));

        smRequest.saveChanges();

        SOAPMessage smResponse = sendMessage(smRequest,
                getJspProperties().getProperty("url.servlet.structure"));

        SOAPBody sbResponse = smResponse.getSOAPBody();

        if (sbResponse.hasFault()) {
            checkFault(sbResponse, "get");
        } else {
            vFieldDefs = getFieldDefs(smResponse);
        }

    } catch (SOAPException se) {
        throw se;
    }

}

From source file:edu.xtec.colex.client.beans.ColexRecordBean.java

/**
 * Calls the web service operation <I>getPermission
 * (User,Owner,Collection,Record) : Guest</I>
 *
 * @throws javax.xml.soap.SOAPException when a SOAPException error occurs
 *//*from   ww w.j  a v a 2  s . c o m*/
protected void getPermission() throws SOAPException {
    User u = new User("");

    if (sUserVisitor != null) {
        u.setUserId(sUserVisitor);
    } else {
        u = new User(getUserId());
    }

    Owner o = new Owner(owner);
    Collection c = new Collection(collection);

    try {
        smRequest = mf.createMessage();

        SOAPBodyElement sbeRequest = setRequestName(smRequest, "getPermission");

        addParam(sbeRequest, u);
        addParam(sbeRequest, o);
        addParam(sbeRequest, c);
        if (record != null) {
            Record r = new Record();
            r.setId(record.getId());
            addParam(sbeRequest, r);
        }

        smRequest.saveChanges();

        SOAPMessage smResponse = sendMessage(smRequest,
                this.getJspProperties().getProperty("url.servlet.share"));

        SOAPBody sbResponse = smResponse.getSOAPBody();

        if (sbResponse.hasFault()) {
            checkFault(sbResponse, "getPermission");
        } else {
            permission = getIntValue(smResponse, "permission");
        }
    } catch (SOAPException se) {
        throw se;
    }
}