Back to project page ShyHi_Old.
The source code is released under:
GNU General Public License
If you think the Android project ShyHi_Old listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package dev.rug.shyhi.jersey; /* ww w . j a va 2 s. co m*/ import java.sql.SQLException; import javax.ws.rs.GET; import javax.ws.rs.Path; import javax.ws.rs.Produces; import javax.ws.rs.QueryParam; import javax.ws.rs.core.MediaType; //Path: http://localhost/<appln-folder-name>/register @Path("/register") public class Register { // HTTP Get Method @GET // Path: http://localhost/<appln-folder-name>/register/doregister @Path("/doregister") // Produces JSON as response @Produces(MediaType.APPLICATION_JSON) // Query parameters are parameters: http://localhost/<appln-folder-name>/register/doregister?name=pqrs&username=abc&password=xyz public String doLogin(@QueryParam("firstName") String fName, @QueryParam("lastName") String lName, @QueryParam("username") String uname, @QueryParam("password") String pwd){ String response = ""; //System.out.println("Inside doLogin "+uname+" "+pwd); int retCode = registerUser(uname, pwd, fName, lName); if(retCode == 0){ response = Utitlity.constructJSON("register",true); }else if(retCode == 1){ response = Utitlity.constructJSON("register",false, "You are already registered"); }else if(retCode == 2){ response = Utitlity.constructJSON("register",false, "Special Characters are not allowed in Username and Password"); }else if(retCode == 3){ response = Utitlity.constructJSON("register",false, "Error occured"); }else if(retCode == 4){ response = Utitlity.constructJSON("register",false, "Auth Error occured"); } return response; } private int registerUser(String uname, String pwd, String fName, String lName){ System.out.println("Inside checkCredentials"); int result = 3; if(true){//Utitlity.isNotNull(uname) && Utitlity.isNotNull(pwd) && Utitlity.isNotNull(fName) && Utitlity.isNotNull(lName)){ try { if(DBConnection.insertUser(uname, pwd, fName, lName)){ System.out.println("RegisterUSer if"); result = 0; } } catch(SQLException sqle){ System.out.println("RegisterUSer catch sqle"); //When Primary key violation occurs that means user is already registered if(sqle.getErrorCode() == 1062){ result = 1; } //When special characters are used in name,username or password else if(sqle.getErrorCode() == 1064){ System.out.println(sqle.getErrorCode()); result = 2; } } catch (Exception e) { // TODO Auto-generated catch block System.out.println("Inside checkCredentials catch e "); result = 3; } }else{ System.out.println("Inside checkCredentials else"); result = 4; } return result; } }