Skip to main content

Creating a JMeter test plan for an API invocation through WSO2 API Manager

The use-case :
  • Create an API for a REST endpoint and publish it from API-Publisher app
  • Then subscribe to it from API-Store app and generate a key
  • Finally create a test-paln from jmeter to this API invocation with using OAuth access token.
Pre-Requesties :


Steps :
  1. Deploy the backend JAX-RS Endpoint    
  • First download and extract above two servers and to run both servers simultaneously,change one server's port offset to 1 by navigating to {Product_Home}/repository/conf/carbon.xml .
  • Then download the sample JAX-RS war file from checking out it from here and deploy it to WSO2 AS -4.1.2  
  • This sample JAX-RS contains three REST endpoints and here I'm going to use its endpoint of getting menu list as '/pizzashack-api-1.0.0/api/menu/'.Once you deployed the war file,you can check accessing   'http://yourip:port/pizzashack-api-1.0.0/api/menu/'  from browser whether you get a successful json response or not.

     2.  Create the API for backend JAX-RS endpoint
  • Browse api-publisher web UI from browser and create a new API with setting its endpoint as  'http://yourip:port/pizzashack-api-1.0.0/api/menu/
Add API
       
  • Publish it to API-Store.
Publish API
     
  • From API-Store,subscribe the created API to an application and generate an access token.So now you are ready to invoke the API.


Subscribe to API
User Subscriptions

     3.  Create JMeter Test Plan
  • Start jmeter with jmeter.sh script and browse jmeter UI. Add a new test-pan.
  • First add a new thread group by navigate to Add->Threads (Users) ->Thread Group  
         


  • Since we are going to send a RESTful[HTTP] request to the create API,click on thread group ,select the   sampler as HTTP Request and add the ip address,port and path accordingly as shown in below image.
          From this example we are doing a GET request.So no need of request parameters.
Add HTTP Request
After setting REST URL for the request
                              
  • Then we need to add the access token for request header.That can be done by adding the config element called 'HTTP Header Manager' to the thread group as below.
Add HTTP Header Manager



  • Then click on 'add' button of the  'HTTP Header Manager' UI and add ;
         header name -"Authorization"
         value            - "Bearer "+accessToken
        
After adding the authorization header

  • Now we have finished configuring test-plan,save all of them and now remaining is running the test-plan.To collect test running results you can add a Listener for thread group as 'View Results Tree' or 'View Results Table' or either graph.Just change number of threads/iterations and see how the average time,other performance values varying on each.
                                        


  • You can find the above created JMeter test plan by checking out it from here.

Comments

  1. Any idea on how to work with oAuth2 authentication for cloud based application using JMeter?

    ReplyDelete

Post a Comment

Popular posts from this blog

Convert an InputStream to XML

For that we can use DocumentBuilder class in java. By using the method parse(InputStream) ; A new DOM Document object will return. InputStream input; DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder parser = factory.newDocumentBuilder(); Document dc= parser.parse(input); In the above code segment,by using the created Document object,the corresponding XML file for the inputStream can be accessed. References: http://www.w3schools.com/dom/dom_intro.asp http:// download.oracle.com/javase/1.4.2/docs/api/javax/xml/parsers/DocumentBuilder.html

CORS support from WSO2 API Manager 2.0.0

Cross-origin resource sharing (CORS) is a mechanism that allows restricted resources  on a web page to be requested from another domain outside the domain from which the first restricted resource was served. For example, an HTML page of a web application served from http://domain-a.com makes an <img src >  request for a different domain as 'domain-b.com' to get an image via an API request.  For security reasons, browsers restrict cross-origin HTTP requests initiated from within scripts as in above example and only allows to make HTTP requests to its own domain. To avoid this limitation modern browsers have been used CORS standard to allow cross domain requests. Modern browsers use CORS in an API container - such as  XMLHttpRequest  or Fetch - to mitigate risks of cross-origin HTTP requests.Thing to  note is it's not only sufficient that the browsers handle client side of cross-origin sharing,but also the servers from which these resources getting need to handl

[WSO2 AM] APIStore User Signup as an approval process

In previous versions of WSO2 APIManager before 1.6.0, it was allowed any user who's accessible the running APIStore come and register to the app.But there will be requirement like,without allowing any user to signup by him/her self alone,first get an approve by a privileged user and then allow to complete app registration.Same requirement can be apply to application creation and subscription creation as well.To fulfill that,we have introduced workflow extension support for  WSO2 APIManager  and you can find the introductory post on this feature from my previous blog post on " workflow-extentions-with-wso2-am-160 " . From this blog-post,I'll explain how to achieve simple workflow integration with default shipped resources with  WSO2 APIManager 1.6.0 and WSO2 Business Process Server 3.1.0 with targeting "user-signup" process. Steps First download the WSO2 APIManager 1.6.0[AM] binary pack from product download page . Extract it and navigate to