Skip to content

Latest commit

 

History

History
117 lines (98 loc) · 4.26 KB

README.md

File metadata and controls

117 lines (98 loc) · 4.26 KB

API Access Tracker (Java Client)

Java CI with Maven

This is the supporting Java client for API Access Tracker.

This Java client in conjunction with the API Access Tracker (Backend) can be used to log all request and response data for your webservices APIs. If you want to log all the requests coming to your webservices you can use API Access Tracker.

API Access Tracker stores all the request details of API calls made to your webservices to AWS using serverless technologies such as AWS DynamoDB, AWS Lambda, AWS SQS etc.

This README will not detail into how API Access Tracker works, but will describe setup of this Java client too allow you to start pushing data too AWS Stack created by API Access Tracker (Backend).

How this client works?

This client contains a simple Http Servlet filter, which when setup correctly, intercepts all the requests coming to your APIs, and publishes them to the AWS SQS created by API Access Tracker (Backend). Before starting to use this client, you must follow steps described in API Access Tracker (Backend) to setup your AWS Stack.

Getting Started

Follow below steps to setup API Access Tracker.

  • Setup API Access Tracker (Backend)
  • Create an AWS IAM user that has access to AWS SQS queues generated by API Access Tracker (Backend). You can use below policy for reference.
{
 "Version": "2012-10-17",
 "Statement": [
   {
     "Sid": "VisualEditor0",
     "Effect": "Allow",
     "Action": [
       "sqs:GetQueueUrl",
       "sqs:SendMessage",
       "sqs:CreateQueue"
     ],
     "Resource": "arn:aws:sqs:us-east-1:<Your-AWS-Account-ID>:aal_*"
   }
 ]
}
  • Add this API Access Tracker (Java Client) to you Java project.

For Maven Project

<dependency>
  <groupId>com.actigence</groupId>
  <artifactId>api-access-tracker-java-client</artifactId>
  <version>0.0.1</version>
</dependency>

For Gradle Project

plugins {
id 'maven'
}

dependencies {
implementation 'com.actigence:api-access-tracker-java-client:0.0.1'
}
  • Configure request filter to intercept desired URLs.

For projects build using Spring Boot add below configuration file:

@Configuration
public class FilterConfiguration
{

    @Bean
    public FilterRegistrationBean<ApiAccessLoggingFilter> loggingFilter()
    {
        FilterRegistrationBean<ApiAccessLoggingFilter> registrationBean = new FilterRegistrationBean<>();
        registrationBean.setFilter(new ApiAccessLoggingFilter());
        registrationBean.addUrlPatterns("/test/*");
        registrationBean.addInitParameter("clientId", "MyServiceName");
        return registrationBean;
    }
}

For projects built using Java Servlets:

<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE web-app
        PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN"
        "http://java.sun.com/j2ee/dtds/web-app_2_2.dtd">

<web-app>

    <filter>
        <filter-name>API Access Tracking Filter</filter-name>
        <filter-class>com.actigence.aal.ApiAccessLoggingFilter</filter-class>
        <init-param>
            <param-name>clientId</param-name>
            <param-value>MyServiceName</param-value>
        </init-param>
    </filter>
    
    <filter-mapping>
        <filter-name>API Access Tracking Filter</filter-name>
        <url-pattern>/test/*</url-pattern>
    </filter-mapping>

</web-app>

That's it. Now any request made to your webservice APIs at the configured URLs will be intercepted and you will be able to see entries in AWS DynamoDB tables.

Limitations

  • Minimum Java version 8 is required.
  • AWS SQS has limit of maximum payload size of 256 KB. Hence combined data of request and response values can not be more than 256 KB.