1

I am getting exception com.sai.peps.ejb.frequentexceeding.FrequentExceedingBean cannot be cast to cannot be cast to javax.ws.rs.core.Application

I am using EJB 3.0 and jboss 5.1 & resteasy

Please suggested to me, where is my mistake.

  <context-param>
        <param-name>resteasy.scan</param-name>
        <param-value>true</param-value>
    </context-param>
    <context-param>
        <param-name>resteasy.resources</param-name>
        <param-value>com.sai.peps.ejb.frequentexceeding.MyRestApplication</param-value>
    </context-param>
    <context-param>
        <param-name>resteasy.servlet.mapping.prefix</param-name>
        <param-value>/rest/</param-value>
    </context-param>

 <servlet>
        <servlet-name>resteasy-servlet</servlet-name>
        <servlet-class>
            org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher
        </servlet-class>
        <init-param>
            <param-name>javax.ws.rs.Application</param-name>
            <param-value>com.sai.peps.ejb.frequentexceeding.MyRestApplication</param-value>
        </init-param>
    </servlet>  
  <servlet-mapping>
        <servlet-name>resteasy-servlet</servlet-name>
        <url-pattern>/rest/*</url-pattern>
    </servlet-mapping>

Edited:

package com.sai.peps.ejb.frequentexceeding;

import java.util.HashSet;
import java.util.Set;

import javax.ws.rs.ApplicationPath;
import javax.ws.rs.core.Application;
@ApplicationPath("/rest")
public class MyRestApplication extends Application {
    private Set<Object> resourceObjects = new HashSet<Object>();
    private Set<Class<?>> resourceClasses = new HashSet<Class<?>>();

    public  MyRestApplication() {
        resourceClasses.add(FrequentExceedingBean.class);
    }
    @Override
    public Set<Class<?>> getClasses() {
        return resourceClasses;
    }
    @Override
    public Set<Object> getSingletons() {
        return resourceObjects;
    }
}

i have added this code.. Still not working

2 Answers2

1

If your class com.sai.peps.ejb.frequentexceeding.FrequentExceedingBean should be the Aplication class as it is configured, it must extend javax.ws.rs.core.Application because the servlet container will instantiate an object of this class and then cast ist to javax.ws.rs.core.Application to be able to call it's getClasses() and getSingletons() method.

Update

Alas JBoss 5.1 has not yet Servlet 3.0., so you cannot confugre it without the web.xml.

Please check the accepted answer of this question for the needed entries in the web.xml file. The configuration is different from yours in respect to where the classnames are. I myself haven't used web.xml configuration for quite a time anymore, so I am not so firm there.

Community
  • 1
  • 1
P.J.Meisch
  • 18,013
  • 6
  • 50
  • 66
  • Thanks. well explained –  Apr 26 '17 at 09:08
  • Based on your suggestion i made create class (MyRestApplication ).But i still getting com.sai.peps.ejb.frequentexceeding.MyRestApplication cannot be cast to cannot be cast to javax.ws.rs.core.Application .Please help me sir –  Apr 27 '17 at 11:42
  • And does this new class `MyRestApplication` extend `javax.ws.rs.core.Application`? – P.J.Meisch Apr 27 '17 at 13:17
0

your web.xml seems a little bit messy.

The question is: why should you provide your own implementation fo Application class?

If you have

resteasy.scan = true

you don't need anything else (exept for proper annotations on your Resource and Providers classes to publish your resources).

if you have

resteasy.resources

valued with a list of resources

you can omit the resteasy.scan parameter and explicitly provide a list of resources to be published (in this case you put com.sai.peps.ejb.frequentexceeding.MyRestApplication and it's wrong, probably you should have put com.sai.peps.ejb.frequentexceeding.FrequentExceedingBean)

You may override Application class to move configuration out of web.xml and still have a strict control on the list of resources to be published with custom logic. Are you sure this is your need? If this is the case you should skip above configurations.

In any case choose one of the three methods