After you integrate your web application with AHAS application protection, you can configure traffic control, degradation, and system protection rules to ensure system stability.
Procedure
Log on to the AHAS console.
In the upper-left corner of the AHAS console, select the region where your application is deployed.
In the left-side navigation pane, choose .
In the upper-right corner of the Application Protection page, click Add Application. On the Java tab, click SDK Access, and then click Web Application Access.
Add the application protection dependency to your web application using one of the following methods.
Add the following dependency to your web application's pom.xml file.
<dependency> <groupId>com.alibaba.csp</groupId> <artifactId>ahas-sentinel-client</artifactId> <version>x.y.z</version> </dependency>On the Web Application Access page, find the latest dependency version in the Step 1: Add Pom Dependency section. Replace
x.y.zwith the latest version number.
Add JAR package dependencies.
On the Web Application Access page, click Download to get the compressed package. Place all JAR files from this package into the classpath directory.
In the web.xml file, add the filter and configure it as the first filter. The following code shows an example:
<filter> <filter-name>SentinelCommonFilter</filter-name> <filter-class>com.alibaba.csp.sentinel.adapter.servlet.CommonFilter</filter-class> </filter> <filter-mapping> <filter-name>SentinelCommonFilter</filter-name> <!-- Configure the URL patterns to intercept. --> <url-pattern>/*</url-pattern> </filter-mapping>Configure the startup parameters for your application.
Category
Example configuration
internal network
-Dproject.name=AppName -Dahas.namespace=default -Dahas.regionId=<RegionId>NoteReplace AppName with your application's name.
Replace <RegionId> with the ID of the region where your application is deployed. For a list of regions and their corresponding region IDs, see the Regions and region IDs table in this topic.
public network
-Dproject.name=AppName -Dahas.license=<license> -Dahas.namespace=default -Dahas.regionId=cn-publicNoteReplace AppName with your application's name and replace <license> with your license key.
Applications on the public network require a license. Applications on an internal network do not. You can find your license in the Step 3: Configure startup parameters section. For more information, see View the license.

Optional: You can set a custom redirect URL in the following two ways. When a request triggers traffic control, degradation, or a system protection rule, the request is automatically redirected to the specified URL.
Call the
WebServletConfig.setBlockPage(blockPage)method to set a custom redirect URL.Implement the UrlBlockHandler interface to define custom blocking logic, and then register the logic with WebCallbackManager. For more information, see Web Servlet Filter extension interface.
NoteBy default, when a traffic control, degradation, or system protection rule blocks a request, AHAS returns a default page with the following message:
Blocked by Sentinel (flow limiting).Optional: You can customize URL cleanup to prevent an excessive accumulation of REST-style URLs, such as
/payment/{id}, from affecting system performance. There are two ways to configure URL cleanup:Implement the UrlCleaner interface to define custom URL normalization logic. For more information, see Web Servlet Filter.
Configure prefix-based cleaning by using a properties file.
In the properties file, define rules using the format 'matching prefix=normalized resource name', for example, /payment/=/payment/*. Then, specify the configuration file path by using the
-Dcsp.sentinel.url.clean.config.pathstartup parameter.NoteBy default, the startup parameter points to the ahas-sentinel-url-clean.properties file, which is expected to be in the same directory as the JAR package. The startup parameter supports the classpath format. For example:
-Dcsp.sentinel.url.clean.config.path=classpath:ahas-sentinel-url-clean.properties.
Verify the integration
Log on to the AHAS console. In the left-side navigation pane, choose . The integration is successful if the application card for your application appears on the Application Protection page and reports data.

Regions and region IDs
Region | Region ID |
public network | cn-public |
China (Hangzhou) | cn-hangzhou |
China (Shanghai) | cn-shanghai |
China (Beijing) | cn-beijing |
China (Zhangjiakou) | cn-zhangjiakou |
China (Shenzhen) | cn-shenzhen |
Singapore | ap-southeast-1 |
Germany (Frankfurt) | eu-central-1 |