Example usage for javax.xml.ws.soap SOAPFaultException SOAPFaultException

List of usage examples for javax.xml.ws.soap SOAPFaultException SOAPFaultException

Introduction

In this page you can find the example usage for javax.xml.ws.soap SOAPFaultException SOAPFaultException.

Prototype

public SOAPFaultException(SOAPFault fault) 

Source Link

Document

Constructor for SOAPFaultException

Usage

From source file:cn.com.ttblog.ssmbootstrap_table.webservice.LicenseHandler.java

@SuppressWarnings("unchecked")
@Override/*from   www .j  a v  a 2 s .co  m*/
public boolean handleMessage(SOAPMessageContext context) {
    try {
        Boolean out = (Boolean) context.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
        logger.debug("LicenseHandler:{}", out);
        if (!out) {
            SOAPMessage message = context.getMessage();
            logger.debug("SOAPMessage:{}", ToStringBuilder.reflectionToString(message));
            SOAPEnvelope enve = message.getSOAPPart().getEnvelope();
            SOAPHeader header = enve.getHeader();
            SOAPBody body = enve.getBody();
            Node bn = body.getChildNodes().item(0);
            String partname = bn.getLocalName();
            if ("getUser".equals(partname)) {
                if (header == null) {
                    // ?
                    SOAPFault fault = body.addFault();
                    fault.setFaultString("??!");
                    throw new SOAPFaultException(fault);
                }
                Iterator<SOAPHeaderElement> iterator = header.extractAllHeaderElements();
                if (!iterator.hasNext()) {
                    // ?
                    SOAPFault fault = body.addFault();
                    fault.setFaultString("??!");
                    throw new SOAPFaultException(fault);
                }
                while (iterator.hasNext()) {
                    SOAPHeaderElement ele = iterator.next();
                    System.out.println(ele.getTextContent());
                }
            }
        }
    } catch (SOAPException e) {
        e.printStackTrace();
    }
    return true;
}

From source file:com.hiperium.integration.access.control.SoapSessionHandler.java

/**
 * /*w  w w  . j a v  a2  s .  c om*/
 * @param msg
 * @param reason
 */
private void generateFault(SOAPMessage msg, String reason) {
    try {
        SOAPBody body = msg.getSOAPBody();
        SOAPFault fault = body.addFault();
        fault.setFaultString(reason);
        throw new SOAPFaultException(fault);
    } catch (SOAPException e) {
        LOGGER.error(e.getMessage(), e);
    }
}

From source file:be.fedict.eid.idp.protocol.saml2.artifact.ArtifactServiceServerHandler.java

private SOAPFaultException createSOAPFaultException(String faultString) {

    SOAPFault soapFault;/*from   w ww  .ja v a 2s  .  c o  m*/
    try {
        SOAPFactory soapFactory = SOAPFactory.newInstance();
        soapFault = soapFactory.createFault();
        soapFault.setFaultString(faultString);
    } catch (SOAPException e) {
        throw new RuntimeException("SOAP error");
    }

    return new SOAPFaultException(soapFault);
}

From source file:com.qubit.solution.fenixedu.bennu.webservices.services.server.BennuWebServiceHandler.java

private void generateSOAPErrorMessage(SOAPMessage msg, String reason) {
    try {/*from w w w . j a  v a  2  s.  c o  m*/
        SOAPBody soapBody = msg.getSOAPPart().getEnvelope().getBody();
        SOAPFault soapFault = soapBody.addFault();
        soapFault.setFaultString(reason);
        throw new SOAPFaultException(soapFault);
    } catch (SOAPException e) {
    }
}

From source file:be.fedict.trust.xkms2.WSSecurityServerHandler.java

public static SOAPFaultException createSOAPFaultException(String faultString, String wsseFaultCode) {

    SOAPFault soapFault;//from  ww  w . j a  v  a  2  s . co m
    try {
        SOAPFactory soapFactory = SOAPFactory.newInstance();
        soapFault = soapFactory.createFault(faultString,
                new QName("http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd",
                        wsseFaultCode, "wsse"));
    } catch (SOAPException e) {
        throw new RuntimeException("SOAP error");
    }
    return new SOAPFaultException(soapFault);
}

From source file:edu.duke.cabig.c3pr.webservice.studyimportexport.impl.StudyImportExportImpl.java

/**
 * Creates the soap fault exception./*  ww  w. j  av  a  2  s  .c  om*/
 *
 * @param msg the msg
 * @return the sOAP fault exception
 */
private SOAPFaultException createSOAPFaultException(String msg) {
    return new SOAPFaultException(createSOAPFault(msg));
}

From source file:de.unibi.techfak.bibiserv.BiBiTools.java

/**
 * Returns a SOAPFaultException with specified
 *
 * @param faultcode/*from ww w .  j a  v  a  2s.  c om*/
 * @param faultstring
 * @param hobitstatuscode
 * @param hobitstatusdescription
 * @return
 */
public static SOAPFaultException createSOAPFaultException(String faultcode, String faultstring,
        String hobitstatuscode, String hobitstatusdescription) {
    SOAPFault fault = null;
    try {
        SOAPFactory sfi = SOAPFactory.newInstance();
        fault = sfi.createFault();

        fault.setFaultCode(new QName("http://schemas.xmlsoap.org/soap/envelope/", faultcode, "soap"));
        fault.setFaultString(faultstring);
        if (hobitstatuscode != null && hobitstatusdescription != null) {
            Detail detail = fault.addDetail();
            DetailEntry detailentry = detail.addDetailEntry(new QName(
                    "http://hobit.sourceforge.net/xsds/hobitStatuscode.xsd", "hobitStatuscode", "status"));

            SOAPElement statuscode = detailentry.addChildElement(
                    new QName("http://hobit.sourceforge.net/xsds/hobitStatuscode.xsd", "statuscode", "status"));
            statuscode.addTextNode(hobitstatuscode);

            SOAPElement description = detailentry.addChildElement(new QName(
                    "http://hobit.sourceforge.net/xsds/hobitStatuscode.xsd", "description", "status"));
            description.addTextNode(hobitstatusdescription);
        }

    } catch (SOAPException e) {
        log.fatal("SOAPException occured : " + e.getMessage());
    }

    return new SOAPFaultException(fault);

}

From source file:org.apache.axis2.jaxws.marshaller.impl.alt.MethodMarshallerUtils.java

/**
 * Create a system exception/*from   w ww  .java2s.c  o  m*/
 *
 * @param message
 * @return
 */
public static ProtocolException createSystemException(XMLFault xmlFault, Message message) {
    ProtocolException e = null;
    Protocol protocol = message.getProtocol();
    String text = xmlFault.getReason().getText();

    if (protocol == Protocol.soap11 || protocol == Protocol.soap12) {
        // Throw a SOAPFaultException
        if (log.isDebugEnabled()) {
            log.debug("Constructing SOAPFaultException for " + text);
        }
        String protocolNS = (protocol == Protocol.soap11) ? SOAPConstants.URI_NS_SOAP_1_1_ENVELOPE
                : SOAPConstants.URI_NS_SOAP_1_2_ENVELOPE;
        try {
            // The following set of instructions is used to avoid 
            // some unimplemented methods in the Axis2 SAAJ implementation
            javax.xml.soap.MessageFactory mf = SAAJFactory.createMessageFactory(protocolNS);
            SOAPBody body = mf.createMessage().getSOAPBody();
            SOAPFault soapFault = XMLFaultUtils.createSAAJFault(xmlFault, body);
            e = new SOAPFaultException(soapFault);
        } catch (Exception ex) {
            // Exception occurred during exception processing.
            // TODO Probably should do something better here
            if (log.isDebugEnabled()) {
                log.debug("Exception occurred during fault processing:", ex);
            }
            e = ExceptionFactory.makeProtocolException(text, null);
        }
    } else if (protocol == Protocol.rest) {
        if (log.isDebugEnabled()) {
            log.debug("Constructing ProtocolException for " + text);
        }
        // TODO Is there an explicit exception for REST
        e = ExceptionFactory.makeProtocolException(text, null);
    } else if (protocol == Protocol.unknown) {
        // REVIEW What should happen if there is no protocol
        if (log.isDebugEnabled()) {
            log.debug("Constructing ProtocolException for " + text);
        }
        e = ExceptionFactory.makeProtocolException(text, null);
    }
    return e;
}

From source file:org.apache.cxf.ws.security.sts.provider.SecurityTokenServiceProvider.java

public Source invoke(Source request) {
    Source response = null;/* ww w .  ja va  2s  .c o  m*/
    try {
        RequestSecurityTokenType rst = convertToJAXBObject(request);
        Object operationImpl = null;
        List<?> objectList = rst.getAny();
        for (int i = 0; i < objectList.size(); i++) {
            Object obj = objectList.get(i);
            if (obj instanceof JAXBElement) {
                QName qname = ((JAXBElement<?>) obj).getName();
                if (qname.equals(new QName(WSTRUST_13_NAMESPACE, WSTRUST_REQUESTTYPE_ELEMENTNAME))) {
                    operationImpl = operationMap.get(((JAXBElement<?>) obj).getValue().toString());
                    break;
                }

            }
        }

        if (operationImpl == null) {
            throw new Exception("Implementation for this operation not found.");
        }
        Method[] methods = operationImpl.getClass().getMethods();
        for (int x = 0; x < methods.length; x++) {
            Class<?>[] paramClass = methods[x].getParameterTypes();
            if (paramClass.length == 1 && paramClass[0].equals(rst.getClass())) {
                RequestSecurityTokenResponseCollectionType tokenResponse = (RequestSecurityTokenResponseCollectionType) methods[x]
                        .invoke(operationImpl, rst);
                if (tokenResponse == null) {
                    throw new Exception("Error in implementation class.");
                }

                response = new JAXBSource(jaxbContext,
                        new ObjectFactory().createRequestSecurityTokenResponseCollection(tokenResponse));
                return response;
            }
        }

    } catch (Exception e) {
        LOG.error(e);
        try {
            SOAPFault fault = soapFactory.createFault();
            if (e.getMessage() == null) {
                fault.setFaultString(e.getCause().getMessage());
            } else {
                fault.setFaultString(e.getMessage());
            }
            Detail detail = fault.addDetail();
            detail = fault.getDetail();
            QName qName = new QName(WSTRUST_13_NAMESPACE, "Fault", "ns");
            DetailEntry de = detail.addDetailEntry(qName);
            qName = new QName(WSTRUST_13_NAMESPACE, "ErrorCode", "ns");
            SOAPElement errorElement = de.addChildElement(qName);
            StackTraceElement[] ste = e.getStackTrace();
            errorElement.setTextContent(ste[0].toString());
            throw new SOAPFaultException(fault);
        } catch (SOAPException e1) {
            LOG.error(e1);
        }

    }

    return response;
}