<?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>Dimuthu's Blog &#187; wsdl2c</title>
	<atom:link href="http://www.dimuthu.org/catagory/axis2c/wsdl2c/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.dimuthu.org</link>
	<description>Waiting for your comments</description>
	<lastBuildDate>Wed, 07 Jul 2010 12:42:52 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
<image>
  <link>http://www.dimuthu.org</link>
  <url>http://www.dimuthu.org/favicon.ico</url>
  <title>Dimuthu's Blog</title>
</image>
		<item>
		<title>Code Generate Custom SOAP Faults For Axis2/C</title>
		<link>http://www.dimuthu.org/blog/2009/02/09/code-generate-custom-soap-faults-for-axis2c/</link>
		<comments>http://www.dimuthu.org/blog/2009/02/09/code-generate-custom-soap-faults-for-axis2c/#comments</comments>
		<pubDate>Mon, 09 Feb 2009 06:04:41 +0000</pubDate>
		<dc:creator>dimuthu</dc:creator>
				<category><![CDATA[2 minutes guide]]></category>
		<category><![CDATA[SOA]]></category>
		<category><![CDATA[Tutorial/Guide]]></category>
		<category><![CDATA[WSDL]]></category>
		<category><![CDATA[adb]]></category>
		<category><![CDATA[axis2/c]]></category>
		<category><![CDATA[codegen]]></category>
		<category><![CDATA[tool]]></category>
		<category><![CDATA[web services]]></category>
		<category><![CDATA[wsdl2c]]></category>
		<category><![CDATA[xml schema]]></category>
		<category><![CDATA[custom]]></category>
		<category><![CDATA[example]]></category>
		<category><![CDATA[faults]]></category>
		<category><![CDATA[handling]]></category>
		<category><![CDATA[SOAP]]></category>
		<category><![CDATA[throwing]]></category>

		<guid isPermaLink="false">http://www.dimuthu.org/?p=916</guid>
		<description><![CDATA[Web services use SOAP faults to report fault cases back to clients. The faults can be generated from the SOAP framework in a case of invalid SOAP messages, invalid security tokens or they can be generated from the service business logic itself. The fault messages may contain simply a string indicating the error, or it [...]]]></description>
			<content:encoded><![CDATA[<p>Web services use SOAP faults to report fault cases back to clients. The faults can be generated from the SOAP framework in a case of invalid SOAP messages, invalid security tokens or they can be generated from the service business logic itself. The fault messages may contain simply a string indicating the error, or it may contain lot of details which could be useful to the clients find the problem. In fact the format of the SOAP fault is a standard. But services can send custom details within the details element in a SOAP fault.</p>
<pre class="xml"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;soapenv:Envelope</span> <span style="color: #000066;">xmlns:soapenv</span>=<span style="color: #ff0000;">"http://schemas.xmlsoap.org/soap/envelope/"</span><span style="font-weight: bold; color: black;">&gt;</span></span>
   <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;soapenv:Body<span style="font-weight: bold; color: black;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;soapenv:Fault<span style="font-weight: bold; color: black;">&gt;</span></span></span>
         <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;faultcode<span style="font-weight: bold; color: black;">&gt;</span></span></span>soapenv:Sender<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/faultcode<span style="font-weight: bold; color: black;">&gt;</span></span></span>
         <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;faultstring<span style="font-weight: bold; color: black;">&gt;</span></span></span>..<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/faultstring<span style="font-weight: bold; color: black;">&gt;</span></span></span>
         <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;detail<span style="font-weight: bold; color: black;">&gt;</span></span></span> You Custom Message <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/detail<span style="font-weight: bold; color: black;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/soapenv:Fault<span style="font-weight: bold; color: black;">&gt;</span></span></span>
   <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/soapenv:Body<span style="font-weight: bold; color: black;">&gt;</span></span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/soapenv:Envelope<span style="font-weight: bold; color: black;">&gt;</span></span></span></pre>
<p>And you can define the schema of your custom fault message in a WSDL, so the clients can prepare to handle fault scenarios. In facts tools like <a href="http://ws.apache.org/axis2/">Apache Axis2</a> WSDL2C, WSDL2Java tool will help you to work with custom faults when they are defined in the WSDL.  Here is an example section of a WSDL with an operation which can throw two faults &#8220;MyFirstException&#8221;, &#8220;MySecondException&#8221;.</p>
<pre class="xml"><span style="color: #009900;"><span style="color: #808080; font-style: italic;">&lt;!-- fault schemas --&gt;</span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;types<span style="font-weight: bold; color: black;">&gt;</span></span></span>
 <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;schema</span> ..<span style="font-weight: bold; color: black;">&gt;</span></span>
  <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;element</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"MyFirstException"</span><span style="font-weight: bold; color: black;">&gt;</span></span>
   <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;complexType<span style="font-weight: bold; color: black;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;sequence<span style="font-weight: bold; color: black;">&gt;</span></span></span>
     <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;element</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"text"</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">"xsd:string"</span><span style="font-weight: bold; color: black;">/&gt;</span></span>
    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/sequence<span style="font-weight: bold; color: black;">&gt;</span></span></span>
   <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/complexType<span style="font-weight: bold; color: black;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/element<span style="font-weight: bold; color: black;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #808080; font-style: italic;">&lt;!-- fault element --&gt;</span></span>
  <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;element</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"MySecondException"</span><span style="font-weight: bold; color: black;">&gt;</span></span>
   <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;complexType<span style="font-weight: bold; color: black;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;sequence<span style="font-weight: bold; color: black;">&gt;</span></span></span>
     <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;element</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"number"</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">"xsd:int"</span><span style="color: #ff0000;"></span><span style="font-weight: bold; color: black;">/&gt;</span></span>
    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/sequence<span style="font-weight: bold; color: black;">&gt;</span></span></span>
   <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/complexType<span style="font-weight: bold; color: black;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/element<span style="font-weight: bold; color: black;">&gt;</span></span></span>
 <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/schema<span style="font-weight: bold; color: black;">&gt;</span></span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/types<span style="font-weight: bold; color: black;">&gt;</span></span></span>

<span style="color: #009900;"><span style="color: #808080; font-style: italic;">&lt;!-- the fault messages --&gt;</span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;message</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"MySecondExceptionFault"</span><span style="font-weight: bold; color: black;">&gt;</span></span>
 <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;part</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"fault"</span> <span style="color: #000066;">element</span>=<span style="color: #ff0000;">"ns1:MySecondException"</span><span style="font-weight: bold; color: black;">/&gt;</span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/message<span style="font-weight: bold; color: black;">&gt;</span></span></span>

<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;message</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"MyFirstExceptionFault"</span><span style="font-weight: bold; color: black;">&gt;</span></span>
 <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;part</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"fault"</span> <span style="color: #000066;">element</span>=<span style="color: #ff0000;">"ns1:MyFirstException"</span><span style="font-weight: bold; color: black;">/&gt;</span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/message<span style="font-weight: bold; color: black;">&gt;</span></span></span>

<span style="color: #009900;"><span style="color: #808080; font-style: italic;">&lt;!-- operation to throw fault --&gt;</span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;portType</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"MyType"</span><span style="font-weight: bold; color: black;">&gt;</span></span>
 <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;operation</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"myOperation"</span><span style="font-weight: bold; color: black;">&gt;</span></span>
  <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;input</span> <span style="color: #000066;">message</span>=<span style="color: #ff0000;">"tns:myOperationRequest"</span><span style="font-weight: bold; color: black;">/&gt;</span></span>
  <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;output</span> <span style="color: #000066;">message</span>=<span style="color: #ff0000;">"tns:myOperationResponse"</span><span style="font-weight: bold; color: black;">/&gt;</span></span>
  <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;fault</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"MySecondException"</span> <span style="color: #000066;">message</span>=<span style="color: #ff0000;">"tns:MySecondExceptionFault"</span><span style="font-weight: bold; color: black;">/&gt;</span></span>
  <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;fault</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"MyFirstException"</span> <span style="color: #000066;">message</span>=<span style="color: #ff0000;">"tns:MyFirstExceptionFault"</span><span style="font-weight: bold; color: black;">/&gt;</span></span>
 <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/operation<span style="font-weight: bold; color: black;">&gt;</span></span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/portType<span style="font-weight: bold; color: black;">&gt;</span></span></span></pre>
<p>Note that the operation &#8220;myOperation&#8221; is throwing faults &#8220;MyFirstException&#8221;, &#8220;MySecondExcpetion&#8221;. If you generate the Java code for this operation, it would be simple as this,</p>
<pre class="java"><span style="color: #000000; font-weight: bold;">public</span> MyOperationRequest
MyOperation<span style="color: #66cc66;">(</span>MyOperationRequest<span style="color: #66cc66;">)</span> <span style="color: #000000; font-weight: bold;">throws</span>
          MyFirstExcpetion,
          MySecondExcpetion <span style="color: #66cc66;">{</span>
  <span style="color: #808080; font-style: italic;">// here is your business logic</span>
<span style="color: #66cc66;">}</span></pre>
<p>Anyway we are going to write codes in &#8216;C&#8217; language, which doesn&#8217;t have similar exception mechanism. Let see how we can do it, starting with writing the service and then writing a client.</p>
<p><strong>Writing Services With Custom SOAP Faults</strong></p>
<p>Once you generate the &#8216;C&#8217; codes for the WSDL using WSDL2C tool, you should first have a look at the skeleton header file.</p>
<pre class="c">    <span style="color: #808080; font-style: italic;">/**
     * the generated fault union for operation "myOperation|urn:myuri:1.0",
     * in a case you want to return a fault, put the appropriate adb object for
     * the union variable pointer comes as the last parameter of the method
     */</span>
    <span style="color: #993333;">typedef</span> <span style="color: #993333;">union</span>
    <span style="color: #66cc66;">{</span>
        adb_MyFirstException_t* MyFirstException;
        adb_MySecondException_t* MySecondException;

    <span style="color: #66cc66;">}</span> axis2_skel_MyService_myOperation_fault;

    <span style="color: #808080; font-style: italic;">/**
     * auto generated function declaration
     * for "myOperation|urn:myuri:1.0" operation.
     * @param env environment ( mandatory)
     * @param _myOperation of the adb_myOperation_t*
     *
     * @return adb_myOperationResponse_t*
     */</span>
    adb_myOperationResponse_t* axis2_skel_MyService_myOperation<span style="color: #66cc66;">(</span><span style="color: #993333;">const</span> axutil_env_t *env,
                                      adb_myOperation_t* _myOperation,
                                      axis2_skel_MyService_myOperation_fault *fault<span style="color: #66cc66;">)</span>;</pre>
<p>And at the very end of the header file, you will see an enumeration of constants corresponding to each fault is generated.</p>
<pre class="c">    <span style="color: #993333;">typedef</span> <span style="color: #000000; font-weight: bold;">enum</span>
    <span style="color: #66cc66;">{</span>
        AXIS2_SKEL_MYSERVICE_ERROR_NONE = AXIS2_SKEL_MYSERVICE_ERROR_CODES_START,

        AXIS2_SKEL_MYSERVICE_MYOPERATION_FAULT_MYFIRSTEXCEPTION,
        AXIS2_SKEL_MYSERVICE_MYOPERATION_FAULT_MYSECONDEXCEPTION,

        AXIS2_SKEL_MYSERVICE_ERROR_LAST

    <span style="color: #66cc66;">}</span> axis2_skel_MyService_error_codes;</pre>
<p>That&#8217;s all you need to aware of. The plan is whenever you need to report the fault, you have to do three things inside the business logic.</p>
<ol>
<li>Create the adb object for the fault, in this case either &#8220;adb_MyFirstException_t&#8221; or &#8220;adb_MySecondException_t&#8221; and set it to the fault pointer variable.</li>
<li>Set the constant corresponding to the fault using &#8220;AXIS2_ERROR_SET&#8221; function</li>
<li>return NULL</li>
</ol>
<p>Here is an example how you do it inside the actual business logic code.</p>
<pre class="c">    adb_myOperationResponse_t* axis2_skel_MyService_myOperation<span style="color: #66cc66;">(</span><span style="color: #993333;">const</span> axutil_env_t *env,
                                      adb_myOperation_t* myOperation,
                                      axis2_skel_MyService_myOperation_fault *fault <span style="color: #66cc66;">)</span>
    <span style="color: #66cc66;">{</span>
        <span style="color: #808080; font-style: italic;">/* the buisness logic */</span>

        ....

        <span style="color: #b1b100;">if</span><span style="color: #66cc66;">(</span><span style="color: #808080; font-style: italic;">/* checking some condition to throw the "MyFirstException" fault */</span><span style="color: #66cc66;">)</span>
        <span style="color: #66cc66;">{</span>
          <span style="color: #808080; font-style: italic;">/* 1. Creating the adb object and set it to the fault pointer variable */</span>
          adb_MyFirstException_t *exp = <span style="color: #000000; font-weight: bold;">NULL</span>;
          exp = adb_MyFirstException_create<span style="color: #66cc66;">(</span>env<span style="color: #66cc66;">)</span>;
          adb_MyFirstException_set_text<span style="color: #66cc66;">(</span>exp, env, <span style="color: #ff0000;">"this is the exception 1"</span><span style="color: #66cc66;">)</span>; <span style="color: #808080; font-style: italic;">/* custom value */</span>

          fault-&gt;MyFirstException = exp;

          <span style="color: #808080; font-style: italic;">/* 2. Setting the error constant corrosponding to the fault */</span>
          AXIS2_ERROR_SET<span style="color: #66cc66;">(</span>env-&gt;error,
                      AXIS2_SKEL_MYSERVICE_MYOPERATION_FAULT_MYFIRSTEXCEPTION,
                      AXIS2_FAILURE<span style="color: #66cc66;">)</span>;

          <span style="color: #808080; font-style: italic;">/* 3. Returning NULL */</span>
          <span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">NULL</span>;
        <span style="color: #66cc66;">}</span>

        <span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span><span style="color: #66cc66;">(</span><span style="color: #808080; font-style: italic;">/* checking some condition to throw the "MySecondException" fault */</span><span style="color: #66cc66;">)</span>
        <span style="color: #66cc66;">{</span>
          <span style="color: #808080; font-style: italic;">/* 1. Creating the adb object and set it to the fault pointer variable */</span>
          adb_MySecondException_t *exp = <span style="color: #000000; font-weight: bold;">NULL</span>;
          exp = adb_MySecondException_create<span style="color: #66cc66;">(</span>env<span style="color: #66cc66;">)</span>;
          adb_MySecondException_set_number<span style="color: #66cc66;">(</span>exp, env, <span style="color: #cc66cc;">2</span><span style="color: #66cc66;">)</span>;<span style="color: #808080; font-style: italic;">/* custom value */</span>

          fault-&gt;MySecondException = exp;

          <span style="color: #808080; font-style: italic;">/* 2. Setting the error constant corrosponding to the fault */</span>
          AXIS2_ERROR_SET<span style="color: #66cc66;">(</span>env-&gt;error,
                      AXIS2_SKEL_MYSERVICE_MYOPERATION_FAULT_MYSECONDEXCEPTION,
                      AXIS2_FAILURE<span style="color: #66cc66;">)</span>;
          <span style="color: #808080; font-style: italic;">/* 3. Returning NULL */</span>
          <span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">NULL</span>;
        <span style="color: #66cc66;">}</span>

        <span style="color: #808080; font-style: italic;">/* return the response in no fault scenario */</span>
        <span style="color: #b1b100;">return</span> response;
    <span style="color: #66cc66;">}</span></pre>
<p>That&#8217;s all you have to do, Axis2/C will make sure to build the fault and put your custom message inside the details element.</p>
<p><strong>Writing Clients  to Handle custom SOAP Faults</strong></p>
<p>After generating the code for clients using WSDL2C tool, this time you should look at the generated stub header file first. It is just similar to the skeleton header files may be except all the &#8220;skel&#8221; prefixes are renamed to &#8220;stub&#8221; and additional parameter &#8220;stub&#8221; for the operation.</p>
<pre class="c">    <span style="color: #808080; font-style: italic;">/**
     * the generated fault union for operation "myOperation|urn:myuri:1.0",
     * in a case the server return a fault, the corresponding adb object will be loaded for
     * the union variable pointer comes as the last parameter of the method
     */</span>
    <span style="color: #993333;">typedef</span> <span style="color: #993333;">union</span>
    <span style="color: #66cc66;">{</span>
        adb_MyFirstException_t* MyFirstException;
        adb_MySecondException_t* MySecondException;

    <span style="color: #66cc66;">}</span> axis2_stub_MyService_myOperation_fault;

    <span style="color: #808080; font-style: italic;">/**
     * auto generated function declaration
     * for "myOperation|urn:myuri:1.0" operation.
     * @param env environment ( mandatory)
     * @param _myOperation of the adb_myOperation_t*
     *
     * @return adb_myOperationResponse_t*
     */</span>
    adb_myOperationResponse_t* axis2_stub_MyService_myOperation<span style="color: #66cc66;">(</span>axis2_stub_t* stub, <span style="color: #993333;">const</span> axutil_env_t *env,
                                      adb_myOperation_t* _myOperation,
                                      axis2_stub_MyService_myOperation_fault *fault<span style="color: #66cc66;">)</span>;

    <span style="color: #993333;">typedef</span> <span style="color: #000000; font-weight: bold;">enum</span>
    <span style="color: #66cc66;">{</span>
        AXIS2_STUB_MYSERVICE_ERROR_NONE = AXIS2_STUB_MYSERVICE_ERROR_CODES_START,

        AXIS2_STUB_MYSERVICE_MYOPERATION_FAULT_MYFIRSTEXCEPTION,
        AXIS2_STUB_MYSERVICE_MYOPERATION_FAULT_MYSECONDEXCEPTION,

        AXIS2_STUB_MYSERVICE_ERROR_LAST

    <span style="color: #66cc66;">}</span> axis2_stub_MyService_error_codes;</pre>
<p>Looking at this, you may have got the idea how to differentiate what fault is being thrown by the server and how to extract the parameters of the custom fault. Here is an example client code correctly handling exceptions.</p>
<pre class="c">    <span style="color: #808080; font-style: italic;">/* the structure to keep the fault */</span>
    axis2_stub_MyService_myOperation_fault fault;

    ..... <span style="color: #808080; font-style: italic;">/* the part preparing the request is ignored here */</span>

    <span style="color: #808080; font-style: italic;">/* invoking the "myOperation" operation */</span>
    response = axis2_stub_op_MyService_myOperation<span style="color: #66cc66;">(</span>stub, env, op, &amp;fault<span style="color: #66cc66;">)</span>;

    <span style="color: #808080; font-style: italic;">/* checking the response == NULL implies fault is sent  */</span>
    <span style="color: #b1b100;">if</span><span style="color: #66cc66;">(</span>response == <span style="color: #000000; font-weight: bold;">NULL</span><span style="color: #66cc66;">)</span>
    <span style="color: #66cc66;">{</span>
        <span style="color: #808080; font-style: italic;">/* getting the error number to distinguish the fault */</span>
        error_code = env-&gt;error-&gt;error_number;

        <span style="color: #808080; font-style: italic;">/* compare error code with constants of each faults */</span>
        <span style="color: #b1b100;">if</span><span style="color: #66cc66;">(</span>error_code == AXIS2_STUB_MYSERVICE_MYOPERATION_FAULT_MYFIRSTEXCEPTION<span style="color: #66cc66;">)</span> <span style="color: #66cc66;">{</span>

            <span style="color: #808080; font-style: italic;">/* extracting out the adb objects */</span>
            axis2_char_t *text = adb_MyFirstException_get_text<span style="color: #66cc66;">(</span>fault.<span style="color: #202020;">MyFirstException</span>, env<span style="color: #66cc66;">)</span>;

            <span style="color: #808080; font-style: italic;">/* do a printf of the message */</span>
            <a href="http://www.opengroup.org/onlinepubs/009695399/functions/printf.html"><span style="color: #000066;">printf</span></a><span style="color: #66cc66;">(</span><span style="color: #ff0000;">"My First Exception called: with param %s<span style="color: #000099; font-weight: bold;">\\</span>n"</span>, text<span style="color: #66cc66;">)</span>;

        <span style="color: #66cc66;">}</span>
        <span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span><span style="color: #66cc66;">(</span>error_code == AXIS2_STUB_MYSERVICE_MYOPERATION_FAULT_MYSECONDEXCEPTION<span style="color: #66cc66;">)</span> <span style="color: #66cc66;">{</span>
            <span style="color: #808080; font-style: italic;">/* extracting out the adb objects */</span>
            <span style="color: #993333;">int</span> number = adb_MySecondException_get_number<span style="color: #66cc66;">(</span>fault.<span style="color: #202020;">MySecondException</span>, env<span style="color: #66cc66;">)</span>;

            <span style="color: #808080; font-style: italic;">/* do a printf of the message */</span>
            <a href="http://www.opengroup.org/onlinepubs/009695399/functions/printf.html"><span style="color: #000066;">printf</span></a><span style="color: #66cc66;">(</span><span style="color: #ff0000;">"My Second Exception called: with param %d<span style="color: #000099; font-weight: bold;">\\</span>n"</span>, number<span style="color: #66cc66;">)</span>;

        <span style="color: #66cc66;">}</span>

    <span style="color: #66cc66;">}</span></pre>
<p>Note that this feature is available only in the very latest WSDL2C tool. Try to get latest build from <a href="http://ws.apache.org/axis2">Axis2/Java</a> to use this up to date tool.</p>
<p>You can download the WSDL and codes used in this example from here, <a href="https://issues.apache.org/jira/secure/attachment/12399724/case45.zip">https://issues.apache.org/jira/secure/attachment/12399724/case45.zip</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.dimuthu.org/blog/2009/02/09/code-generate-custom-soap-faults-for-axis2c/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Sending Binary with Apache Axis2/C ADB</title>
		<link>http://www.dimuthu.org/blog/2008/11/24/sending-binary-with-apache-axis2c-adb/</link>
		<comments>http://www.dimuthu.org/blog/2008/11/24/sending-binary-with-apache-axis2c-adb/#comments</comments>
		<pubDate>Mon, 24 Nov 2008 18:21:22 +0000</pubDate>
		<dc:creator>dimuthu</dc:creator>
				<category><![CDATA[SOA]]></category>
		<category><![CDATA[Tutorial/Guide]]></category>
		<category><![CDATA[adb]]></category>
		<category><![CDATA[axis2/c]]></category>
		<category><![CDATA[codegen]]></category>
		<category><![CDATA[tool]]></category>
		<category><![CDATA[web services]]></category>
		<category><![CDATA[wsdl2c]]></category>
		<category><![CDATA[xml]]></category>
		<category><![CDATA[xml schema]]></category>
		<category><![CDATA[base64 binary]]></category>
		<category><![CDATA[binary]]></category>

		<guid isPermaLink="false">http://www.dimuthu.org/?p=716</guid>
		<description><![CDATA[Axis2/C ADB is a C language binding to the XML schema. ADB object model represents an XML specific to a given schema in a WSDL. You can use the Axis2 codegen tool to generate ADB codes for your WSDL and use that to build and parse your XMLs. The idea is, if you use ADB [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://ws.apache.org/axis2/c/">Axis2/C</a> ADB  is a C language binding to the XML schema. ADB object model represents an  XML specific to a given schema in a WSDL. You can use the Axis2 codegen tool to generate ADB codes for your WSDL and use that to build and parse your XMLs. The idea is, if you use ADB to build and parse your xmls, it will be really easy to do that  and you don&#8217;t need to know or understand anything about the schema or the wsdl.</p>
<p>Apache Axis2/C to can be used to send and receive binaries as MTOM, SWA or base64 encoded. But ADB generated code still support to send and receive base64 encoded binaries only. So if you use contract first approach  with Axis2/C (i.e start with the WSDL, then write the service based on that), you have to use base64-encoded (non-optimized) as the binary transferring method. Note that you can use the other methods like MTOM or SWA, if you write the code to build and parse the xmls from AXIOM which is a general model for XML like DOM.</p>
<p>Say you have an element with base64Binary type in your request XML. So the schema for that element would be,</p>
<pre class="xml"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;xs:complexType</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"Person"</span><span style="font-weight: bold; color: black;">&gt;</span></span>
    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;xs:sequence<span style="font-weight: bold; color: black;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;xs:element</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"image"</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">"xs:base64Binary"</span><span style="font-weight: bold; color: black;">/&gt;</span></span>
        ... <span style="color: #009900;"><span style="font-style: italic; color: #808080;">&lt;!-- some more elements --&gt;</span></span>
    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/xs:sequence<span style="font-weight: bold; color: black;">&gt;</span></span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/xs:complexType<span style="font-weight: bold; color: black;">&gt;</span></span></span></pre>
<p>After you code generated, you will get the adb_person.h and adb_person.c files with the following function prototypes and the implementations,</p>
<pre class="c">        <span style="font-style: italic; color: #808080;">/**
         * Constructor for creating adb_Person_t
         * @param env pointer to environment struct
         * @return newly created adb_Person_t object
         */</span>
        adb_Person_t* AXIS2_CALL
        adb_Person_create<span style="color: #66cc66;">(</span>
            <span style="color: #993333;">const</span> axutil_env_t *env <span style="color: #66cc66;">)</span>;

        <span style="font-style: italic; color: #808080;">/**
         * Free adb_Person_t object
         * @param  _Person adb_Person_t object to free
         * @param env pointer to environment struct
         * @return AXIS2_SUCCESS on success, else AXIS2_FAILURE
         */</span>
        axis2_status_t AXIS2_CALL
        adb_Person_free <span style="color: #66cc66;">(</span>
            adb_Person_t* _Person,
            <span style="color: #993333;">const</span> axutil_env_t *env<span style="color: #66cc66;">)</span>;

        <span style="font-style: italic; color: #808080;">/**
         * Getter for image.
         * @param  _Person adb_Person_t object
         * @param env pointer to environment struct
         * @return axutil_base64_binary_t*
         */</span>
        axutil_base64_binary_t* AXIS2_CALL
        adb_Person_get_image<span style="color: #66cc66;">(</span>
            adb_Person_t* _Person,
            <span style="color: #993333;">const</span> axutil_env_t *env<span style="color: #66cc66;">)</span>;

        <span style="font-style: italic; color: #808080;">/**
         * Setter for image.
         * @param  _Person adb_Person_t object
         * @param env pointer to environment struct
         * @param arg_image axutil_base64_binary_t*
         * @return AXIS2_SUCCESS on success, else AXIS2_FAILURE
         */</span>
        axis2_status_t AXIS2_CALL
        adb_Person_set_image<span style="color: #66cc66;">(</span>
            adb_Person_t* _Person,
            <span style="color: #993333;">const</span> axutil_env_t *env,
            axutil_base64_binary_t*  arg_image<span style="color: #66cc66;">)</span>;</pre>
<p>So you can manipulate the person element in c language using the create, get, set and free function.</p>
<pre class="c">    <span style="font-style: italic; color: #808080;">/* here the env is the axutil_env_t* instance - the axis2/c environment */</span>
    FILE *f = fopen<span style="color: #66cc66;">(</span><span style="color: #ff0000;">"./images/person.png"</span>, <span style="color: #ff0000;">"r+"</span><span style="color: #66cc66;">)</span>;
    <span style="color: #993333;">int</span> binary_count;
    <span style="font-style: italic; color: #808080;">/* binary read a function you may write to read the binary data to the
     variable binary and the count to the variable binary_count */</span>
    <span style="color: #993333;">unsigned</span> <span style="color: #993333;">char</span> *binary = binary_read<span style="color: #66cc66;">(</span>f, env, &amp;binary_count<span style="color: #66cc66;">)</span>;
    axutil_base64_binary_t *base64 = axutil_base64_binary_create_with_plain_binary<span style="color: #66cc66;">(</span>
                                        env, binary, binary_count<span style="color: #66cc66;">)</span>;

    adb_Person_t *person = adb_Person_create<span style="color: #66cc66;">(</span>env<span style="color: #66cc66;">)</span>;
    adb_Person_set_image<span style="color: #66cc66;">(</span>person, env, base64<span style="color: #66cc66;">)</span>;</pre>
<p>You can set this adb person directly to your request or to a setter of another adb instance to complete the ADB tree. So this way you can send binaries (as base64 encoded) using the Axis2/C ADB generated code.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dimuthu.org/blog/2008/11/24/sending-binary-with-apache-axis2c-adb/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Use Axis2/C WSDL2C With Unwrapped Mode for Simpler Code</title>
		<link>http://www.dimuthu.org/blog/2008/09/15/use-axis2c-wsdl2c-with-unwrapped-mode-for-simpler-code/</link>
		<comments>http://www.dimuthu.org/blog/2008/09/15/use-axis2c-wsdl2c-with-unwrapped-mode-for-simpler-code/#comments</comments>
		<pubDate>Mon, 15 Sep 2008 15:10:37 +0000</pubDate>
		<dc:creator>dimuthu</dc:creator>
				<category><![CDATA[Tutorial/Guide]]></category>
		<category><![CDATA[WSDL]]></category>
		<category><![CDATA[adb]]></category>
		<category><![CDATA[axis2/c]]></category>
		<category><![CDATA[codegen]]></category>
		<category><![CDATA[tool]]></category>
		<category><![CDATA[web services]]></category>
		<category><![CDATA[wsdl2c]]></category>
		<category><![CDATA[xml schema]]></category>
		<category><![CDATA[Code generation]]></category>
		<category><![CDATA[Easier]]></category>
		<category><![CDATA[Simple]]></category>
		<category><![CDATA[unwrapped]]></category>

		<guid isPermaLink="false">http://www.dimuthu.org/?p=263</guid>
		<description><![CDATA[WSDL2Java and WSDL2C tools shipped with the Axis2/Java project are used to generate Stubs(client side) and Skeletons(Server Side) respectively for Axis2/Java and Axis2/C codes. This make the development of web services and consumers more quicker and easier. The tools come with many options allowing the user to customize the code generation. One of the such [...]]]></description>
			<content:encoded><![CDATA[<p>WSDL2Java and WSDL2C tools shipped with the <a href="http://ws.apache.org/axis2">Axis2/Java project</a> are used to generate Stubs(client side) and Skeletons(Server Side) respectively for Axis2/Java and Axis2/C codes. This make the development of web services and consumers more quicker and easier.</p>
<p>The tools come with many options allowing the user to customize the code generation. One of the such option is &#8216;-uw&#8217; which used to turn on the &#8216;unwrapping&#8217; mode. WSDL2Java project had this option for a long time, But it is just Today I was able to enable that option in the WSDL2C tool. So lets see how it make the code easier.</p>
<p>Say you have the &#8216;simpleAdd&#8217; operation with the following schema,</p>
<pre>            <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;xs:element</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"simpleAdd"</span><span style="font-weight: bold; color: black;">&gt;</span></span>
                <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;xs:complexType<span style="font-weight: bold; color: black;">&gt;</span></span></span>
                    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;xs:sequence<span style="font-weight: bold; color: black;">&gt;</span></span></span>
                        <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;xs:element</span> <span style="color: #000066;">minOccurs</span>=<span style="color: #ff0000;">"0"</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"param0"</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">"xs:int"</span><span style="font-weight: bold; color: black;">/&gt;</span></span>
                        <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;xs:element</span> <span style="color: #000066;">minOccurs</span>=<span style="color: #ff0000;">"0"</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"param1"</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">"xs:int"</span><span style="font-weight: bold; color: black;">/&gt;</span></span>
                    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/xs:sequence<span style="font-weight: bold; color: black;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/xs:complexType<span style="font-weight: bold; color: black;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/xs:element<span style="font-weight: bold; color: black;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;xs:element</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"simpleAddResponse"</span><span style="font-weight: bold; color: black;">&gt;</span></span>
                <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;xs:complexType<span style="font-weight: bold; color: black;">&gt;</span></span></span>
                    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;xs:sequence<span style="font-weight: bold; color: black;">&gt;</span></span></span>
                        <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;xs:element</span> <span style="color: #000066;">minOccurs</span>=<span style="color: #ff0000;">"0"</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"return"</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">"xs:int"</span><span style="font-weight: bold; color: black;">/&gt;</span></span>
                    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/xs:sequence<span style="font-weight: bold; color: black;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/xs:complexType<span style="font-weight: bold; color: black;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/xs:element<span style="font-weight: bold; color: black;">&gt;</span></span></span></pre>
<p>When you generate the code for server side with Java using the following command, (note the option -uw which stands for &#8216;unwrapping&#8217;)</p>
<pre>wsdl2java.sh -uri xxx.wsdl -u -ss -sd -uw</pre>
<p>it gives you the following service function.</p>
<pre><span style="font-weight: bold; color: #000000;">public</span> <span style="color: #993333;">int</span> simpleAdd<span style="color: #66cc66;">(</span><span style="color: #993333;">int</span> param0, <span style="color: #993333;">int</span> param1<span style="color: #66cc66;">)</span>
<span style="color: #66cc66;">{</span>
    <span style="font-style: italic; color: #808080;">//TODO : fill this with the necessary business logic</span>
<span style="color: #66cc66;">}</span></pre>
<p>Note the input and output parameters of the function are simple types. If you don&#8217;t give the &#8216;-uw&#8217; option, You will instead get a function with input and output variables as class names wrapping these simple types which is not this much straight forward.</p>
<p>So now the same is available with C. You can use  WSDl2C tool with the same option set to generate a very simple service API.</p>
<pre>wsdl2c.sh -uri xxx.wsdl -u -ss -sd -uw</pre>
<p>And here is the service logic you may write, Can you think of an API simpler than this,</p>
<pre>        <span style="font-style: italic; color: #808080;">/**
         * auto generated function definition signature
         * for "simpleAdd|http://ws.apache.org/axis2" operation.
         * @param env environment ( mandatory)
         * @param _param0 of the int
         * @param _param1 of the int
         *
         * @return int
         */</span>
        <span style="color: #993333;">int</span> axis2_skel_UnwrappedAdder_simpleAdd<span style="color: #66cc66;">(</span><span style="color: #993333;">const</span> axutil_env_t *env,
                                              <span style="color: #993333;">int</span> _param0,
                                              <span style="color: #993333;">int</span> _param1 <span style="color: #66cc66;">)</span>

        <span style="color: #66cc66;">{</span>
          <span style="color: #b1b100;">return</span> _param0 + _param1;
        <span style="color: #66cc66;">}</span></pre>
<p>You can find the code for complete case (wsdl, skel and stub) in the <a href="https://issues.apache.org/jira/secure/attachment/12390112/unwrapped.zip"> Axis2/C Jira Attachment space for the &#8216;unwrapping&#8217; issue</a>. Note that this update is only available in the nightly build and not in the release. You can download the nightly build from <a href="http://builder.wso2.org/browse/AXIS2-NIGHTLY">wso2&#8242;s axis2/java nightly build page</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dimuthu.org/blog/2008/09/15/use-axis2c-wsdl2c-with-unwrapped-mode-for-simpler-code/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>How to Hack Axis2 Codegen templates from an Axis2 Binary</title>
		<link>http://www.dimuthu.org/blog/2008/09/13/how-to-hack-axis2-codegen-templates-from-a-axis2-binary/</link>
		<comments>http://www.dimuthu.org/blog/2008/09/13/how-to-hack-axis2-codegen-templates-from-a-axis2-binary/#comments</comments>
		<pubDate>Sat, 13 Sep 2008 14:35:17 +0000</pubDate>
		<dc:creator>dimuthu</dc:creator>
				<category><![CDATA[Tutorial/Guide]]></category>
		<category><![CDATA[WSDL]]></category>
		<category><![CDATA[adb]]></category>
		<category><![CDATA[axis2/c]]></category>
		<category><![CDATA[codegen]]></category>
		<category><![CDATA[tool]]></category>
		<category><![CDATA[web services]]></category>
		<category><![CDATA[wsdl2c]]></category>
		<category><![CDATA[xml schema]]></category>
		<category><![CDATA[Axis2/Java]]></category>
		<category><![CDATA[binary]]></category>
		<category><![CDATA[Custom templates]]></category>
		<category><![CDATA[Skeleton]]></category>
		<category><![CDATA[Stub]]></category>
		<category><![CDATA[Tools]]></category>
		<category><![CDATA[XSLT]]></category>

		<guid isPermaLink="false">http://www.dimuthu.org/?p=255</guid>
		<description><![CDATA[I have been working for Axis2/C codegen tool for sometime now and I found lot of users who want to edit the codegen templates for a more optimized code specific to their use cases. This is mainly because codegen tool generates a very general code (For an example lot of unused variables generated for some [...]]]></description>
			<content:encoded><![CDATA[<p>I have been working for <a href="http://ws.apache.org/axis2/c/">Axis2/C</a> codegen tool for sometime now and I found lot of users who want to edit the codegen templates for a more optimized code specific to their use cases. This is mainly because codegen tool generates a very general code (For an example lot of unused variables generated for some WSDLs, but they are used in some other WSDLs) where as mostly &#8216;C&#8217; people prefer to be as optimized as possible. Axis2 Java templates are more stable and not needed to customized as much as C templates, but Java developers too may find it is really useful to edit them in a case they need some customizations.</p>
<p>Both Axis2 C and Java tools comes with <a href="http://ws.apache.org/axis2/">Axis2/Java project</a>. So you may already have downloaded the latest <a href="http://ws.apache.org/axis2/download.cgi">Axis2/Java release</a> or <a href="http://builder.wso2.org/browse/AXIS2-NIGHTLY">the Axis2/Java nightly build</a>. As per title you can do this customization not only in the source but also in the binary pack. So I assume you have the binary pack.</p>
<p>Codegen tool mainly comes within two jars inside the lib directory of your Axis2/Java pack. (Here xxxx should be replaced with the particular jar version, it can be 1.4, 1.4.1 or SNAPSHOT)</p>
<ul>
<li>axis2-codegen-xxxx.jar &#8211; The core classes of the codegen (This is where WSDL2C and WSDL2Java classes reside)</li>
<li>axis2-adb-codegen-xxxx.jar &#8211; This is the library containing the adb component of the codegen tool. ADB (Axis2 Data Binding) is the native databinding format of Axis2 which convert your xml schema to a more programmer friendly set of java classes or &#8216;C&#8217; structures. The XSD2Java class comes in this jar.</li>
</ul>
<p><strong>Editing the Stub and Skeleton templates</strong></p>
<p>When you unpack the axis2-codegen-xxxx.jar</p>
<pre>jar xf axis2-codegen-xxxx.jar</pre>
<p>you can find the template for Stub and Skel in org/apache/axis2/wsdl/template/c or org/apache/axis2/wsdl/template/java directories.</p>
<ul>
<li>Stub For C &#8211; org/apache/axis2/wsdl/template/c/StubSourceTemplate.xsl (source) and org/apache/axis2/wsdl/template/c/StubHeaderTemplate.xsl (header)</li>
<li>Skeleton for C &#8211; org/apache/axis2/wsdl/template/c/SkelSourceTemplate.xsl (source) and org/apache/axis2/wsdl/template/c/SkelHeaderTemplate.xsl (header)</li>
<li>Stub For Java &#8211; org/apache/axis2/wsdl/template/java/InterfaceImplementationTemplate.xsl</li>
<li>Skel For Java &#8211; org/apache/axis2/wsdl/template/java/MessageReceiverTemplate.xsl (Message Reciever) and org/apache/axis2/wsdl/template/java/SkeletonTemplate.xsl (skeleton)</li>
</ul>
<p>These templates are written is XSL. Even if you are an XSL expert, you may find little difficult to understand whole lot of codes in there. But if you really know what you need to change, you can track back the lines (may be using comment or some specific static set of code). So you don&#8217;t actually need to know any XSL to do these little customizations.</p>
<p>After you do the change simply pack the classes (which are in the &#8216;org&#8217; directory) as the jar with the same name.</p>
<pre>jar cf axis2-codegen-xxxx.jar org</pre>
<p><strong>Editing the ADB templates</strong></p>
<p>You can similarly observe the axis2-adb-codegen-xxxx.jar. All the templates are in the org/apache/axis2/schema/template/ directory.</p>
<ul>
<li>C ADB templates &#8211; org/apache/axis2/schema/template/CADBBeanTemplateHeader.xsl (Source) and org/apache/axis2/schema/template/CADBBeanTemplateHeader.xsl (Header)</li>
<li>Java ADB template &#8211; org/apache/axis2/schema/template/ADBBeanTemplate.xsl</li>
</ul>
<p>You will find the template for the Java classes and C structures there. In C code generation if you find some variables are not used throughout your WSDLs, you can remove directly if from the templates. And some constants which are defined to allocate memory can be changed to suit to your application.</p>
<p>Anyway after all these notes, I have to say it is not really recommended to hack a code specific to your application. If you found a change general to all the applications you better submit the patch to the Axis2 community, so others too can use it. Otherwise whenever you do a upgrade you have to do this again on your own. But I hope these tips may be useful specially when you are working with ADB to do your own experiments.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dimuthu.org/blog/2008/09/13/how-to-hack-axis2-codegen-templates-from-a-axis2-binary/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Axis2/C ADB 2 Minutes Introduction</title>
		<link>http://www.dimuthu.org/blog/2008/09/03/axis2c-adb-2-minitue-introduction/</link>
		<comments>http://www.dimuthu.org/blog/2008/09/03/axis2c-adb-2-minitue-introduction/#comments</comments>
		<pubDate>Wed, 03 Sep 2008 14:14:27 +0000</pubDate>
		<dc:creator>dimuthu</dc:creator>
				<category><![CDATA[2 minutes guide]]></category>
		<category><![CDATA[Tutorial/Guide]]></category>
		<category><![CDATA[WSDL]]></category>
		<category><![CDATA[adb]]></category>
		<category><![CDATA[axis2/c]]></category>
		<category><![CDATA[codegen]]></category>
		<category><![CDATA[tool]]></category>
		<category><![CDATA[wsdl2c]]></category>
		<category><![CDATA[xml]]></category>
		<category><![CDATA[xml schema]]></category>
		<category><![CDATA[2 minutes]]></category>
		<category><![CDATA[guide]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://www.dimuthu.org/?p=204</guid>
		<description><![CDATA[Building and Traversing XML are regular tasks for any Web Service developer. We may use DOM, AXIOM or even simple String manipulation functions to do that. Normally this takes a lot of time and effort. And if we are coding in &#8216;C&#8217; it become more tedious as string manipulation in &#8216;C&#8217; is not that straight [...]]]></description>
			<content:encoded><![CDATA[<p>Building and Traversing XML are regular tasks for any Web Service developer. We may use DOM, AXIOM or even simple String manipulation functions to do that. Normally this takes a lot of time and effort. And if we are coding in &#8216;C&#8217; it become more tedious as string manipulation in &#8216;C&#8217; is not that straight forward.</p>
<p>What ADB does is it generates a set of &#8216;C&#8217; functions specially for our XML Schema to build and traverse the XML.<br />
Say you have the following XML Schema. (You need to have it inside a WSDL to generate the code).</p>
<pre>        <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;xs:schema</span> <span style="color: #000066;">targetNamespace</span>=<span style="color: #ff0000;">"http://dimuthu.org/adb/demo/2008/sept"</span><span style="font-weight: bold; color: black;">&gt;</span></span>
            <span style="color: #009900;"><span style="font-style: italic; color: #808080;">&lt;!-- demonstrating element--&gt;</span></span>
            <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;xs:element</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"myDemo"</span><span style="font-weight: bold; color: black;">&gt;</span></span>
                <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;xs:complexType<span style="font-weight: bold; color: black;">&gt;</span></span></span>
                    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;xs:sequence<span style="font-weight: bold; color: black;">&gt;</span></span></span>
                        <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;xs:element</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"demo1"</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">"xs:int"</span><span style="font-weight: bold; color: black;">/&gt;</span></span>
                        <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;xs:element</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"demo2"</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">"xs:string"</span><span style="font-weight: bold; color: black;">/&gt;</span></span>
                    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/xs:sequence<span style="font-weight: bold; color: black;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/xs:complexType<span style="font-weight: bold; color: black;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/xs:element<span style="font-weight: bold; color: black;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;xs:schema</span><span style="font-weight: bold; color: black;">/&gt;</span></span></pre>
<p>For this particular element there will be one adb type (adb_myDemo_t), one source (adb_myDemo.c) and one header (adb_myDemo.h) are generated. Don&#8217;t ever look at the source file (unless you want to hack it) just go through the header, it will have all the function you need to manipulate your ADB.</p>
<p>It will have following set of functions,</p>
<pre>To create and free the object
<ul>
<li>adb_myDemo_create</li>
<li>adb_myDemo_free</li>
</ul>

Getters and Setters to manipulate Data
<ul>
<li>adb_myDemo_get_demo1</li>
<li>adb_myDemo_set_demo1</li>
<li>adb_myDemo_get_demo2</li>
<li>adb_myDemo_set_demo2</li>
</ul>

Build and Parse XML
<ul>
<li>adb_myDemo_serialize</li>
<li>adb_myDemo_deserialize</li>
</ul>
</pre>
<p>First we will check how to build a simple XML using an ADB object.</p>
<pre>    adb_myDemo_t *mydemo = adb_myDemo_create<span style="color: #66cc66;">(</span>env<span style="color: #66cc66;">)</span>;
    adb_myDemo_set_demo1<span style="color: #66cc66;">(</span>mydemo, env, <span style="color: #cc66cc;">3</span><span style="color: #66cc66;">)</span>; <span style="font-style: italic; color: #808080;">/* some arbitrary value */</span>
    adb_myDemo_set_demo2<span style="color: #66cc66;">(</span>mydemo, env, <span style="color: #ff0000;">"some arbitrary string"</span><span style="color: #66cc66;">)</span>;
    axiom_t *xml = adb_myDemo_serialize<span style="color: #66cc66;">(</span>mydemo, env, <span style="font-weight: bold; color: #000000;">NULL</span>, <span style="font-weight: bold; color: #000000;">NULL</span>, AXIS2_TRUE, <span style="font-weight: bold; color: #000000;">NULL</span>, <span style="font-weight: bold; color: #000000;">NULL</span><span style="color: #66cc66;">)</span>;</pre>
<p>So now we have the AXIOM representation of the XML which we just build using ADB.</p>
<pre><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;ns0:myDemo</span> xmlns:ns0=<span style="color: #ff0000;">"http://dimuthu.org/adb/demo/2008/sept"</span><span style="font-weight: bold; color: black;">&gt;</span></span>
    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;ns0:demo1<span style="font-weight: bold; color: black;">&gt;</span></span></span>3<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/ns0:demo1<span style="font-weight: bold; color: black;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;ns0:demo2<span style="font-weight: bold; color: black;">&gt;</span></span></span>some arbitrary string<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/ns0:demo2<span style="font-weight: bold; color: black;">&gt;</span></span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/ns0:myDemo<span style="font-weight: bold; color: black;">&gt;</span></span></span></pre>
<p>Anyway ADB is easier when you want to navigate through an XML. (you can read data randomly as you preferred). Here we starting from the AXIOM representation of our XML.</p>
<pre>      adb_myDemo_t *mydemo= adb_myDemo_create<span style="color: #66cc66;">(</span> env<span style="color: #66cc66;">)</span>;
      adb_myDemo_deserialize<span style="color: #66cc66;">(</span>mydemo, env, &amp;xml, <span style="font-weight: bold; color: #000000;">NULL</span>, AXIS2_FALSE<span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span>
      <span style="color: #993333;">int</span> demo1 = adb_myDemo_get_demo1<span style="color: #66cc66;">(</span>mydemo, env<span style="color: #66cc66;">)</span>;
      <a href="http://www.opengroup.org/onlinepubs/009695399/functions/printf.html"><span style="color: #000066;">printf</span></a><span style="color: #66cc66;">(</span><span style="color: #ff0000;">"My Demo1 is: %d<span style="font-weight: bold; color: #000099;">\\</span>n"</span>, demo1<span style="color: #66cc66;">)</span>;
      axis2_char_t *demo2 = adb_myDemo_get_demo2<span style="color: #66cc66;">(</span>mydemo, env<span style="color: #66cc66;">)</span>;
      <a href="http://www.opengroup.org/onlinepubs/009695399/functions/printf.html"><span style="color: #000066;">printf</span></a><span style="color: #66cc66;">(</span><span style="color: #ff0000;">"My Demo2 is: %s<span style="font-weight: bold; color: #000099;">\\</span>n"</span>, demo2<span style="color: #66cc66;">)</span>;</pre>
<p>I have printed the Data contained in the XML with the help of ADB objects.</p>
<p>In ordre to download the Codegen tool with ADB you have to download the <a href="http://ws.apache.org/axis2/download.cgi">Axis2/Java package</a>.</p>
<p>If you want to learn more about ADB, Just go through <a href="http://www.dimuthu.org/blog/2008/07/21/axis2c-adb-codegen-wsdl2c-tutorial-resources/">more Axis2/C Codegen / ADB resources </a>which I have blogged few weeks ago.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dimuthu.org/blog/2008/09/03/axis2c-adb-2-minitue-introduction/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to Build Custom SOAP Headers in WSDL Using Axis2/C and WSF/PHP</title>
		<link>http://www.dimuthu.org/blog/2008/08/21/how-to-build-custom-soap-headers-in-wsdl-using-axis2c-and-wsfphp/</link>
		<comments>http://www.dimuthu.org/blog/2008/08/21/how-to-build-custom-soap-headers-in-wsdl-using-axis2c-and-wsfphp/#comments</comments>
		<pubDate>Thu, 21 Aug 2008 01:29:47 +0000</pubDate>
		<dc:creator>dimuthu</dc:creator>
				<category><![CDATA[Tutorial/Guide]]></category>
		<category><![CDATA[WSDL]]></category>
		<category><![CDATA[adb]]></category>
		<category><![CDATA[axis2/c]]></category>
		<category><![CDATA[codegen]]></category>
		<category><![CDATA[tool]]></category>
		<category><![CDATA[web services]]></category>
		<category><![CDATA[wsdl2c]]></category>
		<category><![CDATA[wsf/php]]></category>
		<category><![CDATA[wso2]]></category>
		<category><![CDATA[Headers]]></category>
		<category><![CDATA[SOAP]]></category>

		<guid isPermaLink="false">http://www.dimuthu.org/?p=200</guid>
		<description><![CDATA[SOAP Headers are used in many WS-* standards (for an example WS-Security) to transmit information related to the QOS aspects of the service. So only the SOAP engines which process these QOS parameters are supposed to see these headers. Web Service Developer or Consumer need to care only what is in the SOAP payload (which [...]]]></description>
			<content:encoded><![CDATA[<p>SOAP Headers are used in many WS-* standards (for an example WS-Security) to transmit information related to the QOS aspects of the service. So only the SOAP engines which process these QOS parameters are supposed to see these headers. Web Service Developer or Consumer need to care only what is in the SOAP payload (which is what inside the SOAP body element) and not SOAP headers.</p>
<p>But that is theory, In practice we see many places where people uses SOAP headers to transmit what they should have easily sent through SOAP Body. And many SOAP stacks also provide APIs to allow people to send/receive custom headers and standards like WSDL too provide ways to describe services which accept custom headers. So I thought it might worth to discuss how you describe custom headers in a service from a WSDL and how you can consume and serve in real world with SOAP stacks like <a href="http://ws.apache.org/axis2">Axis2/C</a> and <a href="http://wso2.org/projects/wsf/php">WSF/PHP</a>.</p>
<p>In a WSDL 1.1 you first declare your headers in the binding section itself which is the section that is used to provide the messaging and transport protocol information.</p>
<pre>  <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;binding</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"RetHeaderBinding"</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">"tns:RetHeaderPortType"</span><span style="font-weight: bold; color: black;">&gt;</span></span>
    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;soap:binding</span> <span style="color: #000066;">transport</span>=<span style="color: #ff0000;">"http://schemas.xmlsoap.org/soap/http"</span> <span style="color: #000066;">style</span>=<span style="color: #ff0000;">"document"</span><span style="font-weight: bold; color: black;">/&gt;</span></span>
    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;operation</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"echoString"</span><span style="font-weight: bold; color: black;">&gt;</span></span>
      <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;soap:operation</span> <span style="color: #000066;">soapAction</span>=<span style="color: #ff0000;">"http://soapinterop.org/"</span> <span style="color: #000066;">style</span>=<span style="color: #ff0000;">"document"</span><span style="font-weight: bold; color: black;">/&gt;</span></span>
      <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;input<span style="font-weight: bold; color: black;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;soap:body</span> <span style="color: #000066;">use</span>=<span style="color: #ff0000;">"literal"</span><span style="font-weight: bold; color: black;">/&gt;</span></span>
        <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;soap:header</span> <span style="color: #000066;">message</span>=<span style="color: #ff0000;">"tns:Header1"</span> <span style="color: #000066;">part</span>=<span style="color: #ff0000;">"Header1"</span> <span style="color: #000066;">use</span>=<span style="color: #ff0000;">"literal"</span><span style="font-weight: bold; color: black;">/&gt;</span></span>
        <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;soap:header</span> <span style="color: #000066;">message</span>=<span style="color: #ff0000;">"tns:Header2"</span> <span style="color: #000066;">part</span>=<span style="color: #ff0000;">"Header2"</span> <span style="color: #000066;">use</span>=<span style="color: #ff0000;">"literal"</span><span style="font-weight: bold; color: black;">/&gt;</span></span>
      <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/input<span style="font-weight: bold; color: black;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;output<span style="font-weight: bold; color: black;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;soap:body</span> <span style="color: #000066;">use</span>=<span style="color: #ff0000;">"literal"</span><span style="font-weight: bold; color: black;">/&gt;</span></span>
        <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;soap:header</span> <span style="color: #000066;">message</span>=<span style="color: #ff0000;">"tns:Header1"</span> <span style="color: #000066;">part</span>=<span style="color: #ff0000;">"Header1"</span> <span style="color: #000066;">use</span>=<span style="color: #ff0000;">"literal"</span><span style="font-weight: bold; color: black;">/&gt;</span></span>
        <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;soap:header</span> <span style="color: #000066;">message</span>=<span style="color: #ff0000;">"tns:Header2"</span> <span style="color: #000066;">part</span>=<span style="color: #ff0000;">"Header2"</span> <span style="color: #000066;">use</span>=<span style="color: #ff0000;">"literal"</span><span style="font-weight: bold; color: black;">/&gt;</span></span>
      <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/output<span style="font-weight: bold; color: black;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/operation<span style="font-weight: bold; color: black;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/binding<span style="font-weight: bold; color: black;">&gt;</span></span></span></pre>
<p>There you can see we have Header1 and Header2 in both in input and output of the operation. It refers to the message section with the specific part name that represent the header. Here is how message section will look like.</p>
<pre>  <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;message</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"Header1"</span><span style="font-weight: bold; color: black;">&gt;</span></span>
    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;part</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"Header1"</span> <span style="color: #000066;">element</span>=<span style="color: #ff0000;">"types:Header1"</span><span style="font-weight: bold; color: black;">/&gt;</span></span>
  <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/message<span style="font-weight: bold; color: black;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;message</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"Header2"</span><span style="font-weight: bold; color: black;">&gt;</span></span>
    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;part</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"Header2"</span> <span style="color: #000066;">element</span>=<span style="color: #ff0000;">"types:Header2"</span><span style="font-weight: bold; color: black;">/&gt;</span></span>
  <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/message<span style="font-weight: bold; color: black;">&gt;</span></span></span></pre>
<p>In this section it refers to the schema element that actually describe the element structure/schema. Here I put a string and an int in each header.</p>
<pre>  <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;s:element</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"Header1"</span><span style="font-weight: bold; color: black;">&gt;</span></span>
      <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;s:complexType<span style="font-weight: bold; color: black;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;s:sequence<span style="font-weight: bold; color: black;">&gt;</span></span></span>
          <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;s:element</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"string"</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">"s:string"</span><span style="font-weight: bold; color: black;">/&gt;</span></span>
          <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;s:element</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"int"</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">"s:int"</span><span style="font-weight: bold; color: black;">/&gt;</span></span>
        <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/s:sequence<span style="font-weight: bold; color: black;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/s:complexType<span style="font-weight: bold; color: black;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/s:element<span style="font-weight: bold; color: black;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;s:element</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"Header2"</span><span style="font-weight: bold; color: black;">&gt;</span></span>
      <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;s:complexType<span style="font-weight: bold; color: black;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;s:sequence<span style="font-weight: bold; color: black;">&gt;</span></span></span>
          <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;s:element</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"int"</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">"s:int"</span><span style="font-weight: bold; color: black;">/&gt;</span></span>
          <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;s:element</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"string"</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">"s:string"</span><span style="font-weight: bold; color: black;">/&gt;</span></span>
        <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/s:sequence<span style="font-weight: bold; color: black;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/s:complexType<span style="font-weight: bold; color: black;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/s:element<span style="font-weight: bold; color: black;">&gt;</span></span></span></pre>
<p>Here is a valid SOAP message for the WSDL description.</p>
<pre><span style="font-weight: bold; color: black;">&lt;soapenv:Envelope</span> <span style="color: #000066;">xmlns:soapenv</span>=<span style="color: #ff0000;">"http://schemas.xmlsoap.org/soap/envelope/"</span><span style="font-weight: bold; color: black;">&gt;</span>
   <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;soapenv:Header<span style="font-weight: bold; color: black;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;ns1:Header1</span> xmlns:ns1=<span style="color: #ff0000;">"http://soapinterop.org/xsd"</span><span style="font-weight: bold; color: black;">&gt;</span></span>
         <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;ns1:string<span style="font-weight: bold; color: black;">&gt;</span></span></span>test1<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/ns1:string<span style="font-weight: bold; color: black;">&gt;</span></span></span>
         <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;ns1:int<span style="font-weight: bold; color: black;">&gt;</span></span></span>5<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/ns1:int<span style="font-weight: bold; color: black;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/ns1:Header1<span style="font-weight: bold; color: black;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;ns1:Header2</span> xmlns:ns1=<span style="color: #ff0000;">"http://soapinterop.org/xsd"</span><span style="font-weight: bold; color: black;">&gt;</span></span>
         <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;ns1:int<span style="font-weight: bold; color: black;">&gt;</span></span></span>8<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/ns1:int<span style="font-weight: bold; color: black;">&gt;</span></span></span>
         <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;ns1:string<span style="font-weight: bold; color: black;">&gt;</span></span></span>test2<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/ns1:string<span style="font-weight: bold; color: black;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/ns1:Header2<span style="font-weight: bold; color: black;">&gt;</span></span></span>
   <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/soapenv:Header<span style="font-weight: bold; color: black;">&gt;</span></span></span>
   <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;soapenv:Body<span style="font-weight: bold; color: black;">&gt;</span></span></span>
      My payload
   <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/soapenv:Body<span style="font-weight: bold; color: black;">&gt;</span></span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/soapenv:Envelope<span style="font-weight: bold; color: black;">&gt;</span>
</span></span></pre>
<p>If you are using <a href="http://ws.apache.org/axis2">Apache Axis2/C WSDL2C Codegen tool (which is shipped with Axis2/Java)</a> you will be able to directly use the API provided with the generated code to deal with custom headers. Here is how the client API is generated for the above WSDL.</p>
<pre>         <span style="font-style: italic; color: #808080;">/**
          * auto generated method signature
          * for "echoString|http://ws.dimuthu.org/blog/headers" operation.
          *
          * @param _echoStringParam
          * @param _header1
          * @param _header2
          *
          * @param dp_header10 - output header
          * @param dp_header21 - output header
          * @return adb_echoStringReturn_t*
          */</span>
         adb_echoStringReturn_t*
         axis2_stub_op_RetHeaderService_echoString<span style="color: #66cc66;">(</span> axis2_stub_t *stub, <span style="color: #993333;">const</span> axutil_env_t *env,
                                              adb_echoStringParam_t* _echoStringParam,
                                              adb_Header1E0_t* _header1,
                                              adb_Header2E1_t* _header2,
                                              adb_Header1E0_t** dp_header10 <span style="font-style: italic; color: #808080;">/* output header double ptr*/</span>,
                                              adb_Header2E1_t** dp_header21 <span style="font-style: italic; color: #808080;">/* output header double ptr*/</span><span style="color: #66cc66;">)</span></pre>
<p>Note that the first parameter is the environment variable passed in every function in Axis2/c. The second parameters is the payload. Input headers (input headers for server side) are in 3rd and 4th parameters, you can build them similar to how you build payload object. 5th and 6th are for the output headers which you only need to provide some pointers and the generated code will build you the objects from the response data.</p>
<p>You service will also have a similar API. There you have to create adb objects for output headers (like you build output payload) and assign the pointer to these output header double pointers.</p>
<pre>             adb_Header2_t* arg_Header1 = adb_Header1_create<span style="color: #66cc66;">(</span>env<span style="color: #66cc66;">)</span>;
             adb_Header1_set_string<span style="color: #66cc66;">(</span>arg_Header1, env, <span style="color: #ff0000;">"I m response Header 1"</span><span style="color: #66cc66;">)</span>;
             adb_Header1_set_int<span style="color: #66cc66;">(</span>arg_Header1, env, <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">)</span>;
             adb_Header10_t* _header1 = adb_Header10_create<span style="color: #66cc66;">(</span>env<span style="color: #66cc66;">)</span>;
             adb_Header10_set_Header1<span style="color: #66cc66;">(</span>_header1, env, arg_Header1<span style="color: #66cc66;">)</span>;
             *dp_header10 = _header1;</pre>
<p>Now how about PHP, can you provide the same API form the PHP as well. Yes, PHP has references similar to C pointers. WSF/PHP already have the custom headers support in the SVN and to be released with the 2.0.<br />
Here is the generated API for the service business logic for the above WSDL.</p>
<pre><span style="font-style: italic; color: #808080;">/**
 * Service function echoString
 * @param string $input
 * @param object of Header1 $header_in0 input header
 * @param object of Header2 $header_in1 input header
 * @param reference object of Header1 $header_out0 output header
 * @param reference object of Header2 $header_out1 output header
 * @return string
 */</span>
<span style="font-weight: bold; color: #000000;">function</span> echoString<span style="color: #66cc66;">(</span><span style="color: #0000ff;">$input</span>, <span style="color: #0000ff;">$header_in0</span>, <span style="color: #0000ff;">$header_in1</span>, &amp;<span style="color: #0000ff;">$header_out0</span>, &amp;<span style="color: #0000ff;">$header_out1</span><span style="color: #66cc66;">)</span> <span style="color: #66cc66;">{</span>

...
<span style="color: #66cc66;">}</span></pre>
<p>These tool provides APIs to consume and provide data through custom headers in same easiness you send the data in the payload. Anyway it is really recommended to not to use custom SOAP headers in your Service and try to avoid them as much as possible. Whenever you think there is valid reason to put a custom header (it is relevant to QOS aspects), just try to integrate the header processing logic to the SOAP engine. In Axis2 C or Java you can write Axis2 modules for that. That will really speed up the processing of your service and give consumers a well-designed API.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dimuthu.org/blog/2008/08/21/how-to-build-custom-soap-headers-in-wsdl-using-axis2c-and-wsfphp/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Axis2/C ADB Codegen (WSDL2C) Tutorial + Resources</title>
		<link>http://www.dimuthu.org/blog/2008/07/21/axis2c-adb-codegen-wsdl2c-tutorial-resources/</link>
		<comments>http://www.dimuthu.org/blog/2008/07/21/axis2c-adb-codegen-wsdl2c-tutorial-resources/#comments</comments>
		<pubDate>Mon, 21 Jul 2008 02:03:26 +0000</pubDate>
		<dc:creator>dimuthu</dc:creator>
				<category><![CDATA[adb]]></category>
		<category><![CDATA[axis2/c]]></category>
		<category><![CDATA[codegen]]></category>
		<category><![CDATA[tool]]></category>
		<category><![CDATA[web services]]></category>
		<category><![CDATA[wsdl2c]]></category>
		<category><![CDATA[resources]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[WSLD2C]]></category>

		<guid isPermaLink="false">http://www.dimuthu.org/?p=18</guid>
		<description><![CDATA[Here are some list of links that you may find useful to start working with Axis2/C ADB Codegen tool. Building Axis2/C Web Services with the help of Axis2/Java Tools (Tutorial) Codegen + ADB Samples (SVN) 20+ Test cases, how different schemas are constructed in ADB/C Helper tools to generate demo codes for Axis2/C ADB generated [...]]]></description>
			<content:encoded><![CDATA[<p>Here are some list of links that you may find useful to start working with Axis2/C ADB Codegen tool.</p>
<ol>
<li><a title="Axis2/C ADB tutorial" href="http://wso2.org/library/3534">Building Axis2/C Web Services with the help of Axis2/Java Tools (Tutorial)</a></li>
<li><a title="Codegen + ADB Samples from SVN" href="http://svn.apache.org/repos/asf/webservices/axis2/trunk/c/samples/codegen/">Codegen + ADB Samples (SVN)</a></li>
<li><a title="Axis2/C ADB Test Cases" href="http://people.apache.org/~dimuthu/leisure/1_dec/wsdl2ctests.tar.bz2">20+ Test cases, how different schemas are constructed in ADB/C</a></li>
<li><a title="Axis2/C codegen helper tool blog" href="http://dimuthuc.wordpress.com/2007/12/01/axis2c-codegen-helper-tools/">Helper tools to generate demo codes for Axis2/C ADB generated code (Blog)<br />
</a></li>
<li><a title="Axis2/C Codegen new features Blog" href="http://dimuthuc.wordpress.com/2007/11/16/axis2c-codegen-new-features/">How Axis2/C ADB Codegen support nillable and minOccurs=0 (Blog)<br />
</a></li>
<li><a title="Blog on Simple Type List Support" href="http://dimuthuc.wordpress.com/2007/12/31/last-jira-for-the-year-2007/">Simple Type List Support (Blog)</a></li>
<li><a title="Overview of Axis2/C ADB" href="http://wsaxc.blogspot.com/2007/06/using-wsdl2c-tool.html">Overview of using Axis2/C ADB (Blog)</a></li>
<li><a title="Little Howto base64 xmime" href="http://www.nabble.com/adb-with-base64Binary-and-xmime.xsd---little-howto-td12900422.html">adb with base64Binary and xmime.xsd &#8211; little howto (Mail)</a></li>
<li><a title="Developer list archieves" href="http://www.nabble.com/forum/Search.jtp?query=wsdl2c+OR+codegen+and+not+jira&amp;sort=date&amp;local=y&amp;forum=227&amp;daterange=0">Latest developers discussion on Axis2/C codegen tool (Mail)</a></li>
<li><a title="Past user list archieves" href="http://www.nabble.com/forum/Search.jtp?query=wsdl2c+or+codegen&amp;sort=date&amp;local=y&amp;forum=228&amp;daterange=0">Past User inquiries on Axis2/C Adb Codegen tool (Mail)</a></li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://www.dimuthu.org/blog/2008/07/21/axis2c-adb-codegen-wsdl2c-tutorial-resources/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
