Thursday, November 21, 2013

Download WSDL with import Schema files as a zip or gar file from WSO2 Governance Registry.

This sample demonstrate that how to download the WSDL file with  import Schema files as a zip or gar archive.

1. Download the latest WSO2 Governance Registry (version 4.6.0) from here. http://wso2.com/products/governance-registry/

2. You can find the installation instructions in the documentation. http://docs.wso2.org/display/Governance460/Installation

3. Go to the <GREG_HOME>/bin and execute the "ant" command. (This will copy client dependency jars to <GREG_HOME>/repository/lib  directory).

4.  Add the sample WSDL[i] (That WSDL contain import Schema) to  WSO2 Governance Registry Server.

Adding WSDL Doc http://docs.wso2.org/display/Governance460/Managing+WSDLs#ManagingWSDLs-AddingaWSDL

[i]https://svn.wso2.org/repos/wso2/people/ajith/blog/wsdl/WeatherForecastService.wsdl


5. After few second you should see the added WSDL file and Schema  files.



6. Open the WSDLDownload.java class from your IDE and add the following jars to class path (You can find the jars inside <GREG_HOME/repository/lib>)

axiom_1.2.11.wso2v4.jar
axis2_1.6.1.wso2v10.jar
commons-codec_1.4.0.wso2v1.jar
commons-httpclient_3.1.0.wso2v2.jar
httpcore_4.3.0.wso2v1.jar
neethi_2.0.4.wso2v4.jar
org.wso2.carbon.authenticator.stub_4.2.0.jar
org.wso2.carbon.base_4.2.0.jar
org.wso2.carbon.core.common_4.2.0.jar
org.wso2.carbon.governance.api_4.2.1.jar
org.wso2.carbon.governance.client-4.2.0.jar
org.wso2.carbon.logging_4.2.0.jar
org.wso2.carbon.registry.admin.api_4.2.0.jar
org.wso2.carbon.registry.api_4.2.0.jar
org.wso2.carbon.registry.common_4.2.1.jar
org.wso2.carbon.registry.core_4.2.0.jar
org.wso2.carbon.registry.indexing.stub-4.2.0.jar
org.wso2.carbon.registry.ws.client_4.2.0.jar
org.wso2.carbon.registry.ws.stub_4.2.0.jar
org.wso2.carbon.user.api_4.2.0.jar
org.wso2.carbon.user.core_4.2.0.jar
org.wso2.carbon.utils_4.2.0.jar
org.wso2.securevault_1.0.0.wso2v2.jar
woden_1.0.0.M8-wso2v1.jar
wsdl4j_1.6.2.wso2v4.jar
XmlSchema_1.4.7.wso2v2.jar


You can find the source code here https://github.com/ajithnv/blog_resources/blob/master/WSDL-Download/src/org/wso2/registry/wsdl/test/WSDLDownload.java


7.  Change the value of CARBON_HOME,serverURL and zipFilesLocation in WSDLDownload.java according to your test environment.

8.  Execute the WSDLDownload.java. If it is success, you should see the following type log.

WSDL archive created at : /home/ajith/WeatherForecastService.zip

9.  If you extract the WeatherForecastService.zip file you should see the Schema files are located against the Namespace paths.



9. You can consider the created zip file as a "Governance Archive". Read more here. http://docs.wso2.org/display/Governance460/Creating+a+Governance+Archive

10. Delete the WSDL file and Schema files from Governance Registry admin UI.



11.  Upload the WeatherForecastService.zip to Governance Registry.


12. Check the back end logs and  you should see the following log messages.

INFO {org.wso2.carbon.registry.extensions.handlers.ZipWSDLMediaTypeHandler} -  Total Number of Files Uploaded: 6
INFO {org.wso2.carbon.registry.extensions.handlers.ZipWSDLMediaTypeHandler} -  Total Number of Files Failed to Upload: 0
INFO {org.wso2.carbon.registry.extensions.handlers.ZipWSDLMediaTypeHandler} -  Completed uploading files from archive file



13. After few seconds you should see the uploaded WSDL and Schema files from Governance Registry Admin UI as well.


14. If you want to download the archive file as a .gar file, change the value of the "compressMethod" to ".gar" in WSDLDownload.java.

Friday, November 15, 2013

[Jmeter] Java Request extension for Governance/Registry API performance.


First  download the Jmeter and WSO2 Governance Registry from the following download links.

[1]http://jmeter.apache.org/download_jmeter.cgi (version 2.1.0).
[2]http://wso2.com/products/governance-registry/ (version 4.6.0).

1) Now you need to write the your governance/registry API client extending the AbstractJavaSamplerClient provided by Jmeter.

How to add dependency jars to class path:

* Unzip the wso2greg-4.6.0.zip and run the ant inside the bin directory, it will copy the  jars to repository/lib.

You need to copy the following jars list to IDE class path from <GREG_HOME/repository/lib>.

axiom_1.2.11.wso2v4.jar
axis2_1.6.1.wso2v10.jar
commons-codec_1.4.0.wso2v1.jar
commons-httpclient_3.1.0.wso2v2.jar
httpcore_4.3.0.wso2v1.jar
neethi_2.0.4.wso2v4.jar
org.wso2.carbon.authenticator.stub_4.2.0.jar
org.wso2.carbon.base_4.2.0.jar
org.wso2.carbon.core.common_4.2.0.jar
org.wso2.carbon.governance.api_4.2.1.jar
org.wso2.carbon.governance.client-4.2.0.jar
org.wso2.carbon.logging_4.2.0.jar
org.wso2.carbon.registry.admin.api_4.2.0.jar
org.wso2.carbon.registry.api_4.2.0.jar
org.wso2.carbon.registry.common_4.2.1.jar
org.wso2.carbon.registry.core_4.2.0.jar
org.wso2.carbon.registry.indexing.stub-4.2.0.jar
org.wso2.carbon.registry.ws.client_4.2.0.jar
org.wso2.carbon.registry.ws.stub_4.2.0.jar
org.wso2.carbon.user.api_4.2.0.jar
org.wso2.carbon.user.core_4.2.0.jar
org.wso2.carbon.utils_4.2.0.jar
org.wso2.securevault_1.0.0.wso2v2.jar
woden_1.0.0.M8-wso2v1.jar
wsdl4j_1.6.2.wso2v4.jar
XmlSchema_1.4.7.wso2v2.jar

* Unzip the apache-jmeter-2.9.zip and add the ApacheJMeter_java.jar,  ApacheJMeter_core.jar to the class path.

You need to implement 4 methods based on your use case.

i) public Arguments getDefaultParameters() {..}
  - This method can be used to initialize the parameters providing through the Jmeter UI.

ii) public void setupTest(JavaSamplerContext context) {..}
  -This is used to initialize parameters before executing the actual tests.

iii) public SampleResult runTest(JavaSamplerContext javaSamplerContext) {...}
  - This is used to implement the test.

iv) public void teardownTest(JavaSamplerContext context) {..}
  -If there are things to do after the test.

In my sample I’m going to use the governance API to get the endpoint which is stored in Governance Registry.

package org.performance.test460;

import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.axis2.context.ConfigurationContext;
import org.apache.axis2.context.ConfigurationContextFactory;
import org.apache.jmeter.config.Arguments;
import org.apache.jmeter.protocol.java.sampler.AbstractJavaSamplerClient;
import org.apache.jmeter.protocol.java.sampler.JavaSamplerContext;
import org.apache.jmeter.samplers.SampleResult;
import org.wso2.carbon.base.ServerConfiguration;
import org.wso2.carbon.governance.api.generic.GenericArtifactManager;
import org.wso2.carbon.governance.api.generic.dataobjects.GenericArtifact;
import org.wso2.carbon.governance.api.util.GovernanceUtils;
import org.wso2.carbon.governance.client.WSRegistrySearchClient;
import org.wso2.carbon.registry.core.Registry;
import org.wso2.carbon.registry.core.pagination.PaginationContext;
import org.wso2.carbon.registry.core.session.UserRegistry;
import org.wso2.carbon.registry.ws.client.registry.WSRegistryServiceClient;

public class WSO2Registry460Client extends AbstractJavaSamplerClient {

    private static class DataHolder {
        private String cookie = null;
        private Registry gov = null;
        private WSRegistrySearchClient wsRegistrySearchClient = null;
        private GenericArtifactManager artifactManager = null;

        public String getCookie() {
            return cookie;
        }

        public Registry getGov() {
            return gov;
        }

        public WSRegistrySearchClient getWsRegistrySearchClient() {
            return wsRegistrySearchClient;
        }

        private void setCookie(String cookie) {
            this.cookie = cookie;
        }

        private void setGov(Registry gov) {
            this.gov = gov;
        }

        private void setWsRegistrySearchClient(WSRegistrySearchClient wsRegistrySearchClient) {
            this.wsRegistrySearchClient = wsRegistrySearchClient;
        }

        private GenericArtifactManager getArtifactManager() {
            return artifactManager;
        }

        private void setArtifactManager(GenericArtifactManager artifactManager) {
            this.artifactManager = artifactManager;
        }
    }

    public static ConfigurationContext configContext = null;
    private static String CARBON_HOME = "";
    private static String axis2Repo = "";
    private static String axis2Conf = ServerConfiguration.getInstance()
            .getFirstProperty("Axis2Config.clientAxis2XmlLocation");
    private static String username = "";
    private static String password = "";
    private static String serverURL = "";
    private static String artifact_key = "";
    private static String artifact_name = "";

    private static ThreadLocal dataHolder = new ThreadLocal() {
        protected DataHolder initialValue() {
            return new DataHolder();
        }
    };

    private static void initialize() throws Exception {
        System.setProperty("javax.net.ssl.trustStore", CARBON_HOME
                + File.separator + "repository" + File.separator + "resources"
                + File.separator + "security" + File.separator
                + "wso2carbon.jks");
        System.setProperty("javax.net.ssl.trustStorePassword", "wso2carbon");
        System.setProperty("javax.net.ssl.trustStoreType", "JKS");
        System.setProperty("carbon.repo.write.mode", "true");
        if (configContext != null) {
            configContext = ConfigurationContextFactory
                    .createConfigurationContextFromFileSystem(axis2Repo,
                            axis2Conf);
        }
        DataHolder holder = dataHolder.get();
        holder.setWsRegistrySearchClient(new WSRegistrySearchClient());
        // authenticate user.
        holder.setCookie(holder.getWsRegistrySearchClient().authenticate(configContext, serverURL, username,
                password));
        // initialize registry.
        Registry registry = new WSRegistryServiceClient(serverURL, holder.getCookie());
        // initialize governance registry
        holder.setGov(GovernanceUtils.getGovernanceUserRegistry(registry,
                username));
        // Should be load the governance artifact.
        GovernanceUtils.loadGovernanceArtifacts((UserRegistry) holder.getGov());
        PaginationContext.init(0, 1, "", "", Integer.MAX_VALUE);
        holder.getWsRegistrySearchClient().init(holder.getCookie(), serverURL, configContext);
        holder.setArtifactManager(new GenericArtifactManager(holder.getGov(), artifact_key));
    }

    @Override
    public SampleResult runTest(JavaSamplerContext javaSamplerContext) {
        SampleResult result = new SampleResult();
        boolean success = true;
        result.sampleStart();
        result.setDataType(SampleResult.TEXT);

        try {
            DataHolder holder = dataHolder.get();
            Map> listMap = new HashMap>();
            // Create the search attribute map
            listMap.put("overview_name", new ArrayList() {
                {
                    add(artifact_name);
                }
            });
            // Find the results.

            GenericArtifact[] genericArtifacts = holder.getArtifactManager().findGenericArtifacts(listMap);

            String productionEp = null;
            for (GenericArtifact artifact : genericArtifacts) {
                String[] endPoint = artifact.getAttributes("endpoints_entry");

                for (String ep : endPoint) {
                    if (ep.startsWith("Prod:")) {
                        productionEp = ep.split("Prod:")[1];
                    }
                }
            }

            if (productionEp != null) {
                result.setResponseMessage("Succesfully picked the production endpoint");
                result.setResponseData(productionEp);
                result.setSuccessful(true);
            }

        } catch (Exception e) {
            result.setResponseMessage("Failed picked the production endpoint");
            result.setSuccessful(false);
            e.printStackTrace();
        } finally {
            PaginationContext.destroy();
        }

        result.setSuccessful(success);
        result.sampleEnd();
        return result;
    }

    @Override
    public Arguments getDefaultParameters() {
        Arguments args = new Arguments();
        args.addArgument("CARBON_HOME", "");
        args.addArgument("serverURL", "");
        args.addArgument("username", "");
        args.addArgument("password", "");
        args.addArgument("artifact_key", "");
        args.addArgument("artifact_name", "");
        return args;
    }

    @Override
    public void setupTest(JavaSamplerContext context) {

        CARBON_HOME = context.getParameter("CARBON_HOME");
        serverURL = context.getParameter("serverURL");
        username = context.getParameter("username");
        password = context.getParameter("password");
        axis2Repo = CARBON_HOME + File.separator + "repository"
                + File.separator + "deployment" + File.separator + "client";
        artifact_key = context.getParameter("artifact_key");
        artifact_name = context.getParameter("artifact_name");

        try {
            initialize();
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    @Override
    public void teardownTest(JavaSamplerContext context) {

    }
}


2. Build the jar (org.performance.test460.jar) file and drop it to apache-jmeter-2.9/lib/ext.

3. Copy all the jars in <GREG_HOME>/repository/lib to , apache-jmeter-2.9/lib.

4. Start the WSO2 Governance Registry server.

5. Create a service as mentioned in the following image.

6. Start the JMeter.

i) Right click on the “Test Plan” → “Threads” → “Thread Group”.

ii)Right click on the “Thread Group” → “Sampler” → “Java Request”

iii) Select the class name. (org.performance.test460.WSO2Registry460Client)

iv) Fill the input values as shown in the following image.


v) Right click on the “Thread Group” → “Listeners” → “Summary Report”

vi ) Right click on the “Thread Group” → “Listeners” → “View Results Tree”


7. Click on the “Start” button to send a request to validate the test.



8 Load test/results.

Eg : For 100 concurrency , 10 minutes.




For 200 concurrency, 10 minutes,

Tuesday, October 8, 2013

EDI to XML using WSO2 ESB - Smooks mediator.

1. What is an EDI file ? 

EDI (Electronic Data Interchange) is a stand way of sharing the business data like orders, invoice, tax, cheques ..etc between business applications.

X12 and Un/EDIFACT are the most commonly used EDI standards.

2. Why we need EDI than paper documents ?

i. Less man hours required to process.
ii. Less user errors (data input and process by computer applications)
iii. Fast business flows.

3. Why we need to transform EDI to XML ?

I) Some business applications can't understand  the EDI formats when they are integrate with the other system.

II) Need  more processing/routing ..etc based on the attributes of the EDI, in that case XML is more readable and widely use standard.

Simple use case using WSO2 ESB.

i. Drop order type EDI file to VFS input directory.
ii. ESB pick the file and send to smooks mediator.
iii. Smooks mediator transform the EDI file to XML format.
iv. Base on the message type sending file to correct endpoints.

For this we need a smooks mapping file for order type EDI file.

You can download the EDI mapping model jar from [1]

[1]http://mvnrepository.com/artifact/org.milyn.edi.unedifact/d97b-mapping/1.4

You can find the ORDER.xml and __modelset_definitions.xml inside the jar.

Steps to setup.

1. Download the latest WSO2 ESB version from product download site. http://wso2.com/products/enterprise-service-bus/

2. Enable the VFS transport in axis2.xml file. - Un-comment the following two lines.

<transportReceiver name="vfs" class="org.apache.synapse.transport.vfs.VFSTransportListener"/>
<ransportSender name="vfs" class="org.apache.synapse.transport.vfs.VFSTransportSender"/>

3.Copy the content of ORDER.xml to <ESB_HOME>/repository/samples/resources/smooks/xml-mapping-order.xml .

4. Copy  __modelset_definitions.xml to  <ESB_HOME>/repository/samples/resources/smooks.

WSO2 developer studio is our development platform which is going to use for creating the ESB artifacts. http://wso2.com/more-downloads/developer-studio/

5. Create a ESB config project and draw a simple mediation flow.

6. Create a new local entry to add the smooks configuration file.

<localEntry xmlns="http://ws.apache.org/ns/synapse" key="smooks-config">
   <smooks-resource-list xmlns="http://www.milyn.org/xsd/smooks-1.1.xsd"
                         xmlns:unedifact="http://www.milyn.org/xsd/smooks/unedifact-1.4.xsd">
      <resource-config selector="org.xml.sax.driver">
         <resource>org.milyn.smooks.edi.EDIReader</resource>
         <param name="mapping-model">repository/samples/resources/smooks/xml-mapping-order.xml</param>
      </resource-config>
   </smooks-resource-list>
   <description/>
</localEntry>

7. Create a ProxyService  add  mediation flow.

<proxy xmlns="http://ws.apache.org/ns/synapse" name="EDITransformProxy" transports="http https vfs" startOnLoad="true" trace="disable">
    <target>
        <inSequence>
            <smooks config-key="smooks-config">
                <input type="text"/>
                <output type="xml"/>
            </smooks>
            <log level="full"/>
            <property xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" name="MESSAGE_TYPE" expression="name(//soapenv:Body/*)" scope="default" type="STRING"/>
            <switch source="/default/xpath">
                <case regex="ORDERS">
                    <send>
                        <endpoint>
                            <address uri="http://www.example.org/service/order"/>
                        </endpoint>
                    </send>
                </case>
                <case regex="INVOICE">
                    <send>
                        <endpoint>
                            <address uri="http://www.example.org/service/invoice"/>
                        </endpoint>
                    </send>
                </case>
                <default>
                    <send>
                        <endpoint>
                            <address uri="http://www.example.org/default"/>
                        </endpoint>
                    </send>
                </default>
            </switch>
        </inSequence>
        <outSequence/>
        <faultSequence/>
    </target>
    <parameter name="transport.vfs.ActionAfterProcess">MOVE</parameter>
    <parameter name="transport.PollInterval">5</parameter>
    <parameter name="transport.vfs.MoveAfterProcess">C:\wso2\original</parameter>
    <parameter name="transport.vfs.FileURI">C:\wso2\in</parameter>
    <parameter name="transport.vfs.MoveAfterFailure">C:\wso2\failed</parameter>
    <parameter name="transport.vfs.FileNamePattern">.*.edi</parameter>
    <parameter name="transport.vfs.ContentType">text/plain</parameter>
    <parameter name="transport.vfs.ActionAfterFailure">MOVE</parameter>
</proxy>


8. Add new Carbon Application project and include the ESB-Cofig artifact.
9. Build your Capp project.
10. Start the ESB server and Deploy the Capp file.
11. Create sample file test.edi using the following content, and copy that file to VFS “in” directory.

BGM+380+342459+9'
DTM+3:20060515:102'
RFF+ON:521052'
NAD+BY+792820524::16++CUMMINS MID-RANGE ENGINE PLANT'
NAD+SE+005435656::16++GENERAL WIDGET COMPANY'
CUX+1:USD'
LIN+1++157870:IN'
IMD+F++:::WIDGET'
QTY+47:1020:EA'
ALI+US'
MOA+203:1202.58'
PRI+INV:1.179'
LIN+2++157871:IN'
IMD+F++:::DIFFERENT WIDGET'
QTY+47:20:EA'
ALI+JP'
MOA+203:410'
PRI+INV:20.5'
UNS+S'
MOA+39:2137.58'
ALC+C+ABG'
MOA+8:525'

12. Out put in console.

<ORDERS>
    <Beginning_of_message>
        <DOCUMENT_MESSAGE_NAME>
            <Document_name_code>380</Document_name_code>
        </DOCUMENT_MESSAGE_NAME>
        <DOCUMENT_MESSAGE_IDENTIFICATION>
            <Document_identifier>342459</Document_identifier>
        </DOCUMENT_MESSAGE_IDENTIFICATION>
        <Message_function_code>9</Message_function_code>
    </Beginning_of_message>
    <Date_time_period>
        <DATE_TIME_PERIOD>
            <Date_or_time_or_period_function_code_qualifier>3</Date_or_time_or_period_function_code_qualifier>
            <Date_or_time_or_period_text>20060515</Date_or_time_or_period_text>
            <Date_or_time_or_period_format_code>102</Date_or_time_or_period_format_code>
        </DATE_TIME_PERIOD>
    </Date_time_period>
    <Segment_group_1>
        <Reference>
            <REFERENCE>
                <Reference_code_qualifier>ON</Reference_code_qualifier>
                <Reference_identifier>521052</Reference_identifier>
            </REFERENCE>
        </Reference>
    </Segment_group_1>
    <Segment_group_2>
        <Name_and_address>
            <Party_function_code_qualifier>BY</Party_function_code_qualifier>
            <PARTY_IDENTIFICATION_DETAILS>
                <Party_identifier>792820524</Party_identifier>
                <Code_list_identification_code/>
                <Code_list_responsible_agency_code>16</Code_list_responsible_agency_code>
            </PARTY_IDENTIFICATION_DETAILS>
            <NAME_AND_ADDRESS>
            </NAME_AND_ADDRESS>
            <PARTY_NAME>
                <Party_name_-_-1>CUMMINS MID-RANGE ENGINE PLANT</Party_name_-_-1>
            </PARTY_NAME>
        </Name_and_address>
    </Segment_group_2>
    <Segment_group_2>
        <Name_and_address>
            <Party_function_code_qualifier>SE</Party_function_code_qualifier>
            <PARTY_IDENTIFICATION_DETAILS>
                <Party_identifier>005435656</Party_identifier>
                <Code_list_identification_code/>
                <Code_list_responsible_agency_code>16</Code_list_responsible_agency_code>
            </PARTY_IDENTIFICATION_DETAILS>
            <NAME_AND_ADDRESS>
            </NAME_AND_ADDRESS>
            <PARTY_NAME>
                <Party_name_-_-1>GENERAL WIDGET COMPANY</Party_name_-_-1>
            </PARTY_NAME>
        </Name_and_address>
    </Segment_group_2>
    <Segment_group_7>
        <Currencies>
            <CURRENCY_DETAILS_-_-1>
                <Currency_usage_code_qualifier>1</Currency_usage_code_qualifier>
                <Currency_identification_code>USD</Currency_identification_code>
            </CURRENCY_DETAILS_-_-1>
        </Currencies>
    </Segment_group_7>
    <Segment_group_28>
        <Line_item>
            <Line_item_identifier>1</Line_item_identifier>
            <Action_request_notification_description_code/>
            <ITEM_NUMBER_IDENTIFICATION>
                <Item_identifier>157870</Item_identifier>
                <Item_type_identification_code>IN</Item_type_identification_code>
            </ITEM_NUMBER_IDENTIFICATION>
        </Line_item>
        <Item_description>
            <Description_format_code>F</Description_format_code>
            <ITEM_CHARACTERISTIC>
            </ITEM_CHARACTERISTIC>
            <ITEM_DESCRIPTION>
                <Item_description_code/>
                <Code_list_identification_code/>
                <Code_list_responsible_agency_code/>
                <Item_description_-_-1>WIDGET</Item_description_-_-1>
            </ITEM_DESCRIPTION>
        </Item_description>
        <Quantity>
            <QUANTITY_DETAILS>
                <Quantity_type_code_qualifier>47</Quantity_type_code_qualifier>
                <Quantity>1020</Quantity>
                <Measurement_unit_code>EA</Measurement_unit_code>
            </QUANTITY_DETAILS>
        </Quantity>
        <Additional_information>
            <Country_of_origin_name_code>US</Country_of_origin_name_code>
        </Additional_information>
        <Monetary_amount>
            <MONETARY_AMOUNT>
                <Monetary_amount_type_code_qualifier>203</Monetary_amount_type_code_qualifier>
                <Monetary_amount>1202.58</Monetary_amount>
            </MONETARY_AMOUNT>
        </Monetary_amount>
        <Segment_group_32>
            <Price_details>
                <PRICE_INFORMATION>
                    <Price_code_qualifier>INV</Price_code_qualifier>
                    <Price_amount>1.179</Price_amount>
                </PRICE_INFORMATION>
            </Price_details>
        </Segment_group_32>
    </Segment_group_28>
    <Segment_group_28>
        <Line_item>
            <Line_item_identifier>2</Line_item_identifier>
            <Action_request_notification_description_code/>
            <ITEM_NUMBER_IDENTIFICATION>
                <Item_identifier>157871</Item_identifier>
                <Item_type_identification_code>IN</Item_type_identification_code>
            </ITEM_NUMBER_IDENTIFICATION>
        </Line_item>
        <Item_description>
            <Description_format_code>F</Description_format_code>
            <ITEM_CHARACTERISTIC>
            </ITEM_CHARACTERISTIC>
            <ITEM_DESCRIPTION>
                <Item_description_code/>
                <Code_list_identification_code/>
                <Code_list_responsible_agency_code/>
                <Item_description_-_-1>DIFFERENT WIDGET</Item_description_-_-1>
            </ITEM_DESCRIPTION>
        </Item_description>
        <Quantity>
            <QUANTITY_DETAILS>
                <Quantity_type_code_qualifier>47</Quantity_type_code_qualifier>
                <Quantity>20</Quantity>
                <Measurement_unit_code>EA</Measurement_unit_code>
            </QUANTITY_DETAILS>
        </Quantity>
        <Additional_information>
            <Country_of_origin_name_code>JP</Country_of_origin_name_code>
        </Additional_information>
        <Monetary_amount>
            <MONETARY_AMOUNT>
                <Monetary_amount_type_code_qualifier>203</Monetary_amount_type_code_qualifier>
                <Monetary_amount>410</Monetary_amount>
            </MONETARY_AMOUNT>
        </Monetary_amount>
        <Segment_group_32>
            <Price_details>
                <PRICE_INFORMATION>
                    <Price_code_qualifier>INV</Price_code_qualifier>
                    <Price_amount>20.5</Price_amount>
                </PRICE_INFORMATION>
            </Price_details>
        </Segment_group_32>
    </Segment_group_28>
    <Section_control>
        <SECTION_IDENTIFICATION>S</SECTION_IDENTIFICATION>
    </Section_control>
    <Monetary_amount>
        <MONETARY_AMOUNT>
            <Monetary_amount_type_code_qualifier>39</Monetary_amount_type_code_qualifier>
            <Monetary_amount>2137.58</Monetary_amount>
        </MONETARY_AMOUNT>
    </Monetary_amount>
    <Segment_group_60>
        <Allowance_or_charge>
            <Allowance_or_charge_code_qualifier>C</Allowance_or_charge_code_qualifier>
            <ALLOWANCE_CHARGE_INFORMATION>
                <Allowance_or_charge_identifier>ABG</Allowance_or_charge_identifier>
            </ALLOWANCE_CHARGE_INFORMATION>
        </Allowance_or_charge>
        <Monetary_amount>
            <MONETARY_AMOUNT>
                <Monetary_amount_type_code_qualifier>8</Monetary_amount_type_code_qualifier>
                <Monetary_amount>525</Monetary_amount>
            </MONETARY_AMOUNT>
        </Monetary_amount>
    </Segment_group_60>
</ORDERS>


Friday, June 28, 2013

Exclude transitive dependency while building(maven) a WAR file.

Sometime you want to copy ONLY the dependency jar in WEB-INF/lib directory of the WAR file.
Because service hosting product already provided the transitive dependencies.
You can achieve this requirement using the proper exclusions with the dependency.

Let's say your project has following dependency,

<dependency>
            <groupId>org.wso2.carbon</groupId>
            <artifactId>org.wso2.carbon.registry.common</artifactId>
            <version>4.2.0-SNAPSHOT</version>      
</dependency>

1. First run the mvn dependency:tree command to get the dependency tree of your project. After that copy the output  to some text file and search above jar name(org.wso2.carbon.registry.common).

Let's say you have found following sub tree in the dependency tree of your project .

+- org.wso2.carbon:org.wso2.carbon.registry.common:jar:4.2.0-SNAPSHOT:provided
  +- commons-beanutils.wso2:commons-beanutils:jar:1.8.0.wso2v1:provided
  \- org.wso2.carbon:org.wso2.carbon.feature.mgt.services:jar:4.2.0-SNAPSHOT:provided
     +- org.wso2.carbon:org.wso2.carbon.feature.mgt.core:jar:4.2.0-SNAPSHOT:provided
     +- org.eclipse.equinox:org.eclipse.equinox.p2.artifact.repository:jar:1.1.100.v20110519:provided
     |  +- org.eclipse.equinox:org.eclipse.equinox.p2.director:jar:2.1.0.v20110504-1715:provided
     |  +- org.eclipse.equinox:org.eclipse.equinox.p2.metadata.repository:jar:1.2.0.v20110511-1359:provided
     |  \- org.eclipse.equinox:org.eclipse.equinox.simpleconfigurator:jar:1.0.301.v20120828-033635:provided
     +- org.eclipse.equinox:org.eclipse.equinox.p2.core:jar:2.1.0.v20110502-1955:provided
     +- org.eclipse.equinox:org.eclipse.equinox.p2.engine:jar:2.1.0.v20110511:provided
     +- org.eclipse.equinox:org.eclipse.equinox.p2.metadata:jar:2.1.0.v20110510:provided
     +- org.eclipse.equinox:org.eclipse.equinox.p2.repository:jar:2.1.0.v20110601:provided
     \- org.eclipse.equinox:org.eclipse.equinox.common:jar:3.6.100.v20120522-1841:provided

2. Now, if you want to prevent packaging its transitive dependency you should update the above dependency as follow.

<dependency>
            <groupId>org.wso2.carbon</groupId>
            <artifactId>org.wso2.carbon.registry.common</artifactId>
            <version>4.2.0-SNAPSHOT</version> 
           <exclusions>
                  <exclusion>
                      <groupId>commons-beanutils.wso2</groupId>
                      <artifactId>commons-beanutils</artifactId>
                  </exclusion>

          </exclusions>     
</dependency>

OR , you can  define new dependency with the scope as provided.

<dependency>
            <groupId>commons-beanutils.wso2</groupId>
            <artifactId>commons-beanutils</artifactId>
            <version>1.8.0.wso2v1</version> 
            <scope>provided</scope>               
</dependency>

Wednesday, June 26, 2013

Export data source configs from one Application Server node and import to another.


Here, we used registry checkin client tool to export data source configurations from WSO2 Application Server  registry and import to another Application Server instance.

i) When you create a data source from wizard, it will be stored in registry as a XML resource.

/_system/config/repository/components/org.wso2.carbon.ndatasource



ii) Copy checkin-client.sh or checkin-client.bat to AS_HOME/bin.

ii) Copy the checkin-client-4.5.3.jar to the AS_HOME/repository/lib.

iii) Start the Application server and go the bin directory and execute the following command to dump the data source configurations.

sh checkin-client.sh co https://localhost:9443/registry/_system/config/repository/components/org.wso2.carbon.ndatasource -u admin -p admin -f ds.dump

Now all the data source configurations will dump to ds.dump file (it is in the bin directory).

iv) Execute the following command to import the data source configurations to next Application Server (9444).

sh checkin-client.sh ci https://localhost:9444/registry/_system/config/repository/components/org.wso2.carbon.ndatasource -u admin -p admin -f ds.dump file

v) Restart the server.
 
Resource location : https://svn.wso2.org/repos/wso2/people/ajith/blog/checkin-client/

Documentation : http://docs.wso2.org/wiki/display/Governance460/Check-in+Client
 

Wednesday, March 27, 2013

How to invoke registry inside the web application.


You can initialize the registry inside the web application.

  // Obtain the reference to the registry from the CarbonContext
    CarbonContext cCtx = CarbonContext.getCurrentContext();
    Registry registry = cCtx.getRegistry(RegistryType.SYSTEM_CONFIGURATION);

You can find the sample web application at [1].

[1]https://svn.wso2.org/repos/wso2/carbon/platform/branches/4.0.0/products/as/5.0.1/modules/samples/common/webapp/src/main/resources/carbon/registry/index.jsp


Wednesday, February 13, 2013

How to invoke custom artifacts using Governance Registry API.

Configurable Governance Artifacts(RXT) is one of the powerful extension point is supported by WSO2 Governance Registry. You can build your own custom artifacts using the functionality of RXT. And also G-Reg is providing a Governance API to manage those artifacts.

How to run the sample
================

1. Add new sample_application.rxt to Registry.

   Go to the Extensions > Configure > Artifact Types
   Click on "Add new Artifact".
   Copy the content of the sample_application.rxt and save.

2. Sign out and sign in, now you should be able to view the new artifact type called "Enterprise Application".

3. Go to the wso2greg-4.5.3/bin and run the ant command.
   (Now all the required jars, which is used to invoke the client will be placed in wso2greg-4.5.3/repository/lib)

4. Create a java project using the SampleWSRegistryClient.java.

5. Point the class path to wso2greg-4.5.3/repository/lib.

6. Run the client code. (You have to change the some values of the parameters (CARBON_HOME,serverURL,username,password)
   in code according to your environment).

import java.io.File;  
  
import org.apache.axis2.context.ConfigurationContext;  
import org.apache.axis2.context.ConfigurationContextFactory;  
import org.wso2.carbon.base.ServerConfiguration;  
import org.wso2.carbon.governance.api.exception.GovernanceException;  
import org.wso2.carbon.governance.api.generic.GenericArtifactFilter;  
import org.wso2.carbon.governance.api.generic.GenericArtifactManager;  
import org.wso2.carbon.governance.api.generic.dataobjects.GenericArtifact;  
import org.wso2.carbon.governance.api.util.GovernanceUtils;  
import org.wso2.carbon.registry.core.Registry;  
import org.wso2.carbon.registry.core.session.UserRegistry;  
import org.wso2.carbon.registry.ws.client.registry.WSRegistryServiceClient;  
  
import javax.xml.namespace.QName;  
  
public class SampleWSRegistryClient {  
  
    private static ConfigurationContext configContext = null;  
  
    private static final String CARBON_HOME = "/home/ajith/products/wso2greg-4.5.3";  
    private static final String axis2Repo = CARBON_HOME + File.separator + "repository" +  
            File.separator + "deployment" + File.separator + "client";  
    private static final String axis2Conf =  
            ServerConfiguration.getInstance().getFirstProperty("Axis2Config.clientAxis2XmlLocation");  
    private static final String username = "admin";  
    private static final String password = "admin";  
    private static final String serverURL = "https://localhost:9443/services/";  
  
    private static WSRegistryServiceClient initialize() throws Exception {  
  
        System.setProperty("javax.net.ssl.trustStore", CARBON_HOME + File.separator + "repository" +  
                File.separator + "resources" + File.separator + "security" + File.separator +  
                "wso2carbon.jks");  
        System.setProperty("javax.net.ssl.trustStorePassword", "wso2carbon");  
        System.setProperty("javax.net.ssl.trustStoreType", "JKS");  
        System.setProperty("carbon.repo.write.mode", "true");  
        configContext = ConfigurationContextFactory.createConfigurationContextFromFileSystem(  
                axis2Repo, axis2Conf);  
        return new WSRegistryServiceClient(serverURL, username, password, configContext);  
  
    }  
  
    public static void main(String[] args) throws Exception {  
  
        Registry registry = initialize();  
        //We should use the UserRegisty to initialize the GenericArtifactManager  
        registry = GovernanceUtils.getGovernanceUserRegistry(registry, "admin");  
        //You should load governance Artifacts  
        GovernanceUtils.loadGovernanceArtifacts((UserRegistry) registry);  
        //"applications" is the short name of the RXT  
        GenericArtifactManager artifactManager = new GenericArtifactManager(registry, "applications");  
  
        // add new artifact  
        GenericArtifact artifact = artifactManager.newGovernanceArtifact(new QName("http://www.example.com","app2"));  
        artifact.setAttribute("overview_version","3.7.8");  
        artifactManager.addGenericArtifact(artifact);  
  
        //Get all "application" artifacts and it's attributes  
        GenericArtifact[] applicationArtifacts = artifactManager.getAllGenericArtifacts();  
        for(GenericArtifact artifact1 : applicationArtifacts){  
           String[] attributes = artifact1.getAttributeKeys();  
            for(String attribute : attributes){  
                System.out.println("Artifact attributes --- > " +attribute);  
  
                System.out.println(attribute + " : " + artifact1.getAttribute(attribute));  
  
            }  
        }  
  
        //Search for Application using attributes.  
        GenericArtifact[] filteredArtifacts = artifactManager.findGenericArtifacts(  
                new GenericArtifactFilter() {  
                    public boolean matches(GenericArtifact artifact) throws GovernanceException {  
                        String attributeVal = artifact.getAttribute("overview_name");  
                        return (attributeVal != null && attributeVal.equals("app2"));  
                    }  
                });  
        //Print some search values  
        for(GenericArtifact filter : filteredArtifacts){  
            System.out.println( "Name : " +  
                    filter.getAttribute("overview_name") +", Version " +filter.getAttribute("overview_version")+  
                    " Id :" +filter.getId());  
        }  
    }  
}
The attribute name of the custom artifact is produce like this.

tableName_fieldName

How to make login(user name) case insensitive in WSO2 Governance Registry.


WSO2 Governance Registry is shipped with the JDBC based user store manager. The default queries that are used in user management bundle(to handle the user name) is case sensitive. You can convert those queries to case insensitive manner and override the default queries .

To make the user name case insensitive:

Environments : G-Reg 4.5.3, JDK 1.6, MySql(or Oracle)

1) Download the latest G-Reg (4.5.3) and configure with MySQL or Oracle database.

2) Open the user-mgt.xml file, which is reside the wso2greg-4.5.3/repository/conf

2) Add the following two queries in user-mgt.xml  as properties  in <UserStoreManager>  configuration.

<Property name="UserFilterSQL">SELECT UM_USER_NAME FROM UM_USER WHERE UPPER(UM_USER_NAME) LIKE UPPER(?) AND UM_TENANT_ID=? ORDER BY UM_USER_NAME</Property> 

<Property name="UserRoleSQL">SELECT UM_ROLE_NAME FROM UM_USER_ROLE, UM_ROLE, UM_USER WHERE UPPER(UM_USER.UM_USER_NAME)=UPPER(?) AND UM_USER.UM_ID=UM_USER_ROLE.UM_USER_ID AND UM_ROLE.UM_ID=UM_USER_ROLE.UM_ROLE_ID AND UM_USER_ROLE.UM_TENANT_ID=? AND UM_ROLE.UM_TENANT_ID=? AND UM_USER.UM_TENANT_ID=?</Property>

Now you should be able to login to G-Reg server as AdMiN.