本文整理汇总了Java中javax.xml.soap.SOAPBody.hasFault方法的典型用法代码示例。如果您正苦于以下问题:Java SOAPBody.hasFault方法的具体用法?Java SOAPBody.hasFault怎么用?Java SOAPBody.hasFault使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.xml.soap.SOAPBody
的用法示例。
在下文中一共展示了SOAPBody.hasFault方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: getReceivedMessagesIds
import javax.xml.soap.SOAPBody; //导入方法依赖的package包/类
/**
* Send the web service request to Hermes2 requesting for querying
* all message id of the AS2 message(s) which are ready to download from Hermes2.
*
* @return An iterator which contains all message id of the message(s) which
* are ready to download.
*
* @throws Exception
*/
public Iterator getReceivedMessagesIds() throws Exception {
// Make a SOAP Connection and SOAP Message.
SOAPConnection soapConn = SOAPConnectionFactory.newInstance().createConnection();
SOAPMessage request = MessageFactory.newInstance().createMessage();
// Populate the SOAP Body
/* This is the sample WSDL request for the sending EbMS message WS request.
/* This is the sample WSDL request for the sending AS2 message WS request.
*
* <as2_from> as2from </as2_from>
* <as2_to> as2to </as2_to>
* <numOfMessages> 100 </numOfMessages>
*/
SOAPBody soapBody = request.getSOAPPart().getEnvelope().getBody();
soapBody.addChildElement(createElement("as2From" , nsPrefix, nsURI, this.as2From));
soapBody.addChildElement(createElement("as2To" , nsPrefix, nsURI, this.as2To));
soapBody.addChildElement(createElement("numOfMessages", nsPrefix, nsURI, this.numOfMessages + ""));
// Send the request to Hermes and return the set of message id that are ready to d/l.
SOAPMessage response = soapConn.call(request, receiverListWSURL);
SOAPBody responseBody = response.getSOAPBody();
/*
* The response is something like:
* <soap-body>
* <messageIds>
* <messageId> .. </messageId>
* <messageId> .. </messageId>
* ..
* ..
* </messageIds>
* </soap-body>
*/
if (!responseBody.hasFault()){
SOAPElement messageIdsElement = getFirstChild(responseBody, "messageIds", nsURI);
Iterator messageIdElementIter = getChildren(messageIdsElement, "messageId", nsURI);
ArrayList messageIdsList = new ArrayList();
while(messageIdElementIter.hasNext()) {
SOAPElement messageIdElement = (SOAPElement)messageIdElementIter.next();
messageIdsList.add(messageIdElement.getValue());
}
return messageIdsList.iterator();
} else {
throw new SOAPException(responseBody.getFault().getFaultString());
}
}
示例3: send
import javax.xml.soap.SOAPBody; //导入方法依赖的package包/类
/**
* Send the web service request to Hermes2 requesting for sending
* a <code>AS2 message</code> loopback with a set of <code>payloads</code>.
*
* @param payloads
* The payload set acting as the attachment in <code>AS2 Message</code>.
* @return
* A String representing the ID of the message you request to send.
* @throws Exception
*
* @see hk.hku.cecid.corvus.test.Payload
*/
public String send(Payload [] payloads) throws Exception {
// Make a SOAP Connection and SOAP Message.
SOAPConnection soapConn = SOAPConnectionFactory.newInstance().createConnection();
SOAPMessage request = MessageFactory.newInstance().createMessage();
// Populate the SOAP Body by filling the required parameters.
/* This is the sample WSDL request for the sending AS2 message WS request.
*
* <as2_from> as2from </as2_from>
* <as2_to> as2to </as2_to>
* <type> type </type>
*/
SOAPBody soapBody = request.getSOAPBody();
soapBody.addChildElement(createElement("as2_from", nsPrefix, nsURI, this.as2From));
soapBody.addChildElement(createElement("as2_to" , nsPrefix, nsURI, this.as2To));
soapBody.addChildElement(createElement("type" , nsPrefix, nsURI, this.type));
// Add the payloads
for (int i=0; i < payloads.length; i++) {
AttachmentPart attachmentPart = request.createAttachmentPart();
FileDataSource fileDS = new FileDataSource(new File(payloads[i].getFilePath()));
attachmentPart.setDataHandler(new DataHandler(fileDS));
attachmentPart.setContentType(payloads[i].getContentType());
request.addAttachmentPart(attachmentPart);
}
// Send the request to Hermes and return the message Id to "sender" web services.
SOAPMessage response = soapConn.call(request, senderWSURL);
SOAPBody responseBody = response.getSOAPBody();
if (!responseBody.hasFault()){
SOAPElement messageIdElement = getFirstChild(responseBody, "message_id", nsURI);
return messageIdElement == null ? null : messageIdElement.getValue();
} else {
throw new SOAPException(responseBody.getFault().getFaultString());
}
}
示例4: 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;
}
示例5: 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();
}
}
}
示例6: run
import javax.xml.soap.SOAPBody; //导入方法依赖的package包/类
/**
* The thread execution method.
*/
public void run()
{
// Variable declaration.
SOAPMessage request = null;
SOAPConnectionFactory factory = null;
// Signals a kick-off event.
this.onStart();
try{
for(int i = 0; i < this.getLoopTimes(); i++){
this.curTimes = i;
// Signals a loop start event.
this.onEachLoopStart();
// Asks child class for creating the request.
request = this.onCreateRequest();
factory = SOAPConnectionFactory.newInstance();
SOAPConnection soapConn = factory.createConnection();
this.onBeforeRequest(soapConn, request);
// Save the request if the developers modify the request
// at somewhere.
if (this.isRequestDirty()){
if (this.isRequireXMLDecl)
this.request.setProperty(SOAPMessage.WRITE_XML_DECLARATION , "true");
this.request.saveChanges();
this.setRequestDirty(false);
}
this.response = soapConn.call(request, this.serviceEndPoint);
// Check whether has SOAP fault from server side.
SOAPBody sb = this.response.getSOAPBody();
if (sb.hasFault()){
throw new SOAPException(
sb.getFault().getFaultCode()
+ " "
+ sb.getFault().getFaultString());
}
this.onResponse();
}
this.onEnd();
// Reset soap request and response.
this.resetSOAPRequest();
this.resetSOAPResponse();
}
catch(Exception e){
this.onError(e);
}
}
示例7: downloadPayloads
import javax.xml.soap.SOAPBody; //导入方法依赖的package包/类
/**
* Send the web service request to Hermes2 requesting for downloading the payload
* of particular AS2 message.
*
* @return An iterator which contains all message id of the message(s) which
* are ready to download.
*
* @throws Exception
*/
public Iterator downloadPayloads(String messageId) throws Exception {
// Make a SOAP Connection and SOAP Message.
SOAPConnection soapConn = SOAPConnectionFactory.newInstance().createConnection();
SOAPMessage request = MessageFactory.newInstance().createMessage();
// Populate the SOAP Body
SOAPBody soapBody = request.getSOAPPart().getEnvelope().getBody();
soapBody.addChildElement(createElement("messageId", nsPrefix, nsURI, messageId));
// Send the request to Hermes and return the payload if any.
SOAPMessage response = soapConn.call(request, hermes2ReceiverWSURL);
SOAPBody responseBody = response.getSOAPBody();
/*
* The response is something like:
* <soap-body>
* <hasMessage>
* </soap-body>
* .
* .
* attachment as a MIME part.
*/
if (!responseBody.hasFault()){
// See whether has <hasMessage> element.
SOAPElement hasMessageElement = getFirstChild(responseBody, "hasMessage", nsURI);
ArrayList payloadsList = new ArrayList();
if (hasMessageElement != null){
Iterator attachmentPartIter = response.getAttachments();
while(attachmentPartIter.hasNext()) {
AttachmentPart attachmentPart = (AttachmentPart) attachmentPartIter.next();
// Add a new payload to the payload list.
Payload payload = new Payload(
attachmentPart.getDataHandler().getInputStream(),
attachmentPart.getContentType());
payloadsList.add(payload);
}
}
return payloadsList.iterator();
} else {
throw new SOAPException(responseBody.getFault().getFaultString());
}
}
示例8: downloadPayloads
import javax.xml.soap.SOAPBody; //导入方法依赖的package包/类
/**
* Send the web service request to Hermes2 requesting for downloading the payload
* of particular message.
*
* @return An iterator which contains all message id of the message(s) which
* are ready to download.
*
* @throws Exception
*/
public Iterator downloadPayloads(String messageId) throws Exception {
// Make a SOAP Connection and SOAP Message.
SOAPConnection soapConn = SOAPConnectionFactory.newInstance().createConnection();
SOAPMessage request = MessageFactory.newInstance().createMessage();
// Populate the SOAP Body
SOAPBody soapBody = request.getSOAPPart().getEnvelope().getBody();
soapBody.addChildElement(createElement("messageId", nsPrefix, nsURI, messageId));
// Send the request to Hermes and return the payload if any.
SOAPMessage response = soapConn.call(request, hermes2ReceiverWSURL);
SOAPBody responseBody = response.getSOAPBody();
/*
* The response is something like:
* <soap-body>
* <hasMessage>
* </soap-body>
* .
* .
* attachment as a MIME part.
*/
if (!responseBody.hasFault()){
// See whether has <hasMessage> element.
SOAPElement hasMessageElement = getFirstChild(responseBody, "hasMessage", nsURI);
ArrayList payloadsList = new ArrayList();
if (hasMessageElement != null){
Iterator attachmentPartIter = response.getAttachments();
while(attachmentPartIter.hasNext()) {
AttachmentPart attachmentPart = (AttachmentPart) attachmentPartIter.next();
// Add a new payload to the payload list.
Payload payload = new Payload(
attachmentPart.getDataHandler().getInputStream(),
attachmentPart.getContentType());
payloadsList.add(payload);
}
}
return payloadsList.iterator();
} else {
throw new SOAPException(responseBody.getFault().getFaultString());
}
}
示例9: send
import javax.xml.soap.SOAPBody; //导入方法依赖的package包/类
/**
* Send the web service request to Hermes2 requesting for sending
* a <code>EbXML message</code> loopback with a set of <code>payloads</code>.
*
* @param payloads
* The payload set acting as the attachment in <code>EbXML Message</code>.
* @return
* A String representing the ID of the message you request to send.
* @throws Exception
*
* @see hk.hku.cecid.corvus.test.Payload
*/
public String send(Payload [] payloads) throws Exception {
// Make a SOAP Connection and SOAP Message.
SOAPConnection soapConn = SOAPConnectionFactory.newInstance().createConnection();
SOAPMessage request = MessageFactory.newInstance().createMessage();
// Populate the SOAP Body by filling the required parameters.
/* This is the sample WSDL request for the sending EbMS message WS request.
*
* <cpaId> ebmscpaid </cpaId>
* <service> http://localhost:8080/corvus/httpd/ebms/inbound <service>
* <action> action </action>
* <convId> convId </convId>
* <fromPartyId> fromPartyId </fromPartyId>
* <fromPartyType> fromPartyType </fromPartyType>
* <toPartyId> toPartyId </toPartyId>
* <toPartyType> toPartyType </toPartyType>
* <refToMessageId> </refToMessageId>
*/
SOAPBody soapBody = request.getSOAPBody();
soapBody.addChildElement(createElement("cpaId", nsPrefix, nsURI, cpaId));
soapBody.addChildElement(createElement("service", nsPrefix, nsURI, service));
soapBody.addChildElement(createElement("action", nsPrefix, nsURI, action));
soapBody.addChildElement(createElement("convId", nsPrefix, nsURI, conversationId));
soapBody.addChildElement(createElement("fromPartyId", nsPrefix, nsURI, fromPartyId));
soapBody.addChildElement(createElement("fromPartyType", nsPrefix, nsURI, fromPartyType));
soapBody.addChildElement(createElement("toPartyId", nsPrefix, nsURI, toPartyId));
soapBody.addChildElement(createElement("toPartyType", nsPrefix, nsURI, toPartyType));
soapBody.addChildElement(createElement("refToMessageId", nsPrefix, nsURI, refToMessageId));
// Add the payloads
for (int i=0; i < payloads.length; i++) {
AttachmentPart attachmentPart = request.createAttachmentPart();
FileDataSource fileDS = new FileDataSource(new File(payloads[i].getFilePath()));
attachmentPart.setDataHandler(new DataHandler(fileDS));
attachmentPart.setContentType(payloads[i].getContentType());
request.addAttachmentPart(attachmentPart);
}
// Send the request to Hermes and return the message Id to "sender" web services.
SOAPMessage response = soapConn.call(request, senderWSURL);
SOAPBody responseBody = response.getSOAPBody();
if (!responseBody.hasFault()){
SOAPElement messageIdElement = getFirstChild(responseBody, "message_id", nsURI);
return messageIdElement == null ? null : messageIdElement.getValue();
} else {
throw new SOAPException(responseBody.getFault().getFaultString());
}
}
示例10: getReceivedMessagesIds
import javax.xml.soap.SOAPBody; //导入方法依赖的package包/类
/**
* Send the web service request to Hermes2 requesting for querying
* all message id of the EbMS message(s) which are ready to download from Hermes2.
*
* @return An iterator which contains all message id of the message(s) which
* are ready to download.
*
* @throws Exception
*/
public Iterator getReceivedMessagesIds() throws Exception {
// Make a SOAP Connection and SOAP Message.
SOAPConnection soapConn = SOAPConnectionFactory.newInstance().createConnection();
SOAPMessage request = MessageFactory.newInstance().createMessage();
// Populate the SOAP Body
/* This is the sample WSDL request for the sending EbMS message WS request.
*
* <cpaId> ebmscpaid </cpaId>
* <service> http://localhost:8080/corvus/httpd/ebms/inbound <service>
* <action> action </action>
* <convId> convId </convId>
* <fromPartyId> fromPartyId </fromPartyId>
* <fromPartyType> fromPartyType </fromPartyType>
* <toPartyId> toPartyId </toPartyId>
* <toPartyType> toPartyType </toPartyType>
* <numOfMessages> 100 </numOfMessages>
*/
SOAPBody soapBody = request.getSOAPPart().getEnvelope().getBody();
soapBody.addChildElement(createElement("cpaId", nsPrefix, nsURI, cpaId));
soapBody.addChildElement(createElement("service", nsPrefix, nsURI, service));
soapBody.addChildElement(createElement("action", nsPrefix, nsURI, action));
soapBody.addChildElement(createElement("convId", nsPrefix, nsURI, conversationId));
soapBody.addChildElement(createElement("fromPartyId", nsPrefix, nsURI, fromPartyId));
soapBody.addChildElement(createElement("fromPartyType", nsPrefix, nsURI, fromPartyType));
soapBody.addChildElement(createElement("toPartyId", nsPrefix, nsURI, toPartyId));
soapBody.addChildElement(createElement("toPartyType", nsPrefix, nsURI, toPartyType));
soapBody.addChildElement(createElement("numOfMessages", nsPrefix, nsURI, numOfMessages + ""));
// Send the request to Hermes and return the set of message id that are ready to d/l.
SOAPMessage response = soapConn.call(request, receiverListWSURL);
SOAPBody responseBody = response.getSOAPBody();
/*
* The response is something like:
* <soap-body>
* <messageIds>
* <messageId> .. </messageId>
* <messageId> .. </messageId>
* ..
* ..
* </messageIds>
* </soap-body>
*/
if (!responseBody.hasFault()){
SOAPElement messageIdsElement = getFirstChild(responseBody, "messageIds", nsURI);
Iterator messageIdElementIter = getChildren(messageIdsElement, "messageId", nsURI);
ArrayList messageIdsList = new ArrayList();
while(messageIdElementIter.hasNext()) {
SOAPElement messageIdElement = (SOAPElement)messageIdElementIter.next();
messageIdsList.add(messageIdElement.getValue());
}
return messageIdsList.iterator();
} else {
throw new SOAPException(responseBody.getFault().getFaultString());
}
}
示例11: 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);
}
}
}
}