当前位置: 首页>>代码示例>>Java>>正文


Java SOAPFactory.createSOAPFaultText方法代码示例

本文整理汇总了Java中org.apache.axiom.soap.SOAPFactory.createSOAPFaultText方法的典型用法代码示例。如果您正苦于以下问题:Java SOAPFactory.createSOAPFaultText方法的具体用法?Java SOAPFactory.createSOAPFaultText怎么用?Java SOAPFactory.createSOAPFaultText使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.axiom.soap.SOAPFactory的用法示例。


在下文中一共展示了SOAPFactory.createSOAPFaultText方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testFaultSerialization

import org.apache.axiom.soap.SOAPFactory; //导入方法依赖的package包/类
public void testFaultSerialization() throws Exception {
    final String REASON = "ReasonValue";

    SOAPFactory soapFactory = OMAbstractFactory.getSOAP12Factory();
    SOAPFaultCode soapFaultCode = soapFactory.createSOAPFaultCode();
    SOAPFaultValue soapFaultValue = soapFactory
            .createSOAPFaultValue(soapFaultCode);
    soapFaultValue.setText(new QName(
            SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI, "Sender"));

    SOAPFaultReason soapFaultReason = soapFactory.createSOAPFaultReason();
    SOAPFaultText soapFaultText = soapFactory
            .createSOAPFaultText(soapFaultReason);
    soapFaultText.setText(REASON);

    SOAPFaultDetail soapFaultDetail = soapFactory.createSOAPFaultDetail();
    QName qName = new QName("http://mycompany.com", "FaultException", "ex");
    OMElement exception = soapFactory.createOMElement(qName,
            soapFaultDetail);
    exception.setText("Detail text");
    AxisFault fault = new AxisFault(soapFaultCode, soapFaultReason, null,
            null, soapFaultDetail);

    ConfigurationContext cc = ConfigurationContextFactory
            .createDefaultConfigurationContext();
    MessageContext ctx = cc.createMessageContext();
    SOAPFactory fac = OMAbstractFactory.getSOAP12Factory();
    ctx.setEnvelope(fac.getDefaultEnvelope());
    MessageContext faultCtx = MessageContextBuilder
            .createFaultMessageContext(ctx, fault);

    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    TransportUtils.writeMessage(faultCtx, bos);

    String result = new String(bos.toByteArray());

    // For right now, just making sure we have a test for AXIS2-2752
    // Confirm reason was correctly processed
    assertTrue("Incorrect or missing reason!", result.indexOf(REASON) > -1);
}
 
开发者ID:wso2,项目名称:wso2-axis2,代码行数:41,代码来源:FaultSerializationTest.java

示例2: initFaultInformation

import org.apache.axiom.soap.SOAPFactory; //导入方法依赖的package包/类
private void initFaultInformation(MessageContext inMessageContext) {
    SOAPFactory soapFactory;
    if (inMessageContext.isSOAP11()) {
        soapFactory = OMAbstractFactory.getSOAP11Factory();
    } else {
        soapFactory = OMAbstractFactory.getSOAP12Factory();
    }

    soapFaultCode = soapFactory.createSOAPFaultCode();
    SOAPFaultValue soapFaultValue = soapFactory.createSOAPFaultValue(soapFaultCode);
    soapFaultValue.setText(new QName("http://test.org", "TestFault", "test"));

    soapFaultReason = soapFactory.createSOAPFaultReason();
    SOAPFaultText soapFaultText = soapFactory.createSOAPFaultText(soapFaultReason);
    soapFaultText.setText("This is some FaultReason");

    soapFaultDetail = soapFactory.createSOAPFaultDetail();
    QName qName = new QName("http://someuri.org", "FaultException");
    OMElement detail = soapFactory.createOMElement(qName, soapFaultDetail);
    qName = new QName("http://someuri.org", "ExceptionMessage");
    Throwable e = new Exception("This is a test Exception");
    while (e != null) {
        OMElement exception = soapFactory.createOMElement(qName, null);
        exception.setText(e.getMessage());
        detail.addChild(exception);
        e = e.getCause();
    }
}
 
开发者ID:wso2,项目名称:wso2-axis2,代码行数:29,代码来源:FaultThrowingService.java

示例3: invoke

import org.apache.axiom.soap.SOAPFactory; //导入方法依赖的package包/类
public InvocationResponse invoke(MessageContext msgContext) throws AxisFault {
    // this handler will be used to check the fault handling of Axis2.
    // this will create some dummy faults and send

    SOAPFactory soapFac = msgContext.isSOAP11() ? OMAbstractFactory.getSOAP11Factory() :
            OMAbstractFactory.getSOAP12Factory();

    // I have a sudden fake error ;)
    OMElement firstElement = msgContext.getEnvelope().getBody().getFirstElement();

    OMElement detailEntry = soapFac.createOMElement("MoreInfo", null);
    detailEntry.setText(DETAIL_MORE_INFO);

    if (ERR_HANDLING_WITH_MSG_CTXT.equals(firstElement.getLocalName())) {
        SOAPFaultCode soapFaultCode = soapFac.createSOAPFaultCode();
        soapFaultCode.declareNamespace("http://someuri.org", "m");
        if (msgContext.isSOAP11()) {
            soapFaultCode.setText(M_FAULT_EXCEPTION);
        } else {
            SOAPFaultValue soapFaultValue = soapFac.createSOAPFaultValue(soapFaultCode);
            soapFaultValue.setText(M_FAULT_EXCEPTION);
        }

        SOAPFaultReason soapFaultReason = soapFac.createSOAPFaultReason();

        if (msgContext.isSOAP11()) {
            soapFaultReason.setText(FAULT_REASON);
        } else {
            SOAPFaultText soapFaultText = soapFac.createSOAPFaultText();
            soapFaultText.setLang("en");
            soapFaultText.setText(FAULT_REASON);
            soapFaultReason.addSOAPText(soapFaultText);
        }

        SOAPFaultDetail faultDetail = soapFac.createSOAPFaultDetail();
        faultDetail.addDetailEntry(detailEntry);

        msgContext.setProperty(SOAP12Constants.SOAP_FAULT_CODE_LOCAL_NAME, soapFaultCode);
        msgContext.setProperty(SOAP12Constants.SOAP_FAULT_REASON_LOCAL_NAME, soapFaultReason);
        msgContext.setProperty(SOAP12Constants.SOAP_FAULT_DETAIL_LOCAL_NAME, faultDetail);

        throw new AxisFault("A dummy exception has occurred");
    } else if (ERR_HANDLING_WITH_AXIS_FAULT.equals(firstElement.getLocalName())) {
        throw new AxisFault(new QName(M_FAULT_EXCEPTION), FAULT_REASON, null, null,
                            detailEntry);
    }
    return InvocationResponse.CONTINUE;
}
 
开发者ID:wso2,项目名称:wso2-axis2,代码行数:49,代码来源:FaultHandler.java


注:本文中的org.apache.axiom.soap.SOAPFactory.createSOAPFaultText方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。