I have been working on my own REST API built with jersey and java. Today it stopped working though after a friend who also works on it pushed his changes. he didn't change anything on the dependency side, but he did add an controller that our main API class creates. Now whenever I try to reach a resource the tomcat server throws an error:
exception
javax.servlet.ServletException: Servlet execution threw an exception
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
root cause
java.lang.AbstractMethodError: javax.ws.rs.core.UriBuilder.uri(Ljava/lang/String;)Ljavax/ws/rs/core/UriBuilder;
javax.ws.rs.core.UriBuilder.fromUri(UriBuilder.java:119)
com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:669)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.ja
We belive it started after he added jsoup dependency.
EDIT:
I edited my dependencies and web.xml, and now I only get 404 not found.
This is my dependencies form my pom.xml
<dependencies>
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-client</artifactId>
<version>2.23.2</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet-core</artifactId>
<version>2.23.2</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.codehaus.jettison</groupId>
<artifactId>jettison</artifactId>
<version>1.3.8</version>
</dependency>
<dependency>
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
<version>1.9.2</version>
</dependency>
<dependency>
<groupId>org.twitter4j</groupId>
<artifactId>twitter4j-core</artifactId>
<version>[4.0,)</version>
</dependency>
<dependency>
<groupId>org.facebook4j</groupId>
<artifactId>facebook4j-core</artifactId>
<version>[2.4,)</version>
</dependency>
</dependencies>
This is my 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>api</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>Jersey Web Application</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Jersey Web Application</servlet-name>
<url-pattern>/api/*</url-pattern>
</servlet-mapping>
</web-app>
Edit
If I try to reach: http://localhost:8080/api-mashup-api/api/v1/foobar
#Path("/v1")
public class API {
private Controller controller;
public API(){
controller = new Controller();
}
/**
* Prints to the screen if we are in /v1/foobar
*
* #return
*/
#GET
#Path("/foobar")
#Produces(MediaType.TEXT_HTML)
public String print2() {
return "Please specify what resource you need.";
}
I just get 404.
Probably your issue caused by wrong jersey-container-servlet which may cause the wrong uribuilder to be pickedup
https://jersey.java.net/documentation/latest/modules-and-dependencies.html#server-jdk
jersey-container-servlet => Jersey core Servlet 3.x implementation
jersey-container-servlet-core => Jersey core Servlet 2.x implementation
Change:
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet-core</artifactId>
<version>2.23.2</version>
<scope>provided</scope>
</dependency>
to
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet</artifactId>
<version>2.23.2</version>
<scope>provided</scope>
</dependency>
Also refer https://jersey.java.net/documentation/latest/modules-and-dependencies.html#dependencies to find out which dependencies you need to provide for Glassfish and other Servlet based (non jax-rs integrated) containers
1) You have an AbstractMethodError exception which is thrown when an application tries to call an abstract method.
uri is an abstract method in UriBuilder, so you need an implementation of this.
You should use JAX-RS 2.0 with Jersey 2.* that implements JAX-RS 2.0 and contains an implementation to uri method.
2) By looking at your stack trace it clearly states that you are using both Jersey versions 1 & 2 and that's not possible, So the classloader is picking up the wrong URIBuilder class.
Stack Trace:
com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:669)
The Jersey dependencies in group com.sun.jersey are all Jersey version 1. Jersey version 2 uses the group org.glassfish.jersey.
Related
I'm trying to make a restful service with jersey, for that I'm using the jersey example for a maven project. So this is what I got:
my pom.xml:
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>simple-service-webapp</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<name>simple-service-webapp</name>
<build>
<finalName>simple-service-webapp</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
<inherited>true</inherited>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.glassfish.jersey</groupId>
<artifactId>jersey-bom</artifactId>
<version>${jersey.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet-core</artifactId>
<!-- use the following artifactId if you don't need servlet 2.x compatibility -->
<!-- artifactId>jersey-container-servlet</artifactId -->
</dependency>
<!-- uncomment this to get JSON support <dependency> <groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-moxy</artifactId> </dependency> -->
<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>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.jaxrs</groupId>
<artifactId>jackson-jaxrs-json-provider</artifactId>
<version>2.6.0</version>
</dependency>
</dependencies>
<properties>
<jersey.version>2.19</jersey.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>
my web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!-- This web.xml file is not required when using Servlet 3.0 container,
see implementation details http://jersey.java.net/nonav/documentation/latest/jax-rs.html -->
<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">
<servlet>
<servlet-name>Jersey Web Application</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>com.example</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Jersey Web Application</servlet-name>
<url-pattern>/webapi/*</url-pattern>
</servlet-mapping>
</web-app>
the resource
package com.example;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
/**
* Root resource (exposed at "myresource" path)
*/
#Path("/myresource")
public class MyResource {
/**
* Method handling HTTP GET requests. The returned object will be sent
* to the client as "text/plain" media type.
*
* #return String that will be returned as a text/plain response.
*/
#GET
#Produces(MediaType.TEXT_PLAIN)
public String getIt() {
return "Got it!";
}
#Path( "complexObject/{name}" )
#GET
#Produces( { MediaType.APPLICATION_JSON } )
public ComplexObject complexObject( #PathParam( "name" ) String name ) {
return new ComplexObject(name);
}
}
The ComplexObject class is just a class with a string.
when I hit the url: http://localhost:8080/simple-service-webapp/webapi/myresource/
This work, I get "Got it!"
but when I hit on: http://localhost:8080/simple-service-webapp/webapi/myresource/complexObject/capo
I get this error on the console:
SEVERE: MessageBodyWriter not found for media type=application/json,
type=class com.example.ComplexObject, genericType=class
com.example.ComplexObject.
How can I fix this?
With this dependency
<dependency>
<groupId>com.fasterxml.jackson.jaxrs</groupId>
<artifactId>jackson-jaxrs-json-provider</artifactId>
<version>2.6.0</version>
</dependency>
You will still need to register the provider. You could register it individually
<init-param>
<param-name>jersey.config.server.provider.classnames</param-name>
<param-value>
com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider
</param-value>
</init-param>
Or since the dependency also comes with Jackson ExceptionMappers, you might want to just have the whole package scanned (just add it to the list of packages)
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>
com.example,
com.fasterxml.jackson.jaxrs.json
</param-value>
</init-param>
Another option, besides using the above dependency, is to use Jersey's "wrapper" dependency (which handle the registration of the of the providers, among a couple other things such as Jackson Entity Filtering. Just used
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-json-jackson</artifactId>
</dependency>
With this dependency, do registration is required. It is automatically registered through Jersey's auto-discoverable feature
This question already has answers here:
Why does Spring MVC respond with a 404 and report "No mapping found for HTTP request with URI [...] in DispatcherServlet"?
(13 answers)
Closed 6 years ago.
Morning, I already checked most of the answers to this problem (No mapping found for HTTP request with URI.... in DispatcherServlet with name) and also (No mapping found for HTTP request with URI [/ChickenTest/index] in DispatcherServlet with name 'dispatcherServlet') but I'm still getting "No mapping found for HTTP request with URI [/bmoa-surrounds/bmoa] in DispatcherServlet with name 'bmoa'", so, any help whould be apreciated:
pom:
<dependencies>
<!-- Junit -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<!-- Testng -->
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.8.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
</dependency>
<!-- Log4j -->
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.2.6</version>
</dependency>
<dependency>
<groupId>javax.xml</groupId>
<artifactId>jaxb-impl</artifactId>
<version>2.1</version>
</dependency>
</dependencies>
then my web.xml
<display-name>bmoa-surrounds</display-name>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/bmoa-servlet.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>bmoa</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>bmoa</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
my spring config file
<context:component-scan base-package="xxxx"/>
<context:annotation-config/>
<context:spring-configured/>
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/"/>
<property name="suffix" value=".jsp"/>
</bean>
and finally my controller
#Controller
public class BMOAServlet implements HttpRequestHandler {
/**
*
*/
#RequestMapping("/bmoa-surrounds/bmoa")
public void handleRequest(final HttpServletRequest request,
final HttpServletResponse response) throws ServletException,
IOException {
response.getWriter().write("result=" + handleIncomingMessage(request));
}
I'm calling "http:// localhost :8080/bmoa-surrounds/bmoa?juan=9898" but I'm still geting No mapping found for HTTP request with URI [/bmoa-surrounds/bmoa] in DispatcherServlet with name 'bmoa', any ideas? my env is java6 a deploying to jboss
also im sure that the beans are beign loaded, I got this in the server log
12:34:06,671 INFO [org.springframework.beans.factory.support.DefaultListableBeanFactory] (MSC service thread 1-5) Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory#57ffa0: defining beans [BMOABussinesDelegate,properties,BMOAServlet,.........]; parent: org.springframework.beans.factory.support.DefaultListableBeanFactory#122d7c6
and also this
12:34:06,753 INFO [org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping] (MSC service thread 1-5) Mapped URL path [/bmoa-surrounds/bmoa] onto handler 'BMOAServlet' 12:34:06,754 INFO [org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping] (MSC service thread 1-5) Mapped URL path [/bmoa-surrounds/bmoa.*] onto handler 'BMOAServlet' 12:34:06,755 INFO [org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping] (MSC service thread 1-5) Mapped URL path [/bmoa-surrounds/bmoa/] onto handler 'BMOAServlet'
doesnt the last one means that the mappings are loaded?? please help ;(
I'm feeling really dumb right now....at first (and thanks for the clue Angad), the url-pattern was wrong, it should point to the servlet, also, the loaded bean was BMOAServlet instead of bmoa, so when I changed the url-patter no bmoa, managed to see the error, at the end my web.xml needed to look like this:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/bmoa-servlet.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>bmoa</servlet-name>
<servlet-class>org.springframework.web.context.support.HttpRequestHandlerServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>bmoa</servlet-name>
<url-pattern>/bmoa</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
and the bean class like this:
#Controller("bmoa")
public class BMOAServlet implements HttpRequestHandler {
/**
*
*/
#RequestMapping("/bmoa-surrounds/bmoa")
public void handleRequest(final HttpServletRequest request,
final HttpServletResponse response) throws ServletException,
IOException {
response.getWriter().write("result=" + handleIncomingMessage(request));
}
Now everything works smooth, I also changed the servlet class like this:
<servlet>
<servlet-name>bmoa</servlet-name>
<servlet-class>org.springframework.web.context.support.HttpRequestHandlerServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
Check this config file: src\main\webapp\WEB-INF\spring\appServlet\controllers.xml
content is like:
<context:component-scan base-package="org.springframework.samples.mvc" />
is your controller in "org.springframework.samples.mvc"?
In pom.xml make sure packaging is set to war like <packaging>war</packaging> ,not to jar or any thing else.
I am trying to add webflow and security configuration to an operational Spring 3.1 MVC web application.
I got rid of the application-context.xml file and ContextLoaderListener, and use AnnotationConfigWebApplicationContext with an #EnableWebMvc #Configuration annotated class.
Yet, when I follow the webflow and security documentation, it seems like an application-context.xml file and ContextLoaderListener are necessary. The later seems to create a conflict with AnnotationConfigWebApplicationContext.
Can anyone provide a simple but complete Spring 3.1 MVC Web Application configuration with webflow and security enabled example? I am looking for a web.xml example file, plus any other required files.
If someone has a complete sample application downloadable online, it is even better.
The following works when deploying to Tomcat 7:
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<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"
metadata-complete="false">
<!-- Context Params -->
<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.mypackage.web.WebConfig</param-value>
</context-param>
<!-- Filters -->
<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>
<!-- Listeners -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- Declaring and configuring the default Spring Servlet -->
<servlet>
<servlet-name>springExample</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<!-- Enabling annotation configuration for web app -->
<init-param>
<param-name>contextClass</param-name>
<param-value>org.springframework.web.context.support.AnnotationConfigWebApplicationContext
</param-value>
</init-param>
<!-- Loading order -->
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>springExample</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
WebConfig
#EnableWebMvc
#ImportResource({ "/WEB-INF/spring-security.xml", "/WEB-INF/spring-webflow.xml"})
#Configuration
public class WebConfig extends WebMvcConfigurerAdapter {
// ...
}
Caveat: using #Import(SomeConfig.class) does not work anymore. It causes initialization issues. The workaround is to move the content of SomeConfig.class to WebConfig.class itself.
It is important to add proper maven dependencies, otherwise, Tomcat results in 404 Resource not found error messages:
pom.xml
<properties>
...
<spring.framework.version>3.1.2.RELEASE</spring.framework.version>
<spring.security.version>3.1.1.RELEASE</spring.security.version>
<spring.webflow.version>2.3.1.RELEASE</spring.webflow.version>
</properties>
<dependencies>
...
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring.framework.version}</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-core</artifactId>
<version>${spring.security.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-web</artifactId>
<version>${spring.security.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-config</artifactId>
<version>${spring.security.version}</version>
</dependency>
<dependency>
<groupId>cglib</groupId>
<artifactId>cglib</artifactId>
<version>2.1_3</version>
</dependency>
<dependency>
<groupId>org.springframework.webflow</groupId>
<artifactId>spring-webflow</artifactId>
<version>${spring.webflow.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.webflow</groupId>
<artifactId>spring-binding</artifactId>
<version>${spring.webflow.version}</version>
</dependency>
</dependencies>
Here's a working web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app
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"
version="3.0">
<session-config>
<session-timeout>30</session-timeout>
</session-config>
<filter>
<filter-name>rememberMeCookieFilter</filter-name>
<filter-class>be.example.fun.jsp.filters.RememberMeCookieFilter</filter-class>
</filter>
<filter>
<filter-name>mustBeSignedInFilter</filter-name>
<filter-class>be.example.fun.jsp.filters.MustBeSignedInFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>rememberMeCookieFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>mustBeSignedInFilter</filter-name>
<url-pattern>/private/*</url-pattern>
</filter-mapping>
</web-app>
When I remove the <filter> elements and use the following annotations instead:
#WebFilter(filterName="rememberMeCookieFilter")
public class RememberMeCookieFilter implements Filter
#WebFilter(filterName="mustBeSignedInFilter")
public class MustBeSignedInFilter implements Filter
Then Tomcat 7.0.14 gives me the following error:
java.lang.IllegalArgumentException: Filter mapping must specify either a <url-pattern> or a <servlet-name>
at org.apache.catalina.core.StandardContext.validateFilterMap(StandardContext.java:2956)
at org.apache.catalina.core.StandardContext.addFilterMap(StandardContext.java:2915)
at org.apache.catalina.deploy.WebXml.configureContext(WebXml.java:1180)
at org.apache.catalina.startup.ContextConfig.webConfig(ContextConfig.java:1270)
...
I followed the answer of this question, but that doesn't work for me.
Here are the dependencies of my web application:
<dependencies>
<!-- SLF4J (+ LOGBack) for logging -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.6.4</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy</artifactId>
<version>1.8.3</version>
</dependency>
<!-- The servlet API that I installed in my local repo -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>3.0</version>
<type>jar</type>
<scope>provided</scope>
<!--optional>false</optional-->
</dependency>
<!-- JUnit for testing -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.2</version>
<scope>test</scope>
</dependency>
</dependencies>
EDIT: I only have the issue when using Tomcat (7.0.14). Glassfish is fine.
It's a bug in Tomcat 7. I reported it as issue 53354.
As it's not possible to specify the invocation order in a #WebFilter, users are forced to explicitly specify <filter-mapping> in web.xml. This works in combination with a #WebFilter(filterName) in Glassfish and JBoss AS as follows:
#WebFilter(filterName="filter1")
public class Filter1 implements Filter {}
#WebFilter(filterName="filter2")
public class Filter2 implements Filter {}
with
<filter-mapping>
<filter-name>filter1</filter-name>
<url-pattern>/url1/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>filter2</filter-name>
<url-pattern>/url2/*</url-pattern>
</filter-mapping>
However it fails in Tomcat 7.0.27 with the following confusing exception (the <url-pattern> is been set)
Caused by: java.lang.IllegalArgumentException: Filter mapping must specify either a <url-pattern> or a <servlet-name>
at org.apache.catalina.core.StandardContext.validateFilterMap(StandardContext.java:3009)
at org.apache.catalina.core.StandardContext.addFilterMap(StandardContext.java:2968)
at org.apache.catalina.deploy.WebXml.configureContext(WebXml.java:1207)
at org.apache.catalina.startup.ContextConfig.webConfig(ContextConfig.java:1294)
at org.apache.catalina.startup.ContextConfig.configureStart(ContextConfig.java:855)
at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:345)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5161)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
... 7 more
In the meanwhile your best bet is to use Glassfish or JBoss AS instead, or to register the filters by <filter> anyway.
You must specify a target for the Servlet Filter. Either provide a value for 'servletNames' or 'urlPatterns'.
http://docs.oracle.com/javaee/6/api/javax/servlet/annotation/WebFilter.html
e.g.
#WebFilter(filterName="mustBeSignedInFilter", urlPatterns={ "/signed/in/path/*" })
public class MustBeSignedInFilter implements Filter
I am trying to deploy a simplest REST service using jersey, and JAX-RS, but I am getting this error,
HTTP ERROR: 404
NOT_FOUND
RequestURI=/hosting/demo/example
Powered by Jetty://
Where I think I have done everything right, below is the code I am using for it.
POM.XML (only pasting the part related to jersey)
<dependency>
<!-- the implementation of JAX-RS -->
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-server</artifactId>
<version>1.0.1</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-core</artifactId>
<version>1.0.1</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-client</artifactId>
<version>1.0.1</version>
<scope>compile</scope>
</dependency>
WEB.XML
<servlet>
<servlet-name>jersey</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>mop.core.service.restservices</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>jersey</servlet-name>
<url-pattern>/demo</url-pattern>
</servlet-mapping>
My Class having #GET
package mop.core.service.restservices;
import javax.swing.JOptionPane;
import javax.ws.rs.Consumes;
import javax.ws.rs.FormParam;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
#Path("/example")
public class PricePointRestService {
#GET
#Produces("text/plain")
public String getPricePoint(){
JOptionPane.showMessageDialog(null, "GET CALLED");
return "hello";
}
#POST
#Produces("application/xml")
#Consumes({"application/x-www-form-urlencoded", "multipart/form-data"})
public String doPost(#FormParam("xml") String xml) {
return "<xml></xml>";
}
}
The url I hit is: http://localhost/hosting/demo/example
Change your url-pattern in your web.xml to:
<url-pattern>/demo/*</url-pattern>
Are you sure the "hosting" part of the url is correct? What is the web app deployed under? Can you hit any pages in the web app?
Try adding a jsp to the web-app and see if you can hit that.
The problem i figured out was compatibility issue of ASM 2.2.3 and Jersey which requires ASM 3.1.
Hibernate depends upon ASm 2.2.3.
This bug is reported at http://opensource.atlassian.com/projects/hibernate/browse/EJB-358?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
I am trying to find out the work arounds for this, but those doesnt seem to work out, as cglib 2.2 and cglib-nodep also doesnt help.
javassist cannot be used through XML config file of hibernate, it requires hibernate.properties file, where the project i am working on used hibernate.cfg.xml.
Any Solution ?
Agree with Damo on:
<url-pattern>/demo/*</url-pattern>
Also add:
<load-on-startup>1</load-on-startup>
before:
</servlet>
I assume you're using Maven. Hibernate 3.2.4 runs fine on ASM 3.1 so you can ignore that dependency. This entry will work with Jersey.
<dependency><!-- hibernate 3.2.4.ga -->
<groupId>org.hibernate</groupId>
<artifactId>hibernate</artifactId>
<version>3.2.6.ga</version>
<exclusions>
<exclusion>
<groupId>asm</groupId>
<artifactId>asm</artifactId>
</exclusion>
<exclusion>
<groupId>asm</groupId>
<artifactId>asm-attrs</artifactId>
</exclusion>
<exclusion>
<groupId>cglib</groupId>
<artifactId>cglib</artifactId>
</exclusion>
</exclusions>
</dependency>