Vaadin 7 Servlet ClassCastException - java

I'm trying to migrate from Vaadin 6 to Vaadin 7.
When I'm trying to open application url I get a ClassCastException
SEVERE: Allocate exception for servlet Vaadin Application Servlet
java.lang.ClassCastException: com.vaadin.server.VaadinServlet cannot be cast to javax.servlet.Servlet
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1136)
at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:857)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:136)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:929)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1002)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:585)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
I cann't understand what's wrong because it seems that web.xml is ok.
Mapping of application servlet is listed below
<servlet>
<servlet-name>Ohta Application</servlet-name>
<servlet-class>com.vaadin.server.VaadinServlet</servlet-class>
<init-param>
<description>
Vaadin UI class to use</description>
<param-name>UI</param-name>
<param-value>com.ritmsoft.ohta.OhtaUI</param-value>
</init-param>
<init-param>
<param-name>widgetset</param-name>
<param-value>com.ritmsoft.ohta.widgetset.OhtaWidgetSet</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>Ohta Application</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Ohta Application</servlet-name>
<url-pattern>/VAADIN/*</url-pattern>
</servlet-mapping>
Help me, please.

Or if you use Maven make your servlet's scope "provided" like so:
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
<scope>provided</scope>
</dependency>
That way it will use the container's version of the servlet jar if it exists, otherwise it will use the one you declare in Maven.

The problem is most likely caused by javax.servlet.Servlet being loaded by multiple class-loaders. It usually exists in servlet*.jar. It is possible that the container provides its own version of this jar, and your application provides another. Try removing the one in your war.

I have the same issue here, but only if I try to run the vaadin maven project with the tomcat plugin for eclipse. The dependency for the serlet-api is exactly as shown above. Snd tehr eis no difference if I comment it completely or just the scope part.
There is always a servlet-api-2.5-6.1.11 in the lib folder. I don't know from where this comes from. But with the scope provided there is definitly no javax.servlet-api.jar in the lib folder.
And if i copy the war manuelly into the tomcats webapps folder and start if by console it works fine. I don't get the difference.
Any ideas?

Related

HTTP Proxy Servlet Error

Let me start off by saying this was working yesterday, so I'm totally confused as to why it stopped working all of a sudden. And Java / Plugins are really not my specialty.
I'm working on an application that makes POST and GET calls to a server on another domain. This is a Maven Project. To avoid the Cross-Origin issues I have a httpproxy.ProxyServlet plugin.
I'm going to list all the working peices here, but basically the question and error are summed up at the bottom of this post.
pom.xml
<dependencies>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
<version>2.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.mitre.dsmiley.httpproxy</groupId>
<artifactId>smiley-http-proxy-servlet</artifactId>
<version>1.6</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.0.2</version>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
<!-- War plugin below is required for above plugin to build project without errors. http://stackoverflow.com/questions/7539970/cannot-construct-org-apache-maven-plugin-war-util-webappstructure-as-it-does-not-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.1.1</version>
</plugin>
</plugins>
web.xml
The second servlet section is the one in question. I only post the first because the first works fine. for reference.
<servlet>
<servlet-name>ad_auth</servlet-name>
<servlet-class>org.mitre.dsmiley.httpproxy.ProxyServlet</servlet-class>
<init-param>
<param-name>targetUri</param-name>
<param-value>${authserver}/aaenroll/rest/authContext</param-value>
</init-param>
<init-param>
<param-name>log</param-name>
<param-value>true</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>ad_auth</servlet-name>
<url-pattern>/adauth</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>user_profile</servlet-name>
<servlet-class>org.mitre.dsmiley.httpproxy.ProxyServlet</servlet-class>
<init-param>
<param-name>targetUri</param-name>
<param-value>${authserver}/aaenroll/rest/userProfile/userName/{_username}.json?user={_username}</param-value>
<!--<param-value>${authserver}/aaenroll/rest/userProfile/userName/segotac.json?user=segotac</param-value>-->
</init-param>
<init-param>
<param-name>log</param-name>
<param-value>true</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>user_profile</servlet-name>
<url-pattern>/userProfile</url-pattern>
</servlet-mapping>
Javascript Ajax call
function checkEnrollment() {
var username = Cookies.get('username');
var authToken = Cookies.get('authToken');
$.ajax({
type: "GET",
beforeSend: function(request)
{
request.setRequestHeader("Authorization", authToken);
},
url: "userProfile?_username=" + username, //**PROBLEM HERE** -> Url intercepted by servlet plugin. Full path mapping is available in web.xml. As per the Plugin syntax, param _username will replace all "{_username}" in web.xml userProfile targetUri param-values.
success: function(msg, success) {
window.location.replace("enroll.jsp");
},
error: function(xhr, ajaxOptions, thrownError) {
console.log('false Enrollment');
}
});
Syntax for how the intercepted URL being passed in above is located at the bottom of this link. Which is the plugin. Which again... was working yesterday... https://github.com/mitre/HTTP-Proxy-Servlet
And at long last. The Error:
<html><head><title>Apache Tomcat/7.0.39 - Error report</title><style><!--H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} B {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} P {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}A {color : black;}A.name {color : black;}HR {color : #525D76;}--></style> </head><body><h1>HTTP Status 500 - Trying to process targetUri init parameter: java.net.URISyntaxException: Illegal character in path at index 71: http://cslxintwebdev3.csmc.edu:8087/aaenroll/rest/userProfile/userName/{_username}.json?user={_username}</h1><HR size="1" noshade="noshade"><p><b>type</b> Exception report</p><p><b>message</b> <u>Trying to process targetUri init parameter: java.net.URISyntaxException: Illegal character in path at index 71: http://cslxintwebdev3.csmc.edu:8087/aaenroll/rest/userProfile/userName/{_username}.json?user={_username}</u></p><p><b>description</b> <u>The server encountered an internal error that prevented it from fulfilling this request.</u></p><p><b>exception</b> <pre>javax.servlet.ServletException: Trying to process targetUri init parameter: java.net.URISyntaxException: Illegal character in path at index 71: http://cslxintwebdev3.csmc.edu:8087/aaenroll/rest/userProfile/userName/{_username}.json?user={_username}
org.mitre.dsmiley.httpproxy.ProxyServlet.initTarget(ProxyServlet.java:156)
org.mitre.dsmiley.httpproxy.ProxyServlet.init(ProxyServlet.java:140)
javax.servlet.GenericServlet.init(GenericServlet.java:160)
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:947)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1009)
org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
java.lang.Thread.run(Thread.java:722)
root cause java.net.URISyntaxException: Illegal character in path at index 71: http://example.com:8087/aaenroll/rest/userProfile/userName/{_username}.json?user={_username}
java.net.URI$Parser.fail(URI.java:2829)
java.net.URI$Parser.checkChars(URI.java:3002)
java.net.URI$Parser.parseHierarchical(URI.java:3086)
java.net.URI$Parser.parse(URI.java:3034)
java.net.URI.<init>(URI.java:595)
org.mitre.dsmiley.httpproxy.ProxyServlet.initTarget(ProxyServlet.java:154)
org.mitre.dsmiley.httpproxy.ProxyServlet.init(ProxyServlet.java:140)
javax.servlet.GenericServlet.init(GenericServlet.java:160)
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:947)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1009)
org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
java.lang.Thread.run(Thread.java:722)
note The full stack trace of the root cause is available in the Apache Tomcat/7.0.39 logs.Apache Tomcat/7.0.39
So the short question is, why is the username param being sent to the HttpProxy plugin not being intercepted and replaced correctly?
Sorry if this is way to much info to throw at this. Hopefully someone who is familiar with these technologies will be able to quickly identify the issue or point me on the correct debugging path.
THANK ALOOOT!
Edit
web.xml
<servlet-class>org.mitre.dsmiley.httpproxy.URITemplateProxyServlet</servlet-class>
<url-pattern>/userProfile/*</url-pattern>
js
url: "userProfile?_username=" + username,
Error:
HTTP Status 500 - Missing HTTP parameter _username to fill the template
I know username has a value in the javascript call. Variable is not being applied correctly to the template in web.xml
Thanks again!
It is mainly a problem with your servlet mapping.
Per the documentation, I don't see any indication that class ProxyServlet allows for parameterization (though maybe it does). Perhaps you should use class URITemplateProxyServlet instead.
You would change your servlet definition as such:
<servlet-class>org.mitre.dsmiley.httpproxy.URITemplateProxyServlet</servlet-class>
<init-param>
<param-name>targetUri</param-name>
<param-value>{authserver}/aaenroll/rest/userProfile/userName/{_username}.json?user={_username}</param-value>
...
and the servlet mapping as such, (notice the '*'):
<servlet-mapping>
<servlet-name>user_profile</servlet-name>
<url-pattern>/userProfile/*</url-pattern>
</servlet-mapping>
Then in your ajax:
...
url: "userProfile/?authserver=" + authserver + "&_username=" + username;
...
So I was reading the source for URITemplateProxyServlet and I think it might be expecting a one to one matching of args. In other words, for every argument in the targetUri, there must be a matching argument in the querystring (i.e. the URL your ajax generates). Unfortunately I can't test, but you should be able to tell quickly if this is the fact.
Try this:
To avoid confusion set the url-pattern to have a second '/' as such <url-pattern>/userProfile/*</url-pattern> just as their documentation does.
Change the ajax generated URL to match this pattern AND have a second param as such : "userProfile/subpath?_username=" + username + "&_username2=" + username;
Change your target uri as necessary: <param-value>${authserver}/aaenroll/rest/userProfile/userName/{_username}.json?user={_username2}</param-value>
Well, I finally figured out what the issue was. Since I was trying to use the same _username param to fill in TWO spots in my targetUri, one of them was getting lost. Basically you cant apply the same param twice to the targetUri using this plugin.
Solution:
web.xml
<servlet>
<servlet-name>user_profile</servlet-name>
<servlet-class>org.mitre.dsmiley.httpproxy.URITemplateProxyServlet</servlet-class>
<init-param>
<param-name>targetUri</param-name>
<param-value>${authserver}/aaenroll/rest/userProfile/userName/{_username}.json?user={_username2}</param-value>
</init-param>
<init-param>
<param-name>log</param-name>
<param-value>true</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>user_profile</servlet-name>
<url-pattern>/userProfile/*</url-pattern>
</servlet-mapping>
ajax call
$.ajax({
type: "GET",
beforeSend: function(request)
{
request.setRequestHeader("Authorization", authToken);
},
url: "userProfile?_username=" + username + "&_username2=" + username;, //Url intercepted by servlet plugin. Full path mapping is available in web.xml
success: function(msg, success) {
},
error: function(xhr, ajaxOptions, thrownError) {
}
});

Cannot integrate Jersey 2.16 into Tomcat 8.0.12 using servlet 3 plugability feature

In new project I decided to use latest Jersey (2.16) with Tomcat 8, but integration scheme described in documentation causes Tomcat to throw NPE:
java.lang.NullPointerException
org.apache.catalina.loader.WebappClassLoader.binaryNameToPath(WebappClassLoader.java:2503)
org.apache.catalina.loader.WebappClassLoader.findLoadedClass0(WebappClassLoader.java:2708)
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1215)
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1173)
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:493)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:610)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:534)
org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1081)
org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:658)
org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:277)
org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.doRun(AprEndpoint.java:2381)
org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:2370)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
java.lang.Thread.run(Thread.java:744)
Here is my web.xml
<servlet>
<servlet-name>bla.bla.core.jersey.config.JerseyServerConfig</servlet-name>
</servlet>
<servlet-mapping>
<servlet-name>bla.bla.core.jersey.config.JerseyServerConfig</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
Here is the listing of JerseyServerConfig:
package ru.huawei.rnd.bulksms.core.jersey.config;
import org.glassfish.jersey.server.ResourceConfig;
import ru.huawei.rnd.bulksms.core.jersey.constants.FILTERS_AND_INTERCEPTORS;
import ru.huawei.rnd.bulksms.core.jersey.constants.JERSEY_FEATURES;
public class JerseyServerConfig extends ResourceConfig {
public JerseyServerConfig() {
register(JERSEY_FEATURES.FORM_PROVIDER);
register(JERSEY_FEATURES.MULTIPART);
register(FILTERS_AND_INTERCEPTORS.USER_GZIP_FILTER);
register(FILTERS_AND_INTERCEPTORS.GZIP_ENCODER);
packages("bla.bla.rest");
}
}
So, it looks correct according to scheme described here in "4.7.2.2. Deployment using web.xml descriptor". But when I try to call any JAX-RS resource, bang, Tomcat throws NPE. And it seems it's because of missing servlet-class element in web.xml.
It appears you are using the jersey-container-servlet-core dependency. This will work in situations when we declare the servlet container. But when we want to take advantage of the features where Jersey is automatically loaded, we need the jersey-container-servlet
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet</artifactId>
<version>${jersey.version}</version>
</dependency>
This artifact has the JerseyServletContainerInitializer, which implements SerlvetContainerInitializer (for Servlet 3.x deployments).
Tested and got same results as you when using the former artifact, and works fine using the latter.

javax.ws.rs.NotFoundException: Could not find resource for full path Error Occures

I found this same question in here few times, but I couldn't find an answer to that.
When I run my application, Im getting the following error
javax.ws.rs.NotFoundException: Could not find resource for full path: http://localhost:8080/RemoteQuartzScheduler/rest/TestClass/hello
at org.jboss.resteasy.core.registry.ClassNode.match(ClassNode.java:73)
at org.jboss.resteasy.core.registry.RootClassNode.match(RootClassNode.java:48)
at org.jboss.resteasy.core.ResourceMethodRegistry.getResourceInvoker(ResourceMethodRegistry.java:444)
at org.jboss.resteasy.core.SynchronousDispatcher.getInvoker(SynchronousDispatcher.java:234)
at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:171)
at org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:220)
at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:56)
at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:51)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1023)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:722)
Here is the pom file of the project (I only added the main parts)
<repositories>
<repository>
<id>JBoss repository</id>
<url>https://repository.jboss.org/nexus/content/groups/public-jboss/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jaxrs</artifactId>
<version>3.0.9.Final</version>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-servlet-initializer</artifactId>
<version>3.0.9.Final</version>
</dependency>
</dependencies>
And here is my web.xml file
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
<display-name>RemoteQuartzScheduler</display-name>
<servlet-mapping>
<servlet-name>resteasy-servlet</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
<!-- this should be the same URL pattern as the servlet-mapping property -->
<context-param>
<param-name>resteasy.servlet.mapping.prefix</param-name>
<param-value>/rest</param-value>
</context-param>
<listener>
<listener-class>
org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap
</listener-class>
</listener>
<servlet>
<servlet-name>resteasy-servlet</servlet-name>
<servlet-class>
org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher
</servlet-class>
</servlet>
Here is my Test.java class
#Path("/TestClass")
public class Test implements Serializable{
private static final long serialVersionUID = -262701666015379272L;
#GET
#Path("/hello")
public Response heloMessage() {
String result = "Hello Word!!!!!!!!!";
return Response.status(200).entity(result).build();
}
}
Please tell me where did I do wrong?? Thanks in advance
I haven't gotten a chance to test your version (with the web.xml), and honestly I don't work much with xml when I do use Resteasy, so I won't go trying to explain what is wrong (if anything) with the web.xml.
But when working with an javax.xs.rs.core.Application subclass, we can define an #ApplicationPath("/path") annotation. This defines a servlet for our JAX-RS application, with the url mapping of /path/*. This is specified in the JAX-RS spec.
You can see more here about this deployment option, as well as others, in section 2.3.2 Configuration - Servlet. This is a 1.1 spec (you are using 2.0), but the deployment options are similar. I just couldn't find an html link to the 2.0. You can download the pdf though from here.
You can also read more about deployments with Resteasy here in the documentation.
But basically, what this deployment option does is scan for annotations of #Path, #Provider, etc for the application. The reason is that JAX-RS will first look for classes and object in overridden getClasses() and getSingletons(), respectively. If then return empty sets, this tell JAX-RS to do scanning (per the spec).

class path resource [java/lang/Object.class] cannot be opened because it does not exist

I am having a strange issue with a Spring web application. This is from the Tomcat log:
GRAVE: Exception lors de l'envoi de l'évènement contexte initialisé (context initialized) à l'instance de classe d'écoute (listener) org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanDefinitionStoreException: Failed to load bean class: com.jverstry.Configuration.WebConfig; nested exception is java.io.FileNotFoundException: class path resource [java/lang/Object.class] cannot be opened because it does not exist
at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:267)
at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:203)
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:622)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:451)
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:383)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:283)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:111)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4791)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5285)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.manager.ManagerServlet.start(ManagerServlet.java:1247)
at org.apache.catalina.manager.HTMLManagerServlet.start(HTMLManagerServlet.java:714)
at org.apache.catalina.manager.HTMLManagerServlet.doPost(HTMLManagerServlet.java:219)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.filters.CsrfPreventionFilter.doFilter(CsrfPreventionFilter.java:186)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.filters.SetCharacterEncodingFilter.doFilter(SetCharacterEncodingFilter.java:108)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:225)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:581)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1001)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:585)
at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:1770)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.io.FileNotFoundException: class path resource [java/lang/Object.class] cannot be opened because it does not exist
at org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:157)
at org.springframework.core.type.classreading.SimpleMetadataReader.<init>(SimpleMetadataReader.java:49)
at org.springframework.core.type.classreading.SimpleMetadataReaderFactory.getMetadataReader(SimpleMetadataReaderFactory.java:80)
at org.springframework.core.type.classreading.CachingMetadataReaderFactory.getMetadataReader(CachingMetadataReaderFactory.java:101)
at org.springframework.core.type.classreading.SimpleMetadataReaderFactory.getMetadataReader(SimpleMetadataReaderFactory.java:76)
at org.springframework.context.annotation.ConfigurationClassParser.doProcessConfigurationClass(ConfigurationClassParser.java:257)
at org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass(ConfigurationClassParser.java:149)
at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:126)
at org.springframework.context.annotation.ConfigurationClassParser.doProcessConfigurationClass(ConfigurationClassParser.java:219)
at org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass(ConfigurationClassParser.java:149)
at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:126)
at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:263)
... 36 more
16-sept.-2012 15:51:56 org.apache.catalina.core.ApplicationContext log
INFO: Closing Spring root WebApplicationContext
I have seen similar questions on SO, but none related to java/lang/Object.class. I hae no idea what is causing this.
This is my web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<context-param>
<param-name>contextClass</param-name>
<param-value>org.springframework.web.context.support.AnnotationConfigWebApplicationContext</param-value>
</context-param>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>com.jverstry.Configuration</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<servlet>
<servlet-name>mytest</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value></param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>spring</servlet-name>
<url-pattern>/mytest/*</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file></welcome-file>
</welcome-file-list>
</web-app>
Here is my WebConfig class:
#EnableWebMvc
#Configuration
#ComponentScan(basePackages = {"com.jverstry", "org.krams"})
#ImportResource("WEB-INF/spring-security.xml")
public class WebConfig extends WebMvcConfigurerAdapter {
#Bean
public ViewResolver getViewResolver() {
InternalResourceViewResolver resolver
= new InternalResourceViewResolver();
resolver.setPrefix("WEB-INF/pages/");
resolver.setSuffix(".jsp");
return resolver;
}
}
That is most peculiar.
Lets start with the what we do know. The class java.lang.Object and the corresponding java/lang/Object.class file most certainly do exist. If they didn't then is is highly unlikely that the JVM would have started in the first place.
So how come you get the exception?
My theory it that somewhere in your codebase (or the libraries you are using) there is a classloader that is breaking the rules. When it is asked to load a resource, a well behaved class loader will first delegate up the class loader chain to see if its parent classloader can load the resource. I suspect that what is happening is that the broken classloader is skipping the delegation step and just trying to load the resource itself. If the "rt.jar" is not on its list of JARs, etc (and it normally won't be) then the class loader won't find the Object.class file ... and you will get a FileNotFoundException.
UPDATE
I think I understand. If your Java installation was corrupted to the extent that it couldn't load java.lang.Object, then the JVM wouldn't boot. And if it had already booted before the corruption, then it wouldn't be trying to load the Object class.
But it is not trying to do that. It is actually trying to read the Object.class file. And the stacktrace seem to be saying that this is occurring in Spring's annotation processing code.
So I think that something has triggered a servlet restart after the Java installation was compromised. And the restart caused the spring configuration to be done again. Why it worked when you rebooted is a mystery ... unless the problem was due to a hardware error or stuck device driver that was cleared by the reboot.
(The post you found describes a different scenario ... where the JVM fail during its bootstrap. Your scenario is more complicated.)
It turns out my JRE6 installation was somehow corrupted. I reinstalled it manually and now I don't have an issue anymore. I have also found another post which might explain why the issue would disappear after rebooting.

Tomcat 5.5 Don't Find My Servlet

I've compiled the source into the class Files, then putted at the folder:
Tomcat 5.5\WEB-INF\ROOT\classes\Files.class
And added this to the web.xml file:
<servlet>
<servlet-name>Files</servlet-name>
<servlet-class>Files</servlet-class>
</servlet>
But when I tried to access the URL http://localhost:8080/Files, I got this error from Tomcat:
Tomcat 5.5 404 Error http://img251.imageshack.us/img251/5042/tomcat404.png
Update: after adding <servlet-mapping> I'm now getting the following error:
exception
javax.servlet.ServletException: Error allocating a servlet instance
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:174)
org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:837)
org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:640)
org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1287)
java.lang.Thread.run(Unknown Source)
root cause
java.lang.NoClassDefFoundError: IllegalName: /Files
java.lang.ClassLoader.preDefineClass(Unknown Source)
java.lang.ClassLoader.defineClassCond(Unknown Source)
java.lang.ClassLoader.defineClass(Unknown Source)
java.security.SecureClassLoader.defineClass(Unknown Source)
org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:1960)
org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:931)
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1405)
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1284)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:174)
org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:837)
org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:640)
org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1287)
java.lang.Thread.run(Unknown Source)
root cause
java.lang.NoClassDefFoundError: IllegalName: /Files
This means that the given class definition cannot be found because it has an illegal name /Files. This in turn means that you've changed the <servlet-class> to /Files. This is wrong. You're basically instructing the servletcontainer to declare and instantiate the servlet as follows:
/Files Files = new /Files();
This won't already compile. The complete mapping should look like:
<servlet>
<servlet-name>instanceName</servlet-name>
<servlet-class>com.example.ServletClass</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>instanceName</servlet-name>
<url-pattern>/urlPattern</url-pattern>
</servlet-mapping>
Which is to be interpreted in raw Java code as follows:
com.example.ServletClass instanceName = new com.example.ServletClass();
The <servlet-class> should denote the full qualified classname, including any package. The <servlet-name> should denote the unique instance name. The <url-pattern> should denote the URL pattern for which the servletcontainer should invoke this servlet.
You also need to define a
<servlet-mapping>
<servlet-name>Files</servlet-name>
<url-pattern>/Files</url-pattern>
</servlet-mapping>
To match the url pattern to the servlet
You also need the servlet-mapping:
<servlet-mapping>
<servlet-name>Files</servlet-name>
<url-pattern>/Files</url-pattern>
</servlet-mapping>
Also, in you classes folder under WEB-INF, make sure you make a folder whose name is the same as the package name of the classes and put all the classes in that folder. In web.xml, use
<servlet>
<servlet-name>File</servlet-name>
<servlet-class>package.File</servlet-class>
</servlet>
to reference you servlet in the classes folder

Categories