zend framework 1 cdata wsdl - web-services

I have an existing soap webservice that is working but need one element to output data enclosed in the form of <data><![CDATA[some text]]></data>.
I tried it but on the xml response the data is outputting as <data><[CDATA[some text]]></data> instead of <data><![CDATA[some text]]></data>.
I read somewhere after googling that zend framework does the encoding of the < to < and > to > on cdata automatically before passing it to the xml.
How can I get only <data><![CDATA[some text]]></data> instead of <data><[CDATA[some text]]></data>?

Related

How to convert XML into string in Wso2

Scenario
I've a use case where I've XML tags as shown, I need to convert the complete XML as a single string but don't want to stringify them because it then converts the tags < >as < >
XML
<VERIFICATION>
<USER_VERIFICATION>
<USERNAME>XXXX</USERNAME>
<PASSWORD>XXXXX</PASSWORD>
</USER_VERIFICATION>
<REQUEST_DATA>
<TRANSACTION_ID>XXXXX</TRANSACTION_ID>
<SESSION_ID/>
<CITIZEN_NUMBER>160XXXXX</CITIZEN_NUMBER>
<CONTACT_NUMBER>033XXXX</CONTACT_NUMBER>
<AREA_NAME>khyber-pakhtunkhwa</AREA_NAME>
</REQUEST_DATA>
</VERIFICATION>
Question
My question is how do I convert the XML to string without affecting the angle tags?
Place them within a CDATA tag.
<![CDATA[YOUR XML]]>

Why is libxml not storing html in my htmlDocPtr?

I am working on a piece of software that uses libxml to store xml on webpages in an xmlDocPtr. I need to expand this functionality to do the same for html.
The original code:
xmlDocPtr doc = xmlParseEntity(filename.c_str());
Where filename = 10.1.1.135/poll_data.xml and everything works just fine
Now, I have html filename = 10.1.1.165/index.htm and would like to store this as well. I have tried using htmlParseDoc with no success.
htmlDocPtr doc = htmlParseFile(filename.c_str(), "windows-1252");
The resulting doc object is not null but it does not contain the contents of the index.html
Netbeans spits out:
http://10.1.1.165/index.htm:1: HTML parser error : Document is empty
Any suggestions?

how to save a xml list from response to a csv file in JMeter

one of my tests uses a Loop Controller, CSV Data Set Config and an If Controller to iterate through a csv list to do one request with several parameters defined in an csv file.
I want to change this testcase to use a list of parameters that i get from an GET response in an xml format.
for example using this xml list: http://www.w3schools.com/xml/cd_catalog.xml
now i want to iterate through all < TITLE > values.
i tried to save the response with the 'Save Responses to a file' Listener and then use a BeanShell Listener to read the file and transform it to a csv list which contains only the < TITLE > values. but i'm not sure how to to this transformation part in the BeanShell Listener.
import org.apache.jmeter.services.FileServer;
import org.apache.commons.io.FileUtils;
File xmlFile = new File(FileServer.getFileServer().getBaseDir()+"/resources/data/csv/response1.xml", "UTF-8");
String fileData = FileUtils.readFileToString(xmlFile);
fileData = fileData.replaceAll("<?xml version="1.0" encoding="UTF-8"?>", "");
fileData = fileData.replaceAll("<CATALOG>", "");
//...
FileUtils.writeStringToFile(xmlFile, fileData);
/*
f = new FileOutputStream(FileServer.getFileServer().getBaseDir()+"/resources/data/csv/parameterlist.csv", true);
p = new PrintStream(f);
p.println(fileData);
p.close();
f.close();
*/
there must be some solution using regex, xpath or XSL transformation on all < TITLE > elements or is there an easier way that i didn't thought of?
found a different and easier method that works for my purpose:
Get Request to get the xml list.
add XPath Extractor
Reference Name: 'titles'
XPAth query: '//title'
ForEach Controller
Input variable prefix: 'titles'
Output variable name: 'title'

Parametrising encoded web service requests

I am trying to parametrise web service requests in a web performance test. Using Fiddler2 I have recorded a sequence of over 60 web service requests for a transaction performed by my desktop application and saved them as a .webtest file. This web test runs without any errors and the responses that I have checked look correct.
When the web service requests are viewed in Visual Studio 2012 they appear in plain text and so I should be able to edit them to parametrise the values in the SOAP requests. For example, most of the requests contain the text <Database>db1a</Database> (actually it has <Database>db1a</Database>) and I want to change them to get the database name from a context parameter. There are several other items to replace with parameters. For this one transaction there are over 60 web service requests and I have other transactions to record. The .webtest file contains XML and the requests looks like:
<Request Method="POST" Version="1.1" Url="http://example.com/somewhere.asmx" ThinkTime="83" Timeout="60" ParseDependentRequests="True" FollowRedirects="True" RecordResult="True" Cache="False" ResponseTimeGoal="0" Encoding="utf-8">
<Headers>
<Header Name="Content-Type" Value="text/xml; charset=utf-8" />
<Header Name="SOAPAction" Value=""http://example.com/webservices/VariousActionNamesHere"" />
</Headers>
<StringHttpBody ContentType="text/xml; charset=utf-8">PAA/AHgAbQBsACAAdg
... lots more characters not shown
+AA==</StringHttpBody>
</Request>
The StringHttpBody field contains an encoded version of the SOAP request. Visual Studio shows it as plain text. What is the encoding of this field and how can I decode and encode it?
I have installed Release 3.0 of the “Web and Load Test Plugins for Visual Studio Team Test” from http://teamtestplugins.codeplex.com/ . They provide a slightly better interface for editing the SOAP requests one at a time. But they do not allow mass changes.
Converting the web test to a coded web test (ie into C#) shows the SOAP requests as simple text and they could be edited there but I would prefer to keep the flexibility of a .webtest file.
Update: I have posted a partial answer to the question. Whilst it works, it feels the wrong way to do the work because it feels too complicated. So I am looking for a better overall approach.
StringHttpBody is base64 encoded. The raw body of the request is converted to a UTF-16 byte array and then base64 encoded, like so:
Convert.ToBase64String(Encoding.Unicode.GetBytes(oSession.GetRequestBodyAsString()));
For a quick view, you can copy/paste this string into Fiddler's Tools > TextWizard screen then use the From Base64 option to decode.
Here is part of an answer to working with the StringHttpBody fields. This is about decoding and encoding the fields to allow easier understanding and modification.
Read the input XML and find the contents of the StringHttpBody fields. Replace each field contents with the result of calling the following routine on the original contents. Write the all the lines to a new intermediate file. The byte array contains UTF-16 characters as high and low bytes. (All the characters I have seen so far have high byte zero.)
private string DecodeBody(string source) {
byte[] outBytes = Convert.FromBase64String(source);
StringBuilder sb = new StringBuilder();
Assert( (outBytes.Length % 2) != 0 );
for (int ix = 0; ix < outBytes.Length; ix += 2) {
Assert(outBytes[ix] != 0);
sb.Append((char)outBytes[ix + 1]);
}
return sb.ToString();
}
Now have a file containing a simple text version of the .webtest file. This file can easily be edited to parameterise fields of the requests. Have an routine used similar to the one above and writing to another intermediate file. The routine has statements such as:
source = source.Replace("<Database>db1a</Database>", "<Database>{{DatabaseName}}</Database>");
The final intermediate file is then reencoded to create a new .webtest file. Just as before the contents of the StringHttpBody fields are found and replaced with the result of calling a routine. The encoding routine is:
private string EncodeBody(string source) {
StringBuilder sb = new StringBuilder();
byte[] outBytes = new byte[2 * source.Length];
for (int ix = 0; ix < source.Length; ix++) {
char ch = source[ix];
outBytes[2 * ix] = (byte)(((int)ch) & 0xFF);
outBytes[2 * ix + 1] = (byte)((((int)ch) / 256) & 0xFF);
}
sb.Append(Convert.ToBase64String(outBytes));
return sb.ToString();
}
The flow of files is thus:
decode original.webtest > intermediate1
parameterise intermediate1 > intermediate2
encode intermediate2 > final.webtest
On the small number of .webtest files I have tried the encode operation is the inverse of the decode operation, the original file from before decoding is identical to the file after encoding. Having the two intermediate files allows easy checking and searching of the contents of the unencoded file and the effect of the parameterise step.
For
[StringHttpBody ContentType="application/json"]
To Decode the body:
var encodedString = childNode.InnerText;
var encodedStringBytes = Convert.FromBase64String(encodedString);
var decodedString = Encoding.Unicode.GetString(encodedStringBytes);
JObject jsonString =JsonConvert.DeserializeObject(decodedString);
To Encode the body:
childNode.InnerText =
Convert.ToBase64String(Encoding.Unicode.GetBytes(JsonConvert.SerializeObject(jsonString)));
I think this might help.

How to replace text in content control after, XML binding using docx4j

I am using docx4j 2.8.1 with Content Controls in my .docx file. I can replace the CustomXML part by injecting my own XML and then calling BindingHandler.applyBindings after supplying the input XML. I can add a token in my XML such as ¶ then I would like to replace that token in the MainDocumentPart, but using that approach, when I iterate through the content in the MainDocumentPart with this (link) method none of my text from my XML is even in the collection extracted from the MainDocumentPart. I am thinking that even after binding the XML, it remains separate from the MainDocumentPart (??)
I haven't tried this with anything more than a little test doc yet. My token is the Pilcrow: ¶. Since it's a single character, it won't be split in separate runs. My code is:
private void injectXml (WordprocessingMLPackage wordMLPackage) throws JAXBException {
MainDocumentPart part = wordMLPackage.getMainDocumentPart();
String xml = XmlUtils.marshaltoString(part.getJaxbElement(), true);
xml = xml.replaceAll("¶", "</w:t><w:br/><w:t>");
Object obj = XmlUtils.unmarshalString(xml);
part.setJaxbElement((Document) obj);
}
The pilcrow character comes from the XML and is injected by applying the XML bindings to the content controls. The problem is that the content from the XML does not seem to be in the MainDocumentPart so the replace doesn't work.
(Using docx4j 2.8.1)