Package de.danet.an.workflow.clients.wfxml

Source Code of de.danet.an.workflow.clients.wfxml.FaultUtils

/*
* This file is part of the WfMOpen project.
* Copyright (C) 2001-2006 Danet GmbH (www.danet.de), BU BTS.
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*
* $Id: FaultUtils.java 2576 2007-11-02 16:00:34Z drmlipp $
*
* $Log$
* Revision 1.5  2007/09/21 22:20:14  mlipp
* Workaround for JDK 1.6 SAAJ bug.
*
* Revision 1.4  2007/03/27 21:59:42  mlipp
* Fixed lots of checkstyle warnings.
*
* Revision 1.3  2007/01/31 22:55:36  mlipp
* Some more refactoring and fixes of problems introduced by refactoring.
*
* Revision 1.2  2007/01/30 11:56:14  drmlipp
* Merged Wf-XML branch.
*
* Revision 1.1.2.1  2006/12/13 11:23:48  schnelle
* Implemented instance ListActivities.
*
*/
package de.danet.an.workflow.clients.wfxml;

import javax.xml.soap.Detail;
import javax.xml.soap.DetailEntry;
import javax.xml.soap.Name;
import javax.xml.soap.SOAPBody;
import javax.xml.soap.SOAPBodyElement;
import javax.xml.soap.SOAPElement;
import javax.xml.soap.SOAPEnvelope;
import javax.xml.soap.SOAPException;
import javax.xml.soap.SOAPFault;
import javax.xml.soap.SOAPMessage;

/**
* This class provides utility methods to fill the {@link SOAPFault} part
* of the response.
*
* @author Dirk Schnelle
*
*/
class FaultUtils {
    /**
     * Sets the detail message of the given exception as the fault string
     * of the SOAP message without specifying a {@link Detail} part.
     * @param message the message, where to set the fault string.
     * @param throwable the throwable
     * @throws SOAPException
     *         error setting the fault string.
     */
    static void setFault(SOAPMessage message, Throwable throwable)
        throws SOAPException {
        SOAPEnvelope respEnv = message.getSOAPPart().getEnvelope();

        SOAPFault fault = respEnv.getBody().addFault();
        fault.setFaultString(throwable.toString());
    }

    /**
     * Sets the detail message of the given exception as the fault string
     * of the SOAP message.
     * @param message the message, where to set the fault string.
     * @param errorCode the ASAP error code
     * @param errorMessage the error message
     * @throws SOAPException
     *         error setting the fault string.
     */
    static void setFault(SOAPMessage message, int errorCode,
            String errorMessage)
        throws SOAPException {
        SOAPEnvelope se = message.getSOAPPart().getEnvelope();

        // Work around for Bug 6581434 in JDK 1.6:
        // javax.xml.soap.Detail.addDetailEntry is broken
        /*
        SOAPFault fault = se.getBody().addFault();
        fault.setFaultString(errorMessage);
       
        Detail detail = fault.addDetail();
        detail.addNamespaceDeclaration(Consts.ASAP_PREFIX, Consts.ASAP_NS);
       
        Name codeName
            = se.createName("ErrorCode", Consts.ASAP_PREFIX, null);
        DetailEntry codeDetail = detail.addDetailEntry(codeName);
        codeDetail.addTextNode(Integer.toString(errorCode));

        Name messageName
            = se.createName("ErrorMessage", Consts.ASAP_PREFIX, null);
        DetailEntry messageDetail = detail.addDetailEntry(messageName);
        messageDetail.addTextNode(errorMessage);
        */
       
        final String SOAP_ENV = "http://schemas.xmlsoap.org/soap/envelope/";
        SOAPBody sb = se.getBody();
        SOAPBodyElement fault
            = sb.addBodyElement(se.createName("Fault", "SOAP_ENV", SOAP_ENV));
        fault.addChildElement("faultstring")
            .addTextNode(errorMessage);
        SOAPElement detail = fault.addChildElement("detail");
        detail.addChildElement
            ("ErrorCode", Consts.ASAP_PREFIX, Consts.ASAP_NS)
            .addTextNode(Integer.toString(errorCode));
        detail.addChildElement
            ("ErrorMessage", Consts.ASAP_PREFIX, Consts.ASAP_NS)
            .addTextNode(errorMessage);
    }
}
TOP

Related Classes of de.danet.an.workflow.clients.wfxml.FaultUtils

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.