<?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>Engwar &#187; perl</title>
	<atom:link href="http://engwar.com/tags/perl/feed" rel="self" type="application/rss+xml" />
	<link>http://engwar.com</link>
	<description>Chintana Wilamuna&#039;s weblog</description>
	<lastBuildDate>Wed, 30 Nov 2011 13:28:16 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
		<item>
		<title>StockTrader client using Catalyst</title>
		<link>http://engwar.com/post/93?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=stocktrader-client-using-catalyst</link>
		<comments>http://engwar.com/post/93#comments</comments>
		<pubDate>Thu, 05 Mar 2009 12:16:35 +0000</pubDate>
		<dc:creator>Chintana</dc:creator>
				<category><![CDATA[catalyst]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[stocktrader]]></category>

		<guid isPermaLink="false">http://engwar.com/?p=93</guid>
		<description><![CDATA[I&#8217;ve been rewriting the Perl StockTrader client using Catalyst for the past week or so. The first version of the client was done using (gasp!) Perl/CGI. So it was about time to do it right. Thanks to the excellent documentation &#8230; <a href="http://engwar.com/post/93">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been rewriting the Perl StockTrader client using <a href="http://www.catalystframework.org/">Catalyst</a> for the past week or so. The first version of the client was done using (gasp!) Perl/<a href="http://search.cpan.org/dist/CGI.pm/CGI.pm">CGI</a>. So it was about time to do it right. Thanks to the excellent documentation Catalyst provide, it was a straightforward task.</p>
<p>The main annoyance I faced was the lack of a proper error reporting mechanism. When you have an error on your controller, the script that starts the server simply refuse to start you can see the following VERY helpful error message in the console.</p>
<p><code>Unknown error<br />
Compilation failed in require at /usr/share/perl5/Catalyst/Utils.pm line 270.<br />
Compilation failed in require at ./script/stocktrader_server.pl line 55.</code></p>
<p>You cannot find out where the error occured. Only conclusion that you can make out of this is that there is an error in one of your controllers. Errors in models are shown correctly as they should. Template errors can easily be fixed. If you haven&#8217;t been doing incremental development, meaning you add a little bit of code then start the server and see whether everything has worked ok up to now, you&#8217;ll be in serious trouble. If you have the habit of writing large amounts of code without testing and keep testing for the last minute, Catalyst will torture you and put you through hellish debugging sessions for hours. I spent an inordinate amount of time trying to figure out the error and finally spotted that I&#8217;ve forgotten to make a single variable lexically scoped with my.</p>
<p>I also configured Log4perl to log all the errors to a log file and enabled the option to log warnings. Sadly I could not see any more log messages than I see in the console.</p>
<p>That aside, Catalyst is a fantastic framework to write web applications if you know Perl. As a big fan of frameworks it&#8217;s so exciting to see high quality open source MVC frameworks being developed that drastically reduce the effort of building web applications. Whatever the language you&#8217;re comfortable in programming, you can easily find a decent MVC framework for it these days. Well .. almost.</p>
]]></content:encoded>
			<wfw:commentRss>http://engwar.com/post/93/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Catalyst</title>
		<link>http://engwar.com/post/85?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=catalyst</link>
		<comments>http://engwar.com/post/85#comments</comments>
		<pubDate>Wed, 25 Feb 2009 21:48:05 +0000</pubDate>
		<dc:creator>Chintana</dc:creator>
				<category><![CDATA[catalyst]]></category>
		<category><![CDATA[mvc]]></category>
		<category><![CDATA[perl]]></category>

		<guid isPermaLink="false">http://engwar.com/?p=85</guid>
		<description><![CDATA[Last time I looked at Catalyst for a project, the time was really tight and had to do it by other means. This time however, I had slightly more time available so I started from Catalyst::Manual::Tutorial and boy, the docs &#8230; <a href="http://engwar.com/post/85">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Last time I looked at <a href="http://www.catalystframework.org/">Catalyst</a> for a project, the time was really tight and had to do it by other means. This time however, I had slightly more time available so I started from <a href="http://search.cpan.org/dist/Catalyst-Manual/lib/Catalyst/Manual/Tutorial.pod">Catalyst::Manual::Tutorial</a> and boy, the docs are amazingly well written. Kennedy Clark has done a wonderful job with the documentation.</p>
<p>Catalyst is a MVC framework written in Perl. If you&#8217;ve written any applications with Ruby on Rails or Django, the first thing you&#8217;ll notice is, like anything written in Perl, speed. Also, another difference that I see with Catalyst is the unprecedented flexibility it gives to the hands of the application developer. For a framework providing this level of flexibility, Catalyst is surprisingly easy to program with. Will write more about my Catalyst chronicles in another post.</p>
]]></content:encoded>
			<wfw:commentRss>http://engwar.com/post/85/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Perl embedding example</title>
		<link>http://engwar.com/post/42?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=perl-embedding-example</link>
		<comments>http://engwar.com/post/42#comments</comments>
		<pubDate>Wed, 09 Jul 2008 05:56:02 +0000</pubDate>
		<dc:creator>Chintana</dc:creator>
				<category><![CDATA[embedding]]></category>
		<category><![CDATA[perl]]></category>

		<guid isPermaLink="false">http://engwar.com/?p=42</guid>
		<description><![CDATA[Since there was no progress from my last experiment, writing a rudimentary program without any WSF/C code seemed like a logical next step. For those of you who don&#8217;t know what I tried to do, here&#8217;s a brief explanation. I &#8230; <a href="http://engwar.com/post/42">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Since there was no progress from my <a href="http://engwar.com/post/40">last experiment</a>, writing a rudimentary program without any WSF/C code seemed like a logical next step.  For those of you who don&#8217;t know what I tried to do, here&#8217;s a brief explanation.  I want to let other people provide Web services in Perl.  My objective is to enable people to just copy their Perl scripts to, say, a folder and it&#8217;ll automatically become a Web service.  Let me explain that with an example.  Say you have the following Perl script,</p>
<pre lang="perl">
#!/usr/bin/env perl

sub getRandomNumber {
    return 4;
}
</pre>
<p>I&#8217;m going to assuming you have configured your web server to execute Perl scripts ending with .pl via ModPerl for a directory called perl.  You copy the file and it&#8217;s accessible from http://localhost/perl/random.pl.  And it&#8217;s a web service now.  So you can send an XML payload like,</p>
<pre lang="xml">
<getRandomNumber />
</pre>
<p>And get back something like,</p>
<pre lang="xml">
<number>4</number>
</pre>
<p>Since I&#8217;m using <a href="http://wso2.org/projects/wsf/c">WSF/C</a> as the underlying Web service engine and it provides various other facilities like WS-Security, WS-ReliableMessaging etc&#8230; at blazing speed, I wanna use it.</p>
<p>Here&#8217;s a simplified graphical version of the story,</p>
<p><img src="http://engwar.com/wp-content/uploads/2008/07/wsf-perl-service-arch.png" alt="" title="WSF/Perl service architecture" width="570" height="406" class="aligncenter size-full wp-image-43" /></p>
<p>1. Request comes to rand.pl via ModPerl and it gets executed.<br />
2. rand.pl then calls some methods in Service.pm module which in turn calls to some C functions.<br />
3. From one of those C functions we need to call a Perl function residing in the script the request came into.</p>
<p>If you&#8217;re wondering how the graphic relates to the story of copying your Perl script and making it a service (&#8216;cos there&#8217;s a Service.pm in the picture), please note that I&#8217;ve not yet figured out every detail in the system <img src='http://engwar.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>Perl is segfaulting at all the bizzare places when this is executed. When things get this bad it&#8217;s time to write a very simple application that does the same thing without any WSF/C code.  Here&#8217;s how I did it.</p>
<p>I started by creating a new Perl extension in C.</p>
<pre>
$ h2xs -A -n ICanHaz
</pre>
<p>This&#8217;ll create the skeleton and all I have to do is edit the .xs file and put my code there.  Here&#8217;s my ICanHaz.xs file,</p>
<pre lang="c">
#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"
#include <string.h>

#include "ppport.h"

static	PerlInterpreter *my_perl;

void cheeseburger( void )
{
    char *embedding[] = {"/usr/local/apache2/perl/exec-this.pl"};

    my_perl = perl_alloc();
    perl_construct(my_perl);
    PL_exit_flags |= PERL_EXIT_DESTRUCT_END;
    perl_parse(my_perl, NULL, 1, embedding, NULL);
    perl_run(my_perl);
    perl_destruct(my_perl);
    perl_free(my_perl);
    PERL_SYS_TERM();
}

MODULE = ICanHaz		PACKAGE = ICanHaz		

void
cheeseburger()
</pre>
<p>Now you have to edit Makefile.PL and give the output of, <code>perl -MExtUtils::Embed -e ccopts -e ldopts</code> to the compiler flags.  After that you can compile and install the module.  Here&#8217;s what&#8217;s inside exec-this.pl,</p>
<pre lang="perl">
sub keele_teh_urth {
    print "oh noez. i iz gud kitteh";
}
</pre>
<p>Just a simple function.  Then I wrote another Perl script to invoke the method in my C extension.  Here&#8217;s the program,</p>
<pre lang="perl">
#!/usr/local/bin/perl

use ICanHaz;

ICanHaz::cheeseburger();

print "Content-type: text/html\n\n";
print "dis segfaults, srsly.\n";
</pre>
<p>Executing this file via ModPerl results in a segmentation fault.  As you can see even the simplest case of embedding will not execute through ModPerl.  Switched to CGI and got the same results.  Possible alternatives to try is 1) move all the embedding stuff to it&#8217;s own executable, when you need to call the Perl function from C do a fork followed by exec, pass the payload as a parameter, store the result in a shared memory and once done read from it (this .. um .. a bit ugly to say the least).  Second alternative is to use <a href="http://search.cpan.org/~adamk/PPI-1.203/lib/PPI.pm">PPI</a>.  I haven&#8217;t looked into PPI yet so don&#8217;t know for sure whether it&#8217;s possible.</p>
]]></content:encoded>
			<wfw:commentRss>http://engwar.com/post/42/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Perl embedding woes</title>
		<link>http://engwar.com/post/40?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=perl-embedding-woes</link>
		<comments>http://engwar.com/post/40#comments</comments>
		<pubDate>Thu, 03 Jul 2008 02:03:55 +0000</pubDate>
		<dc:creator>Chintana</dc:creator>
				<category><![CDATA[mod_perl]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[web services]]></category>
		<category><![CDATA[wsf/c]]></category>
		<category><![CDATA[wsf/perl]]></category>

		<guid isPermaLink="false">http://engwar.com/?p=40</guid>
		<description><![CDATA[While developing server side components that enables providing Web services using Perl bumped into a brick wall. First the requirement is when a client request comes, need to extract the payload and pass it to WSF/C which acts as the &#8230; <a href="http://engwar.com/post/40">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>While developing server side components that enables providing Web services using Perl bumped into a brick wall.  First the requirement is when a client request comes, need to extract the payload and pass it to WSF/C which acts as the underlying Web services engine.  So WSF/C knows how to process the incoming XML payload and do what it does and return another XML payload which is then passed back to the client who send the request.  And the business logic is written using Perl.  Simple, I know.</p>
<p>We used SWIG to generate some wrapper functions (plus some custom written C code) which belongs to WSF/C and wrote a Perl module encapsulating the lower level stuff.  So when you have to write a Web service in Perl all you have to do is <code>use WSO2::WSF::Service;</code> in your script and call a couple of functions.  As the deployment scenario we choose Apache with ModPerl.  That combination seemd logical and some of the heavy trafficked sites are using that.</p>
<p>It gets interesting when you test the whole thing.  Apache is configured to run ModPerl on a folder named <code>/perl</code> so requests matching <code>/perl/something</code> will go through ModPerl.  <code>ResponseHandler</code> is <code>ModPerl::Registry</code> and also <code>GlobalRequest</code> has been enabled to get the global request via <code>Apache::RequestUtil->request()</code>.</p>
<p>Say, we have a service script named <code>echo_service.pl</code> which simply return back whatever it gets.  Here&#8217;s the code,</p>
<pre lang="perl">
#!/usr/bin/perl

use strict;
use WSO2::WSF;
use WSO2::WSF::WSService;
use Apache2::RequestUtil ();

my $payload =<<E;
<ns1:echoString xmlns:ns1="http://perl.axis2.org/samples">
  <text>plurk u can haz</text>
</ns1:echoString>
E

sub echoFunction {
    my $arg = $_[0];
    my $message = new WSO2::WSF::WSMessage ({'payload' => $arg});
    return $message;
}

my %operations = ( 'echoString' => 'echoFunction');

if (defined $ENV{MOD_PERL}) {
  my $r = Apache2::RequestUtil->request();

  my $service = new WSO2::WSF::WSService(
    {'operations' => \%operations, 'action' => 'testAction'}
  );

  $service->reply( $r );
}
</pre>
<p>When it goes to the reply method it&#8217;ll call up some C routines.  Inside one of those C functions, after determining the function name to call by looking at the request payload, we need to call it.  From a C function.  How can you do that?  By embedding the Perl interpreter.  AFAIK, you cannot call a Perl function from C without embedding the interpreter (please correct me if I&#8217;m wrong).  In WSF/Ruby server side there was no such issue because the entire Ruby module (<code>WSService</code> class and methods) is written in C.</p>
<p>Let me show you the code that embeds the interpreter and calls the function after looking at the XML payload in the request,</p>
<pre lang="c">
static axiom_node_t *
wsf_xml_msg_recv_invoke_other(axis2_msg_recv_t* msg_recv,
        const axutil_env_t* env,
        wsf_svc_info_t* svc_info,
        axis2_msg_ctx_t* in_msg_ctx,
        axis2_msg_ctx_t* out_msg_ctx,
        axis2_char_t* function_name,
        axis2_char_t* class_name)
{
    AXIS2_PARAM_CHECK(env->error, svc_info, NULL);
    AXIS2_PARAM_CHECK(env->error, in_msg_ctx, NULL);
    AXIS2_PARAM_CHECK(env->error, out_msg_ctx, NULL);

    axiom_node_t *node = NULL;
    axiom_node_t *om_node = NULL;
    axiom_soap_envelope_t *envelope = NULL;
    axiom_soap_body_t *body = NULL;
    axis2_char_t *retstr = NULL;
    axiom_node_t *soap_body_node = NULL;

    /* extracting payload from the soap message */
    envelope = axis2_msg_ctx_get_soap_envelope(in_msg_ctx, env);
    if (!envelope)
    {
        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "[wsf-perl-service] soap envelope not found");
        return NULL;
    }

    body = axiom_soap_envelope_get_body(envelope, env);
    if (!body)
    {
        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "[wsf-perl-service] soap body not found");
        return NULL;
    }

    soap_body_node = axiom_soap_body_get_base_node(body, env);
    if (!soap_body_node)
    {
        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "[wsf-perl-service] soap body base node not found");
        return NULL;
    }

    om_node = axiom_node_get_first_child(soap_body_node, env);
    if (!om_node)
    {
        return NULL;
    }

    axis2_char_t *embedding[] = {"-M'WSO2::WSF::C; WSO2::WSF::Service;'", ""};
    if (!svc_info->script_filename)
    {
        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI,
                "perl function invocation failed, script_file name not found for "
                "service %s", svc_info->svc_name);
        return NULL;
    }
    /* passing script real path into perl interpreter. */
    embedding[1] = svc_info->script_filename;

    my_perl = perl_alloc();
    PL_perl_destruct_level = 0;
/*    PL_use_safe_putenv = 1; */
    PERL_SET_CONTEXT(my_perl);
    perl_construct(my_perl);

    PL_origalen = 1;
    PERL_SET_CONTEXT(my_perl);
    if (perl_parse(my_perl, xs_init, 2, embedding, NULL))
    {
        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "perl_parse method failed");
        return NULL;
    }
    PL_exit_flags |= PERL_EXIT_DESTRUCT_END;
    /* perl_run(my_perl); */

    if (SvTRUE(ERRSV))
    {
        AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, "invoke perl function failed");
    }

    retstr = invoke_perl_function(env, om_node, function_name, NULL);

    if (retstr)
    {
        node = wsf_util_deserialize_buffer(env, retstr);
    }

    PERL_SET_CONTEXT(my_perl);
    perl_destruct(my_perl);
    PERL_SET_CONTEXT(my_perl);
    perl_free(my_perl);
    PERL_SYS_TERM();
    AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, axiom_node_to_string(node, env));
    return node;
}

static axis2_char_t *
invoke_perl_function(const axutil_env_t *env, axiom_node_t *om_node,
        axis2_char_t *operation, axis2_char_t *class_name)
{
    int count = 0;
    axis2_char_t *inmsg = NULL;
    SV **wsmsg_str = NULL; /* hold the value for the key 'payload' in WSMessage */
    SV *wsmsg_ref = NULL; /* reference to a WSMessage object */
    HV *wsmsg = NULL; /* WSMessage object */
    char *tmp_str = NULL;
    axis2_char_t *res_payload_str = NULL;

    if (!operation)
    {
        AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI,
                "invoking perl function failed, operation not available");
        return NULL;
    }

    if (om_node)
    {
        inmsg = axiom_node_to_string(om_node, env);
    }

    /* declare and init a local copy of the Perl stack pointer */
    dSP;

    /* mortal SVs for the stack */
    ENTER;
    SAVETMPS;

    /* "record" the current stack pointer */
    PUSHMARK(SP);

    /* push parameters to the stack */
    XPUSHs(sv_2mortal(newSVpv(inmsg, 0)));

    /* make the global copy of the stack pointer same as the local copy */
    PUTBACK;

    /* call the Perl function, expecting a scalar to be returned */
    count = call_pv(operation, G_SCALAR);

    /* refreshing the local copy of the stack pointer, call_pv might have reallocated it */
    SPAGAIN;

    if (count != 1)
    {
        croak("perl function invocation failed") ;
        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "perl function %s invocation failed", operation);
    }

    /* get the scalar reference from the stack */
    wsmsg_ref = (SV *) POPs;

    /* getting the object from the reference */
    wsmsg = SvRV(wsmsg_ref);

    /* fetching the value of the member variable 'payload' from WSMessage */
    wsmsg_str = hv_fetch(wsmsg, "payload", 7, FALSE);

    /* perl scalar to c string */
    tmp_str = SvPVutf8_nolen(*wsmsg_str);
    res_payload_str = (axis2_char_t *) savepvn(tmp_str, strlen(tmp_str));

    PUTBACK;

    /* cleaning up mortal SVs */
    FREETMPS;
    LEAVE;

    return res_payload_str;
}
</pre>
<p><a href="http://wso2.org/repos/wso2/trunk/wsf/perl/service/wsf_xml_msg_recv.c">Full source is here</a> (note that the actual source might be different from what you see here since it&#8217;s being modified at the time of this writing).  Also <code>my_perl</code> is declared as a static variable.   The problem is when my_perl gets freed it looks like ModPerl is also affected.  A valgrind report shows that it tries to read from a pointer after <code>perl_free()</code> gets called.  As the following valgrind exerpt shows,</p>
<pre>
==16101== Invalid read of size 4
==16101==    at 0x62AD118: _wrap_wsf_worker_process_request (wsf_wrap.c:4167)
==16101==    by 0x5476D68: Perl_pp_entersub (pp_hot.c:2847)
==16101==    by 0x5438092: Perl_runops_debug (dump.c:1931)
==16101==    by 0x546FF97: Perl_call_sv (perl.c:2646)
==16101==    by 0x4DC2AF3: modperl_callback (modperl_callback.c:101)
==16101==    by 0x4DC388B: modperl_callback_run_handlers (modperl_callback.c:262)
==16101==    by 0x4DC4289: modperl_callback_per_dir (modperl_callback.c:369)
==16101==    by 0x4DBB53E: modperl_response_handler_run (mod_perl.c:1004)
==16101==    by 0x4DBB704: modperl_response_handler_cgi (mod_perl.c:1099)
==16101==    by 0x25A6C: ap_run_handler (config.c:158)
==16101==    by 0x295BE: ap_invoke_handler (config.c:372)
==16101==    by 0x35D80: ap_process_request (http_request.c:258)
==16101==  Address 0x649051c is 12 bytes inside a block of size 1,692 free'd
==16101==    at 0x480590A: free (vg_replace_malloc.c:323)
==16101==    by 0x546AED4: perl_free (perl.c:1394)
==16101==    by 0x62BD599: wsf_xml_msg_recv_invoke_business_logic_sync (wsf_xml_msg_recv.c:452)
==16101==    by 0x613D503: axis2_msg_recv_invoke_business_logic (msg_recv.c:392)
==16101==    by 0x613DB34: axis2_msg_recv_receive_impl (msg_recv.c:319)
==16101==    by 0x613D583: axis2_msg_recv_receive (msg_recv.c:431)
==16101==    by 0x61327D4: axis2_engine_receive (engine.c:315)
==16101==    by 0x6167177: axis2_http_transport_utils_process_http_post_request (http_transport_utils.c:595)
==16101==    by 0x62BE9B3: wsf_worker_process_request (wsf_worker.c:301)
==16101==    by 0x62AD0F7: _wrap_wsf_worker_process_request (wsf_wrap.c:4166)
==16101==    by 0x5476D68: Perl_pp_entersub (pp_hot.c:2847)
==16101==    by 0x5438092: Perl_runops_debug (dump.c:1931)
</pre>
<p>Still haven&#8217;t been able to pin down what exactly happens when <code>perl_free()</code> gets called <img src='http://engwar.com/wp-includes/images/smilies/icon_sad.gif' alt=':-(' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://engwar.com/post/40/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>WSF/Perl 1.1</title>
		<link>http://engwar.com/post/39?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=wsfperl-11</link>
		<comments>http://engwar.com/post/39#comments</comments>
		<pubDate>Wed, 28 May 2008 15:45:13 +0000</pubDate>
		<dc:creator>Chintana</dc:creator>
				<category><![CDATA[perl]]></category>
		<category><![CDATA[webservices]]></category>
		<category><![CDATA[wsf/perl]]></category>

		<guid isPermaLink="false">http://engwar.com/?p=39</guid>
		<description><![CDATA[Just uploaded WSF/Perl 1.1 to CPAN. Doesn&#8217;t show up there yet but will be available within a few hours. This has many things added since the last release (which was ages ago). You could now do WS-ReliableMessaging, WS-Security, WS-SecurityPolicy. The &#8230; <a href="http://engwar.com/post/39">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Just uploaded WSF/Perl 1.1 to CPAN.  Doesn&#8217;t show up there yet but will be available within a few hours.  This has many things added since the last release (which was ages ago).  You could now do WS-ReliableMessaging, WS-Security, WS-SecurityPolicy.  The release became ridiculously late due to couple of bugs which took me REALLY LONG to debug and fix.  Ouch.  Download and give it a shot.  It&#8217;ll take couple of seconds to compile.  If you&#8217;re in a generous mood I recommend <a href="http://www.everytopicintheuniverseexceptchickens.com/">contributing to a good cause</a> in those few seconds.</p>
<p>This release again has only support only on the client side, if you&#8217;re looking forward to write/host services with WSF/Perl you still have to wait a bit more.  <a href="http://nethu.org/">Dinesh</a> and Danushka has done some excellent progress on that front and will be finishing it soon.  If you wanna know how it&#8217;s taking shape, then <a href="http://wso2.org/repos/wso2/trunk/wsf/perl/service/">by all means</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://engwar.com/post/39/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SWIG binary string caveat</title>
		<link>http://engwar.com/post/31?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=swig-binary-string-caveat</link>
		<comments>http://engwar.com/post/31#comments</comments>
		<pubDate>Wed, 23 Apr 2008 23:18:37 +0000</pubDate>
		<dc:creator>Chintana</dc:creator>
				<category><![CDATA[mtom]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[swig]]></category>
		<category><![CDATA[wsf/perl]]></category>

		<guid isPermaLink="false">http://engwar.com/post/31</guid>
		<description><![CDATA[If you have been working with Web services you might have heard the term MTOM. I was getting MTOM support to work on WSF/Perl and the image that was not getting saved properly. Only the first few bytes was written &#8230; <a href="http://engwar.com/post/31">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>If you have been working with Web services you might have heard the term <a href="http://en.wikipedia.org/wiki/MTOM">MTOM</a>.  I was getting MTOM support to work on <a href="http://wso2.org/projects/wsf/perl">WSF/Perl</a> and the image that was not getting saved properly.  Only the first few bytes was written to the file.  The magic numbers that were getting saved was enough for the file command to say it&#8217;s a JPEG image.  From the C layer it was reading image data to a character pointer and returning it to the scripting language.</p>
<p>The C function reading the image had a <code>char *</code> return type.  The code that was generated by SWIG was returning the pointer after running it through the following function,</p>
<pre lang="c">
SWIG_FromCharPtr(const char *cptr)
{
  return SWIG_FromCharPtrAndSize(cptr, (cptr ? strlen(cptr) : 0));
}
</pre>
<p>The rough English translation of the above is, &#8220;you&#8217;re screwed&#8221;.  Why?  The <code>strlen</code> doesn&#8217;t particularly like to go through binary strings.  It&#8217;ll choke and die when it see a null byte.  So, only the content before the null byte was returned.</p>
<p>The solution was to create a string using the API provided by the particular scripting language.  For Perl it&#8217;s <code>newSVpv</code> and for Ruby it&#8217;s <code>rb_str_new</code>.  Wrapped the functions inside an ifdef (thanks to the nice SWIG&lt;lang&gt; defines) and all is set for MTOM!</p>
]]></content:encoded>
			<wfw:commentRss>http://engwar.com/post/31/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Custom SOAP headers using WSF/Perl</title>
		<link>http://engwar.com/post/30?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=custom-soap-headers-using-wsfperl</link>
		<comments>http://engwar.com/post/30#comments</comments>
		<pubDate>Fri, 04 Apr 2008 00:35:00 +0000</pubDate>
		<dc:creator>Chintana</dc:creator>
				<category><![CDATA[perl]]></category>
		<category><![CDATA[soap]]></category>
		<category><![CDATA[webservices]]></category>
		<category><![CDATA[wsf/perl]]></category>

		<guid isPermaLink="false">http://engwar.com/post/30</guid>
		<description><![CDATA[SOAP headers are used to convey additional control information that complements the information in the payload. For example WS-Security is one such thing that use SOAP headers to say how integrity and confidentiality should be achieved. Apart from the specs &#8230; <a href="http://engwar.com/post/30">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>SOAP headers are used to convey additional control information that complements the information in the payload.  For example WS-Security is one such thing that use SOAP headers to say how integrity and confidentiality should be achieved.  Apart from the specs that define standard SOAP headers you could also define your own custom headers which could then be processed as you wish from your application.  Let&#8217;s see how we can generate custom SOAP headers using WSF/Perl.  You&#8217;ll need to get the SVN head revision of <a href="http://wso2.org/projects/wsf/perl">WSF/Perl</a> in order to get this working (as of this writing).</p>
<p>First, let&#8217;s see an example from &#8220;Processing XML with Java&#8221; (<a href="http://www.amazon.com/Processing-XML-Java-TM-Guide/dp/0201771861/">Amazon page</a>) also <a href="http://www.cafeconleche.org/books/xmljava">available online here</a>.  I&#8217;m using <a href="http://www.cafeconleche.org/books/xmljava/chapters/ch02s06.html#bid_with_credit_card.xml">the SOAP header example</a> to show you how to generate the exact thing.</p>
<pre lang="xml">
<Payment xmlns="http://namespaces.cafeconleche.org/xmljava/ch2/">
    <Name>Elliotte Harold</Name>
    <Issuer>VISA</Issuer>
    <Number>5125456787651230</Number>
    <Expires>2005-12</Expires>
</Payment>
</pre>
<p>Here&#8217;s how you can generate the above headers using WSF/Perl,</p>
<pre lang="php">
my $name = new WSO2::WSF::WSHeader(
    {'name' => 'Name', 'data' => 'Elliotte Harold' } );

my $issuer = new WSO2::WSF::WSHeader(
    {'name' => 'Issuer', 'data' => 'VISA' } );

my $number = new WSO2::WSF::WSHeader(
    {'name' => 'Number', 'data' => '5125456787651230' } );

my $expires = new WSO2::WSF::WSHeader(
    {'name' => 'Expires', 'data' => '2005-12' } );

my $payment = new WSO2::WSF::WSHeader(
    {'name' => 'Payment',
      'ns' => 'http://namespaces.cafeconleche.org/xmljava/ch2/',
      'data' => [$name, $issuer, $number, $expires] } );

my $client = new WSO2::WSF::WSClient(
    {...,
     'inputHeaders' => [$payment] } );
</pre>
<p>In the <a href="http://www.cafeconleche.org/books/xmljava/chapters/ch02s06.html#signed_bid_with_payment.xml">next example</a> it shows the header with the <code>mustUnderstand</code> attribute set, this is how you set it,</p>
<pre lang="php">
my $client = new WSO2::WSF::WSClient(
    {...,
     'mustUnderstand' => 'true',
     'inputHeaders' => [$payment] } );
</pre>
<p>Next, I&#8217;ll take an example from a <a href="http://www.ibm.com/developerworks/webservices/library/ws-soapheaders/index.html?ca=drs">developerWorks article that shows you how to manipulate SOAP headers in WebSphere</a>.  Consider the following header contents (Listing 4 in the article)</p>
<pre lang="xml">
<MyPrefix:CallingApplication xmlns:MyPrefix="http://SOAPHeaderDemonstration">
    <name>ServiceRequester1</name>
    <version>1.0</version>
    <timeRequestMade>13:20:00</timeRequestMade>
</MyPrefix:CallingApplication>
</pre>
<p>The main difference in this is that it contains a custom prefix for the element <code>CallingApplication</code>.  Here&#8217;s the WSF/Perl code to generate this header,</p>
<pre lang="php">
my $name = new WSO2::WSF::WSHeader(
    {'name' => 'name', 'data' => 'ServiceRequester1' } );

my $version = new WSO2::WSF::WSHeader(
    {'name' => 'version', 'data' => '1.0' } );

my $timereq = new WSO2::WSF::WSHeader(
    {'name' => 'timeRequestMade', 'data' => '13:20:00' } );

my $capp = new WSO2::WSF::WSHeader(
    {'name' => 'CallingApplication', 'ns' => 'http://SOAPHeaderDemonstration',
     'nsprefix' => 'MyPrefix',
     'data' => [$name, $version, $timereq] } );

my $client = new WSO2::WSF::WSClient(
    {...,
     'inputHeaders' => [$capp] } );
</pre>
<p>As you saw in the examples, <code>WSHeader</code> class facilitate creating custom SOAP headers with WSF/Perl.</p>
]]></content:encoded>
			<wfw:commentRss>http://engwar.com/post/30/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Scripting language bindings</title>
		<link>http://engwar.com/post/20?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=scripting-language-bindings</link>
		<comments>http://engwar.com/post/20#comments</comments>
		<pubDate>Thu, 03 Jan 2008 08:53:08 +0000</pubDate>
		<dc:creator>Chintana</dc:creator>
				<category><![CDATA[perl]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[swig]]></category>
		<category><![CDATA[webservices]]></category>

		<guid isPermaLink="false">http://engwar.com/post/20</guid>
		<description><![CDATA[Besides having the ability to provide a high level and a more developer friendly API, making a scripting language binding to an existing C library could make the testing of the library a less painful process. Initially I was under &#8230; <a href="http://engwar.com/post/20">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Besides having the ability to provide a high level and a more developer friendly API, making a scripting language binding to an existing C library could make the testing of the library a less painful process.  Initially I was under the impression that exposing low level C functions to the scripting language will make it flexible so that you could build a high level module in that scripting language encapsulating those low level functions.  True.  But the big downside when you have, say, 3 different language bindings for your C library all exposing low level functions is, a) you need to spend a lot of time writing the module in the respective scripting language b) too much overhead when it comes to debugging.  If you find a subtle bug which you have overlooked in the Ruby binding, now you need to change the same thing on your Python and Perl bindings as well.</p>
<p>This was a real issue that we came across developing the Ruby and Perl bindings for the <a href="http://wso2.org/projects/wsf/c">WSF/C</a> framework.  Also having the Python binding in sight.  We use <a href="http://www.swig.org/">SWIG</a> to generate language bindings.  Having learned the price you have to pay exposing the lowest level functions, I&#8217;m gonna look into refactoring the existing code limiting the stuff that&#8217;s exposed to the scripting language to a minimum.  So, code that goes into the module which need to be written in the respective scripting language is very small.</p>
<p>At the end of the day it&#8217;s about making you feel sooo comfortable when you program in your favourite scripting language, exposing your services with the doublew ess death star goodness with a few lines which will call the C library for maximum performance which will then give the result back to your favourite scripting language scripting language.  It&#8217;s a deadly game out there <img src='http://engwar.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' />   Yes, you can breathe now.</p>
]]></content:encoded>
			<wfw:commentRss>http://engwar.com/post/20/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>WSF/Perl is out there</title>
		<link>http://engwar.com/post/11?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=wsfperl-is-out-there</link>
		<comments>http://engwar.com/post/11#comments</comments>
		<pubDate>Mon, 22 Oct 2007 02:24:40 +0000</pubDate>
		<dc:creator>Chintana</dc:creator>
				<category><![CDATA[perl]]></category>
		<category><![CDATA[webservices]]></category>

		<guid isPermaLink="false">http://engwar.com/post/11</guid>
		<description><![CDATA[Initial version of WSF/Perl was released a few weeks ago and I&#8217;ve been too lazy to write a blog post about it. You can install it via CPAN. Documentation is available in the familiar POD format. You can find more &#8230; <a href="http://engwar.com/post/11">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Initial version of WSF/Perl was released a few weeks ago and I&#8217;ve been too lazy to write a blog post about it.  You can install it via CPAN.  Documentation is available in the familiar <a href="http://search.cpan.org/~chintana/WSO2-WSF-Perl-v1.0.0/WSO2-WSF/lib/WSO2/WSF.pm">POD format</a>.  You can find more info from <a href="http://wso2.org/projects/wsf/perl">WSF/Perl project page</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://engwar.com/post/11/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Webservices with Perl</title>
		<link>http://engwar.com/post/10?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=webservices-with-perl</link>
		<comments>http://engwar.com/post/10#comments</comments>
		<pubDate>Tue, 18 Sep 2007 02:49:22 +0000</pubDate>
		<dc:creator>Chintana</dc:creator>
				<category><![CDATA[perl]]></category>
		<category><![CDATA[webservices]]></category>

		<guid isPermaLink="false">http://engwar.com/post/10</guid>
		<description><![CDATA[If you have been doing Web services with SOAP::Lite you&#8217;ll be thrilled to hear that there is another library that&#8217;ll provide WS-* goodness to consume and provide services. Well at least on the way of providing Still there is no &#8230; <a href="http://engwar.com/post/10">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>If you have been doing Web services with SOAP::Lite you&#8217;ll be thrilled to hear that there is another library that&#8217;ll provide WS-* goodness to consume and provide services.  Well at least on the way of providing <img src='http://engwar.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' />   Still there is no support for all the WS- specs implemented by WSF/C but it&#8217;s on the pipeline.  I&#8217;ve been doing development of the Perl binding to the <a href="http://wso2.com/">WSO2</a> <a href="http://wso2.org/projects/wsf/c">WSF/C</a> library.  It&#8217;s not officially released yet but if you&#8217;re feeling a bit adventurous you can try playing with the <a href="http://wso2.org/repos/wso2/trunk/wsf/perl/">svn</a>.  Still the installation is a bit dodgy.  Haven&#8217;t made it a CPAN module yet but it&#8217;ll be when it&#8217;s released.  Still there are loads of improvements to be done.  I have to get rid of those quick and dirty wrapper functions and use typemaps.  Also need to get a proper exception mechanism in place.</p>
]]></content:encoded>
			<wfw:commentRss>http://engwar.com/post/10/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

