I keep on receiving a IllegalStateException: Could not find the FeatureManager when installing togglz in a web app on maven. I've followed the instuctions exactly. In my maven application, I have the following settings in my pom.xml file:
<dependency>
<groupId>org.togglz</groupId>
<artifactId>togglz-core</artifactId>
<version>2.1.0.Final</version>
</dependency>
<dependency>
<groupId>org.togglz</groupId>
<artifactId>togglz-console</artifactId>
<version>2.1.0.Final</version>
</dependency>
<dependency>
<groupId>org.togglz</groupId>
<artifactId>togglz-servlet</artifactId>
<version>2.1.0.Final</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
As well as the following in the web.xml file:
<context-param>
<param-name>org.togglz.core.manager.TogglzConfig</param-name>
<param-value>com.test.test.ana.FeatureFlagConfiguration</param-value>
</context-param>
<servlet>
<servlet-name>TogglzConsoleServlet</servlet-name>
<servlet-class>org.togglz.console.TogglzConsoleServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>TogglzConsoleServlet</servlet-name>
<url-pattern>/togglz/*</url-pattern>
</servlet-mapping>
This sample maven app runs fine, but when I try to go to the togglz virtual directory, it throws IllegalStateException: Could not find the FeatureManager error, it doesn't give much more detail than that. Any suggestions as to what that error really means?
I'm just trying to get a sample project that uses togglz that works. I can't use spring or cdi, just servlets. (yes, i have servlet 3.0 configured)
Thanks in advance,
Edit: Here is the exact stack trace:
[ERROR ] SRVE0777E: Exception thrown by application class 'org.togglz.core.context.FeatureContext.getFeatureManager:49'
java.lang.IllegalStateException: Could not find the FeatureManager. For web applications please verify that the TogglzFilter starts up correctly. In other deployment scenarios you will typically have to implement a FeatureManagerProvider as described in the 'Advanced Configuration' chapter of the documentation.
at org.togglz.core.context.FeatureContext.getFeatureManager(FeatureContext.java:49)
at org.togglz.core.manager.LazyResolvingFeatureManager.getDelegate(LazyResolvingFeatureManager.java:24)
at org.togglz.core.manager.LazyResolvingFeatureManager.getCurrentFeatureUser(LazyResolvingFeatureManager.java:49)
at org.togglz.console.TogglzConsoleServlet.isFeatureAdmin(TogglzConsoleServlet.java:68)
at org.togglz.console.TogglzConsoleServlet.service(TogglzConsoleServlet.java:55)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:668)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1285)
at [internal classes]
If you are in a plain Servlet environment, you will have to do the following things after adding the Maven dependencies:
Implement your feature enum
This typically looks like this:
public enum MyFeatures implements Feature {
#EnabledByDefault
#Label("First Feature")
FEATURE_ONE,
#Label("Second Feature")
FEATURE_TWO;
public boolean isActive() {
return FeatureContext.getFeatureManager().isActive(this);
}
}
Configure Togglz by implementing TogglzConfig
A typical example looks like this:
public class MyTogglzConfiguration implements TogglzConfig {
public Class<? extends Feature> getFeatureClass() {
return MyFeatures.class;
}
public StateRepository getStateRepository() {
return new FileBasedStateRepository(new File("/tmp/features.properties"));
}
public UserProvider getUserProvider() {
return new ServletUserProvider();
}
}
Register your configuration class in web.xml
In a plain Servlet environment you will now have to register your TogglzConfig implementation by adding something like this to your web.xml:
<context-param>
<param-name>org.togglz.core.manager.TogglzConfig</param-name>
<param-value>com.example.myapp.MyTogglzConfiguration</param-value>
</context-param>
You should also explicitly tell Togglz that you do not want it to lookup the FeatureManager from Spring or CDI but to create and manage an instance itself:
<context-param>
<param-name>org.togglz.FEATURE_MANAGER_PROVIDED</param-name>
<param-value>true</param-value>
</context-param>
In Servlet 3.0 environments, the TogglzFilter is typically picked up automatically. However, you can also register it manually:
<filter>
<filter-name>TogglzFilter</filter-name>
<filter-class>org.togglz.servlet.TogglzFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>TogglzFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
I hope this help. If this still doesn't work, please include the full stacktrace in your question.
Related
I'm doing a websocket app using Atmosphere and I'm trying to reproduce the chat sample in my own environment. I'm working with a TomEE 7 plus server, and the sample works fine on it.
I added the maven dependency to atmosphere-runtime and to servlet 3.0 as is it done in the sample
<!-- PubSub dependencies -->
<dependency>
<groupId>org.atmosphere</groupId>
<artifactId>atmosphere-runtime</artifactId>
<version>2.3.3</version>
</dependency>
<!-- Spécification servlet 3.0 nécessaire pour atmosphere -->
<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-servlet_3.0_spec</artifactId>
<version>1.0</version>
</dependency>
Then I put my servlet in the web.xml file
<!-- Atmosphere Servlet -->
<servlet>
<description>AtmosphereServlet</description>
<servlet-name>AtmosphereServlet</servlet-name>
<servlet-class>org.atmosphere.cpr.AtmosphereServlet</servlet-class>
<!-- limit classpath scanning to speed up starting, not mandatory -->
<init-param>
<param-name>org.atmosphere.cpr.packages</param-name>
<param-value>my.package.web.websocket</param-value>
</init-param>
<init-param>
<param-name>org.atmosphere.interceptor.HeartbeatInterceptor.clientHeartbeatFrequencyInSeconds</param-name>
<param-value>10</param-value>
</init-param>
<load-on-startup>0</load-on-startup>
<async-supported>true</async-supported>
</servlet>
<servlet-mapping>
<servlet-name>AtmosphereServlet</servlet-name>
<url-pattern>/chat/*</url-pattern>
</servlet-mapping>
But then when I try to Inject AtmosphereResource in my Chat class I got this error :
GRAVE: CDI Beans module deployment failed
org.apache.webbeans.exception.inject.DeploymentException: javax.enterprise.inject.UnsatisfiedResolutionException: Api type [org.atmosphere.cpr.AtmosphereResource] is not found with the qualifiers
Qualifiers: [#javax.enterprise.inject.Default()]
for injection into Field Injection Point, field name : resource, Bean Owner : [Chat, Name:null, WebBeans Type:MANAGED, API Types:[my.package.web.websocket.Chat,java.lang.Object], Qualifiers:[javax.enterprise.inject.Any,javax.enterprise.inject.Default]]
at org.apache.webbeans.config.BeansDeployer.deploy(BeansDeployer.java:215)
at org.apache.openejb.cdi.OpenEJBLifecycle.startApplication(OpenEJBLifecycle.java:192)
at org.apache.openejb.cdi.ThreadSingletonServiceImpl.initialize(ThreadSingletonServiceImpl.java:160)
at org.apache.openejb.cdi.CdiBuilder.build(CdiBuilder.java:41)
at org.apache.openejb.assembler.classic.Assembler.createApplication(Assembler.java:846)
at org.apache.openejb.assembler.classic.Assembler.createApplication(Assembler.java:652)
at org.apache.tomee.catalina.TomcatWebAppBuilder.startInternal(TomcatWebAppBuilder.java:1261)
at org.apache.tomee.catalina.TomcatWebAppBuilder.configureStart(TomcatWebAppBuilder.java:1100)
at org.apache.tomee.catalina.GlobalListenerSupport.lifecycleEvent(GlobalListenerSupport.java:130)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)
at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5416)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1575)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1565)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
Caused by: javax.enterprise.inject.UnsatisfiedResolutionException: Api type [org.atmosphere.cpr.AtmosphereResource] is not found with the qualifiers
Qualifiers: [#javax.enterprise.inject.Default()]
for injection into Field Injection Point, field name : resource, Bean Owner : [Chat, Name:null, WebBeans Type:MANAGED, API Types:[my.package.wen.websocket.Chat,java.lang.Object], Qualifiers:[javax.enterprise.inject.Any,javax.enterprise.inject.Default]]
at org.apache.webbeans.util.InjectionExceptionUtil.throwUnsatisfiedResolutionException(InjectionExceptionUtil.java:60)
at org.apache.webbeans.container.InjectionResolver.checkInjectionPoint(InjectionResolver.java:195)
at org.apache.webbeans.container.BeanManagerImpl.validate(BeanManagerImpl.java:960)
at org.apache.webbeans.config.BeansDeployer.validate(BeansDeployer.java:491)
at org.apache.webbeans.config.BeansDeployer.validateInjectionPoints(BeansDeployer.java:422)
at org.apache.webbeans.config.BeansDeployer.deploy(BeansDeployer.java:202)
... 18 more
Ha and another usefull Information I don't use the ObjectMapperInjectable.java so I don't have the META-INF/Services/org.atmosphere.inject.Injectable file (it's used in the sample).
And I have a beans.xml in my projet, i'm able to inject my business service in Chat.java
I understand that it doesn't find the Default qualifier, but I don't understand why.
Do I need to specify a Qualifier for AtmospherResource interface (I don't think so) ? Are not there a default implementation ?
Is there someone who solved the same problem ?
Thanks
EDIT
After some test it seems come from the beans.xml. If I add it in the original sample project under META-INF/ I got the same error.
I have found a few questions like this on SO already but none of them seemed to address my particular problem, and I have been unable to find a solution on my own.
Here is the error I'm getting:
Caused by: org.glassfish.jersey.message.internal.MessageBodyProviderNotFoundException: MessageBodyReader not found for media type=multipart/form-data; boundary=----WebKitFormBoundaryHWk1XUaeu7pEiDth, type=class org.glassfish.jersey.media.multipart.FormDataMultiPart, genericType=class org.glassfish.jersey.media.multipart.FormDataMultiPart.
I am sending this through a jQuery AJAX request that looks like this:
$('#upload-image-form').on('submit', function(e) {
e.preventDefault();
var data = new FormData(this);
$.ajax({
url: url,
method: 'POST',
contentType: false,
processData: false,
data: data,
}).done(function(data) {
console.log(data);
}).fail(function(res, status) {
onError(res, status, 'Image upload failed');
});
});
And this is my Java endpoint:
#POST
#Path("/{userId}")
#Consumes("multipart/form-data")
public Response createGraphic(
#PathParam("userId") int userId,
FormDataMultiPart multiPartFormData) { ... }
I have seen a few people have luck with changing the parameter of the endpoint method to use #FormDataParam instead of FormDataMultiPart (as seen here), but I cannot edit the Java class, so I must use it how it is above.
My pom.xml has the following dependencies:
<dependency>
<groupId>org.jvnet</groupId>
<artifactId>mimepull</artifactId>
<version>1.6</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-server</artifactId>
<version>2.12</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-multipart</artifactId>
<version>2.12</version>
</dependency>
web.xml
<servlet>
<servlet-name>Jersey</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>my.package</param-value>
</init-param>
<load-on-startup>5</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Jersey</servlet-name>
<url-pattern>/api/*</url-pattern>
</servlet-mapping>
The only other thing I was able to dig up was to register the MultiPartFeature using a ResourceConfig; however, the project I'm working with does not have any Application classes or any class that extends ResourceConfig (it's a WAR that's deployed to Tomcat, so no main class).
Is there any other configuration that needs to be done? I'm stumped as to why this is not working.
The MultiPartFeature has the required reader and writer. But you still need to register the feature. As you've mentioned, you will often see it's registration in an Application/ResourceConfig subclass. But in a web.xml, you can simply add it to the list of classes to add as provider. You can do that by adding an <init-param> to the servlet configuration, i.e.
<init-param>
<param-name>jersey.config.server.provider.classnames</param-name>
<param-value>
org.glassfish.jersey.media.multipart.MultiPartFeature,
some.other.Provider
</param-value>
</init-param>
As you can see in the example, if you need to register any other providers/features, you comma-delimit the class names.
I am trying to use the GZipFilter servlet provided in the jetty-servlets lib. My web app runs on Tomcat rather than Jetty. I know that Jetty is another servlet engine, but I should be able to use individual components.
I use maven to build my application. Whenever I include jetty-servlets in my pom, my web application refuses to start, failing at the declaration of GzipFilter in the web.xml.
The error is as follows,
Mar 31, 2014 3:03:32 PM org.apache.catalina.core.StandardContext filterStart
SEVERE: Exception starting filter GzipFilter
java.lang.NoClassDefFoundError: javax/servlet/AsyncListener
at java.lang.Class.getDeclaredConstructors0(Native Method)
at java.lang.Class.privateGetDeclaredConstructors(Class.java:2493)
at java.lang.Class.getConstructor0(Class.java:2803)
at java.lang.Class.newInstance(Class.java:345)
at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:275)
I knew that Jetty-Servlets has a dependency on servlets-api, so I excluded it from the dependency in maven.
My snippet of pom.xml looks like,
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-servlets</artifactId>
<version>9.1.0.M0</version>
<exclusions>
<exclusion>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
</exclusion>
</exclusions>
</dependency>
My snippet of web.xml looks like,
<filter>
<filter-name>GzipFilter</filter-name>
<filter-class>org.eclipse.jetty.servlets.GzipFilter</filter-class>
<init-param>
<param-name>mimeTypes</param-name>
<param-value>text/html,text/plain,text/xml,application/xhtml+xml,text/css,application/javascript,image/svg+xml</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>GzipFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
The missing javax.servlet.AsyncListener class is part of Servlet Spec 3.0, which makes sense because Jetty 9.0.x follows that spec.
Perhaps you are using an older version of Tomcat? Tomcat versions prior to 7.0.x do not implement this, in which case you have a problem.
See also this question.
I am working on a project with RESTful services. I have modules as web layer, business layer and so. I added basic api layer (using jersey) and I get basic response for get request. Now I must connect it to business layer. I was googling but I am not sure how to implement each solutions to my project.
This is my resource class for trip:
#Path("trip")
public class TripResource {
#Context
private UriInfo context;
#Inject
private AdminService adminService;
public TripResource() {
}
#GET
#Produces("text/plain")
public List<TripDTO> getText() {
return adminService.listAllTrips();
}
}
and this I use for adding resources classes:
#javax.ws.rs.ApplicationPath("api")
public class ApplicationConfig extends Application {
#Override
public Set<Class<?>> getClasses() {
Set<Class<?>> resources = new java.util.HashSet<Class<?>>();
addRestResourceClasses(resources);
return resources;
}
private void addRestResourceClasses(Set<Class<?>> resources) {
resources.add(cz.infi.javatravelagency.ServiceResource.class);
resources.add(cz.infi.javatravelagency.TripResource.class);
}
}
My pom.xml:
<name>JavaTravelAgency - Api module</name>
<dependencies>
<dependency>
<groupId>cz.infi</groupId>
<artifactId>javatravelagency-business</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet</artifactId>
<version>2.4.1</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-moxy</artifactId>
<version>2.4.1</version>
</dependency>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-web-api</artifactId>
<version>7.0</version>
<type>jar</type>
</dependency>
</dependencies>
<build>
<plugins>
<!-- Java language version -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>6</source>
<target>6</target>
</configuration>
</plugin>
<!-- Servlet 3.0 without web.xml -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.1.1</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
</plugins>
</build>
I tried to follow answer in this link. And I just added:
public class MyApplicationBinder extends AbstractBinder {
#Override
protected void configure() {
bind(AdminServiceImpl.class).to(AdminService.class);
}
}
and now I am stuck.
How can I add this binder to my config class?
What's the easiest implementation without using any other technology?
this also cost me a lot of time.
Try the following:
Add a HK2 Binder to your project as described here: https://jersey.java.net/documentation/latest/migration.html
Here you have to add the binding to your business logic.
You have this already (just added for completeness).
e. g.
public class MyBinder extends AbstractBinder {
#Override
protected void configure() {
// request scope binding
bind(MyInjectablePerRequest.class)
.to(MyInjectablePerRequest.class)
.in(RequestScope.class);
// singleton binding
bind(MyInjectableSingleton.class).in(Singleton.class);
// singleton instance binding
bind(new MyInjectableSingleton()).to(MyInjectableSingleton.class);
}
}
Then add a "ResourceConfig" class to your project and register your binder like here: http://sleeplessinslc.blogspot.de/2012/10/jax-rs-20-jersey-20-preview-example.html
In your case you could simply extend your ApplicationConfig from ResourceConfig instead of ApplicationConfig (this is what I did). All classes registered in "getClasses()" should then be like described below.
e. g.
/**
* Application config
*/
public class ApplicationConfig extends ResourceConfig {
public ApplicationConfig() {
register(SomeResources.class, SomeProviders.class);
// Register different Binders
addBinders(new MyBinder());
}
}
At least ensure that your web.xml uses the config. This depends on your setup (glassfish, servlet v1 / v2, etc.)
As you're already using the ApplicationConfig class, chances are good, that you're using the correct settings already.
Again here is an example:
<servlet>
<servlet-name>om.example.package.to.your.config.ApplicationConfig</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>javax.ws.rs.Application</param-name>
<param-value>com.example.package.to.your.config.ApplicationConfig</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
Hope this will help ;)
Regards
Ben
Found a similar post right now:
Dependency injection with Jersey 2.0
You need to register your resource class with Jersey. So if your application is named MyApplication, then you can do
public class MyApplication extends ResourceConfig {
/*Register JAX-RS application components.*/
public MyApplication () {
register(TripResource.class);
}
}
Also in the web.xml file, add the MyApplication to the servlet container:
<servlet>
<servlet-name>SpringApplication</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>javax.ws.rs.Application</param-name>
<param-value>mypackage.MyApplication</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
A simple example of using Jersey with Spring DI can be found here.
I am able to access REST services from the browser url: http://localhost:8080/assignment/services/services/test/test1
From My servlet, I use to call service method as shown below. Now I need to call through REST services but getting below error.
URL url = new URL("http://localhost:8080/assignment/services/services/"+userName+"/"+password);
System.out.println("URL-->"+url);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
connection.setRequestProperty("Accept", "application/xml");
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
while(bufferedReader.readLine() != null){
result = bufferedReader.readLine();
}
// result = userService.login(userName, password);
System.out.println(result);
here is the error:
INFO: Reloading Context with name [/assignment] is completed
URL-->http://localhost:8080/assignment/services/test/test1
Jul 30, 2013 12:52:02 PM org.apache.cxf.jaxrs.interceptor.JAXRSInInterceptor processRequest
WARNING: No root resource matching request path /assignment/services/test/test1 has been found, Relative Path: /test/test1. Please enable FINE/TRACE log level for more details.
Jul 30, 2013 12:52:02 PM org.apache.cxf.jaxrs.impl.WebApplicationExceptionMapper toResponse
WARNING: javax.ws.rs.NotFoundException
at org.apache.cxf.jaxrs.interceptor.JAXRSInInterceptor.processRequest(JAXRSInInterceptor.java:172)
at org.apache.cxf.jaxrs.interceptor.JAXRSInInterceptor.handleMessage(JAXRSInInterceptor.java:100)
at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:271)
at org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:121)
at org.apache.cxf.transport.http.AbstractHTTPDestination.invoke(AbstractHTTPDestination.java:239)
at org.apache.cxf.transport.servlet.ServletController.invokeDestination(ServletController.java:223)
at org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:203)
at org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:137)
at org.apache.cxf.transport.servlet.CXFNonSpringServlet.invoke(CXFNonSpringServlet.java:158)
at org.apache.cxf.transport.servlet.AbstractHTTPServlet.handleRequest(AbstractHTTPServlet.java
...
Jul 30, 2013 12:52:02 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [LoginServlet] in context with path [/assignment] threw exception
java.io.FileNotFoundException: http://localhost:8080/assignment/services/services/test/test1
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1623)
at com.viasat.test.login.servlet.LoginServlet.process(LoginServlet.java:77)
at com.viasat.test.login.servlet.LoginServlet.doPost(LoginServlet.java:52)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
Service class:
#Service
#Path("/services/")
public class UserServiceImpl implements UserService {
#GET
#Path("{userName}/{password}")
#Produces(MediaType.TEXT_XML)
public String login(#PathParam("userName")String username, #PathParam("password")String password)
throws JAXBException, PropertyException, FileNotFoundException {
web.xml:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>WEB-INF/beans.xml</param-value>
</context-param>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<servlet>
<servlet-name>cxf</servlet-name>
<servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet>
<display-name>LoginServlet</display-name>
<servlet-name>LoginServlet</servlet-name>
<servlet-class>com.abc.test.login.servlet.LoginServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>LoginServlet</servlet-name>
<url-pattern>/LoginServlet</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>cxf</servlet-name>
<url-pattern>/services/*</url-pattern>
</servlet-mapping>
</web-app>
Update:
pom.xml:
<dependencies>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-jaxrs</artifactId>
<version>1.9.12</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxrs</artifactId>
<version>2.7.5</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>3.2.3.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>3.2.3.RELEASE</version>
</dependency>
Now Javax.ws.rs.NotFoundException gone, but, File not found exception still comes.
Solution-1
One of the solution is that version issue with CXF and Spring. I have made cxf version to 2.5.2 which avoids javax.ws.rs.NotFoundException.
Now I have updated to
<spring.version>3.2.2.RELEASE</spring.version>
<cxf.version>2.5.2</cxf.version>
I was using 2.7.5 cxf version.
Solution -2
In my service class I have made
#Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) instead of
#Produces(MediaType.TEXT_XML)
The URL you are using to fire the GET request has two services levels:
http://localhost:8080/assignment/services/services/"
but in your REST service class, there is only one 'services' level in Path. You may need to change the Path Param to like this:
#Service
#Path("/services/")
public class UserServiceImpl implements UserService {
#GET
#Path("services/{userName}/{password}")
#Produces(MediaType.TEXT_XML)
public String login(#PathParam("userName")String username, #PathParam("password")String password)
throws JAXBException, PropertyException, FileNotFoundException {
I think "services" is by default the path where CXF exposes the auto-generated WADLs and therefore cannot be used in a resource path.
Try either changing "services" to another word in your web.xml and Service class (#Path) or change the CXF servlet config like so (see the service-list-path param):
<servlet>
<servlet-name>cxf</servlet-name>
<servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
<init-param>
<param-name>service-list-path</param-name>
<param-value>web-services</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
Reference: http://cxf.apache.org/docs/jaxrs-services-description.html (section Service listings and WADL queries almost at the end).
Note that you can override the location at which listings are provided
(in case you would like '/services' be available to your resources)
using 'service-list-path' CXFServlet parameter
one common reason for this error is that cxf cannot find a restful implementation for the restful service to match the request to the resource method later. the spec is ambiguious in this area but your jaxrs annotations in the interface must match implementation in cxf.
--eliani
As described in CXF project throws java.lang.NoClassDefFoundError: javax/ws/rs/NotFoundException the
Error can be solved by adding
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
<version>2.0-m10</version>
</dependency>