<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>q fraction</title>
	<atom:link href="http://blog.sztart.pl/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.sztart.pl</link>
	<description>Do Not Try, Just Do It</description>
	<lastBuildDate>Sun, 16 Oct 2011 22:20:24 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Searching data in xml efficiently</title>
		<link>http://blog.sztart.pl/2011/10/searching-data-in-xml-efficiently/</link>
		<comments>http://blog.sztart.pl/2011/10/searching-data-in-xml-efficiently/#comments</comments>
		<pubDate>Sun, 16 Oct 2011 20:12:16 +0000</pubDate>
		<dc:creator>serek</dc:creator>
				<category><![CDATA[Performance]]></category>
		<category><![CDATA[Php]]></category>
		<category><![CDATA[Xml]]></category>

		<guid isPermaLink="false">http://blog.sztart.pl/?p=162</guid>
		<description><![CDATA[There is many way to search data in xml documents. For example I needed find Spanish subtitles in given xml: &#60;?xml version=&#34;1.0&#34; encoding=&#34;UTF-8&#34;?&#62; &#60;import&#62; &#60;video&#62; &#60;title&#62;Movie_1&#60;/title&#62; &#60;id&#62;123&#60;/id&#62; &#60;meta_data&#62; &#60;duration&#62;1:59:12&#60;/duration&#62; &#60;/meta_data&#62; &#60;subtitles&#62; &#60;subtitle&#62;ftp://user:pass@example.com/123/subtitles_fi.sub&#60;/subtitle&#62; &#60;subtitle&#62;ftp://user:pass@example.com/123/subtitles_en.sub&#60;/subtitle&#62; &#60;subtitle&#62;ftp://user:pass@example.com/123/subtitles_es.sub&#60;/subtitle&#62; &#60;subtitle&#62;ftp://user:pass@example.com/123/subtitles_pl.sub&#60;/subtitle&#62; &#60;/subtitles&#62; &#60;/video&#62; &#60;/import&#62; The most easy way is of course: /** * Return callback function which check if fileURL contains [...]]]></description>
			<content:encoded><![CDATA[<p>There is many way to search data in xml documents.</p>
<p>For example I needed find Spanish subtitles in given xml:</p>


<div class="wp-geshi-highlight-wrap5"><div class="wp-geshi-highlight-wrap4"><div class="wp-geshi-highlight-wrap3"><div class="wp-geshi-highlight-wrap2"><div class="wp-geshi-highlight-wrap"><div class="wp-geshi-highlight"><div class="xml"><pre class="de1"><span class="sc3"><span class="re1">&lt;?xml</span> <span class="re0">version</span>=<span class="st0">&quot;1.0&quot;</span> <span class="re0">encoding</span>=<span class="st0">&quot;UTF-8&quot;</span><span class="re2">?&gt;</span></span> 
<span class="sc3"><span class="re1">&lt;import<span class="re2">&gt;</span></span></span>
	<span class="sc3"><span class="re1">&lt;video<span class="re2">&gt;</span></span></span>
		<span class="sc3"><span class="re1">&lt;title<span class="re2">&gt;</span></span></span>Movie_1<span class="sc3"><span class="re1">&lt;/title<span class="re2">&gt;</span></span></span>
		<span class="sc3"><span class="re1">&lt;id<span class="re2">&gt;</span></span></span>123<span class="sc3"><span class="re1">&lt;/id<span class="re2">&gt;</span></span></span>
		<span class="sc3"><span class="re1">&lt;meta_data<span class="re2">&gt;</span></span></span>
			<span class="sc3"><span class="re1">&lt;duration<span class="re2">&gt;</span></span></span>1:59:12<span class="sc3"><span class="re1">&lt;/duration<span class="re2">&gt;</span></span></span>
		<span class="sc3"><span class="re1">&lt;/meta_data<span class="re2">&gt;</span></span></span>
		<span class="sc3"><span class="re1">&lt;subtitles<span class="re2">&gt;</span></span></span>
			<span class="sc3"><span class="re1">&lt;subtitle<span class="re2">&gt;</span></span></span>ftp://user:pass@example.com/123/subtitles_fi.sub<span class="sc3"><span class="re1">&lt;/subtitle<span class="re2">&gt;</span></span></span>
			<span class="sc3"><span class="re1">&lt;subtitle<span class="re2">&gt;</span></span></span>ftp://user:pass@example.com/123/subtitles_en.sub<span class="sc3"><span class="re1">&lt;/subtitle<span class="re2">&gt;</span></span></span>
			<span class="sc3"><span class="re1">&lt;subtitle<span class="re2">&gt;</span></span></span>ftp://user:pass@example.com/123/subtitles_es.sub<span class="sc3"><span class="re1">&lt;/subtitle<span class="re2">&gt;</span></span></span>
			<span class="sc3"><span class="re1">&lt;subtitle<span class="re2">&gt;</span></span></span>ftp://user:pass@example.com/123/subtitles_pl.sub<span class="sc3"><span class="re1">&lt;/subtitle<span class="re2">&gt;</span></span></span>
		<span class="sc3"><span class="re1">&lt;/subtitles<span class="re2">&gt;</span></span></span>
	<span class="sc3"><span class="re1">&lt;/video<span class="re2">&gt;</span></span></span>
<span class="sc3"><span class="re1">&lt;/import<span class="re2">&gt;</span></span></span></pre></div></div></div></div></div></div></div>


<p>The most easy way is of course:</p>


<div class="wp-geshi-highlight-wrap5"><div class="wp-geshi-highlight-wrap4"><div class="wp-geshi-highlight-wrap3"><div class="wp-geshi-highlight-wrap2"><div class="wp-geshi-highlight-wrap"><div class="wp-geshi-highlight"><div class="php"><pre class="de1"><span class="co4">/**
 * Return callback function which check if fileURL contains proper language version 
 */</span>
<span class="re0">$fFindSubtitlesByLang</span> <span class="sy0">=</span> <span class="kw2">function</span> <span class="br0">&#40;</span><span class="re0">$lang</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
	<span class="re0">$lang</span> <span class="sy0">.=</span> <span class="st_h">'.'</span><span class="sy0">;</span> <span class="co1">//to be sure that no part of 'example' word is searching</span>
	<span class="kw1">return</span> <span class="kw2">function</span> <span class="br0">&#40;</span><span class="re0">$fileUrl</span><span class="br0">&#41;</span> <span class="kw2">use</span> <span class="br0">&#40;</span><span class="re0">$lang</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
		<span class="kw1">return</span> <span class="kw3">strpos</span><span class="br0">&#40;</span><span class="re0">$fileUrl</span><span class="sy0">,</span> <span class="re0">$lang</span><span class="br0">&#41;</span><span class="sy0">;</span>
	<span class="br0">&#125;</span><span class="sy0">;</span>
<span class="br0">&#125;</span><span class="sy0">;</span>
&nbsp;
<span class="co1">//normal usage of Simple Xml Element</span>
<span class="re0">$subtitles</span> <span class="sy0">=</span> <span class="br0">&#40;</span><span class="kw3">array</span><span class="br0">&#41;</span> <span class="re0">$xml</span><span class="sy0">-&gt;</span><span class="me1">video</span><span class="sy0">-&gt;</span><span class="me1">subtitles</span><span class="sy0">;</span>
<span class="re0">$spanishSubtitles</span> <span class="sy0">=</span> <span class="kw3">reset</span><span class="br0">&#40;</span><span class="kw3">array_filter</span><span class="br0">&#40;</span><span class="re0">$subtitles</span><span class="br0">&#91;</span><span class="st_h">'subtitle'</span><span class="br0">&#93;</span><span class="sy0">,</span> <span class="re0">$fFindSubtitlesByLang</span><span class="br0">&#40;</span><span class="st_h">'es'</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span>
<span class="kw1">echo</span> <span class="re0">$spanishSubtitles</span> <span class="sy0">.</span>PHP_EOL<span class="sy0">;</span></pre></div></div></div></div></div></div></div>


<p>It works, great. But there is also possibility to use Xpath</p>


<div class="wp-geshi-highlight-wrap5"><div class="wp-geshi-highlight-wrap4"><div class="wp-geshi-highlight-wrap3"><div class="wp-geshi-highlight-wrap2"><div class="wp-geshi-highlight-wrap"><div class="wp-geshi-highlight"><div class="php"><pre class="de1"><span class="re0">$subtitles</span> <span class="sy0">=</span> <span class="re0">$xml</span><span class="sy0">-&gt;</span><span class="me1">xpath</span><span class="br0">&#40;</span><span class="st_h">'/import/video/subtitles/subtitle'</span><span class="br0">&#41;</span><span class="sy0">;</span>
<span class="re0">$spanishSubtitles</span> <span class="sy0">=</span> <span class="kw3">reset</span><span class="br0">&#40;</span><span class="kw3">array_filter</span><span class="br0">&#40;</span><span class="re0">$subtitles</span><span class="sy0">,</span> <span class="re0">$fFindSubtitlesByLang</span><span class="br0">&#40;</span><span class="st_h">'es'</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span>
<span class="kw1">echo</span> <span class="re0">$spanishSubtitles</span> <span class="sy0">.</span>PHP_EOL<span class="sy0">;</span></pre></div></div></div></div></div></div></div>


<p>In my opinion this solution looks much better. Special designed function (xpath) is used for traversing XML, but this attempt is slower than previous example. This is not good.</p>
<p>So lets try modify xpath a little:</p>


<div class="wp-geshi-highlight-wrap5"><div class="wp-geshi-highlight-wrap4"><div class="wp-geshi-highlight-wrap3"><div class="wp-geshi-highlight-wrap2"><div class="wp-geshi-highlight-wrap"><div class="wp-geshi-highlight"><div class="php"><pre class="de1"><span class="re0">$spanishSubtitles</span> <span class="sy0">=</span> <span class="kw3">reset</span><span class="br0">&#40;</span><span class="re0">$xml</span><span class="sy0">-&gt;</span><span class="me1">xpath</span><span class="br0">&#40;</span><span class="st_h">'/import/video/subtitles/subtitle[contains(., &quot;es.&quot;)]'</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span>
<span class="kw1">echo</span> <span class="re0">$spanishSubtitles</span> <span class="sy0">.</span>PHP_EOL<span class="sy0">;</span></pre></div></div></div></div></div></div></div>


<p>Viola! Fast, readable, only 2 lines of code, not need to use anonymous function. Also adding some additional logic (e.g. specify id of element which I am looking for) is extremely easy.</p>
<p>More info about available function can be found on W3C pages <a href="http://www.w3schools.com/xpath/xpath_functions.asp" target="_blank">http://www.w3schools.com/xpath/xpath_functions.asp</a></p>
<p>All files are available here: <a href="https://github.com/mrok/xpath-examples">https://github.com/mrok/xpath-examples</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.sztart.pl/2011/10/searching-data-in-xml-efficiently/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Storing sessions in memcache(d)</title>
		<link>http://blog.sztart.pl/2011/10/storing-sessions-in-memcached-2/</link>
		<comments>http://blog.sztart.pl/2011/10/storing-sessions-in-memcached-2/#comments</comments>
		<pubDate>Sat, 15 Oct 2011 19:49:50 +0000</pubDate>
		<dc:creator>serek</dc:creator>
				<category><![CDATA[Php]]></category>

		<guid isPermaLink="false">http://blog.sztart.pl/?p=153</guid>
		<description><![CDATA[Sometimes I hear idea about storing user session data in memcache. It is great idea, memcache is fast, easy to scale, cached data can be shared between many servers, so it is not necessary to take care about advanced load balancing. Yeach it is a trap. Even official Memcached FAQ says that: http://code.google.com/p/memcached/wiki/NewProgrammingFAQ#Why_is_memcached_not_recommended_for_sessions?_Everyone_does_it! http://dormando.livejournal.com/495593.html To prove that [...]]]></description>
			<content:encoded><![CDATA[<p>Sometimes I hear idea about storing user session data in memcache. It is great idea, memcache is fast, easy to scale, cached data can be shared between many servers, so it is not necessary to take care about advanced load balancing. Yeach it is a trap. Even official Memcached FAQ says that:</p>
<p><a href="http://code.google.com/p/memcached/wiki/NewProgrammingFAQ#Why_is_memcached_not_recommended_for_sessions?_Everyone_does_it!">http://code.google.com/p/memcached/wiki/NewProgrammingFAQ#Why_is_memcached_not_recommended_for_sessions?_Everyone_does_it!<br />
</a><a href="http://dormando.livejournal.com/495593.html">http://dormando.livejournal.com/495593.html</a></p>
<p>To prove that described situation can easily happened I wrote some example code available here <a href="https://mrok@github.com/mrok/memcache_test.git" target="_blank">https://mrok@github.com/mrok/memcache_test.git</a>. Download it, fix memcache configuration section, run and wait for first missing key. Do you still think it is good idea?</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.sztart.pl/2011/10/storing-sessions-in-memcached-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using Zend Framework components separately</title>
		<link>http://blog.sztart.pl/2011/08/using-zend-framework-components-separately/</link>
		<comments>http://blog.sztart.pl/2011/08/using-zend-framework-components-separately/#comments</comments>
		<pubDate>Sun, 07 Aug 2011 19:37:54 +0000</pubDate>
		<dc:creator>serek</dc:creator>
				<category><![CDATA[Php]]></category>
		<category><![CDATA[Zend Framework]]></category>

		<guid isPermaLink="false">http://blog.sztart.pl/?p=114</guid>
		<description><![CDATA[Did you have a situation when you are working on a project which is not using Zend Framework (ZF) and you need provide functionality which is already implemented within ZF? I did, and I do not like to reinvent a wheel. This is what I did: Task: Automatically detect user preferred language and set proper month names for select box and [...]]]></description>
			<content:encoded><![CDATA[<p>Did you have a situation when you are working on a project which is not using Zend Framework (ZF) and you need provide functionality which is already implemented within ZF? I did, and I do not like to reinvent a wheel. This is what I did:</p>
<p>Task: Automatically detect user preferred language and set proper month names for select box and proper currency sign.</p>
<p>What should be done:</p>
<p>1. Add needed component and dependencies into product structure &#8211;  the best way IMHO is create something called &#8216;lib&#8217; directory and put there all third part library.</p>
<p><a href="http://blog.sztart.pl/wp-content/uploads/2011/07/zf_autoloader.png" rel="lightbox[114]"><img class="alignnone size-full wp-image-115" title="zf_autoloader" src="http://blog.sztart.pl/wp-content/uploads/2011/07/zf_autoloader.png" alt="" width="186" height="162" /></a></p>
<p>2. Setup autoloader for ZF.</p>
<pre>set_include_path(get_include_path() . PATH_SEPARATOR . getcwd() . '/library');
require getcwd() . '/library/Zend/Loader/Autoloader.php';

$autoloader = Zend_Loader_Autoloader::getInstance();</pre>
<p>If your additional libraries does not have commons namespaces structure you can use:</p>
<pre>$autoloader-&gt;setFallbackAutoloader(true)</pre>
<p>or write your own autoloader and register it by pushAutoloader method.</p>
<p>3. Use ZF as you like:</p>
<pre>$locale = new Zend_Locale();</pre>
<pre>echo 'Language: ' . $locale-&gt;getLanguage() . '&lt;br /&gt;';   //return da_DK</pre>
<pre>$list = $locale-&gt;getTranslationList('Month', $locale);
var_dump($list);</pre>
<pre>string 'januar' (length=6)
string 'februar' (length=7)
string 'marts' (length=5)
string 'april' (length=5)
string 'maj' (length=3)
string 'juni' (length=4)
string 'juli' (length=4)
string 'august' (length=6)
string 'september' (length=9)
string 'oktober' (length=7)
string 'november' (length=8)
string 'december' (length=8)</pre>
<pre>$currency = new Zend_Currency($locale);

var_dump($currency-&gt;getShortName()); //return DKK
var_dump($currency-&gt;getName()); //return Dansk krone
var_dump($currency-&gt;getSymbol()); //return kr</pre>
<p>P.S You should also add Currency.php and Currency directory to your lib dir (those are not listed at first point).</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.sztart.pl/2011/08/using-zend-framework-components-separately/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Symfony 2.0 released</title>
		<link>http://blog.sztart.pl/2011/07/symfony-2-0-released/</link>
		<comments>http://blog.sztart.pl/2011/07/symfony-2-0-released/#comments</comments>
		<pubDate>Thu, 28 Jul 2011 18:28:14 +0000</pubDate>
		<dc:creator>serek</dc:creator>
				<category><![CDATA[Php]]></category>

		<guid isPermaLink="false">http://blog.sztart.pl/?p=118</guid>
		<description><![CDATA[I have waited long time for this moment. And now it is http://symfony.com/blog/symfony-2-0 More than 2 years after PHP 5.3 release, with all namespace, closures and gc goods, PHP community get first* modern framework for this language. * I am not sure if lithium was not faster  http://lithify.me/en]]></description>
			<content:encoded><![CDATA[<p>I have waited long time for this moment. And now it is <a href="http://symfony.com/blog/symfony-2-0">http://symfony.com/blog/symfony-2-0</a></p>
<p>More than 2 years after PHP 5.3 release, with all namespace, closures and gc goods, PHP community get first* modern framework for this language.</p>
<p>* I am not sure if lithium was not faster <img src='http://blog.sztart.pl/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />  <a href="http://lithify.me/en">http://lithify.me/en</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.sztart.pl/2011/07/symfony-2-0-released/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Work effectively with mocked Web Services using SoapUI</title>
		<link>http://blog.sztart.pl/2011/07/webservices-mockups/</link>
		<comments>http://blog.sztart.pl/2011/07/webservices-mockups/#comments</comments>
		<pubDate>Sun, 17 Jul 2011 23:02:10 +0000</pubDate>
		<dc:creator>serek</dc:creator>
				<category><![CDATA[Software testing]]></category>

		<guid isPermaLink="false">http://blog.sztart.pl/?p=9</guid>
		<description><![CDATA[Today at work we get interesting case. How to test web-service(WS) client when only WSDL description is available,  WS was still in development? WSDL document is rather self descriptive so it is not a tragedy. At least we know what can be expected as response after specified request. With help of SoapUI live become easier. [...]]]></description>
			<content:encoded><![CDATA[<p>Today at work we get interesting case. How to test web-service(WS) client when only WSDL description is available,  WS was still in development?</p>
<p>WSDL document is rather self descriptive so it is not a tragedy. At least we know what can be expected as response after specified request.</p>
<p>With help of <a href="http://www.soapui.org/">SoapUI</a> live become easier.</p>
<p>Lets try to create simulation of web-service when only WSDL file is available.</p>
<p><strong>1. Create new project (I use SoapUI v4.0.0):</strong></p>
<p>- for test purpose I choose <a href="http://webapi.allegro.pl/uploader.php?wsdl">Allegro Web API</a> &#8211; the biggest Polish online auction system</p>
<p><a href="http://blog.sztart.pl/wp-content/uploads/2011/07/new_project.png" rel="lightbox[9]"><img class="alignnone size-full wp-image-10" title="New SOAP UI project" src="http://blog.sztart.pl/wp-content/uploads/2011/07/new_project.png" alt="" width="666" height="322" /></a></p>
<p>Probably you also noticed option &#8220;Create a Web Service Simulation &#8230;&#8221; &#8211; do not forget checked it.</p>
<p><strong>2. Next form lets us generate mocks for chosen services:</strong></p>
<p><a href="http://blog.sztart.pl/wp-content/uploads/2011/07/Generate-MockService.png" rel="lightbox[9]"><img class="alignnone size-full wp-image-12" title="Generate MockService" src="http://blog.sztart.pl/wp-content/uploads/2011/07/Generate-MockService.png" alt="" width="581" height="417" /></a></p>
<p>I chose doLogin method to avoid passing 25 different parameters.</p>
<p><strong>3. Click ok, provide name of your new created mockService, again click ok</strong></p>
<p><strong>4. If everything went OK your screen should look like image bellow:</strong></p>
<p><a href="http://blog.sztart.pl/wp-content/uploads/2011/07/Mock-Service-List.png" rel="lightbox[9]"><img class="alignnone size-full wp-image-14" title="Mock Service List" src="http://blog.sztart.pl/wp-content/uploads/2011/07/Mock-Service-List.png" alt="" width="666" /></a></p>
<p>&nbsp;</p>
<p><strong>5. Double click on &#8220;do Login&#8221; service to open MockResponses List.</strong></p>
<p><a href="http://blog.sztart.pl/wp-content/uploads/2011/07/Mock-Responses-List.png" rel="lightbox[9]"><img class="alignnone size-full wp-image-16" title="Mock Responses List" src="http://blog.sztart.pl/wp-content/uploads/2011/07/Mock-Responses-List.png" alt="" width="598" height="445" /></a></p>
<p><strong>6. Right click on &#8216;Response 1&#8242; and Show MockResponse Editor</strong></p>
<p>In editor we can create response text as we want. For example.</p>
<pre>&lt;soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:urn="urn:AllegroWebApi"&gt;
   &lt;soapenv:Header/&gt;
   &lt;soapenv:Body&gt;
      &lt;urn:doLoginResponse soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"&gt;
         &lt;session-handle-part xsi:type="xsd:string"&gt;abcdef098765&lt;/session-handle-part&gt;
         &lt;user-id xsi:type="xsd:long"&gt;345&lt;/user-id&gt;
         &lt;server-time xsi:type="xsd:long"&gt;12345678&lt;/server-time&gt;
      &lt;/urn:doLoginResponse&gt;
   &lt;/soapenv:Body&gt;
&lt;/soapenv:Envelope&gt;</pre>
<p><strong>7. Run server </strong></p>
<p><a href="http://blog.sztart.pl/wp-content/uploads/2011/07/run_server.png" rel="lightbox[9]"><img class="alignnone size-full wp-image-35" title="run_server" src="http://blog.sztart.pl/wp-content/uploads/2011/07/run_server.png" alt="" width="646" height="97" /></a></p>
<p><strong>8. Right click on the &#8216;Response 1&#8242; Mock and choose &#8216;Open request&#8217; option.</strong></p>
<p>Then by clicking on green arrow you can test your MockServer. In response window you should receive the same xml which you provide in 6th step.</p>
<p>Lets try this outside SoapUI and write any Python code (Suds module available <a href="https://fedorahosted.org/suds/">here</a>):</p>
<pre>from suds.client import Client

WSDLURL = 'http://szymon:8088/mockAllegroWebApiBinding?WSDL'

if __name__ == '__main__':
    client = Client(WSDLURL)

    params = {'user-login' : 'testUser',
              'user-password' : 'pass',
              'country-code' : 12,
              'webapi-key': 'xxxxYYYYY',
              'local-version' : 32546}
    response = client.service.doLogin(**params)
    print response</pre>
<p>Response</p>
<pre>(reply){
   session-handle-part = "abcdef098765"
   user-id = 345
   server-time = 12345678
 }</pre>
<p>Do not forget change value for WSDLURL.</p>
<p>It is very easy way to test not exist yet webservice. Manualy defined reponse are usefull for modes:</p>
<ul>
<li>SEQUENCE</li>
<li>RANDOM</li>
<li>QUERY_MATCH</li>
<li>XPATH</li>
</ul>
<p>more information abut them are available on soapUI project <a href="http://www.soapui.org/Service-Mocking/simulating-complex-behaviour.html#Groovy_Script_Dispatching">page</a>.</p>
<p>What in case that we need more logic to prepare resposne and it should be depended from request parameter? It is also not a problem. Everything what we need is set response mode as SCRIPT and write logic using groovy.</p>
<p>For example lets return user-id as doubled country code.</p>
<pre>def util = new com.eviware.soapui.support.GroovyUtils(context)
def xml = util.getXmlHolder(mockRequest.requestContent)
context.userId = xml.getNodeValue("//country-code").toInteger() * 2</pre>
<p>then in response editor change</p>
<pre>         &lt;user-id xsi:type="xsd:long"&gt;345&lt;/user-id&gt;</pre>
<p>into<span class="Apple-style-span" style="font-family: Consolas, Monaco, monospace; font-size: 12px; line-height: 18px; white-space: pre;">      </span></p>
<pre>         &lt;user-id xsi:type="xsd:long"&gt;${userId}&lt;/user-id&gt;</pre>
<p>now the returned response (for country-code = 12) looks like:</p>
<pre>(reply){
   session-handle-part = "abcdef098765"
   user-id = 24
   server-time = 12345678
 }</pre>
<p>It works! <img src='http://blog.sztart.pl/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /><br />
<a href="http://www.soapui.org/Service-Mocking/creating-dynamic-mockservices.html">Here</a> is article about more advanced creation of response in groovy and currently available <a href="http://www.soapui.org/apidocs/">API</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.sztart.pl/2011/07/webservices-mockups/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Http build query</title>
		<link>http://blog.sztart.pl/2011/07/http_build_query/</link>
		<comments>http://blog.sztart.pl/2011/07/http_build_query/#comments</comments>
		<pubDate>Sun, 17 Jul 2011 23:01:47 +0000</pubDate>
		<dc:creator>serek</dc:creator>
				<category><![CDATA[Performance]]></category>
		<category><![CDATA[Php]]></category>

		<guid isPermaLink="false">http://blog.sztart.pl/?p=25</guid>
		<description><![CDATA[Today during code review Olle noticed that there is much simpler way to build query part of url then concatenate strings in loop. For example instead of: $aParams = array('id' =&#62; 12, 'method' =&#62; 'post', 'callback_function_name' =&#62; 'add'); $sQuery = '?'; foreach ($aParams as $key =&#62; $value) { $sQuery .= $key .'=' .$value .'&#38;'; } [...]]]></description>
			<content:encoded><![CDATA[<p>Today during code review <a href="https://github.com/olleolleolle/" target="_blank">Olle</a> noticed that there is much simpler way to build query part of url then concatenate strings in loop.</p>
<p>For example instead of:</p>
<pre>$aParams = array('id' =&gt; 12,
	'method' =&gt; 'post',
	'callback_function_name' =&gt; 'add');
$sQuery = '?';
foreach ($aParams as $key =&gt; $value) {
	$sQuery .= $key .'=' .$value .'&amp;';
}
$sQuery = substr($sQuery, 0, -1); //to remove last &amp;
$sUrl = $sHost .$sQuery;</pre>
<p>Solution proposed by Olle was:</p>
<pre>$aParams = array('id' =&gt; 12,
	'method' =&gt; 'post',
	'callback_function_name' =&gt; 'add');
$sQuery = http_build_query($aParams, '', '&amp;');
$sUrl = $sHost . $sQuery;</pre>
<p>I checked that function in <a href="http://dk2.php.net/manual/en/function.http-build-query.php">manual</a> and it looks quite powerful. One thing which considered me was performance, of course native C function are faster then loop, etc, but is not that function too powerful and slow to use it in responsible part of code with huge load?</p>
<p>Lets check:</p>
<pre>$aParams = array('id' =&gt; 12,
	'user_id' =&gt; 234,
	'method' =&gt; 'post',
	'callback_function_name' =&gt; 'add');

$fStarttime = microtime(true);

for ($i = 0; $i &lt; 100000; $i++) {
	$sQuery = http_build_query($aParams, '', '&amp;');
}
echo 'http_build_query: ' . (microtime(true) - $fStarttime) .PHP_EOL;

$fStarttime = microtime(true);

for ($i = 0; $i &lt; 100000; $i++) {
	$sQuery = '';
	foreach ($aParams as $key =&gt; $value) {
		$sQuery .= $key . '=' . $value . '&amp;';
	}
	$sQuery = substr($sQuery, 0, -1); //to remove last &amp;
}
echo 'concatenation: ' . (microtime(true) - $fStarttime);</pre>
<p>and results:</p>
<pre>http_build_query: 0.69601511955261
concatenation:    1.1222679615021</pre>
<p>As you see it is definitely easier, faster way and needs less lines of code.</p>
<p>Tip: there is an extension called <a href="http://dk.php.net/manual/en/book.http.php">http://dk.php.net/manual/en/book.http.php</a> which posses more useful function.</p>
<p>In PHP5.4 second approach will faster due to introduce caches to eliminate repeatable run-time bindings of functions, classes, constants, methods and properties &#8211; more info about this feature <a href="http://php.net/releases/NEWS_5_4_0_alpha1.txt">here</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.sztart.pl/2011/07/http_build_query/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

