Java Code Examples for javax.xml.soap.SOAPFault#setFaultCode()

The following examples show how to use javax.xml.soap.SOAPFault#setFaultCode() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SoapServlet.java    From mdw with Apache License 2.0 5 votes vote down vote up
/**
 * Allow version specific factory passed in to support SOAP 1.1 and 1.2
 * <b>Important</b> Faults are treated differently for 1.1 and 1.2 For 1.2
 * you can't use the elementName otherwise it throws an exception
 */
protected String createSoapFaultResponse(String soapVersion, String code, String message)
        throws SOAPException, TransformerException {

    SOAPMessage soapMessage = getSoapMessageFactory(soapVersion).createMessage();
    SOAPBody soapBody = soapMessage.getSOAPBody();
    /**
     * Faults are treated differently for 1.1 and 1.2 For 1.2 you can't use
     * the elementName otherwise it throws an exception
     *
     * @see http://docs.oracle.com/cd/E19159-01/819-3669/bnbip/index.html
     */
    SOAPFault fault = null;
    if (soapVersion.equals(SOAPConstants.SOAP_1_1_PROTOCOL)) {
        // existing 1.1 functionality
        fault = soapBody.addFault(soapMessage.getSOAPHeader().getElementName(), message);
        if (code != null)
            fault.setFaultCode(code);
    }
    else if (soapVersion.equals(SOAPConstants.SOAP_1_2_PROTOCOL)) {
        /**
         * For 1.2 there are only a set number of allowed codes, so we can't
         * just use any one like what we did in 1.1. The recommended one to
         * use is SOAPConstants.SOAP_RECEIVER_FAULT
         */
        fault = soapBody.addFault(SOAPConstants.SOAP_RECEIVER_FAULT,
                code == null ? message : code + " : " + message);

    }
    return DomHelper.toXml(soapMessage.getSOAPPart().getDocumentElement());

}
 
Example 2
Source File: WsaTubeHelper.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public SOAPFault newMapRequiredFault(MissingAddressingHeaderException e) {
    QName subcode = addVer.mapRequiredTag;
    QName subsubcode = addVer.mapRequiredTag;
    String faultstring = addVer.getMapRequiredText();

    try {
        SOAPFactory factory;
        SOAPFault fault;
        if (soapVer == SOAPVersion.SOAP_12) {
            factory = SOAPVersion.SOAP_12.getSOAPFactory();
            fault = factory.createFault();
            fault.setFaultCode(SOAPConstants.SOAP_SENDER_FAULT);
            fault.appendFaultSubcode(subcode);
            fault.appendFaultSubcode(subsubcode);
            getMapRequiredDetail(e.getMissingHeaderQName(), fault.addDetail());
        } else {
            factory = SOAPVersion.SOAP_11.getSOAPFactory();
            fault = factory.createFault();
            fault.setFaultCode(subsubcode);
        }

        fault.setFaultString(faultstring);

        return fault;
    } catch (SOAPException se) {
        throw new WebServiceException(se);
    }
}
 
Example 3
Source File: WsaTubeHelper.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public SOAPFault createInvalidAddressingHeaderFault(InvalidAddressingHeaderException e, AddressingVersion av) {
    QName name = e.getProblemHeader();
    QName subsubcode = e.getSubsubcode();
    QName subcode = av.invalidMapTag;
    String faultstring = String.format(av.getInvalidMapText(), name, subsubcode);

    try {
        SOAPFactory factory;
        SOAPFault fault;
        if (soapVer == SOAPVersion.SOAP_12) {
            factory = SOAPVersion.SOAP_12.getSOAPFactory();
            fault = factory.createFault();
            fault.setFaultCode(SOAPConstants.SOAP_SENDER_FAULT);
            fault.appendFaultSubcode(subcode);
            fault.appendFaultSubcode(subsubcode);
            getInvalidMapDetail(name, fault.addDetail());
        } else {
            factory = SOAPVersion.SOAP_11.getSOAPFactory();
            fault = factory.createFault();
            fault.setFaultCode(subsubcode);
        }

        fault.setFaultString(faultstring);

        return fault;
    } catch (SOAPException se) {
        throw new WebServiceException(se);
    }
}
 
Example 4
Source File: ResponseBuilder.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
private SOAPFaultException createDuplicateHeaderException() {
    try {
        SOAPFault fault = soapVersion.getSOAPFactory().createFault();
        fault.setFaultCode(soapVersion.faultCodeServer);
        fault.setFaultString(ServerMessages.DUPLICATE_PORT_KNOWN_HEADER(headerName));
        return new SOAPFaultException(fault);
    } catch(SOAPException e) {
        throw new WebServiceException(e);
    }
}
 
Example 5
Source File: ResponseBuilder.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
private SOAPFaultException createDuplicateHeaderException() {
    try {
        SOAPFault fault = soapVersion.getSOAPFactory().createFault();
        fault.setFaultCode(soapVersion.faultCodeServer);
        fault.setFaultString(ServerMessages.DUPLICATE_PORT_KNOWN_HEADER(headerName));
        return new SOAPFaultException(fault);
    } catch(SOAPException e) {
        throw new WebServiceException(e);
    }
}
 
Example 6
Source File: EndpointArgumentsBuilder.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private SOAPFaultException createDuplicateHeaderException() {
    try {
        SOAPFault fault = soapVersion.getSOAPFactory().createFault();
        fault.setFaultCode(soapVersion.faultCodeClient);
        fault.setFaultString(ServerMessages.DUPLICATE_PORT_KNOWN_HEADER(headerName));
        return new SOAPFaultException(fault);
    } catch(SOAPException e) {
        throw new WebServiceException(e);
    }
}
 
Example 7
Source File: WsaTubeHelper.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public SOAPFault createInvalidAddressingHeaderFault(InvalidAddressingHeaderException e, AddressingVersion av) {
    QName name = e.getProblemHeader();
    QName subsubcode = e.getSubsubcode();
    QName subcode = av.invalidMapTag;
    String faultstring = String.format(av.getInvalidMapText(), name, subsubcode);

    try {
        SOAPFactory factory;
        SOAPFault fault;
        if (soapVer == SOAPVersion.SOAP_12) {
            factory = SOAPVersion.SOAP_12.getSOAPFactory();
            fault = factory.createFault();
            fault.setFaultCode(SOAPConstants.SOAP_SENDER_FAULT);
            fault.appendFaultSubcode(subcode);
            fault.appendFaultSubcode(subsubcode);
            getInvalidMapDetail(name, fault.addDetail());
        } else {
            factory = SOAPVersion.SOAP_11.getSOAPFactory();
            fault = factory.createFault();
            fault.setFaultCode(subsubcode);
        }

        fault.setFaultString(faultstring);

        return fault;
    } catch (SOAPException se) {
        throw new WebServiceException(se);
    }
}
 
Example 8
Source File: EndpointArgumentsBuilder.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
private SOAPFaultException createDuplicateHeaderException() {
    try {
        SOAPFault fault = soapVersion.getSOAPFactory().createFault();
        fault.setFaultCode(soapVersion.faultCodeClient);
        fault.setFaultString(ServerMessages.DUPLICATE_PORT_KNOWN_HEADER(headerName));
        return new SOAPFaultException(fault);
    } catch(SOAPException e) {
        throw new WebServiceException(e);
    }
}
 
Example 9
Source File: SAAJUtils.java    From cxf with Apache License 2.0 5 votes vote down vote up
public static void setFaultCode(SOAPFault f, QName code) throws SOAPException {
    if (f.getNamespaceURI().equals(Soap12.SOAP_NAMESPACE)) {
        try {
            f.setFaultCode(code);
        } catch (SOAPException ex) {
            f.setFaultCode(SOAPConstants.SOAP_SENDER_FAULT);
            f.appendFaultSubcode(code);
        }
    } else {
        try {
            f.setFaultCode(code);
        } catch (Throwable t) {
            int count = 1;
            String pfx = "fc1";
            while (!StringUtils.isEmpty(f.getNamespaceURI(pfx))) {
                count++;
                pfx = "fc" + count;
            }
            if (code.getNamespaceURI() != null && !"".equals(code.getNamespaceURI())) {
                f.addNamespaceDeclaration(pfx, code.getNamespaceURI());
            } else {
                f.addNamespaceDeclaration(pfx, f.getNamespaceURI());
            }
            f.setFaultCode(pfx + ":" + code.getLocalPart());
        }
    }
}
 
Example 10
Source File: BodyImpl.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public SOAPFault addFault(
     QName faultCode,
     String faultString,
     Locale locale)
     throws SOAPException {

     SOAPFault fault = addFault();
     fault.setFaultCode(faultCode);
     fault.setFaultString(faultString, locale);
     return fault;
 }
 
Example 11
Source File: WsaTubeHelper.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
public SOAPFault createInvalidAddressingHeaderFault(InvalidAddressingHeaderException e, AddressingVersion av) {
    QName name = e.getProblemHeader();
    QName subsubcode = e.getSubsubcode();
    QName subcode = av.invalidMapTag;
    String faultstring = String.format(av.getInvalidMapText(), name, subsubcode);

    try {
        SOAPFactory factory;
        SOAPFault fault;
        if (soapVer == SOAPVersion.SOAP_12) {
            factory = SOAPVersion.SOAP_12.getSOAPFactory();
            fault = factory.createFault();
            fault.setFaultCode(SOAPConstants.SOAP_SENDER_FAULT);
            fault.appendFaultSubcode(subcode);
            fault.appendFaultSubcode(subsubcode);
            getInvalidMapDetail(name, fault.addDetail());
        } else {
            factory = SOAPVersion.SOAP_11.getSOAPFactory();
            fault = factory.createFault();
            fault.setFaultCode(subsubcode);
        }

        fault.setFaultString(faultstring);

        return fault;
    } catch (SOAPException se) {
        throw new WebServiceException(se);
    }
}
 
Example 12
Source File: WsaTubeHelper.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
public SOAPFault newMapRequiredFault(MissingAddressingHeaderException e) {
    QName subcode = addVer.mapRequiredTag;
    QName subsubcode = addVer.mapRequiredTag;
    String faultstring = addVer.getMapRequiredText();

    try {
        SOAPFactory factory;
        SOAPFault fault;
        if (soapVer == SOAPVersion.SOAP_12) {
            factory = SOAPVersion.SOAP_12.getSOAPFactory();
            fault = factory.createFault();
            fault.setFaultCode(SOAPConstants.SOAP_SENDER_FAULT);
            fault.appendFaultSubcode(subcode);
            fault.appendFaultSubcode(subsubcode);
            getMapRequiredDetail(e.getMissingHeaderQName(), fault.addDetail());
        } else {
            factory = SOAPVersion.SOAP_11.getSOAPFactory();
            fault = factory.createFault();
            fault.setFaultCode(subsubcode);
        }

        fault.setFaultString(faultstring);

        return fault;
    } catch (SOAPException se) {
        throw new WebServiceException(se);
    }
}
 
Example 13
Source File: BodyImpl.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public SOAPFault addFault(
    Name faultCode,
    String faultString,
    Locale locale)
    throws SOAPException {

    SOAPFault fault = addFault();
    fault.setFaultCode(faultCode);
    fault.setFaultString(faultString, locale);
    return fault;
}
 
Example 14
Source File: EndpointArgumentsBuilder.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
private SOAPFaultException createDuplicateHeaderException() {
    try {
        SOAPFault fault = soapVersion.getSOAPFactory().createFault();
        fault.setFaultCode(soapVersion.faultCodeClient);
        fault.setFaultString(ServerMessages.DUPLICATE_PORT_KNOWN_HEADER(headerName));
        return new SOAPFaultException(fault);
    } catch(SOAPException e) {
        throw new WebServiceException(e);
    }
}
 
Example 15
Source File: ResponseBuilder.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
private SOAPFaultException createDuplicateHeaderException() {
    try {
        SOAPFault fault = soapVersion.getSOAPFactory().createFault();
        fault.setFaultCode(soapVersion.faultCodeServer);
        fault.setFaultString(ServerMessages.DUPLICATE_PORT_KNOWN_HEADER(headerName));
        return new SOAPFaultException(fault);
    } catch(SOAPException e) {
        throw new WebServiceException(e);
    }
}
 
Example 16
Source File: WsaTubeHelper.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public SOAPFault newMapRequiredFault(MissingAddressingHeaderException e) {
    QName subcode = addVer.mapRequiredTag;
    QName subsubcode = addVer.mapRequiredTag;
    String faultstring = addVer.getMapRequiredText();

    try {
        SOAPFactory factory;
        SOAPFault fault;
        if (soapVer == SOAPVersion.SOAP_12) {
            factory = SOAPVersion.SOAP_12.getSOAPFactory();
            fault = factory.createFault();
            fault.setFaultCode(SOAPConstants.SOAP_SENDER_FAULT);
            fault.appendFaultSubcode(subcode);
            fault.appendFaultSubcode(subsubcode);
            getMapRequiredDetail(e.getMissingHeaderQName(), fault.addDetail());
        } else {
            factory = SOAPVersion.SOAP_11.getSOAPFactory();
            fault = factory.createFault();
            fault.setFaultCode(subsubcode);
        }

        fault.setFaultString(faultstring);

        return fault;
    } catch (SOAPException se) {
        throw new WebServiceException(se);
    }
}
 
Example 17
Source File: WsaTubeHelper.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public SOAPFault createInvalidAddressingHeaderFault(InvalidAddressingHeaderException e, AddressingVersion av) {
    QName name = e.getProblemHeader();
    QName subsubcode = e.getSubsubcode();
    QName subcode = av.invalidMapTag;
    String faultstring = String.format(av.getInvalidMapText(), name, subsubcode);

    try {
        SOAPFactory factory;
        SOAPFault fault;
        if (soapVer == SOAPVersion.SOAP_12) {
            factory = SOAPVersion.SOAP_12.getSOAPFactory();
            fault = factory.createFault();
            fault.setFaultCode(SOAPConstants.SOAP_SENDER_FAULT);
            fault.appendFaultSubcode(subcode);
            fault.appendFaultSubcode(subsubcode);
            getInvalidMapDetail(name, fault.addDetail());
        } else {
            factory = SOAPVersion.SOAP_11.getSOAPFactory();
            fault = factory.createFault();
            fault.setFaultCode(subsubcode);
        }

        fault.setFaultString(faultstring);

        return fault;
    } catch (SOAPException se) {
        throw new WebServiceException(se);
    }
}
 
Example 18
Source File: EndpointArgumentsBuilder.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private SOAPFaultException createDuplicateHeaderException() {
    try {
        SOAPFault fault = soapVersion.getSOAPFactory().createFault();
        fault.setFaultCode(soapVersion.faultCodeClient);
        fault.setFaultString(ServerMessages.DUPLICATE_PORT_KNOWN_HEADER(headerName));
        return new SOAPFaultException(fault);
    } catch(SOAPException e) {
        throw new WebServiceException(e);
    }
}
 
Example 19
Source File: WsaTubeHelper.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public SOAPFault createInvalidAddressingHeaderFault(InvalidAddressingHeaderException e, AddressingVersion av) {
    QName name = e.getProblemHeader();
    QName subsubcode = e.getSubsubcode();
    QName subcode = av.invalidMapTag;
    String faultstring = String.format(av.getInvalidMapText(), name, subsubcode);

    try {
        SOAPFactory factory;
        SOAPFault fault;
        if (soapVer == SOAPVersion.SOAP_12) {
            factory = SOAPVersion.SOAP_12.getSOAPFactory();
            fault = factory.createFault();
            fault.setFaultCode(SOAPConstants.SOAP_SENDER_FAULT);
            fault.appendFaultSubcode(subcode);
            fault.appendFaultSubcode(subsubcode);
            getInvalidMapDetail(name, fault.addDetail());
        } else {
            factory = SOAPVersion.SOAP_11.getSOAPFactory();
            fault = factory.createFault();
            fault.setFaultCode(subsubcode);
        }

        fault.setFaultString(faultstring);

        return fault;
    } catch (SOAPException se) {
        throw new WebServiceException(se);
    }
}
 
Example 20
Source File: BodyImpl.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public SOAPFault addFault(Name faultCode, String faultString)
    throws SOAPException {

    SOAPFault fault = addFault();
    fault.setFaultCode(faultCode);
    fault.setFaultString(faultString);
    return fault;
}