This post talks about using one external java component to sign a SOAP message request, with a digital certificate, inside performance test projects built at Borland SilkPerformer.
As part of a project that I have been worked, I needed to sign a SOAP request using a digital certificate. I not found any way to do that using only SilkPerformer language in a bdl script, in a simple SOAP/HTML project, then I built a java program with only one responsability: sign a SOAP request message using a given digital certificate. In the SilkPerformer project was very easy to use the jar file and call the method of a java class that receive the original text and responds with it signed.
First, it is necessary to create one project in SilkPerformer using the XML/SOAP template.
After that, add the data file of the java component to sign the request. Here, will be used the jar file of the SignSOAPRequest project, found at https://sourceforge.net/projects/signsoaprequest/
After that, add the data files needed the to sign process of the request:
Now, will be created the bdf file of the script. It will be like described below:
dcluser
user
VU_User
transactions
TInit : begin;
TTestCase : 1;
TEnd : end;
JavaCreateJavaVM();
signSOAPRequestObject := JavaLoadObject("br/gov/dataprev/soaptools/sign/SignSOAPRequest");
JavaSetString(signSOAPRequestObject, [properties file name]);
JavaCallMethod(signSOAPRequestObject, "setResourceNameConfiguracoes");
SslSetEncryption(SSL_VERSION_TLS1, SSL_CIPHERS_SSLv3);
SslSetClientCert([pem file name]);
SslSetClientCertPassword([password]);
JavaSetString(signSOAPRequestObject, originalMessageString);
JavaCallMethod(signSOAPRequestObject, "sign");
JavaGetString(signSOAPRequestObject, signedMessageString);
WebPagePost([string of the target webservice], signedMessageString, STRING_COMPLETE, "application/soap+xml;charset=UTF-8", "01_TTestCase");
JavaFreeObject(signSOAPRequestObject);
At this point, there are a functional script that can be used to send a signed message to the webservice.
Others things may be done to make the test more interesting, one template of the request message can be used making possible to use a file with a mass of data to test diferent cases.
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:jws="http://your.application.namespace.com/">
<soapenv:Header/>
<soapenv:Body>
<jws:RequestObject>
<FirstRequestParam>{value_for_first_request_param}</FirstRequestParam>
<SecondRequestParam>{value_for_second_request_param}</SecondRequestParam>
</jws:RequestObject>
</soapenv:Body>
</soapenv:Envelope>
With the template above, the followed code can be inserted to load a file of mass data and replace the text between “{}” to test differents cases:
FileCSVLoadGlobal(massVariable, [csv_mass_file], ",");
msgTemplate := loadTemplate([name_of_template_file]);
dclfunc
function loadTemplate(fileName: string): string
var
hFile1, nSize: number;
begin
FOpen(hFile1, fileName, OPT_FILE_ACCESS_READ);
FSizeGet(hFile1, nSize);
FRead(hFile1, loadTemplate, nSize);
FClose(hFile1);
end loadTemplate;
FileGetNextRow(massVariable);
ven_first_param:= FileGetCol(massVariable, 1, STRING_COMPLETE)
ven_second_param:= FileGetCol(massVariable, 2, STRING_COMPLETE)
msgTemplateExpanded := msgTemplate;
FStrReplace(msgTemplateExpanded, "{value_for_first_request_param}", ven_first_param);
FStrReplace(msgTemplateExpanded, "{value_for_second_request_param}", ven_second_param);
JavaSetString(signSOAPRequestObject, msgTemplateExpanded);
JavaCallMethod(signSOAPRequestObject, "sign");
JavaGetString(signSOAPRequestObject, signedMessageString);
More one interesting thing is to do validations over the result, like that:
WebXmlVerifyNodeValue(ToEncoding("/soap:Envelope[1]/soap:Body[1]/ns2:ResultTag[1]/Code[1]"), ven_expectedReturn, 1, WEB_FLAG_EQUAL,
ToEncoding("xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:ns2=\"http://your.namespace.com/\""), 1,
ToEncoding("text/xml;charset=UTF-8"), SEVERITY_ERROR);
WebPagePost([string of the target webservice], signedMessageString, STRING_COMPLETE, "application/soap+xml;charset=UTF-8", "01_TTestCase");
Almost forgotten, the “01_TTestCase” parameter is one measure set in TInit, like that:
MeasureSetBound("01_TTestCase", MEASURE_PAGE_PAGETIME , 1, 5.0, SEVERITY_SUCCESS);
It´s all folks!