Skip to content

Commit

Permalink
Encaplsulated ESDL transfrom parameters in new get schema method. Added
Browse files Browse the repository at this point in the history
an enum to indicate which schema being requested.
  • Loading branch information
kenrowland committed Jul 14, 2023
1 parent f5cc2ad commit 732446a
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 33 deletions.
68 changes: 36 additions & 32 deletions esp/bindings/http/platform/httpbinding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1429,10 +1429,7 @@ void EspHttpBinding::getSoapMessage(StringBuffer& soapmsg, IEspContext& ctx, CHt
StringBuffer req, tag, schema, filtered;
msg->marshall(req, NULL);

Owned<IProperties> params;
params.set(createProperties());

getServiceSchema(ctx, request, serviceQName, methodQName, params, getVersion(ctx), EsdlXslToXsd, schema);
getServiceSchema(ctx, request, serviceQName, methodQName, SCHEMA_SOAP, getVersion(ctx), schema);

getXMLMessageTag(ctx, true, methodQName, tag);
filterXmlBySchema(req,schema,tag.str(),filtered);
Expand Down Expand Up @@ -1732,9 +1729,10 @@ bool EspHttpBinding::getSchema(StringBuffer& schema, IEspContext &ctx, CHttpRequ
}

void EspHttpBinding::getServiceSchema(IEspContext& context, CHttpRequest* request, const char *serviceQName, const char *methodQName,
Owned<IProperties> &params, double version, EsdlXslTypeId EsdlXslType, StringBuffer &schema)
SchemaType schemaType, double version, StringBuffer &schema)
{
IProperties *opts = context.queryRequestParameters();
EsdlXslTypeId esdlXslType = EsdlXslToXsd;

Owned<IEsdlDefinition> esdlDef = createEsdlDefinition(nullptr, nullptr);
Owned<IEsdlDefinitionHelper> defHelper = createEsdlDefinitionHelper();
Expand All @@ -1745,6 +1743,31 @@ void EspHttpBinding::getServiceSchema(IEspContext& context, CHttpRequest* reque
throw MakeStringException(-1, "Unable to get service XML filename");
}

StringBuffer nstr;
generateEsdlNamespace(context, request, serviceQName, methodQName, nstr);

IProperties *params = createProperties();
params->setProp("version", StringBuffer("'").appendf("%g", version).append("'"));
params->setProp("tnsParam", StringBuffer("'").append(nstr).append("'").str());

//
// Selectively add parameters based on the type of schema requested
if (schemaType == SCHEMA_WSDL)
{
params->setProp( "create_wsdl", "true()" );
StringBuffer location(m_wsdlAddress.str());
if (request->queryParameters()->hasProp("wsdl_destination_path"))
location.append(request->queryParameters()->queryProp("wsdl_destination_path"));
else
location.append('/').append(serviceQName).appendf("?ver_=%g", version);
params->setProp("location", StringBuffer("'").append(location).append("'").str());
esdlXslType = EsdlXslToWsdl;
}
else if (schemaType == SCHEMA_XFORM)
{
params->setProp( "all_annot_Param", "true()" );
}

std::string xmlFilePath(getCFD());
xmlFilePath.append("esdl_files").append(PATHSEPSTR).append(xmlFilename.str());
esdlDef->addDefinitionsFromFile(xmlFilePath.c_str());
Expand All @@ -1754,17 +1777,10 @@ void EspHttpBinding::getServiceSchema(IEspContext& context, CHttpRequest* reque
StringBuffer xlstFile(getCFD());
xlstFile.append("xslt").append(PATHSEPSTR).append("esp_service_xml2xsd.xslt");

params->setProp("version", StringBuffer("'").appendf("%g", version).append("'"));

StringBuffer nstr;
generateEsdlNamespace(context, request, serviceQName, methodQName, nstr);
params->setProp("tnsParam", StringBuffer("'").append(nstr).append("'").str());

defHelper->loadTransform(xlstFile, params, EsdlXslType);
defHelper->toWSDL(*structs, schema, EsdlXslType, version, opts, nstr, optFlags);
defHelper->loadTransform(xlstFile, params, esdlXslType);
defHelper->toWSDL(*structs, schema, esdlXslType, version, opts, nstr, optFlags);
}


int EspHttpBinding::onGetXsd(IEspContext &context, CHttpRequest* request, CHttpResponse* response, const char *service, const char *method)
{
return getServiceWsdlOrXsd(context, request, response, service, method, false);
Expand Down Expand Up @@ -1801,7 +1817,7 @@ int EspHttpBinding::getServiceWsdlOrXsd(IEspContext &context, CHttpRequest* requ

StringBuffer schema;
getServiceSchema(context, request, serviceQName, methodQName,
params, version, isWsdl ? EsdlXslToWsdl : EsdlXslToXsd, schema);
isWsdl ? SCHEMA_WSDL : SCHEMA_XSD, version, schema);

response->setContent(schema.length(), schema.str());
response->setContentType(HTTP_TYPE_APPLICATION_XML_UTF8);
Expand Down Expand Up @@ -1897,10 +1913,7 @@ void EspHttpBinding::generateSampleXml(bool isRequest, IEspContext &context, CHt
return;
}

Owned<IProperties> params;
params.set(createProperties());

getServiceSchema(context, request, serviceQName, methodQName, params, getVersion(context), EsdlXslToXsd, schemaXml);
getServiceSchema(context, request, serviceQName, methodQName, SCHEMA_XML, getVersion(context), schemaXml);

Owned<IXmlSchema> schema;
IXmlType* type = nullptr;
Expand Down Expand Up @@ -1976,10 +1989,7 @@ void EspHttpBinding::generateSampleJson(bool isRequest, IEspContext &context, CH
return;
}

Owned<IProperties> params;
params.set(createProperties());

getServiceSchema(context, request, serviceQName, methodQName, params, getVersion(context), EsdlXslToXsd, schemaXml);
getServiceSchema(context, request, serviceQName, methodQName, SCHEMA_JSON, getVersion(context), schemaXml);

Owned<IXmlSchema> schema;
IXmlType* type = nullptr;
Expand Down Expand Up @@ -2451,13 +2461,10 @@ int EspHttpBinding::onGetXForm(IEspContext &context, CHttpRequest* request, CHtt
}
else
{
Owned<IProperties> params;
params.set(createProperties());
double ver = getVersion(context);

params->setProp( "all_annot_Param", "true()" );
StringBuffer schema;
getServiceSchema(context, request, serviceQName, methodQName, params, ver, EsdlXslToXsd, schema);

getServiceSchema(context, request, serviceQName, methodQName, SCHEMA_XFORM, ver, schema);

StringBuffer page;
IXslProcessor* xslp = getXmlLibXslProcessor();
Expand Down Expand Up @@ -2761,10 +2768,7 @@ void EspHttpBinding::validateResponse(IEspContext& context, CHttpRequest* reques
}

// schema
Owned<IProperties> params;
params.set(createProperties());

getServiceSchema(context, request, serviceQName, methodQName, params, getVersion(context), EsdlXslToXsd, xsd);
getServiceSchema(context, request, serviceQName, methodQName, SCHEMA_VALIDATION, getVersion(context), xsd);

// validation
if (getEspLogLevel()>LogMax)
Expand Down
12 changes: 11 additions & 1 deletion esp/bindings/http/platform/httpbinding.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -461,8 +461,18 @@ class esp_http_decl EspHttpBinding :
const char *serviceName, const char* methodName);
void sortResponse(IEspContext& context, CHttpRequest* request,MemoryBuffer& contentconst,
const char *serviceName, const char* methodName);

enum SchemaType {
SCHEMA_WSDL,
SCHEMA_XSD,
SCHEMA_JSON,
SCHEMA_XML,
SCHEMA_SOAP,
SCHEMA_XFORM,
SCHEMA_VALIDATION
};
void getServiceSchema(IEspContext& context, CHttpRequest* request, const char *serviceQName, const char *methodQName,
Owned<IProperties> &params, double version, EsdlXslTypeId EsdlXslType, StringBuffer &schema);
SchemaType schemaType, double version, StringBuffer &schema);
};

inline bool isEclIdeRequest(CHttpRequest *request)
Expand Down

0 comments on commit 732446a

Please sign in to comment.