Thursday, September 24, 2015

Exposing the WSO2 Admin service as REST service

There can be a situation where you want to invoke the wso2 admin services from your external custom management tool. This post is taking a single use case where, making the WSO2 admin service for blocking users as a REST service.

<api name="UserProfileMgtRestServices" context="/UserProfileMgtRestServices">
<resource methods="GET" uri-template="/getUserProfiles/{userId}">
<inSequence>
<payloadFactory media-type="xml">
<format>
<mgt:getUserProfiles xmlns:mgt="http://mgt.profile.user.identity.carbon.wso2.org">
<mgt:username>$1</mgt:username>
</mgt:getUserProfiles>
</format>
<args>
<arg evaluator="xml" expression="get-property('uri.var.userId')"/>
</args>
</payloadFactory>
<property name="messageType" value="application/xml" scope="axis2"/>
<property name="ContentType" value="application/xml" scope="axis2"/>
<header name="Action" value="urn:getUserProfiles"/>
<send>
<endpoint>
<address uri="https://localhost:9443/services/UserProfileMgtService.UserProfileMgtServiceHttpsSoap11Endpoint"
format="soap11"/>
</endpoint>
</send>
</inSequence>
<outSequence>
<property name="messageType" value="application/json" scope="axis2"/>
<property name="ContentType" value="application/json" scope="axis2"/>
<send/>
</outSequence>
</resource>
</api>

Debug Web application in tomcat with Intellij Idea

Tomcat facilitate the debugging capability with JPDA to web app developers and it explained in the official wiki of tomcat. However, document is not giving any explicit document for debugging with  Intellij Idea. Therefore in this blog, Step by Step guide is given to debug the web app hosted in tomcat with Intellij Idea.


Step 1
Export the JPDA port 
LM-SFA-00871979:apache-tomcat-7.0.64 vsivajothy$ export JPDA_ADDRESS="8080"

Step 2
Start the Tomcat server with JPDA

LM-SFA-00871979:apache-tomcat-7.0.64 vsivajothy$ bin/catalina.sh jpda start


Step 3

Create a remort debugging with Intellij Idea with port that given for JPDA.



Step 4
Run the project with 



Thursday, September 17, 2015

Recursively get the property value in synapse

There are certain situation that you may know only the one property name but there might be some other property



<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="RecursiveValueFetch"
transports="https,http"
statistics="disable"
trace="disable"
startOnLoad="true">
<target>
<inSequence>
<property name="Key" value="Location" scope="default" type="STRING"/>
<property name="Location" value="Colombo" scope="default" type="STRING"/>
<log level="custom">
<property name="Value Fetched" expression="get-property(get-property('Key'))"/>
</log>
<respond/>
</inSequence>
</target>
<description/>
</proxy>

Interesting Pattern with single for loop!

Minimum loop required to print below Pattern (can be n*n).

4 4 4 4 4 4 4 
4 3 3 3 3 3 4 
4 3 2 2 2 3 4 
4 3 2 1 2 3 4 
4 3 2 2 2 3 4 
4 3 3 3 3 3 4 
4 4 4 4 4 4 4 

import java.lang.Math;
public class NxNPattern
{
public static void main(String[] args)
{
for (int i = 0, j = 0; i < 49; i++) {
if (i % 7 == 0) {
if (j > 0) System.out.println();
j++;
}
int x = Math.abs(i % 7 - 3);
int y = Math.abs(j - 4);
if (x < y) System.out.print(y + 1);
else System.out.print(x + 1);
}
}
}
view raw NxNPattern.java hosted with ❤ by GitHub