- Practical Site Reliability Engineering
- Pethuru Raj Chelliah Shreyash Naithani Shailender Singh
- 226字
- 2021-06-10 19:08:10
Jersey Framework
Jersey is an open source framework developed by Oracle. It is the official reference implementation of JAX-RS API, which is very similar to Apache CFX. On the server side, Jersey provides a servlet implementation that scans through the predefined classes we define to identified the restful resources. In the web.xml file, which is the deployment file for web applications, we can configure either the restful servlet or the jersey servlet.
Jersey provides the implementation of the client library, which is fully compliant with the JAX-RS API. It also provides several tools for security such as authorization or bean validation. Furthermore, it allows us to integrate testing for container deployments. The current version of Jersey is 2.27. You can learn more about Jersey by going to its official website at http://jersey.java.net.
For Spring integration, we have to add the jersey-spring4 dependency, as follows:
<dependency>
<groupId>org.glassfish.jersey.ext</groupId>
<artifactId>jersey-spring4</artifactId>
<version>2.26</version>
</dependency>
Let's take a look at a basic example of how to implement the Jersey framework:
public class SimpleTest extends JerseyTest
{
@Path("hello")
public static class HelloResource
{
@GET
public String getHello()
{
return "Hello World!";
}
}
@Override
protected Application configure()
{
return new ResourceConfig(HelloResource.class)
}
@Test
public void test()
{
Response response = target("hello").request().get();
String hello = response.readEntity(String.class);
assertEquals("Hello World!", hello);
response.close();
}
}
The web request from projectURL/hello/ will match Hello World!, via @Path("/hello").
- 集成架構中型系統(tǒng)
- 大數(shù)據(jù)戰(zhàn)爭:人工智能時代不能不說的事
- Mastercam 2017數(shù)控加工自動編程經(jīng)典實例(第4版)
- 網(wǎng)頁編程技術
- 群體智能與數(shù)據(jù)挖掘
- Lightning Fast Animation in Element 3D
- Dreamweaver CS6精彩網(wǎng)頁制作與網(wǎng)站建設
- 教育機器人的風口:全球發(fā)展現(xiàn)狀及趨勢
- 單片機技能與實訓
- 大數(shù)據(jù)案例精析
- 網(wǎng)絡脆弱性掃描產(chǎn)品原理及應用
- Drupal高手建站技術手冊
- 從零開始學ASP.NET
- PyTorch深度學習
- 信息系統(tǒng)安全保障評估