bool CLoggingManager::updateLog(IEspContext* espContext, const char* option, IPropertyTree* userContext, IPropertyTree* userRequest,
    const char* backEndReq, const char* backEndResp, const char* userResp, const char* logDatasets, StringBuffer& status)
{
    if (!initialized)
        throw MakeStringException(-1,"LoggingManager not initialized");

    bool bRet = false;
    try
    {
        Owned<IPropertyTree> espContextTree;
        if (espContext)
        {
            espContextTree.setown(createPTree("ESPContext"));

            short port;
            StringBuffer sourceIP, peerStr;
            const char* esdlBindingID = espContext->queryESDLBindingID();
            espContext->getServAddress(sourceIP, port);
            espContextTree->addProp("SourceIP", sourceIP.str());
            espContext->getPeer(peerStr);
            espContextTree->addProp("Peer", peerStr.str());
            if (!isEmptyString(esdlBindingID))
                espContextTree->addProp("ESDLBindingID", esdlBindingID);
            //More information in espContext may be added to the espContextTree later.

            const char* userId = espContext->queryUserId();
            if (userId && *userId)
                espContextTree->addProp("UserName", userId);

            espContextTree->addProp("ResponseTime", VStringBuffer("%.4f", (msTick()-espContext->queryCreationTime())/1000.0));
        }
        Owned<IEspUpdateLogRequestWrap> req =  new CUpdateLogRequestWrap(nullptr, option, espContextTree.getClear(), LINK(userContext), LINK(userRequest),
            backEndReq, backEndResp, userResp, logDatasets);
        Owned<IEspUpdateLogResponse> resp =  createUpdateLogResponse();
        bRet = updateLog(espContext, *req, *resp, status);
    }
    catch (IException* e)
    {
        status.set("Failed to update log: ");
        e->errorMessage(status);
        ERRLOG("%s", status.str());
        e->Release();
    }
    return bRet;
}
Esempio n. 2
0
void MessageGenerator::initCfgDefValues(const char* method)
{
    if (m_cfg.get())
    {
        m_cfgDefValues.clear();
        
        // Common
        Owned<IPropertyTreeIterator> fs = m_cfg->getElements("Common/Field");
        for (fs->first(); fs->isValid(); fs->next())
        {
            IPropertyTree& f = fs->query();
            m_cfgDefValues[f.queryProp("@name")] = f.queryProp("@value");
        }

        // Service specific
        fs.setown(m_cfg->getElements(VStringBuffer("Services/Service[@name='%s']/Field",method)));
        for (fs->first(); fs->isValid(); fs->next())
        {
            IPropertyTree& f = fs->query();
            m_cfgDefValues[f.queryProp("@name")] = f.queryProp("@value");
        }
    }
}
Esempio n. 3
0
MessageGenerator::MessageGenerator(const char* path, bool keepfile, SchemaType st, IProperties* globals)
    :  m_keepfile(keepfile), m_schemaType(st)
{
    if(globals)
        m_globals = globals;

    m_items = globals->queryProp("items")?atoi(globals->queryProp("items")):1;
    m_isRoxie = globals->queryProp("roxie") ? true : false;
    m_genAllDatasets = globals->queryProp("alldataset") ? true : false;
    m_gx = globals->queryProp("gx") ? true : false;
    m_soapWrap = globals->queryProp("gs") ? false: true;
    m_ecl2esp = globals->getPropBool("ECL2ESP", false);
    if (m_ecl2esp)
        m_items = 1;

    if (globals->queryProp("gf"))
        m_gfile.set(globals->queryProp("gf"));

    if (globals->queryProp("cfg"))
    {
        StringBuffer cfg;
        if (loadFile(cfg, globals->queryProp("cfg")))
            m_cfg.setown(createPTreeFromXMLString(cfg));
        else
            ERRLOG("Can not load cfg file; ignored");
    }

    m_logfile = stdout;

    if(!path || !*path)
    {
        throw MakeStringException(-1, "please provide the path of wsdl");
    }
    
    m_path.append(path);

    if(strnicmp(path, "http:", 5) == 0 || strnicmp(path, "https:", 6) == 0)
    {
        HttpClient client(NULL, path);
        StringBuffer requestbuf;
        client.generateGetRequest(requestbuf);
        client.sendRequest(requestbuf, NULL, NULL, NULL, &m_schema);
        const char* ptr = m_schema.str();
        if(ptr)
        {
            ptr = strchr(ptr, '<');
            if(!ptr)
            {
                if(http_tracelevel > 0)
                    fprintf(m_logfile, "The schema is not valid xml%s", LT);
                return;
            }
            else
                m_schema.remove(0, ptr - m_schema.str());
        }
    }
    else
    {
        m_schema.loadFile(path);
        if(http_tracelevel >= 10)
            fprintf(m_logfile, "Loaded schema:\n%s\n", m_schema.str());
    }

    if(m_schema.length() == 0)
    {
        throw MakeStringException(-1, "wsdl is empty");
    }

    Owned<IPropertyTree> schema = createPTreeFromXMLString(m_schema.str());
    if (m_isRoxie)
        m_roxieSchemaRoot.set(schema->queryBranch("//Result"));
    else
        m_schemaTree.set(schema);

    if(!m_schemaTree.get() && !m_roxieSchemaRoot.get())
        throw MakeStringException(-1, "can't generate property tree from schema");

    setXsdNamespace();

    if (!m_isRoxie)
    {
        if(m_schemaType == WSDL)
        {
            Owned<IPropertyTreeIterator> mi = m_schemaTree->getElements("portType/operation");
            if(mi.get())
            {
                std::set<std::string> methods;
                for (mi->first(); mi->isValid(); mi->next())
                {
                    const char *name = mi->query().queryProp("@name");
                    if(!name || !*name)
                        continue;

                    StringBuffer xpath;
                    xpath.clear().append("portType/operation[@name='").append(name).append("']/input/@message");
                    const char* input = m_schemaTree->queryProp(xpath.str());
                    if(!input || !*input)
                        throw MakeStringException(-1, "can't find input message for method %s", name);
            
                    if(strncmp(input, "tns:", 4) == 0)
                        input += 4;

                    xpath.clear().append("message[@name='").append(input).append("']/part/@element");
                    const char* element = m_schemaTree->queryProp(xpath.str());
                    if(!element || !*element)
                        throw MakeStringException(-1, "can't find message %s\n", input);

                    if(strncmp(element, "tns:", 4) == 0)
                        element += 4;

                    if(methods.find(element) == methods.end())
                    {
                        methods.insert(element);
                        m_methods.append(element);
                    }

                    xpath.clear().append("portType/operation[@name='").append(name).append("']/output/@message");
                    const char* output = m_schemaTree->queryProp(xpath.str());
                    if(!output || !*output)
                        throw MakeStringException(-1, "can't find output message for method %s", name);
            
                    if(strncmp(output, "tns:", 4) == 0)
                        output += 4;

                    xpath.clear().append("message[@name='").append(output).append("']/part/@element");
                    element = m_schemaTree->queryProp(xpath.str());
                    if(!element || !*element)
                        throw MakeStringException(-1, "can't find message %s\n", output);

                    if(strncmp(element, "tns:", 4) == 0)
                        element += 4;

                    if(methods.find(element) == methods.end())
                    {
                        methods.insert(element);
                        m_methods.append(element);
                    }
                }
            }
        }
        else
        {
            Owned<IPropertyTreeIterator> mi = m_schemaTree->getElements(VStringBuffer("%s:element",xsdNs()));
            if(mi.get())
            {
                for (mi->first(); mi->isValid(); mi->next())
                {
                    const char *name = mi->query().queryProp("@name");
                    if(name && *name)
                        m_methods.append(name);
                }
            }       
        }
    }

    initDefaultValues();
}
Esempio n. 4
0
void MessageGenerator::genRoxieMessage(const char* templatemsg, StringBuffer& message)
{
    Owned<IPropertyTree> tmplat;
    StringBuffer root;

    if (templatemsg)
    {
        tmplat.setown(createPTreeFromXMLString(templatemsg));
        if(!tmplat.get())
            throw MakeStringException(-1, "can't generate property tree from input, please make sure it's valid xml.");
        root = tmplat->queryName();
        tmplat.setown(tmplat->getPropTree(VStringBuffer("//Results/Result")));
        if (!tmplat.get())
            throw MakeStringException(-1, "can't find Results/Result in input XML");
    }
    else 
        root = "Unknown"; // TODO: find out the root?

    message.appendf("<!-- <%s> --> %s", root.str(), LT);
    message.appendf(" <!-- <Results> --> %s", LT);
    message.appendf("  <Result>%s", LT);

    Owned<IPropertyTreeIterator> it = m_roxieSchemaRoot->getElements(VStringBuffer("XmlSchema"));
    for (it->first(); it->isValid(); it->next())
    {
        IPropertyTree* ds = &it->query();

        const char* name = ds->queryProp("@name");
        if (!name)
        {
            ERRLOG("XmlSchema without name");
            continue;
        }
        
        IPropertyTree* p = ds->queryBranch(VStringBuffer("%s:schema", xsdNs()));
        m_schemaTree.setown(LINK(p));
        IXmlSchema* xs = createXmlSchemaFromPTree(m_schemaTree);
        IXmlType* type = xs->queryElementType("Dataset");
        if (!type)
        {
            ERRLOG("Can not find type '%s'", name);
            continue;
        }
        // get the Row type
        type = type->queryFieldType(0);
        if (!type)
        {
            ERRLOG("The root element for %s is not an array", name);
            continue;
        }

        IPropertyTree* dsTmplat = tmplat.get() ? tmplat->queryPropTree(VStringBuffer("Dataset[@name='%s']",name)) : NULL;
        if (dsTmplat && dsTmplat->numChildren()>0)
        {
            message.appendf("    <Dataset name=\"%s\">%s", name, LT);
    
            Owned<IPropertyTreeIterator> row = dsTmplat->getElements("Row");
            for (row->first(); row->isValid(); row->next())
            {
                message.appendf("     <Row>%s", LT);
    
                StringStack parent;
                doType(parent,5,"Row",type, &row->query(), message);

                message.appendf("     </Row>%s", LT);
            }

            message.appendf("   </Dataset>%s", LT);
        }
        else if (m_genAllDatasets)
        {
            message.appendf("    <Dataset name=\"%s\">%s", name, LT);
            for (int i=0; i < m_items; i++)
            {
                message.appendf("     <Row>%s", LT);
                StringStack parent;
                doType(parent,6,"Row",type,message);
                message.appendf("     </Row>%s", LT);
            }
            if (m_ecl2esp)
                message.appendf("     <Row/>%s", LT);

            message.appendf("   </Dataset>%s", LT);
        }
    }

    message.appendf("  </Result>%s", LT);
    message.appendf(" <!-- </Results> --> %s", LT);
    message.appendf("<!-- </%s> --> %s", root.str(), LT);
}
Esempio n. 5
0
void MessageGenerator::genNonRoxieMessage(const char* method, const char* templatemsg, StringBuffer& message)
{
    if (m_soapWrap)
        message.appendf("<?xml version=\"1.0\" encoding=\"utf-8\"?>"
            "%s<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\""
            " xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\""
            " xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\""
            " xmlns:SOAP-ENC=\"http://schemas.xmlsoap.org/soap/encoding/\""
            " xmlns:wsse=\"http://schemas.xmlsoap.org/ws/2002/04/secext\"><soap:Body>%s", LT, LT);

    const char* element = method;
    IPTree* schema = NULL;
    if(m_schemaType == WSDL) 
        schema = m_schemaTree->queryPropTree("types/xsd:schema");
    else
        schema = m_schemaTree;

    if (schema)
    {
        const char* ns = schema->queryProp("@targetNamespace");
        if(ns && ns && !m_ecl2esp)
            message.appendf("  <%s  xmlns=\"%s\">", element, ns);
        else
            message.appendf("  <%s>", element);

        
        Owned<IXmlSchema> s = createXmlSchemaFromPTree(LINK(schema));

        if (s.get())
        {
            IXmlType* type = s->queryElementType(element);
            if (type)
            {
                StringStack parent;

                if (templatemsg && *templatemsg)
                {
                    Owned<IPropertyTree> tmplat = createPTreeFromXMLString(templatemsg);
                    if(!tmplat.get())
                        throw MakeStringException(-1, "can't generate property tree from input, please make sure it's valid xml.");
                    IPropertyTree* tmp = NULL;
                    if (strcmp(tmplat->queryName(),element)==0)
                        tmp = tmplat;
                    else
                        tmp = tmplat->queryPropTree(VStringBuffer("//%s",element)); 
                    if (tmp)
                        doType(parent,2, element, type, tmp, message);
                    else
                        doType(parent,2, element, type, message);
                }
                else
                    doType(parent,2, element, type, message);
            }
        }
        
        message.appendf("</%s>%s", element, LT);
    }

    if (m_soapWrap)
        message.append("</soap:Body></soap:Envelope>");
}