本文整理匯總了Java中javax.xml.soap.SOAPFault.setFaultString方法的典型用法代碼示例。如果您正苦於以下問題:Java SOAPFault.setFaultString方法的具體用法?Java SOAPFault.setFaultString怎麽用?Java SOAPFault.setFaultString使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.xml.soap.SOAPFault
的用法示例。
在下文中一共展示了SOAPFault.setFaultString方法的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: handleOutbound
import javax.xml.soap.SOAPFault; //導入方法依賴的package包/類
protected boolean handleOutbound(final SOAPMessageContext msgContext)
{
try
{
SOAPFault fault = null;
MessageFactory factory = MessageFactory.newInstance();
SOAPMessage resMessage = factory.createMessage();
fault = resMessage.getSOAPBody().addFault();
fault.setFaultString("this is an exception thrown by client outbound");
throw new SOAPFaultException(fault);
}
catch (SOAPException e)
{
//ignore
}
return true;
}
示例5: 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);
}
示例6: handleFault
import javax.xml.soap.SOAPFault; //導入方法依賴的package包/類
public boolean handleFault(SOAPMessageContext messagecontext) {
tracker.handleFault((Boolean) messagecontext.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY));
try {
SOAPFault fault = messagecontext.getMessage().getSOAPBody().getFault();
String faultString = fault.getFaultString();
Throwable webmethodException = (Throwable)
messagecontext.get("jaxws.outbound.response.webmethod.exception");
// Update the fault string with the stack trace
if (webmethodException != null) {
TestLogger.logger.debug("The webmethod exception is available...setting the fault string");
faultString += "stack = " + stackToString(webmethodException);
fault.setFaultString(faultString);
} else {
TestLogger.logger.debug("The webmethod exception was not available");
}
} catch (Exception e) {
tracker.log("Exception occurred:" + e.getMessage(),
(Boolean) messagecontext.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY));
}
return true;
}
示例7: _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());
}
示例8: testSetFaultStringLocale
import javax.xml.soap.SOAPFault; //導入方法依賴的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));
}
示例9: createMUSOAPFaultException
import javax.xml.soap.SOAPFault; //導入方法依賴的package包/類
/**
* @param notUnderstoodHeaders
* @return SOAPfaultException with SOAPFault representing the MustUnderstand SOAP Fault.
* notUnderstoodHeaders are added in the fault detail.
*/
final SOAPFaultException createMUSOAPFaultException(Set<QName> notUnderstoodHeaders) {
try {
SOAPFault fault = soapVersion.getSOAPFactory().createFault(
MUST_UNDERSTAND_FAULT_MESSAGE_STRING,
soapVersion.faultCodeMustUnderstand);
fault.setFaultString("MustUnderstand headers:" +
notUnderstoodHeaders + " are not understood");
return new SOAPFaultException(fault);
} catch (SOAPException e) {
throw new WebServiceException(e);
}
}
示例10: createInvalidAddressingHeaderFault
import javax.xml.soap.SOAPFault; //導入方法依賴的package包/類
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);
}
}
示例11: newMapRequiredFault
import javax.xml.soap.SOAPFault; //導入方法依賴的package包/類
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);
}
}
示例12: createDuplicateHeaderException
import javax.xml.soap.SOAPFault; //導入方法依賴的package包/類
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);
}
}
示例13: createDuplicateHeaderException
import javax.xml.soap.SOAPFault; //導入方法依賴的package包/類
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);
}
}
示例14: addFault
import javax.xml.soap.SOAPFault; //導入方法依賴的package包/類
@Override
public SOAPFault addFault(
Name faultCode,
String faultString,
Locale locale)
throws SOAPException {
SOAPFault fault = addFault();
fault.setFaultCode(faultCode);
fault.setFaultString(faultString, locale);
return fault;
}
示例15: getSOAPMessage
import javax.xml.soap.SOAPFault; //導入方法依賴的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;
}