官术网_书友最值得收藏!

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").

主站蜘蛛池模板: 沧州市| 东辽县| 杭锦旗| 吕梁市| 台南市| 子长县| 广安市| 柘荣县| 扎鲁特旗| 苗栗市| 德庆县| 秦皇岛市| 永靖县| 樟树市| 米脂县| 响水县| 卫辉市| 大宁县| 宜昌市| 大英县| 恭城| 永嘉县| 通山县| 荔波县| 玛纳斯县| 上栗县| 淮滨县| 安龙县| 定结县| 临城县| 巴林右旗| 松江区| 曲麻莱县| 冀州市| 临泽县| 永胜县| 凤翔县| 象州县| 沅陵县| 武汉市| 连城县|