This is the error I am getting.
com.sun.jersey.api.container.ContainerException: A root resource, class
org.apache.hadoop.hdfs.server.datanode.web.resources.DatanodeWebHdfsMethods,
has a non-unique URI template /
I am using Hadoop and REST API.
This is how I am initialising REST API in web.xml
<servlet>
<servlet-name>ServletAdaptor</servlet-name>
<servlet-class>
com.sun.jersey.server.impl.container.servlet.ServletAdaptor</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>ServletAdaptor</servlet-name>
<url-pattern>/RESTMOB/CALL/*</url-pattern>
</servlet-mapping>
I have tried removing the Hadoop JARs and it works, but I need those Hadoop JARs so what's the alternative. Thanks in advance
what is likely happening is some .class file(s) in the jar you removed are also present in the other jars - this is common in java and can create issue restarting your app and it might load different versions on restarts. I would open up the jars and search for duplicate class files and remove them from one jar and test. You can extract the jars to file system and search for all .class files and sort by name. Its always a good idea to eliminate duplicate .class files when possible even though it requires some tedious work
Related
I have an existing jetty application that i need to modify. Basically i just need one access point that can handle POST requests. I have access to the WEB-INF directory of the project. There i have web.xml file and a lib folder. As i understand from jetty documentation jars under lib will be loaded automatically. Is it possible to add a custom jar under lib folder and the somehow configure web.xml so that my jar will handle HTTP requests from a certain URL? If so how would i start with that?
You can simply create a jar with your Servlet class inside (a class that extends HttpServlet) and add the servlet declaration inside the web.xml
<servlet>
<servlet-name>A_Name</servlet-name>
<servlet-class>your.new.ServletClass</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>A_Name</servlet-name>
<url-pattern>/the/path/you/want</url-pattern>
</servlet-mapping>
I'm packaging a web application and tomcat into a zip file. This zip should be able to use in any location or path.
This web application require to load an additional folder (response-folder) to be able to startup.
Due to the zip can be unzip anywhere, I need to find out my current path when the server is started and set the path in the startup.bat.
The following is my zip folder structure:
my.zip
- apache-tomcat
- bin
- startup.bat
- webapp
- mywebapp
- WEB-INF
- web.xml
- response-folder
In my startup.bat, I had the following line
set CATALINA_OPTS=-Dapache-tomcat-current-folder="%TOMCAT_CURRENT_FOLDER%"
I would like achieve something like below:
<servlet>
<description>MyService</description>
<display-name>MyService</display-name>
<servlet-name>MyService</servlet-name>
<servlet-class>com.my.package.MyService</servlet-class>
<init-param>
<description>Folder that contains response files</description>
<param-name>RESPONSE_FOLDER</param-name>
<param-value>${apache-tomcat-current-folder}\response-folder</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
Note: I'm not able to the change the web application java code, as the web application is not belong to me.
May I know is there anyway to make web.xml to support variable interpolation or achieve behavior such as above?
Any help would be great.
To use environment variables in web.xml, you can add
set "CATALINA_OPTS=-Dapache-tomcat-current-folder=somevalue"
or if you want to reference a System environment variable
set "CATALINA_OPTS=-Dapache-tomcat-current-folder=%apache-tomcat-current-folder%"
in bin/setenv.bat (bin/setenv.sh for *nix).
You need to create this file.
I've created a .jar with some Jersey web services in it, and I want to import that .jar in other projects. Those web services work like a handler/proxy for local code to link with a remote service provider.
So, I import the .jar document in a project and configure web.xml like this:
<servlet>
<servlet-name>Services</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.package.for.services.in.current.project, com.package.for.services.in.jar</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>Services</servlet-name>
<url-pattern>/s/*</url-pattern>
</servlet-mapping>
But when I run the project, the web services specified in com.package.for.services.in.jar aren't found.
The .jar document is in build path. What am I doing wrong? Isn't possible to run web services from an external library?
Thanks in advance.
I found the answer from this post: Jersey REST The ResourceConfig instance does not contain any root resource classes
The PackagesResourceConfig class depends on having a directory with the name of the package in order to find the classes within it. I went back to Eclipse, and found an option at the bottom of the "Export ... > Jar" dialog for "Add directory entries." I turned that on, exported the jar again, and then the scanning found my resource classes. You'll need to find some comparable option in your build environment.
In my WEB-INF/web.xml file, an upload path is set absolutely.
Can I make this relative to the application root?
Or is there a better "best practices" approach to configuring paths for file uploads?
Below is the relevant config code.
entire config file
<filter>
<filter-name>PrimeFaces FileUpload Filter</filter-name>
<filter-class>org.primefaces.webapp.filter.FileUploadFilter</filter-class>
<init-param>
<param-name>uploadDirectory</param-name>
<param-value>/var/webapp/mdjdreview/upload/temp</param-value>
</init-param>
</filter>
If you make it a relative path, and use new File(path) to access the directory, it will be relative to the directory from which your container is started.
You can do it, but except for making it more difficult to know where the files are actually stored, and for risking to look at the wrong place because the container is started from elsewhere, I don't really see the point.
If waht you plan to do is storing the uploaded files in the directory of the deployed webapp, then you should definitely not do that, as a redeploy of the webapp will remove all the uploaded files. Treat the webapp directory as read-only.
I'm trying to test a war that I deployed in Tomcat 7, however it seems its missing a xml configuration:
web.xml
<servlet>
<servlet-name>StorageEngine</servlet-name>
<servlet-class>com.jpeterson.littles3.StorageEngine</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:StorageEngine-servlet.xml</param-value>
</init-param>
</servlet>
I have downloaded the StorageEngine-servlet.xml separately, to be able to satisfy this init-param where do I need put the
xml file in the \webapps\littleS3-2.3.0\WEB-INF folder, just relative to the web.xml? Or?
No, it belongs in WEB-INF/classes of your WAR file. That is always in the CLASSPATH of a Tomcat app, loaded by the app class loader.
Given the mapping it would need to be placed in the root of your classpath. Try placing it within the root of any source folder