本文整理汇总了Java中javax.xml.soap.SOAPBody.getFault方法的典型用法代码示例。如果您正苦于以下问题:Java SOAPBody.getFault方法的具体用法?Java SOAPBody.getFault怎么用?Java SOAPBody.getFault使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.xml.soap.SOAPBody
的用法示例。
在下文中一共展示了SOAPBody.getFault方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testDetails
import javax.xml.soap.SOAPBody; //导入方法依赖的package包/类
@Test
public void testDetails() throws Exception {
MessageFactory mf = MessageFactory.newInstance();
SOAPMessage smsg =
mf.createMessage(new MimeHeaders(), new ByteArrayInputStream(xmlString.getBytes()));
SOAPBody body = smsg.getSOAPBody();
//smsg.writeTo(System.out);
SOAPFault fault = body.getFault();
fault.addDetail();
javax.xml.soap.Detail d = fault.getDetail();
Iterator i = d.getDetailEntries();
while (i.hasNext()) {
DetailEntry entry = (DetailEntry)i.next();
String name = entry.getElementName().getLocalName();
if ("tickerSymbol".equals(name)) {
assertEquals("the value of the tickerSymbol element didn't match",
"MACR", entry.getValue());
} else if ("exceptionName".equals(name)) {
assertEquals("the value of the exceptionName element didn't match",
"test.wsdl.faults.InvalidTickerFaultMessage", entry.getValue());
} else {
assertTrue("Expecting details element name of 'tickerSymbol' or " +
"'expceptionName' - I found :" + name, false);
}
}
}
示例2: send
import javax.xml.soap.SOAPBody; //导入方法依赖的package包/类
public Element send(Element request, URI endpointURL) throws TransportException {
if (log.isDebugEnabled()) {
String requestMessage = XMLUtils.convertNodeToXMLString(request);
log.debug("Request message: %s\n%s" + endpointURL + ":" + requestMessage);
}
Element response = null;
try {
SOAPMessage message = this.createSOAPMessage(request);
//Make the SAAJ Call now
SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance();
SOAPConnection connection = soapConnectionFactory.createConnection();
SOAPMessage soapResponse = connection.call(message, endpointURL.toURL());
SOAPBody soapBody = soapResponse.getSOAPBody();
boolean hasFault = soapBody.hasFault();
if (hasFault) {
SOAPFault soapFault = soapBody.getFault();
String faultStr = soapFault.getFaultCode() + "::" + soapFault.getFaultString();
throw new RegistryException(faultStr);
}
response = getFirstChildElement(soapBody);
} catch (Exception ex) {
log.error("Exception::" + ex.getMessage(), ex);
throw new TransportException(ex);
}
if (log.isDebugEnabled()) {
String responseMessage = XMLUtils.convertNodeToXMLString(response);
log.debug("Response message: %s" + responseMessage);
}
return response;
}
示例3: execute
import javax.xml.soap.SOAPBody; //导入方法依赖的package包/类
/**
* Executes SOAP message
*
* @param endpointUrl SOAP endpoint
* @param message SOAP request
* @return SOAP response message
* @throws SOAPException in case of a SOAP issue
* @throws IOException in case of an IO issue
*/
private final SOAPMessage execute(final String endpointUrl, final SOAPMessage message) throws Exception {
SOAPConnection conn = null;
try {
/* Create new SOAP connection */
conn = SOAPConnectionFactory.newInstance().createConnection();
if (logger.isDebugEnabled()) {
logger.debug("----Inside execute, going to execute SOAP message : " + message.getSOAPBody().getTextContent());
}
/* Call SOAP service */
final SOAPMessage response = conn.call(message, endpointUrl);
/* Get SOAP response body */
final SOAPBody body = response.getSOAPBody();
if (logger.isDebugEnabled()) {
logger.debug("----Inside execute, has fault? : " + body.hasFault());
}
if (body.hasFault() && body.getFault() != null) {
logger.error("----Inside execute, fault : " + body.getFault().getTextContent() + ", fault reason : " + body.getFault().getFaultString());
/* Throw error */
throw new SOAPException(body.getFault().getTextContent());
}
return response;
} catch (final Exception e) {
logger.error("----Inside execute, error recieved : " + e.getMessage() + ", error : " + e);
/* Throw user error */
throw new SOAPException(e);
} finally {
if (conn != null) {
conn.close();
}
}
}
示例4: testFaults
import javax.xml.soap.SOAPBody; //导入方法依赖的package包/类
@Validated @Test
public void testFaults() throws Exception {
MessageFactory messageFactory = MessageFactory.newInstance();
SOAPFactory soapFactory = SOAPFactory.newInstance();
SOAPMessage message = messageFactory.createMessage();
SOAPBody body = message.getSOAPBody();
SOAPFault fault = body.addFault();
Name faultName =
soapFactory.createName("Client", "",
SOAPConstants.URI_NS_SOAP_ENVELOPE);
fault.setFaultCode(faultName);
fault.setFaultString("Message does not have necessary info");
fault.setFaultActor("http://gizmos.com/order");
Detail detail = fault.addDetail();
Name entryName =
soapFactory.createName("order", "PO",
"http://gizmos.com/orders/");
DetailEntry entry = detail.addDetailEntry(entryName);
entry.addTextNode("Quantity element does not have a value");
Name entryName2 =
soapFactory.createName("confirmation", "PO",
"http://gizmos.com/confirm");
DetailEntry entry2 = detail.addDetailEntry(entryName2);
entry2.addTextNode("Incomplete address: " + "no zip code");
message.saveChanges();
//message.writeTo(System.out);
// Now retrieve the SOAPFault object and
// its contents, after checking to see that
// there is one
if (body.hasFault()) {
SOAPFault newFault = body.getFault();
// Get the qualified name of the fault code
assertNotNull(newFault.getFaultCodeAsName());
assertNotNull(newFault.getFaultString());
assertNotNull(newFault.getFaultActor());
Detail newDetail = newFault.getDetail();
if (newDetail != null) {
Iterator entries = newDetail.getDetailEntries();
while (entries.hasNext()) {
DetailEntry newEntry = (DetailEntry)entries.next();
String value = newEntry.getValue();
assertNotNull(value);
}
}
}
}