java


com.sun.jersey.server.impl.application.RootResourceUriRules.<init> The ResourceConfig instance does not contain any root resource classes


I am facing some problem while uploading war file to AWS Tomcat8 Server.
Project Type: Dynamic Web Project;
Tomcat: Version - 8;
Java: Version 1.8
It was working perfectly before I added some code for File Upload and Download Operation to AWS S3 Instance using Java.
13-May-2017 19:29:55.770 INFO [http-nio-8088-exec-3]
org.apache.jasper.servlet.TldScanner.scanJars At least one JAR was
scanned for TLDs yet contained no TLDs. Enable debug logging for this
logger for a complete list of JARs that were scanned but no TLDs were
found in them. Skipping unneeded JARs during scanning can improve
startup time and JSP compilation time. 13-May-2017 19:29:55.784 INFO
[http-nio-8088-exec-3]
com.sun.jersey.api.core.PackagesResourceConfig.init Scanning for root
resource and provider classes in the packages:
com.harsha.app.services 13-May-2017 19:29:55.881 INFO
[http-nio-8088-exec-3]
com.sun.jersey.server.impl.application.WebApplicationImpl._initiate
Initiating Jersey application, version 'Jersey: 1.19.1 03/11/2016
02:08 PM' 13-May-2017 19:29:56.304 SEVERE [http-nio-8088-exec-3]
com.sun.jersey.server.impl.application.RootResourceUriRules. The
ResourceConfig instance does not contain any root resource classes.
13-May-2017 19:29:56.313 INFO [http-nio-8088-exec-3]
org.apache.catalina.startup.HostConfig.deployWAR Deployment of web
application archive C:\Program Files\Apache Software Foundation\Tomcat
8.0\webapps\harsha.war has finished in 6,475 ms
AmazonS3Operation Class:
package com.harsha.app.servlet.file;
import java.io.File;
import com.amazonaws.AmazonClientException;
import com.amazonaws.AmazonServiceException;
import com.amazonaws.auth.AWSCredentials;
import com.amazonaws.auth.BasicAWSCredentials;
import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.AmazonS3Client;
import com.amazonaws.services.s3.model.DeleteObjectRequest;
import com.amazonaws.services.s3.model.GetObjectRequest;
import com.amazonaws.services.s3.model.S3Object;
import com.harsha.app.constant.Constant;
public class AmazonS3DriveOperation {
AWSCredentials credentials;
AmazonS3 s3Client;
public AmazonS3DriveOperation() {
s3Authorization();
}
public void s3Authorization() {
credentials = new BasicAWSCredentials(Constant.ACCESS_KEY_ID, Constant.SECRET_ACCESS_KEY);
s3Client = new AmazonS3Client(credentials);
}
public void s3FileUpload(String bucketName, String fileName, File file) {
s3Client.putObject(bucketName, fileName, file);
}
public S3Object s3FileDownload(String bucketName, String fileName) {
GetObjectRequest request = new GetObjectRequest(bucketName, fileName);
S3Object s3Object = s3Client.getObject(request);
return s3Object;
}
public boolean s3FileDelete(String bucketName, String fileName) {
try {
DeleteObjectRequest deleteObjectRequest = new DeleteObjectRequest(bucketName, fileName);
s3Client.deleteObject(deleteObjectRequest);
return true;
}
catch (AmazonClientException e) {
e.printStackTrace();
return false;
}
}
}
DataDeleteServlet Class:
package com.harsha.app.servlet.file;
import java.io.File;
import java.io.IOException;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.harsha.app.constant.Constant;
import com.harsha.app.database.DBManager;
import com.harsha.app.database.DataUpload;
/**
* Servlet implementation class DataFileDelete
*/
#WebServlet("/DataFileDelete")
public class DataFileDelete extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* #see HttpServlet#HttpServlet()
*/
public DataFileDelete() {
super();
// TODO Auto-generated constructor stub
}
/**
* #see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String fileName = request.getParameter("fileName");
String filePath = Constant.DATA_DRIVE + fileName;
String serverDocumentsId = request.getParameter("serverDocumentsId");
fileName = Constant.BASE_UPLOAD_FOLDER + Constant.SUFFIX + fileName;
DBManager dbManager = new DBManager();
System.out.println(filePath);
RequestDispatcher rd = request.getRequestDispatcher("adminUploadExcel.jsp");
AmazonS3DriveOperation amazon = new AmazonS3DriveOperation();
if(amazon.s3FileDelete(Constant.BUCKET_NAME, fileName)) {
DataUpload.deleteFileFromServer(serverDocumentsId, dbManager);
System.out.println("Done");
request.setAttribute("msg", "Data Delete Successful");
}
else {
request.setAttribute("msg", "Data Delete Unsuccessful");
System.out.println("Not Done");
}
dbManager.close();
rd.forward(request, response);
}
/**
* #see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
doGet(request, response);
}
}
DataFileUploadDownload Servlet Class:
package com.harsha.app.servlet.file;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Iterator;
import java.util.List;
import javax.activation.MimetypesFileTypeMap;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.FileItemFactory;
import org.apache.commons.fileupload.FileUploadException;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.fileupload.servlet.ServletFileUpload;
import org.codehaus.jettison.json.JSONArray;
import com.amazonaws.services.s3.model.S3Object;
import com.harsha.app.constant.Constant;
import com.harsha.app.database.DBManager;
import com.harsha.app.database.DataUpload;
import com.harsha.app.util.ExcelRead;
#WebServlet(name = "DataFileUploadDownload",urlPatterns = {"/DataFileUploadDownload/*"})
public class DataFileUploadDownload extends HttpServlet {
private static final long serialVersionUID = 1L;
int BUFFER_LENGTH = 4096;
String fileNameAssigned = "";
String fileNameGiven = "";
String excelType = "";
public DataFileUploadDownload() {
super();
}
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
String filePath = request.getRequestURI();
String fileName = filePath.replace(Constant.REPLACE_URL,"");
AmazonS3DriveOperation amazon = new AmazonS3DriveOperation();
fileName = Constant.BASE_UPLOAD_FOLDER + Constant.SUFFIX + fileName;
S3Object s3Object = amazon.s3FileDownload(Constant.BUCKET_NAME, fileName);
InputStream input = s3Object.getObjectContent();
response.setContentLength((int) s3Object.getObjectMetadata().getContentLength());
response.setContentType(new MimetypesFileTypeMap().getContentType(s3Object.getObjectMetadata().getContentType()));
OutputStream output = response.getOutputStream();
byte[] bytes = new byte[BUFFER_LENGTH];
int read = 0;
while ((read = input.read(bytes, 0, BUFFER_LENGTH)) != -1) {
output.write(bytes, 0, read);
output.flush();
}
input.close();
output.close();
}
public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
DBManager dbManager = new DBManager();
out.println("Hello<br/>");
boolean isMultipartContent = ServletFileUpload.isMultipartContent(request);
if (!isMultipartContent) {
out.println("You are not trying to upload<br/>");
return;
}
out.println("You are trying to upload<br/>");
FileItemFactory factory = new DiskFileItemFactory();
ServletFileUpload upload = new ServletFileUpload(factory);
try {
List<FileItem> fields = upload.parseRequest(request);
out.println("Number of fields: " + fields.size() + "<br/><br/>");
Iterator<FileItem> it = fields.iterator();
if (!it.hasNext()) {
out.println("No fields found");
return;
}
out.println("<table border=\"1\">");
while (it.hasNext()) {
out.println("<tr>");
FileItem fileItem = it.next();
boolean isFormField = fileItem.isFormField();
if (isFormField) {
out.println("<td>regular form field</td><td>FIELD NAME: " + fileItem.getFieldName() +
"<br/>STRING: " + fileItem.getString()
);
out.println("</td>");
if(fileItem.getFieldName().equals("fileName"))
excelType = fileItem.getString();
} else {
out.println("<td>file form field</td><td>FIELD NAME: " + fileItem.getFieldName() +
//"<br/>STRING: " + fileItem.getString() +
"<br/>NAME: " + fileItem.getName() +
"<br/>CONTENT TYPE: " + fileItem.getContentType() +
"<br/>SIZE (BYTES): " + fileItem.getSize() +
"<br/>TO STRING: " + fileItem.toString()
);
fileNameGiven = fileItem.getName();
fileNameAssigned = DataUpload.getCurrentTime() + "" + getFileName(fileNameGiven);
String path = Constant.DATA_DRIVE + ""+ fileNameAssigned;
System.out.println(path);
//File fileUpload = new File(path);
fileNameAssigned = Constant.BASE_UPLOAD_FOLDER + Constant.SUFFIX + fileNameAssigned;
File file = new File(fileNameAssigned);
fileItem.write(file);
AmazonS3DriveOperation amazon = new AmazonS3DriveOperation();
amazon.s3FileUpload(Constant.BUCKET_NAME, fileNameAssigned, file);
out.println("</td>");
}
out.println("</tr>");
}
out.println("</table>");
DataUpload.insertNewUploadFileDetails(fileNameGiven, fileNameAssigned, dbManager);
} catch (FileUploadException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
uploadExcelData(fileNameAssigned, excelType, dbManager);
dbManager.close();
RequestDispatcher rd = request.getRequestDispatcher("adminUploadExcel.jsp");
request.setAttribute("msg", "Data Upload Successful");
rd.forward(request, response);
}
private String getFileName(String fileName) {
return fileName.substring(fileName.indexOf('.')).trim();
}
private void uploadExcelData(String fileNameAssigned, String excelType, DBManager dbManager) throws IOException {
ExcelRead er = new ExcelRead();
if(excelType.equals("Family")) {
JSONArray jArray = er.readBooksFromExcelFile(fileNameAssigned, excelType);
DataUpload.uploadFamilyArchieve(jArray, dbManager);
}
else if(excelType.equals("Member")) {
JSONArray jArray = er.readBooksFromExcelFile(fileNameAssigned, excelType);
DataUpload.uploadMemberArchieve(jArray, dbManager);
}
}
}
ExcelFileCreating and Download Servlet Class:
package com.harsha.app.servlet.file;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Date;
import javax.activation.MimetypesFileTypeMap;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.codehaus.jettison.json.JSONArray;
import com.amazonaws.services.s3.model.S3Object;
import com.harsha.app.constant.Constant;
import com.harsha.app.database.DBHandler;
import com.harsha.app.database.DBManager;
import com.harsha.app.util.ExcelRead;
/**
* Servlet implementation class TableDataDownload
*/
#WebServlet(name = "TableDataDownload",urlPatterns = {"/TableDataDownload/*"})
public class TableDataDownload extends HttpServlet {
private static final long serialVersionUID = 1L;
int BUFFER_LENGTH = 4096;
String fileNameAssigned = "";
String fileNameGiven = "";
String excelType = "";
/**
* #see HttpServlet#HttpServlet()
*/
public TableDataDownload() {
super();
}
public JSONArray agricultureImpactReport() {
DBManager dbManager=new DBManager();
JSONArray jsonArray = DBHandler.getAgricultureImpactReport(0, new Date().getTime()/1000, dbManager);
dbManager.close();
return jsonArray;
}
/**
* #see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String filePath = request.getRequestURI();
System.out.println(filePath);
String impactName = filePath.replace(Constant.REPLACE_URL2,"");
System.out.println(impactName);
JSONArray jsonArray = new JSONArray();
if(impactName.equals("agriculture.xls")) {
jsonArray = agricultureImpactReport();
filePath = ExcelRead.generateExcelReport(jsonArray, impactName);
}
System.out.println(jsonArray.toString());
System.out.println("filepath=" + filePath);
String path = Constant.DATA_DRIVE + filePath;
System.out.println("path=" + path);
String fileName = filePath;
/*File file = new File(path);
InputStream input = new FileInputStream(file);
response.setContentLength((int) file.length());
response.setContentType(new MimetypesFileTypeMap().getContentType(file));
*/
fileName = Constant.BASE_UPLOAD_FOLDER + Constant.SUFFIX + fileName;
AmazonS3DriveOperation amazon = new AmazonS3DriveOperation();
S3Object s3Object = amazon.s3FileDownload(Constant.BUCKET_NAME, fileName);
InputStream input = s3Object.getObjectContent();
response.setContentLength((int) s3Object.getObjectMetadata().getContentLength());
response.setContentType(new MimetypesFileTypeMap().getContentType(s3Object.getObjectMetadata().getContentType()));
OutputStream output = response.getOutputStream();
byte[] bytes = new byte[BUFFER_LENGTH];
int read = 0;
while ((read = input.read(bytes, 0, BUFFER_LENGTH)) != -1) {
output.write(bytes, 0, read);
output.flush();
}
input.close();
output.close();
}
/**
* #see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
doGet(request, response);
}
}
Web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">
<display-name>Yushu</display-name>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>Jersey REST Service</servlet-name>
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>com.sun.jersey.config.property.packages</param-name>
<param-value>com.harsha.app.services</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Jersey REST Service</servlet-name>
<url-pattern>/api/*</url-pattern>
</servlet-mapping>
</web-app>
List of Jar Configured in Project. All present in lib folder under WEB-INF
Dependencies in my pom.ml:
<dependencies>
<!-- https://mvnrepository.com/artifact/com.amazonaws/aws-java-sdk -->
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk</artifactId>
<version>1.11.127</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.amazonaws/aws-java-sdk-core -->
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-core</artifactId>
<version>1.11.127</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-collections4 -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-collections4</artifactId>
<version>4.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.poi/poi -->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.16</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.poi/poi-ooxml -->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.16</version>
</dependency>
<!-- https://mvnrepository.com/artifact/commons-fileupload/commons-fileupload -->
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.3.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/commons-io/commons-io -->
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.5</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.25</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20141113</version>
</dependency>
<dependency>
<groupId>com.sun.mail</groupId>
<artifactId>javax.mail</artifactId>
<version>1.4.5</version>
</dependency>
<dependency>
<groupId>com.lowagie</groupId>
<artifactId>itext</artifactId>
<version>2.1.7</version>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-core-asl</artifactId>
<version>1.9.2</version>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-jaxrs</artifactId>
<version>1.9.2</version>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
<version>1.9.2</version>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-xc</artifactId>
<version>1.9.2</version>
</dependency>
<dependency>
<groupId>javax.el</groupId>
<artifactId>javax.el-api</artifactId>
<version>2.2.4</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-client</artifactId>
<version>1.19.1</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-core</artifactId>
<version>1.19.1</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-json</artifactId>
<version>1.19.1</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-server</artifactId>
<version>1.19.1</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-servlet</artifactId>
<version>1.19.1</version>
</dependency>
<dependency>
<groupId>org.codehaus.jettison</groupId>
<artifactId>jettison</artifactId>
<version>1.1</version>
</dependency>
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>jsr311-api</artifactId>
<version>1.1.1</version>
</dependency>
I tried many solutions like:
Including Jar Files for every API.
Including dependencies for maven in pom.
Checking Web.xml for Jersey Servlet Container and the Services root
packkage.
Checking for similr URL for more than 1 service which create
ambiguity.
Java and Tomcat Version Checked. AWS and my locak machine version are
mathcing.
Still the bug not fixed. Please help me with this. Thanks in Advance.
If you're trying to use Jersey, why are you using Servlets? This is not how Jersey works. With Jersey, you have resource classes annotated with #Path. For example
package com.harsha.app.services;
#Path("pets")
public class PetsResource {
#GET
#Path("{id}")
#Produces("application/json")
public Pet get(#PathParam("id") long id) {
...
}
#POST
#Consumes("application/json")
public Response create(Pet pet) {
...
}
}
Notice the package at the top. Jersey will scan that package (because that's the package you configured in your web.xml) for classes annotated with #Path, so it can register it as a resource class. This is why you are getting the error message "there are no root resource classes".
I am not even going to try to explain what the code above does. It is too broad a topic. You will need to go through some tutorials and documentation to really learn this stuff. But what you are currently doing is completely wrong.

Related Links

Many calls to the server
Is a usage of array of references to a generic type better than using an array of raw types? [duplicate]
Stream of cartesian product of other streams, each element as a List?
SQL in Java Select From Where
How can programs written in Java not require the JRE?
How to add a character to both sides of a word of a string in java?
LayoutInflator in ArrayAdapter's getView() gives me UnsupportedOperationException: addView(View, LayoutParams) is not supported in AdapterView
Automatically add a tag for a Java Cucumber method
404 errors accessing web app URLs with Tomcat over local IP, but works fine with external IP
Extract query parts from a SelectQuery (or equivalents)?
Superpowered Android JNI: understanding “JNI(jintArray …” format
Kinesis consumer recordprocessor factory and record processor threadsafety
acessing the Sonarqube with http://xyz.abc.com:9000
How to run Junit test with xml file
Query in Exception Handling
java regex subtraction of a capturing group

Categories

HOME
sendgrid
netbeans
openstack
deezer
frameworks
serverspec
echarts
azure-media-services
numeral.js
correlation
decomposition
django-simple-history
uitypeeditor
amazonsellercentral
xlsxwriter
excel-2007
trading
intel-pin
kannel
user-interaction
bootstrap-material-design
fifo
junit5
karaf
main
retina-display
neuroscience
libraries
dynamics-crm-2013
starteam
google-closure
qwt
taffy
yii2-extension
jxcore
forever
media-player
capacity
orthogonal
passport-google-oauth
sts-springsourcetoolsuite
login-control
fputcsv
persist
blackberry-10
ready-api
two-factor-authentication
associative-array
uid
ios8-today-widget
execute
python-3.2
jmeter-maven-plugin
mutation-observers
wordml
map-projections
tableau-online
myo
apache-commons-fileupload
sonarqube5.1.2
notify
bridge.net
asp.net-dynamic-data
gulp-less
mechanize-ruby
tidy
odata4j
kyotocabinet
distutils
chuck
quickdialog
google-email-migration
gdata-api
asyncfileupload
gnu-prolog
yetanotherforum
asp.net-mvc-areas
rescale
pascal-fc
w3wp
lzh
uiq3

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App