當前位置: 首頁>>代碼示例>>Java>>正文


Java SOAPBody.getFault方法代碼示例

本文整理匯總了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);
        }
    }
}
 
開發者ID:wso2,項目名稱:wso2-axis2,代碼行數:27,代碼來源:SOAPFaultDetailTest.java

示例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;
}
 
開發者ID:apache,項目名稱:juddi-scout,代碼行數:34,代碼來源:SaajTransport.java

示例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();
    }
  }
}
 
開發者ID:inbravo,項目名稱:scribe,代碼行數:51,代碼來源:SOAPExecutor.java

示例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);
            }
        }
    }
}
 
開發者ID:wso2,項目名稱:wso2-axis2,代碼行數:57,代碼來源:SOAPFaultTest.java


注:本文中的javax.xml.soap.SOAPBody.getFault方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。