本文整理匯總了Java中javax.xml.soap.SOAPFault.setFaultCode方法的典型用法代碼示例。如果您正苦於以下問題:Java SOAPFault.setFaultCode方法的具體用法?Java SOAPFault.setFaultCode怎麽用?Java SOAPFault.setFaultCode使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.xml.soap.SOAPFault
的用法示例。
在下文中一共展示了SOAPFault.setFaultCode方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: _testQuick
import javax.xml.soap.SOAPFault; //導入方法依賴的package包/類
public void _testQuick() throws Exception {
MessageFactory msgfactory = MessageFactory.newInstance();
SOAPFactory factory = SOAPFactory.newInstance();
SOAPMessage outputmsg = msgfactory.createMessage();
String valueCode = "faultcode";
String valueString = "faultString";
SOAPFault fault = outputmsg.getSOAPPart().getEnvelope().getBody().addFault();
fault.setFaultCode(valueCode);
fault.setFaultString(valueString);
Detail detail = fault.addDetail();
detail.addDetailEntry(factory.createName("Hello"));
ByteArrayOutputStream baos = new ByteArrayOutputStream();
if (outputmsg.saveRequired()) {
outputmsg.saveChanges();
}
outputmsg.writeTo(baos);
String xml = new String(baos.toByteArray());
assertTrue(xml.indexOf("Hello") != -1);
}
示例2: addFault
import javax.xml.soap.SOAPFault; //導入方法依賴的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;
}
示例3: invoke
import javax.xml.soap.SOAPFault; //導入方法依賴的package包/類
@Override
public DOMSource invoke(DOMSource request) {
try {
return invokeAllowingFaults(request);
} catch (FaultMessage faultMessage) {
try {
SOAPFactory factory = SOAPFactory.newInstance();
SOAPFault soapFault = factory.createFault();
soapFault.setFaultCode(SOAP11_FAULTCODE_SERVER); // todo here is a constant until we have a mechanism to determine the correct value (client / server)
soapFault.setFaultString(faultMessage.getMessage());
Detail detail = soapFault.addDetail();
serializeFaultMessage(detail, faultMessage);
// fault actor?
// stack trace of the outer exception (FaultMessage) is unimportant, because it is always created at one place
// todo consider providing stack trace of the inner exception
//Detail detail = soapFault.addDetail();
//detail.setTextContent(getStackTraceAsString(faultMessage));
throw new SOAPFaultException(soapFault);
} catch (SOAPException e) {
throw new RuntimeException("SOAP Exception: " + e.getMessage(), e);
}
}
}
示例4: throwSoapFaultException
import javax.xml.soap.SOAPFault; //導入方法依賴的package包/類
public void throwSoapFaultException()
{
try
{
MessageContext ctx = context.getMessageContext();
ctx.put(MessageContext.HTTP_RESPONSE_CODE, 400);
SOAPFactory factory = SOAPFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
SOAPFault fault = factory.createFault();
fault.addFaultReasonText("this is a fault string!", Locale.ITALIAN);
fault.setFaultCode(SOAPConstants.SOAP_SENDER_FAULT);
fault.setFaultActor("mr.actor");
fault.appendFaultSubcode(new QName("http://ws.gss.redhat.com/", "AnException"));
fault.addDetail().addChildElement("test");
throw new SOAPFaultException(fault);
}
catch (Exception s)
{
throw new RuntimeException(s);
}
}
示例5: throwSoapFaultException
import javax.xml.soap.SOAPFault; //導入方法依賴的package包/類
public void throwSoapFaultException()
{
// This should be thrown as-is
try
{
SOAPFactory factory = SOAPFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
SOAPFault fault = factory.createFault();
fault.addFaultReasonText("this is a fault string!", Locale.ITALIAN);
fault.setFaultCode(SOAPConstants.SOAP_VERSIONMISMATCH_FAULT);
fault.setFaultActor("mr.actor");
fault.appendFaultSubcode(new QName("http://ws.gss.redhat.com/", "NullPointerException"));
fault.addDetail().addChildElement("test");
throw new SOAPFaultException(fault);
}
catch (SOAPException s)
{
throw new RuntimeException(s);
}
}
示例6: throwSoapFault
import javax.xml.soap.SOAPFault; //導入方法依賴的package包/類
private static void throwSoapFault(String faultMessage, String ExceptionDetail, String SonosError) throws RuntimeException {
SOAPFault soapFault;
try {
soapFault = SOAPFactory.newInstance(SOAPConstants.SOAP_1_1_PROTOCOL).createFault();
soapFault.setFaultString(faultMessage);
soapFault.setFaultCode(new QName(faultMessage));
if(!ExceptionDetail.isEmpty() && !SonosError.isEmpty()) {
Detail detail = soapFault.addDetail();
SOAPElement el1 = detail.addChildElement("ExceptionDetail");
el1.setValue(ExceptionDetail);
SOAPElement el = detail.addChildElement("SonosError");
el.setValue(SonosError);
}
} catch (Exception e2) {
throw new RuntimeException("Problem processing SOAP Fault on service-side." + e2.getMessage());
}
throw new SOAPFaultException(soapFault);
}
示例7: createFault
import javax.xml.soap.SOAPFault; //導入方法依賴的package包/類
/**
* Creates a new SOAPFault object initialized with the given reasonText and faultCode
*
* @param reasonText - the ReasonText/FaultString for the fault faultCode - the FaultCode for
* the fault
* @return: a SOAPFault object
* @throws: SOAPException - if there is a SOAP error
*/
public SOAPFault createFault(String reasonText, QName faultCode) throws SOAPException {
SOAPFault soapFault;
if (soapVersion.equals(SOAPConstants.SOAP_1_2_PROTOCOL)) {
soapFault = new SOAPFaultImpl(DOOMAbstractFactory.getSOAP12Factory()
.createSOAPFault());
} else {
soapFault = new SOAPFaultImpl(DOOMAbstractFactory.getSOAP11Factory()
.createSOAPFault());
}
soapFault.setFaultCode(faultCode);
try {
soapFault.addFaultReasonText(reasonText, Locale.getDefault());
} catch (UnsupportedOperationException e) {
throw new SOAPException(e.getMessage());
}
return soapFault;
}
示例8: _testFaults
import javax.xml.soap.SOAPFault; //導入方法依賴的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());
}
示例9: _testGetFaultCodeAsQName
import javax.xml.soap.SOAPFault; //導入方法依賴的package包/類
public void _testGetFaultCodeAsQName() 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();
soapFault.addFaultReasonText("myReason", new Locale("en"));
soapFault.setFaultCode("mycode");
soapMessage.saveChanges();
QName qname = soapFault.getFaultCodeAsQName();
assertNotNull(qname);
}
示例10: testFaultCodeWithPrefix1
import javax.xml.soap.SOAPFault; //導入方法依賴的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);
}
示例11: testFaultCodeWithPrefix2
import javax.xml.soap.SOAPFault; //導入方法依賴的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);
}
示例12: testSetGetFaultCodeAsName1
import javax.xml.soap.SOAPFault; //導入方法依賴的package包/類
@Validated @Test
public void testSetGetFaultCodeAsName1() throws Exception {
SOAPFactory fac = SOAPFactory.newInstance(SOAPConstants.SOAP_1_1_PROTOCOL);
SOAPFault sf = fac.createFault();
Name name = fac.createName("myfault", "flt", "http://example.com");
sf.setFaultCode(name);
Name name2 = sf.getFaultCodeAsName();
assertNotNull(name2);
assertEquals(name.getLocalName(), name2.getLocalName());
assertEquals(name.getPrefix(), name2.getPrefix());
assertEquals(name.getURI(), name2.getURI());
QName name3 = sf.getFaultCodeAsQName();
assertNotNull(name3);
assertEquals(name.getLocalName(), name3.getLocalPart());
assertEquals(name.getPrefix(), name3.getPrefix());
assertEquals(name.getURI(), name3.getNamespaceURI());
}
示例13: testSetGetFaultCodeAsName2
import javax.xml.soap.SOAPFault; //導入方法依賴的package包/類
@Validated @Test
public void testSetGetFaultCodeAsName2() throws Exception {
QName qname = SOAPConstants.SOAP_SENDER_FAULT;
SOAPFactory fac = SOAPFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
Name name = fac.createName(qname.getLocalPart(),
qname.getPrefix(), qname.getNamespaceURI());
SOAPFault sf = fac.createFault();
sf.setFaultCode(name);
Name name2 = sf.getFaultCodeAsName();
assertNotNull(name2);
assertEquals(name.getLocalName(), name2.getLocalName());
assertEquals(name.getPrefix(), name2.getPrefix());
assertEquals(name.getURI(), name2.getURI());
QName name3 = sf.getFaultCodeAsQName();
assertNotNull(name3);
assertEquals(name.getLocalName(), name3.getLocalPart());
assertEquals(name.getPrefix(), name3.getPrefix());
assertEquals(name.getURI(), name3.getNamespaceURI());
}
示例14: testSetGetFaultCodeAsQName1
import javax.xml.soap.SOAPFault; //導入方法依賴的package包/類
@Validated @Test
public void testSetGetFaultCodeAsQName1() throws Exception {
SOAPFactory fac = SOAPFactory.newInstance(SOAPConstants.SOAP_1_1_PROTOCOL);
SOAPFault sf = fac.createFault();
QName name = new QName("http://example.com", "myfault", "flt");
sf.setFaultCode(name);
QName name2 = sf.getFaultCodeAsQName();
assertNotNull(name2);
assertEquals(name.getLocalPart(), name2.getLocalPart());
assertEquals(name.getPrefix(), name2.getPrefix());
assertEquals(name.getNamespaceURI(), name2.getNamespaceURI());
Name name3 = sf.getFaultCodeAsName();
assertNotNull(name3);
assertEquals(name.getLocalPart(), name3.getLocalName());
assertEquals(name.getPrefix(), name3.getPrefix());
assertEquals(name.getNamespaceURI(), name3.getURI());
}
示例15: testSetGetFaultCodeAsQName2
import javax.xml.soap.SOAPFault; //導入方法依賴的package包/類
@Validated @Test
public void testSetGetFaultCodeAsQName2() throws Exception {
QName name = SOAPConstants.SOAP_SENDER_FAULT;
SOAPFactory fac = SOAPFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
SOAPFault sf = fac.createFault();
sf.setFaultCode(name);
QName name2 = sf.getFaultCodeAsQName();
assertNotNull(name2);
assertEquals(name.getLocalPart(), name2.getLocalPart());
assertEquals(name.getPrefix(), name2.getPrefix());
assertEquals(name.getNamespaceURI(), name2.getNamespaceURI());
Name name3 = sf.getFaultCodeAsName();
assertNotNull(name3);
assertEquals(name.getLocalPart(), name3.getLocalName());
assertEquals(name.getPrefix(), name3.getPrefix());
assertEquals(name.getNamespaceURI(), name3.getURI());
}