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