Social Icons

twitterfacebookgoogle pluslinkedinrss feed

Featured Posts

Thursday, February 19, 2015

Remove duplicate XML elements using XSLT

Today I faced an issue where I am receiving a XML message with duplicate elements. So I wanted to remove those duplicate elements using some condition . For that I came up with a XSLT which does that.

My XML input:

<OurGuestsCollection  xmlns="http://ws.wso2.org/dataservice">
   <OurGuests>
      <id>2</id>
      <firstname>Sample</firstname>
      <lastname>Sample</lastname>
      <email>One</email>
      <reg_date>2015-02-18T13:59:43.000+05:30</reg_date>
   </OurGuests>
   <OurGuests>
      <id>3</id>
      <firstname>Sample1</firstname>
      <lastname>Sample1</lastname>
      <email>One</email>
      <reg_date>2015-02-18T14:13:18.000+05:30</reg_date>
   </OurGuests>
   <OurGuests>
      <id>4</id>
      <firstname>Sample1</firstname>
      <lastname>Sample1</lastname>
      <email>One1</email>
      <reg_date>2015-02-18T14:16:21.000+05:30</reg_date>
   </OurGuests>
</OurGuestsCollection>

XSLT:

<xsl:stylesheet version="2.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output omit-xml-declaration="yes" indent="yes"/>

   <xsl:template match="@*|node()">
        <xsl:copy>
            <xsl:apply-templates select="@*|node()"/>
        </xsl:copy>
    </xsl:template>
   
   <xsl:template match="m0:OurGuests" xmlns:m0="http://ws.wso2.org/dataservice" >
        <xsl:if test="not(following::m0:OurGuests[m0:firstname=current()/m0:firstname])">
            <xsl:copy>
                <xsl:apply-templates select="@*|node()"/>
            </xsl:copy>
        </xsl:if>  
    </xsl:template>
</xsl:stylesheet>

XML Output :

<OurGuestsCollection xmlns="http://ws.wso2.org/dataservice">
   <OurGuests>
      <id>2</id>
      <firstname>Sample</firstname>
      <lastname>Sample</lastname>
      <email>One</email>
      <reg_date>2015-02-18T13:59:43.000+05:30</reg_date>
   </OurGuests>
 
   <OurGuests>
      <id>4</id>
      <firstname>Sample1</firstname>
      <lastname>Sample1</lastname>
      <email>One1</email>
      <reg_date>2015-02-18T14:16:21.000+05:30</reg_date>
   </OurGuests>
</OurGuestsCollection>

Tuesday, February 10, 2015

Writing a Create API Executor for API.RXT

One of the use cases of the WSO2 Governance Registry is storing metadata information of different artifacts. In an Organization, there can be different metadata of different artifacts such their REST APIs, SOAP Services etc. In such a scenario you can use API and Service RXT which are available in the WSO2 Governance Registry to store metadata information.

With the use of API metadata which is stored in the WSO2 Governance Registry, you can publish APIs into WSO2 API Manager without accessing the web interface of the API Manager. This API creation is handled through lifecycle executor of the WSO2 Governance Registry. Once lifecycle state of the api publisher is reached, the executor will invoke Publisher REST API of the WSO2 API Manager and create the API. "Integrating with WSO2 API Manager" documentation explains about how to create an API using SOAP service meta data information.

If you want to create an API using the REST API metadata information available in the WSO2 Governance Registry, you have to write your own executor to achieve this. So I have written an example Implementation of the lifecycle executor which can used to create API's in the API Manager.

Saturday, January 17, 2015

WSO2 API Manager - Changing the default token expiration time

In WSO2 API Manager, expiration period of all the access tokens is set to 60 minutes (3600 seconds) by default. However, you can modify the default expiration period value using identity.xml file located in <APIM_HOME>/repository/conf/ directory.

In the identity.xml file you can see separate configurations to modify default expirations of User tokens and application access tokens.

ApplicationAccessTokenDefaultValidityPeriod

If you are planning to modify the validity period of appliccation access token, then you have to modify the default value of the <ApplicationAccessTokenDefaultValidityPeriod> element in identity.xml file. Changing the value of <ApplicationAccessTokenDefaultValidityPeriod> will not affect for existing applications which have alreday generated application tokens. So when you regenerate the application token, it will pick the token validity time from the UI. Therefore, for applications which has already generated tokens, token validity period needs to be changed from the UI as well. However, when you are creating a new application or when you generating the token for the first time, it will pick the token validity period from the identity.xml file.

UserAccessTokenDefaultValidityPeriod

If you are planning to modify the validity period of user token, then you need to update value of the <UserAccessTokenDefaultValidityPeriod> element in identity.xml file. The User token validity period will get updated when user generating and refreshing the token.

Sunday, December 21, 2014

Configurable Governance Artifacts - CURD Operation

Please refer my previous post which explain about Configurable Governance Artifacts in WSO2 Governance Registry.

Once you have added an RXT, it will generate HTML based List and Add view. Also it will be deployed as an Axis2 based service with CRUD operations. For example, when you upload contact.rxt, there will be a Contact Service exposed with CRUD operations. Using provided CRUD operations, external client applications(php, .net,etc) can perform registry operations.

Below is an example CRUD operations provided for Contact RXT which we created in my previous post(RXT Source).
  • addContact - create an artifact in the type Contact .
  • getContact - retrieve an artifact in the type Contact .
  • updateContact - update an artifact in the type Contact .
  • deleteContact - delete an artifact in the type Contact . 
  • getContactArtifactIDs - get all the artifact ID s of artifacts in the type Contact .


To retrieve WSDL of the above service, we need to disable "HideAdminServiceWSDLs" in "carbon.xml" file. After that, you need to restart WSO2 Governance Registry server. Then Contract(WSDL) will be exposed like this: 



https://localhost:9443/services/Contact?wsdl



Please refer Service Client Example for more details:     https://docs.wso2.com/display/Governance460/RXT+Service+Client+Sample