Exemplo n.º 1
0
CObjectHookGuardBase::CObjectHookGuardBase(const CObjectTypeInfo& info,
                                           CWriteObjectHook& hook,
                                           CObjectOStream* stream)
    : m_Hook(&hook),
      m_HookMode(eHook_Write),
      m_HookType(eHook_Object)
{
    m_Stream.m_OStream = stream;
    if ( stream ) {
        info.SetLocalWriteHook(*stream, &hook);
    }
    else {
        info.SetGlobalWriteHook(&hook);
    }
}
Exemplo n.º 2
0
void CSoapMessage::Write(CObjectOStream& out) const
{
    CObjectOStreamXml* os = 0;
    bool schema = false, loc = false;
    string ns_default;
    ESerialDataFormat fmt = out.GetDataFormat();
    if (fmt == eSerial_Xml) {
        os = dynamic_cast<CObjectOStreamXml*>(&out);
        if (os) {
            schema = os->GetReferenceSchema();
            os->SetReferenceSchema();
            loc = os->GetUseSchemaLocation();
            os->SetUseSchemaLocation(false);
            ns_default = os->GetDefaultSchemaNamespace();
            os->SetDefaultSchemaNamespace(GetSoapNamespace());
        }
    }

    CSoapEnvelope env;

    if (!m_Header.empty()) {
// This is to make the stream think the Header was not empty.
// Since Header is optional, we do not have to make it *always*
        CRef<CAnyContentObject> h(new CAnyContentObject);
        env.SetHeader().SetAnyContent().push_back(h);
    }

// This is to make the stream think the Body was not empty.
// Body is mandatory
    CRef<CAnyContentObject> h(new CAnyContentObject);
    env.SetBody().SetAnyContent().push_back(h);

    CSoapFault* flt = 0;
    if (!m_FaultDetail.empty()) {
// This is to make the stream think the Detail was not empty.
// Since Detail is optional, we do not have to make it *always*
        flt = dynamic_cast<CSoapFault*>(const_cast<CSerialObject*>(
            GetSerialObject("Fault", eMsgBody).GetPointer()));
        if (!flt) {
// throw exception here (?)
        } else {
            CRef<CAnyContentObject> h2(new CAnyContentObject);
            flt->SetDetail().SetAnyContent().push_back(h2);
        }
    }

    CObjectTypeInfo typeH = CType<CSoapHeader>();
    typeH.SetLocalWriteHook(out, new CSoapWriteHook(m_Header));

    CObjectTypeInfo typeB = CType<CSoapBody>();
    typeB.SetLocalWriteHook(out, new CSoapWriteHook(m_Body));

    CObjectTypeInfo typeF = CType<CSoapFault::C_Detail>();
    typeF.SetLocalWriteHook(out, new CSoapWriteHook(m_FaultDetail));

    x_VerifyFaultObj(true);
    out << env;
    x_VerifyFaultObj(false);

    if (flt) {
        flt->SetDetail().SetAnyContent().clear();
    }
    if (os) {
        os->SetReferenceSchema(schema);
        os->SetUseSchemaLocation(loc);
        os->SetDefaultSchemaNamespace(ns_default);
    }
}