I. General description
This example demonstrates how to use Jersey to build a RESTful service and how to persistently import data into MySQL through Hibernate.
II. Environment
1. RestDemo of the above project
2. MySQL5.6 download http://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.16-win32.zip
3. Hibernate4.3.4 download http://sourceforge.net/projects/hibernate/files/hibernate4/4.3.4.Final/hibernate-release-4.3.4.Final.zip
4. Java program connectio
The details of rest are not discussed here, but in general rest is a way for clients to interact with server segments by sending and receiving display resources, where it is necessary to explain:
Fielding is one of the core authors of the HTTP protocol and the Apache Web server. As an example:
An HTTP GET request can receive a resource
An HTTP POST request can generate a resource.
This description, may be
Jersey integrated Spring is relatively simple, the points to note are: 1. The introduction of Maven dependency jersey-spring, which contains spring dependencies, can be removed by exclusions if it conflicts with the spring version used in the project. 2, ensure that the Jersey resource class is located in the package path, can be scanned by spring, that is, the s
Maven DependenciesThe following Maven dependencies need to being added to the POM:Dependency> groupId>Com.sun.jerseygroupId> Artifactid>Jersey-serverArtifactid> version>1.19.1version>Dependency>Dependency> groupId>Com.sun.jerseygroupId> Artifactid>Jersey-grizzly2Artifactid> version>1.19.1version>Dependency>Creating a root resourceCreate the following Java class in your project: Packagecom.
Tags: console asc view ADE href dem SQL Server add NESFirst, the overall descriptionThis example performs a demonstration of building a RESTful service with Jersey. How to integrate Spring3Second, the environment
1. The above item Restdemo
2.Spring and other related jars, importing the project
Third, the configuration1. Create a Spring configuration file under the root folder applicationContext.xml ;Configuration such as the followin
Create a digital resource in a collectionCreate a child resource below.DELETE Deletes the entire collection of resources.Delete the digital resource labeled 1234.II: REST and JSR (Jersey)JSR-311 Java API for RESTful Web Services (JAX-RS) 1.0 and 1.1Jax-rs is a new technology that will be generated in Java EE 6. Jax-rs, the Java API for RESTful Web Services, is an application interface for the Java programm
Sometimes, we need to create a web service, but do not need to deploy it in a container. Instead, we need to run it like an application, listen to the port, parse the HTTP request, and send an HTTP response.
This can occupy less resources. For example, I have encountered a rented server that cannot be started by the Glassfish server due to the number of core threads. Many system service programs are implemented like this, such as Gerrit2.
Jersey also
Javax.ws.rs.core.MediaType; @Path ("/userservice") public class UserService {Userdao Userdao = new Userdao (); private static final String success_result= "Webservicetester (Write test client ourselves)Jersey allows us to implement our own test classes (Web Service Client)Import Java.util.list;import Javax.ws.rs.client.client;import Javax.ws.rs.client.clientbuilder;import Javax.ws.rs.client.entity;import Javax.ws.rs.core.form;import Javax.ws.rs.c
copy the jar files under Jersey-archive-1.18 \ Lib to the/hellorestworld/webcontent/WEB-INF/lib directory.
4. Create helloworld. Java with the following code:
packagecom.favccxx.favrestful;importjavax.ws.rs.GET;importjavax.ws.rs.Path;importjavax.ws.rs.Produces;importjavax.ws.rs.core.MediaType;@Path("/hello")publicclassHelloWorld{@GET@Produces(MediaType.TEXT_PLAIN)publicStringgetIt(){return"WelcometoJeyseyHelloWorld!";}}
5. modify web. xml and
I. Background Recently, Jersey Learning group Friends More and more, many friends ask some very basic questions, I think this phenomenon is widespread, because the students into the group are mostly Jersey beginners, and, worse, may be Java beginners, they take on rest WebService curiosity, broke into the jersey of the
(document document) {returndocument;}Both messagebodyreaders and Messagebodywriters are used in the this case, all we need be do POST request with some XML documen T as a request entity. I want to keep the as simple as possible so I ' m going to send only the root element with no content: " . You can create a Jersey client to do or use some the other tool, for example as curl I did. (curl -v http://localhost:9998/helloworld/1 -d "). You should get ex
As the processing power of the server becomes stronger and the business demand accumulates, more and more companies start from single server, single service to multi-server, multi-service and fast-expanding. Traditional methods are difficult to meet and respond to changes in the growth and deployment patterns of this business volume. As a best practice for distributed services, restful service has emerged.When it comes to restful Service, let's start by understanding his basic concept: it's an a
members of the resource collection.
put
post
delete
delete marked as1234 of digital resources.
JSR 311 (jax-rs) and Jersey
The proposal for a JSR 311 or jax-rs (Java API for RESTful Web Services) began in 2007, 1.0 and finalized in October 2008. Currently, JSR 311 version 1.1 is still in the draft phase. The goal of the JSR is to provide a set of APIs to simplify
The Jersey client API is a high-level Java based API for interoperating with RESTful Web services. It makes it very easy-to-interoperate with RESTful WEB services and enables a developer to concisely and efficiently imple ment A reusable client-side solution that leverages existing and well established Client-side HTTP implementations.The Jersey client API can be utilized to interoperate with any RESTful WE
As we all know, the Java service provider to the service requester should be a specific format of the data, but not the exception stack similar information, then jersey, how to add uniform exception handling?For Jersey booting if the implementation class implements the ResourceConfig interface, you can register the custom exception-handling class./*** Function Description: Unified exception Handling Filter
CXF, Restlet, Resteasy, jersey contrast
I. Description of requirements
Because of the need for the new system call interface to use the JSR311 Specification standard Rest Architecture Web service. Consider later in the product may often use the rest architecture of the webservice, for the mainstream implementation of the architecture for research, testing, com
Sometimes, we need to create a web service, but do not need to deploy it in a container. Instead, we need to run it like an application, listen to the port, parse the HTTP request, and send an HTTP response.
This can occupy less resources. For example, I have encountered a rented server that cannot be started by the glassfish Server due to the number of core threads. Many system service programs are implemented like this, such as gerrit2.
Jersey also
RESTful Web Services
REST was presented in 2000 by Roy Fielding in his doctoral dissertation, one of the chief authors of the HTTP Specification version 1.0 and 1.1.The most important concept in REST is resources, which are identified by using a global ID (usually a URI). The client application uses the HTTP method (Get/post/put/delete) to manipulate the resource or resource set. RESTful Web services are W
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.