Wednesday, July 5, 2017

Running MSSQL on Mac

 This is a great post on how you can setup mssql in mac with Docker. Once the docker instance is up and running, you can use an sql editor such as DBeaver[2] to execute the sql queries.


[1] https://medium.com/@reverentgeek/sql-server-running-on-a-mac-3efafda48861
[2] http://dbeaver.jkiss.org/download/

Wednesday, June 28, 2017

Common error on securityConfirmation when invoking secured service with .NET client

When invoking a secured SOAP service over a .NET client a very common error as below can be seen.

<Exception> <ExceptionType>System.ServiceModel.Security.MessageSecurityException</ExceptionType> <Message>Signature confirmation is not expected in the security header.</Message> <StackTrace>
 
This is because the secured policy used for the service is sending a SignatureConfirmation header in its security header.

If you secured the service over WSO2 ESB secured proxy , then you only need to remove below tag in blue from your WS-policy for service.

 
 
             <sp:Wss11>
                <wsp:Policy>
                    <sp:MustSupportRefKeyIdentifier/>
                    <sp:MustSupportRefIssuerSerial/>
                    <sp:MustSupportRefThumbprint/>
                    <sp:MustSupportRefEncryptedKey/>
                    <sp:RequireSignatureConfirmation/>
                </wsp:Policy>
            </sp:Wss11> 


Executing sqls for AS400 objects with WSO2 ESB

1. Download and add jt400.jar to ESB_HOME/repository/components/lib.
2. Then you could create the connection pool as below and execute your query with dblookup mediator.


         <dblookup>
            <connection>
               <pool>
                  <password>123456</password>
                  <driver>com.ibm.as400.access.AS400JDBCDriver</driver>
                  <url>jdbc:as400://{IP}/{DB_NAME}</url>
                  <user>userA</user>
               </pool>
            </connection>
            <statement>
               <sql>select id from exp1000 where clId ='A1000000'</sql>
               <result name="custID" column="id"/>
            </statement>
         </dblookup>

Wednesday, March 1, 2017

Add failed endpoint name and address through fault sequence in WSO2 ESB

When generating custom fault sequence messages, one common use case is when you need to send the endpoint name and endpoint address of the failed endpoint back to the client. This can be done by getting the value of two properties which are 'last_endpoint' and 'ENDPOINT_PREFIX'.

However you can't get 'last_endpoint' property value directly as it sends the endpoint object. Therefore you will have to write a class mediator like below and get the value of that endpoint object and set it to a custom property that you have in your fault sequence.

 public boolean mediate(MessageContext mc) {
          // Get 'last_endpoint' property from message context
         AbstractEndpoint failedEP =(AbstractEndpoint)mc.getProperty("last_endpoint");
         // Get name of the failed endpoint
         String failedEPName =  failedEP.getName();
         // Set value to the endpoint name holder in proxy
         mc.setProperty("default_ep", failedEPName);
            return true;
        }

Now you can create your fault sequence like below.

<faultSequence>
         <property name="default_ep" value="default"/>
         <class name="org.test.EPMediator"/>
         <payloadFactory media-type="xml">
            <format>
               <tp:fault xmlns:tp="http://test.com">
                  <tp:message>Error connecting to the backend</tp:message>
                  <tp:description>Endpoint $1 with address $2 failed!</tp:description>
               </tp:fault>
            </format>
            <args>
               <arg evaluator="xml" expression="get-property('default_ep')"/>
               <arg evaluator="xml" expression="get-property('ENDPOINT_PREFIX')"/>
            </args>
         </payloadFactory>
        </send>
</faultSequence>

Wednesday, February 15, 2017

Firefox issue with javascript functions directly called on tags

If you try adding a javascript method on a html link like below, You will run into issues when trying out in firefox.

<a href="javascript:functionA();" />

This is because if this functionA returns some value (true/false) other than undefined, it will be appended to the link as a string value , and will try to be rendered which will redirect you to a blank page. Therefore it is always better to add a js function like below.

<a href="#" onclick="functionA();"/>

Sunday, October 9, 2016

Creating a custom mode and worker files in Ace editor

[1] and [2]  contain a good example on how to create your own worker code , and integrating the worker to the mode with a worker client. The problem I faced was  though this content was added to two new files, syntax validation was not working as the worker file was lacking some initial methods that was coming from ace editor itself. So in order to create your custom worker with all those basic methods include this is what you can follow.

Let us assume your custom language is called 'lang1'.
1. Create mode and worker content files with the naming convention a 'lang1.js' and 'lang1_worker.js.
2. Download ace source code from https://github.com/ajaxorg/ace.
3. In ace source code go to '/lib/ace/mode' folder and place your lang1.js and lang1_worker.js files.
4. Build ace source code with command ' node ./Makefile.dryice.js '.(Check github page for instructions)
5. Once successfully built, go to 'build/src' folder and you can find your mode file as 'lang1.js' and your worker file created as 'worker-nel.js'.

Now you can place these files in your source code location and work with them. Do remember to update the worker name to new one,  when creating the worker client.
var worker = new WorkerClient(["lang1"], "lang1/mode/worker-lang1", "Lang1Module");

[1] https://github.com/antlr/antlr4/blob/master/doc/ace-javascript-target.md
[2] https://github.com/ajaxorg/ace/wiki/Syntax-validation

Thursday, September 15, 2016

XSLT stylesheet template to add a namespace with namespace prefix

If you need to write down a xslt stylesheet ,and you need to add a namespace to a certain element with a namespace prefix , you could write a template like below. In this it will add the namespace to <UserRequest> node.

<xsl:template match="UserRequest">
        <!--Define the namespace with namespace prefix ns0 -->
        <xsl:element name="ns0:{local-name()}" namespace="http://sample.org">
            <!--apply to above selected node-->
            <xsl:apply-templates select="node()|@*">
        </xsl:apply-templates></xsl:element>
    </xsl:template>


If you need to add this namespace to <UserRequest> and its child element , the template match should change to below.

<xsl:template match="UserRequest | UserRequest/*">