本文整理匯總了Java中javax.xml.soap.SOAPBody.addFault方法的典型用法代碼示例。如果您正苦於以下問題:Java SOAPBody.addFault方法的具體用法?Java SOAPBody.addFault怎麽用?Java SOAPBody.addFault使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.xml.soap.SOAPBody
的用法示例。
在下文中一共展示了SOAPBody.addFault方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: addFault
import javax.xml.soap.SOAPBody; //導入方法依賴的package包/類
/**
* Adds a SOAP fault to the SOAP message of this response.
*
* @param code the fault code.
* @param actor the fault actor.
* @param desc the fault description.
* @return the SOAP fault which has been added to the SOAP message. null if
* there is no SOAP message in this response or the fault has
* already been added.
* @throws SOAPException a SOAP error occurred when adding the the fault.
*/
public SOAPFault addFault(String code, String actor, String desc)
throws SOAPException {
SOAPMessage msg = getMessage();
if (msg != null) {
SOAPEnvelope env = msg.getSOAPPart().getEnvelope();
SOAPBody body = env.getBody();
if (body != null && !body.hasFault()) {
SOAPFault fault = body.addFault();
if (code != null) {
fault.setFaultCode(env.getElementName().getPrefix() + ":"
+ code);
}
if (actor != null) {
fault.setFaultActor(actor);
}
if (desc != null) {
fault.setFaultString(desc);
}
return fault;
}
}
return null;
}
示例2: testCustomFault11
import javax.xml.soap.SOAPBody; //導入方法依賴的package包/類
/**
* Test Custom FaultQName for SOAP 1.1
* @throws Exception
*/
public void testCustomFault11() throws Exception {
MessageFactory mf = MessageFactory.newInstance(SOAPConstants.SOAP_1_1_PROTOCOL);
SOAPMessage sm = mf.createMessage();
SOAPBody body = sm.getSOAPBody();
SOAPFault fault = body.addFault(CUSTOM, "Custom Fault");
XMLFault xmlFault = XMLFaultUtils.createXMLFault(fault);
assertTrue(xmlFault != null);
XMLFaultReason reason = xmlFault.getReason();
assertTrue(reason != null);
assertTrue(reason.getText().equals("Custom Fault"));
XMLFaultCode code = xmlFault.getCode();
assertTrue(code != null);
QName codeQName = code.toQName(SOAPConstants.URI_NS_SOAP_1_1_ENVELOPE);
assertTrue("Expected QName = " + CUSTOM + " but received = " + codeQName, codeQName.equals(CUSTOM));
}
示例3: testCustomFault12
import javax.xml.soap.SOAPBody; //導入方法依賴的package包/類
/**
* Test Custom FaultQName for SOAP 1.2
* @throws Exception
*/
public void testCustomFault12() throws Exception {
MessageFactory mf = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
SOAPMessage sm = mf.createMessage();
SOAPBody body = sm.getSOAPBody();
try {
SOAPFault fault = body.addFault(CUSTOM, "Custom Fault");
fail("Expected Failure, custom fault codes are not supported with SOAP 1.2");
} catch (SOAPException e) {
// Expected...
} catch (Throwable t) {
fail("Expected different failure, received: " + t);
}
}
示例4: createSOAPFault
import javax.xml.soap.SOAPBody; //導入方法依賴的package包/類
SOAPFault createSOAPFault() throws SOAPException {
SOAPFault soapFault = null;
// REVIEW: The following does not work due to Axis2 SAAJ problems.
//
// SOAPFactory soapFactory = SOAPFactory.newInstance();
// SOAPFault soapFault = soapFactory.createFault();
// Alternate Approach
org.apache.axiom.soap.SOAPFactory asf = DOOMAbstractFactory.getSOAP11Factory();
org.apache.axiom.soap.impl.dom.SOAPEnvelopeImpl axiomEnv = (org.apache.axiom.soap.impl.dom.SOAPEnvelopeImpl) asf.createSOAPEnvelope();
javax.xml.soap.SOAPEnvelope env = new SOAPEnvelopeImpl(axiomEnv);
SOAPBody body = env.addBody();
soapFault = body.addFault();
return soapFault;
}
示例5: _testFaults
import javax.xml.soap.SOAPBody; //導入方法依賴的package包/類
public void _testFaults() throws Exception {
SOAPEnvelope envelope = getSOAPEnvelope();
SOAPBody body = envelope.getBody();
assertFalse(body.hasFault());
SOAPFault soapFault = body.addFault();
soapFault.setFaultString("myFault");
soapFault.setFaultCode("CODE");
assertTrue(body.hasFault());
assertNotNull(body.getFault());
assertSame(soapFault, body.getFault());
assertEquals("myFault", soapFault.getFaultString());
assertEquals("CODE", soapFault.getFaultCode());
}
示例6: testFaultCodeWithPrefix2
import javax.xml.soap.SOAPBody; //導入方法依賴的package包/類
@Test
public void testFaultCodeWithPrefix2() throws Exception {
MessageFactory fac = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
SOAPMessage soapMessage = fac.createMessage();
SOAPPart soapPart = soapMessage.getSOAPPart();
SOAPEnvelope envelope = soapPart.getEnvelope();
SOAPBody body = envelope.getBody();
SOAPFault sf = body.addFault();
String prefix = "wso2";
sf.setFaultCode(prefix + ":Server");
String result = sf.getFaultCode();
assertNotNull(result);
assertEquals(prefix + ":Server", result);
}
示例7: testFaultCodeWithPrefix1
import javax.xml.soap.SOAPBody; //導入方法依賴的package包/類
@Test
public void testFaultCodeWithPrefix1() throws Exception {
MessageFactory fac = MessageFactory.newInstance();
SOAPMessage soapMessage = fac.createMessage();
SOAPPart soapPart = soapMessage.getSOAPPart();
SOAPEnvelope envelope = soapPart.getEnvelope();
SOAPBody body = envelope.getBody();
SOAPFault sf = body.addFault();
String prefix = "wso2";
sf.setFaultCode(prefix + ":Server");
String result = sf.getFaultCode();
assertNotNull(result);
assertEquals(prefix + ":Server", result);
}
示例8: _testGetFaultReasonTexts
import javax.xml.soap.SOAPBody; //導入方法依賴的package包/類
public void _testGetFaultReasonTexts() throws Exception {
MessageFactory fac = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
SOAPMessage soapMessage = fac.createMessage();
SOAPPart soapPart = soapMessage.getSOAPPart();
SOAPEnvelope envelope = soapPart.getEnvelope();
envelope.addNamespaceDeclaration("cwmp", "http://cwmp.com");
SOAPBody body = envelope.getBody();
SOAPFault soapFault = body.addFault();
soapFault.addFaultReasonText("myReason", new Locale("en"));
soapFault.addFaultReasonText("de-myReason", new Locale("de"));
soapFault.addFaultReasonText("si-myReason", new Locale("si"));
soapMessage.saveChanges();
Iterator reasonTexts = soapFault.getFaultReasonTexts();
while (reasonTexts.hasNext()) {
String reasonText = (String)reasonTexts.next();
assertNotNull(reasonText);
}
}
示例9: testAddFault
import javax.xml.soap.SOAPBody; //導入方法依賴的package包/類
@Validated @Test
public void testAddFault() {
try {
MessageFactory fact = MessageFactory.newInstance();
SOAPMessage message = fact.createMessage();
SOAPPart soapPart = message.getSOAPPart();
SOAPEnvelope soapEnvelope = soapPart.getEnvelope();
SOAPBody soapBody = soapEnvelope.getBody();
QName qname = new QName("http://test.apache.org/", "Child1", "ch");
String value = "MyFault";
SOAPFault soapFault = soapBody.addFault(qname, value);
message.saveChanges();
assertNotNull(soapFault);
assertTrue(soapFault instanceof SOAPFault);
} catch (Exception e) {
fail("Unexpected Exception : " + e);
}
}
示例10: testSetFaultStringLocale
import javax.xml.soap.SOAPBody; //導入方法依賴的package包/類
@Validated @Test
public void testSetFaultStringLocale() throws Exception {
MessageFactory fac = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
//MessageFactory fac = MessageFactory.newInstance();
SOAPMessage soapMessage = fac.createMessage();
SOAPPart soapPart = soapMessage.getSOAPPart();
SOAPEnvelope envelope = soapPart.getEnvelope();
SOAPBody body = envelope.getBody();
SOAPFault sf = body.addFault();
Locale expected = Locale.ENGLISH;
sf.setFaultString("this is the fault string", expected);
Locale result = sf.getFaultStringLocale();
assertNotNull(result);
assertTrue(result.equals(expected));
}
示例11: testHasDetail
import javax.xml.soap.SOAPBody; //導入方法依賴的package包/類
@Validated @Test
public void testHasDetail() throws Exception {
MessageFactory fac = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
//MessageFactory fac = MessageFactory.newInstance();
SOAPMessage soapMessage = fac.createMessage();
SOAPPart soapPart = soapMessage.getSOAPPart();
SOAPEnvelope envelope = soapPart.getEnvelope();
envelope.addNamespaceDeclaration("cwmp", "http://cwmp.com");
SOAPBody body = envelope.getBody();
SOAPFault soapFault = body.addFault();
Detail detail = soapFault.addDetail();
detail.setAttribute("test", "myvalue");
soapMessage.saveChanges();
}
示例12: getSOAPMessage
import javax.xml.soap.SOAPBody; //導入方法依賴的package包/類
/**
* Get SOAP Fault message from the information given.
*
* @return <code>SOAPMessage</code> object containing Fault element.
*/
public SOAPMessage getSOAPMessage() {
try {
final MessageFactory mf = MessageFactory.newInstance();
final SOAPMessage message = (SOAPMessage)mf.createMessage();
// set default SOAP XML declaration and encoding
message.setProperty(SOAPMessage.WRITE_XML_DECLARATION,
Boolean.toString(EbxmlMessage.WRITE_XML_DECLARATION));
message.setProperty(SOAPMessage.CHARACTER_SET_ENCODING,
EbxmlMessage.CHARACTER_SET_ENCODING);
final SOAPPart part = message.getSOAPPart();
final SOAPEnvelope envelope = part.getEnvelope();
final SOAPBody body = envelope.getBody();
final SOAPFault fault = body.addFault();
fault.setFaultCode(errorCode);
fault.setFaultString(errorString);
if (faultActor != null) {
fault.setFaultActor(faultActor);
}
if (detail != null) {
Detail d = fault.addDetail();
Name name = envelope.createName(ELEMENT_ERROR,
NAMESPACE_PREFIX_CECID, NAMESPACE_URI_CECID);
DetailEntry entry = d.addDetailEntry(name);
entry.addTextNode(detail);
}
return message;
}
catch (SOAPException e) {
}
return null;
}
示例13: createSoapFaultResponse
import javax.xml.soap.SOAPBody; //導入方法依賴的package包/類
/**
* 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
*
* @see http://docs.oracle.com/cd/E19159-01/819-3669/bnbip/index.html
*
* @param factory
* @param code
* @param message
* @return Xml fault string
* @throws SOAPException
* @throws TransformerException
*/
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());
}
示例14: replaceByJPlagException
import javax.xml.soap.SOAPBody; //導入方法依賴的package包/類
/**
* Manually builds up a JPlagException SOAP message and replaces the
* original one with it
*/
public void replaceByJPlagException(SOAPMessageContext smsg, String desc, String rep) {
try {
SOAPMessage msg = smsg.getMessage();
SOAPEnvelope envelope = msg.getSOAPPart().getEnvelope();
/*
* Remove old header andy body
*/
SOAPHeader oldheader = envelope.getHeader();
if (oldheader != null)
oldheader.detachNode();
SOAPBody oldbody = envelope.getBody();
if (oldbody != null)
oldbody.detachNode();
SOAPBody sb = envelope.addBody();
SOAPFault sf = sb.addFault(envelope.createName("Server", "env", SOAPConstants.URI_NS_SOAP_ENVELOPE),
"jplagWebService.server.JPlagException");
Detail detail = sf.addDetail();
DetailEntry de = detail.addDetailEntry(envelope.createName("JPlagException", "ns0", JPLAG_WEBSERVICE_BASE_URL + "types"));
SOAPElement e = de.addChildElement("exceptionType");
e.addTextNode("accessException");
e = de.addChildElement("description");
e.addTextNode(desc);
e = de.addChildElement("repair");
e.addTextNode(rep);
} catch (SOAPException x) {
x.printStackTrace();
}
}
示例15: OperationA
import javax.xml.soap.SOAPBody; //導入方法依賴的package包/類
@Override
public void OperationA() throws Exception {
MessageFactory fac = MessageFactory.newInstance();
//Create a SOAPFault and throw it through SOAPFaultException
SOAPMessage soapMessage = fac.createMessage();
SOAPPart soapPart = soapMessage.getSOAPPart();
SOAPEnvelope envelope = soapPart.getEnvelope();
SOAPBody body = envelope.getBody();
//Create a generic SOAPFault object
SOAPFault soapFault = body.addFault();
soapFault.setFaultCode("Client");
soapFault.setFaultString("Generic fault");
//Add custom fault detail information
Detail customFaultDetail = soapFault.addDetail();
Name customFaultElementName = envelope.createName("Fault", "sy", "http://fault.switchyard.org/fault");
DetailEntry customFaultElement = customFaultDetail.addDetailEntry(customFaultElementName);
// Add a custom fault code element
SOAPElement customFaultCodeElement = customFaultElement.addChildElement("FaultCode");
customFaultCodeElement.addTextNode("CUSTOMFAULTCODE");
// Add a custom fault message element with qualified name
SOAPElement customQNamedFaultElement = customFaultElement.addChildElement(envelope.createName("FaultMessage", "sy", "http://fault.switchyard.org/fault"));
customQNamedFaultElement.addTextNode("Custom fault message");
SOAPFaultException soapFaultException = new SOAPFaultException(soapFault);
throw soapFaultException;
}