Thursday, June 9, 2016
Friday, June 3, 2016
Loosely Coupled Systems
Loose coupling is a little bit like buying insurance. It's best when you don't need it, even though you might feel like you wasted the money.
Ex: which component invokes which one ?
“How do you make two systems loosely coupled? Don't connect them.” -- David Orchard, BEA
Thursday, June 2, 2016
JSON Object with JAX RS
MessageRestService.java
Reference link 1, link 2, link 3
package com.jeetu.rest; import com.google.gson.Gson; import org.json.JSONException; import org.json.JSONObject; import javax.ws.rs.*; import javax.ws.rs.core.Response; import java.util.LinkedHashMap; import java.util.Map; @Path("/message") public class MessageRestService { @POST @Path("/sendParams") @Consumes("application/json") public Response consumeJSONParams( MapStudent.javastudent ) { /* POST-MAN http://jbosseap.jeetualex.info/rest/message/sendParams Body raw = {"id":"12","firstName":"Catain","lastName":"Hook","age":"10", "params":{"a": 1, "b": 2}} Content-Type = application/json */ LinkedHashMap params = null; String id = ""; id = (String) student.get("id"); params = (LinkedHashMap) student.get("params"); return Response.status(200).entity(params.toString()).build(); } @POST @Path("/sendMapper") @Consumes("application/json") public Response consumeJSONMapper( String student ) { /* POST-MAN http://jbosseap.jeetualex.info/rest/message/sendMapper Body raw = {"id":"12","firstName":"Catain","lastName":"Hook","age":"10", "params":{"a": 1, "b": 2}} Content-Type = application/json */ JSONObject output = null; JSONObject params = null; String id = ""; try { output = new JSONObject(student); id = (String) output.get("id"); params = output.getJSONObject("params"); } catch (JSONException e) { e.printStackTrace(); } //return Response.status(200).entity(output.toString()).build(); //return Response.status(200).entity(id).build(); return Response.status(200).entity(params.toString()).build(); } @POST @Path("/sendRequest") @Consumes("application/json") public Response consumeJSONRequest( String student ) { /* POST-MAN http://jbosseap.jeetualex.info/rest/message/sendRequest Body raw = {"id":"12","firstName":"Catain","lastName":"Hook","age":"10"} Content-Type = application/json */ Gson gson = new Gson(); Student output = gson.fromJson(student, Student.class); return Response.status(200).entity(gson.toJson(output)).build(); } @POST @Path("/sendString") @Consumes("application/json") public Response consumeJSONString( String student ) { /* POST-MAN http://jbosseap.jeetualex.info/rest/message/sendString Body raw = {"id":"12","firstName":"Catain","lastName":"Hook","age":"10"} Content-Type = application/json */ Gson gson = new Gson(); Student output = gson.fromJson(student, Student.class); return Response.status(200).entity(output).build(); } @POST @Path("/send") @Consumes("application/json") public Response consumeJSON( Student student ) { /* POST-MAN http://jbosseap.jeetualex.info/rest/message/send Body raw = {"id":"12","firstName":"Catain","lastName":"Hook","age":"10"} Content-Type = application/json */ String output = student.toString(); return Response.status(200).entity(output).build(); } @GET @Path("/print/{name}") @Produces("application/json") public Student produceJSON( @PathParam("name") String name ) { /* http://jbosseap.jeetualex.info/rest/message/print/James */ Student st = new Student(name, "Marco",19,12); return st; } @GET @Path("/{param}") public Response printMessage(@PathParam("param") String msg) { /* http://jbosseap.jeetualex.info/rest/message/jeetu */ String result = "Restful example : " + msg; return Response.status(200).entity(result).build(); } }
package com.jeetu.rest; public class Student { private int id; private String firstName; private String lastName; private int age; // Must have no-argument constructor public Student() { } public Student(String fname, String lname, int age, int id) { this.firstName = fname; this.lastName = lname; this.age = age; this.id = id; } public void setFirstName(String fname) { this.firstName = fname; } public String getFirstName() { return this.firstName; } public void setLastName(String lname) { this.lastName = lname; } public String getLastName() { return this.lastName; } public void setAge(int age) { this.age = age; } public int getAge() { return this.age; } public void setId(int id) { this.id = id; } public int getId() { return this.id; } @Override public String toString() { return new StringBuffer(" First Name : ").append(this.firstName) .append(" Last Name : ").append(this.lastName) .append(" Age : ").append(this.age).append(" ID : ") .append(this.id).toString(); } }pom.xml
dependency\> groupid>org.jboss.resteasy/groupid> artifactid>resteasy-jaxrs/artifactid> version>2.2.1.GA/version> /dependency> dependency> groupid>org.jboss.resteasy/groupid> artifactid>resteasy-jackson-provider/artifactid> version>3.0.4.Final/version> /dependency>Web.xml
!--rest easy !!!--> !-- 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>/rest/param-value> /context-param> listener> listener-class> org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap /listener-class> /listener> servlet> servlet-name>resteasy-servlet servlet-class> org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher /servlet-class> /servlet> servlet-mapping> servlet-name>resteasy-servlet/servlet-name> url-pattern>/rest/*/url-pattern> /servlet-mapping> !--rest easy !!!-->
Reference link 1, link 2, link 3
Sunday, May 22, 2016
Codes for B15
Code:
This code can be used to get some interesting information about your phone and battery. It shows following 4 menus on screen:
This code can be used for a factory data reset. It'll remove following things:
It'll NOT remove:
This code can be used to get some interesting information about your phone and battery. It shows following 4 menus on screen:
- Phone information
- Battery information
- Battery history
- Usage statistics
*#*#4636#*#*Code:
This code can be used for a factory data reset. It'll remove following things:
- Google account settings stored in your phone
- System and application data and settings
- Downloaded applications
It'll NOT remove:
- Current system software and bundled applications
- SD card files e.g. photos, music files, etc.
*#*#7780#*#*PS: Once you give this code, you get a prompt screen asking you to click on "Reset phone" button. So you get a chance to cancel your operation. Read more...
Friday, February 12, 2016
Saturday, February 6, 2016
Friday, February 5, 2016
Subscribe to:
Posts
(
Atom
)