Wednesday, December 18, 2013

How to install Open JDK in Ubuntu


You can refer http://openjdk.java.net/ to know what is Open JDK. In this I will be installing Open jdk version 1.7.0_25
  1. You can download your referred version from http://www.oracle.com/technetwork/java/javase/downloads/index.html
     
  2. Once you download, uncompress the file using following command
    sudo tar -xvf jdk-7u25-<version>.tar.gz

    JDK 7 package is extracted into /jdk1.7.0_25 directory.

  3. It is better to move the JDK 7 directory to /usr/lib via following commands
            sudo mkdir -p /usr/lib/jvm
            sudo mv jdk1.7.0_25/ /usr/lib/jvm/jdk1.7.0_25
  1. Then run the following commands :
sudo update-alternatives --install “/usr/bin/java” “java” “/usr/lib/jvm/jdk1.7.0_25/bin/java” 1
sudo update-alternatives --install “/usr/bin/javac” “javac” “/usr/lib/jvm/jdk1.7.0_25/bin/javac” 1
sudo update-alternatives --install “/usr/bin/javaws” “javaws” “/usr/lib/jvm/jdk1.7.0_25/bin/javaws” 1
  1. Then configure for the open jdk
    For Java :
    sudo update-alternatives --config java
This will output the following
There are 5 choices for the alternative java (providing /usr/bin/java).
Selection Path Priority Status
------------------------------------------------------------
0 /usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java 1061 auto mode
1 /opt/java/jdk1.7.0_25/bin/java 1 manual mode
2 /opt/java/jre1.7.0_25/bin/java 1 manual mode
3 /usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java 1061 manual mode
* 4 /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java 1051 manual mode
5 /usr/lib/jvm/jdk1.7.0_25/bin/java 1 manual mode
You have to Press enter to keep the current choice[*], or type selection number. In here I will be entering * since I need the 4th option.
    For Javac :
    sudo update-alternatives --config javac
This will output the following
There are 3 choices for the alternative javac (providing /usr/bin/javac).
Selection Path Priority Status
------------------------------------------------------------
0 /usr/lib/jvm/java-6-openjdk-amd64/bin/javac 1061 auto mode
1 /usr/lib/jvm/java-6-openjdk-amd64/bin/javac 1061 manual mode
* 2 /usr/lib/jvm/java-7-openjdk-amd64/bin/javac 1051 manual mode
3 /usr/lib/jvm/jdk1.7.0_25/bin/javac 1 manual mode
You have to Press enter to keep the current choice[*], or type selection number. In here I will be entering * since I need the 2nd option.

    For Javaws :
    sudo update-alternatives --config javaws
This will output the following
There are 3 choices for the alternative javaws (providing /usr/bin/javaws).
Selection Path Priority Status
------------------------------------------------------------
0 /usr/lib/jvm/java-6-openjdk-amd64/jre/bin/javaws 1061 auto mode
1 /usr/lib/jvm/java-6-openjdk-amd64/jre/bin/javaws 1061 manual mode
* 2 /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/javaws 1060 manual mode
3 /usr/lib/jvm/jdk1.7.0_25/bin/javaws 1 manual mode
You have to Press enter to keep the current choice[*], or type selection number. In here I will be entering * since I need the 2nd option.

  1. Now you can check the java version
    java -version
This will output the following if the installation is successful :
java version "1.7.0_25"
OpenJDK Runtime Environment (IcedTea 2.3.10) (7u25-2.3.10-1ubuntu0.12.04.2)
OpenJDK 64-Bit Server VM (build 23.7-b01, mixed mode)

  1. Also you have to set JAVA_HOME in .bashrc.
    Run the following command and open the .bashrc and give the correct path.
    gedit ~/.bashrc
    Add the following to the end of the file.
    export JAVA_HOME=/usr/lib/jvm/java-1.7.0_25
    export PATH=$PATH:$JAVA_HOME/bin
  2. Source the bash profile.
    source ~/.bashrc

Sunday, November 3, 2013

How to Test JWT caching in WSO2 API Manager


How to Test JWT caching in API Manager

Before get in to this post (http://ushanib.blogspot.com/2013/03/how-to-test-values-in-oauth2-token.html) should be referred to know the steps to enable JWT token.
When you enable JWT token in a distributed set up you should enable it in publisher node and the key manager node.
This is enabled in publisher node because to change the API template accordingly.
Enable in keymanager node : To cache it in keymanager
But when you enable caching you will have to enable it only in the key manager node.

Steps:
=====
  1. First you need to enable JWT token as explained in this post
  2. To enable Caching you need to set “true” in the following parameter in the api-manager.xml in <AM_Home>/repository/conf.
    <EnableJWTCache>true</EnableJWTCache>

To Test :
======
  1. First without the caching enabled you can vie the results as explained in the post mentioned.

  2. Then to go to your My Application page as given in the below screenshot and edit the application name that you have subscribed to. E.g., In the above mentioned post, subscription is done to DefaultApplication. You can change the name of it as app1.




  3. Then send a API call request and follow the steps 11 to 15 as given in this post.

  4. You will see the changed app name fter decoding the encoded value as follows :

"http://wso2.org/claims/applicationname":"app1"

  1. Now enable the JWT caching as given in step 2 above and edit the app name as app2 and perform the above step 3 again.

Observation :
==========
  1. Once you decode, you will be able to see the application name as app1 still since the JWT caching is enabled and the app name will be taken from the cache.

  2. But if you disable JWT caching and do the same steps you will be able to see the changed app name.

  3. If you have enabled key manager or gateway caching with JWT caching still it will show you the cached app name. But if the JWT caching is disabled and gateway or key manager caching is enabled, you should not be able to see the app name changes since the JWT caching is disabled.

Thursday, September 5, 2013

WSO2 Governance Registry (GREG) Check-in Client

The Check-in Client is a tool used to replicate the resources tree in the Governance Registry into your file-system or to a dump file. Much like a version control system like Subversion (SVN), you can do checkout, check-in and update operations using this tool.

To read more, check this link. http://docs.wso2.org/display/Governance451/Check-in+Client

This feature can be used in 2 ways.
1. Super Admin users.
2. Tenant users.

Role -Admin - Super Admin
==================

1. To checkout via admin, use the following command in bin.

sh checkin-client.sh co https://localhost:9443/registry/ -u admin -p admin

2. It will create a folder called _system.

3. To checkin a file you create inside governance, use the following steps.

First to create a file, go in to governance inside _system and,
vi readme_admin

It will create a file named readme_admin.

4. To add it to the repository, (you have to run checkin-client from the bin)

sh ../../checkin-client.sh add readme_admin https://localhost:9443/registry/ -u admin -p admin


or

 sh ../../checkin-client.sh add readme_admin -u admin -p admin

5. To check the status,

 sh ../../checkin-client.sh status


6. To commit the file,

 sh ../../checkin-client.sh ci -u admin -p admin


For a different tenant/ Tenant User
======================

E.g., Tenant is created as ushani.com
A role inside ushani.com - ushaniR
users inside ushaniR - ushani/pwrd-ushani, ushani1/pwrd-ushani1

1. To checkout via a tenant, use the following command in bin.

sh checkin-client.sh co https://localhost:9443/t/ushani.com/registry -u ushani1    -p ushani1


2. To add a file in to repository,

sh ../../checkin-client.sh add readme_ushani1


3. To commit.,

sh ../../checkin-client.sh ci -u ushani1 -p ushani1

Tuesday, August 13, 2013

How to test Compression (gzip encoding) in WSO2 App Server server side response/During the deployment time.


1. First make sure echo service is deployed in your AS pack which you are going to test. (This will be available by deafult)

2. Then give the echo service wsdl as the endpoint and create a soap project. E.g., http://192.168.94.1:9763/services/echo?wsdl

3. Then Go to <AS_HOME>/repository/conf/tomcat and edit the catalina-server.xml.

4. Use the document http://tomcat.apache.org/tomcat-7.0-doc/config/http.html as reference.

   compression="on"  
   compressionMinSize="2048"  
   noCompressionUserAgents="gozilla, traviata"  
   compressableMimeType="text/html,text/xml,text/javascript,application/x-javascript,application/javascript,application/xml,text/css,application/xslt+xml,text/xsl,image/gif,image/jpg,image/jpeg"  

 If you want to disable gzip encoding, make compression="off". By default this will be on.
 You have to provide the correct MimeType of your request. E.g., text/xml

5. Now start the AS server.

6. Open a tcp mon and open a port listening to 9764 and target point as 9763. Host name will be the host address of your AS, which is echo service is available. E.g., localhost/127.0.0.1

7. Go to SOAP Project created and open the  echoString request editor.

8. Change the endpoint as it goes to the listen port we set in tcpmon.
http://192.168.94.1:9764/services/echo.echoHttpSoap11Endpoint/

9. Now send a request, (You can change this request by editing the "in" value as the string will be more than or lesser than compressionMinSize value and test more how these properties will work)

Request:

  <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:echo="http://echo.services.core.carbon.wso2.org">  
   <soapenv:Header/>  
   <soapenv:Body>  
    <echo:echoString>  
      <!--Optional:-->  
      <in>abc</in>  
    </echo:echoString>  
   </soapenv:Body>  
 </soapenv:Envelope>  


Response:

 <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">  
   <soapenv:Body>  
    <ns:echoStringResponse xmlns:ns="http://echo.services.core.carbon.wso2.org">  
      <return>abc</return>  
    </ns:echoStringResponse>  
   </soapenv:Body>  
 </soapenv:Envelope>  


10. Now test the response headers via tcpmon or via soap raw values.

 You should see the request and response headers as follows:


 Request Header :

POST /services/echo.echoHttpSoap11Endpoint/ HTTP/1.1
Accept-Encoding: gzip,deflate
Content-Type: multipart/related; type="text/xml"; start="<rootpart@soapui.org>"; boundary="----=_Part_0_1020577184.1376370045484"
SOAPAction: "urn:echoString"
MIME-Version: 1.0
Content-Length: 703
Host: 127.0.0.1:9764
Connection: Keep-Alive
User-Agent: Apache-HttpClient/4.1.1 (java 1.5)



 Response Header :

HTTP/1.1 200 OK
Content-Type: text/xml;charset=UTF-8
Transfer-Encoding: chunked
Content-Encoding: gzip
Vary: Accept-Encoding
Date: Tue, 13 Aug 2013 05:00:45 GMT
Server: WSO2 Carbon Server

a


Note : You can test other parameters as well by using this sample

Thursday, July 18, 2013

Why do we get "PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target" exception?

Most of the time we might get an issue which says the following while trying to subscribe to emails in carbon products,


 [2013-07-18 11:25:22,974] ERROR {org.apache.axis2.transport.mail.MailTransportSender} - Error creating mail message or sending it to the configured server
javax.mail.MessagingException: Can't send command to SMTP host;
  nested exception is:
        javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target


This issue is occurred when the server has got self verified certificates and client's trust store does not have it. But in gmail there is a certificate that is issued by a CA. So if you use JRE certificate store ($JREHOME/lib/security/cacerts) in the client side, this issue may not be occurred as it contains some CA's root certificates. But this certificates store can be changed by setting system property 'javax.net.ssl.trustStore'.
Sometimes this blog might help you to store this certificate.

Why do we get "Failed Sending Email org.apache.axis2.AxisFault: The system cannot infer the transport information from the mailto" issue?


Most of the time in WSO2 Carbon products, users may encounter exceptions as follow when subscribing for a particular mail response:


[2013-07-17 09:49:45,781] ERROR {org.apache.axis2.description.ClientUtils} - The system cannot infer the transport information from the mailto:<email> URL.
Failed Sending Email
org.apache.axis2.AxisFault: The system cannot infer the transport information from the mailto : <email>

 at org.apache.axis2.description.ClientUtils.inferOutTransport(ClientUtils.java:81)
        at org.apache.axis2.client.OperationClient.prepareMessageContext(OperationClient.java:288)
        at org.apache.axis2.description.OutOnlyAxisOperationClient.executeImpl(OutOnlyAxisOperation.java:249)
        at org.apache.axis2.client.OperationClient.execute(OperationClient.java:149)
        at org.apache.axis2.client.ServiceClient.fireAndForget(ServiceClient.java:511)
        at org.apache.axis2.client.ServiceClient.fireAndForget(ServiceClient.java:488)
        at org.wso2.carbon.email.verification.util.EmailSender.run(EmailSender.java:115)
[2013-07-17 09:49:46,079] DEBUG {org.wso2.carbon.user.core.authorization.JDBCAuthorizationManager} - Authorization cache entry is not found for username

The reason can be :

The reason for this issue is the AxisConfiguration which uses to send this message does not have the mail transport. In axis2.xml you have to define the transportSender as below.

<transportSender name="mailto" class="org.apache.axis2.transport.mail.MailTransportSender">
        <parameter name="mail.smtp.from">user@gmail.com</parameter>
        <parameter name="mail.smtp.user">user</parameter>
        <parameter name="mail.smtp.password">mailpassword</parameter>
        <parameter name="mail.smtp.host">smtp.gmail.com</parameter>
        <parameter name="mail.smtp.port">587</parameter>
        <parameter name="mail.smtp.starttls.enable">true</parameter>
        <parameter name="mail.smtp.auth">true</parameter>
</transportSender> 


Sometimes having an unnecessary space in between these values might also be a reason for this issue.

Friday, July 12, 2013

How to test the disable HTTP chunking for outgoing messaging via WSO2 ESB and a REST request



There are few HTTP transport-specific properties in ESB.

Properties use in ESB access various types of information regarding a message that passes through the ESB. Also properties can be used to control the behavior of the ESB on a given message.

WSO2 ESB support transfer-encoding – chunked by default. To make it disabled, there is a property that would help to perform it.
 
      <property name="DISABLE_CHUNKING" value="true" scope="axis2"/>  


Transfer-encoding - chunked is a feature came along with HTTP 1.1. Therefore no matter what HTTP 1.0 will support only content type. Therefore if the message is forced to send as HTTP1.0 you will be able to see only the content type. Refer the previous blog post for more reference. Outgoing message can be seen in here.

By the following steps I will be explaining how to test this behavior if WSO2 ESB.


To Setup :
----------------
  1. Go to <ESB_Home>/samples/axis2Server/src/SimpleStockQuoteService and build it, ant

  2. Start the Go to <ESB_Home>/samples/axis2Server and start the axis2Server by the following command, sh axis2server.sh.

  3. Start the ESB Server, <ESB_Home>/bin by providing, sh wso2server.sh.

  4. Run a tcpMon to view the outgoing messages.

  5. Start the tcpmon in the <ESB_Home>/bin - sh tcpmon.sh
    Create 2 listeners as below. 

    1. Listen Port 8281, Target host – localhost, Target port – 8280 – Before hits the ESB
    2. Listen Port 9001, Target host – localhost, target port – 9000 – After passing through ESB and Before hits the backend
  1. Log in to the ESB and provide the following synapse configuration.


     <?xml version="1.0" encoding="UTF-8"?>  
     <definitions xmlns="http://ws.apache.org/ns/synapse">  
       <sequence name="fault">  
        <log level="full">  
          <property name="MESSAGE" value="Executing default &#34;fault&#34; sequence"/>  
          <property name="ERROR_CODE" expression="get-property('ERROR_CODE')"/>  
          <property name="ERROR_MESSAGE" expression="get-property('ERROR_MESSAGE')"/>  
        </log>  
        <drop/>  
       </sequence>  
       <sequence name="main">  
        <header name="Action" value="urn:getQuote"/>  
        <filter source="get-property('To')" regex=".*/StockQuote.*">  
         <property name="DISABLE_CHUNKING" value="true" scope="axis2"/>  
          <send>  
           <endpoint>  
             <address uri="http://localhost:9001/services/SimpleStockQuoteService"  
                 format="soap11"/>  
           </endpoint>  
          </send>  
          <drop/>  
        </filter>  
        <send/>  
       </sequence>  
     </definitions>  
    

To Send the Rest request :
---------------------------------------------

  1. Go to axis2Client, <ESB_Home>/samples/axis2Client and send the following REST request.
 ant stockquote -Dtrpurl=http://localhost:8281/services/StockQuote -Drest=true  


Observations :
-------------------------
  1. On the server side, Standard :: Stock price = $70.54750695255485 will be generated.
  2. Observe the tcpMon.

Rest request sent to ESB can be seen in port 8281,

Transfer-Encoding: chunked


Outgoing message from ESB can be seen in port 9001,

Content-Length: 275

How to test the Force HTTP 1.0 outgoing messages via WSO2 ESB and a REST request



There are few HTTP transport-specific properties in ESB.

Properties use in ESB access various types of information regarding a message that passes through the ESB. Also properties can be used to control the behavior of the ESB on a given message.
WSO2 ESB support HTTP 1.1 outgoing messages by default. To make it HTTP 1.0, there is a property that would help to perform it.
 
      <property name="FORCE_HTTP_1.0" value="true" scope="axis2"/>  



By the following steps I will be explaining how to test this behavior if WSO2 ESB.


To Setup :
----------------
  1. Go to <ESB_Home>/samples/axis2Server/src/SimpleStockQuoteService and build it, ant

  2. Start the Go to <ESB_Home>/samples/axis2Server and start the axis2Server by the following command, sh axis2server.sh.

  3. Start the ESB Server, <ESB_Home>/bin by providing, sh wso2server.sh.

  4. Run a tcpMon to view the outgoing messages.

  5. Start the tcpmon in the <ESB_Home>/bin - sh tcpmon.sh
    Create 2 listeners as below. 

    1. Listen Port 8281, Target host – localhost, Target port – 8280 – Before hits the ESB
    2. Listen Port 9001, Target host – localhost, target port – 9000 – After passing through ESB and Before hits the backend
  1. Log in to the ESB and provide the following synapse configuration.


     <?xml version="1.0" encoding="UTF-8"?>  
     <definitions xmlns="http://ws.apache.org/ns/synapse">  
       <sequence name="fault">  
        <log level="full">  
          <property name="MESSAGE" value="Executing default &#34;fault&#34; sequence"/>  
          <property name="ERROR_CODE" expression="get-property('ERROR_CODE')"/>  
          <property name="ERROR_MESSAGE" expression="get-property('ERROR_MESSAGE')"/>  
        </log>  
        <drop/>  
       </sequence>  
       <sequence name="main">  
        <header name="Action" value="urn:getQuote"/>  
        <filter source="get-property('To')" regex=".*/StockQuote.*">  
         <property name="FORCE_HTTP_1.0" value="true" scope="axis2"/>  
          <send>  
           <endpoint>  
             <address uri="http://localhost:9001/services/SimpleStockQuoteService"  
                 format="soap11"/>  
           </endpoint>  
          </send>  
          <drop/>  
        </filter>  
        <send/>  
       </sequence>  
     </definitions>  
    

To Send the Rest request :
---------------------------------------------

  1. Go to axis2Client, <ESB_Home>/samples/axis2Client and send the following REST request.
 ant stockquote -Dtrpurl=http://localhost:8281/services/StockQuote -Drest=true  


Observations :
-------------------------
  1. On the server side, Standard :: Stock price = $157.06490695255485 will be generated.
  2. Observe the tcpMon.

Rest request sent to ESB can be seen in port 8281,


POST /services/StockQuote HTTP/1.1



Outgoing message from ESB can be seen in port 9001,


POST /services/SimpleStockQuoteService HTTP/1.0

Saturday, June 29, 2013

How to test Multipart/form-data with attachments and json content type pass-through support for WSO2 ESB.


I hope the reader of this blog has got an idea about WSO2 ESB and the pass-through transport and the different type of content types support for the product.

To test Multipart/form data, we need the below things ready.

  1. A backend service.
  2. tcpmon to view the pass through
  3. A form to submit data
  4. Attachments – text files, json file, an image
  5. WSO2 ESB with the correct synapse configuration of the proxy


Backend Service

  1. As the backend service, I will be setting the offset to 2 and run a WSO2 App Server, which can also be downloaded from http://wso2.com/products/application-server/. I am using 5.1.0.
  2. I will be using the HelloService in unsecured mode.
  3. I assume now that I have the HelloService up and runninn in, http://localhost:9765/services/HelloService

Set up tcp mon

    1. Start the tcpmon in the <ESB_Home>/bin - sh tcpmon.sh

    2. Create 2 listeners as below.
                 1. Listen Port 8281, Target host – localhost, Target port – 8280 –  Before hits the ESB/ HelloProxyService proxy
                 2. Listen Port 9766, target host – localhost, target port – 9765 – After passing through ESB and Before hits the backend


A form to submit data

I will be using a html which contains a form to submit data and to upload attachments and which has the form action set to the our first tcpmon (Before hits the ESB/ HelloProxyService proxy),
form action="http://localhost:8281/services/HelloProxyService/greet"

 <html>  
  <head><title>multipart/form-data - Client</title></head>  
  <body>   
 <form action="http://localhost:8281/services/HelloProxyService/greet" method="POST" enctype="multipart/form-data">  
 User Name: <input type="text" name="name">  
 User id: <input type="text" name="id">  
 User Address: <input type="text" name="add">  
 AGE: <input type="text" name="age">  
  <br>   
 Upload :   
 <input type="file" name="datafile" size="40" multiple>  
 </p>  
  <input type="submit" value="Submit">  
  </form>  
  </body>  
 </html>  


Attachments

  1. As attachments, I have just a text file with some texts in it
  2. A jpeg image
  3. A Json file with a json object.
E.g., jsonfile.txt

 {  
 "name":"John Johnson",  
 "street":"Oslo West 555",  
 "age":33,  
 "phone":"555 1234567"  
 }  


Synapse configurations

  1. The below proxy will allow the user to view the data that has been sent.
    <Port> = 9766 or a different port you provide
 <proxy name="HelloProxyService"  
      transports="https http"  
      startOnLoad="true"  
      trace="disable">  
    <description/>  
    <target>  
      <endpoint>  
       <address uri="http://localhost:<port>/services/HelloService"/>  
      </endpoint>  
      <outSequence>  
       <property name="OUT_ONLY" value="true"/>  
       <send/>  
      </outSequence>  
    </target>  
   </proxy>  


   2. If you want to test whether this form data saved in to a file correctly, you can enable VFS transport in axis2.xml and use the following synapse accordingly. We will be saving it in to a file in the given location.

 <proxy name="HelloProxyService"  
      transports="https http"  
      startOnLoad="true"  
      trace="disable">  
    <description/>  
    <target>  
      <endpoint>  
       <address uri="vfs:file:///home/ushani/Downloads/out"/>  
      </endpoint>  
      <inSequence>  
       <property name="OUT_ONLY" value="true"/>  
      </inSequence>  
      <outSequence>  
       <send/>  
      </outSequence>  
    </target>  
   </proxy>  

To Test :

Open the html form in browser format and fill in the input values and attach the attachment (Json file or a text file or an image) submit and observe in tcpmon.




(Listen Port 8281, Target host – localhost, Target port – 8280 –  Before hits the ESB/ HelloProxyService proxy)




(Listen Port 9766 or a different port, target host – localhost, target port – 9765 or different port which the backend service is run – After passing through ESB and Before hits the backend)


Sunday, June 23, 2013

How to create a MySQL database and a datasource using WSO2 Appfactory


With the beta release of WSO2 App factory, it enables you to create a database and datasource for the applications you create using App Factory.
Current latest version supports MySQL.
This blog post explains you steps to create a database and a datasource and how to point them in a Web application (WAR) created using WSO2 App Factory.

For more information on WSO2 App Factory :



To create a WAR/ Web app supports the datasource

  1. Registered user can successfully login to WSO2 app factory and create a web application. As an example I will be creating a web application named ColourFindApp.


    Application Creation

  2. Once I created the application, I will be assigning user roles for the application using the Team page.
  3. Then a developer or the app owner which has developer rights will be checking out the source code using GIT and do the necessary code level changes via Developer studio and then commit the code.
    http://ushanib.blogspot.com/2013/02/steps-to-checkout-and-commit-wso2.html
  4. As an example assume in my source code, I refer my datasource as colour. So the sample code in my application source code will be something like below.
    E.g.,

    …............
      Hashtable hashtable = new Hashtable();  
 hashtable.put("java.naming.factory.initial","org.wso2.carbon.tomcat.jndi.CarbonJavaURLContextFactory");  
 Context initContext = new InitialContext(hashtable);  
 ds = (DataSource) initContext.lookup("jdbc/colour");  
 Connection conn = ds.getConnection();  
 Statement statement = conn.createStatement();   
        …............

  1. So the datasource I will be creating should be named as colour.
Databases Permission level

User Role Permission
App Owner Can create and configure databases in Development, Testing and Staging
Developer Can create and configure databases in Development and Testing environments
QA/Tester Can create and configure databases in Testing and Staging environments
Dev-Ops Can create and configure databases in Staging and Production environments
  1. A user can login to the system and select the resource section to create a database.
  2. User can create the database as per the above permission. Visibility of Database environment will be as above user role permission. User will be able to select the environment from the drop down. DB User and template can be created inline or separately and select it form the drop down.
  3. Created users and the templates for each environment will be loaded depends on the selected database environment.


                                              Database Creation


    Datasource Permission Level
User Role Permission
App Owner Can create and edit datsources in Development, Testing and Staging
Developer Can create and edit datasources in Development and Testing environments
QA/Tester Can configure created datasources in Testing and Staging environments
Dev-Ops Can configure created datadources in Staging and Production environments
  1. App owner can create a datasource and provide the database url created initially. E.g., I create a database named COL_DB and Datasource as colour.
  2. Then a datasource will be copied in to testing and staging as well along with the provided database URL. E.g., If I provide the database URL of the development stage it will copy the database URL of development stage in testing and staging as well.
    E.g.,
    jdbc:mysql://rss.dev.appfactorypreview.wso2.com:3306/COL_DB

                                Shows the datasources visibility as an APP Owner

  3. If a developer logs in to the system, he or she will see the datasources created in Dveloement and testing stages.
  4. A Developer or a testing user can create another database in testing environment and select the datasource created and the stage as Testing and provide the newly created database URL of the testing stage. E.g., Database created in testing : COL_DB in testing storage server and select the colour as the datasource and the stage as testing and the testing DB URL and update it.

    E.g.,
    jdbc:mysql://rss.test.appfactorypreview.wso2.com:3306/COL_DB
  5. This will enable the different users to easily update their datasource with their desired database location and test the application.
  6. Depends on the stage selected, existing database URL and attached users will be loaded.
  7. If not a developer or a tester can test their application with the datasource created initially which points to the database in the development without editing and configuring it to the different environment.
  8. When promoting the application in to proceeding stage it will refer the database pointed to the promoted environment.
  9. Only Dev Ops have permission to configure the production environment. Therefore DevOps will have to select the stage as Production and provide the database URL accordingly.

Wednesday, April 24, 2013

How to test SOAP Fault Data in WSO2 ESB and JMS message store, a message processor with a reply sequence and a fault sequence


In this post I am not going to explain about message store or message processor and their behavior. I will exactly explain how to test SOAP Fault Data in WSO2 ESB and JMS message store, a message processor with a reply sequence and a fault sequence.
Before you try out this sample, it is better to read the following articles and blog posts to get more information.


  • Applications and networks can be full of errors, Applications crash. Network routers and links get into states where they cannot pass messages through with the expected efficiency. These error conditions are very likely to cause a fault or trigger a runtime exception in the ESB. 
  • When applications and networks can be full of errors. Applications crash. Network routers and links get into states where they cannot pass messages through with the expected efficiency. These error conditions are very likely to cause a fault or trigger a runtime exception in the ESB. 
  • It is not mandatory to associate each sequence and proxy service with a fault sequence. In situations where a fault sequence is not specified explicitly, a default fault sequence will be used to handle errors.


Whenever an error occurs in WSO2 ESB, the mediation engine attempts to provide as much information as possible on the error to the user by initializing the following properties on the erroneous message:
  • ERROR_CODE
  • ERROR_MESSAGE
  • ERROR_DETAIL
  • ERROR_EXCEPTION etc

We can configure a message broker to save the failed requests in a message store for later delivery. When the client sends requests to a proxy service , the proxy service stores the messages to a JMS message store if it cannot be delivered and then the back-end service is invoked by a message forwarding processor, which picks stored messages in the JMS message store.

To test this scenario we need the following:
  1. Message Broker – I will be using WSO2 Message Broker (MB)
  2. WSO2 ESB
  3. WSO2 Application Server to invoke a service – Axis2Service (You can use any other service which will generate an exception)


    To configure WSO2 ESB, AS and MB, follow the steps below:
  1. Follow the steps in the following location. http://docs.wso2.org/wiki/display/ESB460/Configure+with+WSO2+Message+Broker 
  2. Or 1 and 2 steps in http://sandapa.blogspot.com/2013/02/jms-messaging-with-wso2-esb-460-and.html   
  3. Now the ESB and Message broker should be ready.

    Configurations :
    ---------------------------

  4. Set the offset as 2 in carbon.xml (<AS_HOME/repository/conf>) and start the Application server deploying the Axis2service. Refer the following document. http://docs.wso2.org/wiki/display/AS510/Installation+Guide
  5. Create a proxy. Provide the following synapse configuration. 
  <proxy name="FaultTestProxy"  
      transports="https http"  
      startOnLoad="true"  
      trace="disable">  
    <description/>  
    <target>  
      <inSequence>  
       <log level="full"/>  
       <property name="target.endpoint" value="AxisEp"/>  
       <property name="FORCE_SC_ACCEPTED" value="true" scope="axis2"/>  
       <property name="FORCE_ERROR_ON_SOAP_FAULT" value="true"/>  
       <store messageStore="Queue1"/>  
      </inSequence>  
      <outSequence>  
       <send/>  
      </outSequence>  
      <faultSequence>  
       <log level="full" category="ERROR"/>  
      </faultSequence>  
    </target>  
   </proxy>  


6. Set the endpoint as following to invoke Axis2Service. This can be any service which will help to produce an error.

  <endpoint name="AxisEp">  
    <address uri="http://localhost:9765/services/Axis2Service">  
      <suspendOnFailure>  
       <errorCodes>-1</errorCodes>  
       <progressionFactor>1.0</progressionFactor>  
      </suspendOnFailure>  
    </address>  
   </endpoint>  



7. Create a message store as following.

 <messageStore class="org.wso2.carbon.message.store.persistence.jms.JMSMessageStore"  
          name="Queue1">  
    <parameter name="java.naming.factory.initial">org.wso2.andes.jndi.PropertiesFileInitialContextFactory</parameter>  
    <parameter name="store.jms.cache.connection">false</parameter>  
    <parameter name="java.naming.provider.url">repository/conf/jndi.properties</parameter>  
    <parameter name="store.jms.JMSSpecVersion">1.1</parameter>  
    <parameter name="store.jms.destination">Queue1</parameter>  
   </messageStore>  



8. Create a Scheduled Message Forwarding Processor as following.

 <messageProcessor class="org.apache.synapse.message.processors.forward.ScheduledMessageForwardingProcessor"  
            name="MyMsgProc"  
            messageStore="Queue1">  
    <parameter name="message.processor.reply.sequence">Axis_Ok</parameter>  
    <parameter name="max.delivery.attempts">4</parameter>  
    <parameter name="interval">5000</parameter>  
    <parameter name="message.processor.fault.sequence">Axis_Fault</parameter>  
   </messageProcessor>  


9.  Following fault sequence should be configured

 <sequence name="Axis_Fault">  
    <log level="custom" category="ERROR">  
      <property name="text" value="An error occured"/>  
      <property xmlns:ns="http://org.apache.synapse/xsd"  
           name="ERROR_MESSAGE"  
           expression="get-property('ERROR_MESSAGE')"/>  
      <property xmlns:ns="http://org.apache.synapse/xsd"  
           name="ERROR_CODE"  
           expression="get-property('ERROR_CODE')"/>  
      <property xmlns:ns="http://org.apache.synapse/xsd"  
           name="ERROR_DETAIL"  
           expression="get-property('ERROR_DETAIL')"/>  
      <property xmlns:ns="http://org.apache.synapse/xsd"  
           name="ERROR_EXCEPTION"  
           expression="get-property('ERROR_EXCEPTION')"/>  
      <property xmlns:ns="http://org.apache.synapse/xsd"  
           name="FaultTo"  
           expression="get-property('FaultTo')"/>  
      <property xmlns:ns="http://org.apache.synapse/xsd"  
           name="FAULT"  
           expression="get-property('FAULT')"/>  
      <property xmlns:ns="http://org.apache.synapse/xsd"  
           name="SENDING_FAULT"  
           expression="get-property('SENDING_FAULT')"/>  
      <property xmlns:ns="http://org.apache.synapse/xsd" name="REPLY" expression="/"/>  
      <property xmlns:ns="http://org.apache.synapse/xsd"  
           name="RESPONSE"  
           expression="get-property('RESPONSE ')"/>  
      <property xmlns:ns="http://org.apache.synapse/xsd"  
           name="HTTP_SC"  
           expression="get-property('HTTP_SC')"/>  
    </log>  
    <log level="full" category="ERROR"/>  
   </sequence>  




The whole Synapse Configuration would be as follows :

 <?xml version="1.0" encoding="UTF-8"?>  
 <definitions xmlns="http://ws.apache.org/ns/synapse">  
   <registry provider="org.wso2.carbon.mediation.registry.WSO2Registry">  
    <parameter name="cachableDuration">15000</parameter>  
   </registry>  
 #######################  
 # Proxy  
 #######################   
   <proxy name="FaultTestProxy"  
      transports="https http"  
      startOnLoad="true"  
      trace="disable">  
    <description/>  
    <target>  
      <inSequence>  
       <log level="full"/>  
       <property name="target.endpoint" value="AxisEp"/>  
       <property name="FORCE_SC_ACCEPTED" value="true" scope="axis2"/>  
       <property name="FORCE_ERROR_ON_SOAP_FAULT" value="true"/>  
       <store messageStore="Queue1"/>  
      </inSequence>  
      <outSequence>  
       <send/>  
      </outSequence>  
      <faultSequence>  
       <log level="full" category="ERROR"/>  
      </faultSequence>  
    </target>  
   </proxy>  
 #######################  
 # Endpoint  
 #######################   
   <endpoint name="AxisEp">  
    <address uri="http://localhost:9765/services/Axis2Service">  
      <suspendOnFailure>  
       <errorCodes>-1</errorCodes>  
       <progressionFactor>1.0</progressionFactor>  
      </suspendOnFailure>  
    </address>  
   </endpoint>  
 #######################  
 # Fault Sequence  
 #######################   
   <sequence name="Axis_Fault">  
    <log level="custom" category="ERROR">  
      <property name="text" value="An error occured"/>  
      <property xmlns:ns="http://org.apache.synapse/xsd"  
           name="ERROR_MESSAGE"  
           expression="get-property('ERROR_MESSAGE')"/>  
      <property xmlns:ns="http://org.apache.synapse/xsd"  
           name="ERROR_CODE"  
           expression="get-property('ERROR_CODE')"/>  
      <property xmlns:ns="http://org.apache.synapse/xsd"  
           name="ERROR_DETAIL"  
           expression="get-property('ERROR_DETAIL')"/>  
      <property xmlns:ns="http://org.apache.synapse/xsd"  
           name="ERROR_EXCEPTION"  
           expression="get-property('ERROR_EXCEPTION')"/>  
      <property xmlns:ns="http://org.apache.synapse/xsd"  
           name="FaultTo"  
           expression="get-property('FaultTo')"/>  
      <property xmlns:ns="http://org.apache.synapse/xsd"  
           name="FAULT"  
           expression="get-property('FAULT')"/>  
      <property xmlns:ns="http://org.apache.synapse/xsd"  
           name="SENDING_FAULT"  
           expression="get-property('SENDING_FAULT')"/>  
      <property xmlns:ns="http://org.apache.synapse/xsd" name="REPLY" expression="/"/>  
      <property xmlns:ns="http://org.apache.synapse/xsd"  
           name="RESPONSE"  
           expression="get-property('RESPONSE ')"/>  
      <property xmlns:ns="http://org.apache.synapse/xsd"  
           name="HTTP_SC"  
           expression="get-property('HTTP_SC')"/>  
    </log>  
    <log level="full" category="ERROR"/>  
   </sequence>  
    <sequence name="main">  
    <in>  
      <log level="full"/>  
      <filter source="get-property('To')" regex="http://localhost:9000.*">  
       <send/>  
      </filter>  
    </in>  
    <out>  
      <send/>  
    </out>  
    <description>The main sequence for the message mediation</description>  
   </sequence>  
 #######################  
 # Message Store  
 #######################   
   <messageStore class="org.wso2.carbon.message.store.persistence.jms.JMSMessageStore"  
          name="Queue1">  
    <parameter name="java.naming.factory.initial">org.wso2.andes.jndi.PropertiesFileInitialContextFactory</parameter>  
    <parameter name="store.jms.cache.connection">false</parameter>  
    <parameter name="java.naming.provider.url">repository/conf/jndi.properties</parameter>  
    <parameter name="store.jms.JMSSpecVersion">1.1</parameter>  
    <parameter name="store.jms.destination">Queue1</parameter>  
   </messageStore>  
 #######################  
 # Message Processor  
 #######################   
   <messageProcessor class="org.apache.synapse.message.processors.forward.ScheduledMessageForwardingProcessor"  
            name="MyMsgProc"  
            messageStore="Queue1">  
    <parameter name="message.processor.reply.sequence">Axis_Ok</parameter>  
    <parameter name="max.delivery.attempts">4</parameter>  
    <parameter name="interval">5000</parameter>  
    <parameter name="message.processor.fault.sequence">Axis_Fault</parameter>  
   </messageProcessor>  
 </definitions>  


To Test:
------------

1. Via SOAP create a new SOAP project and provide the following wsdl URL,
http://localhost:8281/services/FaultTestProxy?wsdl

2. Then  stop the Axis2Service and send the following request in echoInt method. (We are sending a String value except an int value)

 <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ser="http://service.carbon.wso2.org">  
   <soapenv:Header/>  
   <soapenv:Body>  
    <ser:echoInt>  
      <!--Optional:-->  
      <ser:x>String</ser:x>  
    </ser:echoInt>  
   </soapenv:Body>  
 </soapenv:Envelope>  

3. Then the message store will store the message. Then start the Axis2Service. Then the Message Processor will pick the message and try to forward it. Due to the string value, following Error codes will be printed in the ESB Server console.


ERROR - LogMediator text = An error occured, ERROR_MESSAGE = Invalid value "String" for element x, ERROR_CODE = Client, ERROR_DETAIL = , ERROR_EXCEPTION = , FaultTo = , FAULT = TRUE, SENDING_FAULT = null, REPLY = <?xml version='1.0' encoding='utf-8'?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Header><ns:BAMEvent xmlns:ns="http://wso2.org/ns/2010/10/bam" activityID="13320046414250_138"/></soapenv:Header><soapenv:Body><soapenv:Fault xmlns:axis2ns26="http://schemas.xmlsoap.org/soap/envelope/"><faultcode>axis2ns26:Client</faultcode><faultstring>Invalid value "String" for element x</faultstring><detail/></soapenv:Fault></soapenv:Body></soapenv:Envelope>, RESPONSE = null, HTTP_SC = 500

This was done with the great help provided by Charitha Kankanamge. :)




 

Saturday, March 16, 2013

How to set up a Task scheduler and store messages in a message store using WSO2 ESB (Enterprise Service Bus) and WSO2 MB (Message Broker)



This is a simple scenario which allows you to create a scheduled task and in the main sequence, which has a IN and OUT to send the request to the backend service (SimpleStockQuote Service) and get the response and store it in the JMS message store which points to the WSO2 Message Broker and process it inside the ESB message processor.


  1. Setup
    Follow the first 3 steps given in the Following blog written By Sandapa Handakumbura.
    http://sandapa.blogspot.com/2013/02/jms-messaging-with-wso2-esb-460-and.html
    a. Prerequisites
    b. Step 1 - Configuring MB
    c. Step 2 - Configuring ESB
    d. Step 3 - Setting up the Backend

    For More information : http://docs.wso2.org/wiki/display/ESB460/Configure+with+WSO2+Message+Broker

    Now we have a up and running ESB and a Message Broker.


  2. Create a Message Store
  • Click on the Message Stores under Main → Manage → Service Bus
  • Click on Add Message Stores and select Add JMS Message Store to create a JMS message store.
  • Provide the mandatory parameter as below. Since we use JMS and as in above steps we have created a message store named Queue1 in jndi properties, we should configure the following as below.
    - Name - Queue1
    - Message Store Provider - org.wso2.carbon.message.store.persistence.jms.JMSMessageStore
    - Initial Context Factory - org.wso2.andes.jndi.PropertiesFileInitialContextFactory
    - Provider URL - repository/conf/jndi.properties


    So the above created Message store synapse configuration should be as follows:

     <messageStore class="org.wso2.carbon.message.store.persistence.jms.JMSMessageStore"  
              name="Queue1">  
        <parameter name="java.naming.factory.initial">org.wso2.andes.jndi.PropertiesFileInitialContextFactory</parameter>  
        <parameter name="store.jms.cache.connection">false</parameter>  
        <parameter name="java.naming.provider.url">repository/conf/jndi.properties</parameter>  
        <parameter name="store.jms.destination">Queue1</parameter>  
        <parameter name="store.jms.JMSSpecVersion">1.1</parameter>  
       </messageStore>  
    


  1. Create the Task Scheduler
  • Click on the Scheduled Tasks under Main → Manage → Service Bus
  • Click on Add Task to create a task.
  • Provide the mandatory parameter as below.



-Task Name -TheTask
-Task Group- synapse.simple.quartz
-Task Implementation - org.apache.synapse.startup.tasks.MessageInjector 

Properties
----------------
-format - Literal - soap12
-to - Literal - http://localhost:9000/services/SimpleStockQuoteService
-message - XML - <ser:getSimpleQuote xmlns:ser="http://services.samples">
<ser:symbol>IBM</ser:symbol>
</ser:getSimpleQuote>
-soapAction - Literal - urn:getSimpleQuote 

Trigger Information of the Task
--------------------------------- --
-Trigger Type - Simple
-Count -1
-Interval (in seconds)* - 10
So the above created Task synapse configuration should be as follows:


 <task name="TheTask"  
 class="org.apache.synapse.startup.tasks.MessageInjector"  
 group="synapse.simple.quartz">  
 <trigger count="1" interval="25"/>  
 <property name="to"  
 value="http://localhost:9000/services/SimpleStockQuoteService"/>  
 <property name="soapAction" value="urn:getSimpleQuote"/>  
 <property name="format" value="soap12"/>  
 <property name="message">  
 <ser:getSimpleQuote xmlns:ser="http://services.samples">  
 <ser:symbol>IBM</ser:symbol>  
 </ser:getSimpleQuote>  
 </property>  
 </task>   


  1. Create the Sequence:

Edit the main sequence as follows :


Main Sequence synapse configurations should be as follows :

 <sequence name="main" trace="enable">  
 <in>  
 <log level='full' />  
 <send/>  
 </in>  
 <out>  
 <log level='full' />  
 <store messageStore="Queue1"/>  
 </out>  
 </sequence>   



  1. Create a Message Processor
    Click on the Message Processors under Main → Manage → Service Bus
    Click on Add Scheduled Message Forwarding Processor to create a processor.
    Provide the mandatory parameter as below.



Message Processor synapse configurations should be as follows :

 <messageProcessor class="org.apache.synapse.message.processors.forward.ScheduledMessageForwardingProcessor"  
 name="MyMsgProc"  
 messageStore="Queue1">  
 <parameter name="max.delivery.attempts">4</parameter>  
 <parameter name="interval">150000</parameter>  
 </messageProcessor>   



   6. Now everything is ready. Once you schedule the task, it will generate the requests and SimpleStockQuoteService will generate the response and it will be stored in the message store.
You can view the stored messages, just by clicking on the Message Stores → Store Name (Queue1) → Show Envelope to view the particular stored message.



  7. If you want, you can process it and send it to another service by adding other   sequences.

For more information, can refer : http://abeykoon.blogspot.com/2012/12/configuring-wso2-esb-451-with-wso2-mb.html

 and

docs.wso2.org/wiki/display/ESB460/Sample+702%3A+Introduction+to+Message+Forwarding+Processor