Tuesday, June 17, 2014

EnablingSSO for WSO2 Servers : Overcome session time out issue running on same machine

EnablingSSO for WSO2 Servers is one nice thing you can do with WSO2 Identity Server. If you do it on a single server and try to access multiple server instances on same browser you may come across session time outs.
What happens here is when user access one server and switch to access other server in the same browser, JSESSION cookie is replaced by other server. To overcome that we have to do the following steps.
  1. Go to <ESB_HOME>/repository/conf/carbon.xml. 
    • Find config under name of HostName. 
    • Uncomment it. 
    • Change it to some meaningful hostname 
<HostName>esb.wso2.com</HostName>
    • change config MgtHostName as well
<MgtHostName>esb.wso2.com</MgtHostName>
  1. Do the step 1 to GREG as well.
  2. Go to hosts file in your server. 
    • sudo gedit /etc/hosts
    • add following entries 
127.0.0.1 esb.wso2.com
127.0.0.1 greg.wso2.com

  1. Restart the servers

Wednesday, June 11, 2014

Easy way to check WS-I compliance

Are you worried about whether the wsdl you created WS-I compliance? If you want to check WS-I compliance you can use tools . The problem is I found it quite messy to work with. I looked around to get it done the way I want. It lacks support.

Don't worry. SoapUI provides you the best solution. With SoapUi you just can open your wsdl as a project and check WS-I compliance.

after add wsdl



Right click on the selected soap binding and select Check WSI compliance option. You can view the generated report on SoapUI it self or as a separate HTML.

When I first ran this I was left with a blank window. Then I found you need to change some settings in SoapUI.

Go to File > Preference and set as follows for WS-I

WS-I settings in soapui

Try it your self. Easiest way to check WS-I compliance.





How to upload file and associate with Service in WSO2 Governance Registry

When you create service in WSO2 GREG you can add association to any file. You can define a file path or URL to it. But what happens if you want to associate file to a service which is uploaded to the  registry.

1) You have to upload the file (word, pdf, image, etc..). You can do that by click on resources > browse > add resource 

upload file as a resource

2) To associate resource file with service, you have to first add the service. 
    Then browse service that you need to associate a resource. 
    On the right side you can see menu called Associations. 
    click on it. 
    you can associate resource file. 

add association to a file


You can try that with GREG.

Auto deploy for Tomcat

Auto deployment is a feature we do need to run our test cases. I needed an way to auto deploy web project to tomcat and test it. To to this programatically there are several ways. Lets find out them.

1) Using Embed tomcat

this is the best option I recommend to any one who tries to do that. I will show you the code snippet for it.

 package org.wso2.tomcat;  
 import org.apache.catalina.Context;  
 import org.apache.catalina.LifecycleException;  
 import org.apache.catalina.core.StandardHost;  
 import org.apache.catalina.startup.Tomcat;  
 /**  
  * Created by waruna on 4/17/14.  
  */  
 public class TravelocityDeployer {  
   public static void main(String[] args) throws Exception {  
     Tomcat tomcat = new Tomcat();  
     tomcat.getService().setContainer(tomcat.getEngine());  
     tomcat.setPort(8080);  
     tomcat.setBaseDir(".");  
     StandardHost stdHost = (StandardHost) tomcat.getHost();  
     stdHost.setAppBase(".");  
     stdHost.setAutoDeploy(true);  
     stdHost.setDeployOnStartup(true);  
     stdHost.setUnpackWARs(true);  
     tomcat.setHost(stdHost);  
     System.setProperty("javax.net.ssl.trustStore", "/home/waruna/Products/wso2is-4.7.0/repository/resources/security/wso2carbon.jks");  
     System.setProperty("javax.net.ssl.trustStorePassword",  
         "wso2carbon");  
     System.setProperty("javax.net.ssl.trustStoreType", "JKS");  
     try {  
       Context ctx = tomcat.addWebapp( tomcat.getHost() ,"/travelocity.com", "/home/waruna/tomcatembed/webapps/travelocity.com.war");  
       tomcat.start();  
       HTTPTestClient httpClient = new HTTPTestClient();  
       httpClient.loginToTravelocityApp();  
       tomcat.stop();  
     } catch (LifecycleException e) {  
       e.printStackTrace();  
     }  
   }  
 }  



Best thing in this approach is you do not need to have tomcat installed in your machine. Here I used following dependencies in my pom.xml.
     <dependency>  
       <groupId>org.apache.tomcat</groupId>  
       <artifactId>tomcat-catalina</artifactId>  
       <version>7.0.28</version>  
     </dependency>  
     <dependency>  
       <groupId>org.apache.tomcat.embed</groupId>  
       <artifactId>tomcat-embed-jasper</artifactId>  
       <version>7.0.28</version>  
     </dependency>  



2) Using Cargo Maven plugin

Cargo is an maven plug-in that I came across when I wanted to do this. You can find more on here. The issue I found here is that you need a running Tomcat container here which is really not matching my requirement.

3) Using Curl

curl -T "myapp.war" "http://manager:manager@localhost:8080/manager/text/deploy?path=/myapp&update=true"



this is again using running tomcat instance. There may be many other ways. Please do add them in comments.