Come unto me all ye who are weary of heavy-laden clients and I will give you REST.
Continued from GWT with JAX-RS (aka RPC/REST) Part 2
OK, the cast of the technology mix is
- JAX-RS (either Resteasy or Jersey on the server side)
- JAX-RS + GWT = RestyGWT on the client-side
- JPA on the server-side
- JAXB over JAX-RS on both GWT client and server-side.
- Jackson JSON processor on server-side.
I feel those acronyms are intimidating, but they are actually not difficult to implement. If you could understand the intricacies of GWT-RPC, you should have no problem understanding the soup mix above.
JPA remains to be the most difficult part of the mix to learn/master (most difficult but not difficult). Mastering GWT is actually the more difficult part than JPA. However, if you have no desire for your server to connect to a JDBC-enabled database, you do not need to concern with JPA.
This is your JAX-RS POJO:
@XmlAccessorType(XmlAccessType.FIELD) @XmlRootElement (name="employee") public class Employee implements Serializable { @XmlAttribute private Long eid = null; @XmlAttribute private String name = null; }This is the same POJO, if your app is obsessed with the order of appearance:
@XmlAccessorType(XmlAccessType.FIELD) @XmlRootElement (name="employee") @XmlType(propOrder = { "eid", "name" } public class Employee implements Serializable { @XmlAttribute private Long eid = null; @XmlAttribute private String name = null; }This is the POJO with public getters/setters (generated by Eclipse) so to enable RestyGWT to operate on it. Hoever, RestyGWT would not need the public getters/setters if the fields are public instead of private.
@XmlAccessorType(XmlAccessType.FIELD) @XmlRootElement (name="employee") @XmlType(propOrder = { "eid", "name" } public class Employee implements Serializable { @XmlAttribute private Long eid = null; @XmlAttribute private String name = null; public Long getEid() { return eid; } public void setEid (Long eid ) { this. eid = eid ; } public String getName () { return name ; } public void setName (String name ) { this. name = name ; } }And finally, this is your Three-in-one POJO to accommodate JPA.
@Entity @Table(name="Employee", schema="bombay") @XmlAccessorType(XmlAccessType.FIELD) @XmlRootElement (name="employee") @XmlType(propOrder = { "eid", "name" } public class Employee implements Serializable { @XmlAttribute @Id private Long eid = null; @XmlAttribute private String name = null; public Long getEid() { return eid; } public void setEid (Long eid ) { this. eid = eid ; } public String getName () { return name ; } public void setName (String name ) { this. name = name ; } }Let's create another POJO:
@XmlAccessorType(XmlAccessType.FIELD) @XmlRootElement (name="employees") public class EmployeeList { @XmlElement(name="enployee") private List<Employee> employees; public List<Employee> getEmployees() { if (employees==null) employees = new ArrayList<Employee>(); return employees; } public void setEmployees(List<Employee> employees) { this.employees = employees; } }But, WHERE's THE JSON? JSON output will be borrowing the JAXB XML annotation. The following is the server side service API interface.
@Path("/employee") @Produces({"application/xml", "application/json"}) public interface EmployeeServiceAPI { /** * Find all employee ids with the given name */ @GET @Path("/eids/name") LongList getEmployeeIdsWithName(@QueryParam ("name")String name) ; /** * Get employee wit Id */ @GET @Path("/employee/{id}") Employee getEmployeeWithId(@PathParam ("eid")Long eid) ; /** * Get project list for an employee */ @POST @Path("/projects/employee") ProjectList getProjects(Employee employee) ; }And this is the async service API on the GWT Client.
@Path("/employee") @Consumes({"application/json"}) // put in a http header to tell server to return me JSON public interface EmployeeServiceAPI { /** * Find all employee ids with the given name */ @GET @Path("/eids/name") LongList getEmployeeIdsWithName(@QueryParam ("name")String name, MethodCallback <LongList > callback) ; /** * Get employee wit Id */ @GET @Path("/employee/{id}") Employee getEmployeeWithId(@PathParam ("eid")Long eid, MethodCallback <Employee > callback) ; /** * Get project list for an employee */ @POST @Path("/projects/employee") ProjectList getProjects(Employee employee, MethodCallback <ProjectList > callback) ; }The server-side implementation to access the database.
public class EmployeeServiceAPIImpl implements EmployeeServiceAPI { @Override public Employee getEmployeeIdsWithName(Long eid) { Employee emp = new Employee(); EntityManager em = null; try { em = EMF.get().createEntityManager(); Query q = em.createQuery( "SELECT n FROM Employee n WHERE n.status = 'active' AND n.eid = ?1" ).setParameter(1, eid); Employee emp = q.getSingleResult(); return emp; } finally{ if (em!=null) em.close(); } } ...... }This is how your GWT client will call the async REST service:
public class EmployeePresenter{ static public EmployeeAsyncServiceAPI enpServiceAPI = GWT.create(EmployeeAsyncServiceAPI.class); public void search(Long eid) { enpServiceAPI.getEmployeeIdsWithName(eid, new EmployeeCallBack()); } public class EmployeeCallBack implements MethodCallbackLet's say function search(Long eid) got called as{ @Override public void onFailure(Method method, Throwable exception) { Window.alert("Error accessing data"); } @Override public void onSuccess(Method method, Employee response) { EmployeePresenter.this.view.setEmployeeRecords( response.getEmployee()); if (response.getEmployee().size()==0) { Window.alert("No records found"); } } } }
search(12529);RestyGWT code generated by GWT.create() will send this request over the URL
/employee/employee/12529RestyGWT would find the phrase in the async service API
@Consumes({"application/json"})and proceeds to place a header in the HTTP request
Accepts: application/jsonWhen the RestEasy Listener intercepts the request, it would search for the class implementing EmployeeServiceAPI and finds EmployeeServiceAPIImpl. RestEasy loads that class which proceeds to service the request.
Therefore, you could use the browser to debug your web service independent of the GWT client.
You could use python or PHP to poke the server too. May be, your QA hates Java and loves PHP - so he/she could write unit tests using PHP.
Furthermore, now, you do not have to bother with SmartGWT XML or JSON datasource and you can take full control over your POJO datasource. It's really frustrating to have to take lots of time going thro nooks and corners whenever you need to tweak your datasource a lil' bit. Now you don't have to.
Here is your web.xml to tell RestEasy to do its strut.
<web-app> <display-name>Employee Service</display-name> <!-- Auto scan REST service --> <context-param> <param-name>resteasy.scan</param-name> <param-value>true</param-value> </context-param> <!-- this need same with resteasy servlet url-pattern --> <context-param> <param-name>resteasy.servlet.mapping.prefix</param-name> <param-value>/CurryMuttonOilDrilling/</param-value> </context-param> <listener> <listener-class> org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap </listener-class> </listener> <servlet> <servlet-name>resteasy-servlet</servlet-name> <servlet-class>org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>resteasy-servlet</servlet-name> <url-pattern>/CurryMuttonOilDrilling/*</url-pattern> </servlet-mapping> </web-app>Therefore, according to the web.xml, the actual URL path sent to the server is:
/CurryMuttonOilDrilling/employee/employee/12529
And notice the presence of Jackson json provider in the following maven dependency?
<properties> <resteasy.version>2.3.4.Final</resteasy.version> <gwt.version>2.4.0</gwt.version> </properties> <repositories> <repository> <id>fusesource-snapshots</id> <name>Fusesource Snapshots</name> <url>http://repo.fusesource.com/nexus/content/repositories/snapshots</url> <snapshots><enabled>true</enabled></snapshots> <releases><enabled>false</enabled></releases> </repository> </repositories> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.10</version> <scope>test</scope> </dependency> <dependency> <groupId>javax.validation</groupId> <artifactId>validation-api</artifactId> <version>1.0.0.GA</version> </dependency> <dependency> <groupId>com.google.gwt</groupId> <artifactId>gwt-user</artifactId> <version>${gwt.version}</version> </dependency> <dependency> <groupId>com.sencha.gxt</groupId> <artifactId>gxt</artifactId> <version>2.2.5-gwt22</version> <scope>system</scope> <systemPath>${project.basedir}/lib/GWT/gxt-2.2.5-gwt22.jar</systemPath> </dependency> <dependency> <groupId>com.googlecode.mvp4g</groupId> <artifactId>mvp4g</artifactId> <version>1.4.0</version> </dependency> <dependency> <groupId>org.jboss.resteasy</groupId> <artifactId>resteasy-jaxrs</artifactId> <version>${resteasy.version}</version> <type>jar</type> </dependency> <dependency> <groupId>org.jboss.resteasy</groupId> <artifactId>resteasy-jaxb-provider</artifactId> <version>${resteasy.version}</version> </dependency> <dependency> <groupId>org.jboss.resteasy</groupId> <artifactId>resteasy-jackson-provider</artifactId> <version>${resteasy.version}</version> </dependency> <dependency> <groupId>org.fusesource.restygwt</groupId> <artifactId>restygwt</artifactId> <version>1.3-SNAPSHOT</version> </dependency> <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-entitymanager</artifactId> <version>3.6.10.Final</version> </dependency> <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-validator</artifactId> <version>4.3.0.Final</version> </dependency> <dependency> <groupId>com.google.guava</groupId> <artifactId>guava-gwt</artifactId> <version>13.0-rc1</version> </dependency> <!--dependency> <groupId>com.sun.faces</groupId> <artifactId>mojarra-jsf-api</artifactId> <version>2.0.0-b04</version> </dependency> <dependency> <groupId>com.sun.faces</groupId> <artifactId>mojarra-jsf-impl</artifactId> <version>2.0.0-b04</version> </dependency -->
20160622meiqing
ReplyDeletetimberland boots
skechers shoes
coach outlet
louis vuitton outlet
oakley sunglasses
louis vuitton bags
supra shoes
yeezy boost 350 black
nike air max shoes
north face jackets
louis vuitton handbags
michael kors outlet clearance
louis vuitton factory outlet
supra for sale
kate spade outlet
lacoste outlet
converse shoes
true religion jeans
ray ban sunglasses discount
coach outlet
oakley sunglasses
christian louboutin outlet
true religion jeans
oakley sunglasses
nike store
ralph lauren outlet
abercrombie and fitch
cartier love bracelet
birkenstock sandals
hermes uk
michael kors outlet
michael kors outlet
gucci borse
ray ban sunglasses
mont blanc pens
canada goose jackets
ReplyDeletedolce and gabbana outlet online
michael kors outlet store
ray ban sunglasses discount
adidas superstar
louis vuitton outlet online
michael kors outlet store
polo ralph lauren
michael kors outlet store
birkenstock uk
zhi20161130
adidas sneakers
ReplyDeletenike air max 95
pandora bracelet
longchamp pliage
cheap air max
adidas nmd runner
louis vuitton outlet online
hollister clothing
michael kors outlet store
oakley sunglasses cheap
2017220yuanyuan
adidas yeezy
ReplyDeletecurry 5
basketball shoes
michael kors
dior sunglasses
supreme clothing
adidas tubular
jordan retro 13
jordan 6
off white hoodie
ReplyDeleteIt seems you are so busy in last month. The detail you shared about your work and it is really impressive that's why i am waiting for your post because i get the new ideas over here and you really write so well.
Selenium training in Chennai
Attend The Python Training in Bangalore From ExcelR. Practical Python Training in Bangalore Sessions With Assured Placement Support From Experienced Faculty. ExcelR Offers The Python Training in Bangalore.
ReplyDeleteGreat post!
ReplyDeleteThanks for sharing this list!
It helps me a lot finding a relevant blog in my niche!
Java Training in Chennai
Java Training in Coimbatore
Java Training in Bangalore
I have been reading all your blogs regularly..I admit, this is one of the best blogs I have read till date. Great going.. Waiting for the next...
ReplyDeleteSpoken English Classes in Chennai
Best Spoken English Classes in Chennai
IELTS Coaching in Chennai
IELTS Coaching Centre in Chennai
English Speaking Classes in Mumbai
English Speaking Course in Mumbai
IELTS Classes in Mumbai
IELTS Coaching in Mumbai
IELTS Coaching in Anna Nagar
Spoken English Class in Anna Nagar
ReplyDeleteThis post is so interactive and informative. Thanks for sharing this great blog keep update more information
Data Science Course in Chennai
Data Science Training in Chennai
Data Science Courses in Bangalore
Data science course in coimbatore
Best data science courses in bangalore
Data science institute in bangalore
Data Science Training Institutes in Bangalore
Ethical hacking course in bangalore
Great experience for me by reading this blog. Thank you for wonderful article.
ReplyDeleteAngularjs Training in Chennai
Angularjs Training in Bangalore
angularjs training institute in bangalore
Angular 2 Training in Chennai
best angularjs training in bangalore
Angularjs course in Chennai
dot net training institutes in bangalore
php course in coimbatore
Attend The Data Analytics Courses in Bangalore From ExcelR. Practical Data Analytics Courses in Bangalore Sessions With Assured Placement Support From Experienced Faculty. ExcelR Offers The Data Analytics Courses in Bangalore.
ReplyDeleteExcelR Data Analytics Courses in Bangalore
I Really appreciate, this wonderful post that you have provided for peoples. Its really good. Nice information. Keep posting!! Artificial Intelligence Course
ReplyDeleteVery nice post here and thanks for it .I like this blog and really good content.
ReplyDeleteData Analytics Courses in Chennai
Big Data Analytics Courses in Chennai
IELTS Coaching in Chennai
Japanese Classes in Chennai
Spoken English Classes in Chennai
spanish classes in chennai
content writing course in chennai
Data Analytics Courses in Velachery
Data Analytics Courses in T Nagar
Great Article
ReplyDeleteData Mining Projects
Python Training in Chennai
Project Centers in Chennai
Python Training in Chennai
ReplyDeleteAmazing Post. keep update more information.
German Classes in Chennai
German Classes in Bangalore
German Classes in Coimbatore
German Classes in Madurai
German Language Course in Hyderabad
German Language Course in Chennai
German language course in bangalore
German language course in coimbatore
Selenium Training in Bangalore
Software Testing Course in Bangalore
Great post and huge of good info. Thank you much more for giving useful details.
ReplyDeleteJMeter Training in Chennai
JMeter Training Institute in Chennai
Power BI Training in Chennai
Graphic Design Courses in Chennai
Pega Training in Chennai
Linux Training in Chennai
Corporate Training in Chennai
Tableau Training in Chennai
Oracle Training in Chennai
JMeter Training in Anna Nagar
ReplyDeleteWow it is really wonderful and awesome thus it is veWow, it is really wonderful and awesome thus it is very much useful for me to understand many concepts and helped me a lot. devops training in chennai | devops training in anna nagar | devops training in omr | devops training in porur | devops training in tambaram | devops training in velachery
You are including better information regarding this topic in an effective way. T hank you so much.
ReplyDeleteit was a wonderful
Dot Net Training in Chennai | Dot Net Training in anna nagar | Dot Net Training in omr | Dot Net Training in porur | Dot Net Training in tambaram | Dot Net Training in velachery
Great post i must say and thanks for the information. Education is definitely a sticky subject. However, is still among the leading topics of our time. I appreciate your post and look forward to more.
ReplyDeleteData Science Institute in Bangalore
It's late finding this act. At least, it's a thing to be familiar with that there are such events exist. I agree with your Blog and I will be back to inspect it more in the future so please keep up your act.
ReplyDeleteData Science Course in Bangalore
Very impressed your article.
ReplyDeletePython Training in Chennai
Python Training in Bangalore
Python Training in Hyderabad
Python Training in Coimbatore
Python Training
python online training
python flask training
python flask online training
360DigiTMG, Indore is a leading solutions provider of Training and Consulting to assist students, professionals by delivering top-notch, world-class classroom and online training. It offers data science course in indore.
ReplyDeletegolden goose
ReplyDeletegolden goose
balenciaga
golden goose
goyard handbags
yeezy
supreme clothing
golden goose outlet
goyard handbags
golden goose outlet
This is a great post, despite how much detail it contains, this style of articles keeps users interested in the website and keeps sharing more ... Good luck.data science course in malaysia
ReplyDeleteReally nice and interesting post. I was looking for this kind of information and enjoyed reading this one. Keep posting. Thanks for sharing.
ReplyDeleteeducational course
Truly amazing post found to be very impressive while going through this post with a complete description. Thanks for sharing and keep posting such an informative content.
ReplyDeleteData Science Course in Raipur
Wonderful blog with great piece of information. Regards to your effort. Keep sharing more such blogs.
ReplyDeleteLooking forward to learn more from you.
angular js training in chennai
angular js training in porur
full stack training in chennai
full stack training in porur
php training in chennai
php training in porur
photoshop training in chennai
photoshop training in porur
These musings just knocked my socks off. I am happy you have posted this.
ReplyDeletedata science course in noida
I truly like only reading every one your web logs. Simply desired to in form you which you simply have persons such as me that love your own work out. Absolutely an extraordinary informative article. Hats off to you! The details which you have furnished is quite valuable. Tableau Course in Bangalore
ReplyDeleteExcellent blog,i found some useful information from this blog, waiting for new updates.
ReplyDeleteHadoop Training in Anna Nagar
Hadoop Training in Porur
Hadoop Training in OMR
Hadoop Training in T Nagar
Really, it’s a useful blog. Thanks for sharing this information.
ReplyDeleteR programming Training in Chennai
Xamarin Course in Chennai
Ionic Course in Chennai
ReactJS Training in Chennai
PLC Training in Chennai
Your blog is very informative. Thanks for sharing the valuable information.
ReplyDeleteSEO Training in Anna Nagar
SEO Training in Velachery
SEO Training in OMR
SEO Training in T Nagar
SEO Training in Porur
Nice blog, Thanks for sharing this useful information.
ReplyDeleteC C++ Training in Chennai
c programming classes in coimbatore
Mobile Application Testing Online Training
Mobile App Development Online Course
Mobile App Development Courses in Chennai
Google Analytics Online Course
Google Analytics Training in Chennai
Content Writing Course in Chennai
Online Content Writing Course
This is a great inspiring article.I am pretty much pleased with your good work.You put really very helpful information...
ReplyDeletebusiness analytics course
First You got a great blog .I will be interested in more similar topics. i see you got really very useful topics, i will be always checking your blog thanks.
ReplyDeletebusiness analytics course
it is often compared to Lisp, Tcl, Perl, Ruby, C#, Visual Basic, Visual Fox Pro, Scheme or Java. It can be easily interfaced with C/ObjC/Java/Fortran. It runs on all major operating systems such as Windows, Linux/Unix, OS/2, Mac, Amiga, etc. Day by day we can see a rapid growth in Python Development. data science course in india
ReplyDeleteSo luck to come across your excellent blog. Your blog brings me a great deal of fun.. Good luck with the site.
ReplyDeletebusiness analytics course
Really good information, well written article. Thanks for sharing an article.
ReplyDeletecommon seo mistakes
scope of ai
angular js plugins
advantages of rpa
angularjs interview questions
software testing interview question and answer
This is one of the best content for this topic and this is very useful for me. Thank you!
ReplyDeleteUnix Training in Chennai
Unix Course in Chennai
Linux Course in Chennai
thank you for your information
ReplyDeletePython Training in chennai | Python Classes in Chennai
Mua vé tại Aivivu, tham khảo
ReplyDeletevé máy bay đi Mỹ giá rẻ 2021
vé máy bay hà nội sài gòn tháng 5
vé máy bay đà lạt - hà nội
hà nội nha trang bao nhiêu km
đặt vé máy bay đi bình định
taxi sân bay nội bài
ReplyDeleteVery awesome!!! When I searched for this I found this website at the top of all blogs in search engines.
Best Digital Marketing Courses in Hyderabad
Thanks for sharing nice information....
ReplyDeleteai course in pune
What an incredible message this is. Truly one of the best posts I have ever seen in my life. Wow, keep it up.
ReplyDeleteData Science Training in Bangalore
Your work is very good and I appreciate you and hopping for some more informative posts
ReplyDeletedata scientist certification malaysia
Thanks for sharing this information. I really like your blog post very much. You have really shared a informative and interesting blog post .
ReplyDeletedata analytics courses in hyderabad with placements
ReplyDeleteThis post is so interactive and informative.keep update more information…
IELTS Coaching in anna nagar
IELTS Coaching in Chennai
I am a new user of this site so here i saw multiple articles and posts posted by this site,I curious more interest in some of them hope you will give more information on this topics in your next articles.
ReplyDeleteVery nice information. Thank you for sharing this valauble information with us.
ReplyDeleteThirukkural pdf
Sai Satcharitra in English pdf
Sai Satcharitra in Tamil pdf
Sai Satcharitra in Telugu pdf
Sai Satcharitra in Hindi pdf
There are also varieties of options available to choose a career in data science, like you can become a data scientist, developer, data engineer, analyst, database administrator, and many more.
ReplyDeletedata science training in patna
360DigiTMG is the top-rated institute for Data Science in Bangalore and it has been awarded as the best training institute by Brand Icon. Click the link below to know about fee details.
ReplyDeleteData Science Course in Bangalore
Data Science handles structured and unstructured and data that is generated at an unprecedented rate every day. Anyone with a strong statistical background and an analytical mindset enjoys the challenges of big data that involves building data models and software platforms along with creating attractive visualizations and machine learning algorithms. Sign up for the Data Science courses in Bangalore with Placements and get access to resume building and mock interviews that will help you get placed with top brands in this field.
ReplyDeleteData Science Course in Bangalore with Placement
my blog check my blog navigate to these guys additional reading navigate to this site my site
ReplyDeletehave a peek at this web-site buy replica bags imp source Ysl replica handbags about his dolabuy.su
ReplyDeleteAvast Secureline VPN 5.13.5702 Crack is a privacy and internet security software. It protects user data and operating systems from potential malware attach. Avast Secureline VPN License Key
ReplyDeleteInternet Download Manager is the world's most famous downloader in the current era. The popularity of this downloader has been increasing day by da Download Tally ERP 9 With GST Crack Version
ReplyDeleteReally a awesome blog for the freshers. Thanks for posting the information. Discover the world's best GCSE home tuition with Ziyyara Edutech! Our dedicated GCSE online tuition is designed to empower students with exceptional educational support.
ReplyDeleteFor more info visit Home tuition of GCSE
Nice blog.
ReplyDeletejoin Java classes in Pune