Reputation: 253
I have implemented a hospital management system with REST api.when my individual part is running without any error.but we integrated this project using GitHub, then it gives an error in pom.xml 1st line.this is error line in the code.
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
this is my pom.xml file.
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>Hospital</groupId>
<artifactId>Hospital</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<warSourceDirectory>WebContent</warSourceDirectory>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-bundle</artifactId>
<version>1.19.4</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-core</artifactId>
<version>1.19.4</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-server</artifactId>
<version>1.19.4</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.48</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.2.3</version>
</dependency>
<dependency>
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
<version>1.8.1</version>
</dependency>
</dependencies>
</project>
this is my error
Apr 17, 2020 5:53:40 PM com.sun.jersey.api.core.ScanningResourceConfig logClasses
INFO: Root resource classes found:
class homePage.service.HomePageService
class doctors.service.DoctorService
class hospital.service.HospitalService
class user.service.UserLoginService
class user.service.UserRegisterService
class payment.service.PaymentService
Apr 17, 2020 5:53:40 PM com.sun.jersey.api.core.ScanningResourceConfig init
INFO: No provider classes found.
Apr 17, 2020 5:53:41 PM com.sun.jersey.server.impl.application.WebApplicationImpl _initiate
INFO: Initiating Jersey application, version 'Jersey: 1.19.4 05/24/2017 03:46 PM'
Apr 17, 2020 5:53:43 PM com.sun.jersey.spi.inject.Errors processErrorMessages
WARNING: The following warnings have been detected with resource and/or provider classes:
WARNING: A sub-resource method, public java.lang.String hospital.service.HospitalService.ReadHospitals(), with URI template, "/", is treated as a resource method
WARNING: A sub-resource method, public java.lang.String hospital.service.HospitalService.insertHoapitalDet(java.lang.String,java.lang.String,java.lang.String,java.lang.String,java.lang.String,java.lang.String), with URI template, "/", is treated as a resource method
WARNING: A sub-resource method, public java.lang.String hospital.service.HospitalService.deleteHospitalDet(java.lang.String), with URI template, "/", is treated as a resource method
WARNING: A sub-resource method, public java.lang.String hospital.service.HospitalService.updateHospitalDet(java.lang.String), with URI template, "/", is treated as a resource method
WARNING: A sub-resource method, public java.lang.String doctors.service.DoctorService.updateDoctor(java.lang.String), with URI template, "/", is treated as a resource method
WARNING: A sub-resource method, public java.lang.String doctors.service.DoctorService.insertDoctor(java.lang.String,java.lang.String,java.lang.String,int,java.lang.String,java.lang.String,java.lang.String), with URI template, "/", is treated as a resource method
WARNING: A sub-resource method, public java.lang.String doctors.service.DoctorService.deleteDoctor(java.lang.String), with URI template, "/", is treated as a resource method
WARNING: A sub-resource method, public java.lang.String doctors.service.DoctorService.readDoctors(), with URI template, "/", is treated as a resource method
WARNING: A sub-resource method, public java.lang.String user.service.UserRegisterService.insertUser(java.lang.String,java.lang.String,java.lang.String,int,java.lang.String,int), with URI template, "/", is treated as a resource method
WARNING: A sub-resource method, public java.lang.String user.service.UserLoginService.validateLogin(java.lang.String,java.lang.String), with URI template, "/", is treated as a resource method
WARNING: A sub-resource method, public java.lang.String user.service.UserLoginService.readUser(java.lang.String,java.lang.String), with URI template, "/", is treated as a resource method
WARNING: A sub-resource method, public java.lang.String user.service.UserLoginService.updateUser(java.lang.String), with URI template, "/", is treated as a resource method
WARNING: A sub-resource method, public java.lang.String user.service.UserLoginService.deleteUser(java.lang.String), with URI template, "/", is treated as a resource method
WARNING: A sub-resource method, public java.lang.String payment.service.PaymentService.validatePayment(java.lang.String,java.lang.String), with URI template, "/", is treated as a resource method
Apr 17, 2020 5:53:43 PM org.apache.catalina.core.StandardContext reload
INFO: Reloading Context with name [/Hospital] is completed
this is my hospital java class
package hospital.model;
import java.sql.*;
import dbconnector.DBConnect;
public class Hospital {
public String insertHoapitalDet(String MOHcode, String Hos_name, String Hos_email, String Hos_managername, String Hos_address, String Hos_phoneNumber )
{
String output = "";
try
{
DBConnect db = new DBConnect();
Connection con = null;
con = db.connect();
if (con == null)
{
return "Error while connecting to the database for inserting.";
}
// create a prepared statement
String query = " insert into hospital "
+ "(`hospitalID`,`mohCode`,`hospitalName`,`emailAddress`,`managerName`,`address`,`telephoneNo`)"
+ " values (?, ?, ?, ?, ?, ?, ?)";
PreparedStatement preparedStmt = con.prepareStatement(query);
// binding values
preparedStmt.setInt(1, 0);
preparedStmt.setString(2, MOHcode);
preparedStmt.setString(3, Hos_name);
preparedStmt.setString(4, Hos_email);
preparedStmt.setString(5, Hos_managername);
preparedStmt.setString(6, Hos_address);
preparedStmt.setString(7, Hos_phoneNumber);
// execute the statement
preparedStmt.execute();
con.close();
output = "Inserted successfully";
}
catch (Exception e)
{
output = "Error while inserting the hospital details.";
System.err.println(e.getMessage());
}
return output;
}
public String readHospitalDetails() {
String output = "";
try
{
DBConnect db = new DBConnect();
Connection con = null;
con = db.connect();
if (con == null)
{
return "Error while connecting to the database for reading.";
}
// Prepare the html table to be displayed
output = "<table border=\"1\"><tr>"
+ "<th>MOH Code</th>"
+ "<th>Hospital Name</th>"
+ "<th>Email</th>"
+ "<th>Manager name</th>"
+ "<th>Address</th>"
+ "<th>TelNo</th>"
+ "<th>UPDATE</th>"
+ "<th>REMOVE</th>"
+ "</tr>";
String query = "select * from hospital";
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery(query);
// iterate through the rows in the result set
while (rs.next())
{
String hospitalID = Integer.toString(rs.getInt("hospitalID"));
String MohCode = rs.getString("mohCode");
String hosName = rs.getString("hospitalName");
String emailAdd = rs.getString("emailAddress");
String managerName = rs.getString("managerName");
String address = rs.getString("address");
String telNo = rs.getString("telephoneNo");
// Add into the html table
output += "<tr><td>" + MohCode + "</td>";
output += "<td>" + hosName + "</td>";
output += "<td>" + emailAdd + "</td>";
output += "<td>" + managerName + "</td>";
output += "<td>" + address + "</td>";
output += "<td>" + telNo + "</td>";
// buttons
output += "<td><input name=\"btnUpdate\" type=\"button\" "
+ "value=\"Update\" class=\"btn btn-secondary\"></td>"
+ "<td><form method=\"post\" action=\"hospital.jsp\">"
+ "<input name=\"btnRemove\" type=\"submit\" value=\"Remove\" class=\"btn btn-danger\">"
+ "<input name=\"hospitalID\" type=\"hidden\" value=\"" + hospitalID + "\">"
+ "</form></td></tr>";
}
con.close();
// Complete the html table
output += "</table>";
}
catch (Exception e)
{
output = "Error while reading the hospital details.";
System.err.println(e.getMessage());
}
return output;
}
public String updateHospitalDet(String ID, String MOHcode, String Hos_name, String Hos_email, String Hos_managername, String Hos_address, String Hos_phoneNumber)
{
String output = "";
try {
DBConnect db = new DBConnect();
Connection con = null;
con = db.connect();
if (con == null)
{
return "Error while connecting to the database for updating.";
}
// create a prepared statement
String query = "UPDATE hospital SET mohCode=?,hospitalName=?,emailAddress=?,managerName=?,address=?,telephoneNo=? WHERE hospitalID=?";
PreparedStatement preparedStmt = con.prepareStatement(query);
// binding values
preparedStmt.setString(1, MOHcode);
preparedStmt.setString(2, Hos_name);
preparedStmt.setString(3, Hos_email);
preparedStmt.setString(4, Hos_managername);
preparedStmt.setString(5, Hos_address);
preparedStmt.setString(6, Hos_phoneNumber);
preparedStmt.setInt(7, Integer.parseInt(ID));
// execute the statement
preparedStmt.execute();
con.close();
output = "Updated successfully";
}
catch (Exception e)
{
output = "Error while updating the hospital details.";
System.err.println(e.getMessage());
}
return output;
}
public String deleteHospitalDet(String hospitalID)
{
String output = "";
try
{
DBConnect db = new DBConnect();
Connection con = null;
con = db.connect();
if (con == null)
{
return "Error while connecting to the database for deleting.";
}
// create a prepared statement
String query = "delete from hospital where hospitalID=?";
PreparedStatement preparedStmt = con.prepareStatement(query);
// binding values
preparedStmt.setInt(1, Integer.parseInt(hospitalID));
// execute the statement
preparedStmt.execute();
con.close();
output = "Deleted successfully";
}
catch (Exception e)
{
output = "Error while deleting the hospital details.";
System.err.println(e.getMessage());
}
return output;
}
}
This is my HospitalService Class
package hospital.service;
import hospital.model.Hospital;
//For REST Service
import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
//For JSON
import com.google.gson.*;
//For XML
import org.jsoup.*;
import org.jsoup.parser.*;
import org.jsoup.nodes.Document;
@Path("/Hospitals")
public class HospitalService {
Hospital hosObj = new Hospital();
@GET
@Path("/")
@Produces(MediaType.TEXT_HTML)
public String ReadHospitals() {
return hosObj.readHospitalDetails();
}
@POST
@Path("/")
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@Produces(MediaType.TEXT_PLAIN)
public String insertHoapitalDet(
@FormParam("mohCode") String mohCode,
@FormParam("hospitalName") String hospitalName,
@FormParam("emailAddress") String emailAddress,
@FormParam("managerName") String managerName,
@FormParam("address") String address,
@FormParam("telephoneNo") String telephoneNo)
{
String output = hosObj.insertHoapitalDet(mohCode, hospitalName, emailAddress, managerName,address,telephoneNo);
return output;
}
@PUT
@Path("/")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.TEXT_PLAIN)
public String updateHospitalDet(String hospitalData)
{
//Convert the input string to a JSON object
JsonObject hospitalObject = new JsonParser().parse(hospitalData).getAsJsonObject();
//Read the values from the JSON object
String hospitalID = hospitalObject.get("hospitalID").getAsString();
String mohCode = hospitalObject.get("mohCode").getAsString();
String hospitalName = hospitalObject.get("hospitalName").getAsString();
String emailAddress = hospitalObject.get("emailAddress").getAsString();
String managerName = hospitalObject.get("managerName").getAsString();
String address = hospitalObject.get("address").getAsString();
String telephoneNo = hospitalObject.get("telephoneNo").getAsString();
String output = hosObj.updateHospitalDet(hospitalID, mohCode, hospitalName, emailAddress, managerName,address,telephoneNo);
return output;
}
@DELETE
@Path("/")
@Consumes(MediaType.APPLICATION_XML)
@Produces(MediaType.TEXT_PLAIN)
public String deleteHospitalDet(String hospitalData)
{
//Convert the input string to an XML doc
Document doc = Jsoup.parse(hospitalData, "", Parser.xmlParser());
//Read the value from the element <hospitalID>
String hospitalID = doc.select("hospitalID").text();
String output = hosObj.deleteHospitalDet(hospitalID);
return output;
}
}
I hope to reply if someone has fixed it.
Upvotes: 3
Views: 347
Reputation: 703
I did not understand what you meant by integrated with github.
I think this problem is due to the definition of @Path("/")
in your methods, I am saying this assuming that you already have a class level annotation @Path("/yourPathSpecificToThisClass")
. Then you may add @Path("/somepath")
but not @Path("/")
.
This is because it only needs the request method(@Get, @Post etc) to identify the path.
=========================EDIT==============================
I will try and write a sample HospitalService
class how I expect it to look,
//someAnnotations
@Path("/hospital")
public class HospitalService{
@Get
//@Path("/") if you have this annotation here remove it.
public ResponseEntity readHospitals(/*take input*/) {
//implementation
}
@Post
//@Path("/") if you have this annotation here remove it.
public ResponseEntity insertHoapitalDet(/*take input*/) {
//implementation
}
@Put
//@Path("/") if you have this annotation here remove it.
public ResponseEntity updateHospitalDet(/*take input*/) {
//implementation
}
@Delete
//@Path("/") if you have this annotation here remove it.
public ResponseEntity deleteHospitalDet(/*take input*/) {
//implementation
}
}
Hope you can figure it out now
Upvotes: 3