Tuesday, December 17, 2019

Troubleshooting Key Manager WSO2

Hi all,

Today I am going to tell you something that helped me during support troubleshooting.

One of the most common API manager distribution patterns is the gateway and key manager separation. Now comes the problem.

What happens when a customer complains that the following use cases failing?


  • Token generation
  • API security
  • Slowness in token API


 You can do the following to determine this


  1. Enable %T in the Key Manager access log valve to print response time
  2. Enable client wire logs at the gateway
  3. Send curl request to simulate gateway to the key manager


From the above 3 options, the first 2 needs server restarts. But with 3rd option, you can easily do it in a production environment and troubleshoot. Nothing would be effected.

Let's check what are the important calls.

Wednesday, August 20, 2014

Run maven plugin in java code

This is some thing I wanted to do. My initial requirement was to run a maven plugin within a run time of another plugin.  So i found the way of running the maven plugin via java code.

Use Case

I wanted to integrate running soapui projects within integration tests in a WSO2 product run time. What I did was to have a separate pom.xml with the plugin configuration that I wanted to run and call it within a test case. The test case is executed by the maven surefire plugin.


Here is the sample code snipet.

 InvocationRequest request = new DefaultInvocationRequest();  
     request.setPomFile( new File(FrameworkPathUtil.getSystemResourceLocation() + "artifacts" +  
         File.separator + "AS" + File.separator + "soapprojects" +  
         File.separator + "pom" + File.separator + "pom.xml") );  
     request.setGoals(Arrays.asList("clean", "install"));  
     Invoker invoker = new DefaultInvoker();  
     invoker.setMavenHome(new File("/home/waruna/apache-maven-3.0.5"));  
     invoker.execute( request );  

Run soapui project using maven plugin

SoupUI is a very useful tool that you can  use for test web and other services. Users can create soapui project to send requests and do validations on that. We need to find a way to automate running these soapui projects, so that the test case writer can easily integrate many tests created with soapui to the existing maven projects. In the following steps we will describe how to automate running projects created with soapui within a maven project.

Create your soapui project


You have to create your soapui project first. In the example project we have given here, used existing wsdl files provided with echo and version services shipped with WSO2 ESB.  When you create project with soapui, you have to make sure to pick the option of creating test cases with it.


1.jpg

Add Assertions with soapui projects


You need to configure assertions which needs to be validated against the inputs given in the test cases. If assertion occurs you can view it within the maven build. To create assertion follow the document [1].

Configure maven project


Once you have finished creating soapui project and its assertions you have to save it. The output file will be in xml format. To run soapui project file we use the Maven Soapui Extension Plugin [2].  In this plugin you can run multiple soapui projects to run. In order to do that you have to set the goal as test-multi. Given below is the sample configuration for that.


 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
      xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">  
   <modelVersion>4.0.0</modelVersion>  
   <groupId>com.smartbear.samples</groupId>  
   <artifactId>soapui-maven2-plugin</artifactId>  
   <packaging>jar</packaging>  
   <version>1.0-SNAPSHOT</version>  
   <name>Maven 2 SoapUI Sample</name>  
   <url>http://maven.apache.org</url>  
   <pluginRepositories>  
     <pluginRepository>  
       <id>SmartBearPluginRepository</id>  
       <url>http://www.soapui.org/repository/maven2/</url>  
     </pluginRepository>  
   </pluginRepositories>  
   <build>  
     <plugins>  
       <plugin>  
         <groupId>com.github.redfish4ktc.soapui</groupId>  
         <artifactId>maven-soapui-extension-plugin</artifactId>  
         <version>4.6.4.1</version>  
         <executions>  
           <execution>  
             <id>soapUI1</id>  
             <phase>test</phase>  
             <goals>  
               <goal>test-multi</goal>  
             </goals>  
             <configuration>  
               <projectFiles>  
                 <scan>  
                   <baseDirectory>/home/waruna/workspace/soapuitest/src/main/resources/projects</baseDirectory>  
                   <includes>  
                     <include>*.xml</include>  
                   </includes>  
                   <excludes>  
                     <exclude>**/*fail-*-soapui-project.xml</exclude>  
                     <exclude>**/composite-projects/**</exclude>  
                   </excludes>  
                 </scan>  
               </projectFiles>  
               <outputFolder>/home/waruna/workspace/soapuitest/src/main/resources/</outputFolder>  
               <junitReport>true</junitReport>  
               <useOutputFolderPerProject>true</useOutputFolderPerProject>  
             </configuration>  
           </execution>  
         </executions>  
       </plugin>  
     </plugins>  
   </build>  
 </project>  
[2]http://mvnrepository.com/artifact/com.github.redfish4ktc.soapui/maven-soapui-extension-plugin

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.