Guest User

Untitled

a guest
Sep 5th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.79 KB | None | 0 0
  1. how to secure web service?
  2. [{"MANAGER_ID":0,"DEPARTMENT_ID":90,"SALARY":24000,"HIRE_DATE":"1987-06-17","FIRST_NAME":"Steven","COMMISSION_PCT":0,"EMAIL":"SKING","EMPLOYEE_ID":100,"JOB_ID":"AD_PRES","PHONE_NUMBER":"515.123.4567","LAST_NAME":"King"}]
  3.  
  4. package resource;
  5.  
  6. import java.sql.Connection;
  7. import java.sql.DriverManager;
  8. import java.sql.ResultSet;
  9. import java.sql.SQLException;
  10. import java.sql.Statement;
  11.  
  12. import javax.naming.NamingException;
  13. import javax.sql.DataSource;
  14. import javax.ws.rs.Consumes;
  15. import javax.ws.rs.GET;
  16. import javax.ws.rs.PUT;
  17. import javax.ws.rs.Path;
  18. import javax.ws.rs.Produces;
  19. import javax.ws.rs.core.Context;
  20. import javax.ws.rs.core.UriInfo;
  21.  
  22. import org.json.JSONArray;
  23. import org.json.JSONException;
  24. import org.json.JSONObject;
  25.  
  26. @Path("hr")
  27. public class HumanResources {
  28. @SuppressWarnings("unused")
  29. @Context
  30. private UriInfo context;
  31.  
  32. /**
  33. * Default constructor.
  34. */
  35. public HumanResources() {
  36. // TODO Auto-generated constructor stub
  37. }
  38.  
  39. /**
  40. * Retrieves representation of an instance of HumanResources
  41. * @return an instance of String
  42. * @throws NamingException
  43. * @throws SQLException
  44. */
  45. @GET
  46. @Produces("application/json")
  47. public String getText() throws JSONException, NamingException, SQLException {
  48. // TODO return proper representation object
  49. Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","hr","hr");
  50. Statement sel = conn.createStatement();
  51. ResultSet rs = sel.executeQuery("select * from employees where rownum <= 5");
  52.  
  53. JSONObject employees = new JSONObject();
  54. JSONArray emp = new JSONArray();
  55.  
  56. while (rs.next()) {
  57. JSONObject employee = new JSONObject();
  58. employee.put("EMPLOYEE_ID", rs.getInt("EMPLOYEE_ID"));
  59. employee.put("FIRST_NAME", rs.getString("FIRST_NAME"));
  60. employee.put("LAST_NAME", rs.getString("LAST_NAME"));
  61. employee.put("EMAIL", rs.getString("EMAIL"));
  62. employee.put("PHONE_NUMBER", rs.getString("PHONE_NUMBER"));
  63. employee.put("HIRE_DATE", rs.getDate("HIRE_DATE"));
  64. employee.put("JOB_ID", rs.getString("JOB_ID"));
  65. employee.put("SALARY", rs.getDouble("SALARY"));
  66. employee.put("COMMISSION_PCT", rs.getDouble("COMMISSION_PCT"));
  67. employee.put("MANAGER_ID", rs.getInt("MANAGER_ID"));
  68. employee.put("DEPARTMENT_ID", rs.getInt("DEPARTMENT_ID"));
  69. emp.put(employee);
  70. }
  71.  
  72. employees.put("EMPLOYEES", emp);
  73.  
  74. sel.close();
  75. return emp.toString();
  76. }
  77.  
  78. /**
  79. * PUT method for updating or creating an instance of HumanResources
  80. * @param content representation for the resource
  81. * @return an HTTP response with content of the updated or created resource.
  82. */
  83. @PUT
  84. @Consumes("text/plain")
  85. public void putText(String content) {
  86. }
  87.  
  88. }
Add Comment
Please, Sign In to add comment